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()); string[] inpt = Reader.ReadLine().Split(' '); char[] enzansi = inpt.Where(a=>a.Equals("+") || a.Equals("-")).Select(a=>a[0]).OrderBy(a=>a).ToArray(); int[] numList = inpt.Where(a=>(!a.Equals("+")) && (!a.Equals("-"))).Select(a=>int.Parse(a)).OrderByDescending(a=>a).ToArray(); int saidaiKeta = numList.Length - enzansi.Length; List listSub = new List(); long ans1 = 0; listSub.Add(long.Parse(string.Join(string.Empty, numList.Take(saidaiKeta)))); listSub.AddRange(numList.Skip(saidaiKeta).Select(a=>(long)a)); ans1 = listSub[0]; listSub.RemoveAt(0); for(int i=0; i(); long ans2 = 0; enzansi = enzansi.Reverse().ToArray(); if(enzansi.Count(a=>a=='-') > 0) { listSub.Add(long.Parse(string.Join(string.Empty, numList.Take(saidaiKeta)))); listSub.AddRange(numList.Skip(saidaiKeta).Select(a=>(long)a)); } else { numList = numList.Reverse().ToArray(); int yousosu = enzansi.Length + 1; int[] tmp = numList; int idx = 0; bool isBigger = true; for(int i=0; i= yousosu) { isBigger = false; idx = yousosu - 1; } } else { idx--; if(idx < 0) { isBigger = true; idx = 0; } } } } ans2 = listSub.Last(); listSub.RemoveAt(listSub.Count - 1); for(int i=0; i