using
System;
using
System.Collections;
using
System.Linq;
using
System.Collections.Generic;
public
class
GFG{
static
public
void
Main (){
GFG obj =
new
GFG();
int
N = 56;
String M =
"245769"
;
Console.WriteLine(obj.solve(N, M));
}
public
int
solve(
int
N, String M)
{
Dictionary<
int
,
int
> mymap
=
new
Dictionary<
int
,
int
>();
int
len = M.Length;
var
cArr = M.ToCharArray();
for
(
int
i = 0; i < len; i++)
{
char
c = cArr[i];
if
(c ==
'5'
)
c =
'2'
;
else
if
(c ==
'9'
)
c =
'6'
;
int
c_int =
int
.Parse(c.ToString());
if
(mymap.ContainsKey(c_int))
mymap[c_int]=(mymap[c_int] + 1);
else
mymap.Add(c_int, 1);
}
Dictionary<
int
,
int
> rems
=
new
Dictionary<
int
,
int
>();
while
(N > 0)
{
int
rem = N % 10;
if
(rem == 5)
rem = 2;
if
(rem == 9)
rem = 6;
if
(rems.ContainsKey(rem))
rems[rem]= rems[rem] + 1;
else
rems.Add(rem, 1);
N = N / 10;
}
int
cnt =
int
.MaxValue;
foreach
(
var
ele
in
rems) {
int
key = ele.Key;
if
(!mymap.ContainsKey(key))
return
0;
int
temp = (
int
)mymap[key]
/ (
int
)ele.Value;
cnt = Math.Min(cnt, temp);
}
return
cnt;
}
}