using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int itemCount = int.Parse(Reader.ReadLine()); int[] inpt = Reader.GetInt(); List switchList = new List(inpt); switchList.Sort(); HashSet tmp = this.GetAnsList(0, switchList); Console.WriteLine(tmp.Count); } private Dictionary>> dic = new Dictionary>>(); private HashSet GetAnsList(int srcNum, List switchList) { string key = string.Join("#", switchList); if(!dic.ContainsKey(srcNum)) { dic.Add(srcNum, new Dictionary>()); } if(dic[srcNum].ContainsKey(key)) { return dic[srcNum][key]; } HashSet ans = new HashSet(); ans.Add(srcNum); if(switchList.Count == 1) { int val = srcNum ^ switchList[0]; ans.Add(val); } else { for(int i=0; i subList = new List(switchList); subList.RemoveAt(i); int val = srcNum ^ switchList[i]; HashSet ret = this.GetAnsList(val, subList); ret.ToList().ForEach(a=>ans.Add(a)); } } dic[srcNum].Add(key, ans); return ans; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 6 1 1 4 5 1 4 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }