using System; using System.Collections.Generic; using System.Linq; namespace MixedUpLists { class Program { static void Main(string[] args) { //Input var firstList = Console.ReadLine().Split().Select(int.Parse).ToList(); var secondList = Console.ReadLine().Split().Select(int.Parse).ToList(); //Find the smaller length int k = Math.Min(firstList.Count, secondList.Count); List biggerList = FindTheBiggerList(firstList, secondList); //Find the lower limit and the upper limit int lowerLimit = Math.Min(biggerList[k], biggerList[k + 1]); int upperLimit = Math.Max(biggerList[k], biggerList[k + 1]); List commonList = new List(); for (int i = 0; i < k; i++) { commonList.Insert(2 * i, firstList[i]); commonList.Insert((2 * i + 1), secondList[k - i - 1]); } commonList.RemoveAll(x => (x <= lowerLimit || x >= upperLimit)); commonList.Sort(); Console.WriteLine(String.Join(" ", commonList)); } private static List FindTheBiggerList(List firstList, List secondList) { if (firstList.Count > secondList.Count) return firstList; else return secondList; } } }