malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 520;   int dp[maxn][maxn];   char mp[maxn][maxn];   int h, w, q;   int main() {     cin >> h >> w;     for (int i = 1; i <= h; i++)       for (int j = 1; j <= w; j++) cin >> mp[i][j];     for (int i = 2; i <= w; i++) {       if (mp[1][i] ==  .  && mp[1][i - 1] ==  . )         dp[1][i] = dp[1][i - 1] + 1;       else         dp[1][i] = dp[1][i - 1];     }     for (int i = 2; i <= h; i++) {       if (mp[i][1] ==  .  && mp[i - 1][1] ==  . )         dp[i][1] = dp[i - 1][1] + 1;       else         dp[i][1] = dp[i - 1][1];     }     for (int i = 2; i <= h; i++) {       for (int j = 2; j <= w; j++) {         dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];         if (mp[i][j] ==  .  && mp[i - 1][j] ==  . ) dp[i][j]++;         if (mp[i][j] ==  .  && mp[i][j - 1] ==  . ) dp[i][j]++;       }     }     cin >> q;     int x1, y1, x2, y2;     for (int k = 0; k < q; k++) {       cin >> x1 >> y1 >> x2 >> y2;       int res = 0;       res = dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1];       if (x1 > 1) {         for (int i = y2; i >= y1; i--)           if (mp[x1][i] ==  .  && mp[x1 - 1][i] ==  . ) res--;       }       if (y1 > 1) {         for (int i = x2; i >= x1; i--)           if (mp[i][y1] ==  .  && mp[i][y1 - 1] ==  . ) res--;       }       cout << res << endl;     }     return ~~(0 - 0);   }
#include <bits/stdc++.h>   int a[30][2 * 100000 + 5], cnt[30];   char s[2 * 100000 + 5], t[2 * 100000 + 5];   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   int main() {     long long i, j, n, len, m, maxn;     scanf( %lld , &n);     scanf( %s , s);     for (i = 0; i < n; i++) {       cnt[s[i] -  a ]++;       a[s[i] -  a ][cnt[s[i] -  a ]] = i;     }     scanf( %lld , &m);     while (m--) {       memset(cnt, 0, sizeof(cnt));       scanf( %s , t);       len = strlen(t);       maxn = 0;       for (i = 0; i < len; i++) {         maxn = max(maxn, a[t[i] -  a ][cnt[t[i] -  a ] + 1] + 1);         cnt[t[i] -  a ]++;       }       printf( %lld n , maxn);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, a, b, c, d, t, input;     vector<int> vi;     for (i = 1; i <= 370; i++) {       t = i;       if (t <= 9) {         vi.push_back(t);       } else if (t >= 10 && t < 100) {         a = t % 10;         t = t / 10;         b = t;         vi.push_back(b);         vi.push_back(a);       } else if (t >= 100 && t < 1000) {         c = t % 10;         t = t / 10;         b = t % 10;         t = t / 10;         a = t;         vi.push_back(a);         vi.push_back(b);         vi.push_back(c);       } else if (t >= 1000) {         d = t % 10;         t /= 10;         c = t % 10;         t /= 10;         b = t % 10;         t /= 10;         a = t % 10;         vi.push_back(a);         vi.push_back(b);         vi.push_back(c);         vi.push_back(d);       }     }     while (cin >> input) {       cout << vi[input - 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class DFS {     int N_, R_;     vector<vector<int> > G_;     vector<int> par_, dep_, dep_sub_;     void DFS_internal(int v) {       dep_sub_[v] = 0;       for (auto u : G_[v])         if (par_[u] == -1) {           par_[u] = v;           dep_[u] = dep_[v] + 1;           DFS_internal(u);           dep_sub_[v] = max(dep_sub_[v], dep_sub_[u] + 1);         }     }       public:     DFS(vector<vector<int> >& G, int R) : N_(G.size()), R_(R), G_(G) {       par_.resize(N_, -1);       dep_.resize(N_);       dep_sub_.resize(N_);       par_[R_] = R_;       dep_[R_] = 0;       DFS_internal(R_);     }     int max_dep_id() {       int ret = -1, max_dep = -1;       for (int i = 0; i < N_; i++)         if (max_dep < dep_[i]) {           max_dep = dep_[i];           ret = i;         }       return ret;     }     int dep(int v) { return dep_[v]; }     int par(int v) { return par_[v]; }     int dep_subtree(int v) { return dep_sub_[v]; }   };   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int N, K;     cin >> N >> K;     vector<vector<int> > G(N);     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       G[--u].push_back(--v);       G[v].push_back(u);     }     DFS DFS0(G, 0);     int R1 = DFS0.max_dep_id();     DFS DFS1(G, R1);     int R2 = DFS1.max_dep_id();     DFS DFS2(G, R2);     int D = DFS1.dep(R2);     if (K == 2) {       cout <<  Yes n ;       for (int i = 0; i < N; i++)         cout << DFS1.dep(i) % 2 + 1 << ((i == N - 1) ?   n  :    );       return 0;     }     vector<int> ans(N);     for (int i = 0; i < N; i++) {       if (DFS1.dep(i) + DFS2.dep(i) - D == 0) {         ans[i] = DFS1.dep(i) % K + 1;         continue;       }       int d1 = DFS1.dep_subtree(i) + DFS1.dep(i);       int d2 = DFS1.dep_subtree(i) + DFS2.dep(i);       if (min(d1, d2) >= K - 1) {         cout <<  No n ;         return 0;       }       if (max(d1, d2) < K - 1) {         ans[i] = 1;         continue;       }       if (d1 > d2)         ans[i] = DFS1.dep(i) % K + 1;       else         ans[i] = (D + K - DFS2.dep(i) % K) % K + 1;     }     cout <<  Yes n ;     for (int i = 0; i < N; i++) cout << ans[i] << ((i == N - 1) ?   n  :    );   }
#include <bits/stdc++.h>   #define ll long long    #define INF INT_MAX   #define pii pair<int,int>   using namespace std;      const int maxn=1e3+10;   const int mod=998244353;   int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       ll N,K;       cin>>N>>K;       vector<vector<ll>> p(maxn);       vector<ll> s1(maxn,0);       vector<ll> s2(maxn,0);       ll tem;       for(int i=0;i<K;i++){           for(int j=0;j<N;j++){               cin>>tem;               p[i].push_back(tem);               s1[i]+=tem;               s2[i]+=(tem*tem);           }       }       map<ll,ll> cnt;       map<ll,ll> cnt2;       ll tem2;          for(int i=1;i<=6;i++){           tem=s1[i]-s1[i-1];           tem2=s2[i-1]+s2[i+1]-2*s2[i];           if(cnt.find(tem)==cnt.end()){               cnt[tem]=0;           }           else               cnt[tem]++;           if(i!=6){               if(cnt2.find(tem2)==cnt2.end()){                   cnt2[tem2]=0;               }               else                   cnt2[tem2]++;           }       }       ll d,sq;       auto it=cnt.begin();       if(it->second>=3)       d=it->first;       else{           it++;           d=it->first;       }       auto it2=cnt2.begin();       if(it2->second>=2)       sq=it2->first;       else{           it2++;           sq=it2->first;       }       //cout<<sq<<  n ;       ll er;       for(int i=0;i<K-1;i++){           if(s1[i+1]-s1[i]!=d){               er=i+1;               break;           }       }       if(er==1 && s1[2]-s1[1]==d){           er=0;       }       ll dif,dif2;       tem=0;       for(int i=0;i<N;i++){           tem+=(p[er][i]*p[er][i]);       }       //cout<<tem<<  n ;       if(er==0)       dif=s1[er+1]-d-s1[er];       else       dif=s1[er-1]+d-s1[er];       //cout<<dif<<  n ;       ll ans=0;       for(int i=0;i<N;i++){           if(er<=K-3){               if(s2[er+2]-2*s2[er+1]+s2[er]-p[er][i]*p[er][i]+(p[er][i]+dif)*(p[er][i]+dif)==sq){                   ans=p[er][i]+dif;                   break;               }           }           else{               if(s2[er-2]-2*s2[er-1]+s2[er]-p[er][i]*p[er][i]+(p[er][i]+dif)*(p[er][i]+dif)==sq){                   ans=p[er][i]+dif;                   break;               }           }       }       cout<<er<<   <<ans<<  n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   struct T {     int a, b, i;     T() {}     T(int a, int b, int i) : a(a), b(b), i(i) {}     bool operator<(const T &other) const { return a > other.a; }   };   const int inf = 1e9;   int n, m, k, dp[N][N], f[N][N];   T a[N];   vector<int> ga, gb;   int fsolve(int i, int j) {     if (f[i][j] != -1) return f[i][j];     if (i > n) {       if (j == k)         f[i][j] = 0;       else         f[i][j] = -inf;       return f[i][j];     }     f[i][j] = fsolve(i + 1, j);     if (j < k) f[i][j] = max(f[i][j], fsolve(i + 1, j + 1) + a[i].b);     if (f[i][j] < 0) f[i][j] = -inf;     return f[i][j];   }   int solve(int i, int j) {     if (dp[i][j] != -1) return dp[i][j];     if (i > n) {       if (j == m)         dp[i][j] = 0;       else         dp[i][j] = -inf;       return dp[i][j];     }     int p = i - 1 - j;     if (j == m) {       dp[i][j] = fsolve(i, p);       return dp[i][j];     }     dp[i][j] = solve(i + 1, j + 1) + a[i].a;     if (p != k) dp[i][j] = max(dp[i][j], solve(i + 1, j) + a[i].b);     if (dp[i][j] < 0) dp[i][j] = -inf;     return dp[i][j];   }   void fsolve1(int i, int j) {     if (i > n) {       return;     }     if (f[i][j] == f[i + 1][j])       fsolve1(i + 1, j);     else {       gb.push_back(a[i].i);       fsolve1(i + 1, j + 1);     }   }   void solve1(int i, int j) {     if (i > n) {       return;     }     int p = i - 1 - j;     if (j == m) {       fsolve1(i, p);       return;     }     if (dp[i][j] == dp[i + 1][j + 1] + a[i].a) {       ga.push_back(a[i].i);       solve1(i + 1, j + 1);     } else {       gb.push_back(a[i].i);       solve1(i + 1, j);     }   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> a[i].a;     for (int i = 1; i <= n; i++) cin >> a[i].b;     for (int i = 1; i <= n; i++) a[i].i = i;     sort(a + 1, a + n + 1);     memset(f, -1, sizeof(f));     memset(dp, -1, sizeof(dp));     cout << solve(1, 0) << endl;     solve1(1, 0);     for (int i = 0; i < ga.size(); i++) cout << ga[i] <<    ;     cout << endl;     for (int i = 0; i < gb.size(); i++) cout << gb[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1001][3] = {0};   int b[1001] = {0};   int c[1001] = {0};   vector<int> a1, a2, a3;   int main() {     int n, m, i, x, y, z;     int ans, t = 0;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d%d , &x, &y, &z);       a[x][0] = y;       a[x][1] = z;       b[x]++;       c[y]++;     }     for (i = 1; i <= n; i++) {       if (b[i] == 1 && c[i] == 0) {         x = i;         ans = 1000001;         do {           if (a[x][0] > 0) {             ans = min(ans, a[x][1]);             x = a[x][0];           } else             break;         } while (1);         a1.push_back(i);         a2.push_back(x);         a3.push_back(ans);       }     }     printf( %d n , a1.size());     for (i = 0; i < a1.size(); i++) printf( %d %d %d n , a1[i], a2[i], a3[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, i, j, total, cnt;     cin >> n >> k;     double r, g, b;     r = ceil((n * 2.0) / k);     g = ceil((n * 5.0) / k);     b = ceil((n * 8.0) / k);     cout << int(r + g + b) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x6fffffff;   const int MINF = 0x80000000;   const int mod = 1000000007;   const int cons = 100001;   const double pi = 3.141592653589793;   int dy2[2] = {1, 0};   int dx2[2] = {0, -1};   int dy1[2] = {0, 1};   int dx1[2] = {1, 0};   int n, m;   int main() {     vector<vector<bool> > M;     vector<vector<int> > km, lm;     scanf( %d%d , &n, &m);     M.resize(n + 1, vector<bool>(m + 1, false));     km.resize(n + 1, vector<int>(m + 1, -1));     lm.resize(n + 1, vector<int>(m + 1, -1));     vector<pair<int, int> > pos[10005];     queue<pair<int, int> > qu;     qu.push(make_pair(1, 1));     km[1][1] = 2;     pos[2].push_back(make_pair(1, 1));     while (!qu.empty()) {       int y = qu.front().first;       int x = qu.front().second;       qu.pop();       for (int i = 0; i < 2; i++) {         int ty = y + dy1[i];         int tx = x + dx1[i];         if (ty < 1 || ty > n || tx < 1 || tx > m) continue;         if (km[ty][tx] != -1) continue;         km[ty][tx] = km[y][x] + 1;         pos[km[ty][tx]].push_back(make_pair(ty, tx));         qu.push(make_pair(ty, tx));       }     }     qu.push(make_pair(1, m));     lm[1][m] = 2;     while (!qu.empty()) {       int y = qu.front().first;       int x = qu.front().second;       qu.pop();       for (int i = 0; i < 2; i++) {         int ty = y + dy2[i];         int tx = x + dx2[i];         if (ty < 1 || ty > n || tx < 1 || tx > m) continue;         if (lm[ty][tx] != -1) continue;         lm[ty][tx] = lm[y][x] + 1;         qu.push(make_pair(ty, tx));       }     }     map<int, int> K, L;     int k;     scanf( %d , &k);     for (int i = 1; i <= k; i++) {       int x;       scanf( %d , &x);       K[x]++;     }     int l;     scanf( %d , &l);     for (int i = k + 1; i <= l + k; i++) {       int x;       scanf( %d , &x);       L[x]++;     }     for (int i = n + m; i >= 2; i--) {       for (int j = 0; j < pos[i].size(); j++) {         int y = pos[i][j].first;         int x = pos[i][j].second;         int lvl = lm[y][x];         auto it = K.lower_bound(i);         auto it2 = L.lower_bound(lvl);         if (it == K.end() && it2 == L.end()) {           puts( NO );           return 0;         } else if (it == K.end()) {           it2->second--;           if (it2->second == 0) {             L.erase(it2);           }         } else if (it2 == L.end()) {           it->second--;           if (it->second == 0) {             K.erase(it);           }         } else {           it2->second--;           if (it2->second == 0) {             L.erase(it2);           }         }       }     }     puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long dx[4] = {-1, 0, 1, 0};   const long long dy[4] = {0, -1, 0, 1};   const long long dxx[] = {1, 1, 0, -1, -1, -1, 0, 1};   const long long dyy[] = {0, 1, 1, 1, 0, -1, -1, -1};   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long modexpo(long long x, long long n, long long M) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return modexpo((x * x) % M, n / 2, M);     else       return (x * modexpo((x * x) % M, (n - 1) / 2, M)) % M;   }   long long bexpo(long long x, long long n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return bexpo(x * x, n / 2);     else       return x * bexpo(x * x, (n - 1) / 2);   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   const long long mod = 1e9 + 7;   const long long N = 4e5 + 5;   const long long INF = 1e18;   void solve() {     long long n;     cin >> n;     ;     string second;     cin >> second;     vector<long long> a;     for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n)))       a.push_back(second[i] -  0 );     long long sum = 0;     for (__typeof(n - 1) k = (0) - ((0) > (n - 1));          k != (n - 1) - ((0) > (n - 1)); k += 1 - 2 * ((0) > (n - 1))) {       sum += a[k];       long long c_sum = 0;       for (__typeof(n) i = (k + 1) - ((k + 1) > (n)); i != (n) - ((k + 1) > (n));            i += 1 - 2 * ((k + 1) > (n))) {         if (a[i] == 0) {           continue;         }         if (c_sum == sum) {           c_sum = 0;         }         c_sum += a[i];         if (c_sum > sum) {           break;         }       }       if (c_sum == sum) {         cout <<  YES               <<   n ;         ;         return;       }     }     cout <<  NO           <<   n ;     ;   }   int32_t main() {     long long t;     t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, x, k, mult = 1;     cin >> n >> k >> x;     while (k--) {       mult *= x;     }     vector<long long> pre(n + 1, 0), suf(n + 2, 0), v(n + 1, 0);     for (long long i = 1; i <= n; i++) {       cin >> v[i];       pre[i] = pre[i - 1] | v[i];     }     for (long long i = n; i >= 1; i--) suf[i] = suf[i + 1] | v[i];     long long ans = 0;     for (long long i = 1; i <= n; i++)       ans = max(ans, pre[i - 1] | (mult * v[i]) | suf[i + 1]);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int lp[MAXN];   vector<int> pr;   int ans[MAXN];   int main() {     for (int i = 2; i < MAXN; ++i) {       ans[i] = 0;       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] < MAXN;            ++j)         lp[i * pr[j]] = pr[j];     }     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int s;       cin >> s;       while (s > 1) {         int d = lp[s];         ans[d]++;         while (s % d == 0) {           s /= d;         }       }     }     int res = 0;     for (int i = 2; i < MAXN; i++) {       res = (res > ans[i] ? res : ans[i]);     }     cout << (res > 1 ? res : 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v;     int c;     for (int i = 0; i < n; i++) {       cin >> c;       v.push_back(c);     }     if (n == 1) {       if (v[0] == 1) {         cout <<  YES ;         return 0;       }     }     sort(v.begin(), v.end());     if (v[0] == 0 && v[1] == 1) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, x;   long long eval(long long x) {     long long ret = 0;     if (x % 4 == 0) {       return x / 4;     } else {       if (x % 4 == 3) {         x -= 15;         ret++;         ret++;       } else if (x % 4 == 2) {         x -= 6;         ret++;       } else if (x % 4 == 1) {         x -= 9;         ret++;       }       if (x < 0)         return -1;       else         return ret + x / 4;     }   }   int main() {     cin >> n;     for (int i = 0; i < (n); ++i) {       cin >> x;       printf( %lld n , eval(x));     }   }
#include <bits/stdc++.h>   const int N = 1000;   int n, k;   struct point {     int x, y;     point operator-(const point &rhs) const {       return (point){x - rhs.x, y - rhs.y};     }   } a[7], b[N];   bool same_sgn(int x, int y) { return !x || !y || (x > 0) == (y > 0); }   bool collinear(point a, point b) {     return (long long)a.x * b.y == (long long)a.y * b.x && same_sgn(a.x, b.x) &&            same_sgn(a.y, b.y);   }   bool on_segment(point a, point b, point c) {     return collinear(a - b, c - b) && collinear(a - c, b - c);   }   std::vector<int> need[N][7];   bool unable[N][7], shot[N];   int p[7], id, ans;   bool dfs(int target) {     if (id == k) return 0;     int i = p[id++];     bool success = 1;     if (unable[target][i]) return 0;     for (int nxt : need[target][i])       if (!shot[nxt] && !dfs(nxt)) return 0;     return shot[target] = 1;   }   int main() {     std::ios::sync_with_stdio(0), std::cin.tie(0);     std::cin >> k >> n;     for (int i = 0; i < k; ++i) std::cin >> a[i].x >> a[i].y;     for (int i = 0; i < n; ++i) std::cin >> b[i].x >> b[i].y;     for (int i = 0; i < n; ++i)       for (int j = 0; j < k; ++j)         for (int p = 0; p < n; ++p)           if (p != i && on_segment(b[p], b[i], a[j])) {             need[i][j].emplace_back(p);             if (need[i][j].size() >= k) {               unable[i][j] = 1;               break;             }           }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < k; ++j) p[j] = j;       do         if (dfs((std::memset(shot, id = 0, sizeof shot), i))) {           ++ans;           break;         }       while (std::next_permutation(p, p + k));     }     std::cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int a, b, c, m;     int flag = 0;     int c1 = 0, c2 = 0, c3 = 0;     int t;     cin >> a >> b >> c >> m;     t = 0;     for (int i = min(c, m); i <= 2 * c && i <= 2 * m; i++) {       if ((m <= i && 2 * m >= i) && (c <= i && 2 * c >= i)) {         t = 1;         c3 = i;         break;       }     }     if (t == 0) {       flag = 1;     }     if (flag == 0) {       t = 0;       for (int i = b; i <= 2 * b; i++) {         if ((m <= i) && (b <= i && 2 * b >= i) && i > c3 && (2 * m < i)) {           t = 1;           c2 = i;           break;         }       }       if (t == 0) {         flag = 1;       }     }     if (flag == 0) {       t = 0;       for (int i = a; i <= 2 * a; i++) {         if ((m <= i) && (a <= i && 2 * a >= i) && i > c2 && (2 * m < i)) {           t = 1;           c1 = i;           break;         }       }       if (t == 0) {         flag = 1;       }     }     if (flag == 1) {       cout <<  -1 n ;     } else {       cout << c1 <<   n  << c2 <<   n  << c3 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1e5 + 10;   inline int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   std::vector<int> vec[N];   inline int calc(int n, int m) {     int sum = 0;     for (int i = 0; i < n - 1; ++i)       for (int j = 0; j < m - 1; ++j) {         int x = vec[i][j] + vec[i][j + 1] + vec[i + 1][j] + vec[i + 1][j + 1];         sum += x == 3 ? 1 : (x == 4 ? 4 : 0);       }     return sum;   }   inline void solve() {     int n = read(), m = read(), k = read(), flg = 0;     if (4LL * (n - 1) * (m - 1) < k) return puts( -1 ), void();     if (n > m) std::swap(n, m), flg = 1;     for (int i = 0; i < n; ++i) vec[i].resize(m);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) vec[i][j] = 0;     if (m < 5) {       int suc = 0;       for (int s = 1; s < (1 << n * m); ++s) {         for (int i = 0; i < n; ++i)           for (int j = 0; j < m; ++j) vec[i][j] = s >> i * m + j & 1;         if (calc(n, m) == k) {           suc = 1;           break;         }       }       if (!suc) return puts( -1 ), void();     } else if (4LL * (n - 1) * (m - 1) == k + 8 && n == 3) {       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) vec[i][j] = 1;       vec[0][0] = vec[1][0] = vec[2][0] = 0;     } else {       int sum = 0, flg = k ? 0 : 1;       for (int i = 0; i < m; ++i) vec[0][i] = 1;       for (int i = 1; i < n && !flg; ++i)         for (int j = 0; j < m && !flg; ++j) {           int x = j == m - 1 ? 3 : (j ? 4 : 1);           if (sum + x > k) {             int w = k - sum;             if (w == 0) flg = 1;             if (w == 1) {               if (j != m - 1)                 vec[i][m - 1] = flg = 1;               else if (i != n - 1)                 vec[i + 1][0] = flg = 1;             }             if (w == 2) {               if (j <= m - 3)                 vec[i][m - 2] = flg = 1;               else if (i != n - 1)                 vec[i + 1][1] = flg = 1;             }             if (w == 3) {               if (j <= m - 4)                 vec[i][m - 1] = vec[i][m - 3] = flg = 1;               else if (i != n - 1 && j <= m - 3)                 vec[i][m - 2] = vec[i + 1][0] = flg = 1;               else if (i != n - 1 && j <= m - 2)                 vec[i][m - 1] = vec[i + 1][1] = flg = 1;               else if (i != n - 1)                 vec[i + 1][0] = vec[i + 1][2] = flg = 1;             }             if (flg == 0) return puts( -1 ), void();           } else             vec[i][j] = 1, sum += x;         }     }     if (flg) {       for (int i = 0; i < m; ++i, putchar(  n ))         for (int j = 0; j < n; ++j) putchar(vec[j][i] ?  *  :  . );     } else {       for (int i = 0; i < n; ++i, putchar(  n ))         for (int j = 0; j < m; ++j) putchar(vec[i][j] ?  *  :  . );     }   }   int main() {     for (int T = read(); T; putchar(  n ), --T) solve();     return 0;   }