using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[] LList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => int.Parse(ReadLine())).ToArray(); public static void Main() { Solve(); } static void Solve() { var a = LList(6); var tree = new List[1000000]; for (var i = 0; i < tree.Length; ++i) tree[i] = new List(); for (var i = 0; i < 6; ++i) { for (var j = 0; j < tree.Length; ++j) { tree[j].Add(Add(a[i], j)); } } var visited = new bool[tree.Length]; visited[a[0]] = true; var q = new Queue(); q.Enqueue(a[0]); while (q.Count > 0) { var cur = q.Dequeue(); foreach (var next in tree[cur]) { if (visited[next]) continue; visited[next] = true; q.Enqueue(next); } } WriteLine(visited.Count(f => f)); } static int Add(int a, int b) { return (a / 100000 + b / 100000) % 10 * 100000 + (a / 10000 % 10 + b / 10000 % 10) % 10 * 10000 + (a / 1000 % 10 + b / 1000 % 10) % 10 * 1000 + (a / 100 % 10 + b / 100 % 10) % 10 * 100 + (a / 10 % 10 + b / 10 % 10) % 10 * 10 + (a % 10 + b % 10) % 10; } }