public static void Main(string[] args) { var n = new BigInteger(1); var t = new TernarySearchTree <char>(); t.Add("1"); for (int i = 1; i <= 800; i++) { n = n * 2; t.Add(n.ToString()); } int m = Convert.ToInt32(Console.ReadLine()); for (int v = 0; v < m; ++v) { string a = Console.ReadLine(); var c = 0; for (int i = 0; i < a.Length; ++i) { var matcher = new SequenceMatcher(a, i); c += t.Match(matcher).Count(); } Console.WriteLine(c); } }