malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long modpow(long long x, long long y, long long m) {     long long z = 1;     while (y) {       if (y & 1) z = (z * x) % m;       x = (x * x) % m;       y >>= 1;     }     return z;   }   int egcd(int a, int b, int& x, int& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int x1, y1;     int gcd = egcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return gcd;   }   string z[2] = { NO ,  YES };   long long modinv(long long x, long long mod) { return modpow(x, mod - 2, mod); }   vector<int> pri(1.5e6 + 1), r;   vector<bool> done(1.5e6 + 1);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     int i, j, k, n, m;     string s;     while (t--) {       for (i = 2; i * i <= 1.5e6; ++i) {         if (pri[i]) continue;         pri[i] = i;         for (j = 2 * i; j <= 1.5e6; j += i)           if (!pri[j]) pri[j] = i;       }       k = 1;       for (i = 2; i <= 1.5e6; ++i) {         if (!pri[i]) pri[i] = i;         if (pri[i] == i) r.push_back(i);       }       cin >> n;       vector<int> a(n);       for (i = 0; i < n; ++i) cin >> a[i];       cout << a[0] <<    ;       j = a[0];       set<int> fc;       for (i = 2; i < 1.5e6 + 1; ++i) fc.insert(i);       while (j > 1) {         if (fc.count(pri[j])) {           for (k = pri[j]; k <= 1.5e6; k += pri[j]) fc.erase(k);           done[pri[j]] = 1;         }         j /= pri[j];       }       bool as = 1;       for (i = 1; i < n; ++i) {         j = 2;         if (as) j = a[i];         auto x = fc.lower_bound(j);         cout << *x <<    ;         if (*x != a[i]) as = 0;         k = *x;         while (k > 1) {           if (!done[pri[k]]) {             for (int p = pri[k]; p <= 1.5e6; p += pri[k]) fc.erase(p);             done[pri[k]] = 1;           }           k /= pri[k];         }       }     }     return 0;   }
#include <bits/stdc++.h>   void swap(int *a, int *b) {     int temp = *a;     *a = *b;     *b = temp;   }   int max(int a, int b) { return (a > b) ? a : b; }   int main() {     int t, n, k, a[1005], b[1005];     scanf( %d , &t);     while (t--) {       int total = 0;       scanf( %d %d , &n, &k);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         total += a[i];       }       for (int i = 0; i < n; i++) {         scanf( %d , &b[i]);       }       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           if (a[i] > a[j]) swap(&a[i], &a[j]);           if (b[i] < b[j]) swap(&b[i], &b[j]);         }       }       for (int i = 0; i < k; i++) {         total -= a[i];         total += max(a[i], b[i]);       }       printf( %d n , total);     }   }
#include <bits/stdc++.h>   using namespace std;   long long int j, k, n;   int main() {     long long int q;     string x, y;     map<string, string> m;     map<string, string>::iterator it;     cin >> q;     while (q--) {       cin >> x >> y;       if (m.count(x)) {         string z;         z = m[x];         m.erase(x);         m[y] = z;       } else {         m[y] = x;       }     }     cout << m.size() << endl;     for (it = m.begin(); it != m.end(); it++)       cout << it->second <<     << it->first << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[200010];   string s;   int main() {     int t, n;     cin >> t;     while (t--) {       cin >> n;       cin >> s;       for (int i = 0; i < n; i++) {         arr[i] = s[i] -  0 ;       }       int cur1, cur2, ans, ind;       for (int i = 0; i <= 10; i++) {         for (int j = 0; j < n; j++) {           if (arr[j] > i) {             ind = j;             break;           }         }         ans = i;         bool flag = 1;         cur1 = 0;         cur2 = 0;         for (int j = 0; j < n; j++) {           int look = arr[j];           if (look < i) {             if (look < cur1) {               flag = 0;             } else {               cur1 = look;             }           } else if (look > i) {             if (look < cur2) {               flag = 0;             } else {               cur2 = look;             }           } else {             if (j > ind) {               if (look < cur1) {                 flag = 0;               } else {                 cur1 = look;               }             }           }         }         if (flag == 1) {           break;         }       }       if (ans <= 9) {         for (int i = 0; i < n; i++) {           if (arr[i] < ans) {             cout <<  1 ;           } else if (arr[i] > ans) {             cout <<  2 ;           } else {             if (i < ind) {               cout <<  2 ;             } else {               cout <<  1 ;             }           }         }         cout << endl;       } else {         cout <<  -  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, dif, l;   int a[N], f[N], g[N];   deque<int> dmax, dmin, df;   void Push(int x) {     while (!dmax.empty() && a[dmax.back()] <= a[x]) dmax.pop_back();     dmax.push_back(x);     while (!dmin.empty() && a[dmin.back()] >= a[x]) dmin.pop_back();     dmin.push_back(x);   }   int main() {     cin >> n >> dif >> l;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int c = 1;     for (int i = 1; i <= n; i++) {       Push(i);       while (c <= i && a[dmax.front()] - a[dmin.front()] > dif) {         if (dmax.front() == c) dmax.pop_front();         if (dmin.front() == c) dmin.pop_front();         if (!df.empty() && df.front() == c - 1) df.pop_front();         c++;       }       if (i - l >= c - 1 && f[i - l] != 1e9) {         while (!df.empty() && f[i - l] < f[df.back()]) df.pop_back();         df.push_back(i - l);       }       if (df.empty())         f[i] = 1e9;       else         f[i] = f[df.front()] + 1;     }     if (f[n] == 1e9)       cout << -1;     else       cout << f[n];   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target( avx,avx2 )   using namespace std;   const long double eps = 1e-6;   long double inf = 0;   const long long mod = 1e9 + 7;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int count_dels(long long m) {     int c = 0;     for (long long i = 1; i * i <= m; ++i) {       if (m % i != 0) continue;       ++c;       if (i != m / i) ++c;     }     return c;   }   int main() {     cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       long long a, m;       cin >> a >> m;       long long d = gcd(a, m);       long long m1 = m / d;       long long ans = m1;       for (long long i = 2; i * i <= m1; ++i) {         if (m1 % i == 0) {           ans -= ans / i;           while (m1 % i == 0) m1 /= i;         }       }       if (m1 != 1) ans -= ans / m1;       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A[50];   int main() {     long long n;     A[0] = A[1] = 1;     scanf( %lld , &n);     for (long long i = 1; i <= 50; ++i) {       A[i] = A[i - 1] * i;     }     long long ans = A[n] / A[n / 2] / A[n / 2] / 2;     ans *= A[n / 2 - 1] * A[n / 2 - 1];     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0;     char ch = getchar();     bool f = 0;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = 1;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return f ? -x : x;   }   void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(long long x) {     write(x);     puts(  );   }   void writep(long long x) {     write(x);     putchar(   );   }   const int N = 5e5 + 5, mo = 1e9 + 7;   int n, m, a[N], fac[N], inv[N], b[N];   char s[N];   int C(int n, int m) {     if (n < m) return 0;     return (long long)fac[n] * inv[m] % mo * inv[n - m] % mo;   }   int ksm(int x, int p) {     int res = 1;     for (; p; p >>= 1, x = (long long)x * x % mo)       if (p & 1) res = (long long)res * x % mo;     return res;   }   void init(int n) {     fac[0] = 1;     for (int i = (int)(1); i <= (int)(n); i++)       fac[i] = (long long)i * fac[i - 1] % mo;     inv[n] = ksm(fac[n], mo - 2);     for (int i = (int)(n - 1); i >= (int)(0); i--)       inv[i] = (long long)(i + 1) * inv[i + 1] % mo;   }   int upd(int x, int y) {     x += y;     if (x >= mo) x -= mo;     return x;   }   int main() {     init(N - 1);     n = read();     m = read();     scanf( %s , s + 1);     for (int i = (int)(1); i <= (int)(n); i++) a[i] = s[i] -  0 ;     reverse(a + 1, a + n + 1);     int sum = 0, now = 1;     b[1] = C(n - 1, m);     for (int i = (int)(2); i <= (int)(n); i++) {       sum = upd(sum, (long long)now * C(n - i, m - 1) % mo);       now = (long long)10 * now % mo;       b[i] = upd(sum, (long long)now * C(n - i, m) % mo);     }     int ans = 0;     for (int i = (int)(1); i <= (int)(n); i++)       ans = upd(ans, (long long)b[i] * a[i] % mo);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int N;   string S;   void precompute() {     int cur = 1;     while ((int)S.size() <= 1000) {       int x = cur++;       string tmp;       while (x > 0) {         tmp.push_back(x % 10 +  0 );         x /= 10;       }       for (int i = (int)tmp.size() - 1; i >= 0; i--) S.push_back(tmp[i]);     }   }   int main() {     precompute();     scanf( %d , &N);     printf( %c n , S[N - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   const long long mod = 1000000000 + 7;   struct node {     int l, r;     mutable long long v;     node(int L, int R = -1, long long v = 0) : l(L), r(R), v(v){};     bool operator<(const node &x) const { return l < x.l; }   };   long long quick(long long a, long long n, long long p) {     a %= p;     long long ans = 1;     while (n) {       if (n & 1) ans = ans * a % p;       a = a * a % p;       n >>= 1;     }     return ans;   }   set<node> s;   set<node>::iterator spilt(int pos) {     set<node>::iterator it = s.lower_bound(node(pos));     if (it != s.end() && it->l == pos) return it;     it--;     int R = it->r, L = it->l;     long long V = it->v;     s.erase(it);     s.insert(node(L, pos - 1, V));     return s.insert(node(pos, R, V)).first;   }   void assign_val(int l, int r, long long val) {     set<node>::iterator itr = spilt(r + 1), itl = spilt(l);     s.erase(itl, itr);     s.insert(node(l, r, val));   }   void add(int l, int r, long long val) {     set<node>::iterator itr = spilt(r + 1), itl = spilt(l);     for (; itl != itr; itl++) itl->v += val;   }   long long ranks(int l, int r, int k) {     vector<pair<long long, int> > vp;     set<node>::iterator itr = spilt(r + 1), itl = spilt(l);     for (; itl != itr; itl++) {       vp.push_back({itl->v, itl->r - itl->l + 1});     }     sort(vp.begin(), vp.end());     for (int i = 0; i < vp.size(); i++) {       k -= vp[i].second;       if (k <= 0) return vp[i].first;     }   }   long long sum(int l, int r, int ex, long long p) {     set<node>::iterator itr = spilt(r + 1), itl = spilt(l);     long long ret = 0;     for (; itl != itr; itl++) {       ret += 1ll * (itl->r - itl->l + 1) * quick(itl->v, ex, p) % p;       ret %= p;     }     return ret;   }   int n, m;   long long seed, vmax, a[maxn];   long long rnd() {     long long ret = seed;     seed = (seed * 7 + 13) % mod;     return ret;   }   int main() {     cin >> n >> m >> seed >> vmax;     for (int i = 1; i <= n; i++) {       a[i] = (rnd() % vmax) + 1;       s.insert(node(i, i, a[i]));     }     s.insert(node(n + 1, n + 1, 0));     int x, y;     for (int i = 1; i <= m; i++) {       int op = int(rnd() % 4) + 1;       int l = int(rnd() % n) + 1;       int r = int(rnd() % n) + 1;       if (l > r) swap(l, r);       if (op == 3)         x = int(rnd() % (r - l + 1)) + 1;       else         x = int(rnd() % vmax) + 1;       if (op == 4) y = int(rnd() % vmax) + 1;       if (op == 1)         add(l, r, x);       else if (op == 2)         assign_val(l, r, x);       else if (op == 3)         cout << ranks(l, r, x) << endl;       else         cout << sum(l, r, x, y) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long double V;   long double vx[111111], vy[111111];   int m, N;   struct point {     long double x, y;     bool operator<(const point &b) const {       return (x != b.x) ? (x < b.x) : (y > b.y);     }   } ans[111111], a[111111];   pair<long double, int> k[111111], b[111111], c[111111];   long double cs[111111];   int main() {     double V2;     scanf( %d%lf , &n, &V2);     V = V2;     for (int i = 1; i <= n; ++i) {       double ang;       scanf( %lf , &ang);       long double t = ang;       long double x = cos(t) * V * sin(t) * V / (0.5 * (9.8));       ans[i].x = x;       ans[i].y = 0;       k[i] = make_pair(tan(ang), i);     }     scanf( %d , &m);     long double mn = 1e9;     int arc = 0;     for (int i = 1; i <= m; ++i) {       double x, y;       scanf( %lf%lf , &x, &y);       a[i].x = x;       a[i].y = y;       long double A = 0.5 * (9.8) * x * x;       long double B = -x * V * V;       long double C = 0.5 * x * x * (9.8) + y * V * V;       long double D = B * B - 4 * A * C;       if (D < 0) {         if (x < mn) {           mn = x;           arc = i;         }       } else {         b[++N] = make_pair((sqrt(D) - B) / 2 / A, i);         c[N] = make_pair((-sqrt(D) - B) / 2 / A, i);       }     }     sort(k + 1, k + 1 + n);     sort(b + 1, b + 1 + N);     int j = 0;     long double mn2 = mn;     for (int i = 1; i <= n; ++i) {       for (; j < N && b[j + 1].first <= k[i].first;) {         ++j;         mn = min(a[b[j].second].x, mn);       }       int pos = k[i].second;       if (mn < ans[pos].x) {         ans[pos].x = mn;         ans[pos].y = mn * k[i].first - 0.5 * (9.8) * mn * mn *                                            (1 + k[i].first * k[i].first) / V / V;       }     }     sort(c + 1, c + 1 + N);     j = N + 1;     mn = mn2;     for (int i = n; i >= 1; --i) {       for (; j > 1 && c[j - 1].first >= k[i].first;)         mn = min(a[c[--j].second].x, mn);       int pos = k[i].second;       if (mn < ans[pos].x) {         ans[pos].x = mn;         ans[pos].y = mn * k[i].first - 0.5 * (9.8) * mn * mn *                                            (1 + k[i].first * k[i].first) / V / V;       }     }     for (int i = 1; i <= n; ++i) {       double x = ans[i].x, y = ans[i].y;       printf( %lf %lf n , x, y);     }   }
#include <bits/stdc++.h>   using namespace std;   void OJ() {}   void solve() {     string s;     cin >> s;     string temp =   ;     int alice = 0, flag = 0, l;     while (1) {       int cnt = 0, mx_cnt = 0, mx_l = -1, mx_r = -1, d_l = -1;       l = s.size();       for (int i = 0; i < l; i++) {         if (s[i] ==  0 )           cnt = 0;         else if (cnt == 0) {           d_l = i;           cnt++;         } else           cnt++;         if (cnt > mx_cnt) {           mx_cnt = cnt;           mx_l = d_l;           mx_r = i;         }       }       if (mx_l == -1) break;       temp =   ;       for (int i = 0; i < l; i++) {         if (i >= mx_l && i <= mx_r) continue;         temp += s[i];       }       s = temp;       if (!flag) alice += mx_cnt;       flag = !flag;     }     cout << alice <<   n ;   }   int main() {     OJ();     int tc = 1;     cin >> tc;     while (tc--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     getline(cin, s);     for (int i = 0; i <= s.length() - 1; i++) {       if (s[i] ==  .  && s[i - 1] ==  9 ) {         cout <<  GOTO Vasilisa. ;         return 0;       }       if (s[i] ==  .  && s[i + 1] <  5 ) {         for (int j = 0; j <= i - 1; j++) cout << s[j];       }       if (s[i] ==  .  && s[i + 1] >=  5 ) {         for (int j = 0; j <= i - 2; j++) cout << s[j];         cout << char(s[i - 1] + 1);       }     }     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   struct node {     int ch[27], len, fa;   } dian[N];   struct edge {     int v, nxt;   } e[N];   int n, q, head[N], cnt, las = 1, tot = 1, fl[N], pos[N], ot, x, m, ans;   char s[N], t[N];   void ad(int u, int v) {     e[++cnt].v = v;     e[cnt].nxt = head[u];     head[u] = cnt;   }   void add(int c, int id) {     int np = ++tot, p = las;     fl[np] = id;     dian[np].len = dian[p].len + 1;     for (; p && !dian[p].ch[c]; p = dian[p].fa) dian[p].ch[c] = np;     if (!p)       dian[np].fa = 1;     else {       int q = dian[p].ch[c];       if (dian[q].len == dian[p].len + 1)         dian[np].fa = q;       else {         int nq = ++tot;         dian[nq] = dian[q];         dian[nq].len = dian[p].len + 1;         for (; p && dian[p].ch[c] == q; p = dian[p].fa) dian[p].ch[c] = nq;         dian[np].fa = nq;         dian[q].fa = nq;       }     }     las = np;   }   void dfs(int u) {     if (fl[u]) pos[++ot] = fl[u];     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].v;       dfs(v);     }   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++) {       add(s[i] -  a , i);     }     for (int i = 2; i <= tot; i++) {       ad(dian[i].fa, i);     }     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %d , &x);       scanf( %s , t + 1);       ot = 0;       m = strlen(t + 1);       int u = 1, f = 0;       for (int j = 1; j <= m; j++) {         int to = t[j] -  a ;         u = dian[u].ch[to];         if (!u) {           f = 1;           break;         }       }       if (f) {         printf( -1 n );         continue;       }       dfs(u);       sort(pos + 1, pos + 1 + ot);       ans = 999999999;       for (int j = x; j <= ot; j++) {         ans = min(ans, pos[j] - (pos[j - x + 1] - m + 1) + 1);       }       if (ans == 999999999) {         printf( -1 n );         continue;       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long MOD = 998244353;   template <class T>   inline void chmax(T &a, const T &b) {     if ((a) < (b)) (a) = (b);   }   template <class T>   inline void chmin(T &a, const T &b) {     if ((a) > (b)) (a) = (b);   }   template <typename T>   using PQ = priority_queue<T, vector<T>, greater<T>>;   struct Fast {     Fast() {       std::cin.tie(0);       ios::sync_with_stdio(false);     }   } fast;   long long solve() {     long long n;     cin >> n;     vector<string> a(n);     vector<long long> dcnt(11, 0);     for (long long i = (long long)(0); i < (long long)(n); ++i) {       cin >> a[i];       dcnt[((long long)(a[i]).size())]++;     }     42;     42;     auto f = [&](string s, long long d) {       long long m = ((long long)(s).size());       long long res = 0;       long long mul = 1;       long long cnt = 0;       for (long long i = (long long)((m)-1); i >= (long long)(0); --i) {         long long x = s[i] -  0 ;         res += mul * x;         if (cnt < d) {           mul *= 100;         } else {           mul *= 10;         }         mul %= MOD;         res %= MOD;         cnt++;       }       return res;     };     42;     auto g = [&](string s, long long d) {       long long m = ((long long)(s).size());       long long res = 0;       long long mul = 10;       long long cnt = 0;       for (long long i = (long long)((m)-1); i >= (long long)(0); --i) {         long long x = s[i] -  0 ;         res += mul * x;         if (cnt < d - 1) {           mul *= 100;         } else {           mul *= 10;         }         mul %= MOD;         res %= MOD;         cnt++;       }       return res;     };     42;     long long ans = 0;     for (long long i = (long long)(0); i < (long long)(n); ++i) {       for (long long d = (long long)(1); d < (long long)(11); ++d) {         ans += f(a[i], d) * dcnt[d];         ans += g(a[i], d) * dcnt[d];         ans %= MOD;       }     }     cout << ans << endl;     return 0;   }   signed main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7;   const int M = 2e6 + 7;   long long g[M], q[M];   int n, a[N];   void push(int v, int lr, int rl) {     g[v << 1] += q[v];     g[v << 1 | 1] += q[v];     q[v << 1] += q[v];     q[v << 1 | 1] += q[v];     q[v] = 0;   }   void upd1(int v, int lr, int rl, int l, int x) {     if ((lr & rl) == l) {       g[v] += x;       return;     }     push(v, lr, rl);     int m = (lr + rl) >> 1;     if (l <= m)       upd1(v << 1, lr, m, l, x);     else       upd1(v << 1 | 1, m + 1, rl, l, x);     g[v] = max(g[v << 1], g[v << 1 | 1]);   }   void upd2(int v, int lr, int rl, int l, int r, int x) {     if (l > r) return;     if (lr == l && rl == r) {       q[v] += x;       g[v] += x;       push(v, lr, rl);       return;     }     push(v, lr, rl);     int m = (lr + rl) >> 1;     upd2(v << 1, lr, m, l, min(m, r), x);     upd2(v << 1 | 1, m + 1, rl, max(l, m + 1), r, x);     g[v] = max(g[v << 1], g[v << 1 | 1]);   }   int get(int v, int lr, int rl) {     if (g[v] < 0) return -1;     push(v, lr, rl);     if (lr == rl) return (g[v] ? -1 : lr);     int m = (lr + rl) >> 1;     int first = get(v << 1, lr, m);     int second = get(v << 1 | 1, m + 1, rl);     g[v] = max(g[v << 1], g[v << 1 | 1]);     return max(first, second);   }   int main() {     int w, z = 1;     scanf( %d %d , &n, &w);     while (z < n) z <<= 1;     long long sum = 0;     memset(g, (-1000000000000000007), sizeof(g));     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       g[z - 1 + i] = a[i] - sum;       sum += a[i];     }     for (int i = z - 1; i; --i) g[i] = max(g[i << 1], g[i << 1 | 1]);     for (int i = 0, x, y; i < w; ++i) {       scanf( %d %d , &x, &y);       upd1(1, 1, z, x, y - a[x]);       upd2(1, 1, z, x + 1, n, a[x] - y);       a[x] = y;       printf( %d n , get(1, 1, z));     }     return 0;   }
/*─────────▄▄▄▄▄▄▄▄▄▄▄▄▄   ────────▄▀▀─────────────▀▀▄   ───────█───────────────────█   ──────█─────────────────────█   ─────█───▄▄▄▄▄▄▄───▄▄▄▄▄▄▄───█   ────█───█████████─█████████───█   ────█──██▀────▀█████▀────▀██──█   ───██████───█▀█─███───█▀█─██████   ───██████───▀▀▀─███───▀▀▀─██████   ────█──▀█▄────▄██─██▄────▄█▀──█   ────█────▀█████▀───▀█████▀────█   ────█───────────────▄▄▄───────█   ────█───────▄▄▄▄██▀▀█▀▀█▄─────█   ────█─────▄██▄█▄▄█▄▄█▄▄██▄────█   ────█─────▀▀█████████████▀────█   ───▐▓▓▌─────────────────────▐▓▓▌   ───▐▐▓▓▌▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▐▓▓▌▌   ───█══▐▓▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄▓▌══█   ──█══▌═▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌═▐══█   ──█══█═▐▓▓▓▓▓▓▄▄▄▄▄▄▄▓▓▓▓▓▓▌═█══█   ──█══█═▐▓▓▓▓▓▓▐██▀██▌▓▓▓▓▓▓▌═█══█   ──█══█═▐▓▓▓▓▓▓▓▀▀▀▀▀▓▓▓▓▓▓▓▌═█══█       ──█───█─█──█─█▀▀█─▀▀█▀▀─▀█─█─▀█──   ──█▄█▄█─█▀▀█─█▄▄█───█───█▀─▀─█▀──   ───▀─▀──▀──▀─▀──▀───▀───▄──▄─▄───                 TAKE LOVE AND PRAY FOR ME :) :) :)       */           #include<bits/stdc++.h>   using namespace std;   #define ull unsigned long long   #define ll long long   #define deciset(x) cout <<setprecision(x) <<fixed;   #define pb push_back   #define mp make_pair   #define PI 2*acos(0.0)   #define boost ios::sync_with_stdio(false);cin.tie(0)      int main()   {      boost;      ll t;      cin>>t;      while(t--)      {          ll a,b;          cin>>a>>b;        char arr[a][b];        ll brr[a][b];        for(int i=0;i<a;i++)         for(int j=0;j<b;j++) { cin>>arr[i][j]; brr[i][j]=0; }        int x=1;        for(int i=0;i<a;i++)        for(int j=0;j<b;j++)        {            if(arr[i][j]== * ) brr[i][j]=x;           else if(arr[i][j]== .  && arr[i][j-1]== *  && j>0) x++;        }        ll ans=0;        for(int i=0;i<a;i++)        for(int j=0;j<b;j++)        {            if(arr[i][j]== * ){                        ll kk=1,h=1;                for(ll k=i+1;k<a;k++){                    if(arr[k][j]== *  && brr[k][j+kk]!=0 && brr[k][j-kk]==brr[k][j+kk] && j-kk>=0 && j+kk<b )                      {                             h++;                          kk++;                      }                      else break;                                    }                ans+=h;            }        }        cout<<ans<<endl;      }                                  }