#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define rep(i, x) for(ll i = 0; i < x; i++) #define rep2(i, x) for(ll i = 1; i <= x; i++) #define all(a) (a).begin(),(a).end() #define puts(x) cout << (x) << "\n" using ll = long long; using ld = long double; using namespace std; const ll INF = 1000000000000000000; const int intINF = 1000000000; const ll mod = 1000000007; const ll MOD = 998244353; const ld pi = 3.141592653589793238; //const ld EPS = 1e-9; bool isprime(int p) { if (p == 1) return false; for (int i = 2; i < p; i++) { if (p % i == 0) return false; } return true; } ll gcd(ll a, ll b) { if (a < b)swap(a, b); if (a % b == 0)return b; return gcd(b, a % b); } // 返り値: a と b の最大公約数 // ax + by = gcd(a, b) を満たす (x, y) が格納される //main関数内に extGCD(a, b, x, y); でx, yに解が格納 ll extGCD(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll keta(ll n) { ll res = 0; while (n >= 1) { res += n % 10; n /= 10; } return res; } ll modpow(ll x, ll y) { ll res = 1; while (y) { if (y % 2) { res *= x; res %= mod; } x = x * x % mod; y /= 2; } return res; } ll nCk(ll n, ll k) { ll a = 1, b = 1; for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; } for (int h = 1; h <= k; h++) { b *= h; b %= mod; } return a * modpow(b, mod - 2) % mod; } //printf("%.10f\n", n); typedef pair P; typedef pair pp; ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; struct edge { ll to, cost; }; struct status { ll ima; ll cost; bool operator<(const status& rhs) const { return cost < rhs.cost; }; bool operator>(const status& rhs) const { return cost > rhs.cost; }; }; ll v[10] = { 6, 2, 5, 5, 4, 5, 6, 4, 7, 6 }; ll f(string s) { if (s[0] == '-') { string t; rep(i, s.size()) { if (i == 0) { continue; } t.push_back(s[i]); } return f(t); } if (s.size() == 1) { return v[(s[0] - '0')]; } string t; t.push_back(s[s.size() - 1]); ll cnt = f(t); s.pop_back(); return cnt + f(s); } ll f2(ll s) { if (s <= 9) { return v[s]; } return f2(s / 10) + f2(s % 10); } ll string_to_bigint(string S) {//文字列から配列に ll N = 0; // N = (文字列 S の長さ) for (int i = 0; i < S.size(); ++i) { N *= 10; N += (S[i] - '0'); // 10^i の位の数 } return N; } signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); //cout << fixed << setprecision(15); //input string p, n; cin >> p >> n; ll a = f(p), mae = -1; if (n.size() <= 4) { ll nint = string_to_bigint(n); rep(i, nint - 1) { a = f2(a); } cout << a << endl; return 0; } while (true) { if (a == 4 || a == 5 || a == 6) { break; } a = f2(a); } cout << a << endl; return 0; }