Problem:
かけざん
太郎君はかけざんを習いたての小学生です。なんとなく、彼はかけざんを気に入っているので、数字を見かけるとかけざんをしたくなります。そんな彼はここのところ、次のような処理を0以上の整数に施すことが好きなようです。


(処理の流れ)
手順1. ある0以上の整数nが10進数表示で一けたならばそこで処理を終了する。そうでなければ手順2に進む
手順2. 10以上の整数nを10進数表示をするとどこかの桁の間に切れ目を入れて二つの数字に分解することが可能である(例えば2012-> 20,12)。このような切り方としてありうるものに対して,得られた二つの数字を掛け合わせて最も大きいものを次のnとして手順1に戻る。(詳しくは下記の"手順2に関する補足を参照")
太郎君はこの処理を気に入っているようですが、何回手順2の操作を繰り返せばよいのか大きい数字だと予想ができず、もしかしたら無限回行われなければならないかもしれないと思っています。そこで、太郎君の兄であり大学生であるあなたに0以上の整数nに対してこの手順2を何回しなければならないかを聞いてきました。
あなたの仕事は、Q個の0以上の整数
N
1
..
N
Q
が与えられるので、それぞれの整数で処理の終了までに何回の手順2が施されるかを求めることです。その際にもし無限回の手順が必要ならば、-1を出力してください。
手順2に関する補足
切り分けた結果、桁の初めに0がつくものも考慮に入れる必要があります。
例えばn=1024のとき、1*024 , 10*24 , 102*4をそれぞれ計算するとそれぞれ24,240,408となるため、408が選ばれ、これが次のnとなります。
Input
Q
N
1
N
2
...
N
Q
Q
は与えられる0以上の整数の個数を表す
N
i
は太郎君が気になっている0以上の整数で,i番目のものを表す
Constraints
1≤Q≤100
0≤N
i
≤10
6
Output
Q
個の整数を改行区切りで出力せよ
R
1
R
2
..
R
Q
R
i
は、
N
i
に対して処理を終了するまでに手順2を実行する回数を表す
N
i
に対して手順2を無限回だけ実行する必要がある場合は
R
i
は -1となる
Sample Input 1
3
9
99
123
Output for the Sample Input 1
0
2
3
9は1桁の数なので、手順2が実行されることはありません。

99は2桁であり、手順2を施せば9,9としか分割できずその次の数は81となる。
81も2桁の数であり、手順2を施せば8,1としか分割できずその次の数は8となる。
1桁の数になったので処理が終了し、答えは2。

123は3桁の数なので、手順2を施します。
この場合は12,3と1,23の二つの分け方があり、それぞれでかけざんをすると36,23となるので、
36が次の数として選ばれます。
Sample Input 2
2
999999
1000000
Output for the Sample Input 2
12 
1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int MAXS = 1000000;
vector<int> Next(MAXS + 1,-1);

int main() {
    rep(i,10,MAXS+1) {
        string s = to_string(i);
        rep(j,1,s.size()) {
            chmax(Next[i], stoi(s.substr(0,j)) * stoi(s.substr(j,s.size()-j)));
        }
    }
    int Q;
    cin >> Q;
    rep(_,0,Q) {
        int A;
        cin >> A;
        vector<bool> vis(MAXS+1,false);
        int ANS = 0;
        bool flag = false;
        while(Next[A] >= 0) {
            if (vis[A]) {
                cout << -1 << endl;
                flag = true;
                break;
            }
            vis[A] = true;
            ANS++;
            A = Next[A];
        }
        if (!flag) cout << ANS << endl;
    }
}
accuracy: 1
time_ms: 220
memory_kb: 7420
final_rank: 16

code_snippet: #include <stdio.h>
using namespace std;

int main() {
    int Q, N, count, tmp, max, S;
    bool FLG;
    scanf("%d", &Q);
    bool *table = new bool[1000001];
    for (int loop = 0; loop < Q; loop++) {
        for (int i = 0; i <= 1000000; i++)
            table[i] = false;
        count = 0;
        scanf("%d", &N);
        table[N] = true;
        FLG = false;
        while (N >= 10) {
            max = 0;
            for (S = 10; N / S != 0; S *= 10) {
                tmp = (N / S) * (N % S);
                max = (max >= tmp) ? max : tmp;
            }
            N = max;
            if (table[N]) {
                FLG = true;
                break;
            } else {
                table[N] = true;
                count++;
            }
        }
        if (FLG) {
            printf("-1\n");
        } else {
            printf("%d\n", count);
        }
    }
    delete[] table;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3428
final_rank: 1

code_snippet: #include <bits/stdc++.h>

int main() {
    constexpr int N = 1000001;
    std::array<int, N> ans;
    ans.fill(1e9);

    auto dfs = [&](auto self, int val) -> int {
        if (ans[val] != 1e9) return ans[val];
        if (val < 10) {
            return ans[val] = 0;
        }
        int max_val = -1;
        std::string s = std::to_string(val);
        for (int i = 1; i < (int)s.size(); i++) {
            auto lhs = s.substr(0, i);
            auto rhs = s.substr(i);
            max_val = std::max(max_val, std::stoi(lhs) * std::stoi(rhs));
        }
        return ans[val] = self(self, max_val) + 1;
    };

    for (int i = 0; i < N; i++) dfs(dfs, i);

    int q;
    std::cin >> q;
    while (q--) {
        int n;
        std::cin >> n;
        std::cout << ans[n] << std::endl;
    }
}
accuracy: 1
time_ms: 220
memory_kb: 7408
final_rank: 15

code_snippet: #include <cstdio>
#include <algorithm>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool table[1000001];
  for (int loop = 0; loop < Q; loop++) {
    fill(table, table + 1000001, false);
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (N / 10 != 0) {
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = max > tmp ? max : tmp;
      }
      N = max;
      if (table[N]) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    printf(FLG ? "-1\n" : "%d\n", count);
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3708
final_rank: 9

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001];
  for (int loop = 0; loop < Q; loop++) {
    count = 0;
    scanf("%d", &N);
    for (int i = 0; i <= N; i++)
      table[i] = false;
    table[N] = true;
    FLG = false;
    while (true) {
      if (N / 10 == 0)
        break;
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3708
final_rank: 7

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001];
  for (int loop = 0; loop < Q; loop++) {
    for (int i = 0; i <= 1000000; i++)
      table[i] = false;
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N / 10 == 0)
        break;
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3692
final_rank: 8

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001];
  for (int loop = 0; loop < Q; loop++) {
    for (int i = 0; i < 1000000; i++)
      table[i] = false;
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N / 10 == 0)
        break;
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3712
final_rank: 11

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool table[1000001];
  for (int loop = 0; loop < Q; loop++) {
    for (int i = 0; i <= 1000000; i++)
      table[i] = false;
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N / 10 == 0)
        break;
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3708
final_rank: 9

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool table[1000001] = {};
  for (int loop = 0; loop < Q; loop++) {
    fill(table, table + 1000001, false);
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N < 10)
        break;
      max = 0;
      for (S = 10; S <= N; S *= 10) {
        tmp = (N / S) * (N % S);
        max = max >= tmp ? max : tmp;
      }
      N = max;
      if (table[N]) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3712
final_rank: 11

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001];
  for (int loop = 0; loop < Q; loop++) {
    for (int i = 0; i <= 1000000; i++)
      table[i] = false;
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N < 10)
        break;
      max = 0;
      for (S = 10; S <= N; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  delete[] table;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3444
final_rank: 2

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
const int MAX_N = 1000000;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[MAX_N + 1];
  for (int loop = 0; loop < Q; loop++) {
    for (int i = 0; i <= MAX_N; i++)
      table[i] = false;
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N / 10 == 0)
        break;
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  delete[] table;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3448
final_rank: 3

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001]();
  for (int loop = 0; loop < Q; loop++) {
    fill(table, table + 1000001, false);
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N < 10)
        break;
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N]) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  delete[] table;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3448
final_rank: 3

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001];
  for (int loop = 0; loop < Q; loop++) {
    for (int i = 0; i <= 1000000; i++)
      table[i] = false;
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N < 10)
        break;
      max = 0;
      for (S = 10; N >= S; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3744
final_rank: 13

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001]();
  for (int loop = 0; loop < Q; loop++) {
    fill(table, table + 1000001, false);
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N / 10 == 0)
        break;
      int max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N]) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  delete[] table;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3448
final_rank: 3

code_snippet: #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001];
  for (int loop = 0; loop < Q; loop++) {
    for (int i = 0; i <= 1000000; i++)
      table[i] = false;
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N / 10 == 0)
        break;
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  delete[] table;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3448
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main() {
  int Q, N, count, tmp, max, S;
  bool FLG;
  scanf("%d", &Q);
  bool *table = new bool[1000001];
  for (int loop = 0; loop < Q; loop++) {
    for (int i = 0; i <= 1000000; i++)
      table[i] = false;
    count = 0;
    scanf("%d", &N);
    table[N] = true;
    FLG = false;
    while (true) {
      if (N / 10 == 0)
        break;
      max = 0;
      for (S = 10; N / S != 0; S *= 10) {
        tmp = (N / S) * (N % S);
        max = (max >= tmp) ? max : tmp;
      }
      N = max;
      if (table[N] == true) {
        FLG = true;
        break;
      } else {
        table[N] = true;
        count++;
      }
    }
    if (FLG) {
      printf("-1\n");
    } else {
      printf("%d\n", count);
    }
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4204
final_rank: 14