using System; using System.Collections.Generic; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int seitoCount = int.Parse(Reader.ReadLine()); Dictionary kirawareDic = new Dictionary(); int[] ans = new int[seitoCount]; for(int i=0; i input = new Dictionary(); List numList = new List(); for(int i=0; ia.Value).ToList().ForEach((a)=>{ List target = new List(input.Where(b=>b.Value != a.Key && ans[b.Key] < 0).Select(c=>c.Key)); target.Sort((b, c)=>{ bool bFlag = numList.Contains(input[b]); bool cFlag = numList.Contains(input[c]); if(bFlag && (!cFlag)) { return -1; } if((!bFlag) && cFlag) { return 1; } return 0; }); if(target.Count > 0) { ans[target[0]] = a.Key; numList.Remove(a.Key); } else { canProc = false; } }); if(numList.Count > 0 && canProc) { numList.ForEach((a)=>{ for(int i=0; iConsole.WriteLine(a)); } else { Console.WriteLine(-1); } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 5 1 1 1 0 1 "; 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(); } }