malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include<bits/stdc++.h>   #define llu unsigned long long     #define ll long long    #define l1 int   #define u_m unordered_map   #define M map   #define answer cout<<ans<<endl;   #define Sum cout<<sum<<endl;   #define sort1(s) sort(s.begin(),s.end())   #define pb(x) push_back(x)   #define yes cout<< YES <<endl;   #define no cout<< NO <<endl;   using namespace std;   /*    vector<vector<int>> v(101,vector<int>());   vector<bool> b(101,false);   vector<int> ans(101);       ll power(ll x, ll y)     {         ll res = 1;               while (y > 0)         {             if (y & 1)                 res = (res*x)%mod;             y = y/2;             x = (x*x)%mod;       }         return res%mod;     }   int dfs(int p,int k)   {       a[p]=true;       int i,j=1;       for(i=0;i<v[p].size();i++)       {           if(a[v[p][i]]==false)           {               if(k==4)               {                   ans[v[p][i]]=5;                   a[v[p][i]]=true;                   j=dfs(v[p][i],5);               }               else               {                   ans[v[p][i]]=4;                   a[v[p][i]]=true;                   j=dfs(v[p][i],4);               }           }       }       return j;   }   ll prime(ll n)   {       ll mx=n+1;//cout<<mx<<endl;       for(ll i=2;i*i<=n;i++)       {           if(n%i==0 && n/i!=i)           {               mx=min(mx,(n/i) + i);               //cout<<mx<<endl;           }       }       return mx;   }   ll modinv(ll x)   {       return power(x,mod-2)%mod;       }   void swap(ll *xp, ll *yp)    {        ll temp = *xp;        *xp = *yp;        *yp = temp;    }   void print(vector<ll> v)   {       ll i,j,n=v.size();       for(i=0;i<n;i++)       {           cout<<v[i]<<   ;       }       cout<<endl;   }   bool sortcol( const vector<int>& v1,                   const vector<int>& v2 ) {     return v1[1] < v2[1];    }        bool sortcol1( const vector<int>& v1,                   const vector<int>& v2 ) {     return v1[0] < v2[0];    }   void scan(vll &v,ll n)   {       for(ll i=0;i<n;i++)       cin>>v[i];   }   ll gcd(ll a, ll b)    {        if (b == 0)            return a;        return gcd(b, a % b);     }   ll lcm(ll a,ll b)   {       return (a*b)/gcd(a,b);   }   */       int main()   {       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);       /*l1 t;       cin>>t;       while(t--)*/       {        ll n;        cin>>n;        if(n==1)        {         cout<<4;         return 0;        }        if(n%2==0)        {         n=(n/2 + 1)*(n/2 + 1);        }        else        {         n=2*(n/2 + 1)*(n/2 + 2);        }        cout<<n;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<string> sx;   vector<string> vx;   int ft;   void generate(char str[], int k, int l) {     if (k < 0) {       str[l] =   0 ;       bool status = true;       for (int i = 0; i < strlen(str); i++) {         for (int j = i + 1; j < strlen(str); j++) {           if (str[i] == str[j]) {             status = false;             break;           }         }         if (status == false) break;       }       if (status) {         vx.push_back(string(str));       }       return;     } else {       for (int i = 0; i <= 9; i++) {         str[l] = i +  0 ;         generate(str, k - 1, l + 1);       }     }   }   set<string> check(string sno, int a, int b, set<string> fx) {     set<string> px;     for (int i = 0; i < vx.size(); i++) {       int c = 0, d = 0;       for (int j = 0; j < 4; j++) {         if (vx[i][j] == sno[j])           c++;         else {           for (int k = 0; k < 4; k++)             if (vx[i][j] == sno[k]) {               d++;               break;             }         }       }       if (c == a && b == d) {         if (ft == 0 || fx.find(vx[i]) != fx.end()) px.insert(vx[i]);       }     }     ft = 1;     return px;   }   int main() {     char str[10];     generate(str, 3, 0);     set<string> fx;     ft = 0;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       char inp[100];       getchar();       scanf( %[^ n] , inp);       string sno =   ;       int b, c;       b = c = -1;       bool stat = false;       for (int i = 0; i < strlen(inp); i++) {         if (inp[i] ==    )           stat = true;         else {           if (!stat)             sno += inp[i];           else if (b == -1)             b = inp[i] -  0 ;           else if (c == -1)             c = inp[i] -  0 ;         }       }       fx = check(sno, b, c, fx);     }     if (fx.size() == 1) {       string req = *(fx.begin());       cout << req << endl;     } else if (fx.size() > 1)       cout <<  Need more data  << endl;     else if (fx.size() == 0)       cout <<  Incorrect data  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int> > road;     for (int a = (0); a < (m); a++) {       int p, q;       cin >> p >> q;       if (p > q) swap(p, q);       road.push_back(make_pair(p, q));     }     int field[101][101];     for (int a = (0); a < (101); a++)       for (int b = (0); b < (101); b++) field[a][b] = 10000;     for (int a = (0); a < (m); a++)       for (int b = (0); b < (m); b++) {         int p = road[b].first;         int q = road[b].second;         int r = road[a].first;         int s = road[a].second;         if (p != r && p != s & q != r && q != s) {           int count = 0;           if (p < r && r < q) count++;           if (p < s && s < q) count++;           if (count == 1) {             field[a + 1][b + 1] = 1;             field[b + 1][a + 1] = 1;           }         }       }     int check[101];     for (int j = 1; j <= m; j++)       for (int i = 1; i <= m; i++)         for (int k = 1; k <= m; k++)           field[i][k] = min(field[i][k], field[i][j] + field[j][k]);     int flag = 0;     for (int a = 1; a <= m; a++)       if (field[a][a] % 2 == 1) flag = 1;     if (flag == 1)       cout <<  Impossible  << endl;     else {       int out[101];       for (int a = (0); a < (101); a++) out[a] = -1;       for (int a = 1; a <= m; a++)         if (out[a] == -1) {           out[a] = 0;           for (int b = 1; b <= m; b++)             if (field[a][b] < 200) {               out[b] = field[a][b] % 2;             }         }       int fflag = 0;       for (int a = 1; a <= m; a++)         for (int b = 1; b <= m; b++) {           if (field[a][b] == 1)             if (out[a] + out[b] != 1) fflag = 1;         }       if (fflag == 1)         cout <<  Impossible  << endl;       else {         for (int a = 1; a <= m; a++) {           if (out[a] == 0)             cout <<  o ;           else             cout <<  i ;         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 00;   const long long inf = 1e9 + 800;   long long a[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, r, sum = 0;     ;     cin >> n >> r;     for (long long i = 0; i < (1 << n); i++) {       cin >> a[i];       sum += a[i];     }     cout << fixed << setprecision(10);     for (long long i = 0; i < r; i++) {       cout << (long double)sum / (1 << n) << endl;       long long p, v;       cin >> p >> v;       sum -= a[p];       a[p] = v;       sum += a[p];     }     cout << (long double)sum / (1 << n) << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-11;   void fast() { std::ios_base::sync_with_stdio(0); }   int n;   vector<int> arr;   string s;   vector<vector<int>> dp;   int calc(int i, int state) {     if (i == n) return 0;     int &ret = dp[i][state];     if (ret != -1) {       return ret;     }     if (state == 1) return ret = calc(i + 1, 1) + arr[i];     if (s[i] ==  0 ) return ret = calc(i + 1, 0);     int x = calc(i + 1, 0) + arr[i];     int y = calc(i + 1, 1);     return ret = max(x, y);   }   int main() {     scanf( %d , &n);     arr.resize(n);     dp.resize(n);     for (int i = 0; i < n; i++) dp[i].resize(2, -1);     for (int &i : arr) scanf( %d , &i);     cin >> s;     reverse(arr.begin(), arr.end());     reverse(s.begin(), s.end());     printf( %d n , calc(0, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int head[100005], fa[100005], a[100005];   struct edge {     int to, next;   } edges[200005];   int em;   void addedge(int u, int v) {     edges[em].next = head[u];     edges[em].to = v;     head[u] = em++;     edges[em].next = head[v];     edges[em].to = u;     head[v] = em++;   }   void dfs(int x, int f) {     fa[x] = f;     for (int e = head[x]; e != -1; e = edges[e].next) {       int v = edges[e].to;       if (v != f) {         dfs(v, x);       }     }   }   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int m = n - 1;     memset(head, -1, sizeof(head));     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       addedge(x, y);     }     dfs(1, -1);     while (q--) {       int qq;       scanf( %d , &qq);       if (qq == 1) {         int v;         scanf( %d , &v);         int in = -1;         int tmp = fa[v];         while (tmp != -1) {           int g = gcd(a[tmp], a[v]);           if (g > 1) {             in = tmp;             break;           }           tmp = fa[tmp];         }         printf( %d n , in);       } else if (qq == 2) {         int v, w;         scanf( %d%d , &v, &w);         a[v] = w;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     string second;     cin >> n >> second;     string t = second;     bool ok = 1;     vector<int> vec;     for (int i = 0; i < n; i++) {       if (second[i] ==  W ) continue;       if (i + 1 < n && second[i + 1] == second[i]) {         vec.push_back(i);         second[i] = second[i + 1] =  W ;         continue;       }       bool foo = 1;       int to = -1;       for (int j = i + 1; j < n; j++)         if (second[j] == second[i]) {           to = j;           break;         }       for (int j = i + 1; j < to; j++)         if (second[j] == second[i]) foo = 0;       if (to == -1) foo = 0;       if (foo) {         for (int j = i; j < to; j++) {           vec.push_back(j);           second[j] =  W ;         }         second[to] =  W ;         continue;       }       ok = 0;       break;     }     if (ok) {       cout << (int)vec.size() << endl;       for (auto i : vec) cout << i + 1 <<    ;       cout << endl;       return 0;     }     ok = 1;     vec.clear();     second = t;     for (int i = 0; i < n; i++) {       if (second[i] ==  B ) continue;       if (i + 1 < n && second[i + 1] == second[i]) {         vec.push_back(i);         second[i] = second[i + 1] =  B ;         continue;       }       bool foo = 1;       int to = -1;       for (int j = i + 1; j < n; j++)         if (second[j] == second[i]) {           to = j;           break;         }       for (int j = i + 1; j < to; j++)         if (second[j] == second[i]) foo = 0;       if (to == -1) foo = 0;       if (foo) {         for (int j = i; j < to; j++) {           vec.push_back(j);           second[j] =  B ;         }         second[to] =  B ;         continue;       }       ok = 0;       break;     }     if (ok) {       cout << (int)vec.size() << endl;       for (auto i : vec) cout << i + 1 <<    ;       cout << endl;       return 0;     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   const int oo = 0x3f3f3f3f;   using namespace std;   inline int read() {     int x = 0, f = 1, hhh = getchar();     while (!isdigit(hhh)) {       if (hhh ==  - ) f = -1;       hhh = getchar();     }     while (isdigit(hhh)) {       x = x * 10 + hhh -  0 ;       hhh = getchar();     }     return x * f;   }   const int c[] = {0, 1, 2, 3, 4, 6, 12};   const int r[] = {0, 12, 6, 4, 3, 2, 1};   char a[100][100];   bool ans[10];   int main() {     int T = read();     while (T--) {       memset(a, 0, sizeof(a));       memset(ans, false, sizeof(ans));       string s;       cin >> s;       for (int cas = (1); cas <= (6); ++cas) {         int now = 0;         for (int i = (1); i <= (c[cas]); ++i)           for (int j = (1); j <= (r[cas]); ++j) {             a[i][j] = s[now++];           }         for (int i = (1); i <= (r[cas]); ++i) {           bool flag = false;           for (int j = (1); j <= (c[cas]); ++j) {             if (a[j][i] ==  O ) {               flag = true;               break;             }           }           if (!flag) {             ans[cas] = true;             break;           }         }       }       int ret = 0;       for (int i = (1); i <= (6); ++i) ret += (ans[i] == true);       printf( %d  , ret);       for (int i = (1); i <= (6); ++i)         if (ans[i] == true) printf( %dx%d  , c[i], r[i]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, oo = inf;   inline long long read() {     register long long x = 0, f = 1;     register char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return x * f;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     puts(  );   }   const int Mod = 1e9 + 7;   inline int ppow(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = 1ll * a * a % Mod)       if (b & 1) ans = 1ll * ans * a % Mod;     return ans;   }   const int maxnode = 323333;   struct ACautomto {     struct node {       int nxt[26], fail, v, end;     } T[maxnode];     int tot;     int front, rear, q[maxnode], root[22];     ACautomto() {       tot = 0;       memset(T, 0, sizeof(T));     }     inline void merge(int o1, int o2) {       T[o2].end |= T[o1].end;       for (register int i = (0); i < (26); ++i) {         if (!T[o1].nxt[i])           continue;         else if (!T[o2].nxt[i])           T[o2].nxt[i] = T[o1].nxt[i];         else           merge(T[o1].nxt[i], T[o2].nxt[i]);       }     }     inline void insert(int o, char s[]) {       for (int i = 0; s[i]; ++i) {         if (!T[o].nxt[s[i] -  a ]) T[o].nxt[s[i] -  a ] = ++tot;         o = T[o].nxt[s[i] -  a ];       }       ++T[o].end;     }     inline void build(int rt) {       int u, v, p;       front = rear = 0;       q[rear++] = rt;       while (front < rear) {         u = q[front++];         for (register int i = (0); i < (26); ++i)           if (T[u].nxt[i]) {             v = T[u].nxt[i], p = T[u].fail;             while (p && !T[p].nxt[i]) p = T[p].fail;             T[v].fail = p ? T[p].nxt[i] : rt;             T[v].v = T[v].end + T[T[v].fail].v;             q[rear++] = v;           }       }     }     inline int query(int rt, char s[]) {       int ans = 0, o = rt;       for (int i = 0; s[i]; ++i) {         while (o && !T[o].nxt[s[i] -  a ]) o = T[o].fail;         if (o == 0) o = rt;         o = T[o].nxt[s[i] -  a ];         ans += T[o].v;       }       return ans;     }     inline void add(char s[]) {       int rt = ++tot;       insert(rt, s);       for (int i = 0; i < 20; ++i) {         if (!root[i]) {           root[i] = rt;           build(root[i]);           return;         } else {           merge(root[i], rt);           root[i] = 0;         }       }     }     inline int get(char s[]) {       int ans = 0;       for (int i = 0; i < 20; ++i) ans += query(root[i], s);       return ans;     }   } add, del;   char s[300005];   int main() {     int T = read();     while (T--) {       int op = read();       scanf( %s , s);       if (op == 1) {         add.add(s);       } else if (op == 2) {         del.add(s);       } else {         writeln(add.get(s) - del.get(s));       }       fflush(stdout);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   struct sl {     int SC, LC, TS, TL;     double p;   } a[1005];   struct csl {     long double score, tim;   } f[1005][1561], ans;   double a1, a2, p;   int n, m, z, x, y;   inline bool cmp(sl x, sl y) {     return x.TL * x.p * (1 - y.p) < y.TL * y.p * (1 - x.p);   }   inline csl Max(csl x, int l, int k, int t) {     csl y;     y.score = y.tim = 0;     if (t == 1) {       y.score = f[l - 1][k - a[l].TS].score + a[l].SC;       y.tim = f[l - 1][k - a[l].TS].tim + a[l].TS;     } else {       y.score = f[l - 1][k - a[l].TS - a[l].TL].score + a[l].SC +                 a[l].LC * (1 - a[l].p);       y.tim = a[l].p * (f[l - 1][k - a[l].TS - a[l].TL].tim + a[l].TS) +               k * (1 - a[l].p);     }     if (x.score + eps < y.score ||         (abs(x.score - y.score) < eps && x.tim > y.tim))       return y;     else       return x;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d%d%d%d%lf , &a[i].SC, &a[i].LC, &a[i].TS, &a[i].TL, &a[i].p);     }     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= m; ++j) {         f[i][j] = f[i - 1][j];         if (j >= a[i].TS) f[i][j] = Max(f[i][j], i, j, 1);         if (j >= a[i].TS + a[i].TL) f[i][j] = Max(f[i][j], i, j, 2);       }     }     for (int i = 0; i <= m; ++i)       if (ans.score + eps < f[n][i].score ||           (abs(ans.score - f[n][i].score) < eps && ans.tim > f[n][i].tim))         ans = f[n][i];     printf( %.10lf %.10lf , (double)ans.score, (double)ans.tim);   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int maxn = 205;   int fail[maxn + 5];   int nxt[maxn + 5][maxn + 5];   long long dp[maxn + 5][maxn + 5][maxn + 5];   char s[maxn + 5];   int n, len;   void Get_fail() {     fail[0] = -1;     int j = 0, k = -1;     while (j <= len) {       if (k == -1 || s[j] == s[k])         fail[++j] = ++k;       else         k = fail[k];     }   }   void Get_nxt() {     for (int i = 0; i <= len; i++) {       for (int j = 0; j <= 1; j++) {         if (i == len)           nxt[i + 1][j] = len;         else {           char ch = (j == 0 ?  )  :  ( );           int r = i;           while (r >= 0 && s[r] != ch) r = fail[r];           if (s[r] == ch || r == -1) r++;           nxt[i + 1][j] = r;         }       }     }   }   long long DP() {     dp[0][0][0] = 1;     for (int i = 0; i <= 2 * n; i++) {       for (int j = 0; j <= min(i, n); j++) {         for (int k = 0; k <= len; k++) {           for (int p = 0; p <= 1; p++) {             if (dp[i][j][k] == 0) continue;             int nj = j - (p == 0 ? 1 : -1);             if (nj >= 0 && nj <= n) {               int nk = nxt[k + 1][p];               dp[i + 1][nj][nk] = (dp[i + 1][nj][nk] + dp[i][j][k]) % mod;             }           }         }       }     }     return dp[2 * n][0][len];   }   void Init() {     len = strlen(s);     Get_fail();     Get_nxt();   }   int main() {     scanf( %d , &n);     scanf( %s , s);     Init();     printf( %lld n , DP());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> rating;   void reading() {     cin >> N;     rating.resize(N);     for (int i = 0; i < N; i++) cin >> rating[i];   }   void processing() {     for (int i = 0; i < N; i++) {       int res = 0;       for (int j = 0; j < N; j++)         if (rating[i] < rating[j]) res++;       cout << res + 1 <<    ;     }   }   int main() {     reading();     processing();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXW = 1000000;   const int INF = 0x3f3f3f3f;   const int MOD = 1000000007;   const char test[] =  test n ;   int in();   int tr[100010];   int ls[100010];   int n, m, k;   int hav[100010];   int lowbit(int x) { return (-x) & x; }   void updata(int in, int val) {     while (in <= n) {       if (val > tr[in]) {         tr[in] = val;       }       in += lowbit(in);     }   }   int ask(int to) {     int mx = 0;     while (to) {       mx = max(mx, tr[to]);       to -= lowbit(to);     }     return mx;   }   int main() {     cin >> n >> m;     hav[1]++;     hav[m + 1]--;     for (int i = 0; i < n; ++i) {       int u, v;       cin >> u >> v;       hav[u]++;       hav[v + 1]--;     }     for (int i = 1; i <= m; ++i) {       hav[i] += hav[i - 1];       int val = ask(hav[i]) + 1;       updata(hav[i], val);       ls[i] = val;     }     memset(tr, 0, sizeof tr);     int ans = 0;     for (int i = m; i > 0; --i) {       int val = ask(hav[i]) + 1;       updata(hav[i], val);       ans = max(ans, ls[i] + val - 1);     }     cout << ans;     return 0;   }   int in() {     int input;     scanf( %d , &input);     return input;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &o, vector<T> &vec) {     cout <<  [ ;     for (int i = 0; i < ((int)(vec).size()); i++) {       if (i) cout <<  ,  ;       cout << vec[i];     }     cout <<  ] ;     return o;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &o, pair<T1, T2> &pair) {     cout <<  (  << pair.first <<  ,   << pair.second <<  ) ;     return o;   }   const long long MX = 312312;   const long long SQMX = 1000;   const long long MD = 1000000007;   long long N;   vector<long long> ip;   bool isp[MX];   vector<long long> prime;   long long sm[MX], tmp[MX];   long long C[MX];   long long fac[MX];   long long ps[MX];   long long fp(long long a, long long b) {     if (!b) return 1 % MD;     long long ret = fp(a * a % MD, b / 2);     if (b & 1) ret = ret * a % MD;     return ret;   }   inline long long rev(long long a) { return fp(a, MD - 2); }   void pre() {     fill(isp + 2, isp + MX, true);     for (long long i = 0; i < MX; i++) {       if (isp[i]) {         prime.push_back(i);         for (long long j = i + i; j < MX; j += i) {           isp[j] = false;         }       }     }     fac[0] = 1;     for (long long i = 1; i <= N - 1; i++) fac[i] = fac[i - 1] * i % MD;     for (long long i = 0; i <= N - 1; i++)       C[i] = fac[N - 1] * rev(fac[i]) % MD * rev(fac[N - i - 1]) % MD;     for (long long i = 0; i <= N - 1; i++) {       ps[i + 1] = ps[i] + C[i];     }   }   int32_t main() {     cin >> N;     pre();     ip.resize(N);     for (long long i = 0; i < N; i++) {       cin >> ip[i];     }     long long ans = 0;     for (long long i = 0; i < ((long long)(prime).size()); i++) {       long long p = prime[i];       if (p > SQMX) break;       fill(tmp, tmp + N, 0);       for (long long j = 0; j < N; j++) {         long long t = 0, &a = ip[j];         while (a % p == 0) {           a /= p;           t++;         }         tmp[j] = t;       }       sort(tmp, tmp + N);       for (long long j = 0; j < N; j++) sm[j] += tmp[j];     }     sort(ip.begin(), ip.end());     for (long long i = 0, j = 0; i < N; i = j) {       while (ip[j] == ip[i]) j++;       if (ip[i] == 1) continue;       long long c = j - i;       for (long long k = 0; k < c; k++) {         sm[N - k - 1]++;       }     }     for (long long j = 0; j < N; j++) {       long long f1 = ps[j] - ps[0], f2 = ps[N] - ps[j + 1];       long long f = f1 - f2;       f = (f + MD) % MD;       ans += f * sm[j];       ans %= MD;     }     cout << ans << endl;     return 0;   }