using System; using System.Collections.Generic; using System.Linq; public class PriorityQueue { SortedDictionary> dict = new SortedDictionary>(); int count = 0; public int Count { get { return count; } } public void Enqueue(TKey key, TValue value) { if (!dict.ContainsKey(key)) { dict[key] = new HashSet(); } dict[key].Add(value); count++; } public KeyValuePair Dequeue() { var queue = dict.First(); if (queue.Value.Count <= 1) { dict.Remove(queue.Key); } var val = queue.Value.First(); queue.Value.Remove(val); count--; return new KeyValuePair(queue.Key, val); } public KeyValuePair Peek() { var queue = dict.First(); var val = queue.Value.First(); return new KeyValuePair(queue.Key, val); } public void ChangePriority(TKey prevKey, TKey newKey, TValue value) { var set = dict[prevKey]; set.Remove(value); if (set.Count == 0) { dict.Remove(prevKey); } count--; Enqueue(newKey, value); } } class Solution { internal struct State { internal int Cost; internal int Length; internal int CopiedLength; internal State(int c, int l, int cl) { Cost = c; Length = l; CopiedLength = cl; } } static void Main() { var n = int.Parse(Console.ReadLine()); var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var c = vals[0]; var v = vals[1]; // cost -> length, copied length var states = new PriorityQueue(); states.Enqueue(0, new State(0, 1, 0) ); State best = states.Peek().Value; while (states.Count > 0) { var cur = states.Dequeue().Value; if (cur.Length >= n) { best = cur; break; } // copy if (cur.Length != cur.CopiedLength) { var copied = new State(cur.Cost + c, cur.Length, cur.Length); states.Enqueue(copied.Cost, copied); } // paste var paste = new State(cur.Cost + v, cur.Length + cur.CopiedLength, cur.CopiedLength); states.Enqueue(paste.Cost, paste); } Console.WriteLine(best.Cost); } }