using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); public static void Main() { Solve(); } static void Solve() { var n = NN; var s = ReadLine(); if (n == 1) { WriteLine(1); return; } var count = new int[10]; foreach (var si in s) ++count[si - '0']; var set = new HashSet(); for (var i = 1; i < 10; ++i) { if (count[i] == 0) continue; --count[i]; for (var j = 1; j < 10; ++j) { if (count[j] == 0) continue; --count[j]; var tmp = 0; var evens = 0; var odds = 0; for (var c = 1; c < 10; ++c) { for (var p = 0; p < count[c]; ++p) tmp = (tmp * 10 + c) % 120; if (count[c] > 0) { if (c % 2 == 0) ++evens; else ++odds; } } tmp = (tmp * 100 + i * 10 + j) % 120; set.Add(tmp); if (evens > 0 && odds > 0) set.Add((tmp + 60) % 120); ++count[j]; } ++count[i]; } WriteLine(set.Count); } }