You are given two integers $$$x$$$ and $$$y$$$. You can perform two types of operations:   Pay $$$a$$$ dollars and increase or decrease any of these integers by $$$1$$$. For example, if $$$x = 0$$$ and $$$y = 7$$$ there are four possible outcomes after this operation:   $$$x = 0$$$, $$$y = 6$$$;  $$$x = 0$$$, $$$y = 8$$$;  $$$x = -1$$$, $$$y = 7$$$;  $$$x = 1$$$, $$$y = 7$$$.   Pay $$$b$$$ dollars and increase or decrease both integers by $$$1$$$. For example, if $$$x = 0$$$ and $$$y = 7$$$ there are two possible outcomes after this operation:   $$$x = -1$$$, $$$y = 6$$$;  $$$x = 1$$$, $$$y = 8$$$.  Your goal is to make both given integers equal zero simultaneously, i.e. $$$x = y = 0$$$. There are no other requirements. In particular, it is possible to move from $$$x=1$$$, $$$y=0$$$ to $$$x=y=0$$$.Calculate the minimum amount of dollars you have to spend on it.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. The first line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 10^9$$$). The second line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9$$$).

For each test case print one integer — the minimum amount of dollars you have to spend.

NoteIn the first test case you can perform the following sequence of operations: first, second, first. This way you spend $$$391 + 555 + 391 = 1337$$$ dollars.In the second test case both integers are equal to zero initially, so you dont' have to spend money.

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Fscan(in, &x, &y, &a, &b, )
		min := y
		if x < y {
			min = x
		}
		result := a * (x + y - 2*min)
		if 2*a*min < b*min {
			result += 2 * a * min
		} else {
			result += b * min
		}
		fmt.Fprintln(out, result)
	}
}

package main

import "fmt"

func min(x,y int64) int64{
	if x>y{
		return y
	}
	return x
}

func max(x,y int64) int64{
	if x>y{
		return x
	}
	return y
}

func calc(x,y,a,b int64) int64{
	var temp int64 = (x+y)*a
	var temp2 int64 = (max(x,y)-min(x,y))*a + min(x,y)*b
	return min(temp,temp2)

}

func main(){
	var testCases int
	fmt.Scanln(&testCases)
	for t:=0;t< testCases;t++{
		var x,y int64
		fmt.Scanln(&x,&y)
		var a,b int64
		fmt.Scanln(&a,&b)
		fmt.Println(calc(x,y,a,b))
	}
}

package main

import (
	"fmt"
)

func main(){
	var T,ans int64
	fmt.Scanln(&T)
	//fmt.Println(T)
	var i int64
	for i=0;i<T;i++{
		var a,b,x,y int64
		fmt.Scanln(&x,&y)
		fmt.Scanln(&a,&b)
		//fmt.Scanf("%d %d %d %d",x,y,a,b)
		//fmt.Println(x,y,a,b)
		if x*y < 0{
			if x < 0	{ x = -x}
			if y < 0	{ y = -y}
			ans = (x + y) * a
		}else{
			if x < 0	{ x = -x}
			if y < 0	{ y = -y}
			var MAX,MIN int64
			if x > y{
				MAX = x
				MIN = y
			}else{
				MAX = y
				MIN = x
			}
			ans = MIN * b + (MAX-MIN) * a
			if ans > (MIN+MAX) * a{
				ans = (MIN+MAX) * a
			}
		}
		fmt.Println(ans)
	}

}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		x, y := s.NextInt64(), s.NextInt64()
		a, b := s.NextInt64(), s.NextInt64()

		if x == y {
			i, j := x*b, (x+y)*a
			if i > j {
				fmt.Println(j)
			} else {
				fmt.Println(i)
			}
		} else if x > y {
			i, j := y*b, 2*y*a
			if i > j {
				fmt.Println(j + (x-y)*a)
			} else {
				fmt.Println(i + (x-y)*a)
			}
		} else {
			i, j := x*b, 2*x*a
			if i > j {
				fmt.Println(j + (y-x)*a)
			} else {
				fmt.Println(i + (y-x)*a)
			}
		}
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contests/1342/problem/A
package main

import (
	"bufio"
	"fmt"
	"os"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	var (
		T int
		x, y, a, b int64
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Fscan(input, &x, &y)
		fmt.Fscan(input, &a, &b)

		xo := abs(x)
		yo := abs(y)
		ans := (xo + yo) * a
		if x*y > 0 {
			ans = min(ans, min(xo, yo) * b + abs(xo - yo) * a)
		} else {
			ans = min(ans, min(xo, yo) * b + abs(xo + yo) * a)
		}
		fmt.Println(ans)
	}
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

package main

import "fmt"

func calcCost(a, b, x, y uint64) uint64 {
	min := func() uint64 {
		if x < y {
			return x
		}
		return y
	}()

	diff := func() uint64 {
		if x > y {
			return x - y
		}

		return y - x
	}()

	cost := diff * a

	if b > 2 * a {
		cost += 2*a*min
	} else {
		cost += b*min
	}

	return cost
}

func main() {
	var t, a, b, x, y uint64

	fmt.Scan(&t)

	for t != 0 {
		fmt.Scan(&x, &y, &a, &b)

		fmt.Println(calcCost(a, b, x, y))

		t--
	}
}

package main

import (
    "fmt"
    "bufio"
    "os"
)

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)

    var t int
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        var x, y, a, b int
        fmt.Fscan(in, &x, &y, &a, &b)
        if x < y {
            x, y = y, x
        }
        var cost int64
        cost += int64(x - y) * int64(a)
        x = y
        if 2*a < b {
            cost += int64(2*a) * int64(x)
        } else {
            cost += int64(b) * int64(x)
        }
        fmt.Fprintln(out, cost)
    }
    out.Flush()
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var i, n, x, y, a, b, ans int64
	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		fmt.Scan(&x, &y, &a, &b)
		if a*2 <= b {
			ans = int64(math.Abs(float64(x))+math.Abs(float64(y))) * a
		} else {
			if x > 0 && y > 0 {
				tmp := int64(math.Min(float64(x), float64(y)))
				tmp2 := int64(math.Max(float64(x), float64(y))) - tmp
				ans = tmp*b + tmp2*a
			}else if x < 0 && y < 0{
				tmp := -int64(math.Max(float64(x), float64(y)))
				tmp2 := -int64(math.Min(float64(x), float64(y))) - tmp
				ans = tmp*b + tmp2*a
			}else {
				ans = int64(math.Abs(float64(x))+math.Abs(float64(y))) * a
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var x, y, a, b, ans, temp int64
		fmt.Scanf("%d %d\n", &x, &y)
		fmt.Scanf("%d %d\n", &a, &b)

		ans = a * (x + y)
		if x > y {
			temp = y*b + (x-y)*a
		} else {
			temp = x*b + (y-x)*a
		}
		if ans > temp {
			ans = temp
		}

		fmt.Println(ans)
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1342/A
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		x, y, a, b := ReadInt64_4()
		solve(x, y, a, b)
	}
}

func solve(x, y, a, b int64) {
	ans := int64(INF_BIT60)

	if x > y {
		x, y = y, x
	}

	// 大きいyの方に揃える
	tmp := int64(0)
	tmp += (y - x) * a
	tmp += Min(y*b, 2*y*a)
	ChMin(&ans, tmp)

	// 小さいxの方に揃える
	tmp = 0
	tmp += (y - x) * a
	tmp += Min(x*b, 2*x*a)
	ChMin(&ans, tmp)

	fmt.Println(tmp)
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int64) int64 {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int64, target int64) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import "fmt"

func Abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		var cost int64
		var a, b, x, y int64
		fmt.Scanf("%d %d\n", &x, &y)
		fmt.Scanf("%d %d\n", &a, &b)
		if x != 0 {
			if y == 0 {
				cost = Abs(x) * a
			}
			if y != 0 {
				if (x > 0 && y < 0) || (x < 0 && y > 0) {
					cost = (Abs(x) + Abs(y)) * a
				} else {
					if b > 2*a {
						cost = (Abs(x) + Abs(y)) * a
					}
					if b <= 2*a {
						x = Abs(x)
						y = Abs(y)
						if x < y {
							cost = Abs(x) * b + Abs(y-x) * a
						}
						if x >= y {
							cost = Abs(y) * b + Abs(x-y) * a
						}
					}
				}
			}
		}
		if x == 0 {
			if y == 0 {
				cost = 0
			}
			if y != 0 {
				cost = Abs(y) * a
			}
		}
		fmt.Println(cost)
		t--
	}
}

package main

import (
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1342A(_r io.Reader, _w io.Writer) {
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}
	var t, x, y, a, b int64
	for Fscan(_r, &t); t > 0; t-- {
		Fscan(_r, &x, &y, &a, &b)
		if x > y {
			x, y = y, x
		}
		Fprintln(_w, min(a*(x+y), a*(y-x)+b*x))
	}
}

func main() { CF1342A(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}
	solve := func(_case int) int64{
		var x,y,a,b int64
		Fscan(in, &x, &y, &a, &b)
		if x>y{
			x, y = y, x
		}
		ans1 := (x+y)*a

		ans := b*x
		y-=x
		ans+=y*a
		return min(ans,ans1)
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fprintln(out, solve(_case))
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"fmt"
)

func main() {
	var tot = 0
	_, _ = fmt.Scan(&tot)
	for i := 0; i < tot; i ++ {
		var a int64 = 0
		var b int64 = 0
		var x int64 = 0
		var y int64 = 0
		_, _ = fmt.Scan(&x, &y)
		_, _ = fmt.Scan(&a, &b)
		if x * y < 0 {
			if x < 0 {
				x = -x
			}
			if y < 0 {
				y = -y
			}
			ans1 := (x + y) * a
			fmt.Println(ans1)
		} else {
			if x < 0 {
				x = -x
			}
			if y < 0 {
				y = -y
			}
			var cnt int64 = 0
			if x < y {
				cnt = x
			} else {
				cnt = y
			}
			x -= cnt
			y -= cnt
			var fee int64 = 0
			if 2 * a > b {
				fee = b
			} else {
				fee = a * 2
			}
			ans := cnt * fee
			if x > 0 {
				ans += x * a
			} else {
				ans += y * a
			}
			fmt.Println(ans)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {

	for t := ScanInt(); t > 0; t-- {
		x, y := ScanInt(), ScanInt()
		a, b := ScanInt(), ScanInt()
		P(solv(x, y, a, b))
	}

	close(O)
	oWg.Wait()
}
func solv(x, y, a, b int) int64 {
	sum := int64(0)

	if 2*a > b && (x < 0 && y < 0 || x > 0 && y > 0) {
		if x < 0 && y < 0 {
			maxxy := abs(mx(x, y))
			x = -x
			y = -y

			sum += int64(maxxy) * int64(b)
			x -= maxxy
			y -= maxxy
			sum += (int64(x)*int64(a) + int64(y)*int64(a))
		} else {
			mnxy := mn(x, y)
			sum += (int64(mnxy) * int64(b))

			x -= mnxy
			y -= mnxy
			sum += (int64(x)*int64(a) + int64(y)*int64(a))
		}
	} else {
		return int64(abs(x)+abs(y)) * int64(a)
	}

	return sum
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func mx(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func mn(a, b int) int {
	if a < b {
		return a
	}
	return b
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }

package main

import (
    "fmt"
    "bufio"
    "os"
)

//FOR I/O : STARTS
var Reader *bufio.Reader = bufio.NewReader(os.Stdin)
var Writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func Printf (f string, a ...interface{}) { fmt.Fprintf(Writer, f, a...) }
func Scanf (f string, a ...interface{}) { fmt.Fscanf(Reader, f, a...) }
func Println (a ...interface{}) { fmt.Fprintln(Writer, a...)}
func Scanln (a ...interface{}) { fmt.Fscanln(Reader, a...)}
//I/O ENDS HERE

// Min returns the smaller of x or y.
func Min(x, y int64) int64 {
        if x > y {
                return y
        }
        return x
}

// Max returns the larger of x or y.
func Max(x, y int64) int64 {
        if x < y {
                return y
        }
        return x
}

func Abs(x int64) int64 {
    if x < 0 {
        return -x
    }
    return x
}

func main() {
    defer Writer.Flush()
    var t int = 1
    Scanln(&t)
    for t > 0 {
        var x, y, a, b, ans, temp, Y int64
        Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
        //Println(x,y,a,b)

        temp = Abs(x-y)
        Y = Min(x,y)

        ans = a*temp
        ans += Min(2*a*Y, b*Y)

        Println(ans)

        t -= 1
    }
}

package main

import (
	"fmt"
)

func main() {
	t := 0
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var ans int64
		var x, y, a, b int64
		fmt.Scan(&x, &y, &a, &b)
		var mi, ma int64
		if x <= y {
			mi, ma = x, y
		}
		if x > y {
			mi, ma = y, x
		}
		if mi != ma {
			ans += (ma - mi) * a
		}
		temp1 := mi * a * 2
		temp2 := mi * b
		if temp1 < temp2 {
			fmt.Println(temp1 + ans)
		} else {
			fmt.Println(temp2 + ans)
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
	noEx := 0
	fmt.Fscan(in, &noEx)
	for ; noEx>0; noEx-- {
		var a, b, x, y, sum, diff, rem int64
		fmt.Fscan(in, &x)
		fmt.Fscan(in, &y)
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		diff, rem = x, y-x
		if diff > y {diff, rem = y, x-y}
		if 2*a > b {
			sum += (diff * b)
			sum += (rem * a)
		} else {
			sum += ((x + y) * a)
		}
		fmt.Fprint(out, sum)
		fmt.Fprint(out, "\n")
	}
}

package main

import "fmt"

func main() {
	var t, x, y, a, b int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&x, &y, &a, &b)
		var dollars int64
		if a*2 <= b {
			dollars = int64(a) * int64(x+y)
		} else {
			dollars = int64(b) * int64(min(x, y))
			dollars += int64(a) * int64(x+y-2*min(x, y))
		}
		fmt.Println(dollars)
	}
}

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

package main

import (
	"fmt"
)

func min(x, y int64) int64 {
	// return x<y?x:y
	if x < y {
		return x
	} else {
		return y
	}
	return 0
}

func abs(x int64) int64 {
	// return x <0? -x:x
	if x < 0 {
		return -x
	} else {
		return x
	}
	return 0
}

/*
func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
	return 0
}

// buggy fails at test case 2
func solve(x, y, a, b int) int {
	if x >= 0 && y >= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else if x <= 0 && y <= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else {
		return a * (abs(x) + abs(y))
	}
	return 0
}
*/
func solve(x, y, a, b int64) int64 {
	/* fails at test 2
	if x > y {
		x, y = y, x
	}
	return min(2*a, b)*x + a*(y-x)
	*/
	// same
	return abs(x-y)*a + min(x, y)*min(2*a, b)

}

func main() {
	var (
		test, i    int64
		x, y, a, b int64
	)

	fmt.Scanf("%d\n", &test)

	for i = 0; i < test; i++ {
		fmt.Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
		fmt.Println(solve(x, y, a, b))
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		x, y := reader.NextInt64(), reader.NextInt64()
		a, b := reader.NextInt64(), reader.NextInt64()
		writer.Printf("%d\n", sol(x, y, a, b))
	}
}

func sol(x, y, a, b int64) int64 {
	if b > a*2 {
		return (x+y)*a
	}
	var diff, rem int64
	if x > y {
		diff = x - y
		rem = y
	} else {
		diff = y - x
		rem = x
	}
	return diff*a + rem*b
}

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for t := stdin.ReadInt(); t > 0; t-- {
		x := stdin.ReadInt64()
		y := stdin.ReadInt64()
		a := stdin.ReadInt64()
		b := stdin.ReadInt64()

		ans1 := a * (x + y)
		ans2 := b*Min64(x, y) + a*(Max64(x, y)-Min64(x, y))
		stdout.Println(Min64(ans1, ans2))
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

// ========================================
//      FOR int64
// ========================================

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var x, y, a, b int
		fmt.Fscan(in, &x, &y, &a, &b, )
		min := y
		if x < y {
			min = x
		}
		result := a * (x + y - 2*min)
		if 2*a*min < b*min {
			result += 2 * a * min
		} else {
			result += b * min
		}
		fmt.Fprintln(out, result)
	}
}

package main

import (
	"fmt"
)

//func calc(first,second int){
//
//	for i:=1;i<1000000000;i++{
//		if i&1==1{
//			first -= i
//			if first<0{
//				fmt.Print( "Vladik")
//				return
//			}
//		}else{
//			second -= i
//			if second<0{
//				fmt.Print("Valera")
//				return
//			}
//		}
//	}
//	return
//}
//func min(a,b int64) int64{
//	if a>=b{
//		return b
//	}
//	return a
//}

func calc(a,b,c,d int64) int64{
	var ans int64
	if a==b{
		return a*d
	}else if a>b {
		if b == 0 {
			ans += c
			ans += (a-1)*c + d
		}else{
			return (a-b)*c + b*d
		}
	}else{
		if a==0{
			ans += c
			ans += (b-1)*c + d
		}else{
			return (b-a)*c + a*d
		}
	}
	return ans
}
func main(){
	var t int
	fmt.Scanln(&t)
	for i:=0;i<t;i++{
		var a int64
		var b int64
		fmt.Scanln(&a,&b)
		var c int64
		var d int64
		fmt.Scanln(&c,&d)
		fmt.Println(calc(a,b,c,d))
	}
}
//abbbbboyoyoyoyoyacadabbbbbifgihjabbbklboyoyoyoyoyabbbbbibbbbbeyiyuyzyw
//abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw

package main

import (
	"fmt"
	"math"
)

func calc(a,b,c,d float64) float64{
	ans := 0.0
	if a>0 && b>0{
		if a == 1{
			//fmt.Print("YES1")
			ans = (b-1)*c + d
		}else if b==1{
			//fmt.Print("YES2")
			ans = (a-1)*c + d
		}else{
			//fmt.Print("YES3")
			ans = math.Min( (a-1)*c + (b-1)*c + d , math.Abs(a-b)*c+math.Min(a,b)*d)
		}
	}else{
		if a==0{
			if a==b{
				return 0
			}
			ans =  c + (b-1)*c + d
		}else{
			ans =  c + (a-1)*c + d
		}
	}
	return ans
}

func main(){
	var test_cases int
	fmt.Scanln(&test_cases)

	for i:=0;i<test_cases;i++{
		var x float64
		var y float64
		var a float64
		var b float64
		fmt.Scanln(&x,&y)
		fmt.Scanln(&a,&b)
		ans := int64(calc(x,y,a,b))
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

//func calc(first,second int){
//
//	for i:=1;i<1000000000;i++{
//		if i&1==1{
//			first -= i
//			if first<0{
//				fmt.Print( "Vladik")
//				return
//			}
//		}else{
//			second -= i
//			if second<0{
//				fmt.Print("Valera")
//				return
//			}
//		}
//	}
//	return
//}
func min(a,b int64) int64{
	if a>=b{
		return b
	}
	return a
}

func calc(a,b,c,d int64) int64{
	if a==b{
		return a*d
	}else if a>b{
		return (a-b)*c + b*d
	}
	return (b-a)*c + a*d
}
func main(){
	var t int
	fmt.Scanln(&t)
	for i:=0;i<t;i++{
		var a int64
		var b int64
		fmt.Scanln(&a,&b)
		var c int64
		var d int64
		fmt.Scanln(&c,&d)
		fmt.Println(calc(a,b,c,d))
	}
}
//abbbbboyoyoyoyoyacadabbbbbifgihjabbbklboyoyoyoyoyabbbbbibbbbbeyiyuyzyw
//abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw

package main

import (
	"fmt"
)

//func calc(first,second int){
//
//	for i:=1;i<1000000000;i++{
//		if i&1==1{
//			first -= i
//			if first<0{
//				fmt.Print( "Vladik")
//				return
//			}
//		}else{
//			second -= i
//			if second<0{
//				fmt.Print("Valera")
//				return
//			}
//		}
//	}
//	return
//}
//func min(a,b int64) int64{
//	if a>=b{
//		return b
//	}
//	return a
//}

func calc(a,b,c,d int64) int64{
	var ans int64
	if a==b{
		if d>2*c{
			return (a-1)*2*c + d
		}else {
			return a * d
		}
	}else if a>b {
		if b == 0 {
			ans += c
			b=1
		}
		return (a-1)*c + b*d + ans
	}else{
		if a==0{
			ans += c
			a=1
		}
		return (b-1)*c + a*d + ans
	}
}
func main(){
	var t int
	fmt.Scanln(&t)
	for i:=0;i<t;i++{
		var a int64
		var b int64
		fmt.Scanln(&a,&b)
		var c int64
		var d int64
		fmt.Scanln(&c,&d)
		fmt.Println(calc(a,b,c,d))
	}
}
//abbbbboyoyoyoyoyacadabbbbbifgihjabbbklboyoyoyoyoyabbbbbibbbbbeyiyuyzyw
//abbbbbocadabbbbbifgihjabbbklbobbbbbibbbbbezyw

package main

import (
	"fmt"
)

func main(){
	var T,ans int32
	fmt.Scanln(&T)
	//fmt.Println(T)
	var i int32
	for i=0;i<T;i++{
		var a,b,x,y int32
		fmt.Scanln(&x,&y)
		fmt.Scanln(&a,&b)
		//fmt.Scanf("%d %d %d %d",x,y,a,b)
		//fmt.Println(x,y,a,b)
		if x*y < 0{
			if x < 0	{ x = -x}
			if y < 0	{ y = -y}
			ans = (x + y) * a
		}else{
			if x < 0	{ x = -x}
			if y < 0	{ y = -y}
			var MAX,MIN int32
			if x > y{
				MAX = x
				MIN = y
			}else{
				MAX = y
				MIN = x
			}
			ans = MIN * b + (MAX-MIN) * a
			if ans > (MIN+MAX) * a{
				ans = (MIN+MAX) * a
			}
		}
		fmt.Println(ans)
	}

}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		x, y := s.NextInt(), s.NextInt()
		a, b := s.NextInt(), s.NextInt()

		if x == y {
			fmt.Println(x * b)
		} else if x > y {
			fmt.Println(y*b + (x-y)*a)
		} else {
			fmt.Println(x*b + (y-x)*a)
		}
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contests/1342/problem/A
package main

import (
	"bufio"
	"fmt"
	"os"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	var (
		T, x, y, a, b int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Fscan(input, &x, &y)
		fmt.Fscan(input, &a, &b)

		xo := abs(x)
		yo := abs(y)
		ans := (xo + yo) * a
		if x*y > 0 {
			ans = min(ans, min(xo, yo) * b + abs(xo - yo) * a)
		} else {
			ans = min(ans, min(xo, yo) * b + abs(xo + yo) * a)
		}
		fmt.Println(ans)
	}
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// https://codeforces.com/contest/8/problem/A
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"bytes"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	var path, a, b string
	fmt.Fscanf(input, "%s\n", &path)
	fmt.Fscanf(input, "%s\n", &a)
	fmt.Fscanf(input, "%s\n", &b)
	var buffer bytes.Buffer
	for i := len(path) - 1; i >= 0; i-- {
		buffer.WriteByte(path[i])
	}
	rpath := buffer.String()
	la := strings.Index(path, a)
	ra := strings.Index(rpath, a)
	forward := la > -1 && la + len(a) - 1 < strings.LastIndex(path, b)
	backward := ra > -1 && ra + len(a) - 1 < strings.LastIndex(rpath, b)
	if forward && backward {
		fmt.Println("both")
	} else if !forward && !backward {
		fmt.Println("fantasy")
	} else if forward {
		fmt.Println("forward")
	} else  {
		fmt.Println("backward")
	}
}

// https://codeforces.com/contests/1342/problem/A
package main

import (
	"bufio"
	"fmt"
	"os"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	var (
		T, x, y, a, b int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Fscan(input, &x, &y)
		fmt.Fscan(input, &a, &b)

		if x > y {
			x, y = y, x
		}
		xo := abs(x)
		yo := abs(y)
		ans := (xo + yo) * a
		if x*y > 0 {
			ans = min(ans, min(xo, yo) * b + abs(xo - yo) * a)
		}
		fmt.Println(ans)
	}
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import "fmt"

func calcCost(a, b, x, y uint64) uint64 {
	min := func() uint64 {
		if x < y {
			return x
		}
		return y
	}()

	diff := func() uint64 {
		if x > y {
			return x - y
		}

		return y - x
	}()

	return diff*a + b*min
}

func main() {
	var t, a, b, x, y uint64

	fmt.Scan(&t)

	for t != 0 {
		fmt.Scan(&x, &y, &a, &b)

		fmt.Println(calcCost(a, b, x, y))

		t--
	}
}

package main

import "fmt"

func calcCost(a, b, x, y uint64) uint64 {
	min := func() uint64 {
		if x < y {
			return x
		}
		return y
	}()

	diff := func() uint64 {
		if x > y {
			return x - y
		}

		return y - x
	}()

	cost := diff * a

	if b > 2*a {
		cost += 2 * a * min
	} else {
		cost += b * min
	}

	return cost
}

func main() {
	var t, a, b, x, y uint64

	fmt.Scan(&t)

	for t != 0 {
		go func() {
			fmt.Scan(&x, &y, &a, &b)

			fmt.Println(calcCost(a, b, x, y))
		}()

		t--
	}
}

package main

import "fmt"

func calcCost(a, b, x, y uint) uint {
	min := func() uint {
		if x < y {
			return x
		}
		return y
	}()

	diff := func() uint {
		if x > y {
			return x - y
		}

		return y - x
	}()

	return diff*a + b*min
}

func main() {
	var t, a, b, x, y uint

	fmt.Scan(&t)

	for t != 0 {
		fmt.Scan(&x, &y, &a, &b)

		fmt.Println(calcCost(a, b, x, y))

		t--
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, x, y, a, b, ans int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y, &a, &b)
		if a*2 <= b {
			ans = int(math.Abs(float64(x))+math.Abs(float64(y))) * a
		} else {
			if x > 0 && y > 0 {
				tmp := int(math.Min(float64(x), float64(y)))
				tmp2 := int(math.Max(float64(x), float64(y))) - tmp
				ans = tmp*b + tmp2*a
			}else if x < 0 && y < 0{
				tmp := -int(math.Max(float64(x), float64(y)))
				tmp2 := -int(math.Min(float64(x), float64(y))) - tmp
				ans = tmp*b + tmp2*a
			}else {
				ans = int(math.Abs(float64(x))+math.Abs(float64(y))) * a
			}
		}
		fmt.Println(ans)
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1342/A
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		x, y, a, b := ReadInt4()
		solve(x, y, a, b)
	}
}

func solve(x, y, a, b int) {
	ans := INF_BIT30

	if x > y {
		x, y = y, x
	}

	// 大きいyの方に揃える
	tmp := 0
	tmp += (y - x) * a
	tmp += Min(y*b, 2*y*a)
	ChMin(&ans, tmp)

	// 小さいxの方に揃える
	tmp = 0
	tmp += (y - x) * a
	tmp += Min(x*b, 2*x*a)
	ChMin(&ans, tmp)

	fmt.Println(tmp)
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import "fmt"

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for t > 0 {
		cost := 0
		var a, b, x, y int
		fmt.Scanf("%d %d\n", &x, &y)
		fmt.Scanf("%d %d\n", &a, &b)
		if x != 0 {
			if y == 0 {
				cost = Abs(x) * a
			}
			if y != 0 {
				if (x > 0 && y < 0) || (x < 0 && y > 0) {
					cost = (Abs(x) + Abs(y)) * a
				} else {
					if b > 2*a {
						cost = (Abs(x) + Abs(y)) * a
					}
					if b <= 2*a {
						x = Abs(x)
						y = Abs(y)
						if x < y {
							cost = Abs(x) * b + Abs(y-x) * a
						}
						if x >= y {
							cost = Abs(y) * b + Abs(x-y) * a
						}
					}
				}
			}
		}
		if x == 0 {
			if y == 0 {
				cost = 0
			}
			if y != 0 {
				cost = Abs(y) * a
			}
		}
		fmt.Println(cost)
		t--
	}
}

package main

import (
	"fmt"
)

func main() {
	var tot = 0
	_, _ = fmt.Scan(&tot)
	for i := 0; i < tot; i ++ {
		var a int64 = 0
		var b int64 = 0
		var x int64 = 0
		var y int64 = 0
		_, _ = fmt.Scan(&x, &y)
		_, _ = fmt.Scan(&a, &b)
		if x * y < 0 {
			if x < 0 {
				x = -x
			}
			if y < 0 {
				y = -y
			}
			ans1 := (x + y) * a
			fmt.Println(ans1)
		} else {
			if x < 0 {
				x = -x
			}
			if y < 0 {
				y = -y
			}
			var cnt int64 = 0
			if x < y {
				cnt = x
			} else {
				cnt = y
			}
			x -= cnt
			y -= cnt
			ans := cnt * b
			if x > 0 {
				ans += x * a
			} else {
				ans += y * a
			}
			fmt.Println(ans)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var tot = 0
	_, _ = fmt.Scan(&tot)
	for i := 0; i < tot; i ++ {
		var a = 0
		var b = 0
		var x = 0
		var y = 0
		_, _ = fmt.Scan(&x, &y)
		_, _ = fmt.Scan(&a, &b)
		if x * y < 0 {
			fmt.Println(int(math.Abs(float64(x)) + math.Abs(float64(y))) * a)
		} else {
			x = int(math.Abs(float64(x)))
			y = int(math.Abs(float64(y)))
			cnt := int(math.Min(float64(x), float64(y)))
			x -= cnt
			y -= cnt
			ans := cnt * b
			if x > 0 {
				ans += x * a
			} else {
				ans += y * a
			}
			fmt.Println(ans)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var tot = 0
	_, _ = fmt.Scan(&tot)
	for i := 0; i < tot; i ++ {
		var a int64 = 0
		var b int64 = 0
		var x int64 = 0
		var y int64 = 0
		_, _ = fmt.Scan(&x, &y)
		_, _ = fmt.Scan(&a, &b)
		if x * y < 0 {
			ans1 := int64(math.Abs(float64(x)) + math.Abs(float64(y))) * a
			fmt.Println(ans1)
		} else {
			x = int64(math.Abs(float64(x)))
			y = int64(math.Abs(float64(y)))
			cnt := int64(math.Min(float64(x), float64(y)))
			x -= cnt
			y -= cnt
			ans := cnt * b
			if x > 0 {
				ans += x * a
			} else {
				ans += y * a
			}
			fmt.Println(ans)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	t := 0
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var ans int64
		var x, y, a, b int64
		fmt.Scan(&x, &y, &a, &b)
		var mi, ma int64
		if x < y {
			mi, ma = x, y
		}
		if x > y {
			mi, ma = y, x
		}
		if mi != ma {
			ans += (ma - mi) * a
		}
		temp1 := mi * a * 2
		temp2 := mi * b
		if temp1 < temp2 {
			fmt.Println(temp1 + ans)
		} else {
			fmt.Println(temp2 + ans)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	t := 0
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var ans int64
		x, y, a, b := 0, 0, 0, 0
		fmt.Scan(&x, &y, &a, &b)
		mi, ma := 0, 0
		if x < y {
			mi, ma = x, y
		}
		if x > y {
			mi, ma = y, x
		}
		if mi != ma {
			ans += int64((ma - mi) * a)
		}
		temp1 := mi * a * 2
		temp2 := mi * b
		if temp1 < temp2 {
			fmt.Println(int64(temp1) + ans)
		} else {
			fmt.Println(int64(temp2) + ans)
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
	noEx := 0
	fmt.Fscan(in, &noEx)
	for ; noEx>0; noEx-- {
		var a, b, x, y int
		fmt.Fscan(in, &x)
		fmt.Fscan(in, &y)
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		diff, rem := x, y-x
		if diff > y {diff, rem = y, x-y}
		sum := 0
		if 2*a > b {
			sum += (diff * b)
			sum += (rem * a)
		} else {
			sum += ((x + y) * a)
		}
		fmt.Fprint(out, sum)
		fmt.Fprint(out, "\n")
	}
}

package main

import (
	"fmt"
)

func min(x, y int) int {
	// return x<y?x:y
	if x < y {
		return x
	} else {
		return y
	}
	return 0
}

func abs(x int) int {
	// return x <0? -x:x
	if x < 0 {
		return -x
	} else {
		return x
	}
	return 0
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
	return 0
}

func solve(x, y, a, b int) int {
	if x >= 0 && y >= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else if x <= 0 && y <= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else {
		return a * (abs(x) + abs(y))
	}
	return 0
}

func main() {
	var (
		test       int
		x, y, a, b int
	)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
		fmt.Println(solve(x, y, a, b))
	}
}

package main

import (
	"fmt"
)

func min(x, y int) int {
	// return x<y?x:y
	if x < y {
		return x
	} else {
		return y
	}
	return 0
}

func abs(x int) int {
	// return x <0? -x:x
	if x < 0 {
		return -x
	} else {
		return x
	}
	return 0
}

/*
func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
	return 0
}

// buggy fails at test case 2
func solve(x, y, a, b int) int {
	if x >= 0 && y >= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else if x <= 0 && y <= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else {
		return a * (abs(x) + abs(y))
	}
	return 0
}
*/
func solve(x, y, a, b int) int {
	/* fails at test 2
	if x > y {
		x, y = y, x
	}
	return min(2*a, b)*x + a*(y-x)
	*/
	// same
	return abs(x-y)*a + min(x, y)*min(2*a, b)

}

func main() {
	var (
		test       int
		x, y, a, b int
	)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
		fmt.Println(solve(x, y, a, b))
	}
}

package main

import (
	"fmt"
)

func min(x, y int) int {
	// return x<y?x:y
	if x < y {
		return x
	} else {
		return y
	}
	return 0
}

/*
func abs(x int) int {
	// return x <0? -x:x
	if x < 0 {
		return -x
	} else {
		return x
	}
	return 0
}

func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
	return 0
}

// buggy fails at test case 2
func solve(x, y, a, b int) int {
	if x >= 0 && y >= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else if x <= 0 && y <= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else {
		return a * (abs(x) + abs(y))
	}
	return 0
}
*/
func solve(x, y, a, b int) int {
	if x > y {
		x, y = y, x
	}
	return min(2*a, b)*x + a*(y-x)
}

func main() {
	var (
		test       int
		x, y, a, b int
	)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
		fmt.Println(solve(x, y, a, b))
	}
}

package main

import (
	"fmt"
)

func min(x, y int) int {
	// return x<y?x:y
	if x < y {
		return x
	} else {
		return y
	}
	return 0
}

func abs(x int) int {
	// return x <0? -x:x
	if x < 0 {
		return -x
	} else {
		return x
	}
	return 0
}

func solve(x, y, a, b int) int {
	if x >= 0 && y >= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(2*a*min(x, y), b*min(x, y))
	} else if x <= 0 && y <= 0 {
		x = abs(x)
		y = abs(y)
		return abs((x-y)*a + min(2*a*min(x, y), b*min(x, y)))
	} else {
		return a * (abs(x) + abs(y))
	}
	return 0
}

func main() {
	var (
		test       int
		x, y, a, b int
	)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
		fmt.Println(solve(x, y, a, b))
	}
}

package main

import (
	"fmt"
)

func min(x, y int) int {
	// return x<y?x:y
	if x < y {
		return x
	} else {
		return y
	}
	return 0
}

func abs(x int) int {
	// return x <0? -x:x
	if x < 0 {
		return -x
	} else {
		return x
	}
	return 0
}

/*
func max(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
	return 0
}

// buggy fails at test case 2
func solve(x, y, a, b int) int {
	if x >= 0 && y >= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else if x <= 0 && y <= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(min(2*a*max(x, y), b*max(x, y)), min(2*a*min(x, y), b*min(x, y)))
	} else {
		return a * (abs(x) + abs(y))
	}
	return 0
}
*/
func solve(x, y, a, b int) int {
	/* fails at test 2
	if x > y {
		x, y = y, x
	}
	return min(2*a, b)*x + a*(y-x)
	*/
	return abs(x-y)*a + min(x, y)*min(2*a, b)
}

func main() {
	var (
		test       int
		x, y, a, b int
	)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
		fmt.Println(solve(x, y, a, b))
	}
}

package main

import (
	"fmt"
)

func min(x, y int) int {
	// return x<y?x:y
	if x < y {
		return x
	} else {
		return y
	}
	return 0
}

func abs(x int) int {
	// return x <0? -x:x
	if x < 0 {
		return -x
	} else {
		return x
	}
	return 0
}

func solve(x, y, a, b int) int {
	if x >= 0 && y >= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(2*a*min(x, y), b*min(x, y))
	} else if x <= 0 && y <= 0 {
		x = abs(x)
		y = abs(y)
		return abs(x-y)*a + min(2*a*min(x, y), b*min(x, y))
	} else {
		return a * (abs(x) + abs(y))
	}
	return 0
}

func main() {
	var (
		test       int
		x, y, a, b int
	)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
		fmt.Println(solve(x, y, a, b))
	}
}

package main

import (
	"fmt"
)

func min(x, y int) int {
	// return x<y?x:y
	if x < y {
		return x
	} else {
		return y
	}
	return 0
}

func abs(x int) int {
	// return x <0? -x:x
	if x < 0 {
		return -x
	} else {
		return x
	}
	return 0
}

func solve(x, y, a, b int) int {
	if x >= 0 && y >= 0 {
		return abs(x-y)*a + min(2*a*min(x, y), b*min(x, y))
	} else if x <= 0 && y <= 0 {
		return abs((x-y)*a + min(2*a*min(x, y), b*min(x, y)))
	} else {
		return a * (abs(x) + abs(y))
	}
	return 0
}

func main() {
	var (
		test       int
		x, y, a, b int
	)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d %d\n%d %d\n", &x, &y, &a, &b)
		fmt.Println(solve(x, y, a, b))
	}
}

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for t := stdin.ReadInt(); t > 0; t-- {
		x := stdin.ReadInt()
		y := stdin.ReadInt()
		a := stdin.ReadInt()
		b := stdin.ReadInt()

		ans1 := a * (x + y)
		ans2 := b*Min(x, y) + a*(Max(x, y)-Min(x, y))
		stdout.Println(Min(ans1, ans2))
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}


Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai  ≤  bi).Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!

The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans. The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans.

Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).

NoteIn the first sample, there are already 2 cans, so the answer is "YES".

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	io := bufio.NewReader(os.Stdin)
	var n int64
	fmt.Fscan(io, &n)
	var rem int64
	cap := make([]int64, n)
	for i := int64(0); i < n; i++ {
		var input int64
		fmt.Fscan(io, &input)
		rem += input
	}
	var max1, max2 int64
	for i := int64(0); i < n; i++ {
		var input int64
		fmt.Fscan(io, &input)
		cap[i] = input
		if input > max1 {
			max2, max1 = max1, input
		} else if input > max2 {
			max2 = input
		}
	}
	if rem > max1+max2 {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
}

package main

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

var scanner *bufio.Scanner

func setup() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

func readInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}

func main() {
	setup()
	var n, sumA, b1, b2 int64
	n = readInt()
	for i := int64(0); i < n; i++ {
		sumA += readInt()
	}
	for i := int64(0); i < n; i++ {
		b := readInt()
		if b2 < b {
			b2 = b
		}
		if b1 < b2 {
			b1, b2 = b2, b1
		}
	}
	if sumA <= b1+b2 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var n, a, b, sumA, b1, b2 int64
	fmt.Fscan(in, &n)
	for i := int64(0); i < n; i++ {
		fmt.Fscan(in, &a)
		sumA += a
	}

	for i := int64(0); i < n; i++ {
		fmt.Fscan(in, &b)
		if b2 < b {
			b2 = b
		}
		if b1 < b2 {
			b1, b2 = b2, b1
		}
	}
	if sumA <= b1+b2 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}

}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt()

	var total, max1, max2 int64
	for i := 0; i < n; i++ {
		total += readBigInt()
	}
	for i := 0; i < n; i++ {
		next := readBigInt()
		if next > max1 {
			next, max1 = max1, next
		}
		if next > max2 {
			next, max2 = max2, next
		}
	}

	if total <= max1+max2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

func readBigInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}

package main

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

type can struct {
	capacity uint64
	used     uint64
}

func solve() {
	n := readInt()
	cola := int64(0)
	for i := 0; i < n; i++ {
		cola += readInt64()
	}

	large1 := int64(0)
	large2 := int64(0)

	for i := 0; i < n; i++ {
		cp := readInt64()

		if cp > large1 {
			large2 = large1
			large1 = cp
		} else if cp > large2 {
			large2 = cp
		}
	}

	if cola > (large1 + large2) {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

func solve() {
	n := readInt()

	total := int64(0)
	for i := 0; i < n; i++ {
		total += readInt64()
	}
	max1 := int64(0)
	max2 := int64(0)
	for i := 0; i < n; i++ {
		a := readInt64()
		if a > max1 {
			max2 = max1
			max1 = a
		} else if a > max2 {
			max2 = a
		}
	}
	if total <= max1+max2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n, a := readIntsll(0)
	_, b := readIntsll(n)
	var s int64
	for i := range a {
		s += a[i]
	}
	sort.Slice(b, func(i, j int) bool { return b[i] > b[j] })
	if s <= b[0]+b[1] {
		println("YES")
	} else {
		println("NO")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	io := bufio.NewReader(os.Stdin)
	var n int64
	fmt.Fscan(io, &n)
	var rem int64
	for i := int64(0); i < n; i++ {
		var input int64
		fmt.Fscan(io, &input)
		rem += input
	}
	var max1, max2 int64
	for i := int64(0); i < n; i++ {
		var input int64
		fmt.Fscan(io, &input)
		if input > max1 {
			max2, max1 = max1, input
		} else if input > max2 {
			max2 = input
		}
	}
	if rem > max1+max2 {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type greed struct {
	n int
}

func (c *greed) solve() {
	inp := bufio.NewReader(os.Stdin)

	// read n
	fmt.Fscanf(inp, "%d\n", &c.n)
	if c.n == 2 {
		fmt.Print("YES")
		return
	}

	// read cola
	var totalCola uint64
	var cola, cap int
	for i := 0; i < c.n; i++ {
		fmt.Fscanf(inp, "%d", &cola)
		totalCola += uint64(cola)
	}
	fmt.Fscanf(inp, "\n")

	// check total cola
	if totalCola > 2000000000 {
		fmt.Print("NO")
		return
	}

	// read first 2
	var max1, max2 int
	fmt.Fscanf(inp, "%d %d ", &max1, &max2)
	if max1 > max2 {
		max1, max2 = max2, max1
	}
	for i := 2; i < c.n; i++ {
		fmt.Fscanf(inp, "%d", &cap)
		if cap > max1 {
			max1 = cap
		}
		if max1 > max2 {
			max1, max2 = max2, max1
		}
	}

	if uint64(max1+max2) >= totalCola {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

func main() {
	var g greed
	g.solve()
}

package main
import "sort"

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

var local = false
var scanner *bufio.Scanner

type Arr64 []int64 // named type

func (p Arr64) Len() int { // p can't be pointer receiver
	return len(p)
}

func (p Arr64) Less(i, j int) bool { // i, j are indexes
	return p[i] < p[j]
}

func (p Arr64) Swap(i, j int) { // i, j are indexes
	p[i], p[j] = p[j], p[i]
}

func main() {
	setup()
	n := readInt()

	// volumn
	v := make([]int, n)
	nSum := int64(0)
	for i, _ := range v {
		v[i] = readInt()
		nSum += int64(v[i])
	}

	// capacity
	c := make(Arr64, n)
	for i, _ := range c {
		c[i] = readBigInt()
	}
	sort.Sort(c)
	nSum2 := c[n-1] + c[n-2]
	if nSum2 >= nSum {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

func readBigInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt() // Scan耗时厉害？

	// volumn
	nSum := int64(0)
	for i := 0; i < n; i++ {
		v := readBigInt()
		nSum += v
	}

	// capacity
	var mx1, mx2 int64 = 0, 0
	for i := 0; i < n; i++ {
		c := readBigInt()
		if c > mx1 {
			mx2 = mx1
			mx1 = c
		} else if c > mx2 {
			mx2 = c
		}
	}

	nSum2 := mx1 + mx2
	if nSum2 >= nSum {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

func readBigInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}

package main
import "sort"

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt()

	// volumn
	v := make([]int, n)
	nSum := int64(0)
	for i, _ := range v {
		v[i] = readInt()
		nSum += int64(v[i])
	}

	// capacity
	c := make([]int, n)
	for i, _ := range c {
		c[i] = readInt()
	}
	sort.Ints(c)
	nSum2 := int64(c[n-1]) + int64(c[n-2])
	if nSum2 >= nSum {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

func readBigInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}