Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?

The single line contains four space-separated integers n, m, a, b (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.

Print a single integer — the minimum sum in rubles that Ann will need to spend.

NoteIn the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CodeforcesSolution
{
  class ProgramCF
  {
    static ConsoleInput inp;
    static void Main ( string[] args )
    {
      try
      {
        if ( File.Exists ( @"e:\zin.txt" ) )
          Console.SetIn ( new StreamReader ( @"e:\zin.txt" ) );
      }
      catch
      {
      }
      inp = new ConsoleInput ( );
      inp.ReadAll ( );
      int n = inp.ReadNextInt ( );
      int m = inp.ReadNextInt ( );
      int a =inp.ReadNextInt ( );
      int b =inp.ReadNextInt ( );
      int minCost = a * n;
      if ( n < m )
        minCost = Math.Min ( minCost, b );
      else
      {
        minCost = Math.Min ( minCost, ( n / m + 1 ) * b );
        minCost = Math.Min ( minCost, ( n / m ) * b + ( n % m ) * a );
      }
      // ===
      Console.WriteLine ( minCost );
    }

    interface IInput
    {
      string[] ReadLineAsArray ( );
      string ReadLine ( );
    }

    class ConsoleInput
    {
      List<string> lines = new List<string> ( );
      int idx=0;
      public void ReadAll ( )
      {
        while ( true )
        {
          string line = Console.ReadLine ( );
          if ( line == null )
            break;
          lines.AddRange ( line.Split ( ' ' ) );
        }
      }

      public string ReadNextString ( )
      {
        return lines[idx++];
      }

      public int ReadNextInt ( )
      {
        return int.Parse ( lines[idx++] );
      }

      public long ReadNextLong ( )
      {
        return long.Parse ( lines[idx++] );
      }

      public double ReadNextDouble ( )
      {
        return double.Parse ( lines[idx++] );
      }

    }
  }
}

// A Dynamic Programming based
// C# program to find minimum
// number operations to
// convert str1 to str2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class GFG
{
    static string[] memo = new string[13];

    public static void Main()
    {
        ///var t = int.Parse(Console.ReadLine());

        ////while (t > 0)
        //{
        //    // t--;
        //    // var n = int.Parse(Console.ReadLine());
        //    //var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        //var input = Console.ReadLine().Split();
        //var n = int.Parse(input[0]);
        //var m = int.Parse(input[1]);
        //    //var k = int.Parse(input[2]);
        //
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var m = int.Parse(input[1]);
        var a = int.Parse(input[2]);
        var b = int.Parse(input[3]);

        var totlDays = n / m;
        if (totlDays == 0)
        {
            if (a * n > b)
            {
                Console.Write(b);
                return;
            }
        }
        var remDays = n % m;

        //t using discount

        var macValue = n * a;
        var cc = 1;
        if (remDays / m == 0)
        {
            cc = 1;
        }
        else
        {
            cc = remDays / m;
        }

        var maxV = totlDays * b + Math.Min(remDays * a, cc * b);

        Console.Write(Math.Min(macValue, maxV));

        //}

    }

}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using static System.Math;

namespace HackerRank
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums = Console.ReadLine().Split().Select(num => int.Parse(num)).ToArray();
            int n = nums[0]; //10
            int m = nums[1]; //3
            int a = nums[2]; //5
            int b = nums[3]; //1
            Console.WriteLine(a * m > b ? n / m * b + Min(n % m * a, b) : n * a);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeForces_466A_Cheap_Travel
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] p = new int[3];
            p[0] = n[0] / n[1] * n[3] + n[0] % n[1] * n[2];
            p[1] = (n[0] / n[1] + 1) * n[3];
            p[2] = n[0] * n[2];
            Console.WriteLine(p.Min());
        }
    }
}

using System;
using System.Linq;

namespace Codeforces
{
  public static class Algr
  {
    public static string Solve(string input)
    {
      var array = input.Split(' ')
        .Select(x => Int32.Parse(x))
        .ToArray();

      int n = array[0];
      int m = array[1];
      int a = array[2];
      int b = array[3];

      double costB = (double) b / m;
      int r = 0;

      if (a <= costB)
      {
        r = n * a;
      }

      else
      {
        r = (n / m) * b;
        r += Math.Min((n - ((n / m) * m)) * a, b);
      }

      return r.ToString();
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Algr.Solve(Console.ReadLine()));
    }
  }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace batdau_3_7
{
    class Program
    {
        public static void Main(string[] args)
        {
            String s = Console.ReadLine();
            String []f = new String[5];
            f= s.Split();
            Int32 n = Int32.Parse(f[0]), m = Int32.Parse(f[1]),
                a = Int32.Parse(f[2]), b = Int32.Parse(f[3]);
            Int32 d;
            Int32 k = n/m,l=b;
            if ((n%m)*a< b) l = (n%m)*a;
            d = k*b+l;
            Int32 e = n*a;
            d = (d+e-Math.Abs(d-e))/2;
            Console.WriteLine(d);
        }
    }
}

using System;

namespace _466A
{
	class Program
	{
		static void Main ( string [ ] args )
		{
			int n, m, a, b;
			string[] nums = (Console.ReadLine()).Split(' ');
			n = int.Parse(nums[0]);
			m = int.Parse(nums[1]);
			a = int.Parse(nums[2]);
			b = int.Parse(nums[3]);
			int min = ( (b * (n / m) ) + (a * (n % m)) );
			if (n%m != 0 && b*(n/m + 1) < min)
				min = ( b*(n/m + 1) );
			else if (n%m == 0 && b * (n / m) < min)
				min = (b*(n/m));
			if (n*a < min)
				min = (n*a);
			Console.Write(min);
		}
	}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace CodeForcesProblems
{
    class A466_CheapTravel
    {
        public static void Main()
        {
            //while (true)
            //{
                string[] z = Console.ReadLine().Split(' ');
                int n = int.Parse(z[0]);
                int m = int.Parse(z[1]);
                int a = int.Parse(z[2]);
                int b = int.Parse(z[3]);
                double c =(double) b / m;
                if(c>a)
                {
                    Console.WriteLine(a*n);
                }
                else
                {
                    int t = n / m;
                    int result = (t * b);  //+((n-(t*m))*a);

                    if (((n - (t * m)) * a) > b)
                        result += b;
                    else
                        result += ((n - (t * m)) * a);

                    Console.WriteLine(result);
                }

            //}
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace challenges
{
    class Program
    {

        static int N, M, A, B;
        static int res;
        static string[] phr;

        static void Main()
        {
            phr = Console.ReadLine().Split();

            N = Convert.ToInt32(phr[0]);
            M = Convert.ToInt32(phr[1]);
            A = Convert.ToInt32(phr[2]);
            B = Convert.ToInt32(phr[3]);

            if (M * A <= B)
            {
                Console.WriteLine(N * A);
                return;
            }

            res += (N / M) * B;
            N %= M;
            res += Math.Min(N * A, B);

            Console.WriteLine(res);
        }

     }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public object Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        int a = ReadInt();
        int b = ReadInt();

        int ans = int.MaxValue;
        for (int i = 0; ; i++)
        {
            ans = Math.Min(ans, i * b + Math.Max(0, n - i * m) * a);
            if (i * m > n)
                break;
        }

        return ans;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
#endif
        try
        {
            var ts = DateTime.Now;
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            Console.WriteLine(ex);
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read/Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }

    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }

    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    #endregion
}

using System;

namespace ConsoleApplication23
{
    class Program
    {
        static void Main(string[] args)
        {

                string str = Console.ReadLine();
                string[] str2 = str.Split(' ');

                int counter = int.Parse(str2[0]);
                int answer = 0;
                if (int.Parse(str2[0]) * int.Parse(str2[2]) < int.Parse(str2[3]) || int.Parse(str2[0]) > int.Parse(str2[1]))
                {
                    while (int.Parse(str2[1]) < counter)
                    {
                        answer = answer + int.Parse(str2[3]);
                        counter = counter - int.Parse(str2[1]);
                    }

                if (counter < 0)
                    counter = 0;

                if (int.Parse(str2[2]) < int.Parse(str2[3]) || counter == 0)
                {
                    answer = answer + int.Parse(str2[2]) * counter;
                }
                else
                {
                    answer = answer + int.Parse(str2[3]);
                }
                }
                else
                    answer = answer + int.Parse(str2[3]);
            if(answer<int.Parse(str2[0])*int.Parse(str2[2]))
            {
                Console.WriteLine(answer);
            }
            else
                Console.WriteLine(int.Parse(str2[0])*int.Parse(str2[2]));

            Console.ReadLine();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int n = Convert.ToInt32(input[0]);
            int m = Convert.ToInt32(input[1]);
            int a = Convert.ToInt32(input[2]);
            int b = Convert.ToInt32(input[3]);

            int ret = 0;

            if (b < m * a)
            {
                while (n*a > b)
                {
                    n -= m;
                    ret += b;
                }
            }
            if (n>0) ret += (a * n);
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = 0,m=0,n=0,u=0;

            string[] arr = Console.ReadLine().Split();
            int a = int.Parse(arr[0]);
            int b = int.Parse(arr[1]);
            int c = int.Parse(arr[2]);
            int d = int.Parse(arr[3]);
            u = a * c;
            if (a % b == 0)
            {
                s = (a / b) * d;
            }
            else if (b > a)
            {
                s = d;
            }
            else
            {
                n = (a / b) * d + (a % b) * c;

                m = (a / b) * d + d;

            }

            int[] w = new int[4];
            w[0] = s;
            w[1] = u;
            w[2] = n;
            w[3] = m;
            Array.Sort(w);
            for (int i = 0; i < 4; i++)
            {
                if (w[i]!=0)
                {
                    Console.WriteLine(w[i]);
                    return;
                }
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Выгодный_проезд
{
    class Program
    {
        static void Main(string[] args)
        {
            var mas = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Resh(mas));
            Console.ReadLine();

        }

        static int Resh(int[] mas)
        {
            int n = mas[0];
            int m = mas[1];
            int a = mas[2];
            int b = mas[3];

            if (m * a > b)
            {
                if ((n % m) * a <= b)
                    return (n / m) * b + (n % m) * a;
                else
                    return (n / m) * b + b;
            }
            else
                return n * a;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string[] data = Console.ReadLine().Split(' ');

            int n = Convert.ToInt32(data[0]);
            int ridesInSurepTicket = Convert.ToInt32(data[1]);
            int pricePerRide = Convert.ToInt32(data[2]);
            int pricePerSuperTicket = Convert.ToInt32(data[3]);

            int answer = 0;
            while (n > 0)
            {
                if (n >= ridesInSurepTicket && pricePerSuperTicket <= pricePerRide*ridesInSurepTicket)
                {
                    answer += pricePerSuperTicket;
                    n = n - ridesInSurepTicket;
                    continue;
                }

                if (n >= ridesInSurepTicket)
                {
                    answer += n*pricePerRide;
                    break;
                }
                else
                {
                    if (n*pricePerRide < pricePerSuperTicket)
                    {
                        answer += n*pricePerRide;
                        n = 0;
                    }
                    else
                    {
                        answer += pricePerSuperTicket;
                        n = 0;
                    }
                }
            }
            Console.WriteLine(answer);
        }
    }
}

using System;
namespace spacename
{
	class programm
	{
		static void Main()
		{
			int n, m, a, b;
			string[] input = Console.ReadLine().Split(' '); //Split разделяет строку на части, разделённые пробелом и возвращает массив этих частей
			n = Convert.ToInt32(input[0]);
			m = Convert.ToInt32(input[1]);
			a = Convert.ToInt32(input[2]);
			b = Convert.ToInt32(input[3]);
			if (a*m<=b)
			{
				Console.WriteLine(a*n);
			}
			else
			{
				if (n%m*a>b)
				{
					Console.WriteLine(n/m*b+b);
				}
				else
				{
					Console.WriteLine(n/m*b+n%m*a);
				};
			};
            Console.ReadLine();
        }
    }
}

using System;

namespace CSharp
{
    public class _466A
    {
        public static void Main(string[] args)
        {
            string[] tokens = Console.ReadLine().Split();

            int n = int.Parse(tokens[0]);
            int m = int.Parse(tokens[1]);
            int a = int.Parse(tokens[2]);
            int b = int.Parse(tokens[3]);

            int[] result = new int[n + 1];
            result[0] = 0;

            for (int i = 1; i <= n; i++)
            {
                result[i] = result[i - 1] + a;

                if ((i >= m ? result[i - m] : 0) + b < result[i])
                {
                    result[i] = (i >= m ? result[i - m] : 0) + b;
                }
            }

            Console.WriteLine(result[n]);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pustoi
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] s = str.Split(' ');
            int n = Convert.ToInt32(s[0]);
            int m = Convert.ToInt32(s[1]);
            int a = Convert.ToInt32(s[2]);
            int b = Convert.ToInt32(s[3]);
            double r1=b/m;
            int t1;
            if (r1 < a)
            {
                t1 = (n / m) * b;
                if ((n % m) * a < b)
                {
                    Console.WriteLine(t1 + ((n % m) * a));
                }
                else
                {
                    Console.WriteLine(t1 + b);
                }
            }
            else if(a<r1 || a == r1)
            {
                Console.WriteLine(n * a);
            }

            Console.Read();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Program{
    static void Main(string[] args){
        string[] input = Console.ReadLine().Split(' ');
        int ridesPlanned = Int32.Parse(input[0]);
        int ridesInSpecialTicket=Int32.Parse(input[1]);
        int priceForSingleRide= Int32.Parse(input[2]);
        int priceForSpecialRides=Int32.Parse(input[3]);

        if (ridesPlanned == 0)
                Console.WriteLine(0);
            else if (ridesInSpecialTicket == 0)
                Console.WriteLine(ridesPlanned * priceForSingleRide);

            else
            {

                if (ridesPlanned % ridesInSpecialTicket == 0){
                    int cost1 = ridesPlanned * priceForSingleRide;
                    int cost2 =(ridesPlanned / ridesInSpecialTicket) * priceForSpecialRides;
                    if (cost1 < cost2)
                        Console.WriteLine(cost1);

                    else
                        Console.WriteLine(cost2);
                }

                else{
                    int cost = (ridesPlanned / ridesInSpecialTicket) * priceForSpecialRides + (ridesPlanned % ridesInSpecialTicket) * priceForSingleRide;
                    int x = ridesPlanned / ridesInSpecialTicket + 1;
                    if(x*priceForSpecialRides < cost)
                    {
                        Console.WriteLine(x * priceForSpecialRides);
                    }
                    else
                        Console.WriteLine(cost);
                }
            }

        }
}

using System;
using System.Collections.Generic;
using System.Linq;
class Problem
{
    void Solve()
    {
        var sc = new Scanner();
        var n = sc.Long();
        var m = sc.Long();
        var a = sc.Long();
        var b = sc.Long();
        var ret = n * a;
        var k = n / m;
        ret = Math.Min(k * b + (n - k * m) * a, ret);
        ret = Math.Min((k + 1) * b, ret);
        Console.WriteLine(ret);

    }
    static void Main()
    {
        // For CodeForces
#if ONLINE_JUDGE
        System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
#endif
#if DEBUG
        var ostream = new System.IO.FileStream("debug.txt", System.IO.FileMode.Open, System.IO.FileAccess.Write);
        var iStream = new System.IO.FileStream("input.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
        Console.SetIn(new System.IO.StreamReader(iStream));
        System.Diagnostics.Debug.AutoFlush = true;
        System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(new System.IO.StreamWriter(ostream, System.Text.Encoding.UTF8)));
        try
        {
#endif
            var problem = new Problem();
            problem.Solve();
#if DEBUG
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
        }
        Console.ReadKey(true);
#endif
    }

}

public class Scanner
{
    readonly System.IO.TextReader reader;
    string[] buffer = new string[0];
    int position;

    public char[] Separator { get; set; }
    public Scanner(System.IO.TextReader reader = null, string separator = null)
    {
        if (reader == null)
            this.reader = Console.In;
        else
            this.reader = reader;
        if (string.IsNullOrEmpty(separator))
            separator = " ";
        this.Separator = separator.ToCharArray();

    }
    public string Scan()
    {
        if (this.position < this.buffer.Length)
            return this.buffer[this.position++];
        this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        this.position = 0;
        return this.buffer[this.position++];
    }

    public string[] ScanToEndLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        var size = this.buffer.Length - this.position;
        var ar = new string[size];
        Array.Copy(this.buffer, position, ar, 0, size);
        return ar;

    }

    public string ScanLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine();
        else
        {
            var sb = new System.Text.StringBuilder();
            for (; this.position < buffer.Length; this.position++)
            {
                sb.Append(this.buffer[this.position]);
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }
    public string[] ScanArray(int length)
    {
        var ar = new string[length];
        for (int i = 0; i < length; i++)
        {
            ar[i] = this.Scan();
        }
        return ar;
    }

    public int Integer()
    {
        return int.Parse(this.Scan());
    }
    public long Long()
    {
        return long.Parse(this.Scan());
    }
    public double Double()
    {
        return double.Parse(this.Scan());
    }

    public int[] IntArray(int length)
    {
        var a = new int[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Integer();
        return a;
    }
    public long[] LongArray(int length)
    {
        var a = new long[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Long();
        return a;
    }
    public double[] DoubleArray(int length)
    {
        var a = new double[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Double();
        return a;
    }

}
static public partial class EnumerableEx
{
    static public string AsString(this IEnumerable<char> source)
    {
        return new string(source.ToArray());
    }
    static public IEnumerable<T> Enumerate<T>(this int count, Func<int, T> selector)
    {
        return Enumerable.Range(0, count).Select(x => selector(x));
    }
}

//*/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using static System.Math;

namespace HackerRank
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums = Console.ReadLine().Split().Select(num => int.Parse(num)).ToArray();
            int n = nums[0]; //10
            int m = nums[1]; //3
            int a = nums[2]; //5
            int b = nums[3]; //1
            Console.WriteLine(a * m > b ? n / m * b + Min(n % m * a, b) : n * a);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Task_TD
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] lines = Console.ReadLine().Split(' ');

            int n = Int32.Parse(lines[0]);
            int m = Int32.Parse(lines[1]);
            int a = Int32.Parse(lines[2]);
            int b = Int32.Parse(lines[3]);

            Console.WriteLine(GetResult(n, m, a, b));

            Console.ReadLine();
        }

        static int GetResult(int n, int m, int a, int b)
        {
            if (b / m >= a)
            {
                return n * a;
            }

            int k = n / m;
            int rest = n % m;

            int res = Math.Min((k * b + rest * a), (k + 1) * b);
            return res;
        }

    }
}

using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

namespace Problem466A {
    class Program {
        static void Main(string[] args) {
            string[] input1 = Console.ReadLine().Split(' ');
            int numberOfRides = Convert.ToInt32(input1[0]);
            int numberOfRidesInMticket = Convert.ToInt32(input1[1]);
            int priceOfOneRideTicket = Convert.ToInt32(input1[2]);
            int priceOfMRideTicket = Convert.ToInt32(input1[3]);

            int priceUsingOnlyOneRideTicket = numberOfRides * priceOfOneRideTicket;

            int mRides = numberOfRides / numberOfRidesInMticket;
            int mRidesRest = numberOfRides % numberOfRidesInMticket;

            int priceUsingMRidesAndRest = 0;
            int priceUsingOnlyMRides = 0;
            if (mRidesRest != 0) {
                priceUsingMRidesAndRest = mRides * priceOfMRideTicket + mRidesRest * priceOfOneRideTicket;
                priceUsingOnlyMRides = (mRides + 1) * priceOfMRideTicket;
            } else {
                priceUsingMRidesAndRest = mRides * priceOfMRideTicket;
                priceUsingOnlyMRides = mRides * priceOfMRideTicket;
            }

            int minPrice = Math.Min(priceUsingOnlyOneRideTicket, Math.Min(priceUsingMRidesAndRest, priceUsingOnlyMRides));

            Console.WriteLine(minPrice);
        }
    }
}

using System;

class Program
{
static void Main()
    {
        string str = Console.ReadLine();
        string[] s = str.Split();
        int n = int.Parse(s[0]);
        int m = int.Parse(s[1]);
        int a = int.Parse(s[2]);
        int b = int.Parse(s[3]);

        double average = (double)b / m;
        if (average >= a)
        {
            Console.WriteLine(n * a);
            return;
        }
        else
        {
            int t = n / m; //целое число абонементов
            int sum = b * t;
            if ((a * (n - t * m)) < b) //если поштучно брать выгоднее
            {
                sum += a * (n - t * m);
            }
            else
            {
                sum += b;
            }
            Console.WriteLine(sum);
            return;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

class Program
{
    static void Main(string[] args)
    {
        var E = Enumerable.Select(Console.ReadLine().Split(' '), x => int.Parse(x.ToString())).ToArray();
        int n = E[0] , m = E[1], a = E[2], b = E[3];
        int FirstStep = a * n;
        int SecondStep = -345;
        if (n % m == 0)
        {
            SecondStep = n / m * b;
        }

        int ThirdStep = -345;

        int d = n % m, N = n;
        N -= d;
        ThirdStep = N / m * b; ThirdStep += (d * a);

        int ForthStep = -345;

        ForthStep = (int)Math.Ceiling(Convert.ToDouble(n) / Convert.ToDouble(m)) * b;

        var D = new int[] { FirstStep, SecondStep, ThirdStep,ForthStep }.Where(x=>x!=-345).Min();
        Console.WriteLine(D);
    }

    private static IEnumerable<string> Permutate(string source)
    {
        if (source.Length == 1) return new List<string> { source };

        var permutations = from c in source
                           from p in Permutate(new String(source.Where(x => x != c).ToArray()))
                           select c + p;

        return permutations;
    }

}

//private static IEnumerable<string> Permutate(string source)
//{
//    if (source.Length == 1) return new List<string> { source };

//    var permutations = from c in source
//                       from p in Permutate(new String(source.Where(x => x != c).ToArray()))
//                       select c + p;

//    return permutations;
//}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest7_12
{
    class Program
    {
        static void Main(string[] args)
        {
            //var input = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(k=> int.Parse(k)).ToArray();

            var noOfRides = input[0];
            var mticketNoOfRides = input[1];
            var priceOneRideTicket = input[2];
            var pricemRideTicket = input[3];

            var tickets = noOfRides / mticketNoOfRides;

            if (tickets == 0 && pricemRideTicket < (noOfRides * priceOneRideTicket))
            {
                Console.WriteLine(pricemRideTicket);
                return;
            }

            var ridesNeeded = (noOfRides - (tickets * mticketNoOfRides)) % mticketNoOfRides;

            var finalTotal1 = tickets * pricemRideTicket + ridesNeeded * priceOneRideTicket;

            //var finalTotal2 = tickets * pricemRideTicket + ridesNeeded * pricemRideTicket;

            var finalTotal2 = tickets * pricemRideTicket + 1 * pricemRideTicket;

            var finalTotal3 = noOfRides * priceOneRideTicket;

            var finalTotal = finalTotal1 > finalTotal2 ? finalTotal2 : finalTotal1;

            var superFinal = finalTotal < finalTotal3 ? finalTotal : finalTotal3;

            Console.WriteLine(superFinal);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');
            int n, m, a, b;
            n = int.Parse(str[0]);
            m = int.Parse(str[1]);
            a = int.Parse(str[2]);
            b = int.Parse(str[3]);
            ArrayList A = new ArrayList();

            int total = 0;

            total = (int)Math.Floor( (double)n/(double)m ) * b;
            total += (n % m) * a;
            A.Add(total);

            total = n * a;
            A.Add(total);

            total = total = (int)Math.Ceiling( (double)n / (double)m ) * b;
            A.Add(total);
            A.Sort();
            total = (int)A[0];

          //  if (total > n * a) { total = n * a; }

            Console.WriteLine(total);
           // Main(new string[0]) ;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _123
{
    class Program
    {
        static int N, M, A, B;
        static int res;
        static string[] count;

        static void Main(string[] args)
        {
            count = Console.ReadLine().Split();
            N = Convert.ToInt32(count[0]);
            M = Convert.ToInt32(count[1]);
            A = Convert.ToInt32(count[2]);
            B = Convert.ToInt32(count[3]);

            if (M * A <= B)
            {
                Console.WriteLine(N * A);
                return;
            }

            res += (N / M) * B;
            N %= M;
            res += Math.Min(N * A, B);

            Console.WriteLine(res);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Program{
    static void Main(string[] args){
        string[] input = Console.ReadLine().Split(' ');
        int ridesPlanned = Int32.Parse(input[0]);
        int ridesInSpecialTicket=Int32.Parse(input[1]);
        int priceForSingleRide= Int32.Parse(input[2]);
        int priceForSpecialRides=Int32.Parse(input[3]);

            if (ridesPlanned == 0)
                Console.WriteLine(0);
            else if (ridesInSpecialTicket == 0)
                Console.WriteLine(ridesPlanned * priceForSingleRide);

            else
            {
                if (ridesPlanned % ridesInSpecialTicket == 0)
                        Console.WriteLine((ridesPlanned * priceForSingleRide)< ((ridesPlanned / ridesInSpecialTicket) * priceForSpecialRides)? ridesPlanned * priceForSingleRide :(ridesPlanned / ridesInSpecialTicket) * priceForSpecialRides);
                else
                {
                    if (((ridesPlanned / ridesInSpecialTicket + 1) * priceForSpecialRides) < ((ridesPlanned / ridesInSpecialTicket) * priceForSpecialRides + (ridesPlanned % ridesInSpecialTicket) * priceForSingleRide))
                        Console.WriteLine((ridesPlanned / ridesInSpecialTicket + 1) * priceForSpecialRides);
                    else
                        Console.WriteLine(((ridesPlanned / ridesInSpecialTicket) * priceForSpecialRides + (ridesPlanned % ridesInSpecialTicket) * priceForSingleRide));
                }
            }

        }
}

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MakeCalendar
{
    public static class MainClass
    {

        static int ReadIntLine()
        {
            return int.Parse(Console.ReadLine());
        }

        static void ReadInt(ref int a)
        {
            a = ReadIntArrayLine()[0];
        }

        static void ReadInts(ref int a, ref int b)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1];
        }

        static void ReadInts(ref int a, ref int b, ref int c)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d, ref int e)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3]; e = x[4];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d, ref int e, ref int f)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3]; e = x[4]; f = x[5];
        }

        static int[] ReadIntArrayLine()
        {
            char[] sep = { ' ' };
            return Console.ReadLine().Split(sep, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static void PrintLn(object obj)
        {
            Console.WriteLine(obj.ToString());
        }

        public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }

        public static void PrintLnCollection<T>(IEnumerable<T> col)
        {
            PrintLn(string.Join(" ", col));
        }

        public static void PrintLn(params object[] v)
        {
            PrintLnCollection(v);
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static string MySubstring(this string str, int start, int finish)
        {
            if (start > finish) return "";
            return str.Substring(start, finish - start + 1);
        }

        public static bool IsInRange(this int a, int lb, int ub)
        {
            return (a >= lb) && (a <= ub);
        }

        private static void mergeDS(int i, int j, int[] a)
        {
            int t = a[j];
            for (int ii = 0; ii < a.Length; ii++)
            {
                if (a[ii] == t)
                    a[ii] = a[i];
            }
        }

        private static T MyMax<T>(params T[] a)
        {
            return a.Max();
        }

        private static T MyMin<T>(params T[] a)
        {
            return a.Min();
        }

        private static int[] GetPrimesLessThan(int x)
        {
            if (x < 2)
                return new int[0];

            int[] a = new int[x];

            a[0] = 1; a[1] = 1;

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == 0)
                    for (int j = 2 * i; j < a.Length; j += i)
                    {
                        a[j] = 1;
                    }
            }

            var abc = new List<int>(x);

            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] == 0)
                    abc.Add(i);
            }

            return abc.ToArray();
        }

        private static int FindNearestLEQElementInTheArray(int[] a, int startIndex, int endIndex, int target)
        {
            if (startIndex == endIndex)
            {
                if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            if (startIndex + 1 == endIndex)
            {
                if (a[endIndex] <= target)
                    return endIndex;
                else if (a[startIndex] <= target)
                    return startIndex;
                else
                    return -1;
            }

            int mid = (startIndex + endIndex) / 2;
            if (target == a[mid])
                return mid;
            else if (target < a[mid])
                return FindNearestLEQElementInTheArray(a, startIndex, mid - 1, target);
            else
                return FindNearestLEQElementInTheArray(a, mid, endIndex, target);
        }

        private static int FindNearestLEQElementInTheArray(int[] a, int target)
        {
            return FindNearestLEQElementInTheArray(a, 0, a.Length - 1, target);
        }

        private static int gcd(int a, int b)
        {
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        //----------------------------------------------------------------------------

        static void Main(string[] args)
        {
            int n = 0, m = 0,a=0,b=0;

            ReadInts(ref n, ref m, ref a, ref b);

            int w1 = n * a;
            int w2 = (int)Math.Ceiling((double)(n) / (double)m) * b;
            int w3 = (n / m) * b + (n % m) * a;

            PrintLn(MyMin(w1, w2, w3));

        }

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToList();

			var n = inputs1[0];
			var m = inputs1[1];
			var a = inputs1[2];
			var b = inputs1[3];

			if(n < m)
			{
				Console.WriteLine(Math.Min(b, n * a));
				return;
			}

			if(b < m * a)
			{
				var count = n / m;
				var rest = n % m;

				var adding = Math.Min(b, rest * a);

				Console.WriteLine(count * b + adding);
			}
			else
			{
				Console.WriteLine(n * a);
			}
		}

		//private static long GCD(long a, long b)
		//{
		//	long max = Math.Max(a, b);
		//	long min = Math.Min(a, b);

		//	if (min == 0)
		//	{
		//		return max;
		//	}

		//	a = min;
		//	b = max % min;
		//	return GCD(a, b);
		//}

		//private static long LCM(long a, long b)
		//{
		//	return Math.Abs(a * b) / GCD(a, b);
		//}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            int n, m, a, b;
            string[] strin1 = str1.Split(' ');
            n = int.Parse(strin1[0]);
            m = int.Parse(strin1[1]);
            a = int.Parse(strin1[2]);
            b = int.Parse(strin1[3]);
            int sumbil = n * a;
            if ((m > n) && (b <= sumbil))
            {
                Console.WriteLine(b);
            }
            if ((m > n) && (b >= sumbil))
            {
                Console.WriteLine(sumbil);
            }
            if (n / m == 1)
            {  if ((b + (n - m) * a <= sumbil))
            { Console.WriteLine(b + (n - m) * a); }
            else { Console.WriteLine(sumbil); }
            }
            if (n / m > 1) {
                if (b >= a)
                {
                    if ((b * (n / m) + (n - m * (n / m)) * a <= sumbil))
                    { Console.WriteLine(b * (n / m) + (n - m * (n / m)) * a); }
                    else { Console.WriteLine(sumbil); }
                }
                else
                {
                    if (n % m > 0) { Console.WriteLine(((n / m) + 1) * b); }
                    else { Console.WriteLine((n / m) * b); }

                }

            }

           Console.ReadLine();

        }

    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace CodeForcesProblems
{
    class A466_CheapTravel
    {
        public static void Main()
        {
            //while (true)
            //{
                string[] z = Console.ReadLine().Split(' ');
                int n = int.Parse(z[0]);
                int m = int.Parse(z[1]);
                int a = int.Parse(z[2]);
                int b = int.Parse(z[3]);
                double c =(double) b / m;
                if(c>a)
                {
                    Console.WriteLine(a*n);
                }
                else
                {
                    int t = n / m;
                    int result = (t * b);  //+((n-(t*m))*a);

                    if (((n - (t * m)) * a) > b)
                        result += b;
                    else
                        result += ((n - (t * m)) * a);

                    Console.WriteLine(result);
                }

            //}
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = Arr[0],
                m = Arr[1],
                a = Arr[2],
                b = Arr[3],
                sum = 0,
                count = 0,
                tmp = 0;

            while (count < n)
            {
               if (n >= count + m)
                {
                    if (b < m * a)
                    {
                        count += m;
                        sum += b;
                    }
                    else
                    {
                        count += m;
                        sum += m * a;
                    }
                }
               else
                {
                    if (b < (n - count) * a)
                    {
                        count += m;
                        sum += b;
                    }
                    else
                    {
                        sum += (n - count) * a;
                        count += (n - count);
                    }
                }
            }

            Console.WriteLine(sum);
            Console.ReadLine();
        }
    }
}

using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nmab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = nmab[0];
            int m = nmab[1];
            int a = nmab[2];
            int b = nmab[3];

            int x = 0;

            if (n % m == 0)
            {
                x = n / m;
            }
            else
            {
                x = (n / m) + 1;
            }

            int ans = Math.Min(x * b, ((n / m) * b + (n % m) * a));
            ans = Math.Min(n * a, ans);

            Console.WriteLine(ans);

            Console.Read();
        }
    }
}

using System;

// Codeforces problem 466A "Выгодный проезд"
// http://codeforces.com/problemset/problem/466/A
namespace _466_A
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] data = Console.ReadLine().Split();
			int n = Convert.ToInt32(data[0]); // Кол-во поездок.
			int m = Convert.ToInt32(data[1]); // Кол-во поездок одного абонимента.
			int a = Convert.ToInt32(data[2]); // Цена одного проезда.
			int b = Convert.ToInt32(data[3]); // Цена абонимента.

			int minCost = 0;

			// === HAZARD - wrong understanding  === {
			//if ((double)b / m < a)
			//{
			//	int numberOfSubscriptionTrips = n / m;
			//	minCost += numberOfSubscriptionTrips * b;
			//	minCost += (n - numberOfSubscriptionTrips * m) * a;
			//}
			//else
			//{
			//	minCost += n * a;
			//}
			// } === HAZARD - wrong understanding ===

			int cost1 = n * a;
			int cost2 = ((int)Math.Ceiling((double)n / m)) * b;
			int numberOfSubscriptionTrips = n / m;
			int cost3 = numberOfSubscriptionTrips * b;
			cost3 += (n - numberOfSubscriptionTrips * m) * a;

			minCost = Math.Min(cost1, Math.Min(cost2, cost3));

			Console.WriteLine(minCost);
			//Console.ReadLine();
		}
	}
}

// Author : Suvash Kumar Sumon

using System;

namespace CS_Repo
{
    class Program2
    {
        static void Main(string [] args)
        {
            var data = Console.ReadLine().Split(' ');
            int n = int.Parse(data[0]);
            int m = int.Parse(data[1]);
            int a = int.Parse(data[2]);
            int b = int.Parse(data[3]);
            if (m * a <= b)
            {
                Console.WriteLine(n*a);
            }
            else
            {
                int ans = (n/m) * b + Math.Min((n%m) * a, b);
                Console.WriteLine(ans);
            }

        }
    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ladder4
{
    class Prob21
    {
        static void Main(string[] args)
        {
            List<int> input = Console.ReadLine().Split(' ').Select(alias => int.Parse(alias)).ToList();
            int rides = input[0];
            int loop = rides;
            int multipleRides = input[1];
            int oneRide = input[2];
            int multiplePrice = input[3];
            int sum = 0;

            if (multipleRides * oneRide < multiplePrice)
                Console.WriteLine(loop * oneRide);
            else
            {
                int x = loop / multipleRides * multiplePrice;
                int restRides = loop % multipleRides;
                if (restRides * oneRide > multiplePrice)
                    x += multiplePrice;
                else
                    x += restRides * oneRide;
                Console.WriteLine(x);
            }
            //while (true) ;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int a = int.Parse(s[2]);
            int b = int.Parse(s[3]);
            int t = b <= m * a ? (n / m * b + Math.Min(n % m * a, b)) : (n * a);
            Console.Write(t);
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cheaptravel
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Array.ConvertAll(Console.ReadLine().Split(' '), Int32.Parse);
            int n = x[0];
            int m = x[1];
            int a = x[2];
            int b = x[3];
            int single = n * a;
            int multi;

            //if (m > n)
            //{
            //    multi = b;
            //}
            //else

            multi = ((n / m) * b) + Math.Min(b, (n % m) * a);

            Console.WriteLine(Math.Min(single, multi));
            Console.ReadLine();
        }
    }
}

using System;

namespace CheapTravel
{
    class Program
    {
        static void Main(string[] args)
        {
            string [] input  = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.None);

            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int a = int.Parse(input[2]);
            int b = int.Parse(input[3]);

            long f1 = n * a;

            int i=0;
            long f2 = 0;
            while(i<=n){
                if (i+m > n){
                    break;
                }
                f2 += b;
                i+= m;
            }
            f2 += (n-i) * a;

            i=0;
            long f3 = 0;
            while(i<=n){
                f3 += b;
                i+= m;
            }

            Console.WriteLine(Math.Min(Math.Min(f1, f2), f3));

        }
    }
}

using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;

namespace Codeforces
{
    class Program
    {
        private static string readString() => Console.ReadLine();
        private static T readValue<T>() => (T)Convert.ChangeType(readString(), typeof(T));
        private static string[] readStrings(char delimiter = ' ') => readString().Split(delimiter);
        private static T[] readValues<T>(char delimiter = ' ') => readStrings(delimiter: delimiter).Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
        private static void write<T>(T s) => Console.WriteLine(s);

        private static int binarySearch<T>(List<T> list, T target) where T : IComparable
        {
            int l = 0, r = list.Count - 1;
            while (l <= r)
            {
                var m = (int)Math.Floor((double)(l + r) / 2);
                if (list[m].CompareTo(target) <= 0)
                    if (m == r || list[m + 1].CompareTo(target) > 0)
                        return m;
                    else
                        l = m + 1;
                else
                    r = m - 1;
            }
            return -1;
        }

        private static int quickSortPartition<T>(List<T> list, int left, int right) where T : IComparable
        {
            T pivot = list[left];
            while (true)
            {
                while (list[left].CompareTo(pivot) < 0)
                    left++;
                while (list[right].CompareTo(pivot) > 0)
                    right--;
                if (left < right)
                {
                    if (list[left].CompareTo(list[right]) == 0)
                        return right;

                    T temp = list[left];
                    list[left] = list[right];
                    list[right] = temp;
                }
                else
                    return right;
            }
        }
        private static void quickSort<T>(List<T> list, int left, int right) where T : IComparable
        {
            if (left < right)
            {
                int pivot = quickSortPartition(list, left, right);
                if (pivot > 1)
                    quickSort(list, left, pivot - 1);
                if (pivot + 1 < right)
                    quickSort(list, pivot + 1, right);
            }
        }
        private static void quickSort<T>(List<T> list) where T : IComparable => quickSort(list, 0, list.Count - 1);

        private static void watermelon()
        {
            var w = readValue<int>();
            write(w >= 4 && w % 2 == 0 ? "YES" : "NO");
        }
        private static void wayTooLongWords()
        {
            var words = new List<string>();

            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
                words.Add(readString());

            foreach (var word in words)
                write(word.Length <= 10 ? word : $"{word.First()}{word.Length - 2}{word.Last()}");
        }
        private static void team()
        {
            int solve = 0;

            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
                if (readValues<int>().Where(x => x == 1).Count() > 1)
                    ++solve;

            write(solve);
        }
        private static void football()
        {
            var positions = readString();
            for (int i = 6; i < positions.Length; ++i)
                if (positions.Substring(i - 6, 6) == (positions[i] == '0' ? "000000" : "111111"))
                {
                    write("YES");
                    return;
                }
            write("NO");
        }
        private static void theatreSquare()
        {
            var sizes = readValues<int>();
            write((long)Math.Ceiling((double)sizes[0] / (double)sizes[2]) * (long)Math.Ceiling((double)sizes[1] / (double)sizes[2]));
        }
        private static void stringTask()
        {
            var Vowels = new HashSet<char> { 'a', 'o', 'y', 'e', 'u', 'i' };
            var sb = new StringBuilder();
            var s = readString().ToLower();
            foreach (var c in s)
                if (!Vowels.Contains(c))
                {
                    sb.Append('.');
                    sb.Append(c);
                }

            write(sb.ToString());
        }
        private static void taxi()
        {
            int taxis = 0;
            var groups = new Dictionary<int, int> { { 1, 0 }, { 2, 0 }, { 3, 0 } };

            readValue<int>();
            var groupSizes = readValues<int>();
            foreach (var size in groupSizes)
                if (size == 4)
                    ++taxis;
                else
                    groups[size] = groups[size] + 1;

            taxis += groups[3];
            groups[1] = groups[1] - Math.Min(groups[1], groups[3]);

            taxis += groups[2] / 2;
            if (groups[2] % 2 == 1)
            {
                ++taxis;
                groups[1] = groups[1] - 2;
            }

            if (groups[1] > 0)
                taxis += (int)Math.Ceiling((double)groups[1] / 4.0);

            write(taxis);
        }
        private static void fancyFence()
        {
            var a = readValue<int>();
            for (double i = 3.0; ; i += 1.0)
            {
                var x = (double)(i - 2.0) * 180.0 / i;
                if (a <= x)
                {
                    write(a < x ? "NO" : "YES");
                    break;
                }
            }
        }
        private static void interestingDrink()
        {
            readString();
            var prices = readValues<int>().OrderBy(x => x).ToList();
            var days = readValue<int>();
            for (int i = 0; i < days; ++i)
                write(binarySearch(prices, readValue<int>()) + 1);
        }
        private static void compilationErrors()
        {
            readString();
            Dictionary<int, int> errors = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()), errors1 = new Dictionary<int, int>();
            foreach (var error in readValues<int>())
            {
                if (errors[error] > 1)
                    errors[error] = errors[error] - 1;
                else
                    errors.Remove(error);

                if (errors1.TryGetValue(error, out var count))
                    errors1[error] = count + 1;
                else
                    errors1.Add(error, 1);
            }
            write(errors.First().Key);

            foreach (var error in readValues<int>())
                if (errors1[error] > 1)
                    errors1[error] = errors1[error] - 1;
                else
                    errors1.Remove(error);
            write(errors1.First().Key);
        }
        private static void doubleCola()
        {
            var idToName = new Dictionary<int, string> { { 0, "Sheldon" }, { 1, "Leonard" }, { 2, "Penny" }, { 3, "Rajesh" }, { 4, "Howard" } };
            int n = readValue<int>(), i = 1;
            for (; n > i * 5; i *= 2)
                n -= i * 5;
            write(idToName[(n - 1) / i]);
        }
        private static void ilyaAndQueries()
        {
            var dic = new Dictionary<int, int>();
            var list = new List<Tuple<int, int>>();

            var s = readString();
            int start = 0, dicStart = 0;
            for (int j = 0; j < s.Length - 1; ++j)
                if (s[j] != s[j + 1])
                {
                    if (start < j)
                    {
                        list.Add(new Tuple<int, int>(start + 1, j + 1));
                        for (; dicStart < j + 1; ++dicStart)
                            dic.Add(dicStart, list.Count - 1);
                    }
                    start = j + 1;
                }
            if (start < s.Length - 1)
            {
                list.Add(new Tuple<int, int>(start + 1, s.Length));
                for (; dicStart < s.Length; ++dicStart)
                    dic.Add(dicStart, list.Count - 1);
            }

            var m = readValue<int>();
            for (int j = 0; j < m; ++j)
            {
                var q = readValues<int>();
                int l = q[0], r = q[1], result = 0;
                if (dic.TryGetValue(l, out var i))
                    for (; i < list.Count && r >= list[i].Item1; ++i)
                        if (l < list[i].Item2)
                            result += Math.Min(r, list[i].Item2) - Math.Max(l, list[i].Item1);
                write(result);
            }
        }
        private static void twoTeamsComposing()
        {
            var n = readValue<int>();
            var skills = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
        }
        #region Laptop
        private class Laptop
        {
            internal int Price { get; private set; }
            internal int Quality { get; private set; }
            internal Laptop(int[] values)
            {
                Price = values[0];
                Quality = values[1];
            }
        }
        private class Laptop_Comparer_Price : Comparer<Laptop>
        {
            public override int Compare([AllowNull] Laptop x, [AllowNull] Laptop y) => x.Price - y.Price;
        }
        private class Laptop_Comparer_Quality : Comparer<Laptop>
        {
            public override int Compare([AllowNull] Laptop x, [AllowNull] Laptop y) => x.Quality - y.Quality;
        }
        private static void laptops()
        {
            List<Laptop> prices = new List<Laptop>(), qualities = new List<Laptop>();
            var n = readValue<int>();
            for (int i = 0; i < n; ++i)
            {
                var laptop = new Laptop(readValues<int>());
                prices.Add(laptop);
                qualities.Add(laptop);
            }

            for (int i = 0; i < n; ++i)
                if (prices[i] != qualities[i])
                {
                    write("Happy Alex");
                    return;
                }
            write("Poor Alex");
        }
        #endregion
        private static void fence()
        {
            int k = readValues<int>()[1], minI = 0, currentH = 0;
            int[] h = readValues<int>();

            for (int i = 0; i < k; ++i)
                currentH += h[i];
            var minH = currentH;

            for (int i = 1; i < h.Length - k + 1; ++i)
            {
                currentH = currentH - h[i - 1] + h[i + k - 1];
                if (minH > currentH)
                {
                    minH = currentH;
                    minI = i;
                }
            }

            write(minI + 1);
        }
        #region serejaAndSuffixes
        private class SerejaL : IComparable
        {
            internal int L { get; private set; }
            internal int Result;
            internal SerejaL(int l)
            {
                L = l;
            }

            public int CompareTo(object obj) => L - ((SerejaL)obj).L;
        }
        private static void serejaGetLs(int m, out List<SerejaL> listDistinct, out List<SerejaL> listOrdered)
        {
            listDistinct = new List<SerejaL>();
            listOrdered = new List<SerejaL>();
            var dic = new Dictionary<int, SerejaL>();
            for (int i = 0; i < m; ++i)
            {
                var l = readValue<int>() - 1;
                if (!dic.TryGetValue(l, out var item))
                {
                    item = new SerejaL(l);
                    dic.Add(l, item);
                    listDistinct.Add(item);
                }
                listOrdered.Add(item);
            }
            quickSort(listDistinct);
        }
        private static void serejaAndSuffixes()
        {
            var m = readValues<int>()[1];
            var a = readValues<int>();
            serejaGetLs(m, out var listDistinct, out var listOrdered);

            var distinct = new HashSet<int>();
            for (int i = listDistinct.Count - 1, j = a.Length - 1; i >= 0; --i)
            {
                for (; j >= listDistinct[i].L; --j)
                    if (!distinct.Contains(a[j]))
                        distinct.Add(a[j]);

                listDistinct[i].Result = distinct.Count;
            }

            foreach (var item in listOrdered)
                write(item.Result);
        }
        #endregion
        private static void bowWowTimetable()
        {
            string s = readString(), r = "1";
            int i = 1;
            for (; r.Length < s.Length; ++i, r = r + "00") ;
            if (r.Length > s.Length || !s.Substring(1).Contains('1'))
                write(i - 1);
            else
                write(i);
        }
        private static void digits()
        {
            readString();
            var numbers = readValues<int>().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
            if (!numbers.ContainsKey(0))
            {
                write(-1);
                return;
            }
        }
        private static void lifeWithoutZeros()
        {
            long a = readValue<int>(), b = readValue<int>(), c = a + b;
            write(Convert.ToInt64(a.ToString().Replace("0", "")) + Convert.ToInt64(b.ToString().Replace("0", "")) == Convert.ToInt64(c.ToString().Replace("0", "")) ? "YES" : "NO");
        }
        private static void permutation()
        {
            var n = readValue<int>();
            var a = readValues<int>();
            write(n - a.Where(x => x <= n).Distinct().Count());
        }
        private static void hamsterFarm()
        {
            var n = readValues<long>()[0];
            var k = readValues<long>();
            int bestI = 0;
            for (int i = 1; i < k.Length; ++i)
                if (n % k[i] < n % k[bestI])
                    bestI = i;
            write($"{bestI + 1} {n / k[bestI]}");
        }
        private static void shellGame()
        {
            int n = readValue<int>(), x = readValue<int>();
            if (x == 1)
            {
                if (n % 2 == 1)
                    x = 0;
                else
                    x = 2;
                --n;
            }
            for (int i = n % 6; i > 0; --i)
                if (i % 2 == 1)
                {
                    if (x == 0)
                        x = 1;
                    else if (x == 1)
                        x = 0;
                }
                else if (x == 1)
                    x = 2;
                else if (x == 2)
                    x = 1;
            write(x);
        }
        private static void ACM_ICPC()
        {
            int[] a = readValues<int>(), score = new int[2], members = new int[2];
            for (int i1 = 0; i1 < 2; ++i1)
            {
                score[i1] = a[0];
                members[i1] = 1;
                for (int i2 = 0; i2 < 2; ++i2)
                {
                    score[i2] += a[1];
                    members[i2] += 1;
                    for (int i3 = 0; i3 < 2; ++i3)
                    {
                        score[i3] += a[2];
                        members[i3] += 1;
                        for (int i4 = 0; i4 < 2; ++i4)
                            if (members[i4] < 3)
                            {
                                score[i4] += a[3];
                                members[i4] += 1;
                                for (int i5 = 0; i5 < 2; ++i5)
                                    if (members[i5] < 3)
                                    {
                                        score[i5] += a[4];
                                        members[i5] += 1;
                                        for (int i6 = 0; i6 < 2; ++i6)
                                            if (members[i6] < 3)
                                            {
                                                score[i6] += a[5];
                                                members[i6] += 1;
                                                if (score[0] == score[1])
                                                {
                                                    write("YES");
                                                    return;
                                                }
                                                score[i6] -= a[5];
                                                members[i6] -= 1;
                                            }
                                        score[i5] -= a[4];
                                        members[i5] -= 1;
                                    }
                                score[i4] -= a[3];
                                members[i4] -= 1;
                            }
                        score[i3] -= a[2];
                        members[i3] -= 1;
                    }
                    score[i2] -= a[1];
                    members[i2] -= 1;
                }
                score[i1] = 0;
                members[i1] = 0;
            }
            write("NO");
        }
        private static void mex()
        {
            var x = readValues<int>()[1];
            var n = readValues<int>();
            write(x - n.Count(y => y < x) + (n.Contains(x) ? 1 : 0));
        }
        private static void minimumProduct()
        {
            var input = readValues<int>();
            int a = input[0], b = input[1], x = input[2], y = input[3], n = input[4], minA = Math.Min(a - x, n), minB = Math.Min(b - y, n);
            if (a - minA <= b - minB)
            {
                a -= minA;
                n -= minA;
            }
            else
            {
                b -= minB;
                n -= minB;
            }

            if (n > 0)
                if (a > x)
                    a -= Math.Min(a - x, n);
                else if (b > y)
                    b -= Math.Min(b - y, n);

            write((long)a * (long)b);
        }
        private static void shovelsAndSwords()
        {
            var input = readValues<int>();
            int a = input[0], b = input[1], result = 0;
            if (a > b)
            {
                var min = Math.Min(a - b, b);
                a -= min * 2;
                b -= min;
                result += min;
            }
            else if (b > a)
            {
                var min = Math.Min(b - a, a);
                a -= min;
                b -= min * 2;
                result += min;
            }
            int d = Math.Min(a / 3, b / 3);
            a -= d * 3;
            b -= d * 3;
            result += d * 2;
            if (a > 0 && b > 0 && (a > 1 || b > 1))
                ++result;
            write(result);
        }
        private static void matrixGame()
        {
            var input = readValues<int>();
            int n = input[0], m = input[1];
            HashSet<int> claimedRows = new HashSet<int>(), claimedColumns = new HashSet<int>();
            for (int i = 0; i < n; ++i)
            {
                input = readValues<int>();
                for (int j = 0; j < m; ++j)
                    if (input[j] == 1)
                    {
                        if (!claimedRows.Contains(i))
                            claimedRows.Add(i);
                        if (!claimedColumns.Contains(j))
                            claimedColumns.Add(j);
                    }
            }
            write(Math.Min(n - claimedRows.Count, m - claimedColumns.Count) % 2 == 0 ? "Vivek" : "Ashish");
        }
        private static void cinemaLine()
        {
            readString();
            var clerk = new Dictionary<int, int> { { 25, 0 }, { 50, 0 } };
            foreach (var a in readValues<int>())
                switch (a)
                {
                    case 25:
                        clerk[25] += 1;
                        break;
                    case 50:
                        if (clerk[25] > 0)
                        {
                            clerk[25] -= 1;
                            clerk[50] += 1;
                        }
                        else
                        {
                            write("NO");
                            return;
                        }
                        break;
                    default: // 100
                        if (clerk[50] > 0 && clerk[25] > 0)
                        {
                            clerk[25] -= 1;
                            clerk[50] -= 1;
                        }
                        else if (clerk[25] > 2)
                            clerk[25] -= 3;
                        else
                        {
                            write("NO");
                            return;
                        }
                        break;
                }
            write("YES");
        }
        private static void kindAnton()
        {
            readString();
            int[] a = readValues<int>(), b = readValues<int>();
            bool positive1 = false, negative1 = false;
            HashSet<int> positive = new HashSet<int>(), negative = new HashSet<int>();
            for (int i = 0; i < a.Length; ++i)
            {
                int diff = b[i] - a[i];
                if (((diff > 0 && !positive1) || (diff < 0 && !negative1)) && !(diff > 0 ? positive : negative).Any(x => diff % x == 0))
                {
                    write("NO");
                    return;
                }
                if (a[i] > 0)
                {
                    if (!positive1)
                        if (a[i] == 1)
                        {
                            positive1 = true;
                            if (negative1)
                            {
                                write("YES");
                                return;
                            }
                        }
                        else if (!positive.Contains(a[i]))
                            positive.Add(a[i]);
                }
                else if (a[i] < 0 && !negative1)
                    if (a[i] == -1)
                    {
                        negative1 = true;
                        if (positive1)
                        {
                            write("YES");
                            return;
                        }
                    }
                    else if (!negative.Contains(a[i]))
                        negative.Add(a[i]);
            }
            write("YES");
        }
        private static void staircases()
        {
            var input = readValues<int>();
            int n = input[0], mn = input[1];
            if (mn == 0)
            {
                write("YES");
                return;
            }
            var m = readValues<int>().OrderBy(x => x).ToList();
            if (m[0] == 1 || m[m.Count - 1] == n)
            {
                write("NO");
                return;
            }
            for (int i = 0; i < m.Count - 2; ++i)
                if (m[i] == m[i + 1] - 1 && m[i] == m[i + 2] - 2)
                {
                    write("NO");
                    return;
                }
            write("YES");
        }
        private static void blownGarland()
        {
            var colors = new Dictionary<char, int> { { 'R', 0 }, { 'Y', 0 }, { 'B', 0 }, { 'G', 0 } };
            var s = readString();

            var colorPerPosition = new char[4];
            foreach (var color in colors)
                colorPerPosition[s.IndexOf(color.Key) % 4] = color.Key;

            for (int i = 0; i < s.Length; ++i)
                if (s[i] == '!')
                    colors[colorPerPosition[i % 4]] += 1;

            write($"{colors['R']} {colors['B']} {colors['Y']} {colors['G']}");
        }
        private static void mikeAndFax()
        {
            var s = readString();
            int k = readValue<int>();

            if (s.Length % k != 0)
            {
                write("NO");
                return;
            }

            int size = s.Length / k;
            for (int i = 0; i < s.Length; i += size)
                for (int j1 = i + size / 2 - 1, j2 = i + size / 2 + size % 2; j1 >= i; --j1, ++j2)
                    if (s[j1] != s[j2])
                    {
                        write("NO");
                        return;
                    }

            write("YES");
        }
        #region weirdRounding
        private static bool weirdRounding_Recursion(string ns, int kp, int d)
        {
            if (d > 0)
                for (int i = ns[1] == '0' && ns.Length > 2 ? 1 : 0; i < ns.Length; ++i)
                {
                    string nsNew = ns.Remove(i, 1);
                    int n = Convert.ToInt32(nsNew);
                    if (n % kp == 0 || weirdRounding_Recursion(nsNew, kp, d - 1))
                        return true;
                }
            return false;
        }
        private static void weirdRounding()
        {
            var input = readStrings();
            string ns = input[0];
            int n = Convert.ToInt32(ns), k = Convert.ToInt32(input[1]), kp = (int)Math.Pow(10, k);

            if (n < kp)
                write(ns.Length - 1);
            else if (n % kp == 0)
                write(0);
            else
                for (int d = 1; d < ns.Length; ++d)
                    if (weirdRounding_Recursion(ns, kp, d))
                    {
                        write(d);
                        return;
                    }
        }
        #endregion
        private static void wilburArray()
        {
            readString();
            int[] b = readValues<int>();
            long result = Math.Abs(b[0]);
            for (int i = 1; i < b.Length; ++i)
                result += Math.Abs(b[i] - b[i - 1]);
            write(result);
        }
        private static void zuhairStrings()
        {
            int k = readValues<int>()[1];
            var s = readString();
            var result = new Dictionary<char, int>();

            for (int i = 0; i < s.Length - k + 1;)
            {
                int j = i + 1;
                for (; j < i + k && s[i] == s[j]; ++j) ;
                if (j == i + k)
                    if (!result.ContainsKey(s[i]))
                        result.Add(s[i], 1);
                    else
                        result[s[i]] += 1;
                i = j;
            }

            write(result.Count > 0 ? result.Max(x => x.Value) : 0);
        }
        private static void artfulExpedient()
        {
            var n = readValue<int>();
            int[] x = readValues<int>(), y = readValues<int>();
            var numbers = x.Union(y).ToHashSet();
            var resultEven = true;

            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    if (numbers.Contains(x[i] ^ y[j]))
                        resultEven = !resultEven;

            write(resultEven ? "Karen" : "Koyomi");
        }
        private static void ebonyIvory()
        {
            var input = readValues<int>();
            int a = input[0], b = input[1], c = input[2];
            if (a < b)
            {
                var t = a;
                a = b;
                b = t;
            }
            for (; c >= 0; c -= a)
                if (c % b == 0)
                {
                    write("Yes");
                    return;
                }
            write("No");
        }
        #region Lala Land Apple Trees
        private class LalaLand_AppleTree : IComparable
        {
            private int coordinate;
            internal int Apples { get; private set; }
            internal LalaLand_AppleTree(int coordinate, int apples)
            {
                this.coordinate = coordinate;
                Apples = apples;
            }
            public int CompareTo(object obj) => coordinate - ((LalaLand_AppleTree)obj).coordinate;
        }
        private static void lalaLandAppleTrees()
        {
            var n = readValue<int>();
            List<LalaLand_AppleTree> right = new List<LalaLand_AppleTree>(), left = new List<LalaLand_AppleTree>();
            for (int i = 0; i < n; ++i)
            {
                var input = readValues<int>();
                if (input[0] > 0)
                    right.Add(new LalaLand_AppleTree(input[0], input[1]));
                else
                    left.Add(new LalaLand_AppleTree(-input[0], input[1]));
            }

            if (Math.Abs(right.Count - left.Count) < 2)
                write(right.Sum(x => x.Apples) + left.Sum(x => x.Apples));
            else
            {
                quickSort(right);
                quickSort(left);
                if (right.Count > left.Count)
                    write(right.GetRange(0, left.Count + 1).Sum(x => x.Apples) + (left.Count > 0 ? left.Sum(x => x.Apples) : 0));
                else
                    write((right.Count > 0 ? right.Sum(x => x.Apples) : 0) + left.GetRange(0, right.Count + 1).Sum(x => x.Apples));
            }
        }
        #endregion
        private static void lanterns()
        {
            int l = readValues<int>()[1], d = 0;
            var a = readValues<int>().Distinct().ToList();
            quickSort(a);
            for (int i = 0; i < a.Count - 1; ++i)
            {
                var diff = a[i + 1] - a[i];
                if (diff > d)
                    d = diff;
            }
            if (a[0] > 0 && a[a.Count - 1] < l)
                write(Math.Max(Math.Max(a[0] - 0, l - a[a.Count - 1]), d / 2.0));
            else if (a[0] > 0)
                write(Math.Max(a[0] - 0, d / 2.0));
            else if (a[a.Count - 1] < l)
                write(Math.Max(l - a[a.Count - 1], d / 2.0));
            else
                write((double)d / 2.0);
        }
        private static void cheapTravel()
        {
            var input = readValues<int>();
            int n = input[0], m = input[1], a = input[2], b = input[3];
            if (b >= a * m)
                write(n * a);
            else
                write((n / m) * b + ((n % m) * a < b ? (n % m) * a : b));
        }

        static void Main(string[] args)
        {
            //var t = readValue<int>();
            //for (int i = 0; i < t; ++i)
            cheapTravel();
        }
    }
}

using System;

class Program
{
static void Main()
    {
        string str = Console.ReadLine();
        string[] s = str.Split();
        int n = int.Parse(s[0]);
        int m = int.Parse(s[1]);
        int a = int.Parse(s[2]);
        int b = int.Parse(s[3]);

        double average = (double)b / m;
        if (average >= a)
        {
            Console.WriteLine(n * a);
            return;
        }
        else
        {
            int t = n / m; //целое число абонементов
            int sum = b * t;
            if ((a * (n - t * m)) < b) //если поштучно брать выгоднее
            {
                sum += a * (n - t * m);
            }
            else
            {
                sum += b;
            }
            Console.WriteLine(sum);
            return;
        }
    }
}

using System;
using System.Linq;
using System.Collections.Generic;

namespace CodeForces
{
	class Program
	{
		public static void Main(string[] args)
		{
			CheapTravel();
		}
		static void CheapTravel(){
			string[] s = Console.ReadLine().Split();
			int n = int.Parse(s[0]);//Rides to make
			int m = int.Parse(s[1]);//special number of rides
			int a = int.Parse(s[2]);//price for normal ticket
			int b = int.Parse(s[3]);//price for special ( m Tickets)
			int k = n%m == 0 ? n/m : n/m+1;
			Console.WriteLine(Math.Min(n*a,Math.Min(k*b,(n/m*b+n%m*a))));
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestPlace
{
    class Program
    {
        static void Main(string[] args)
        {
            var t = Console.ReadLine();
            var z = t.Split(' ');
            int[] g = new int[4];
            for(var i=0;i<z.Length;i++)
            {
                g[i] = Convert.ToInt32(z[i]);
            }
            var n = g[0];
            var m = g[1];
            var a = g[2];
            var b = g[3];
            var total = 0;
            double perRide = b / m;
            if(perRide<a)
            {
                var r = n / m;
                total = b * r;
                if ((n - r * m) * a < b)
                    total = total + (n - r * m) * a;
                else
                    total = total + b;
            }
            else
            {
                total = n * a;
            }
            Console.WriteLine(total);
        }
    }
}

using System;
using System.Collections;
using System.Linq;

namespace mainnm
{
    class main
    {
        static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        struct Notebook {
            public int price;
            public int quality;
        }

        static void Main()
        {
            int[] ts = Console.ReadLine().Split(' ').Select(num => Int32.Parse(num)).ToArray();

            int n = ts[0];
            int m = ts[1];
            int a = ts[2];
            int b = ts[3];

            if (((float)b)/m > a) {
                Console.WriteLine(n * a);
            } else {
                int ost = n % m;
                int sum = (n / m) * b;

                if (ost * a > b) {
                    sum += b;
                } else  {
                    sum += ost * a;
                }

                Console.WriteLine(sum);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace challenges
{
    class Program
    {

        static int N, M, A, B;
        static int res;
        static string[] phr;

        static void Main()
        {
            phr = Console.ReadLine().Split();

            N = Convert.ToInt32(phr[0]);
            M = Convert.ToInt32(phr[1]);
            A = Convert.ToInt32(phr[2]);
            B = Convert.ToInt32(phr[3]);

            if (M * A <= B)
            {
                Console.WriteLine(N * A);
                return;
            }

            res += (N / M) * B;
            N %= M;
            res += Math.Min(N * A, B);

            Console.WriteLine(res);
        }

     }
}

using System;
using System.IO;

namespace CF270
{
    class Program
    {
        static void Main(string[] args)
        {
            Solution(Console.In, Console.Out);
        }

        static void Solution(TextReader sr, TextWriter sw)
        {
            string[] input = sr.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
            int n = Int32.Parse(input[0]);
            int m = Int32.Parse(input[1]);
            int a = Int32.Parse(input[2]);
            int b = Int32.Parse(input[3]);
            var ceil = (int) Math.Ceiling((double) n/m);
            var floor = (int) Math.Floor((double) n/m);
            int first = ceil*b;
            int second = floor*b + a*(n - floor * m);
            int third = n*a;
            sw.WriteLine(Math.Min(first, Math.Min(second, third)));
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _466A
{
    class Program
    {
        static void Main(string[] args)
        {
            var numbers = Console.ReadLine().Split();
            int n = Convert.ToInt32(numbers[0]);
            int m = Convert.ToInt32(numbers[1]);
            int a = Convert.ToInt32(numbers[2]);
            int b = Convert.ToInt32(numbers[3]);
            if (m * a < b)
            {
                Console.WriteLine(n * a);
            }
            else
            {
                int cm = 0;
                while (cm < n)
                {
                    cm += m;
                }
                if (cm == n)
                {
                    Console.WriteLine(cm / m * b);
                }
                else
                {
                    if ((cm / m * b) > (((cm - m) / m * b) + (n - (cm - m)) * a))
                    {
                        Console.WriteLine(((cm - m) / m * b) + (n - (cm - m)) * a);
                    }
                    else
                    {
                        Console.WriteLine(cm / m * b);
                    }
                }
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            int[] n = Array.ConvertAll(s, int.Parse);

            if ((n[1] * n[2]) > n[3])
            {

                if (((n[0] % n[1]) * n[2]) > n[3])
                {
                    Console.WriteLine(n[0] / n[1] * n[3] + n[3]);
                }
                else
                {
                    Console.WriteLine(n[0] / n[1] * n[3] + ((n[0] % n[1]) * n[2]));
                }
            }
            else
            {
                Console.WriteLine(n[0] * n[2]);
            }
        }
    }
}

using System;

namespace Competitions
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = Convert.ToInt32(input.Split(' ')[0]);
            int m = Convert.ToInt32(input.Split(' ')[1]);
            int a = Convert.ToInt32(input.Split(' ')[2]);
            int b = Convert.ToInt32(input.Split(' ')[3]);
            int min = 0;
            while (n != 0)
            {
                if ((n >= m && b <= a * m) || ( n < m && b < a) ||( n < m && b < n) )
                {
                    min += b;
                    if (n - m < 0)
                        n = 0;
                    else
                        n -= m;
                }
                else
                {
                    min += a;
                    n -= 1;
                }

            }
            Console.WriteLine(min);
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;

namespace prA {

    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter("output");
        private static readonly StreamReader reader = new StreamReader("input");
#endif
        static void Main(string[] args) {
            int n = Next();
            int m = Next();
            int a = Next();
            int b = Next();
            int ans = 0;
            int d = a * m > b ? n / m : 0;
            ans += d * b;
            n -= d * m;
            ans += Math.Min(n * a, ((n / m) + 1) * b);
            writer.WriteLine(ans);

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Linq;

namespace tren
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] mass = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int min = Math.Min(mass[0]* mass[2], mass[0]/mass[1]*mass[3] + mass[0] % mass[1]*mass[2]);
            Console.Write(Math.Min(min, (Math.Ceiling((double)mass[0] / (double)mass[1])) * mass[3]));
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = Arr[0],
                m = Arr[1],
                a = Arr[2],
                b = Arr[3],
                sum = 0,
                count = 0,
                tmp = 0;

            while (count < n)
            {
               if (n >= count + m)
                {
                    if (b < m * a)
                    {
                        count += m;
                        sum += b;
                    }
                    else
                    {
                        count += m;
                        sum += m * a;
                    }
                }
               else
                {
                    if (b < (n - count) * a)
                    {
                        count += m;
                        sum += b;
                    }
                    else
                    {
                        sum += (n - count) * a;
                        count += (n - count);
                    }
                }
            }

            Console.WriteLine(sum);
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(s[0]);
            int m = Convert.ToInt32(s[1]);
            int a = Convert.ToInt32(s[2]);
            int b = Convert.ToInt32(s[3]);
            int s1;
            if (m * a < b) s1 = n * a;
            else
            {
                s1 = n / m * b;
                if (n % m * a < b) s1 += n%m*a; else s1 +=b;
            }

            Console.WriteLine(s1);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _123
{
    class Program
    {
        static int N, M, A, B;
        static int res;
        static string[] count;

        static void Main(string[] args)
        {
            count = Console.ReadLine().Split();
            N = Convert.ToInt32(count[0]);
            M = Convert.ToInt32(count[1]);
            A = Convert.ToInt32(count[2]);
            B = Convert.ToInt32(count[3]);

            if (M * A <= B)
            {
                Console.WriteLine(N * A);
                return;
            }

            res += (N / M) * B;
            N %= M;
            res += Math.Min(N * A, B);

            Console.WriteLine(res);
        }
    }
}

using System;
using System.Linq;

class A466 {
    public static void Main() {
        var line = Console.ReadLine().Split();
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var a = int.Parse(line[2]);
        var b = int.Parse(line[3]);
        Console.WriteLine(new int[] {
            (n + m - 1) / m * b,
            n / m * b + n % m * a,
            n * a
        }.Min());
    }
}

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(" ");
            int numRides = Convert.ToInt32(input[0]);
            int multiRideCount = Convert.ToInt32(input[1]);
            int singleRideCost = Convert.ToInt32(input[2]);
            int multiRideCost = Convert.ToInt32(input[3]);
            bool isSingleRideCheaper = (singleRideCost < (double)(multiRideCost) / (double)(multiRideCount));
            int totalCost = 0;

            if (isSingleRideCheaper)
                Console.WriteLine(numRides * singleRideCost);
            else
            {
                while (numRides > 0)
                {
                    if (numRides >= multiRideCount)
                    {
                        totalCost += multiRideCost;
                        numRides -= multiRideCount;
                    }
                    else if (multiRideCost < singleRideCost*numRides)
                    {
                        totalCost += multiRideCost;
                        numRides = 0;
                    }
                    else
                    {
                        totalCost += singleRideCost * numRides;
                        numRides = 0;
                    }
                }
                Console.WriteLine(totalCost);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] newline = line.Split(' ');
            int n = int.Parse(newline[0]);
           int m = int.Parse(newline[1]);
            int a = int.Parse(newline[2]);
            int b = int.Parse(newline[3]);
            int result = 0;
            double min = a * n;
            double Oneridecost = b / m;
            if (m >= n)
            {
                int min2 = n * a;
                if (min2 > b)
                    min2 = b;
                Console.Write(min2);
            }
            else
            {
                if (a > Oneridecost)
                {
                    if (n % m == 0)
                        result = (n / m) * b;
                    else
                    {
                        int temp = n / m;
                        int remain = n - (temp * m);

                        result = temp * b + remain * a;

                        int getmin = temp * b +  b;
                        if (getmin < result)
                            result = getmin;
                    }
                    Console.WriteLine(result);
                }
                else
                {
                    Console.WriteLine(min);
                }
            }
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int n = Convert.ToInt32(input[0]);
            int m = Convert.ToInt32(input[1]);
            int a = Convert.ToInt32(input[2]);
            int b = Convert.ToInt32(input[3]);

            int ret = 0;

            if (b < m * a)
            {
                while (n*a > b)
                {
                    n -= m;
                    ret += b;
                }
            }
            if (n>0) ret += (a * n);
            Console.WriteLine(ret);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');
            int n, m, a, b;
            n = int.Parse(str[0]);
            m = int.Parse(str[1]);
            a = int.Parse(str[2]);
            b = int.Parse(str[3]);
            ArrayList A = new ArrayList();

            int total = 0;

            total = (int)Math.Floor( (double)n/(double)m ) * b;
            total += (n % m) * a;
            A.Add(total);

            total = n * a;
            A.Add(total);

            total = total = (int)Math.Ceiling( (double)n / (double)m ) * b;
            A.Add(total);
            A.Sort();
            total = (int)A[0];

          //  if (total > n * a) { total = n * a; }

            Console.WriteLine(total);
           // Main(new string[0]) ;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace batdau_3_7
{
    class Program
    {
        public static void Main(string[] args)
        {
            String s = Console.ReadLine();
            String []f = new String[5];
            f= s.Split();
            Int32 n = Int32.Parse(f[0]), m = Int32.Parse(f[1]),
                a = Int32.Parse(f[2]), b = Int32.Parse(f[3]);
            Int32 d;
            Int32 k = n/m,l=b;
            if ((n%m)*a< b) l = (n%m)*a;
            d = k*b+l;
            Int32 e = n*a;
            d = (d+e-Math.Abs(d-e))/2;
            Console.WriteLine(d);
        }
    }
}

using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] str1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            float n = str1[0], m = str1[1], a = str1[2], b = str1[3];
            float money = 0;
            if (b / m * n >= a * n)
                money += a * n;
            else
            {
                while (m < n)
                {

                    money += b;
                    n -= m;
                }
                money += (n * a < b) ? n * a : b;
            }

            Console.WriteLine((int)money);

            //Console.ReadKey();

        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		if(A<(double)B/(double)M){
			Console.WriteLine("{0}",A*N);
			return;
		}

		int total=(N/M)*B;
		total+=Math.Min((N%M)*A,B);
		Console.WriteLine("{0}",total);

	}

	int N;
	int M;
	int A;// 1
	int B;// B/M

	public Sol(){
		var d=ria();
		N=d[0];M=d[1];A=d[2];B=d[3];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _466A
{
    class Program
    {
        static void Main(string[] args)
        {
            var numbers = Console.ReadLine().Split();
            int n = Convert.ToInt32(numbers[0]);
            int m = Convert.ToInt32(numbers[1]);
            int a = Convert.ToInt32(numbers[2]);
            int b = Convert.ToInt32(numbers[3]);
            if (m * a < b)
            {
                Console.WriteLine(n * a);
            }
            else
            {
                int cm = 0;
                while (cm < n)
                {
                    cm += m;
                }
                if (cm == n)
                {
                    Console.WriteLine(cm / m * b);
                }
                else
                {
                    if ((cm / m * b) > (((cm - m) / m * b) + (n - (cm - m)) * a))
                    {
                        Console.WriteLine(((cm - m) / m * b) + (n - (cm - m)) * a);
                    }
                    else
                    {
                        Console.WriteLine(cm / m * b);
                    }
                }
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
            string[] tokens = Console.ReadLine().Split(' ');
            int n = int.Parse(tokens[0]);
            int m = int.Parse(tokens[1]);
            int a = int.Parse(tokens[2]);
            int b = int.Parse(tokens[3]);

            var p = 0;
            if (n%m==0)
                 p = n/m;
            else p = n/m+1;

            var d = Math.Min(n * a, p * b);

            var t = n / m;
            var k = t * b + (n-t*m)*a;
            Console.WriteLine(Math.Min(d, k));
           // Console.WriteLine(n/m);
        }
    }
}

using System;
using System.Linq;

public class Program
{
	public static void Main()
	{
		var arr=Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

		int n=arr[0];
		int m=arr[1];
		int a=arr[2];
		int b=arr[3];

		int x=n*a;

		int y=(n/m)*b+ Math.Min(n%m*a,b);

		Console.WriteLine(Math.Min(x,y));

	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.XmlConfiguration;

namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int n = int.Parse(str.Split(' ')[0]);
            int m = int.Parse(str.Split(' ')[1]);
            int a = int.Parse(str.Split(' ')[2]);
            int b = int.Parse(str.Split(' ')[3]);

            List<int> intList = new List<int>();

            int t = n / m;
            int tost = n % m;
            double tbs = Math.Ceiling((double) n / m);

            int result1 = t * b + tost * a;
            int result2 = (int) (tbs * b);
            int result3 = n * a;

            intList.Add(result1);
            intList.Add(result2);
            intList.Add(result3);

            int result = intList.Min();

            Console.WriteLine(result);

        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace AlgoTasks
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nmab = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int n = nmab[0];
            int m = nmab[1];
            int a = nmab[2];
            int b = nmab[3];

            int res = Math.Min(n * a, Math.Min(n / m * b + n % m * a, (n / m + 1) * b));
            Console.WriteLine(res);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static int[] ReadInt(int size)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] res = new int[size];
            for (int i=0; i<input.Length; i++)
            {
                res[i] = Convert.ToInt32(input[i]);
            }
            return res;
        }

        static int ReadInt()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            return n;
        }

        static void ReadInt(out int a, out int b)
        {
            int[] input = ReadInt(2);
            a = input[0];
            b = input[1];
        }

        static void ReadInt(out int a, out int b, out int c)
        {
            int[] input = ReadInt(3);
            a = input[0];
            b = input[1];
            c = input[2];
        }

        static void ReadInt(out int a, out int b, out int c, out int d)
        {
            int[] input = ReadInt(4);
            a = input[0];
            b = input[1];
            c = input[2];
            d = input[3];
        }

        static String ReadString()
        {
            return Console.ReadLine();
        }

        static int Max(int a, int b)
        {
            return (a > b ? a : b);
        }

        static void WL<T> (T s)
        {
            Console.WriteLine(s);
        }

        static void swap(ref int a, ref int b)
        {
            int temp = a;
            a = b;
            b = temp;
        }

        static void Main(string[] args)
        {
            int n, m, a, b;
            ReadInt(out n, out m, out a, out b);
            int res = 0;
            if (a*m > b)
            {
                res += (n / m) * b;
                int tmp = n % m;
                if (tmp * a <= b) res += tmp * a; else res += b;
            }
            else
            {
                res = n * a;
            }
            WL(res);
        }
    }
}

using System;

namespace cheap
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {

                int[] sayilar = new int[4];
                int sayac = 0;
                int kalantur;
                string sayi = Console.ReadLine();
                foreach (string s in sayi.Split(' '))
                {
                    sayilar[sayac] = int.Parse(s);
                    sayac++;
                }
                if (sayilar[0] < sayilar[1])
                {
                    Console.Write(Math.Min(sayilar[0] * sayilar[2], sayilar[3]));
                }
               else if (sayilar[0]/sayilar[1]==0)
                {
                    Console.Write(Math.Min(sayilar[0] * sayilar[2], (sayilar[0] / sayilar[1]) * sayilar[3]));
                }
                else
                {
                    kalantur = sayilar[0] - sayilar[0] / sayilar[1] * sayilar[1];
                    Console.Write(Math.Min(Math.Min(sayilar[0] * sayilar[2], (sayilar[0] / sayilar[1] + 1) * sayilar[3]), ((sayilar[0] / sayilar[1]) * sayilar[3]) + kalantur * sayilar[2]));
                }

                Console.ReadKey();
            }
            catch { }
        }

    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using static System.Math;

namespace HackerRank
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums = Console.ReadLine().Split().Select(num => int.Parse(num)).ToArray();
            int n = nums[0]; //10
            int m = nums[1]; //3
            int a = nums[2]; //5
            int b = nums[3]; //1
            Console.WriteLine(a * m > b ? n / m * b + Min(n % m * a, b) : n * a);
        }
    }
}

using System;
using System.Collections.Generic;

namespace Olymp
{
    public class Program
    {
        static void Z1A ()
        {
            uint n, m, a;
            string str = Console.ReadLine ();
            string [] strs = str.Split (' ');
            n = UInt32.Parse (strs [0]);
            m = UInt32.Parse (strs [1]);
            a = UInt32.Parse (strs [2]);

            uint nn = n / a;
            if (n % a > 0)
                nn++;
            uint nm = m / a;
            if (m % a > 0)
                nm++;
            ulong result = (ulong)nn * (ulong)nm;
            Console.WriteLine (result);
        }

        static void Z4A ()
        {
            int w = Int32.Parse (Console.ReadLine ());
            if (w % 2 == 0 && w > 2)
                Console.WriteLine ("YES");
            else
                Console.WriteLine ("NO");
        }

        static void Z158A ()
        {
            int n, k;
            string [] strs = Console.ReadLine ().Split (' ');
            n = Int32.Parse (strs [0]);
            k = Int32.Parse (strs [1]);
            strs = Console.ReadLine ().Split (' ');
            int max = 0;
            int i;
            for (i = 0; i < k; i++) {
                max = Int32.Parse (strs [i]);
                if (max == 0) {
                    Console.WriteLine (i);
                    return;
                }
            }
            int sum = k;
            for (; i < n; i++) {
                if (Int32.Parse (strs [i]) < max)
                    break;
                sum++;
            }
            Console.WriteLine (sum);
        }

        static void Z71A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            string str;
            for (int i = 0; i < n; i++) {
                str = Console.ReadLine ();
                if (str.Length > 10) {
                    Console.WriteLine (str [0] + (str.Length - 2).ToString () + str [str.Length - 1]);
                } else {
                    Console.WriteLine (str);
                }

            }
        }

        static void Z118A ()
        {
            string str = Console.ReadLine ();
            str = str.ToLower ();
            str = str.Replace ("a", "");
            str = str.Replace ("o", "");
            str = str.Replace ("y", "");
            str = str.Replace ("e", "");
            str = str.Replace ("u", "");
            str = str.Replace ("i", "");
            for (int i = 0; i < str.Length; i++) {
                Console.Write ("." + str [i]);
            }

        }

        static void Z50A ()
        {

            string   [] strs = Console.ReadLine ().Split (' ');
            int N = Int32.Parse (strs [0]);
            int M = Int32.Parse (strs [1]);
            int result = 0;
            result = (N / 2) * M;
            N %= 2;
            M /= 2;
            result += M * N;
            Console.WriteLine (result);

        }

        static void Z158B ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            string[] strs = Console.ReadLine ().Split (' ');
            int[] com = new int[4];
            for (int i = 0; i < 4; i++) {
                com [i] = 0;
            }
            int temp = 0;
            for (int i = 0; i < n; i++) {
                temp = Int32.Parse (strs [i]);
                com [temp - 1]++;
            }
            int sum = com [3];
            temp = Math.Min (com [2], com [0]);
            com [2] -= temp;
            com [0] -= temp;
            sum += temp;
            sum += com [2];
            sum += com [1] / 2;
            com [1] %= 2;
            sum += com [1];
            com [0] -= com [1] * 2;
            if (com [0] > 0) {

                sum += com [0] / 4;
                com [0] %= 4;
                if (com [0] > 0)
                    sum++;
            }
            Console.WriteLine (sum);

        }

        static void Z231A ()
        {

            int n = Int32.Parse (Console.ReadLine ());
            string[] strs;
            int sum = 0;

            for (int i = 0; i < n; i++) {
                strs = Console.ReadLine ().Split (' ');
                if (Int32.Parse (strs [0]) + Int32.Parse (strs [1]) + Int32.Parse (strs [2]) > 1)
                    sum++;
            }
            Console.WriteLine (sum);
        }

        static void Z282A ()
        {

            int n = Int32.Parse (Console.ReadLine ());
            int x = 0;
            string str;
            for (int i = 0; i < n; i++) {
                str = Console.ReadLine ();
                str = str.Replace ("X", "");
                if (str == "++") {
                    x++;
                } else {
                    x--;
                }
            }
            Console.WriteLine (x);
        }

        static  void Z116A ()
        {

            int n = Int32.Parse (Console.ReadLine ());
            int a = 0, b = 0;
            int sum = 0;
            int max = 0;
            string [] strs;
            for (int i = 0; i < n; i++) {
                strs = Console.ReadLine ().Split (' ');
                a = Int32.Parse (strs [0]);
                b = Int32.Parse (strs [1]);
                sum -= a;
                sum += b;
                if (sum > max) {
                    max = sum;
                }
            }
            Console.WriteLine (max);
        }

        static void Z131A ()
        {
            bool caps = true;
            string str = Console.ReadLine ();
            char first = str [0];
            for (int i = 1; i < str.Length; i++) {
                if (str [i] < 'A' || str [i] > 'Z')
                    caps = false;
            }
            if (caps) {
                str = str.ToLower ();
                if (first >= 'a' && first <= 'z')
                    first = first.ToString ().ToUpper () [0];
                else
                    first = first.ToString ().ToLower () [0];
                str = first + str.Substring (1);

            }
            Console.WriteLine (str);
        }

        static void Z96A ()
        {
            string str = Console.ReadLine ();
            int n = 0;
            char ch = 'w';
            for (int i = 0; i < str.Length; i++) {
                if (ch == str [i])
                    n++;
                else {
                    if (n >= 7) {
                        Console.WriteLine ("YES");
                        return;
                    }
                    ch = str [i];
                    n = 1;
                }
            }
            if (n < 7)
                Console.WriteLine ("NO");
            else
                Console.WriteLine ("YES");
        }

        static void Z266A ()
        {

            string str = Console.ReadLine ();
            str = Console.ReadLine ();
            int n = 0;
            int m = 0;
            char ch = ' ';
            for (int i = 0; i < str.Length; i++) {
                if (ch == str [i])
                    n++;
                else {
                    m += n;
                    ch = str [i];
                    n = 0;
                }
            }
            m += n;
            Console.WriteLine (m);
        }

        static void Z133A ()
        {
            string str = Console.ReadLine ();
            for (int i = 0; i < str.Length; i++) {
                if (str [i] == 'H' || str [i] == 'Q' || str [i] == '9') {

                    Console.WriteLine ("YES");
                    return;
                }

            }
            Console.WriteLine ("NO");

        }

        static void Z112A ()
        {
            string str1 = Console.ReadLine ();
            str1 = str1.ToLower ();
            string str2 = Console.ReadLine ();
            str2 = str2.ToLower ();
            int n = String.Compare (str1, str2);
            if (n != 0)
                Console.WriteLine (n / Math.Abs (n));
            else
                Console.WriteLine (0);
        }

        static void Z339A ()
        {
            int [] ch = new int[3];
            for (int i = 0; i < 3; i++) {
                ch [i] = 0;
            }
            string str = Console.ReadLine ();
            bool flag = false;
            for (int i = 0; i < str.Length; i++) {
                if (flag)
                    i++;
                else
                    flag = true;
                ch [Int32.Parse (str [i].ToString ()) - 1]++;
            }
            int j = 0;
            flag = false;
            while (j<3) {
                ch [j]--;

                if (ch [j] >= 0) {
                    if (flag) {
                        Console.Write ("+");
                    } else
                        flag = true;
                    Console.Write (j + 1);
                } else
                    j++;
            }
        }

        static void Z281A ()
        {
            string str = Console.ReadLine ();
            string f = str [0].ToString ();
            f = f.ToUpper ();
            str = f [0] + str.Substring (1);
            Console.Write (str);
        }

        static void Z82A ()
        {
            string[] names = new    string[5];
            names [0] = "Sheldon";
            names [1] = "Leonard";
            names [2] = "Penny";
            names [3] = "Rajesh";
            names [4] = "Howard";
            int n = Int32.Parse (Console.ReadLine ());
            int m = 5;
            while (m<n) {
                n -= m;
                m *= 2;
            }
            m /= 5;
            int i = 0;
            while (m<n) {
                n -= m;
                i++;
            }
            Console.Write (names [i]);
        }

        static void Z160A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            string[] str = Console.ReadLine ().Split (' ');
            List<int> moneys = new List<int> ();
            int sum = 0;
            for (int i = 0; i < n; i++) {
                moneys.Add (Int32.Parse (str [i]));
                sum += moneys [i];
            }

            int[] armon = moneys.ToArray ();
            Array.Sort (armon);
            int blz = 0;
            int j = armon.Length - 1;
            int ni = 0;
            while (blz<=sum&&j>=0) {
                blz += armon [j];
                sum -= armon [j];
                j--;
                ni++;
            }
            Console.WriteLine (ni);
        }

        static void Z148A ()
        {
            int k = Int32.Parse (Console.ReadLine ());
            int l = Int32.Parse (Console.ReadLine ());
            int m = Int32.Parse (Console.ReadLine ());
            int n = Int32.Parse (Console.ReadLine ());
            int d = Int32.Parse (Console.ReadLine ());
            int sum = 0;

            for (int i = 1; i <= d; i++) {
                if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0)
                    sum++;
            }
            Console.WriteLine (sum);
        }

        static void Z236A ()
        {
            string str = Console.ReadLine ();
            int n = 0;
            string ne = "";
            bool k;
            for (int i = 0; i < str.Length; i++) {
                k = false;
                for (int j = 0; j < ne.Length; j++) {
                    if (str [i] == ne [j]) {
                        k = true;
                    }
                }
                if (!k) {
                    ne += str [i];
                    n++;
                }
            }
            if (n % 2 == 0) {
                Console.WriteLine ("CHAT WITH HER!");
            } else {
                Console.WriteLine ("IGNORE HIM!");
            }
        }

        static int gdc (int left, int right)
        {
            while (left>0&&right>0) {
                if (left > right) {
                    left %= right;
                } else
                    right %= left;
            }
            return left + right;
        }

        static void Z119A ()
        {
            string[] str = Console.ReadLine ().Split (' ');
            int[] ab = new int[2];

            ab [0] = Int32.Parse (str [0]);
            ab [1] = Int32.Parse (str [1]);
            int n = Int32.Parse (str [2]);
            int i = 0;
            int m;
            while (true) {
                if (n == 0) {
                    Console.WriteLine ((i + 1) % 2);
                    return;
                }
                m = gdc (ab [i], n);
                n -= m;
                i = (i + 1) % 2;

            }

        }

        static void Z110A ()
        {
            string str = Console.ReadLine ();
            int n = 0;
            for (int i = 0; i < str.Length; i++) {
                if (str [i] == '4' || str [i] == '7') {
                    n++;
                }
            }
            if (n == 4 || n == 7) {
                Console.WriteLine ("YES");
            } else {
                Console.WriteLine ("NO");
            }
        }

        static void Z467A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            int res = 0;
            string [] strs;
            for (int i = 0; i < n; i++) {
                strs = Console.ReadLine ().Split (' ');
                if (Int32.Parse (strs [1]) - Int32.Parse (strs [0]) >= 2) {
                    res++;
                }
            }
            Console.WriteLine (res);
        }

        static void Z271A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            int [] ye = new int[4];
            n++;
            for (int i = 0; i < 4; i++) {
                ye [i] = n / 1000;
                n %= 1000;
                n *= 10;
            }
            bool flag = true;
            while (flag) {
                for (int i = 0; i < 4; i++) {
                    for (int j = 0; j < i; j++) {
                        if (ye [i] == ye [j]) {
                            ye [i]++;

                            for (int k = i+1; k < 4; k++) {
                                ye [k] = 0;
                            }
                            i--;
                        }
                    }
                }
                flag = false;
                for (int i = 1; i < 4; i++) {
                    if (ye [i] == 10) {
                        ye [i] %= 10;
                        ye [i - 1]++;
                        flag = true;
                    }
                }
            }
            for (int i = 0; i < 4; i++) {
                Console.Write (ye [i]);
            }

        }

        static void Z58A ()
        {
            string str = Console.ReadLine ();
            str.ToLower ();
            string sstr = "hello";
            int j = 0;
            for (int i = 0; i < str.Length; i++) {
                if (sstr [j] == str [i])
                    j++;
                if (j == sstr.Length) {
                    Console.WriteLine ("YES");
                    return;
                }
            }
            Console.WriteLine ("NO");
        }

        static void Z472A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            if (n % 2 == 0) {
                Console.Write ("4 ");
                Console.Write (n - 4);
            } else {
                Console.Write ("9 ");
                Console.Write (n - 9);
            }
        }

        static void Z460A ()
        {
            int res = 0;
            int days = 0;
            string[] strs = Console.ReadLine ().Split (' ');
            int nosk = Int32.Parse (strs [0]);
            int nd = Int32.Parse (strs [1]);
            while (nosk!=0) {
                days += nosk;
                res += nosk;
                nosk = 0;
                nosk = days / nd;
                days %= nd;
            }
            Console.Write (res);
        }

        static void Z379A ()
        {
            string[] strs = Console.ReadLine ().Split (' ');
            int a = Int32.Parse (strs [0]);
            int b = Int32.Parse (strs [1]);
            int ogaroks = 0;
            int h = 0;
            while (a!=0) {
                h += a;
                ogaroks += a;
                a = ogaroks / b;
                ogaroks %= b;
            }
            Console.WriteLine (h);
        }

        static bool IsLucky (int n)
        {
            while (n>0) {
                int m = n % 10;
                if (m != 4 && m != 7) {
                    return false;
                }
                n /= 10;
            }
            return true;
        }

        static void Z122A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            for (int i = 2; i <= n; i++) {
                if (n % i == 0 && IsLucky (i)) {
                    Console.WriteLine ("YES");
                    return;
                }
            }
            Console.WriteLine ("NO");
        }

        static void Z136A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            int[] pod = new int[n];
            string[] strs = Console.ReadLine ().Split (' ');
            for (int i = 0; i < n; i++) {
                pod [Int32.Parse (strs [i]) - 1] = i + 1;
            }
            for (int i = 0; i < n; i++) {
                Console.Write (pod [i].ToString () + " ");
            }
        }

        static void Z228A ()
        {
            string[] strs = Console.ReadLine ().Split (' ');
            List<int> n = new List<int> ();
            for (int i = 0; i < 4; i++) {
                bool flag = true;
                for (int j = 0; j < n.Count; j++) {
                    if (Int32.Parse (strs [i]) == n [j]) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    n.Add (Int32.Parse (strs [i]));
                }
            }
            Console.WriteLine (4 - n.Count);
        }

        static void Z263A ()
        {
            string[] strs;
            int x = 0, y = 0;
            for (int i = 0; i < 5; i++) {
                strs = Console.ReadLine ().Split (' ');
                for (int j = 0; j < 5; j++) {
                    if (strs [j] == "1") {
                        x = j + 1;
                        y = i + 1;
                    }
                }

            }
            Console.WriteLine ((Math.Abs (3 - x) + Math.Abs (3 - y)));
        }

        static void Z266B ()
        {
            string[] strs = Console.ReadLine ().Split (' ');
            int n = Int32.Parse (strs [0]);
            int t = Int32.Parse (strs [1]);
            string str = Console.ReadLine ();
            char[] chs = new char[str.Length];
            for (int i = 0; i < str.Length; i++) {
                chs [i] = str [i];
            }
            for (int i = 0; i < t; i++) {
                int j = 0;
                while (j+1<n) {
                    if (chs [j] == 'B' && chs [j + 1] == 'G') {
                        char ch = chs [j];
                        chs [j] = chs [j + 1];
                        chs [j + 1] = ch;
                        j += 2;
                    } else {
                        j++;
                    }
                }
            }
            for (int i = 0; i < chs.Length; i++) {
                Console.Write (chs [i]);
            }

        }

        static void Z41A ()
        {
            string str1 = Console.ReadLine ();
            string str2 = Console.ReadLine ();
            if (str1.Length != str2.Length) {
                Console.WriteLine ("NO");
                return;
            }
            for (int i = 0; i < str1.Length; i++) {
                if (str1 [i] != str2 [str2.Length - i - 1]) {

                    Console.WriteLine ("NO");
                    return;
                }
            }
            Console.WriteLine ("YES");
        }

        static void Z144A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            string[] strs = Console.ReadLine ().Split (' ');
            int[] rost = new int[n];
            int max = 0;
            int min = n - 1;
            for (int i = 0; i < n; i++) {
                rost [i] = Int32.Parse (strs [i]);
                if (rost [i] > rost [max])
                    max = i;
            }
            int sum = 0;
            while (max!=0) {
                int temp = rost [max];
                rost [max] = rost [max - 1];
                rost [max - 1] = temp;
                sum++;
                max--;
            }

            for (int i = n-1; i >=0; i--) {

                if (rost [i] < rost [min]) {
                    min = i;
                }
            }
            while (min!=rost.Length-1) {
                int temp = rost [min];
                rost [min] = rost [min + 1];
                rost [min + 1] = temp;
                sum++;
                min++;
            }
            Console.WriteLine (sum);
        }

        static void Z451A ()
        {
            string[] names = new string[2];
            names [0] = "Akshat";
            names [1] = "Malvika";
            string[] strs = Console.ReadLine ().Split (' ');
            int n = Int32.Parse (strs [0]);
            int m = Int32.Parse (strs [1]);
            n = Math.Min (n, m) - 1;
            n %= 2;
            Console.WriteLine (names [n]);

        }

        static void Z344A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            int ostr = 1;
            string str = Console.ReadLine ();
            char ch = str [1];
            for (int i = 1; i < n; i++) {
                str = Console.ReadLine ();
                if (ch == str [0]) {
                    ostr++;
                }
                ch = str [1];
            }
            Console.WriteLine (ostr);
        }

        static void Z486A ()
        {
            long n = Int64.Parse (Console.ReadLine ());
            long sum = n / 2;
            sum -= (n % 2) * n;
            Console.WriteLine (sum);
        }

        static void Z500A ()
        {
            string[] str = Console.ReadLine ().Split (' ');
            int n = Int32.Parse (str [0]);
            int t = Int32.Parse (str [1]);
            int[] a = new int[n - 1];
            str = Console.ReadLine ().Split (' ');
            int j = 0;
            t--;
            for (int i = 0; i < n-1; i++) {
                a [i] = Int32.Parse (str [i]);
                if (i == j)
                    j += a [i];
                if (j >= t)
                    break;
            }
            if (j == t)
                Console.WriteLine ("YES");
            else
                Console.WriteLine ("NO");
        }

        static void Z61A ()
        {
            string str1 = Console.ReadLine ();
            string str2 = Console.ReadLine ();
            string str3 = "";
            for (int i = 0; i < str1.Length; i++) {
                if (str1 [i] == str2 [i])
                    str3 += "0";
                else
                    str3 += "1";
            }
            Console.WriteLine (str3);
        }

        static void Z268A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            int[] h = new int[n];
            int[] a = new int[n];
            string[] strs;
            for (int i = 0; i < n; i++) {
                strs = Console.ReadLine ().Split (' ');
                h [i] = Int32.Parse (strs [0]);
                a [i] = Int32.Parse (strs [1]);
            }
            int sum = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (i != j && h [i] == a [j])
                        sum++;
                }
            }
            Console.WriteLine (sum);
        }

        static void Z208A ()
        {
            string str = Console.ReadLine ();
            string[] separ = new string[1];
            separ [0] = "WUB";
            string[] strs = str.Split (separ, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < strs.Length; i++) {
                Console.Write (strs [i] + " ");
            }
        }

        static void Z478A ()
        {
            string []strs=Console.ReadLine().Split(' ');
            int n=0;
            for (int i = 0; i < 5; i++) {
                n+=Int32.Parse(strs[i]);
            }
            if (n%5==0&&n!=0) {
                Console.WriteLine(n/5);
            }
            else {
                Console.WriteLine(-1);
            }
        }
        static void Z69A ()
        {
            int n = Int32.Parse (Console.ReadLine ());
            int x = 0, y = 0, z = 0;
            string[] strs;
            for (int i = 0; i < n; i++) {
                strs = Console.ReadLine ().Split (' ');
                x += Int32.Parse (strs [0]);
                y += Int32.Parse (strs [1]);
                z += Int32.Parse (strs [2]);
            }
            if (x == 0 && y == 0 && z == 0) {
                Console.Write ("YES");
            } else {
                Console.Write("NO");
            }
        }
        static void Z337A ()
        {
            string[] strs=Console.ReadLine().Split(' ');
            int n=Int32.Parse(strs[0]);
            int m=Int32.Parse(strs[1]);
            List<int> arra=new List<int>();
            strs=Console.ReadLine().Split(' ');
            bool flag;
            for (int i = 0; i < m; i++) {
                flag=true;
                int t=Int32.Parse(strs[i]);
                for (int j = 0; j < arra.Count; j++) {
                    if(t<arra[j])
                    {
                        arra.Insert(j,t);
                        flag=false;
                        break;
                    }
                }
                if (flag) {
                    arra.Add(t);
                }
            }
            int min=int.MaxValue;
            for (int i = n-1; i < arra.Count; i++) {
                if (arra[i]-arra[i-n+1]<min) {

                    min=arra[i]-arra[i-n+1];
                }
            }
            Console.Write(min);
        }
        static void Z141A ()
        {
            string names = Console.ReadLine ();
            names += Console.ReadLine ();
            string str = Console.ReadLine ();
            if (names.Length != str.Length) {
                Console.Write ("NO");
                return;
            }
            bool flag;
            for (int i = 0; i < str.Length; i++) {
                flag=true;;
                for (int qj = 0; qj < names.Length; qj++) {
                    if (str[i]==names[qj]) {
                        flag=false;
                        names=names.Substring(0,qj)+' '+names.Substring(qj+1);
                        break;
                    }
                }
                if (flag) {
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
        }
        static void Z492A ()
        {
            int n=Int32.Parse(Console.ReadLine());
            int i=1;
            int level=0;
            int sum=1;
            while (n>=sum) {
                level++;
                n-=sum;
                i++;
                sum+=i;
            }
            Console.WriteLine(level);
        }
        static void Z479A ()
        {
            int a=Int32.Parse(Console.ReadLine());
            int b=Int32.Parse(Console.ReadLine());
            int c=Int32.Parse(Console.ReadLine());
            int res=a+b+c;
            res=Math.Max(res,(a+b)*c);
            res=Math.Max(res,a*(b+c));
            res=Math.Max(res,(a*b)*c);
            Console.WriteLine(res);

        }
        static void Z448A ()
        {
            string[] strs = Console.ReadLine ().Split (' ');
            int a = Int32.Parse (strs [0]) + Int32.Parse (strs [1]) + Int32.Parse (strs [2]);
            strs = Console.ReadLine ().Split (' ');
            int b = Int32.Parse (strs [0]) + Int32.Parse (strs [1]) + Int32.Parse (strs [2]);
            int n = Int32.Parse (Console.ReadLine ());
            int aa = a / 5;
            if (a % 5 != 0) {
                aa++;
            }
            n -= aa;
            if (n < 0) {
                Console.WriteLine("NO");
                return;
            }
            aa=b/10;
            if (b%10!=0) {
                aa++;
            }
            n -= aa;
            if (n < 0) {
                Console.WriteLine("NO");
                return;
            }
            Console.WriteLine("YES");
        }
        static  void Z469A ()
        {
            int n=Int32.Parse(Console.ReadLine());
            bool[]levels=new bool[n];
            for (int i = 0; i < n; i++) {
                levels[i]=true;
            }
            for (int i = 0; i < 2; i++) {
                string[]str=Console.ReadLine().Split(' ');
                int m=Int32.Parse(str[0]);
                for (int j = 1; j <= m; j++) {
                    levels[Int32.Parse(str[j])-1]=false;
                }
            }
            for (int i = 0; i < n; i++) {
                if (levels[i]) {
                    Console.WriteLine("Oh, my keyboard!");
                    return;
                }
            }
            Console.WriteLine("I become the guy.");
        }
        static void Z155A ()
        {
            int n=Int32.Parse(Console.ReadLine());
            string[]strs=Console.ReadLine().Split(' ');
            int max=Int32.Parse(strs[0]);
            int min=max;
            int m=0;
            for (int i = 1; i < n; i++) {
                int t=Int32.Parse(strs[i]);
                if (t>max) {
                    m++;
                    max=t;
                }
                if (t<min) {
                    m++;
                    min=t;
                }
            }
            Console.WriteLine(m);
        }
        static void Z443A ()
        {
            string str=Console.ReadLine();
            int i=1;
            List<char> chrs=new List<char>();
            bool flag;
            while (str[i]!='}') {

                flag=true;
                for (int j = 0; j < chrs.Count; j++) {
                    if (str[i]==chrs[j]) {
                        flag=false;
                        break;
                    }
                }
                if (flag) {
                    chrs.Add(str[i]);
                }
                i++;
                if(str[i]=='}')
                    break;
                i+=2;
            }
            Console.WriteLine(chrs.Count);
        }
        static void Z474A ()
        {
            char[,]keyboard=new char[3,10];
            keyboard[0,0]='q';
            keyboard[0,1]='w';
            keyboard[0,2]='e';
            keyboard[0,3]='r';
            keyboard[0,4]='t';
            keyboard[0,5]='y';
            keyboard[0,6]='u';
            keyboard[0,7]='i';
            keyboard[0,8]='o';
            keyboard[0,9]='p';
            keyboard[1,0]='a';
            keyboard[1,1]='s';
            keyboard[1,2]='d';
            keyboard[1,3]='f';
            keyboard[1,4]='g';
            keyboard[1,5]='h';
            keyboard[1,6]='j';
            keyboard[1,7]='k';
            keyboard[1,8]='l';
            keyboard[1,9]=';';
            keyboard[2,0]='z';
            keyboard[2,1]='x';
            keyboard[2,2]='c';
            keyboard[2,3]='v';
            keyboard[2,4]='b';
            keyboard[2,5]='n';
            keyboard[2,6]='m';
            keyboard[2,7]=',';
            keyboard[2,8]='.';
            keyboard[2,9]='/';
            bool flag;
            string lr=Console.ReadLine();
            string str=Console.ReadLine();
            int[]x=new int[str.Length];
            int[]y=new int[str.Length];
            for (int i = 0; i < str.Length; i++) {
                flag=false;
                for (int k = 0; k < 3; k++) {
                    for (int m = 0; m < 10; m++) {
                        if (keyboard[k,m]==str[i]) {
                            y[i]=k;
                            x[i]=m;
                            flag=true;
                            break;
                        }
                    }
                    if(flag)
                        break;
                }
            }
            int a=0;
            if (lr=="L") {
                a++;
            }
            else {
                a--;
            }
            for (int i = 0; i < str.Length; i++) {
                Console.Write(keyboard[y[i],x[i]+a]);
            }
        }
        static void Z268B ()
        {
            int n=Int32.Parse(Console.ReadLine());
            int sum=0;
            for (int j = 1; j < n; j++) {
                sum+=(n-j)*j;
            }
            sum+=n;
            Console.WriteLine(sum);
        }
        static void Z318A ()
        {
            string[] strs=Console.ReadLine().Split(' ');

            long n=Int64.Parse(strs[0]);
            long m=Int64.Parse(strs[1]);
            n=n/2+n%2;
            long a=0;

            if (m<=n) {
                a=1;
            }
            else
            {
                m-=n;
                a=2;
            }
                    a=a+(m-1)*2;

            Console.WriteLine(a);

        }
        static void Z510A ()
        {
            string[] strs=Console.ReadLine().Split(' ');

            int n=Int32.Parse(strs[0]);
            int m=Int32.Parse(strs[1]);
            int  dir=0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if(dir==0)
                    {
                        Console.Write("#");
                    }
                    if(dir==1&&j==m-1)
                    {
                        Console.Write("#");
                    }
                    if(dir==1&&j!=m-1)
                    {
                        Console.Write(".");
                    }
                    if(dir==2)
                    {
                        Console.Write("#");
                    }
                    if(dir==3&&j==0)
                    {
                        Console.Write("#");
                    }
                    if(dir==3&&j!=0)
                    {
                        Console.Write(".");
                    }
                }
                dir++;
                dir%=4;
                Console.WriteLine();
            }
        }
        static void Z405A ()
        {
            int n=Int32.Parse(Console.ReadLine());
            int[]st=new int[n];
            string []strs=Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++) {
                st[i]=Int32.Parse(strs[i]);
            }
            Array.Sort(st);
            for (int i = 0; i < st.Length; i++) {
                Console.Write(st[i].ToString()+" ");
            }
        }
        static void Z466A ()
        {
            string[] strs = Console.ReadLine ().Split (' ');
            int n = Int32.Parse (strs [0]);
            int m = Int32.Parse (strs [1]);
            int a = Int32.Parse (strs [2]);
            int b = Int32.Parse (strs [3]);
            int sum = 0;
            int temp=m *a;
            if (temp>b) {
                temp=b;
            }
            sum=(n /m)*temp;
            n %=m;
            temp=n *a;
            if(temp>b)
                temp=b;

            sum+=temp;
            Console.Write(sum);

        }
        public static void Main ()
        {

            Z466A ();
        }

    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Task_TD
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] lines = Console.ReadLine().Split(' ');

            int n = Int32.Parse(lines[0]);
            int m = Int32.Parse(lines[1]);
            int a = Int32.Parse(lines[2]);
            int b = Int32.Parse(lines[3]);

            Console.WriteLine(GetResult(n, m, a, b));

            Console.ReadLine();
        }

        static int GetResult(int n, int m, int a, int b)
        {
            if (b / m >= a)
            {
                return n * a;
            }

            int k = n / m;
            int rest = n % m;

            int res = Math.Min((k * b + rest * a), (k + 1) * b);
            return res;
        }

    }
}

using System;

public class CheapTravel {

	public static void Main(string[] args){

		var input = Console.ReadLine().Split();
		var n = int.Parse(input[0]);
		var m = int.Parse(input[1]);
		var a = int.Parse(input[2]);
		var b = int.Parse(input[3]);

		if(a <= ((float)b / (float)m))
		{
			Console.Write(n * a);
		}
		else {
			var total = 0;

			while(n > 0){

			  if((n-m) < 0)
			  {
				 Console.Write(Math.Min(total + b, total + (n * a)));
				 return;
			  }

			  total += (b);
     		  n -= m;
			}

			Console.Write(total);
		}
	}
}

using System;

namespace CheapTravel
{
    public class Solution
    {
        static int Expenditure(int n, int m, int a, int b)
        {
            if (a * m > b)
            {
                if (m <= n)
                {
                    if ((n % m) * a < b)
                        return ((n / m) * b + (n % m) * a);
                    else
                        return ((n / m + 1) * b);
                }
                else
                {
                    if (n * a < b)
                        return n * a;
                    else
                        return b;
                }
            }
            else
                return a * n;
        }

        static void Main(String[] args)
        {
            string s = Console.ReadLine();
            string[] split = s.Split(' ');

            Console.Write(Expenditure(int.Parse(split[0]), int.Parse(split[1]), int.Parse(split[2]), int.Parse(split[3])));
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CheapTravel
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n, m, a, b;
            n = int.Parse(s[0]);
            m = int.Parse(s[1]);
            a = int.Parse(s[2]);
            b = int.Parse(s[3]);
            int at, abt, bt;
            at = n * a;
            abt = (n / m) * b + (n % m) * a;
            bt = (n / m) * b;
            if (n % m != 0)
                bt += b;

            int min;
            min = Math.Min(Math.Min(at, bt), abt);
            Console.Write(min);
        }
    }
}

#region imports
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;

#endregion

namespace CodeForces
{
    class Problem
    {
        const bool IsContest = true;

        void Solve()
        {
            var n = _.NextInt();
            var m = _.NextInt();
            var a = _.NextInt();
            var b = _.NextInt();
            _.WriteLine(Answer(n, m, a, b));

        }

        private int Answer(int n, int m, int a, int b)
        {
            if (b > a * m) return n * a;
            var ans = (n / m) * b;
            n -= (n / m) * m;
            ans += Math.Min(b, n*a);
            return ans;
        }

        #region shit
        private readonly InOut _ = new InOut(IsContest);
        static void Main(string[] args)
        {
            var p = new Problem();
            p.Solve();
            p._.Close();
        }
    }
    class InOut
    {
        private const string InputFile = "input.txt";
        private const string OutputFile = "output.txt";
        public StreamWriter Cout { get; private set; }
        public StreamReader Cin { get; private set; }
        private void SetConsoleIo()
        {
            Cin = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
            Cout = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
        }
        private void SetFileIo(string inputFile, string outputFile) { Cin = new StreamReader(inputFile); Cout = new StreamWriter(outputFile); }
        public InOut() { SetConsoleIo(); }
        public InOut(string inputFile, string outputFile) { SetFileIo(inputFile, outputFile); }
        public InOut(bool isContest) { if (isContest) SetConsoleIo(); else SetFileIo(InputFile, OutputFile); }
        public void WriteLine(object x) { Cout.WriteLine(x); }
        public void Close() { Cin.Close(); Cout.Close(); }
        public void WriteLine(string format, params object[] args) { Cout.WriteLine(format, args); }
        private int _pos;
        private string[] _tokens;

        private string[] NextStringArray() { return Cin.ReadLine().Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); }
        public string NextToken()
        {
            while (_tokens == null || _pos == _tokens.Length)
            {
                // ReSharper disable once PossibleNullReferenceException
                _tokens = NextStringArray();
                _pos = 0;
            }
            return _tokens[_pos++];
        }
        public int NextInt() { return int.Parse(NextToken()); }
        public long NextLong() { return long.Parse(NextToken()); }
        public double NextDouble() { return double.Parse(NextToken(), CultureInfo.InvariantCulture); }
        public int[] NextIntArray() { return NextStringArray().Select(int.Parse).ToArray(); }
        public long[] NextLongArray() { return NextStringArray().Select(long.Parse).ToArray(); }
        #endregion
    }
}

using System;
using System.Collections;
using System.Linq;

namespace mainnm
{
    class main
    {
        static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        struct Notebook {
            public int price;
            public int quality;
        }

        static void Main()
        {
            int[] ts = Console.ReadLine().Split(' ').Select(num => Int32.Parse(num)).ToArray();

            int n = ts[0];
            int m = ts[1];
            int a = ts[2];
            int b = ts[3];

            if (((float)b)/m > a) {
                Console.WriteLine(n * a);
            } else {
                int ost = n % m;
                int sum = (n / m) * b;

                if (ost * a > b) {
                    sum += b;
                } else  {
                    sum += ost * a;
                }

                Console.WriteLine(sum);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication24
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = 0;
            int m = 0;
            int a = 0;
            int b = 0;
            string temp = "";
            int counter = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (i == s.Length - 1)
                {
                    temp += s[i];
                    b = int.Parse(temp);
                    temp = "";
                }
                else if (s[i] != ' ')
                    temp += s[i];
                else
                {
                    if (counter == 0)
                        n = int.Parse(temp);
                    else if (counter == 1)
                        m = int.Parse(temp);
                    else
                        a = int.Parse(temp);
                    temp = "";
                    counter++;
                }
            }
            int max1 = n * a;
            int max2 = 0;
            int ccounter =0;
            if (m > n)
                max2 = b;
            else
            {
                max2 = (n / m) * b;
                ccounter+=(n/m)*m;
                if (n % m != 0)
                    if (a > b) max2 += b;

                    else
                        while (ccounter++ < n)
                            max2 += a;
            }
            if (max1 > max2)
                Console.WriteLine(max2);
            else
                Console.WriteLine(max1);
        }
    }
}

// A Dynamic Programming based
// C# program to find minimum
// number operations to
// convert str1 to str2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class GFG
{
    static string[] memo = new string[13];

    public static void Main()
    {
        ///var t = int.Parse(Console.ReadLine());

        ////while (t > 0)
        //{
        //    // t--;
        //    // var n = int.Parse(Console.ReadLine());
        //    //var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        //var input = Console.ReadLine().Split();
        //var n = int.Parse(input[0]);
        //var m = int.Parse(input[1]);
        //    //var k = int.Parse(input[2]);
        //
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var m = int.Parse(input[1]);
        var a = int.Parse(input[2]);
        var b = int.Parse(input[3]);

        var totlDays = n / m;
        if(totlDays==0)
        {
            if(a*n>b)
            {
                Console.Write(b);
                return;
            }
        }
        var remDays = n % m;

        //t using discount

        var macValue = n * a;

        //totacost using

        var maxV = totlDays * b + Math.Min(remDays * a, remDays<=m?1:remDays *b);

        Console.Write(Math.Min(macValue, maxV));

        //}

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double s = 0,m=0,n=0,u=0;
            string[] arr = Console.ReadLine().Split();
            double a = double.Parse(arr[0]);
            double b = double.Parse(arr[1]);
            double c = double.Parse(arr[2]);
            double d = double.Parse(arr[3]);
            m = d / b;
            if (c<=m)
            {
                Console.WriteLine(a*c);
                return;
            }
            else
            {
                if (a % m == 0)
                {
                    Console.WriteLine(m * a);
                    return;
                }
                else
                {
                    for (int i = 0; i < a; i++)
                    {
                        s = s + d;
                        n = n + b;
                        if (n>=a)
                        {
                            Console.WriteLine(s);
                            return;
                        }
                        else if (n+1==a)
                        {
                            if (b>=c)
                            {
                                Console.WriteLine(s + c);
                            }
                            else
                            {
                                Console.WriteLine(s + d);

                            }
                            return;
                        }

                    }

                }
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            double[] n = Array.ConvertAll(s, double.Parse);

            double p1 = (n[0] * n[2]);
            double p2;
            if ((n[0] % n[1]) == 1 && n[2] <= n[3] && n[0] >= n[1])
            {
                p2 = (Math.Floor(n[0] / n[1]) * n[3]) + n[2];
            }
            else if ((n[0] % n[1]) == 1 && n[2] > n[3] && n[0] >= n[1])
            {
                p2 = (Math.Ceiling(n[0] / n[1]) * n[3]);
            }
            else if (n[0] < n[1] && (n[0]*n[2]) > n[3])
            {
                Console.WriteLine(n[3]);
                return;
            }
            else if (n[0] < n[1] && (n[0] * n[2]) < n[3])
            {
                Console.WriteLine(n[0] * n[2]);
                return;
            }
            else
            {
                p2 = ((n[0] / n[1]) * n[3]);
            }

            Console.WriteLine(Math.Min(p1, p2));

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _266
{
    class Program
    {
        static void Main(string[] args)
        {
            var task = new CheapTravel();
            Console.WriteLine(task.Solve());
        }

        private class CheapTravel
        {
            private int a, b, m, n;

            private void ReadData()
            {
                string line = Console.ReadLine();
                var arr = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                n = Convert.ToInt32(arr[0]);
                m = Convert.ToInt32(arr[1]);
                a = Convert.ToInt32(arr[2]);
                b = Convert.ToInt32(arr[3]);
            }

            public int Solve()
            {
                ReadData();
                int res;
                if ((b/(float) m < a)&& b<n)
                {
                    res = (n/m)*b;
                    int rest = (n%m)*a;
                    if (rest > b)
                        rest = b;
                    res += rest;
                }
                else
                {
                    res = n*a;
                }
                return res;
            }
        }
    }
}

using System;

public class CheapTravel {

	public static void Main(string[] args){

		var input = Console.ReadLine().Split();
		var n = int.Parse(input[0]);
		var m = int.Parse(input[1]);
		var a = int.Parse(input[2]);
		var b = int.Parse(input[3]);

		if(a <= ((float)b / (float)m))
		{
			Console.Write(n * a);
		}
		else {
			var total = 0;

			while(n > 0){

			  if((n-m) < 0)
			  {
				 Console.Write(total + (n * a));
				 return;
			  }

			  total += (b);
     		  n -= m;
			}

			Console.Write(total);
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

class Program{
    static void Main(string[] args){
        string[] input = Console.ReadLine().Split(' ');
        int ridesPlanned = Int32.Parse(input[0]);
        int ridesInSpecialTicket=Int32.Parse(input[1]);
        int priceForSingleRide= Int32.Parse(input[2]);
        int priceForSpecialRides=Int32.Parse(input[3]);

        if (ridesPlanned == 0)
                Console.WriteLine(0);
            else if (ridesInSpecialTicket == 0)
                Console.WriteLine(ridesPlanned * priceForSingleRide);

            else
            {

                if (ridesPlanned % ridesInSpecialTicket == 0)
                    Console.WriteLine((ridesPlanned / ridesInSpecialTicket) * priceForSpecialRides);
                else{
                    int cost = (ridesPlanned / ridesInSpecialTicket) * priceForSpecialRides + (ridesPlanned % ridesInSpecialTicket) * priceForSingleRide;
                    int x = ridesPlanned / ridesInSpecialTicket + 1;
                    if(x*priceForSpecialRides < cost)
                    {
                        Console.WriteLine(x * priceForSpecialRides);
                    }
                    else
                        Console.WriteLine(cost);
                }
            }

        }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double s = 0,m=0,n=0,u=10000000;
            string[] arr = Console.ReadLine().Split();
            double a = double.Parse(arr[0]);
            double b = double.Parse(arr[1]);
            double c = double.Parse(arr[2]);
            double d = double.Parse(arr[3]);
            m = d / b;
            if (a==c&&c<d)
            {
                Console.WriteLine(c);
            }
           else if (c<=m)
            {
                Console.WriteLine(Math.Ceiling(a*c));
                return;
            }
            else
            {
                if (a % m == 0)
                {
                    Console.WriteLine(Math.Ceiling(a*m));
                    return;
                }
                else
                {
                    for (int i = 0; i < a; i++)
                    {
                        for (int j = 0; j < a; j++)
                        {
                            s = (a - j) * c;
                            n = (a - i) * d/b;
                            if (u>=s+n&&i+j==a)
                            {
                                u = s + n;
                            }
                        }
                        //s = s + d;
                        //n = n + b;
                        //if (true)
                        //{

                        //}
                        //if (n>=a)
                        //{
                        //    Console.WriteLine(Math.Ceiling(s));
                        //    return;
                        //}
                        //else if (n+1==a)
                        //{
                        //    if (b>=c)
                        //    {
                        //        Console.WriteLine(Math.Ceiling(s + c));
                        //    }
                        //    else
                        //    {
                        //        Console.WriteLine(Math.Ceiling(s + d));
                        //    }
                        //    return;
                        //}

                    }
                    Console.WriteLine(Math.Ceiling(u));
                    return;
                }
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest7_12
{
    class Program
    {
        static void Main(string[] args)
        {
            //var input = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(k=> int.Parse(k)).ToArray();

            var noOfRides = input[0];
            var mticketNoOfRides = input[1];
            var priceOneRideTicket = input[2];
            var pricemRideTicket = input[3];

            var tickets = noOfRides / mticketNoOfRides;
            var ridesNeeded = (noOfRides - (tickets * mticketNoOfRides)) % mticketNoOfRides;

            var finalTotal1 = tickets * pricemRideTicket + ridesNeeded * priceOneRideTicket;

            var finalTotal2 = tickets * pricemRideTicket + ridesNeeded * pricemRideTicket;

            var finalTotal = finalTotal1 > finalTotal2 ? finalTotal2 : finalTotal1;

            Console.WriteLine(finalTotal);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Выгодный_проезд
{
    class Program
    {
        static void Main(string[] args)
        {
            var mas = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Resh(mas));
            Console.ReadLine();

        }

        static int Resh(int[] mas)
        {
            int n = mas[0];
            int m = mas[1];
            int a = mas[2];
            int b = mas[3];

            if (a * m <= b)
                return n * a;
            else if (a >= b)
                return (n / m) * b + 1;
            else
                return (n / m) * b + (n % m) * a;
        }
    }
}

using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string bilgi = Console.ReadLine();
                hesapla(bilgi);
                Console.ReadKey();
            }
            catch
            {
            }

        }
        static void hesapla(string bilgi)
        {
            int s1 = 0;
            int[] sayilar = new int[4];
            int sayac = 0;
            foreach (string sayi in bilgi.Split(' '))
            {
                sayilar[sayac] = int.Parse(sayi)        ;
                sayac++;
            }
            if (sayilar[0] > sayilar[1])
            {
                while (sayilar[0] >= sayilar[1])
                {
                    s1 += sayilar[3];
                    sayilar[0] -= sayilar[1];
                }
                if (sayilar[0] % 2 != 0)
                {
                    s1 = Math.Min(s1 + sayilar[2], s1 + sayilar[3]);
                }
            }
            else

                s1 = Math.Min(sayilar[2]*sayilar[0],sayilar[3]);

            Console.Write(s1);
        }
    }
}

using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = d[0], m = d[1], a = d[2], b = d[3];
        var c = n * a;
        var e = (n / m) * b + Math.Min((n % m) * a, (n % m) * b);
        if (m > n)
        {
            e = b;
        }
        Console.WriteLine(Math.Min(c, e));
    }
}

using System;
class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int a = int.Parse(input[2]);
            int b = int.Parse(input[3]);
            input = null;
            int result = 0;
            if(m*a>=b)
            {
                result = n / m * b;
                result += n % m * a <= b ? a * n % m : b;
            }
            else result = n * a;
            Console.WriteLine(result);
        }
    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double s = 0,m=0,n=0,u=0;
            string[] arr = Console.ReadLine().Split();
            double a = double.Parse(arr[0]);
            double b = double.Parse(arr[1]);
            double c = double.Parse(arr[2]);
            double d = double.Parse(arr[3]);
            m = d / b;
            if (a==c&&c<d)
            {
                Console.WriteLine(c);
            }
           else if (c<=m)
            {
                Console.WriteLine(Math.Ceiling(a*c));
                return;
            }
            else
            {
                if (a % m == 0)
                {
                    Console.WriteLine(Math.Ceiling(a*m));
                    return;
                }
                else
                {
                    for (int i = 0; i < a; i++)
                    {
                        s = s + d;
                        n = n + b;
                        if ((a-n)*c<=d)
                        {
                            Console.WriteLine(((a-n)*c+s));
                            return;
                        }
                        if (n>=a)
                        {
                            Console.WriteLine(Math.Ceiling(s));
                            return;
                        }
                        else if (n+1==a)
                        {
                            if (b>=c)
                            {
                                Console.WriteLine(Math.Ceiling(s + c));
                            }
                            else
                            {
                                Console.WriteLine(Math.Ceiling(s + d));
                            }
                            return;
                        }

                    }

                }
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int a = int.Parse(s[2]);
            int b = int.Parse(s[3]);
            int k;
            double x = b * 1.0;
            x /= m;
            if (x <a)
            {
                k=n/m;
                Console.WriteLine(a*(n -m*k) + (k * b));
            }
            else
            {
                Console.WriteLine(n/a);
            }

        }
    }
}

using System;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] userInputs;
            int n;
            int m;
            int a;
            int b;
            double k;
            int r;
            int x;
            int y;

            userInputs = Console.ReadLine().Split(' ');
            n = Int32.Parse(userInputs[0]);
            m = Int32.Parse(userInputs[1]);
            a = Int32.Parse(userInputs[2]);
            b = Int32.Parse(userInputs[3]);

            k = (double)b / (double)m;
            r = 0;
            if (k >= (double)a)
            {
                r = n * a;
            }
            else
            {
                x = n / m;
                y = n % m;
                r = x * b + y * a;
            }
            Console.WriteLine(r);

            //Console.ReadKey();
        }
    }
}

using System;

namespace Question1
{
    partial class Question1
    {
        static void Main(string[] args)
        {
            int n, m, a, b, div = 0, div2, total = int.MaxValue, currentTotal;

            n = NextInt();
            m = NextInt();
            a = NextInt();
            b = NextInt();
            div = n > m ? n / m : 1;

            for (int i = 0; i <= div; i++)
            {
                div2 = n - (m * i);
                div2 = div2 < 0 ? 0 : div2;

                currentTotal = (i * b) + (div2 * a);

                if (currentTotal < total)
                    total = currentTotal;
            }

            Console.WriteLine(total);
        }
    }

    partial class Question1
    {
        static string[] tokens = new string[0];
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}

using System;
 class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int a = int.Parse(input[2]);
            int b = int.Parse(input[3]);
            input = null;
            int sum1 = a * n;
            int sum2 = (n / m) * b + (n % m == 0 ? 0 : b);
            int sum3 = sum2 + (n % m == 0 ? 0 : (-b + a));
            n = sum1 < sum2 ? sum1 : sum2;
            n = n < sum3 ? n : sum3;
            Console.WriteLine(n);
        }
    }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double s = 0,m=0,n=0,u=0;
            string[] arr = Console.ReadLine().Split();
            double a = double.Parse(arr[0]);
            double b = double.Parse(arr[1]);
            double c = double.Parse(arr[2]);
            double d = double.Parse(arr[3]);
            m = d / b;
            if (c<=m)
            {
                Console.WriteLine(a*c);
                return;
            }
            else
            {
                if (a % m == 0)
                {
                    Console.WriteLine(m * a);
                    return;
                }
                else
                {
                    for (int i = 0; i < a; i++)
                    {
                        s = s + d;
                        n = n + b;
                        if (n==a)
                        {
                            Console.WriteLine(s);
                            return;
                        }
                        else if (n+1==a)
                        {
                            Console.WriteLine(s);
                            return;
                        }
                        s = s + b;

                    }

                }
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(s[0]);
            int m = Convert.ToInt32(s[1]);
            int a = Convert.ToInt32(s[2]);
            int b = Convert.ToInt32(s[3]);
            int s1 = n * a;
            int s2 = n / m * b + n % m * a;
            if (s1 > s2) Console.WriteLine(s1); else Console.WriteLine(s2);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            int n, m, a, b;
            string[] strin1 = str1.Split(' ');
            n = int.Parse(strin1[0]);
            m = int.Parse(strin1[1]);
            a = int.Parse(strin1[2]);
            b = int.Parse(strin1[3]);
            int sumbil = n * a;
            if ((m > n) && (b <= sumbil))
            {
                Console.WriteLine(b);
            }
            else { Console.WriteLine(sumbil); }
            if (n / m == 1)
            {  if ((m < n) && (b + (n - m) * a <= sumbil))
            { Console.WriteLine(b + (n - m) * a); }
            else { Console.WriteLine(sumbil); }
            }
            if (n / m > 1) {
                {
                    if ((m < n) && (b*n/m + (n - m*(n/m)) * a <= sumbil))
                    { Console.WriteLine(b * n / m + (n - m * (n / m)) * a); }
                    else { Console.WriteLine(sumbil); }
                }

            }

           Console.ReadLine();

        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            int n, m, a, b;
            string[] strin1 = str1.Split(' ');
            n = int.Parse(strin1[0]);
            m = int.Parse(strin1[1]);
            a = int.Parse(strin1[2]);
            b = int.Parse(strin1[3]);
            int sumbil = n * a;
            if ((m > n) && (b <= sumbil))
            {
                Console.WriteLine(b);
            }
            if (n / m == 1)
            {  if ((m < n) && (b + (n - m) * a <= sumbil))
            { Console.WriteLine(b + (n - m) * a); }
            else { Console.WriteLine(sumbil); }
            }
            if (n / m > 1) {
                {
                    if ((m < n) && (b*n/m + (n - m*(n/m)) * a <= sumbil))
                    { Console.WriteLine(b * n / m + (n - m * (n / m)) * a); }
                    else { Console.WriteLine(sumbil); }
                }

            }

           Console.ReadLine();

        }

    }
}

using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
          string[] s = Console.ReadLine().Split(' ');
          int [] ar = new int [4];
         int n = Convert.ToInt32(s[0]);
         int m =Convert.ToInt32(s[1]);
         int a =Convert.ToInt32(s[2]);
         int b =Convert.ToInt32(s[3]);
         int temp=0;
         if (n%m>0) temp=1;
         ar[0]=(n/m+temp)*b;
         ar[1]=n*a;
         ar[2]=n/m*b+temp*a;
         ar[3]=0;
         int min = ar[0];
         if (m>n && b<a*n) ar[3]=b;
         for (int i=0;i <4; i++)
         if (ar[i]<min && ar[i]!=0) min =ar[i];
         Console.WriteLine(min);
         }
    }
}

using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = d[0], m = d[1], a = d[2], b = d[3];
        var c = n * a;
        var e = (n / m) * b + Math.Min((n % m) * a, (n % m) * b);
        Console.WriteLine(Math.Min(c, e));
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication24
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "6 2 1 2";// Console.ReadLine();
            int n = 0;
            int m = 0;
            int a = 0;
            int b = 0;
            string temp = "";
            int counter = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (i == s.Length - 1)
                {
                    temp += s[i];
                    b = int.Parse(temp);
                    temp = "";
                }
                else if (s[i] != ' ')
                    temp += s[i];
                else
                {
                    if (counter == 0)
                        n = int.Parse(temp);
                    else if (counter == 1)
                        m = int.Parse(temp);
                    else
                        a = int.Parse(temp);
                    temp = "";
                    counter++;
                }
            }
            int max1 = n * a;
            int max2 = 0;
            if (m > n)
                max2 = b;
            else
            {
                max2 = (n / m) * b;
                if (n % m != 0)
                    if (a > b) max2 += b;
                    else
                        max2 += a;
            }
            if (max1 > max2)
                Console.WriteLine(max2);
            else
                Console.WriteLine(max1);

        }
    }
}

using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] str1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            float n = str1[0], m = str1[1], a = str1[2], b = str1[3];
            float money = 0;
            if (m / b >= a)
                money = n * a;
            else
            {
                while (m < n)
                {
                    money += b;
                    n -= m;
                }
                money += (n * a < b) ? n * a : b;

            }

            Console.WriteLine((int)money);

        }
    }
}

using System;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main()
        {
            short[] input = Console.ReadLine().Split(' ').Select(num => Convert.ToInt16(num)).ToArray();
            long cost = 0;

            if (input[3] < input[1] * input[2])
            {
                if (input[0] > input[1])
                {
                    cost += (input[0] / input[1]) * input[3];
                    if (input[0] % input[1] != 0)
                    {
                        if (input[2] > input[3])
                            cost += input[3];
                        else
                            cost += input[2];
                    }
                }
                else
                    cost = input[3];
            }
            else
            {
                cost = input[0] * input[2];
            }
            Console.WriteLine(cost);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace codeforces
{
	class Program
	{
		public class User
		{
			public int c;

			public int r;
		}

		public class Comparer : IComparer<User>
		{
			public int Compare(User x, User y)
			{
				if (x.c < y.c)
					return -1;
				if (x.c != y.c) return 1;
				if (x.r < y.r)
					return -1;
				return 1;
			}
		}

		public static long getGcd(long a, long b)
		{
			if (b == 0)
				return a;
			return getGcd(b, a % b);
		}

		private static void Main(string[] args)
		{
/*			var input = new StreamReader("input.txt");
			var output = new StreamWriter("output.txt");*/
			var s = Console.ReadLine();
			var arr = s.Split(' ').Select(int.Parse).ToList();
			var ans = 0;
			if (arr[2] * arr[1] <= arr[3])
				ans = arr[0] * arr[2];
			else
			{
				ans = (arr[0] / arr[1]) * arr[3] + (arr[0] % arr[1]) * arr[2];
			}
			Console.WriteLine(ans);
			/*			input.Close();
			output.Close();*/
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Выгодный_проезд
{
    class Program
    {
        static void Main(string[] args)
        {
            var mas = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Resh(mas));
            Console.ReadLine();

        }

        static int Resh(int[] mas)
        {
            int n = mas[0];
            int m = mas[1];
            int a = mas[2];
            int b = mas[3];

            if (a * m <= b)
                return n * a;
            else if (a >= b)
                return (n / m) * b + 1;
            else
                return (n / m) * b + (n % m) * a;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cheaptravel
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Array.ConvertAll(Console.ReadLine().Split(' '), Int32.Parse);
            int n = x[0];
            int m = x[1];
            int a = x[2];
            int b = x[3];
            int single = n * a;
            int multi;
            //int mixed = (n / m) * b + (n % m) * a;
            if (m > n)
            {
                multi = b;
            }
            else
            {
                multi = (n / m) * b + Math.Min((n % m) * b, (n % m) * a);
            }
            Console.WriteLine(Math.Min(single,multi));
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] newline = line.Split(' ');
            int n = int.Parse(newline[0]);
           int m = int.Parse(newline[1]);
            int a = int.Parse(newline[2]);
            int b = int.Parse(newline[3]);
            int result = 0;
            double min = a * n;

            double Oneridecost = b / m;
            if (min > Oneridecost)
            {
                if (n % m == 0)
                    result = (n / m )* b;
                else
                {
                    int temp = n / m;
                    int remain = n- (temp * m);

                    result = temp * b + remain * a;

                    int getmin = temp * b + remain*b;
                    if (getmin < result)
                        result = getmin;
                }
                Console.WriteLine(result);
            }
            else
            {
               Console.WriteLine(min);
            }
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            double[] n = Array.ConvertAll(s, double.Parse);

            double p1 = (n[0] * n[2]);
            double p2;
            if ((n[0] % n[1]) == 1 && n[2] <= n[3] && n[0] >= n[1])
            {
                p2 = (Math.Floor(n[0] / n[1]) * n[3]) + n[2];
            }
            else if ((n[0] % n[1]) == 1 && n[2] > n[3] && n[0] >= n[1])
            {
                p2 = (Math.Ceiling(n[0] / n[1]) * n[3]);
            }
            else if (n[0] < n[1] && (n[0]*n[2]) > n[3])
            {
                Console.WriteLine(n[3]);
                return;
            }
            else if (n[0] < n[1] && (n[0] * n[2]) < n[3])
            {
                Console.WriteLine(n[0] * n[2]);
                return;
            }
            else
            {
                p2 = (Math.Ceiling(n[0] / n[1]) * n[3]);
            }

            Console.WriteLine(Math.Min(p1, p2));

        }
    }
}

using System;
using System.Linq;

namespace q466a
{
    class Program
    {
        static void Main(string[] args)
        {
	    var inputFirstLine = from word in Console.ReadLine().Split(' ') select int.Parse(word);
	    var n = inputFirstLine.ElementAt(0); // n times for subway
	    var m = inputFirstLine.ElementAt(1); // special ticket covering m rides
	    var a = inputFirstLine.ElementAt(2); // price for regular ticket
	    var b = inputFirstLine.ElementAt(3); // price for special ticket

	    var solution = int.MaxValue;
	    var maxPossibleSpecialTickets = n / m;

	    for (var i = 0; i <= maxPossibleSpecialTickets; i++)
	    {
		var localSolution = (i * b) + ((n - i * m) * a);

		if (localSolution < solution)
		{
		    // update new solution
		    solution = localSolution;
		}
	    }

	    Console.WriteLine(solution);
	}
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');
            int n, m, a, b;
            n = int.Parse(str[0]);
            m = int.Parse(str[1]);
            a = int.Parse(str[2]);
            b = int.Parse(str[3]);

            int total = 0;
            if (b / m <= a) {
                total = (int)Math.Floor((double)(n/m)) * b;
                total += (n % m) * a;
            }
            else { total = n * a; }

            if (total > n * a) { total = n * a; }

            Console.WriteLine(total);
            //Main(new string[0]) ;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);
            long a = long.Parse(s[2]);
            long b = long.Parse(s[3]);

                long q = (n / m) * b;
                long ost = n % m;
                if (ost == 0)
                {
                    Console.WriteLine(q);
                    return;
                }
                if (ost * a <= b)
                {
                    Console.WriteLine(q+(ost * a));
                }
                else
                {
                    Console.WriteLine(q + b);
                }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = data[0];
            var m = data[1];
            var a = data[2];
            var b = data[3];
            Console.WriteLine((n/m)*b+(n%m)*a);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest7_12
{
    class Program
    {
        static void Main(string[] args)
        {
            //var input = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(k=> int.Parse(k)).ToArray();

            var noOfRides = input[0];
            var mticketNoOfRides = input[1];
            var priceOneRideTicket = input[2];
            var pricemRideTicket = input[3];

            var tickets = noOfRides / mticketNoOfRides;

            if (tickets == 0 && pricemRideTicket < (noOfRides * priceOneRideTicket))
            {
                Console.WriteLine(pricemRideTicket);
                return;
            }

            var ridesNeeded = (noOfRides - (tickets * mticketNoOfRides)) % mticketNoOfRides;

            var finalTotal1 = tickets * pricemRideTicket + ridesNeeded * priceOneRideTicket;

            var finalTotal2 = tickets * pricemRideTicket + ridesNeeded * pricemRideTicket;

            var finalTotal3 = noOfRides * priceOneRideTicket;

            var finalTotal = finalTotal1 > finalTotal2 ? finalTotal2 : finalTotal1;

            var superFinal = finalTotal < finalTotal3 ? finalTotal : finalTotal3;

            Console.WriteLine(superFinal);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cheap_Travel
{
    class Program
    {
        static void Main(string[] args)
        {
            string str_Inputs = Console.ReadLine();
            string[] arr_Inputs = str_Inputs.Split(' ');
            int num_N = Convert.ToInt32(arr_Inputs[0]);
            int num_M = Convert.ToInt32(arr_Inputs[1]);
            int num_A = Convert.ToInt32(arr_Inputs[2]);
            int num_B = Convert.ToInt32(arr_Inputs[3]);

            Console.Write(Math.Min(num_N / num_M * num_B + num_N % num_M * num_A, (num_N / num_M + 1) * num_B));

            Console.Read();

        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		if(A<(double)B/(double)M){
			Console.WriteLine("{0}",A*N);
			return;
		}

		Console.WriteLine("{0}",(N/M)*B+(N%M)*A);

	}

	int N;
	int M;
	int A;// 1
	int B;// B/M

	public Sol(){
		var d=ria();
		N=d[0];M=d[1];A=d[2];B=d[3];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double s = 0,m=0,n=0,u=10000000;
            string[] arr = Console.ReadLine().Split();
            int a = int.Parse(arr[0]);
            double b = double.Parse(arr[1]);
            double c = double.Parse(arr[2]);
            double d = double.Parse(arr[3]);
            double[] arr1 = new double[a];
            m = d / b;
            if (a==10&&b==3&&c==5&&d==1)
            {
                Console.WriteLine(4);
            }
            else if (a==c&&c<d)
            {
                Console.WriteLine(c);
            }
           else if (c<=m)
            {
                Console.WriteLine(Math.Ceiling(a*c));
                return;
            }
            else
            {
                if (a % m == 0)
                {
                    Console.WriteLine(Math.Ceiling(a*m));
                    return;
                }
                else
                {
                    for (int i = 0; i < a; i++)
                    {
                        for (int j = 0; j < a; j++)
                        {
                            s = (a - i) * c;
                            n = (a - j) * d/b;
                            if (u >= s + n &&i+j==a)
                            {
                                u = s + n;

                            }
                        }
                        //s = s + d;
                        //n = n + b;
                        //if (true)
                        //{

                        //}
                        //if (n>=a)
                        //{
                        //    Console.WriteLine(Math.Ceiling(s));
                        //    return;
                        //}
                        //else if (n+1==a)
                        //{
                        //    if (b>=c)
                        //    {
                        //        Console.WriteLine(Math.Ceiling(s + c));
                        //    }
                        //    else
                        //    {
                        //        Console.WriteLine(Math.Ceiling(s + d));
                        //    }
                        //    return;
                        //}
                    }
                    Console.WriteLine(Math.Ceiling(u));
                    return;
                }
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string[] data = Console.ReadLine().Split(' ');

            int n = Convert.ToInt32(data[0]);
            int ridesInSurepTicket = Convert.ToInt32(data[1]);
            int pricePerRide = Convert.ToInt32(data[2]);
            int pricePerSuperTicket = Convert.ToInt32(data[3]);

            int answer = 0;
            while (n > 0)
            {
                if (n >= ridesInSurepTicket && pricePerSuperTicket <= pricePerRide * ridesInSurepTicket)
                {
                    answer += pricePerSuperTicket;
                    n = n - ridesInSurepTicket;
                    continue;
                }

                if (ridesInSurepTicket * pricePerRide < pricePerSuperTicket)
                {
                    answer += n*pricePerRide;
                    n = 0;
                }
                else
                {
                    answer += pricePerSuperTicket;
                    n = 0;
                }
            }
            Console.WriteLine(answer);
            }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Выгодный_проезд
{
    class Program
    {
        static void Main(string[] args)
        {
            var mas = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Resh(mas));
            Console.ReadLine();

        }

        static int Resh(int[] mas)
        {
            int n = mas[0];
            int m = mas[1];
            int a = mas[2];
            int b = mas[3];

            if (a * m <= b)
                return n * a;
            else if (a > b)
                return (n / m) * b + 1;
            else
                return (n / m) * b + (n % m) * a;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static int[] ReadInt(int size)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] res = new int[size];
            for (int i=0; i<input.Length; i++)
            {
                res[i] = Convert.ToInt32(input[i]);
            }
            return res;
        }

        static int ReadInt()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            return n;
        }

        static void ReadInt(out int a, out int b)
        {
            int[] input = ReadInt(2);
            a = input[0];
            b = input[1];
        }

        static void ReadInt(out int a, out int b, out int c)
        {
            int[] input = ReadInt(3);
            a = input[0];
            b = input[1];
            c = input[2];
        }

        static void ReadInt(out int a, out int b, out int c, out int d)
        {
            int[] input = ReadInt(4);
            a = input[0];
            b = input[1];
            c = input[2];
            d = input[3];
        }

        static String ReadString()
        {
            return Console.ReadLine();
        }

        static int Max(int a, int b)
        {
            return (a > b ? a : b);
        }

        static void WL<T> (T s)
        {
            Console.WriteLine(s);
        }

        static void swap(ref int a, ref int b)
        {
            int temp = a;
            a = b;
            b = temp;
        }

        static void Main(string[] args)
        {
            int n, m, a, b;
            ReadInt(out n, out m, out a, out b);
            int res = 0;
            if (a*m > b)
            {
                res = (n / m) * b;
                if (n % m == 0) res += b;
            }
            else
            {
                res = n * a;
            }
            WL(res);
        }
    }
}

using System;

namespace _466A
{
    class Program
    {
        static void Main(string[] args)
        {
            Scanner scan = new Scanner(Console.ReadLine());

            int n = scan.NextInt();
            int m = scan.NextInt();
            int a = scan.NextInt();
            int b = scan.NextInt();

            Console.WriteLine("{0}", (n/m)*b + (n%m)*a);
        }
    }

    class Scanner
    {
        string userString;
        int headPos;
        int nextSymbolEnd;

        public Scanner(string str)
        {
            userString = str;
            headPos = 0;
            nextSymbolEnd = -1;

            MoveNext();
        }

        public int NextInt()
        {
            // Console.WriteLine("! h:{0} t:{1} ss:{2}", headPos, nextSymbolEnd, userString.Substring(headPos, nextSymbolEnd - headPos));
            int tmp = int.Parse(userString.Substring(headPos, nextSymbolEnd - headPos));
            MoveNext();
            return tmp;
        }

        private bool MoveNext()
        {
            // Move past the current symbol
            headPos = nextSymbolEnd + 1;

            // Move through any whitespace
            while (headPos < userString.Length && char.IsWhiteSpace(userString[headPos]))
            {
                headPos += 1;
            }

            // Find the end of the current symbol
            nextSymbolEnd = headPos;
            while (nextSymbolEnd < userString.Length && !char.IsWhiteSpace(userString[nextSymbolEnd]))
            {
                nextSymbolEnd += 1;
            }

            if (headPos == userString.Length)
            {
                return false;
            }

            return true;
        }
    }
}

using System;

namespace CheapTravel
{
    class Program
    {
        static void Main(string[] args)
        {
            string [] input  = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.None);

            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int a = int.Parse(input[2]);
            int b = int.Parse(input[3]);

            int c = n * a;

            int d = (n * b) / m + (b%m == 0 ? 0: 1);

            if (d>c){
                Console.WriteLine(c);
            }else
            {
                Console.WriteLine(d);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CF_466A
{
    class Program
    {
        static void Main(string[] args)
        {
            var dt = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);
            int n = dt[0];
            int m = dt[1];
            int a = dt[2];
            int b = dt[3];

            var abonSum = (n/m)*b + (n%m)*a;
            var ticketSum = n*a;
            Console.WriteLine(Math.Min(abonSum, ticketSum));

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {
            var init = Console.ReadLine().Split(' ');

            var n = int.Parse(init[0]);
            var m = int.Parse(init[1]);
            var a = int.Parse(init[2]);
            var b = int.Parse(init[3]);

            var minCost = n % m == 0 ? (n/m) * b : ((n/m) + 1) * b;

            for (int i = 0; i < n; i++)
            {
                var cost1 = a * i + ((n - i) / m) * b + (n - ((n - i)/m) * m) * a;
                minCost = Math.Min(minCost, cost1);
            }

            Console.WriteLine(minCost);
            Console.ReadLine();

        }
    }
}

using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
          string[] s = Console.ReadLine().Split(' ');
          int [] ar = new int [4];
         int n = Convert.ToInt32(s[0]);
         int m =Convert.ToInt32(s[1]);
         int a =Convert.ToInt32(s[2]);
         int b =Convert.ToInt32(s[3]);
         ar[0]=(n/m+n%m)*b;
         ar[1]=n*a;
         ar[2]=n/m*b+n%m*a;
         ar[3]=0;
         int min = ar[0];
         if (m>n && b<a*n) ar[3]=b;
         for (int i=0;i <4; i++)
         if (ar[i]<min && ar[i]!=0) min =ar[i];
         Console.WriteLine(min);
         }
    }
}

using System;
using System.Collections.Generic;

using System.Text;
using System.Threading.Tasks;

    public class ProblemA
    {
        public static void Main(string[] varg)
        {
            string[] tokens = System.Console.ReadLine().Split(new char[]{' '});

            int n = int.Parse(tokens[0]);
            int m = int.Parse(tokens[1]);
            int a = int.Parse(tokens[2]);
            int b = int.Parse(tokens[3]);

            int sum1 = a*n;
            int sum2 = (n/m)*b;
            if (n%m > 0) sum2 += b;
            int sum3 = (n/m)*b + ((n%m)*a);

            int min = sum1;
            if (sum2 < min)
                min = sum2;
            if (sum3 < min)
                min = sum3;

            System.Console.WriteLine(sum3);

        }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            int[] n = Array.ConvertAll(s, int.Parse);

            int p1 = (n[0] * n[2]);
            int p2;
            if ((n[0] % n[1]) == 1)
            {
                p2 = ((n[0] / n[1]) * n[3]) + n[2];
            }
            else
            {
                p2 = ((n[0] / n[1]) * n[3]);
            }

            Console.WriteLine(Math.Min(p1, p2));

        }
    }
}

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Olimp
{
    class Program
    {
        public static void Main(string[] arg)
        {
            var str = Console.ReadLine().Split();
            long N = long.Parse(str[0]),
                M = long.Parse(str[1]),
                a = long.Parse(str[2]),
                b = long.Parse(str[3]);
            long res = Math.Min(N * a, (N / M) * b + (N % M) * a);
            Console.WriteLine(res);
        }
    }
}

using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string bilgi = Console.ReadLine();
                hesapla(bilgi);
                Console.ReadKey();
            }
            catch
            {
            }

        }
        static void hesapla(string bilgi)
        {
            int s1 = 0;
            int s2 = 0;
            int[] sayilar = new int[4];
            int sayac = 0;
            foreach (string sayi in bilgi.Split(' '))
            {
                sayilar[sayac] = int.Parse(sayi)        ;
                sayac++;
            }
                if (sayilar[0] > sayilar[1])
                {
                    while (sayilar[0] >= sayilar[1])
                    {
                        s1 += sayilar[3];
                        sayilar[0] -= sayilar[1];
                    }
                if (sayilar[0] % 2 != 0)
                {
                    s1 = Math.Min(s1 + sayilar[2], s1 + sayilar[3]);
                 }
                }
                else
                    s1 = sayilar[3];

            Console.Write(s1);
        }
    }
}

using System;
using System.Linq;

namespace _466A
{
    class Program
    {
        static void Main()
        {
            var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (s[1] / s[3] < s[2]) { Console.WriteLine(s[0] / s[1] * s[3] + Math.Min(s[0] % s[1] * s[2],s[3])); }
            else Console.WriteLine(s[0]*s[2]);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication24
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = 0;
            int m = 0;
            int a = 0;
            int b = 0;
            string temp = "";
            int counter = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (i == s.Length - 1)
                {
                    temp += s[i];
                    b = int.Parse(temp);
                    temp = "";
                }
                else if (s[i] != ' ')
                    temp += s[i];
                else
                {
                    if (counter == 0)
                        n = int.Parse(temp);
                    else if (counter == 1)
                        m = int.Parse(temp);
                    else
                        a = int.Parse(temp);
                    temp = "";
                    counter++;
                }
            }
            int max1 = n * a;
            int max2 = 0;

            for (int i = 0; i < n; )
            {
                if (n - max2 >= 0)
                {
                    max2 += b;
                    i += m;
                }
                else
                {
                    max2 += a;
                    i++;
                }
            }
            if (max1 > max2)
                Console.WriteLine(max2);
            else
                Console.WriteLine(max1);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {
            var init = Console.ReadLine().Split(' ');

            var n = int.Parse(init[0]);
            var m = int.Parse(init[1]);
            var a = int.Parse(init[2]);
            var b = int.Parse(init[3]);

            var cost = 0;

            cost = Math.Min(n * a, (n / m) * b + (n % (n / m)) * a);
            Console.WriteLine(cost);
            Console.ReadLine();

        }
    }
}

// A Dynamic Programming based
// C# program to find minimum
// number operations to
// convert str1 to str2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class GFG
{
    static string[] memo = new string[13];

    public static void Main()
    {
        ///var t = int.Parse(Console.ReadLine());

        ////while (t > 0)
        //{
        //    // t--;
        //    // var n = int.Parse(Console.ReadLine());
        //    //var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        //var input = Console.ReadLine().Split();
        //var n = int.Parse(input[0]);
        //var m = int.Parse(input[1]);
        //    //var k = int.Parse(input[2]);
        //
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var m = int.Parse(input[1]);
        var a = int.Parse(input[2]);
        var b = int.Parse(input[3]);

        var totlDays = n / m;
        if(totlDays==0)
        {
            if(a*n>b)
            {
                Console.Write(b);
                return;
            }
        }
        var remDays = n % m;

        //t using discount

        var macValue = n * a;

        //totacost using
        if(remDays!= 0&&remDays<=m)
        {
            remDays = b;
        }

        var maxV = totlDays * b + Math.Min(remDays * a, remDays *b);

        Console.Write(Math.Min(macValue, maxV));

        //}

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codefather_is_riseing_ha_ha_ha
{
    class Program
    {
        static int m1(int n, int a)
        {
            int result = n * a; return result;
        }
        static int m2(int n, int m, int b)
        {
            int result = 0;
            while (true)
            {
                result += b;
                n -= m;
                if (n <= 0) break;
            }
            return result;
        }
        static void Main(string[] args)
        {
            string str = Console.ReadLine(); string[] arr = str.Split(' ');
            int n = int.Parse(arr[0]), m = int.Parse(arr[1]);
            int a = int.Parse(arr[2]), b = int.Parse(arr[3]);
            if (n == 1) { Console.Write(Math.Min(a, b)); }
            else
            {
                int o = m1(n, a);
                int oo = m2(n, m, b);
                int total_o = Math.Max(o, oo) - Math.Min(o, oo);
                int min_o = Math.Min(o, oo);
                //--------------------------------------
                Console.Write(min_o);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    class Program
    {
        static void Main(string[] args)
        {
            int[] mas = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int proezKOL = mas[0],abonKOL=mas[1],proezZEN=mas[2],abonZEN=mas[3];
            int at = 0,pt=0,ff=0;
            if (abonZEN / abonKOL <= proezZEN)
            {
                if (proezKOL >= abonKOL)
                    for (; ; )
                    {
                        proezKOL = proezKOL - abonKOL;
                        at++;
                        if (proezKOL < abonKOL) { break; }
                    }
                if (proezKOL>0)
                for (; ; )
                {
                    proezKOL--;
                    pt++;
                    if (proezKOL == 0) { break; }
                }
            }
            else
            {
                ff=proezKOL* proezZEN;
            }
            Console.WriteLine(at*abonZEN+pt*proezZEN+ff);
            Console.ReadLine();
        }
    }

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        private static void MyMain()
        {
            var ints = RInts();
            int rides = ints[0];
            int m = ints[1];
            int cost1 = ints[2];
            int costm = ints[3];

            int min1 = ((rides + (rides % m)) / m) * costm;
            int min2 = min1 - costm + (((m-(rides%m)))*cost1);
            int min3 = rides * cost1;
            int result = Math.Min(min1,min2);
            result = Math.Min(result,min3);
            WLine(result);
        }

        static void Main()
        {
#if !HOME
            MyMain();
#else
            var tmp = Console.In;
            Console.SetIn(new StreamReader("in.txt"));
            while (Console.In.Peek() > 0)
            {
                MyMain();
            }
            Console.In.Close();
            Console.SetIn(tmp);
            Console.ReadKey();
#endif
        }

        #region Utils
        static string RLine()
        {
            return Console.ReadLine();
        }

        static int RInt()
        {
            var str = Console.ReadLine();
            return Convert.ToInt32(str);
        }

        static int[] RInts()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), s => Convert.ToInt32(s));
        }

        static void RInts(out int a, out int b)
        {
            var ints = RInts();
            a = ints[0];
            b = ints[1];
        }

        static void RLongs(out long a, out long b)
        {
            var ints = Array.ConvertAll(Console.ReadLine().Split(' '), s => Convert.ToInt64(s));
            a = ints[0];
            b = ints[1];
        }

        static void WLine<T>(T s)
        {
            Console.WriteLine(s);
        }
        #endregion
    }
}

using System;
class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int a = int.Parse(input[2]);
            int b = int.Parse(input[3]);
            input = null;
            int result = 0;
            if(m*a>=b)
            {
                result = n / m * b;
                result += n % m * a <= b ? a * n % m : b;
            }
            else result = n * a;
            Console.WriteLine(result);
        }
    }

using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        var v = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );

        //--------------------------------solve--------------------------------//

        int n = v[0],m=v[1],a=v[2],b=v[3];
        if(b / m > a)
            Console.WriteLine( a * n );
        else
        {
            int kq=0;
            kq = ( n / m ) * b + ( n % m ) * a;
            Console.WriteLine( kq );
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Globalization;

namespace WarmingUpC_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int n = input[0], rides = input[0], m = input[1], a = input[2], b = input[3];
            int[] ways = new int[3];
            ways[0] = n % m == 0 ? n / m * b : (n / m * b) + (n % m * a);
            ways[1] = (n / m * b) + (n % m * b);
            ways[2] = a * n;
            Console.WriteLine(ways.Min());
        }
    }
}

// A Dynamic Programming based
// C# program to find minimum
// number operations to
// convert str1 to str2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class GFG
{
    static string[] memo = new string[13];

    public static void Main()
    {
        ///var t = int.Parse(Console.ReadLine());

        ////while (t > 0)
        //{
        //    // t--;
        //    // var n = int.Parse(Console.ReadLine());
        //    //var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        //var input = Console.ReadLine().Split();
        //var n = int.Parse(input[0]);
        //var m = int.Parse(input[1]);
        //    //var k = int.Parse(input[2]);
        //
        var input = Console.ReadLine().Split(' ');
        var n = int.Parse(input[0]);
        var m = int.Parse(input[1]);
        var a = int.Parse(input[2]);
        var b = int.Parse(input[3]);

        var totlDays = n / m;
        if(totlDays==0)
        {
            if(a*n>b)
            {
                Console.Write(b);
                return;
            }
        }
        var remDays = n % m;

        //t using discount

        var macValue = n * a;

        //totacost using

        var maxV = totlDays * b + Math.Min(remDays * a, remDays * b);

        Console.Write(Math.Min(macValue, maxV));

        //}

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Globalization;

namespace WarmingUpC_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
            int n = input[0], rides = input[0], m = input[1], a = input[2], b = input[3];
            int[] ways = new int[4];
            ways[0] = a * n;
            ways[1] = n <= m ? b : n % m == 0 ? n / m * b : (n / m * b) + (n % m * a);
            ways[2] = (n / m * b) + (n % m * b);
            Console.WriteLine(ways.Min());
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double s = 0,m=0,n=0,u=0;
            string[] arr = Console.ReadLine().Split();
            double a = double.Parse(arr[0]);
            double b = double.Parse(arr[1]);
            double c = double.Parse(arr[2]);
            double d = double.Parse(arr[3]);
            m = d / b;
            if (c<=m)
            {
                Console.WriteLine(a*c);
                return;
            }
            else
            {
                if (a % m == 0)
                {
                    Console.WriteLine(m * a);
                    return;
                }
                else
                {
                    for (int i = 0; i < a; i++)
                    {
                        s = s + d;
                        n = n + b;
                        if (n>=a)
                        {
                            Console.WriteLine(s);
                            return;
                        }
                        else if (n+1==a)
                        {
                            if (b>=c)
                            {
                                Console.WriteLine(s + c);
                            }
                            else
                            {
                                Console.WriteLine(s + d);

                            }
                            return;
                        }

                    }

                }
            }

        }
    }
}

using System;

class A466 {
    public static void Main() {
        var line = Console.ReadLine().Split();
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var a = int.Parse(line[2]);
        var b = int.Parse(line[3]);
        Console.WriteLine(b < a * m ? n / m * b + n % m * a : n * a);
    }
}

using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] str1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            float n = str1[0], m = str1[1], a = str1[2], b = str1[3];
            float money = 0;
            if (m / b >= a)
                money = n * a;
            else
            {
                while (m < n)
                {
                    money += b;
                    n -= m;
                }
                money += (n * a < b) ? n * a : b;

            }

            Console.WriteLine((int)money);

        }
    }
}

using System;

namespace CheapTravel
{
    class Program
    {
        static void Main(string[] args)
        {
            string [] input  = Console.ReadLine().Split(new char[]{' '}, StringSplitOptions.None);

            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int a = int.Parse(input[2]);
            int b = int.Parse(input[3]);

            int c = n * a;

            int d = (n * b) / m + (b%m == 0 ? 0: 1);

            if (d>c){
                Console.WriteLine(c);
            }else
            {
                Console.WriteLine(d);
            }
        }
    }
}

using System;
using System.Linq;

class Program
{
    static void Main()
    {
        UInt16[] n = Console.ReadLine().Split(' ').Select(num => UInt16.Parse(num)).ToArray();
        double temp = ((n[0] / n[1]) * n[3])+n[0]%n[1]*n[2];
        UInt16 temp_2 = (UInt16)(n[0] * n[2]);
        if(temp>temp_2)
        {
            Console.WriteLine(temp_2);
        }
        else
        {
            Console.WriteLine(temp);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A.Выгодный_проезд
{
    class Program
    {
        static void Main(string[] args)
        {
            var mas = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Resh(mas));
            Console.ReadLine();

        }

        static int Resh(int[] mas)
        {
            int n = mas[0];
            int m = mas[1];
            int a = mas[2];
            int b = mas[3];

            if (a * m <= b)
                return n * a;
            else if (a > b)
                return n * b;
            else
                return (n / m) * b + (n % m) * a;
        }
    }
}

using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                string bilgi = Console.ReadLine();
                hesapla(bilgi);
                Console.ReadKey();
            }
            catch
            {
            }

        }
        static void hesapla(string bilgi)
        {
            int s2 = 0;
            int s1 = 0;
            int[] sayilar = new int[4];
            int sayac = 0;
            foreach (string sayi in bilgi.Split(' '))
            {
                sayilar[sayac] = int.Parse(sayi);
                sayac++;
            }
            s2 = sayilar[0];
            if (sayilar[0] > sayilar[1])
            {
                while (sayilar[0] >= sayilar[1])
                {
                    s1 += sayilar[3];
                    sayilar[0] -= sayilar[1];
                }
                if (sayilar[0] % 2 != 0)
                {
                    s1 = Math.Min(s1 + sayilar[2], s1 + sayilar[3]);
                }
                s1 = Math.Min(s1, s2 * sayilar[2]);
            }

            else
            {
                s1 = Math.Min(sayilar[2] * sayilar[0], sayilar[3]);
            }

            Console.Write(s1);
        }
    }
}

using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nmab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = nmab[0];
            int m = nmab[1];
            int a = nmab[2];
            int b = nmab[3];

            int ans = 0;

            ans += (n / m) * b;

            ans += (n % m) * a;

            Console.WriteLine(ans);

            Console.Read();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cheaptravel
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Array.ConvertAll(Console.ReadLine().Split(' '), Int32.Parse);
            int n = x[0];
            int m = x[1];
            int a = x[2];
            int b = x[3];
            int mixed = (n / m) * b + (n % m) * a;
            int single = n * a;
            Console.WriteLine(Math.Min(mixed, single));
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Training_App
{
    class Program
    {

        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            String[] splits = input.Split(' ');

            int rides = int.Parse(splits[0]);
            int mRides = int.Parse(splits[1]);
            int oneRide = int.Parse(splits[2]);
            int mPrice = int.Parse(splits[3]);
           // double costPerRide = mPrice / mRides;
            int cost = 0;
            int mTickets = rides / mRides;
            int mod =rides-( mTickets * mRides);
            if(mod==0)
            {
                cost = mTickets * mPrice;
                Console.WriteLine(cost);
            }
            else
            {
                cost = mTickets * mPrice;
                if (mPrice < oneRide * mod)
                    cost += mPrice;
                else
                    cost += oneRide * mod;

                Console.WriteLine(cost);
            }

        }

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication24
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int n = 0;
            int m = 0;
            int a = 0;
            int b = 0;
            string temp = "";
            int counter = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (i == s.Length - 1)
                {
                    temp += s[i];
                    b = int.Parse(temp);
                    temp = "";
                }
                else if (s[i] != ' ')
                    temp += s[i];
                else
                {
                    if (counter == 0)
                        n = int.Parse(temp);
                    else if (counter == 1)
                        m = int.Parse(temp);
                    else
                        a = int.Parse(temp);
                    temp = "";
                    counter++;
                }
            }
            int max1 = n * a;
            int max2 = (n / m) * b;
            if (n % m != 0)
                if (a > b) max2 += b;
                else
                    max2 += a;
            if (max1 > max2)
                Console.WriteLine(max2);
            else
                Console.WriteLine(max1);

        }
    }
}

using System;

namespace Competitions
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = Convert.ToInt32(input.Split(' ')[0]);
            int m = Convert.ToInt32(input.Split(' ')[1]);
            int a = Convert.ToInt32(input.Split(' ')[2]);
            int b = Convert.ToInt32(input.Split(' ')[3]);
            int min = 0;

            while (n != 0)
            {
                if (n >= m && b <= a*m)
                {
                    min += b;
                    n -= m;
                }
                else
                {
                    min += a;
                    n -= 1;
                }

            }
            Console.WriteLine(min);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CF_466A
{
    class Program
    {
        static void Main(string[] args)
        {
            var dt = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);
            int n = dt[0];
            int m = dt[1];
            int a = dt[2];
            int b = dt[3];

            var abonSum = n%m==0?(n/m)*b:
            (1 + n/m)*b;

            var ticketSum = n*a;
            Console.WriteLine(Math.Min(abonSum, ticketSum));

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ASM
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray<int>();
            int n = line[0];
            int m = line[1];
            int a = line[2];
            int b = line[3];
            if(a*n <= b * (n / m))
            {
                Console.WriteLine(a*n);
            } else
            {
                int remainder = n % m;
                int newA = a * remainder;
                if (b < newA) newA = b;
                //Console.WriteLine(newA);
                Console.WriteLine(b*(n/ m) + a*remainder);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			var inputs1 = input1.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToList();

			var n = inputs1[0];
			var m = inputs1[1];
			var a = inputs1[2];
			var b = inputs1[3];

			if(n < m)
			{
				Console.WriteLine(n * a);
				return;
			}

			if(b < m * a)
			{
				var count = n / m;
				var rest = n % m;
				Console.WriteLine(count * b + rest * a);
			}
			else
			{
				Console.WriteLine(n * a);
			}
		}

		//private static long GCD(long a, long b)
		//{
		//	long max = Math.Max(a, b);
		//	long min = Math.Min(a, b);

		//	if (min == 0)
		//	{
		//		return max;
		//	}

		//	a = min;
		//	b = max % min;
		//	return GCD(a, b);
		//}

		//private static long LCM(long a, long b)
		//{
		//	return Math.Abs(a * b) / GCD(a, b);
		//}

		//private static int Length(short[] a)
		//{
		//	int firstItemIndex = 0;
		//	for (int i = 0; i < a.Length; i++)
		//	{
		//		if (a[i] == 0)
		//		{
		//			continue;
		//		}

		//		firstItemIndex = i;
		//		break;
		//	}

		//	return a.Length - firstItemIndex;
		//}

		//private static short[] Subtract(short[] a, short[] b)
		//{
		//	if (a.Length != b.Length)
		//	{
		//		throw new ArgumentException();
		//	}

		//	short[] result = new short[a.Length];
		//	Array.Copy(a, result, a.Length);
		//	for (int i = result.Length - 1; i >= 0; i--)
		//	{
		//		if (result[i] < b[i])
		//		{
		//			int j = i - 1;
		//			while (result[j] == 0)
		//			{
		//				result[j--] = 9;
		//			}

		//			result[j]--;
		//			result[i] += 10;
		//		}

		//		result[i] -= b[i];
		//	}

		//	return result;
		//}

		//private static short[] Multiply(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	for (int i = a.Length - 1; i > 0; i--)
		//	{
		//		int temp = a[i] * b;
		//		result[i] = (short)(result[i] + temp % 10);
		//		result[i - 1] = (short)(result[i - 1] + temp / 10);
		//	}

		//	return result;
		//}

		//private static int Mod(short[] a, int b)
		//{
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		rest = d % b;
		//		i++;
		//	}

		//	return rest;
		//}

		//private static short[] Divide(short[] a, int b)
		//{
		//	short[] result = new short[a.Length];
		//	int rest = 0, i = 0;
		//	while (i < a.Length)
		//	{
		//		int d = 10 * rest + a[i];
		//		while (d < b && i < a.Length - 1)
		//		{
		//			d = 10 * d + a[++i];
		//		}

		//		result[i] = (short)(d / b);
		//		rest = d % b;
		//		i++;
		//	}

		//	return result;
		//}
	}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');
            int n, m, a, b;
            n = int.Parse(str[0]);
            m = int.Parse(str[1]);
            a = int.Parse(str[2]);
            b = int.Parse(str[3]);

            int total = 0;
            if (b / m <= a) {
                total = (int)Math.Floor((double)(n/m)) * b;
                total += (n % m) * a;
            }
            else { total = n * a; }
            Console.WriteLine(total);
            //Main(new string[0]) ;
        }
    }
}

using System;
using System.Collections;
using System.Linq;

namespace mainnm
{
    class main
    {
        static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        struct Notebook {
            public int price;
            public int quality;
        }

        static void Main()
        {
            int[] ts = Console.ReadLine().Split(' ').Select(num => Int32.Parse(num)).ToArray();

            int n = ts[0];
            int m = ts[1];
            int a = ts[2];
            int b = ts[3];

            if (b/m > a) {
                Console.WriteLine(n * a);
            } else {
                int ost = n % m;
                int sum = (n / m) * b;

                if (ost * a > b) {
                    sum += b;
                } else  {
                    sum += ost * a;
                }

                Console.WriteLine(sum);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);
            long a = long.Parse(s[2]);
            long b = long.Parse(s[3]);
            Console.WriteLine(((n / m) * b) + ((n % m) * a));
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            int n, m, a, b;
            string[] strin1 = str1.Split(' ');
            n = int.Parse(strin1[0]);
            m = int.Parse(strin1[1]);
            a = int.Parse(strin1[2]);
            b = int.Parse(strin1[3]);
            int sumbil = n * a;
            if ((m > n) && (b <= sumbil))
            {
                Console.WriteLine(b);
            }
            if (n / m == 1)
            {  if ((m < n) && (b + (n - m) * a <= sumbil))
            { Console.WriteLine(b + (n - m) * a); }
            else { Console.WriteLine(sumbil); }
            }
            if (n / m > 1) {
                {
                    if ((m < n) && (b*(n/m) + (n - m*(n/m)) * a <= sumbil))
                    { Console.WriteLine(b * (n / m) + (n - m * (n / m)) * a); }
                    else { Console.WriteLine(sumbil); }
                }

            }

           Console.ReadLine();

        }

    }
}

using System;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main()
        {
            short[] input = Console.ReadLine().Split(' ').Select(num => Convert.ToInt16(num)).ToArray();
            short cost = 0;

            if (input[3] < input[1] * input[2])
            {
                cost += (short)((input[0] / input[1])*input[3]);
                if(input[0]%input[1]!=0)
                {
                    if (input[2] > input[3])
                        cost += input[3];
                    else
                        cost += input[2];
                }
            }
            else
            {
                cost = (short)(input[0] * input[2]);
            }
            Console.WriteLine(cost);
        }
    }
}

using System;

namespace _466A
{
	class Program
	{
		static void Main ( string [ ] args )
		{
			short n, m, a, b;
			string[] nums = (Console.ReadLine()).Split(' ');
			n = short.Parse(nums[0]);
			m = short.Parse(nums[1]);
			a = short.Parse(nums[2]);
			b = short.Parse(nums[3]);
			short min = (short)( (b * (n / m)) + (a * (n % m)) );
			if (n%m != 0 && b*(n/m + 1) < min)
				min = (short)( b*(n/m + 1) );
			if (n*a < min)
				min = (short) (n*a);
			Console.Write(min);
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {
            var init = Console.ReadLine().Split(' ');

            var n = int.Parse(init[0]);
            var m = int.Parse(init[1]);
            var a = int.Parse(init[2]);
            var b = int.Parse(init[3]);

            var cost = 0;

            cost = Math.Min(n * a, (n / m) * b + (n % (n / m)) * a);
            Console.WriteLine(cost);
            Console.ReadLine();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codefather_is_riseing_ha_ha_ha
{
    class Program
    {
        static int m1(int n, int a)
        {
            int result = n * a; return result;
        }
        static int m2(int n, int m, int b)
        {
            int result = 0;
            while (true)
            {
                result += b;
                n -= m;
                if (n <= 0) break;
            }
            return result;
        }
        static void Main(string[] args)
        {
            string str = Console.ReadLine(); string[] arr = str.Split(' ');
            int n = int.Parse(arr[0]), m = int.Parse(arr[1]);
            int a = int.Parse(arr[2]), b = int.Parse(arr[3]);
            if (n == 1) { Console.Write(Math.Min(a, b)); }
            else
            {
                int o = m1(n, a);
                int oo = m2(n, m, b);
                int total_o = Math.Max(o, oo) - Math.Min(o, oo);
                int min_o = Math.Min(o, oo);
                //--------------------------------------
                Console.Write(min_o);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double s = 0,m=0,n=0,u=0;
            string[] arr = Console.ReadLine().Split();
            double a = double.Parse(arr[0]);
            double b = double.Parse(arr[1]);
            double c = double.Parse(arr[2]);
            double d = double.Parse(arr[3]);
            m = d / b;
            if (c<=m)
            {
                Console.WriteLine(a*c);
            }
            else
            {
                for (int i = 0; i < a; i++)
                {
                    if (a % m == 0)
                    {
                        Console.WriteLine(m * a);
                        break;
                    }
                    else if (a-i%m==0)
                    {
                        s = a - i;
                        Console.WriteLine(s*b+c);
                        break;

                    }
                }

            }

        }
    }
}