using System; using System.Collections.Generic; using System.Linq; namespace yukicoder { public class Program { public static void Main() { var n = Console.ReadLine(); var max = int.Parse(n); var k = Combination.Generate(n.Length, 2, false); foreach(var x in k) { var a = n[x[0]]; var b = n[x[1]]; var m = n.Remove(x[0], 1).Insert(x[0], b.ToString()).Remove(x[1], 1).Insert(x[1], a.ToString()); max = max < int.Parse(m) ? int.Parse(m) : max; } Console.WriteLine(max); } static class Combination { private static List> _comb; public static List> Generate(int n, int r, bool dupulication) { _comb = new List>(); CalcCombination(new List(), n, r, dupulication); return _comb; } private static void CalcCombination(List list, int n, int r, bool dupulication) { if (list.Count == r) { _comb.Add(new List(list)); return; } var index = 0; if (dupulication) { index = list.Any() ? list.Last() : 0; } else { index = list.Any() ? list.Last() + 1 : 0; } for (int i = index; i < n; i++) { list.Add(i); CalcCombination(list, n, r, dupulication); list.Remove(i); } } } } }