#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] == s[i + n / 2]) {
            ans++;
        }
    }
    if (ans == n / 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<ll>>;

// dijkstra
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
// dijkstra end

class UnionFind
{
public:
  ll par[100005];
  ll depth[100005];
  ll nGroup[100005];

  UnionFind(ll n) {
    init(n);
  }

  void init(ll n) {
    for(ll i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }

  ll root(ll x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }

  bool same(ll x, ll y) {
    return root(x) == root(y);
  }

  void unite(ll x, ll y) {
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
// unionfind end

// nCr
const ll MAX = 500010;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// nCr end

// tree DP
vector<ll> depth;
vector<ll> g(10010,0);
ll c[10010];
void dfs(const Graph &G, ll v, ll p, ll &d) {
         g[v] = c[d-1];
    for (auto nv : G[v]) {
        if (nv == p) continue;
        d--;
        dfs(G, nv, v, d);
    }
}
// tree DP end
int main() {
  ll n; cin>>n;
  string s; cin>>s;
  if(n%2!=0){
    cout << "No" << endl;
    return 0;}
  string t = s.substr(1,n/2);
  string u = s.substr(n/2+1,n);
  if(t==u)cout << "Yes" << endl;
  else cout << "No" << endl;
}


#include<stdio.h>

int main ()
{
    int N,n,f=0,i;
    char s[1000] ;

    scanf("%d\n",&N) ;
    scanf("%s",&s) ;

    if(N%2!=0){
        printf("No\n") ;
    }
    else{
        n=N/2 ;

        for( i=0;i<n;i++){
            if(s[i]==s[i+n]){
               f=0;
            }
            else{
                f=1 ;
                break ;
            }
        }
        if(f==0){
            printf("Yes\n") ;
        }
        else{
            printf("No\n") ;
        }
    }

    return 0 ;
}


#include <stdio.h>
int main()
{
	int n,p=0;
  	char s[105];
  	scanf("%d %s",&n,s);
  	if(n%2==0)
    {
     	for(int i=0;i<(n/2);i++)
        {
          if(s[i] != s[(n/2)+i])
          {
           	p=1;
            break;
          }
        }
      	if(p==0){printf("Yes\n");}
        else if(p==1){printf("No\n");}
    }
    else
    {
     	printf("No\n");
    }
     return 0;
}


char buf[1000];
i,len;

main(){
	gets(buf);
	gets(buf);
	if((len=strlen(buf))%2) return puts("No") && 0;

	for(i=0;i<len/2;i++) if(buf[i]!=buf[i+len/2]) return puts("No") && 0;
	puts("Yes");
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n,t,c=0,r,i;
    char a[100];
    scanf("%d",&n);
    scanf("%s",a);
    if(n%2!=0)
    {
        printf("No");
    }
    else
    {
        r=n/2;
        for(i=0,t=r; i<r,t<n; i++,t++)
        {

            if(a[i]==a[t])
            {

                c++;
            }
        }
        if(c==r)
        {
            printf("yes");
        }
        else
            printf("No");
    }
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n,t,c=0,r,i;
    char a[100];
    scanf("%d",&n);
    scanf("%s",a);
    if(n%2!=0)
    {
        printf("No");
    }
    else
    {
        r=n/2;
        for(i=0,t=r; i<r,t<n; i++,t++)
        {

            if(a[i]==a[t])
            {

                c++;
            }
        }
        if(c==r)
        {
            printf("yes");
        }
        else
            printf("no");
    }
}


#include<stdio.h>
#include<math.h>
#include<string.h>

int main()
{
    char s[101],t[101];
    int l,i,j,k,g;
    scanf("%d",&l);
    scanf("%s",s);

    if(l%2==0)
    {
        for(i=0;i<l/2;i++)
        {
            t[i]=s[i];

        }
        for(j=0,i=l/2;i<l,j<l/2;i++,j++)
        {
            t[i]=t[j];
        }
        t[l]='\0';

        g=strcmp(s,t);
        if(g==0)
            printf("YES\n");
        else
            printf("NO\n ");
    }
    else
        printf("NO\n");

}


"use strict";

const main = arg => {
  const n = parseInt(arg.split("\n")[0], 10)
  if (n % 2 !== 0) {
  	console.log("No")
    return
  }
  const s = arg.split("\n")[1]
  if (s.slice(0, n/2) == s.slice(n/2)) {
  	console.log("Yes")
  } else {
  	console.log("No")
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


"use strict"
function Main(input) {
  input = input.trim().split('\n');
  const N = Number(input[0]);
  const S = input[1];

  if(N%2 !== 0){
    console.log('No');
    return;
  }

  const pre = S.slice(0, N/2);
  const suf = S.slice(N/2, N);
  if(pre !== suf){
    console.log('No');
    return;
  }

  console.log('Yes');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function Main(input) {
    var args = input.trim().split('\n');
    var half =  args[1].substr(0,args[1].length / 2);
    var res;
    if(half + half === args[1]) {
      res = 'Yes';
    } else {
      res = 'No';
    }
    console.log(res);
 }

/* var input = `9
abcdabcde`;
Main(input);
 */
 Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict';
function main(input) {
  const arr = input.trim().split('\n');
  const a = arr[1];
  const length = a.length;
  let isDouble = true;

  if (a.length % 2 !== 0) {
    return isDouble = false;
  }

  for (let i = 0; i < (length / 2); i ++) {
    if (a[i] !== a[length / 2]) {
      return isDouble = false;
    }
  }

  console.log(isDouble ? 'Yes' : 'No');
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
    const args = input.split('\n');
    const N = parseInt(args[0], 10),
          S = args[1];
    let str = S.substr(0, N / 2);
    if (str + str == S) return "Yes";
    return "No";
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
    input = input.split('/n')
  var i = input[0]
  var j = input[1]
    if(i % 2 === 1) {
      console.log('No')
    } else {
      var result = true
    	var l = 0
      var r = i / 2
        while(r < i) {
        	if(j[l] !== j[r]) {
            	console.log("No")
              	result = false
              	break
            }
          l++
          r++
        }
        if(result) {
          console.log("Yes")
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


package main

import (
  "fmt"
)

func main() {
  res := "Yes"
  var n int
  var s string
  fmt.Scan(&n, &s)
  if n & 1 == 1 {
    res = "No"
  } else {
    t := s[:n/2]
    if t + t != s {
      res = "No"
    }
  }
  fmt.Println(res)

}


package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	N := sc.nextInt()
	S := sc.next()
	if N%2 != 0 {
		no()
		return
	}
	if S[0:len(S)/2] == S[len(S)/2:len(S)] {
		yes()
	} else {
		no()
	}
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n := nextInt()
	s := nextString()

	ans := true
	if n%2 != 0 {
		ans = false
	} else {
		l := len(s)
		s1 := s[0 : l/2]
		s2 := s[l/2 : l]
		if !reflect.DeepEqual(s1, s2) {
			ans = false
		}
	}
	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()

	S := scanner.Text()

	if N%2 != 0 {
		fmt.Println("No")
		os.Exit(0)
	}
	if S[0:N/2-1] != S[N/2:N-1] {
		fmt.Println("No")
		os.Exit(0)
	}

	fmt.Println("Yes")
}


package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	if N%2 != 0 {
		fmt.Println("No")
		os.Exit(0)
	}

	scanner.Scan()

	S := scanner.Text()

	if S[0:N/2-1] != S[N/2:N-1] {
		fmt.Println("No")
		os.Exit(0)
	}

	fmt.Println("Yes")
}


package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	S := getString()

	if N == 1 {
		fmt.Println("No")
		return
	}

	result := "Yes"
	for i := 0; i < N/2; i++ {
		if S[i] != S[N/2 + i] {
			result = "No"
			break
		}
	}

	fmt.Println(result)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}


n = gets.to_i
st = gets.chomp.split("")

half = n / 2
i = 0
i2= half

if st.size % 2 != 0
  puts "No"
  exit
end

if st.size <= 1
  puts "No"
  exit
end

half.times do
  if st [i] != st[i2]
    puts "No"
    exit
  end
  i += 1
  i2 += 1
end

puts "Yes"


# n:文字列の長さ
n = gets.to_i
# s:文字列
s = gets.chomp

if n.odd?
  puts "No"
else
  if s[0, n / 2] == s[n / 2, n / 2]
    puts "Yes"
  else
    puts "No"
  end
end


N=gets.to_i
S=gets.chomp.to_s

t=S.slice(0,S.length/2.floor)

if S==t+t
    puts "Yes"
else
    puts "No"
end


n=gets.to_i
s=gets.chomp
if n%2==1
  ans=1
else
  n/2.times do|i|
    if s[i]!=s[i+n/2]
      ans=1
    end
  end
end
puts ans==1? :No : :Yes


n = gets.to_i
m = n / 2
st = gets.chomp
puts (n % 2 == 0 and st.slice(0, m - 1) == st.slice(m) ? 'Yes' : 'No')


n = gets.to_i
m = n / 2
st = gets.chomp
puts (n % 2 == 0 and st.slice(0, m) == st.slice(m, m) ? 'Yes' : 'No')


use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let n: usize = match buf.trim().to_string().parse() {
		Ok(m) => m,
		_ => panic!(""),
	};
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s = String::from(buf.trim());
	if n%2 == 0 {
		let s1 = &s[..n/2];
		let s2 = &s[n/2..];
		if s1 == s2 {
			println!("Yes");
		}else{
			println!("No");
		}
	}else{
		println!("No");
	}
}


use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let s: String = read().unwrap();

    if n == 1 {
        println!("No");
    } else {
        if &s[0..n / 2] == &s[n / 2..] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        n: usize,
        s: chars,
    }

    let mut flag: bool = true;
    if n % 2 != 0{
        flag = false;
    } else {
        for i in 0..n/2{
            if s[i] != s[i+n/2]{
                flag = false;
                break;
            }
        }
    }

    if flag==true{
        println!("Yes");
    } else {
        println!("No");
    }

}


fn main() {
    let n: usize = read_line_as_value();
    let s: String = read_line_as_value();
    if n % 2 != 0 {
        println!("No");
    } else {
        let sub_len = n / 2;
        if s.get(0..sub_len) == s.get(sub_len..n) {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


use text_io::*;
use std::process::exit;
use im_rc::*;
use std::cmp::*;

fn main(){
    let mut n:usize = read!();
    let mut a:String = read!();
    let mut v:Vec<char> = a.chars().collect();
    for i in 0..v.len()/2 {
        if v[i]!=v[i+v.len()/2] {
            println!("No");
            exit(0);
        }
    }
    println!("Yes");
}


/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        s: String
    }
    let (t1,t2) = s.split_at(n/2);
    println!("{} {}", t1, t2);
    if t1 == t2 {
        println!("Yes");
    } else {
        println!("No");
    }
}
/* vim:set foldmethod=marker: */


let n=Int(readLine()!)!
let s=readLine()!
let S=Array(s)
var k=0
if n%2==1{
  print("No")
}else{
  for i in 0...n/2-1{
    if S[i] != S[i+n/2]{
      k=1
    }
  }
  if k==1{
    print("No")
  }else{
    print("Yes")
  }
}


let n=Int(readLine()!)!
let s=Array(readLine()!.characters)

var ret = "Yes"
if( n % 2 == 1 ) {
  ret = "No"
} else {
  for(var i=0;i<n/2;i++) {
	if(s[i] != s[i+n/2]) {
		ret = "No"
	}
  }
}

print(ret)


let N = Int(readLine()!)!
let S = readLine()!.characters.map{$0}
print(S[0..<N/2]==S[N/2..<N] ? "Yes":"No")


let n=Int(readLine()!)!
let s=readLine()!
let S=Array(s)
var k=1
if n%2==1{
  print("No")
}else{
  for i in 0...n/2-1{
    if S[i] != S[i+n/2]{
      k=1
    }
  }
  if k==1{
    print("No")
  }else{
    print("Yes")
  }
}


let N = Int(readLine()!)!
let S = readLine()!.characters
print(String(S[0..<N/2])==String(S[N/2..<N]) ? "Yes":"No")


let N = Int(readLine()!)!
let S = readLine()!.characters
print(S[0..<N/2]==S[N/2..<N] ? "Yes":"No")


{
  const main = (input: string) => {
    const r = reader(input)
    const n = r.n()
    const s = r.s()

    const a = s.substring(0, n / 2)
    const b = s.substring(n / 2)

    console.log(a === b ? 'Yes' : 'No')
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}


export class Main {
  main(input: string): string {
    const tmp: string[] = input.split("\n");
    const num = parseInt(tmp[0]);
    const t = tmp[1];
    if (num % 2 != 0) {
      return 'No';
    }
    if (t.substring(0, num / 2) === t.substring(num / 2)) {
      return 'Yes';
    } else {
      return 'No';
    }
  }
}

console.log(new Main().main(require("fs").readFileSync("/dev/stdin", "utf8")));


import * as fs from 'fs';

//in
// 6
// abcabc
//out
// Yes
const main = (inp: string) => {

    const n: number = parseInt(inp.split('\n')[0]);
    const s: string = inp.split('\n')[1];

    if (n % 2 === 1) {
        console.log('No');
        return;
    }

    if (s.substr(0, n / 2) === s.substr(n / 2)) {
        console.log('Yes');
    } else {
        console.log('No');
    }
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());


import * as fs from "fs"

const input = fs.readFileSync('/dev/stdin', 'utf-8').split('\n')
const s = input[0]
const n = input[1]
const t = s.substr(0,parseInt(n)/2)

if (s === `${t}${t}`) {
    console.log("Yes")
} else {
    console.log("No")
}


const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let a=t.s()
  let ans='Yes'
  if(a.length%2==0){
    for(let i=0;i<a.length;i++){
      if(a[i] != a[a.length/2+i]){ans='No';break;}
    }
  }else{
    ans='No'
  }
  t.o(ans)
}
main()


const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):string|string[]=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let a=t.s()
  let ans='Yes'
  if(a.length%2==0){
    for(let i=0;i<a.length;i++){
      if(a[i] != a[a.length/2+i]){ans='No';return;}
    }
  }else{
    ans='No'
  }
  t.o(ans)
}
main()


n = int(input())
k = int(input())
x = int(input())
y = int(input())
print(x * min(k, n) + y * max(n - k, 0))


# coding: utf-8
n = int(input())
k = int(input())
x = int(input())
y = int(input())
if n > k:
    print(k * x + (n - k) * y)
else:
    print(n * x)


a = [int(input()) for _ in range(4)]
if a[0] <= a[1]:
  print(a[0]*a[2])
else:
  print(a[1]*a[2]+a[3]*(a[0]-a[1]))


N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if N<=K:
  print(X*K)
else:
  print(K * X + (N - K) * Y)


N = int(input())
K = int(input())
X = int(input())
Y = int(input())
price = 0
for i in range(K):
  price += X
if N <= K:
  print(price)
else:
  for i in range(N-K):
    price += Y
  print(price)


N = int(input())
K = int(input())
X = int(input())
Y = int(input())
price = 0
for i in range(K):
  price += X
for i in range(N-K):
  price += Y
print(price)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input =new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(input.readLine());
        int K = Integer.parseInt(input.readLine());
        int X = Integer.parseInt(input.readLine());
        int Y = Integer.parseInt(input.readLine());

        if (N>K) {
            System.out.println(X*K + Y*(N-K));
        } else {
            System.out.println(X*N);
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
    execute();
    }

    private static void execute() throws IOException {
        BufferedReader br =
                new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int k = Integer.parseInt(br.readLine());
        int x = Integer.parseInt(br.readLine());
        int y = Integer.parseInt(br.readLine());
        System.out.println(calcHotelFee(n, k, x, y));
    }

    public static int calcHotelFee(int stayNum, int feeChangeDays, int feeX, int feeY) {
        if (stayNum <= feeChangeDays) {
            return stayNum * feeX;
        }
        return feeChangeDays * feeX + (stayNum - feeChangeDays) * feeY;
    }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static InputStream is;
    static PrintWriter out;
    static String INPUT = "";

    static void solve()
    {
        int N = ni();
        int K = ni();
        int X = ni();
        int Y = ni();

        if (N >= K) {
            out.println(K * X + (N - K) * Y);
        } else {
            out.println(N * X);
        }

    }

    public static void main(String[] args) throws Exception
    {
        long S = System.currentTimeMillis();
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        solve();
        out.flush();
        long G = System.currentTimeMillis();
        tr(G-S+"ms");
    }

    private static boolean eof()
    {
        if(lenbuf == -1)return true;
        int lptr = ptrbuf;
        while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;

        try {
            is.mark(1000);
            while(true){
                int b = is.read();
                if(b == -1){
                    is.reset();
                    return true;
                }else if(!isSpaceChar(b)){
                    is.reset();
                    return false;
                }
            }
        } catch (IOException e) {
            return true;
        }
    }

    private static byte[] inbuf = new byte[1024];
    static int lenbuf = 0, ptrbuf = 0;

    private static int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }

    private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private static double nd() { return Double.parseDouble(ns()); }
    private static char nc() { return (char)skip(); }

    private static String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private static char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private static char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private static int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private static int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.function.Predicate;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int N_haku = scan.nextInt();
		int K_first = scan.nextInt();
		int X_yen = scan.nextInt();
		int Y_yen = scan.nextInt();

		int total = K_first * X_yen + (N_haku - K_first) * Y_yen;

		System.out.println(total);

	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

class AC044A {}

class Main {
    public static void main(String[] args) throws IOException {
        int n = ri(), k = ri(), x = ri(), y = ri();
        prln(n * x + max(0, n - k) * y);
        close();
    }

    static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
    static StringTokenizer input;

    // references
    // IBIG = 1e9 + 7
    // IRAND ~= 3e8
    // IMAX ~= 2e10
    // LMAX ~= 9e18
    // constants
    static final int IBIG = 1000000007;
    static final int IRAND = 327859546;
    static final int IMAX = 2147483647;
    static final int IMIN = -2147483648;
    static final long LMAX = 9223372036854775807L;
    static final long LMIN = -9223372036854775808L;
    // util
    static int minof(int a, int b, int c) {return min(a, min(b, c));}
    static int minof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
    static int minstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
    static long minof(long a, long b, long c) {return min(a, min(b, c));}
    static long minof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}
    static long minstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}
    static int maxof(int a, int b, int c) {return max(a, max(b, c));}
    static int maxof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
    static int maxstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
    static long maxof(long a, long b, long c) {return max(a, max(b, c));}
    static long maxof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}
    static long maxstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}
    static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static int floori(double d) {return (int)d;}
    static int ceili(double d) {return (int)ceil(d);}
    static long floorl(double d) {return (long)d;}
    static long ceill(double d) {return (long)ceil(d);}
    // input
    static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
    static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
    static long rl() throws IOException {return Long.parseLong(__in.readLine());}
    static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
    static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
    static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
    static String rline() throws IOException {return __in.readLine();}
    static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
    static int ni() {return Integer.parseInt(input.nextToken());}
    static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
    static long nl() {return Long.parseLong(input.nextToken());}
    // output
    static void pr(int i) {__out.print(i);}
    static void prln(int i) {__out.println(i);}
    static void pr(long l) {__out.print(l);}
    static void prln(long l) {__out.println(l);}
    static void pr(double d) {__out.print(d);}
    static void prln(double d) {__out.println(d);}
    static void pr(char c) {__out.print(c);}
    static void prln(char c) {__out.println(c);}
    static void pr(char[] s) {__out.print(new String(s));}
    static void prln(char[] s) {__out.println(new String(s));}
    static void pr(String s) {__out.print(s);}
    static void prln(String s) {__out.println(s);}
    static void pr(Object o) {__out.print(o);}
    static void prln(Object o) {__out.println(o);}
    static void prln() {__out.println();}
    static void pryes() {__out.println("yes");}
    static void pry() {__out.println("Yes");}
    static void prY() {__out.println("YES");}
    static void prno() {__out.println("no");}
    static void prn() {__out.println("No");}
    static void prN() {__out.println("NO");}
    static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
    static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
    static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
    static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); __out.println(iter.next());}
    static void flush() {__out.flush();}
    static void close() {__out.close();}}


#include <stdio.h>

int main(){
    int n,k,x,y;
    scanf("%d%d%d%d",&n,&k,&x,&y);
    int sum=0;
    for(int i=1;i<=n;i++){
        if(i<=k){
            sum+=x;
        }else{
            sum+=y;
        }
    }
    printf("%d\n",sum);
}


#include <stdio.h>
#include <limits.h>
 int main() { int t,x,y,z,p;
    scanf("%d%d%d%d",&x,&y,&z,&p);

    (x>y)? t=y*z+(x-y)*p:
    t=x*z;
    printf("%d",t);

 return 0; }


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int p = 0;
  if (n <= k) {
    p += x * n;
    cout << p << '\n';
  } else {
    p += k * x;
    p += (n - k) * y;
    cout << p << '\n';
  }
  return 0;
}


#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int,int>
#define F first
#define S second

using namespace std;

int main(){
  int n,k,x,y,ans=0;
  cin >> n >> k >> x >> y;
  Srep(k){
    ans += x;
    n--;
    if(n == 0){
      cout << ans << endl;
      return 0;
    }
  }
  while(n > 0) ans += y;
  cout << ans << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
#include <climits>

using namespace std;

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    if (n >= k) {
        cout << (k * x) + ((n - k) * y);

    }
    else {
        cout << (k * x);
    }

}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
#include <climits>

using namespace std;

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    cout << (k * x) + ((n - k) * y);
}


#include <stdio.h>
#include <math.h>

int main()
{
    int n,k,x,y,e,f,g;

    scanf("%d",&n);
    scanf("%d",&k);
    scanf("%d",&x);
    scanf("%d",&y);
    if(k>n)
    {
        printf("%d",x*n);
    }else{

    e=k*x;
    f=n-k;
    g=f*y;

    printf("%d",g+e);
    }

}


#include<stdio.h>

int main(){
    int n,k,x,y;
    scanf("%d%d%d%d",&n,&k,&x,&y);

    if(n<=k){
        printf("%d\n",n*x);
    }
    else{
        printf("%d\n",k*x+(n-k)*y);
    }
    return 0;
}


#include <stdio.h>
int main() {
    int n, k, x, y, ans;
    scanf("%d %d %d %d", &n, &k, &x, &y);
    if (n > k) {
        ans = k * x + (n - k) * y;
    } else
        ans = n * x;
    printf("%d\n", ans);
    return 0;
}


#include <stdio.h>

int main(void){
	int N, K, X, Y;
	int pay;
	scanf("%d %d %d %d", &N, &K, &X, &Y);
	if (K < N) {
		pay = K * X + (N - K) * Y;
	}
	else {
		pay = N * K;
	}
	printf("%d", pay);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,k,x,y,c=0;
  cin >> n >> k >> x >> y;
  c = k * x + (n - k) * y;
  cout << c;
}


#include<stdio.h>

int main(){
    int n,k,x,y;
    scanf("%d%d%d%d",&n,&k,&x,&y);

    int sum=0;
    for(int i=0;i<n;i++){
        sum+=x;
    }
    if(n>k){
        for(int i=n;i<k;i++){
            sum+=y;
        }
    }
    printf("%d\n",sum);
    return 0;
}


"use strict";

function main(input){
  const nkxy = input.trim().split('\n').map(_=>parseInt(_, 10));
  const n = nkxy[0];
  const k = nkxy[1];
  const x = nkxy[2];
  const y = nkxy[3];

  if(n <= k) console.log(x*n);
  else console.log(x*k + y*(n-k));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input){
 input = input.split("\n");
 var n = parseInt(input[0],10);
 var k = parseInt(input[1],10);
 var x = parseInt(input[2],10);
 var y = parseInt(input[3],10);
 var sum = 0;

 for(var i=0; i<n; i++){
  if(i<k){
    sum += x;
  }else{
    sum += y;
  }
 }
 console.log(sum);
}

main(require("fs").readFileSync("/dev/stdin","utf8"));


'use strict';
function Main(input) {
  input = input.split("\n");
  var total = parseInt(input[0], 10);
  var first = parseInt(input[1], 10);
  var billF = parseInt(input[2], 10);
  var billA = parseInt(input[3], 10);
  if(total <= first){
     console.log(total * billF);
  }else{
    var last = total - first;
  	console.log((first * billF) + (last * billA));
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
  input = input.trim();
  const [a,b,c,d] = input.split('\n').map(Number);
  console.log(a-b>0 ? b*c+(a-b)*d : b*c);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  input = input.trim();
  const [a,b,c,d] = input.split('\n');
  console.log(a>b ? b*c+(a-b)*d : b*c);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {

  const [a,b,c,d] = input.split('\n').map(Number);
  console.log(a>b ? b*c+(a-b)*d : b*c);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	K := getInt()
	X := getInt()
	Y := getInt()

	result := 0
	for i := 1; i <= N; i++ {
		if i <= K {
			result += X
		} else {
			result += Y
		}
	}
	fmt.Println(result)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func bfs(c int, graph *Graph) {
	next := make([]int, 0)
	next = append(next, c)
	visited := make(map[int]struct{})

	for ; len(next) != 0; {
		u := next[0]
		next = next[1:]
		visited[u] = struct{}{}

		for _, v := range graph.edges[u] {
			_, flag := visited[v]
			if flag {
				continue
			}

			// なにか処理

			next = append(next, v)
		}
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntArray(n int) []int {
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = getInt()
	}
	return array
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getStringArray(n int) []string {
	array := make([]string, n)
	for i := 0; i < n; i++ {
		array[i] = getString()
	}
	return array
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func makeRange(min, max int) []int {
	a := make([]int, max-min+1)
	for i := range a {
		a[i] = min + i
	}
	return a
}

func powerset2(nums []int) [][]int {
	length := int(math.Pow(2, float64(len(nums))))
	result := make([][]int, length)

	index := 0
	result[index] = []int{}
	index++

	for _, n := range nums {
		max := index
		for i := 0; i < max; i++ {
			result[index] = copyAndAppend(result[i], n)
			index++
		}
	}

	return result
}

func copyAndAppend(nums []int, n int) []int {
	dst := make([]int, len(nums)+1)
	copy(dst, nums)
	dst[len(nums)] = n
	return dst
}

func calcGcd(x, y int) int {
	if y == 0 {
		return x
	} else if x >= y {
		return calcGcd(y, x % y)
	} else {
		return calcGcd(x, y % x)
	}
}

func getDivisor(n int) []int {
	var divisor []int
	divisor = append(divisor, 1)
	if n != 1 {
		divisor = append(divisor, n)
	}

	sqrt := int(math.Sqrt(float64(n)))
	for i := 2; i <= sqrt; i++ {
		if n % i == 0 {
			divisor = append(divisor, i)
			divisor = append(divisor, n/i)
		}
	}
	return divisor
}

type intHeap []int

func (h intHeap) Len() int {
	return len(h)
}

func (h intHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h intHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func initHeap() *intHeap {
	ih := &intHeap{}
	heap.Init(ih)
	return ih
}

func (h *intHeap) pushHeap(n int) {
	heap.Push(h, n)
}

func (h *intHeap) popHeap() int {
	return heap.Pop(h).(int)
}

func factMod(n int) int {
	value := 1
	for ; n > 1; n-- {
		value = calcMod(value * n)
	}
	return value
}

func combinationMod(n, k int) int {
	factN := factMod(n)
	factK := factMod(k)
	factNK := factMod(n - k)
	factKR := powMod(factK, mod - 2)
	factNKR := powMod(factNK, mod - 2)
	return calcMod(factN * calcMod(factKR * factNKR))
}

func primeFactors(n int) [] int {
	factors := make([]int, 0)
	i := 2
	for i * i <= n {
		r := n % i
		if r != 0 {
			i += 1
		} else if r == 0 {
			n /= i
			factors = append(factors, i)
		}
	}
	if n > 1 {
		factors = append(factors, n)
	}
	return factors
}


package main

import (
  "fmt"
)

func main() {
  var n, k, x, y int
  fmt.Scan(&n, &k, &x, &y)
  var fee int
  if n <= k {fee = x * n} else {fee = x*k + y*(n-k)}
  fmt.Println(fee)
}


package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"reflect"
	"sort"
	"strconv"
	"strings"
	// "regexp"
)

/* sort */
type pair struct {
	index  int64
	p1, p2 interface{}
}
type pairs []pair

func (slice pairs) Len() int {
	return len(slice)
}

func (slice pairs) Less(i, j int) bool {
	return slice[i].index < slice[j].index
}

func (slice pairs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

/* sort */
type Int64Slice []int64

func (slice Int64Slice) Len() int {
	return len(slice)
}

func (slice Int64Slice) Less(i, j int) bool {
	return slice[i] < slice[j]
}

func (slice Int64Slice) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}
func Int64s(a []int64)                    { sort.Sort(Int64Slice(a)) }
func Int64sSliceAreSorted(a []int64) bool { return sort.IsSorted(Int64Slice(a)) }

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
	INF            = 1e8
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	di      = []int64{-1, 0, 1, 0}
	dj      = []int64{0, -1, 0, 1}
	di8     = []int64{-1, -1, 0, 1, 1, 1, 0, -1}
	dj8     = []int64{0, -1, -1, -1, 0, 1, 1, 1}
)

func main() {
	buf := make([]byte, initialBufSize)
	scanner.Buffer(buf, maxBufSize)
	scanner.Split(bufio.ScanWords)
	N, K, X, Y := readInt(), readInt(), readInt(), readInt()
	if N >= K {
		// K+1
		fmt.Println(K*X + (N-K)*Y)
	} else {
		fmt.Println(N * X)
	}
}

/*==========================================
 *             Library
 *==========================================*/
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}
func doubleAry(h int64, w int64, init int64) (res [][]int64) {
	res = make([][]int64, h)
	for i := int64(0); i < h; i++ {
		res[i] = make([]int64, w)
		for j := int64(0); j < w; j++ {
			res[i][j] = init
		}
	}
	return
}

func aryEq(a []int64, b []int64) bool {
	return reflect.DeepEqual(a, b)
}

func clone(n []int64) (r []int64) {
	r = make([]int64, len(n))
	for i := 0; i < len(n); i++ {
		r[i] = n[i]
	}
	return
}
func write(s string) {
	writer.WriteString(s)
}

func print() {
	writer.Flush()
}

// scanner.Split(bufio.ScanWords) をコメントアウトしないと使用不可
func readLine() (s string) {
	if scanner.Scan() {
		s = scanner.Text()
	}
	return s
}

func readInt() (read int64) {
	scanner.Scan()
	read, err := strconv.ParseInt(scanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return
}

func readFloat() (read float64) {
	scanner.Scan()
	read, err := strconv.ParseFloat(scanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return
}

func readRunes() (read []rune) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, v)
	}
	return
}

func readString() (read string) {
	scanner.Scan()
	read = scanner.Text()
	return
}

func readStrings() (read []string) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, string(v))
	}
	return
}

func s2i(s string) int64 {
	var intVal, e = strconv.ParseInt(s, 10, 64)
	if e != nil {
		panic(e)
	}
	return intVal
}

func i2s(i int64) string {
	var strVal = strconv.FormatInt(i, 10)
	return strVal
}

func s2f(s string) float64 {
	var floatVal, e = strconv.ParseFloat(s, 64)
	if e != nil {
		panic(e)
	}
	return floatVal
}

func abs(i int64) int64 {
	return int64(math.Abs(float64(i)))
}

func max(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans < v {
			ans = v
		}
	}
	return ans
}
func min(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans > v {
			ans = v
		}
	}
	return ans
}

func sum(i []int64) int64 {
	sum := int64(0)
	for _, val := range i {
		sum += val
	}
	return sum
}

func split(s string) []string {
	return strings.Fields(s)
}

func strAry2intAry(strs []string) []int64 {
	var ret = make([]int64, 0, len(strs))
	for _, str := range strs {
		var intVal = s2i(str)
		ret = append(ret, intVal)
	}
	return ret
}

func intAry2strAry(nums []int64) []string {
	var ret = make([]string, 0, len(nums))
	for _, num := range nums {
		var strVal = i2s(num)
		ret = append(ret, strVal)
	}
	return ret
}

func ary2str(strs []string) string {
	return strings.Join(strs, " ")
}

func reverse(res []int64) []int64 {
	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return res
}
func reverseStr(res []string) []string {
	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return res
}

func ini(res []int, init int) {
	if len(res) == 0 {
		return
	}
	res[0] = init
	for i := 0; i < len(res); i++ {
		copy(res[i:], res[:i])
	}
}

//
// func regexpExample() {
//     // Your code here!
//     var str = "13:20"
//     r := regexp.MustCompile(`(\d+):(\d+)`)
//     fmt.Println(r.FindStringSubmatch(str))
// }

// type Country struct {
//     gold int
//     silver int
//     blonze int
// }

// // 複数ソートのサンプル
// func stableSortExample() []Country{
//     var country = []Country {
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:3, blonze:2},
//         {gold:1, silver:3, blonze:3},
//     }
//     sort.SliceStable(country, func(i, j int) bool { return country[i].blonze > country[j].blonze })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].silver > country[j].silver })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].gold > country[j].gold })
//     return country
// }


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	K := getInt()
	X := getInt()
	Y := getInt()

	result := 0
	for i := 0; i < N; i++ {
		if i <= K {
			result += X
		} else {
			result += Y
		}
	}
	fmt.Println(result)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func bfs(c int, graph *Graph) {
	next := make([]int, 0)
	next = append(next, c)
	visited := make(map[int]struct{})

	for ; len(next) != 0; {
		u := next[0]
		next = next[1:]
		visited[u] = struct{}{}

		for _, v := range graph.edges[u] {
			_, flag := visited[v]
			if flag {
				continue
			}

			// なにか処理

			next = append(next, v)
		}
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getIntArray(n int) []int {
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = getInt()
	}
	return array
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func getStringArray(n int) []string {
	array := make([]string, n)
	for i := 0; i < n; i++ {
		array[i] = getString()
	}
	return array
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return calcMod(n * powMod(n, p-1))
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func makeRange(min, max int) []int {
	a := make([]int, max-min+1)
	for i := range a {
		a[i] = min + i
	}
	return a
}

func powerset2(nums []int) [][]int {
	length := int(math.Pow(2, float64(len(nums))))
	result := make([][]int, length)

	index := 0
	result[index] = []int{}
	index++

	for _, n := range nums {
		max := index
		for i := 0; i < max; i++ {
			result[index] = copyAndAppend(result[i], n)
			index++
		}
	}

	return result
}

func copyAndAppend(nums []int, n int) []int {
	dst := make([]int, len(nums)+1)
	copy(dst, nums)
	dst[len(nums)] = n
	return dst
}

func calcGcd(x, y int) int {
	if y == 0 {
		return x
	} else if x >= y {
		return calcGcd(y, x % y)
	} else {
		return calcGcd(x, y % x)
	}
}

func getDivisor(n int) []int {
	var divisor []int
	divisor = append(divisor, 1)
	if n != 1 {
		divisor = append(divisor, n)
	}

	sqrt := int(math.Sqrt(float64(n)))
	for i := 2; i <= sqrt; i++ {
		if n % i == 0 {
			divisor = append(divisor, i)
			divisor = append(divisor, n/i)
		}
	}
	return divisor
}

type intHeap []int

func (h intHeap) Len() int {
	return len(h)
}

func (h intHeap) Less(i, j int) bool {
	return h[i] > h[j]
}

func (h intHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
}

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func initHeap() *intHeap {
	ih := &intHeap{}
	heap.Init(ih)
	return ih
}

func (h *intHeap) pushHeap(n int) {
	heap.Push(h, n)
}

func (h *intHeap) popHeap() int {
	return heap.Pop(h).(int)
}

func factMod(n int) int {
	value := 1
	for ; n > 1; n-- {
		value = calcMod(value * n)
	}
	return value
}

func combinationMod(n, k int) int {
	factN := factMod(n)
	factK := factMod(k)
	factNK := factMod(n - k)
	factKR := powMod(factK, mod - 2)
	factNKR := powMod(factNK, mod - 2)
	return calcMod(factN * calcMod(factKR * factNKR))
}

func primeFactors(n int) [] int {
	factors := make([]int, 0)
	i := 2
	for i * i <= n {
		r := n % i
		if r != 0 {
			i += 1
		} else if r == 0 {
			n /= i
			factors = append(factors, i)
		}
	}
	if n > 1 {
		factors = append(factors, n)
	}
	return factors
}


package main

import (
	"fmt"
)

func main() {
	var n, k, x, y float64
	fmt.Scan(&n, &k, &x, &y)
	if n > k {
		fmt.Println(x*k + y*(n-k))
	} else {
		fmt.Println(x * n)
	}
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var n, k, x, y float64
	fmt.Scan(&n, &k, &x, &y)
	fmt.Println(math.Min(n, k)*x + math.Max(0, n-k)*y)
}


a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i

if a > b
  p a * c - (c - d) * (a - b)
else
  p a * c
end


n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
puts (n <= k) ? n * x : k * x + (n - k) * y


n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
puts x * [n, k].min + y * [n - k, 0].max


n=gets.to_i
m=gets.to_i
a=gets.to_i
b=gets.to_i
ans= m*a
ans+=(m-n)*b if n>m
p ans


n=gets.to_i
m=gets.to_i
a=gets.to_i
b=gets.to_i
p m*a+(m-n)*b


n = gets.to_i
k = gets.to_i
x = gets.to_i
y = gets.to_i
puts x * k + (n - k) * y


use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let v:Vec<i32> = procon_read();
	let k = v[0];
	let v:Vec<i32> = procon_read();
	let x = v[0];
	let v:Vec<i32> = procon_read();
	let y = v[0];
	if n <= k {
		println!("{}", n*x);
	}else{
		println!("{}", k*x + (n - k)*y);
	}
}


use std::cmp::max;
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: i64 = s.trim().parse().unwrap();
    s.clear();
    stdin().read_line(&mut s).ok();
    let k: i64 = s.trim().parse().unwrap();
    s.clear();
    stdin().read_line(&mut s).ok();
    let x: i64 = s.trim().parse().unwrap();
    s.clear();
    stdin().read_line(&mut s).ok();
    let y: i64 = s.trim().parse().unwrap();

    println!("{}", min(k, n) * x + max(0, n - k) * y);
}


#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let a = io.readn::<i64>(4);
    let n = a[0];
    let k = a[1];
    let x = a[2];
    let y = a[3];

    io.writeln(x * (min(k, n)) + y * max(0, (n - min(k, n))));
}

static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
use std::cmp;
fn main() {
    input!{
        n: i32,
        k: i32,
        x: i32,
        y: i32,
    }
    let ans = cmp::min(k,n) * x + cmp::max((n - k) * 9000,0);
    println!("{}",ans);
}


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32,
        k: i32,
        x: i32,
        y: i32,
    }
    let ans = cmp::min(k,n) * x + cmp::max((n - k) * 9000,0);
    println!("{}",ans);
}


#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;

fn main() {
    input!{
        N: isize, K: isize,
        X: isize, Y: isize,
    }

    println!("{}", K * X + (N - K) * Y);
}


func i()->Int{return Int(readLine()!)!};let N=i(),K=i();print(min(N,K)*i()+max(N-K,0)*i())


//func i()->Int{return Int(readLine()!)!};let N=i(),K=i();print(min(N,K)*i()+max(N-K,0)*i())
func i()->Int{return Int(readLine()!)!};let N=i(),K=i(),X=i();print(N>K ?K*X+(N-K)*i():N*X)


var i:Int{return Int(readLine()!)!};let N=i,K=i,X=i;print(N>K ?K*X+(N-K)*i:N*X)


//func i()->Int{return Int(readLine()!)!};let N=i(),K=i();print(min(N,K)*i()+max(N-K,0)*i())
func i()->Int{return Int(readLine()!)!};let N=i(),K=i(),X=i(),Y=i();print(N>K ?N*X:K*X+(N-K)*Y)


//func i()->Int{return Int(readLine()!)!};let N=i(),K=i();print(min(N,K)*i()+max(N-K,0)*i())
func i()->Int{return Int(readLine()!)!};let N=i(),K=i(),X=i(),Y=i();print(N>K ?N*X:K*X+(N−K)*Y)


func i()->Int{return Int(readLine()!)!};let N=i(),K=i();print(min(N,K)*i()+min(N-K,0)*i())


import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8").split(/\n/);

// A - 高橋君とホテルイージー

const N = +input[0];
const K = +input[1];
const X = +input[2];
const Y = +input[3];
let result = 0;

for (let i = 0; i < N; i++) {
    if (i + 1 <= K) {
        result += X;
    } else {
        result += Y;
    }
}

console.log(result);


const main: number = (input) => {
  const input = input.split("\n");
  const N = parseInt(input[0], 10);
  const K = parseInt(input[1], 10);
  const X = parseInt(input[2], 10);
  const Y = parseInt(input[3], 10);

  if (N>K) {
      console.log(K*X+(N-K)*Y);
  }else{
    console.log(N*X);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [n, k, x, y] = stdin.split('\n').map(Number)

console.log(n > k ? k * x + (n - k) * y : n * x)


const main: number = (input) => {
  const input = input.split("\n");
  const N = parseInt([0], 10);
  const K = parseInt([1], 10);
  const X = parseInt([2], 10);
  const Y = parseInt([3], 10);

  if (N>K) {
      console.log(K*X+(N-K)*Y);
  }else{
    console.log(N*X);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


const main: number = (input) => {
  const input = input.split("\n");
  const N = parseInt([0], 10);
  const K = parseInt([1], 10);
  const X = parseInt([2], 10);
  const Y = parseInt([3], 10);

  if (N > K) {
      console.log(K * X + (N - K) * Y);
  }else{
    console.log(N * X);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


const main: number = (input) => {
  const input = input.split('\n');
  const N = parseInt([0], 10);
  const K = parseInt([1], 10);
  const X = parseInt([2], 10);
  const Y = parseInt([3], 10);

  if (N > K) {
      console.log(K * X + (N - K) * Y);
  }else{
    console.log(N * X);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


a, b, c = map(int, input().split())
k = int(input())

print(max([a, b, c]) * (2 ** k - 1) + sum([a ,b ,c]))


abc = list(map(int, input().split()))
k = int(input())
ans = sum(abc)
ans += max(abc) * 2 ** k - max(abc)
print(ans)


l = list(map(int, input().split()))
n = int(input())

print(max(l) * 2 ** n + sum(l) - max(l))


def answer(a: int, b: int, c: int, k: int) -> int:
    nums = sorted((a, b, c))
    nums[-1] = nums[-1] * 2 * k

    return sum(nums)

def main():
    a, b, c = map(int, input().split())
    k = int(input())
    print(answer(a, b, c, k))

if __name__ == '__main__':
    main()


a = [int(x) for x in input().split()]
k = int(input())
print(sum(a) + max(a) * (2 ** (k - 1)))


a = [int(x) for x in input().split()]
k = int(input())
print(sum(a) + max(a) * (2 ** (K - 1)))


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line[] = br.readLine().split(" ");
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);
        int c = Integer.parseInt(line[2]);
        int k = Integer.parseInt(br.readLine());

        for (int i = 0; i < k; i++) {
            if (a >= b && a >= c) a = a * 2;
            else if (b >= a && b >= c) b = b * 2;
            else if (c >= a && c >= b) c = c * 2;
        }
        System.out.println(a + b + c);
    }
}


import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
	    int a = in.readInt();
	    int b = in.readInt();
	    int c = in.readInt();
	    int x = in.readInt();

	    System.out.println(a+b+c+Math.max(Math.max(a, b), c) * ((1<<x) -1));
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;

public class Main {
	private static final int MOD = (int) 1E9 + 7, BUF_SIZE = (1 << 13);
	private static final byte IN_BUF[] = new byte[BUF_SIZE], OUT_BUF[] = new byte[BUF_SIZE];

	private static InputStream sInput = System.in;
	private static int sInNextByte, sInNextIndex, sInReadByteCount;

	private static OutputStream sOutput = System.out;
	private static int sOutNextIndex;

	private static PrintStream sErr = System.err;

	private Main() throws Exception {
		if (isLocal) sInput = new FileInputStream(new File("").getAbsolutePath() + "/src/zzz_input");
		if (isLocal) sOutput = new FileOutputStream(new File("").getAbsolutePath() + "/src/zzz_output");
		readByte();
		solve();
		sInput.close();
		flushOutBuf();
	}

	public static void main(String[] args) {
		try {
			new Main();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private int readByte() throws IOException {
		if (sInNextIndex >= sInReadByteCount) {
			sInReadByteCount = sInput.read(IN_BUF, 0, BUF_SIZE);
			if (sInReadByteCount == -1) return (sInNextByte = -1);
			sInNextIndex = 0;
		}
		return (sInNextByte = IN_BUF[sInNextIndex++]);
	}

	private char nc() throws IOException {
		while (sInNextByte <= ' ') readByte();
		char res = (char) sInNextByte;
		readByte();
		return res;
	}

	private int ni() throws IOException {
		int res = 0;
		while (sInNextByte <= ' ') readByte();
		boolean minus = (sInNextByte == '-');
		if (minus) readByte();
		if (sInNextByte < '0' || sInNextByte > '9') throw new RuntimeException();
		do {res = (res << 1) + (res << 3) + sInNextByte - '0';} while (readByte() >= '0' && sInNextByte <= '9');
		return minus ? -res : res;
	}

	private long nl() throws IOException {
		long res = 0;
		while (sInNextByte <= ' ') readByte();
		boolean minus = (sInNextByte == '-');
		if (minus) readByte();
		if (sInNextByte < '0' || sInNextByte > '9') throw new RuntimeException();
		do {res = (res << 1) + (res << 3) + sInNextByte - '0';} while (readByte() >= '0' && sInNextByte <= '9');
		return minus ? -res : res;
	}

	private double nd() throws IOException {
		double pre = 0.0, suf = 0.0, div = 1.0;
		while (sInNextByte <= ' ') readByte();
		boolean minus = (sInNextByte == '-');
		if (minus) readByte();
		if (sInNextByte < '0' || sInNextByte > '9') throw new RuntimeException();
		do {pre = 10 * pre + (sInNextByte - '0');} while (readByte() >= '0' && sInNextByte <= '9');
		if (sInNextByte == '.') while (readByte() >= '0' && sInNextByte <= '9') suf += (sInNextByte - '0') / (div *= 10);
		return minus ? -(pre + suf) : (pre + suf);
	}

	private String ns() throws IOException {
		while (sInNextByte <= ' ') readByte();
		StringBuilder sb = new StringBuilder();
		while (sInNextByte > ' ') {
			sb.append((char) sInNextByte);
			readByte();
		}
		return sb.toString();
	}

	private char[] nc(int n) throws IOException {
		char a[] = new char[n];
		for (int i = 0; i < n; ++i) a[i] = nc();
		return a;
	}

	private char[][] nc(int r, int c) throws IOException {
		char a[][] = new char[r][c];
		for (int i = 0; i < r; ++i) a[i] = nc(c);
		return a;
	}

	private int[] ni(int n) throws IOException {
		int a[] = new int[n];
		for (int i = 0; i < n; ++i) a[i] = ni();
		return a;
	}

	private int[][] ni(int r, int c) throws IOException {
		int a[][] = new int[r][c];
		for (int i = 0; i < r; ++i) a[i] = ni(c);
		return a;
	}

	private long[] nl(int n) throws IOException {
		long a[] = new long[n];
		for (int i = 0; i < n; ++i) a[i] = nl();
		return a;
	}

	private long[][] nl(int r, int c) throws IOException {
		long a[][] = new long[r][c];
		for (int i = 0; i < r; ++i) a[i] = nl(c);
		return a;
	}

	private double[] nd(int n) throws IOException {
		double a[] = new double[n];
		for (int i = 0; i < n; ++i) a[i] = nd();
		return a;
	}

	private double[][] nd(int r, int c) throws IOException {
		double a[][] = new double[r][c];
		for (int i = 0; i < r; ++i) a[i] = nd(c);
		return a;
	}

	private String[] ns(int n) throws IOException {
		String a[] = new String[n];
		for (int i = 0; i < n; ++i) a[i] = ns();
		return a;
	}

	private String[][] ns(int r, int c) throws IOException {
		String a[][] = new String[r][c];
		for (int i = 0; i < r; ++i) a[i] = ns(c);
		return a;
	}

	private void flushOutBuf() {
		try {
			if (sOutNextIndex <= 0) return;
			sOutput.write(OUT_BUF, 0, sOutNextIndex);
			sOutput.flush();
			sOutNextIndex = 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private <T> void print(T ob) {
		String s = ob + "";
		for (int i = 0, N = s.length(); i < N; ++i) {
			OUT_BUF[sOutNextIndex++] = (byte) s.charAt(i);
			if (sOutNextIndex >= BUF_SIZE) flushOutBuf();
		}
	}

	private <T> void println(T ob) {
		print(ob + "\n");
	}

	private <T> void debug(T obj) {
		sErr.print(obj);
	}

	private <T> void debugln(T obj) {
		sErr.println(obj);
	}

	private static final boolean isLocal = false;

	private void solve() throws Exception {
		int a = ni(), b = ni(), c = ni(), K = ni();
		int max = Math.max(a, Math.max(b, c));
		int remain = a + b + c - max;
		println((1 << K) * max + remain);
	}
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            list.add(sc.nextInt());
        }
        int k = sc.nextInt();
        int max = Collections.max(list);
        for (int i = 0; i < k; i++) {
            max *= 2;
        }
        max += list.get(0);
        max += list.get(1);
        System.out.println(max);
    }
}


import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();

    int max = Math.max(Math.max(a, b), c);

    System.out.println(a + b + c + (max * (int) Math.pow(2, k - 1)));

  }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A[] = new int[3];
		A[0] = sc.nextInt();
		A[1] = sc.nextInt();
		A[2] = sc.nextInt();
		int K = sc.nextInt();
		Arrays.parallelSort(A);
		System.out.println(A[0]+A[1]+A[2]*Math.pow(2, K));
	}
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-18
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=tmp*10+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll tmp=1; for(;b;b>>=1){if(b&1)tmp=tmp*a%mod; a=a*a%mod;} return tmp;}
using namespace std;
int main()
{
	ll a=read(),b=read(),c=read(),k=read();
	if(a>b&&a>c)printf("%lld\n",(1<<k)*a+b+c);
	else if(b>c)printf("%lld\n",a+(1<<k)*b+c);
	else printf("%lld\n",a+b+(1<<k)*c);
	return 0;
}


#include<stdio.h>

int main(void){
  int a, b, c;
  int i, n;
  int max, sum;

  scanf("%d%d%d%d", &a, &b, &c, &n);

  sum = a + b + c;

  if(a>=b){
    if(a>=c){
      max = a;
    }else{
      max = c;
    }
  }else{
    if(b>=c){
      max = b;
    }else{
      max = c;
    }
  }

  for(i=0; i<n; i++){
    sum += max;
    max *= 2;
  }

  printf("%d\n", sum);

  return 0;
}


#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,b,c,mx,sum,k,i,mx2;
	scanf("%d %d %d",&a,&b,&c);
	scanf("%d",&k);
	mx=a;
	mx=max(mx,b);
	mx=max(mx,c);
	sum=a+b+c;
	mx2=mx;
	for(i=0;i<k;i++)	{
	mx2=mx2*2;
	}
	sum=sum-mx+mx2;
	printf("%d\n",sum);
	return 0;
 }


#include <bits/stdc++.h>

#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ii pair<int,int>
#define qu queue <int>
#define qmax priority_queue <int>
#define qmin priority_queue <int, vector<int>,greater<int>>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a, b, c, k, maxi, top=100000,result;
    cin>>a>>b>>c>>k;

    maxi = max({a,b,c});

    for(int i=0; i<k;i++){
        result = (maxi * (2*k)) + ((a+b+c) - maxi);

        if(top > result)
            top = result;
    }

    cout<<top<<endl;

    return 0;
}


#include <bits/stdc++.h>

#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ii pair<int,int>
#define qu queue <int>
#define qmax priority_queue <int>
#define qmin priority_queue <int, vector<int>,greater<int>>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a, b, c, k, maxi, top=-1,result;
    cin>>a>>b>>c>>k;

    maxi = max({a,b,c});

    for(int i=0; i<k;i++){
        result = (maxi * (2*k)) + ((a+b+c) - maxi);

        if(top < result)
            top = result;
    }

    cout<<top<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int n = max(A, max(B, C));
  if (n == A) A = 0;
  if (n == B) B = 0;
  if (n == C) C = 0;
  int ans = n;
  for (int i = 0; i < K; i++) {
    ans *= 2;
  }
  cout << ans + A + B + C << endl;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int k;
	scanf("%d", &k);
	if (b < c)Swap(&b, &c);
	if (a < b)Swap(&a, &b);
	REP(i, k)a *= 2;
	PRINTD(a+b+c);
}


#include <stdio.h>

int main(void){
  int a,b,c,k;
  int i;
  int tmp;

  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&k);

  /* Maximize A */
  if( b < c ){
    if( a < c ){
      tmp = c;
      c = a;
      a = tmp;
    }
  }
  else{ // b > c
    if( a < b ){
      tmp = b;
      b = a;
      a = tmp;
    }
  }

  //printf("A B C --(sort)--> %d %d %d\n",a,b,c);

  for( i=0; i<k; i++) a *= 2;

  printf("%d\n",a+b+c);

  return 0;
}


#include <stdio.h>

int main()
{
	int a,b,c,k,i,max,res;

	scanf("%d %d %d", &a,&b,&c);
	scanf("%d", &k);

	max = (a>b)? ((c>a)? c:a):((c>b)? c:b);
	res = a+b+c-max;

	for(i=0; i < k; i++) max *= 2;
	res += max;

	printf("%d\n", res);
	return 0;
}


#include<stdio.h>

int main(void){
    int x[4], i, index, max;
    int y=0;

    for(i=0; i<4; i++){
        scanf("%d", &x[i]);
    }
    index = 0; max = x[0];
    for(i=0; i<3; i++){
        if(max < x[i]){
            index = i;  max = x[i];
        }
        y = y + x[i];
    }
    y = y - x[index] + x[index]*2*(x[3]);
    printf("%d\n", y);
    return 0;
}


#include<stdio.h>

int main(void){
    int x[4], i, index, max;
    int y=0;

    for(i=0; i<4; i++){
        scanf("%d", &x[i]);
    }
    index = 0; max = x[0];
    for(i=0; i<3; i++){
        if(max < x[i]){
            index = i;  max = x[i];
        }
        y = y + x[i];
    }
    y = y + x[index]*(x[3]-1);
    printf("%d\n", y);
    return 0;
}


"use strict";
function main(input) {
  const args = input.split('\n');
  const vars = args[0].split(' ');
  let a = parseInt(vars[0], 10);
  let b = parseInt(vars[1], 10);
  let c = parseInt(vars[2], 10);
  const k = parseInt(args[1], 10);
  for (let i = 0; i < k; i++) {
    if (a > b && a > c) {
      a *= 2;
    } else if (b > a && b > c) {
      b *= 2;
    } else {
      c *= 2;
    }
  }
  console.log(a + b + c);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function Main(input) {

	input = input.split("\n");
	var k = Math.pow(2,Number(input[1]));

	input = input[0].split(" ");

	input.sort(function(a,b){
		if(Number(a)<Number(b))return -1;
		if(Number(a)>Number(b))return 1;
		return 0;
	});

	var a = Number(input[0]);
	var b = Number(input[1]);
	var c = Number(input[2]);

	var ret = a + b + c * k;
	console.log(ret);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


'use strict'

function Main(input) {
	const ipts = input.split('\n');
	const A = Number(ipts[0].split(' ')[0]);
	const B = Number(ipts[0].split(' ')[1]);
	const C = Number(ipts[0].split(' ')[2]);
	const K = Number(ipts[1]);
	let answer = 0;

	answer = Math.max(A, B, C) *  Math.pow(2, K) + A + B + C - Math.max(A, B, C);

	console.log(answer);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


/*
-------関数一覧--------
arr1dto2d(Array) 一次元配列を二次元配列にします
pf(N)因数分解した結果をオブジェクトで返します
gcd(a,b)最大公約数を返します
lcm(a,b)最小公倍数を返します
num(a,b)a-bを返します。ソート用です
isPrime(n)素数かどうか真偽値で返します
isNumber(n)数かどうか真偽値で返します
arrsum(arr)配列の合計値を返します
*/
var inf = Number.MAX_SAFE_INTEGER;
function Main(input){
	input = input.split("\n");
	var arr = input[0].split(" ").map(Number).sort(function(a,b){return a-b;});
	const n = input[1];
	for(var i=0;i<n;i++){
		arr[0] *= 2;
		arr.sort(function(a,b){return a-b;});
	}
	console.log(arrsum(arr));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
		arr[i]=arr[i].split("");
		}
	return arr;
}
function isPrime(n){
    if(false===Number.isInteger(n)){
        return false;
    }
    if(n<=1){
        return false;
    }
    if(2===n){
        return true;
    }
    if(0===n%2){
        return false;
    }
    var square_root = Math.floor(Math.sqrt(n));
    for(var i=3; i<=square_root; i+=2){
        if(0===n%i){
            return false;
        }
    }
    return true;
}
function isNumber(val){
	const pat = /^([1-9]\d*|0)$/;
	return pat.test(val);
}
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
		arr[i]=arr[i].split("");
		}
	return arr;
}
function factorialize(num) {
  if (num === 0) { return 1; }
  return num * factorialize(num-1);
}
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}
function rotate(array) {
  const ROW = array.length;
  const COL = array[0].length;
  const row = ROW-1;
  var a = new Array(COL);
  for (var c=0; c<COL; c++) {
    a[c] = new Array(ROW);
    for (var r=0; r<ROW; r++) {
      a[c][r] = array[row-r][c];
    }
  }
  return a;
}
function part_in(base,push,st){
	for(var i=st,p=0;p<push.length;i++,p++){
		base[i] = push[p];
	}
	return base;
}
function part_reverse(arr,s,g){
	var push = arr.slice(s-1,g);
  push.reverse();
	arr = part_in(arr,push,s-1);
	return arr;
}
function zeroPadding(num,length){
    return (num + '000000000000000000000000000000000').slice(0,length);
}
function arrsum(arr){
    var sum = 0;
    for (var i=0,len=arr.length; i<len; ++i) {
        sum += arr[i]-0;
    };
    return sum;
}
function pf(n) {
    var result = {};

    if (n === 1) {
        return {"1":1}
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i === 0) {
                n /= i;
                if (!(result[i] > 0)) {
                    result[i] = 0;
                }
                result[i]++;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}
function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
}
function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}
function num(a, b) {
  return a - b;
}
function nibu(a,searchValue){
	var index = -1;

//調べる左端を表す添字(index)
var left = 0;

//調べる右端を表す添字(index)
var right = a.length-1;

//左端と右端にデータがある間は処理を繰り返す
while(left <= right){

    //左右の真ん中を表す添字(index)
    middle =Math.floor((left +right)/2);

    //真ん中の値と探す値を比較する
    if(a[middle]==searchValue){
        //一致した場合、変数に入れて処理終了
        index = middle;
        break;
    }else if(a[middle]<searchValue){
        //探す値より小さい場合、左側にはもっと小さい値しかないので左端の値を真ん中の値の右に移動する
        left = middle +1;
    }else{
        //探す値より大きい場合、右側にはもっと大きい値しかないので右端の値を真ん中の値の左に移動する
        right = middle -1;
    }
}
if(index!=-1) return true;
else return false;
}


function main(input) {
  input=input.trim();
  const a = parseInt(input.split(" ")[0], 10);
  const b = parseInt(input.split(" ")[1], 10);
  const c = parseInt(input.split(" ")[2], 10);
  const x = parseInt(input.split("\n")[1], 10);
  console.log(Math.max.apply(null,[a,b,c])*Math.pow(2,x));

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


package main

import (
	. "fmt"
    . "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    var a, b, c, k int
    Scanf("%d %d %d", &a, &b, &c)
    Scanf("%d", &k)

    max := int(Max(float64(a), Max(float64(b), float64(c))))
    ans := a + b + c - max

    for i := 0; i < k; i++ {
        max *= 2
    }
    Println(ans + max)
}


package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)

	x := []int{a, b, c}
	sort.Ints(x)
	fmt.Println(int(math.Pow(2, float64(k)))*x[2] + x[0] + x[1])
}