import sys

input = sys.stdin.readline
out = sys.stdout

def main():
    n, c = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    el_prec = [0, c + b[0]] + [0]*(n - 1)
    for i in range(2, n):
        el_prec[i] = el_prec[i - 1] + b[i - 1]
    dp = [0, min(a[0], c + b[0])] + [0]*(n - 2)
    elev = [True if a[0] >= c + b[0] else False] + [False]*n
    for i in range(2, n):
        if el_prec[i] <= dp[i-1] + c + b[i - 1] and el_prec[i] <= a[i-1] + dp[i-1]:
            dp[i] = el_prec[i]
            elev[i-1]=True
        else:
            if elev[i - 2]:
                if b[i - 1] <= a[i - 1]:
                    dp[i] = dp[i - 1] + b[i - 1]
                    elev[i - 1] = True
                else:
                    dp[i] = dp[i - 1] + a[i - 1]
            else:
                if c + b[i - 1] <= a[i - 1]:
                    dp[i] = dp[i - 1] + b[i - 1] + c
                    elev[i - 1] = True
                else:
                    dp[i] = dp[i - 1] + a[i - 1]
    print(*dp)

if __name__=="__main__":
   main()


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
n,c=map(int,input().split())
sta=list(map(int,input().split()));ele=list(map(int,input().split()))
dp0=[0 for s in range(n)];dp1=[0 for s in range(n)];dp1[0]=c
for s in range(1,n):
    cs=sta[s-1];ce=ele[s-1]
    dp0[s]=min(dp0[s-1],dp1[s-1])+cs
    dp1[s]=min(dp0[s-1]+c,dp1[s-1])+ce
print(*[min(dp0[s],dp1[s]) for s in range(n)])


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
import heapq;from collections import defaultdict
n,c=map(int,input().split())
sta=list(map(int,input().split()));ele=list(map(int,input().split()))
heap=[];ind=defaultdict(list);#c+E_r-S_r<E_l-S_l
ans=[0];sums=[0];sume=[0]
check=[False for s in range(n)]
for s in range(1,n):
    #we are at the s+1th floor
    sums.append(sums[-1]+sta[s-1]);sume.append(sume[-1]+ele[s-1])
    heapq.heappush(heap,-(sume[-2]-sums[-2]))
    ind[sume[-2]-sums[-2]].append(s-1)
    if check[s-1]==True:
        if ele[s-1]<=sta[s-1]:
            ans.append(ans[-1]+ele[s-1])
            heap.clear();heapq.heappush(heap,-(sume[-2]-sums[-2]))
            check[s]=True
        else:
            ans.append(ans[-1]+sta[s-1])
    else:
        val=c+sume[-1]-sums[-1];v0=heapq.heappop(heap)
        if val<=-v0:
            i=ind[-v0][-1]
            if check[i]==True:
                ans.append(min(ans[i]+sume[-1]-sume[i],ans[-1]+ele[s-1]+c))
            else:
                ans.append(min(ans[i]+sume[-1]-sume[i]+c,ans[-1]+ele[s-1]+c))
            heap.clear();check[s]=True;ind[-v0]=[s]
        else:
            ans.append(ans[-1]+sta[s-1])
        heapq.heappush(heap,v0)
print(*ans)


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
n,c=map(int,input().split())
sta=list(map(int,input().split()));ele=list(map(int,input().split()))
onele=False;ind=0;sume=c;sums=0
ans=[0]
for s in range(1,n):
    cs=sta[s-1];ce=ele[s-1]
    if onele:
        if ce<cs:
            ans.append(ans[-1]+ce)
        else:
            ans.append(ans[-1]+cs);onele=False
        ind=0;sume=c;sums=0
    else:
        if ce<cs:
            sume+=ce;sums+=cs
            if sume<=sums:
                ans.append(ans[-1-ind]+sume);onele=True
            else:
                ans.append(ans[-1]+cs)
            ind+=1
        else:
            sume=c;sums=0;ind=0
            ans.append(ans[-1]+cs)
print(*ans)


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
n,c=map(int,input().split())
sta=list(map(int,input().split()));ele=list(map(int,input().split()))
onele=False;ind=0;sume=c;sums=0
ans=[0]
for s in range(1,n):
    cs=sta[s-1];ce=ele[s-1]
    if onele:
        if ce<=cs:
            ans.append(ans[-1]+ce)
        else:
            ans.append(ans[-1]+cs);onele=False
        ind=0;sume=c;sums=0
    else:
        if ce<=cs:
            sume+=ce;sums+=cs
            if sume<=sums:
                ans.append(ans[-1-ind]+sume);onele=True
            else:
                ans.append(ans[-1]+cs)
            ind+=1
        else:
            sume=c;sums=0;ind=0
            ans.append(ans[-1]+cs)
print(*ans)


import heapq;from collections import defaultdict
n,c=map(int,input().split())
sta=list(map(int,input().split()));ele=list(map(int,input().split()))
heap=[];ind=defaultdict(list);#c+E_r-S_r<E_l-S_l
ans=[0];sums=[0];sume=[0]
check=[False for s in range(n)]
for s in range(1,n):
    #we are at the s+1th floor
    sums.append(sums[-1]+sta[s-1]);sume.append(sume[-1]+ele[s-1])
    heapq.heappush(heap,-(sume[-1]-sums[-1]))
    ind[sume[-1]-sums[-1]].append(s)
    if check[s-1]==True:
        if ele[s-1]<=sta[s-1]:
            ans.append(ans[-1]+ele[s-1])
            heap.clear();heapq.heappush(heap,-(sume[-1]-sums[-1]))
            check[s]=True
        else:
            ans.append(ans[-1]+sta[s-1])
    else:
        if s==1:
            if sta[s-1]<=ele[s-1]+c:
                ans.append(sta[s-1])
            else:
                ans.append(ele[s-1]+c);check[s]=True
            continue
        val=c+sume[-1]-sums[-1];v0=heapq.heappop(heap)
        if val<=-v0:
            i=ind[-v0][-1]
            if check[i]==True:
                ans.append(ans[i]+sume[-1]-sume[i])
            else:
                ans.append(ans[i]+sume[-1]-sume[i]+c)
            heap.clear();check[s]=True;ind[-v0]=[s]
        else:
            ans.append(ans[-1]+sta[s-1])
        heapq.heappush(heap,v0)
print(*ans)


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
n,c=map(int,input().split())
sta=list(map(int,input().split()));ele=list(map(int,input().split()))
onele=False;ind=0;sume=c;sums=0
ans=[0]
for s in range(1,n):
    cs=sta[s-1];ce=ele[s-1]
    if onele:
        if ce<=cs:
            ans.append(ans[-1]+ce)
        else:
            ans.append(ans[-1]+cs);onele=False
        ind=0;sume=c;sums=0
    else:
        if ce<=cs:
            sume+=ce;sums+=cs
            if sume<=sums:
                ans.append(ans[-1-ind]+sume);onele=True
            else:
                ans.append(ans[-1]+cs)
            ind+=1
        else:
            if sume+ce<=sums+cs:
                ind1+=1;sume+=ce;sums+=cs
            else:
                ind=0;sume=c;sums=0
            ans.append(ans[-1]+cs)
print(*ans)


n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [[0, 0]] * n
for i in range(1, n):
    if dp[i - 1][1]:
        dp[i] = [dp[i - 1][0] + b[i - 1], 1]
    else:
        dp[i] = [dp[i - 1][0] + b[i - 1] + c, 1]
    if dp[i][0] > dp[i - 1][0] + a[i - 1]:
        dp[i] = [dp[i - 1][0] + a[i - 1], 0]
for elem in dp:
    print(elem[0], end=" ")


n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dp = [[0, 0] for i in range(n)]
dp[0] = [0, c]
for i in range(1, n):
    ans1 = dp[i - 1][0] + a[i - 1]
    ans2 = dp[i - 1][1] + b[i - 1]
    dp[i][1] = min(ans2, dp[i - 1][0] + c + b[i - 1])
    dp[i][0] = min(ans1, dp[i][1])
for elem in dp:
    print(min(elem[0], elem[1]), end=" ")


r=lambda:list(map(int,input().split()))
n,c=r()
s=r()
e=r()
print(0,end=" ")
ele=c+e[0]
st=s[0]
print(min(ele,st),end=" ")
for i in range(1,n-1):
    ele0=min(st+c+e[i],ele+e[i])
    st0=min(ele+s[i],st+s[i])
    ele=ele0
    st=st0
    print(min(ele,st),end=" ")


import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

# ------------------------------

def main():
    n, c = RL()
    arra = RLL()
    arrb = RLL()

    dp = [[0, 0] for _ in range(n)]
    dp[0] = [0, 0]
    dp[1] = [arra[0], arrb[0]+c]

    for i in range(2, n):
        dp[i][0] = min(dp[i-1])+arra[i-1]
        dp[i][1] = min(dp[i-1][1]+arrb[i-1], dp[i-1][0]+arrb[i-1]+c)

    print(*[min(i) for i in dp])

if __name__ == "__main__":
    main()


inp = lambda : map(int, input().split())

n, c = inp()
a = list(inp())
b = list(inp())

ans = list()
ans.append(0)

so_far = 0
is_elevator = False
for i in range(n-1):
  stairs = a[i]
  elevator = b[i]
  if not is_elevator:
    elevator += c

  is_elevator = elevator < stairs

  so_far += min(stairs, elevator)
  ans.append(so_far)

print(*ans)


#hint: https://codeforces.com/blog/entry/70779

inp = lambda : map(int, input().split())

n, c = inp()
a = list(inp())
b = list(inp())

ans = list()
ans.append(0)

arr = [[1000000000,10000000000] for i in range(n)]

arr[0][0] = 0
arr[0][1] = c

for i in range(n-1):
  arr[i+1][0] = min(arr[i+1][0], arr[i][0] + a[i])
  arr[i+1][0] = min(arr[i+1][0], arr[i][1] + a[i])

  arr[i+1][1] = min(arr[i+1][1], arr[i][1] + b[i])
  arr[i+1][1] = min(arr[i+1][1], arr[i][0] + b[i] + c)

ans = []
for i in range(n):
  ans.append(min(arr[i][0], arr[i][1]))

print(*ans)


n,c=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]

dp0=[0]
dp1=[c]

for i in range(0,n-1):
    dp0.append(min(dp0[i],dp1[i])+a[i])
    dp1.append(min(dp0[i]+c,dp1[i])+b[i])

for i in range(0,n):
    print(min(dp0[i],dp1[i]),end=" ")

print(" ")


n,c=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]

dp0=[0]
dp1=[c]

for i in range(0,n-1):
    dp0.append(min(dp0[i]+a[i],dp1[i]+a[i]))
    dp1.append(min(dp0[i]+b[i]+c,dp1[i]+b[i]))

for i in range(0,n):
    print(min(dp0[i],dp1[i]),end=" ")

print(" ")


n,c=list(map(int,input().strip().split()))
a=list(map(int,input().strip().split()))
b=list(map(int,input().strip().split()))
arr=[[0,2] for i in range(n+2)]
op=[0]*(n)
for i in range(1,n):
    # print(a[i-1],b[i-1])
    arr[i][0]=min(arr[i-1][0]+a[i-1],arr[i-1][1]+a[i-1])
    arr[i][1]=min(arr[i-1][1]+b[i-1],arr[i-1][0]+b[i-1]+c)
    op[i]=min(arr[i])
# print(arr)
print(" ".join(list(map(str,op))))


n,c=list(map(int,input().strip().split()))
a=list(map(int,input().strip().split()))
b=list(map(int,input().strip().split()))
arr=[[0,c] for i in range(n+2)]
op=[0]*(n)
for i in range(1,n):
    # print(a[i-1],b[i-1])
    arr[i][0]=min(arr[i-1][0]+a[i-1],arr[i-1][1]+a[i-1])
    arr[i][1]=min(arr[i-1][1]+b[i-1],arr[i-1][0]+b[i-1]+c)
    op[i]=min(arr[i])
# print(arr)
print(" ".join(list(map(str,op))))


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
from random import randint
##import numpy as np
##sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
def pref(a,n,f):
    pre=[0]*n
    if(f==0):         ##from beginning
        pre[0]=a[0]
        for i in range(1,n):
            pre[i]=a[i]+pre[i-1]
    else:              ##from end
        pre[-1]=a[-1]
        for i in range(n-2,-1,-1):
            pre[i]=pre[i+1]+a[i]
    return pre

for _ in range(1):
    n,c=cin()
    a=ain();b=ain();ans=[0]*n
    p=1
    for i in range(0,n-1):
        if(b[i]+p*c<a[i]):
            ans[i+1]+=ans[i]+b[i]+p*c
            p=0
        else:
            ans[i+1]+=ans[i]+a[i]
            p=1
    print(*ans)

##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24
##def kadane(a,size):
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##
##    for i in range(0, size):
##        max_ending_here = max_ending_here + a[i]
##        if (max_so_far < max_ending_here):
##            max_so_far = max_ending_here
##
##        if max_ending_here < 0:
##            max_ending_here = 0
##    return max_so_far
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo
##    else:
##        if(y > 0):return (x * temp * temp)%mo
##        else:return ((temp * temp)//x )%mo

##for _ in range(1):
##    n=inin()
##    l=ain()
##    d=dd(list)
##    dp=dd(set)
##    for k in range(n):
##        i=l[k]
##        dp[i].add(k)
##        b=bin(i)[2:]
##        c=0
##        for j in b[::-1]:
##            if j=='1':
##                d[c]+=[[i,k]]
##            c+=1
##    key=sorted(list(d.keys()),reverse=True)
##    ans=0
##    for i in key:
##        va=d[i]
##        va.sort(reverse=True)
##        p=len(va)
##        if(p!=0):
##            c=0;tans=0
##            for j,po in va:
##                if(po in dp[j]):
##                    c+=1
##                    f1,f2=j,po
##                    tans+=j
##                    dp[j].remove(po)
##            if(c%2==0 and c!=0):
##                c-=1
##
##            ans+=tans
##            print(ans,i,c,va)
##    print(ans)
##
##
##


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
from random import randint
##import numpy as np
##sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
for _ in range(1):
    n,c=cin()
    a=ain();b=ain();ans=[0]*n
    t0=[0]*n;t1=[0]*n;t1[0]=c
    for i in range(0,n-1):
        t0[i+1]=min(t0[i],t1[i])+a[i]
        t1[i+1]=min(t0[i]+b[i]+c,t1[i]+b[i])
        ans[i+1]=min(t0[i+1],t1[i+1])
    print(*ans)

##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24
##def kadane(a,size):
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##
##    for i in range(0, size):
##        max_ending_here = max_ending_here + a[i]
##        if (max_so_far < max_ending_here):
##            max_so_far = max_ending_here
##
##        if max_ending_here < 0:
##            max_ending_here = 0
##    return max_so_far
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo
##    else:
##        if(y > 0):return (x * temp * temp)%mo
##        else:return ((temp * temp)//x )%mo

##for _ in range(1):
##    n=inin()
##    l=ain()
##    d=dd(list)
##    dp=dd(set)
##    for k in range(n):
##        i=l[k]
##        dp[i].add(k)
##        b=bin(i)[2:]
##        c=0
##        for j in b[::-1]:
##            if j=='1':
##                d[c]+=[[i,k]]
##            c+=1
##    key=sorted(list(d.keys()),reverse=True)
##    ans=0
##    for i in key:
##        va=d[i]
##        va.sort(reverse=True)
##        p=len(va)
##        if(p!=0):
##            c=0;tans=0
##            for j,po in va:
##                if(po in dp[j]):
##                    c+=1
##                    f1,f2=j,po
##                    tans+=j
##                    dp[j].remove(po)
##            if(c%2==0 and c!=0):
##                c-=1
##
##            ans+=tans
##            print(ans,i,c,va)
##    print(ans)
##
##
##


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
from random import randint
##import numpy as np
##sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
for _ in range(1):
    n,c=cin()
    a=ain();b=ain();ans=[0]*n
    p=1
    for i in range(0,n-1):
        if(b[i]+p*c<=a[i]):
            ans[i+1]+=ans[i]+b[i]+p*c
            p=0
        else:
            ans[i+1]+=ans[i]+a[i]
            p=1
    print(*ans)

##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):
##    pre=[0]*n
##    if(f==0):         ##from beginning
##        pre[0]=a[0]
##        for i in range(1,n):
##            pre[i]=a[i]+pre[i-1]
##    else:              ##from end
##        pre[-1]=a[-1]
##        for i in range(n-2,-1,-1):
##            pre[i]=pre[i+1]+a[i]
##    return pre
##maxint=10**24
##def kadane(a,size):
##    max_so_far = -maxint - 1
##    max_ending_here = 0
##
##    for i in range(0, size):
##        max_ending_here = max_ending_here + a[i]
##        if (max_so_far < max_ending_here):
##            max_so_far = max_ending_here
##
##        if max_ending_here < 0:
##            max_ending_here = 0
##    return max_so_far
##def power(x, y):
##    if(y == 0):return 1
##    temp = power(x, int(y / 2))%mo
##    if (y % 2 == 0):return (temp * temp)%mo
##    else:
##        if(y > 0):return (x * temp * temp)%mo
##        else:return ((temp * temp)//x )%mo

##for _ in range(1):
##    n=inin()
##    l=ain()
##    d=dd(list)
##    dp=dd(set)
##    for k in range(n):
##        i=l[k]
##        dp[i].add(k)
##        b=bin(i)[2:]
##        c=0
##        for j in b[::-1]:
##            if j=='1':
##                d[c]+=[[i,k]]
##            c+=1
##    key=sorted(list(d.keys()),reverse=True)
##    ans=0
##    for i in key:
##        va=d[i]
##        va.sort(reverse=True)
##        p=len(va)
##        if(p!=0):
##            c=0;tans=0
##            for j,po in va:
##                if(po in dp[j]):
##                    c+=1
##                    f1,f2=j,po
##                    tans+=j
##                    dp[j].remove(po)
##            if(c%2==0 and c!=0):
##                c-=1
##
##            ans+=tans
##            print(ans,i,c,va)
##    print(ans)
##
##
##


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

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

DP = [[float("inf")]*2 for i in range(n)]
DP[0][0] = 0

for i in range(n-1):
    DP[i+1][0] = min(DP[i][0], DP[i][1]) + a[i]
    DP[i+1][1] = min(DP[i][0]+c, DP[i][1]) + b[i]

ans = [min(DP[i]) for i in range(n)]

print(*ans)


import sys
from collections import deque
readline = sys.stdin.readline

n, c = map(int, readline().split())

dp = [[int(pow(10,9)),int(pow(10,9))] for _ in range(n)]
dp[0][0] = 0
dp[0][1] = c
tmp = []
tmp.append([int(x) for x in readline().split()])
tmp.append([int(x) for x in readline().split()])

for i in range(n - 1):
    dp[i + 1][0] = min(dp[i][0],dp[i][1]) + tmp[0][i]
    dp[i + 1][1] = min(dp[i][0] + c,dp[i][1]) + tmp[1][i]

for x in dp:
    print(min(x[0], x[1]),end=' ')


n , c = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans=[0]*n
prev=0
#print(a,b)
for i in range(1,n):
    if prev==0:
        if a[i-1]<b[i-1]+c:
            ans[i]=a[i-1]+ans[i-1]
        else:
            ans[i]=b[i-1]+ans[i-1]+c
            prev=1
    else:
        if a[i-1]<b[i-1]:
            ans[i]=a[i-1]+ans[i-1]
            prev=0
        else:
            ans[i]=b[i-1]+ans[i-1]
#    print(ans[i])
print(*ans)


n,c=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
dp=[[0,c] for i in range(n)]
for i in range(1,n):
	dp[i][0]=min(dp[i-1][0],dp[i-1][1])+a[i-1]
	dp[i][1]=min(dp[i-1][0]+c+b[i-1],dp[i-1][1]+b[i-1])
ans=[]
for i in range(n):
	ans.append(min(dp[i][0],dp[i][1]))
print (*ans)


from sys import setrecursionlimit as SRL, stdin

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

n, c = rrd()
a = list(rrd())
b = list(rrd())
a = [0] + a
b = [0] + b
for i in range(1, n):
    b[i] += b[i - 1]

ans = [10 ** 10] * 200005
ans[0] = 0
mab = 0
for i in range(1, n + 1):
    ans[i] = min(ans[i], ans[i - 1] + a[i - 1], b[i-1] + mab + c)
    if ans[i]-b[i-1] < mab:
        mab = ans[i]-b[i-1]

for i in range(1, n + 1):
    print(ans[i], end=' ')


from sys import stdin
from sys import setrecursionlimit as SRL

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

n,c = rrd()
a = list(rrd())
b = list(rrd())
a = [0]+a
b = [0]+b
for i in range(1,n):
    a[i]+=a[i-1]
    b[i]+=b[i-1]

ans = [10**10] *200005
ans[1] = 0
for i in range(2,n+1):
    for j in range(1,i):
        ans[i] = min(ans[i],ans[j]+a[i-1]-a[j-1],ans[j]+c+b[i-1]-b[j-1])

for i in range(1,n+1):
    print(ans[i],end=' ')


n,c =  list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dp1,dp2 = [0]*n,[0]*n
dp2[0] = c
p = 0
for i in range(1,n):
    dp1[i] = min(dp1[i-1],dp2[i-1])+a[i-1]
    dp2[i] = min(dp2[i-1]+b[i-1],dp1[i-1]+b[i-1]+c)
for i in range(n):
    print(min(dp1[i],dp2[i]),end=" ")


n,c=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
dp=[[0,c] for i in range(n)]
for i in range(1,n):
    dp[i][0]=min(dp[i-1][0]+aa[i-1],dp[i-1][1]+aa[i-1])
    dp[i][1]=min(dp[i-1][0]+c+bb[i-1],dp[i-1][1]+bb[i-1])
print(*[min(i) for i in dp])


'''input
8
1
2
6
13
14
3620
10000
1000000000000000000
'''
# A coding delight

from sys import stdin, stdout
import sys
from bisect import bisect_left, bisect_right
import gc
gc.disable()

def range(start, end, jump):

# main starts
n, c = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
brr = list(map(int, stdin.readline().split()))
dp = [[0 for x in range(2)]for y in range(n)]
dp[0][1] = c

i = 1
while i < n:
	dp[i][0] = min(dp[i - 1][0] + arr[i - 1], dp[i - 1][1] + arr[i - 1])
	dp[i][1] = min(dp[i - 1][0] + c + brr[i - 1], dp[i - 1][1] + brr[i - 1])
	i += 1
# print(dp)
i = 0
while i < n:
	stdout.write(str(min(dp[i])) + ' ')
	i += 1


'''input
8
1
2
6
13
14
3620
10000
1000000000000000000
'''
# A coding delight

from sys import stdin, stdout
import sys
from bisect import bisect_left, bisect_right
import gc
gc.disable()

# main starts
n, c = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
brr = list(map(int, stdin.readline().split()))
dp = [[0 for x in range(2)]for y in range(n)]
dp[0][1] = c
for i in range(1, n):
	dp[i][0] = min(dp[i - 1][0] + arr[i - 1], dp[i - 1][1] + arr[i - 1])
	dp[i][1] = min(dp[i - 1][0] + c + brr[i - 1], dp[i - 1][1] + brr[i - 1])

# print(dp)
for i in range(n):
	stdout.write(str(min(dp[i])) + ' ')


'''input
8
1
2
6
13
14
3620
10000
1000000000000000000
'''
# A coding delight

from sys import stdin, stdout
import sys
from bisect import bisect_left, bisect_right
import gc
gc.disable()

# main starts
n, c = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
brr = list(map(int, stdin.readline().split()))
dp = [[0 for x in range(2)]for y in range(n)]
dp[0][1] = c

i = 1
while i < n:
	dp[i][0] = min(dp[i - 1][0] + arr[i - 1], dp[i - 1][1] + arr[i - 1])
	dp[i][1] = min(dp[i - 1][0] + c + brr[i - 1], dp[i - 1][1] + brr[i - 1])
	i += 1
# print(dp)
i = 0
while i < n:
	stdout.write(str(min(dp[i])) + ' ')
	i += 1


'''input
8
1
2
6
13
14
3620
10000
1000000000000000000
'''
# A coding delight

from sys import stdin, stdout
import sys
from bisect import bisect_left, bisect_right
import gc
gc.disable()

# main starts
n, c = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
brr = list(map(int, stdin.readline().split()))
dp = [[0 for x in range(2)]for y in range(n)]
dp[0][1] = c
for i in range(1, n):
	dp[i][0] = min(dp[i - 1][0] + arr[i - 1], dp[i - 1][1] + arr[i - 1])
	dp[i][1] = min(dp[i - 1][0] + c + brr[i - 1], dp[i - 1][1] + brr[i - 1])

# print(dp)
for i in range(n):
	print(min(dp[i]), end = ' ')


#!/usr/bin/env python3
import sys
from math import inf

#lines = stdin.readlines()
def rint():
    return map(int, sys.stdin.readline().split())

def input():
    return sys.stdin.readline().rstrip('\n')

def oint():
    return int(input())

n, c = rint()

a = list(rint())
b = list(rint())

e = 0
ans = [0]
e = [0]*(n+2)
mina = [inf]*(n+2)
mine = [inf]*(n+2)
mina[0] = a[0]
mine[0] = b[0] + c
for i in range(1, n-1):
    mine[i] = b[i] + min(mine[i-1], mina[i-1] + c, mine[i-2]  + mine[i-1])
    mina[i] = a[i] + min(mina[i-1], mine[i-1])

for i in range(n-1):
    ans.append(min(mine[i], mina[i]))

print(*ans)


#!/usr/bin/env python3
import sys

#lines = stdin.readlines()
def rint():
    return map(int, sys.stdin.readline().split())

def input():
    return sys.stdin.readline().rstrip('\n')

def oint():
    return int(input())

n, c = rint()

a = list(rint())
b = list(rint())

e = 0
prev = 0
ans = [0]
for i in range(n-1):
    if e == 1:
        if b[i] <= a[i]:
            prev = b[i] + prev
            ans.append(prev)
        else:
            prev = a[i] + prev
            ans.append(prev)
            e = 0
    else:
        if b[i] + c <= a[i]:
            prev = b[i] + c + prev
            ans.append(prev)
            e = 1
        else:
            prev = a[i] + prev
            ans.append(prev)

print(*ans)


import math

n,c=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
dp=[[math.inf]*2 for x in range(n)]

dp[0]=[0,c]
for i in range(1,n):
    dp[i][0]=min(dp[i-1])+a[i-1]
    dp[i][1]=min(dp[i-1][0]+c+b[i-1],dp[i-1][1]+b[i-1])

print(' '.join([str(min(x)) for x in dp]))


n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[i] = [0,0]
ans[0][0] = 0
ans[0][0] = c

for i in range(1, n):

    ans[i][0] = min(ans[i - 1][0] + a[i - 1], ans[i - 1][1] + a[i - 1])
    ans[i][1] = min(ans[i - 1][0] + c + b[i - 1], ans[i - 1][1] + b[i - 1])
for i in range(n):
    print(min(ans[i][0], ans[i][1]) + 1, end = ' ')


n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[i] = [0,0]
ans[0][0] = 0
ans[0][1] = c

for i in range(1, n):

    ans[i][0] = min(ans[i - 1][0] + a[i - 1], ans[i - 1][1] + a[i - 1])
    ans[i][1] = min(ans[i - 1][0] + c + b[i - 1], ans[i - 1][1] + b[i - 1])
for i in range(n):
    print(min(ans[i][0], ans[i][1]), end = ' ')


n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[i] = [0,0]
ans[0][0] = 0
ans[0][1] = c

for i in range(1, n):

    ans[i][0] = min(ans[i - 1][0] + a[i - 1], ans[i - 1][1] + a[i - 1])
    ans[i][1] = min(ans[i - 1][0] + c + b[i - 1], ans[i - 1][1] + b[i - 1])
print(ans)
for i in range(n):
    print(min(ans[i][0], ans[i][1]), end = ' ')


n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[i] = [0,0]
ans[0][0] = 0
ans[0][0] = c

for i in range(1, n):

    ans[i][0] = min(ans[i - 1][0] + a[i - 1], ans[i - 1][1] + a[i - 1])
    ans[i][1] = min(ans[i - 1][0] + c + b[i - 1], ans[i - 1][1] + b[i - 1])
print(0, end = ' ')
for i in range(1, n):
    print(min(ans[i][0], ans[i][1]) + 1, end = ' ')


n, c = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
dp = [[0 for i in range(2)] for j in range(n)]
dp[1][0] = a[0]
dp[1][1] = b[0] + c
for i in range(2, n):
    dp[i][0] = min(dp[i - 1][0] + a[i - 1], dp[i - 1][1] + a[i - 1])
    dp[i][1] = min(dp[i - 1][1] + b[i - 1], dp[i - 1][0] + b[i - 1] + c)
ans = [0] * n
for i in range(n):
    ans[i] = min(dp[i][0], dp[i][1])
print(*ans)


n,c=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
dp=[[0]*2for i in range(n+1)]
print(0,end=" ")
for i in range(n-1):
    if i>0:
        dp[i][0]=min(dp[i-1][0]+y[i],dp[i-1][1]+y[i]+c)
        dp[i][1]=min(dp[i-1][0],dp[i-1][1])+x[i]
    else:
        dp[0][0]=y[0]+c
        dp[0][1]=x[0]
    print(min(dp[i][0],dp[i][1]),end=" ")


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

dp = [[0]*2 for i in range(n)]
dp[0][0] = 0
dp[0][1] = c
for i in range(n-1):
    dp[i+1][0] = min(dp[i][0] + a[i], dp[i][1] + a[i])
    dp[i+1][1] = min(dp[i][0] + b[i] + c, dp[i][1] + b[i])
ans = [0]*n
for i in range(n):
    print(min(dp[i][0],dp[i][1]),end=" ")


#include <bits/stdc++.h>
#define F first
#define S second
#define Pb push_back
using namespace std;
long long ANS=-1;
vector < pair < pair < int , int > , pair < int , int > > > v;
set < pair < int , pair < int , int > > > st;
set < pair < int , int > > St[203];
set < pair < int , pair < int , int > > > :: iterator it;
int n,m,GG,SS,Y[203][203],A,B,C,D,Ps,Ans;
pair < int , int > p[205];
int P(int x)
{
    if (p[x].F==x) return x;

    return p[x].F=P(p[x].F);
}
void Union(int a,int b)
{
	a=P(a);
	b=P(b);

	if (a==b) return ;

	if (p[a].S<p[b].S) swap(a,b);

	p[a].S+=p[b].S;
    p[b].F=a;

	if (Ps<p[a].S) Ps=p[a].S;
}
main ()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d",&GG,&SS);

	for (int i=1; i<=m; i++)
	{
		scanf("%d%d%d%d",&A,&B,&C,&D);

		if (A==B) continue;

		if (A>B) swap(A,B);

		v.Pb({{C,D},{A,B}});
	}

	sort(v.begin(),v.end());

	for (int i=0; i<v.size(); i++)
	{
		C=v[i].F.F; D=v[i].F.S; A=v[i].S.F; B=v[i].S.S;

		if (!Y[A][B])
		{
			Y[A][B]=D;
			st.insert({Y[A][B],{A,B}});
			St[A].insert({Y[A][B],B});
			St[B].insert({Y[A][B],A});
		}
			else
		if (Y[A][B]>D)
		{
			St[A].erase({Y[A][B],B});
			St[B].erase({Y[A][B],A});
			st.erase({Y[A][B],{A,B}});
			Y[A][B]=D;
			st.insert({Y[A][B],{A,B}});
			St[A].insert({Y[A][B],B});
			St[B].insert({Y[A][B],A});
		}
			else continue;

		for (int j=1; j<=n; j++) p[j].F=j,p[j].S=1;

		Ps=1;
		Ans=-1;

		for (int j=1; j<=n; j++)
		{
			if (!St[j].size()) continue ;

			if (P(j)==P((*St[j].begin()).S)) continue;

			Union(j,((*St[j].begin()).S));

			if (Ans<(*St[j].begin()).F) Ans=(*St[j].begin()).F;

			if (Ps==n) break;
		}

		for (it=st.begin(); it!=st.end(); it++)
		{
			if (P((*it).S.F)==P((*it).S.S)) continue;

			Union((*it).S.F,(*it).S.S);

			if (Ps==n)
			{
				if (Ans<(*it).F) Ans=(*it).F;
				break;
			}
		}

		if (Ps!=n) continue;

		if (ANS==-1) ANS=1LL*C*GG+1LL*Ans*SS;
			    else
		if (ANS>1LL*C*GG+1LL*Ans*SS) ANS=1LL*C*GG+1LL*Ans*SS;
	}

	printf("%I64d\n",ANS);
}


#include <bits/stdc++.h>
#define F first
#define S second
#define Pb push_back
using namespace std;
long long ANS=-1;
vector < pair < pair < int , int > , pair < int , int > > > v;
set < pair < int , pair < int , int > > > st;
set < pair < int , int > > St[203];
set < pair < int , pair < int , int > > > :: iterator it;
int n,m,G,S,Y[203][203],A,B,C,D,Ps,Ans;
pair < int , int > p[205];
int P(int x)
{
    if (p[x].F==x) return x;

    return p[x].F=P(p[x].F);
}
void Union(int a,int b)
{
	a=P(a);
	b=P(b);

	if (a==b) return ;

	if (p[a].S<p[b].S) swap(a,b);

	p[a].S+=p[b].S;
    p[b].F=a;

	if (Ps<p[a].S) Ps=p[a].S;
}
main ()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d",&G,&S);

	for (int i=1; i<=m; i++)
	{
		scanf("%d%d%d%d",&A,&B,&C,&D);

		if (A==B) continue;

		if (A>B) swap(A,B);

		v.Pb({{C,D},{A,B}});
	}

	sort(v.begin(),v.end());

	for (int i=0; i<v.size(); i++)
	{
		C=v[i].F.F; D=v[i].F.S; A=v[i].S.F; B=v[i].S.S;

		if (!Y[A][B])
		{
			Y[A][B]=D;
			st.insert({Y[A][B],{A,B}});
			St[A].insert({Y[A][B],B});
			St[B].insert({Y[A][B],A});
		}
			else
		if (Y[A][B]>D)
		{
			St[A].erase({Y[A][B],B});
			St[B].erase({Y[A][B],A});
			st.erase({Y[A][B],{A,B}});
			Y[A][B]=D;
			st.insert({Y[A][B],{A,B}});
			St[A].insert({Y[A][B],B});
			St[B].insert({Y[A][B],A});
		}
			else continue;

		Ans=-1;

		for (int j=1; j<=n; j++) p[j].F=j,p[j].S=1;

		Ps=1;

		for (int i=1; i<=n; i++)
		{
			if (P(i)==P((*St[i].begin()).S)) continue;

			Union(i,((*St[i].begin()).S));

			Ans=max(Ans,(*St[i].begin()).F);

			if (Ps==n) break;
		}

		for (it=st.begin(); it!=st.end(); it++)
		{
			Union((*it).S.F,(*it).S.S);

			if (Ps==n)
			{
				Ans=max(Ans,(*it).F);
				break;
			}
		}

		if (Ps!=n) continue;

		if (ANS==-1) ANS=1LL*C*G+1LL*Ans*S;
			    else ANS=min(ANS,1LL*C*G+1LL*Ans*S);
	}

	printf("%I64d\n",ANS);
}


#include <bits/stdc++.h>
using namespace std;
long long ANS=-1;
vector < pair < pair < int , int > , pair < int , int > > > v;
set < pair < int , pair < int , int > > > st;
set < pair < int , pair < int , int > > > :: iterator it;
int n,m,G,S,Y[203][203],A,B,C,D,Ps,Ans;
pair < int , int > parent [205];
int P(int x)
{
    if (parent[x].first==x) return x;

    return parent[x].first=P(parent[x].first);
}
void Union(int a,int b)
{
	a=P(a);
	b=P(b);

	if (a==b) return ;

	if (parent[a].second>parent[b].second)
	{
		parent[a].second+=parent[b].second;
    	parent[b].first=a;
	}
		else
	{
		parent[b].second+=parent[a].second;
    	parent[a].first=b;
	}

	if (Ps<parent[a].second) Ps=parent[a].second;
	if (Ps<parent[b].second) Ps=parent[b].second;
}
main ()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d",&G,&S);

	for (int i=1; i<=m; i++)
	{
		scanf("%d%d%d%d",&A,&B,&C,&D);

		if (A==B) continue;

		if (A>B) swap(A,B);

		v.push_back({{C,D},{A,B}});
	}

	sort(v.begin(),v.end());

	for (int i=0; i<v.size(); i++)
	{
		C=v[i].first.first;
		D=v[i].first.second;
		A=v[i].second.first;
		B=v[i].second.second;

		if (!Y[A][B])
		{
			Y[A][B]=D;
			st.insert({Y[A][B],{A,B}});
		}
			else
		if (Y[A][B]>D)
		{
			st.erase(st.find({Y[A][B],{A,B}}));
			Y[A][B]=D;
			st.insert({Y[A][B],{A,B}});
		}
			else continue;

		Ans=-1;

		for (int j=1; j<=n; j++)
		{
			parent[j].first=j;
			parent[j].second=1;
		}

		Ps=1;

		for (it=st.begin(); it!=st.end(); it++)
		{
			Union((*it).second.first,(*it).second.second);

			if (Ps==n)
			{
				Ans=(*it).first;
				break;
			}
		}

		if (Ans==-1) continue;

		if (ANS==-1) ANS=1LL*C*G+1LL*Ans*S;
			    else ANS=min(ANS,1LL*C*G+1LL*Ans*S);
	}

	printf("%I64d\n",ANS);
}


#include <bits/stdc++.h>
#define F first
#define S second
#define Pb push_back
using namespace std;
long long ANS=-1;
vector < pair < pair < int , int > , pair < int , int > > > v;
set < pair < int , pair < int , int > > > st;
set < int > St[203];
int n,m,GG,SS,Y[203][203],A,B,C,D,Ps,Ans;
pair < int , int > p [205];
int P(int x)
{
    if (p[x].F==x) return x;

    return p[x].F=P(p[x].F);
}
void Union(int a,int b)
{
	a=P(a);
	b=P(b);

	if (a==b) return ;

	if (p[a].S<p[b].S) swap(a,b);

	p[a].S+=p[b].S;
    p[b].F=a;

	if (Ps<p[a].S) Ps=p[a].S;
}
pair < int , pair < int , int > > M;
void Df(int x,int parent,pair < int , pair < int , int > > w)
{
	if (w.F<Y[min(x,parent)][max(x,parent)])
	{
		w.F=Y[min(x,parent)][max(x,parent)];
		w.S.F=x;
		w.S.S=parent;
	}

	if (x==B)
	{
		M=w;
		return ;
	}

	for (set < int > :: iterator it=St[x].begin(); it!=St[x].end(); it++)
	{
		if ((*it)==parent) continue;

		Df((*it),x,w);
	}
}
main ()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d",&GG,&SS);

	for (int i=1; i<=m; i++)
	{
		scanf("%d%d%d%d",&A,&B,&C,&D);

		if (A==B) continue;

		if (A>B) swap(A,B);

		v.Pb({{C,D},{A,B}});
	}

	sort(v.begin(),v.end());

	for (int j=1; j<=n; j++)
		p[j].F=j,p[j].S=1;

	Ps=1;

	for (int i=0; i<v.size(); i++)
	{
		C=v[i].F.F; D=v[i].F.S; A=v[i].S.F; B=v[i].S.S;

		if (P(A)==P(B))
		{
			if (Y[A][B]>D)
			{
				st.erase({Y[A][B],{A,B}});
				Y[A][B]=D;
				st.insert({Y[A][B],{A,B}});
				continue;
			}
				else
			if (Y[A][B]) continue;

			M.F=0;
			M.S.F=0;
			M.S.S=0;

			Df(A,A,{0,{0,0}});

			if (M.S.F>M.S.S) swap(M.S.F,M.S.S);

			if (M.F>D)
			{
				St[M.S.F].erase(M.S.S);
				St[M.S.S].erase(M.S.F);
				st.erase({Y[M.S.F][M.S.S],{M.S.F,M.S.S}});
				Y[M.S.F][M.S.S]=0;

				Y[A][B]=D;
				st.insert({Y[A][B],{A,B}});
				St[A].insert(B);
				St[B].insert(A);
			}
		}
			else
		{
			Y[A][B]=D;
			st.insert({Y[A][B],{A,B}});

			Union(A,B);

			St[A].insert(B);
			St[B].insert(A);
		}

		if (Ps==n)
		{
			if (ANS==-1) ANS=1LL*C*GG+1LL*(*st.rbegin()).F*SS;
				    else ANS=min(ANS,1LL*C*GG+1LL*(*st.rbegin()).F*SS);
		}
	}

	printf("%I64d\n",ANS);
}


#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;
typedef long long ll;
const ll maxn = 205;
const ll maxn2 = 50005;
struct road{
	ll x,y,g,s;
	const bool operator < (const road &b)const
	{
		return g < b.g;
	}
	void show()
	{
		printf("x = %lld,y = %lld,g = %lld,s = %lld\n",x,y,g,s);
	}
	void scan()
	{
		scanf("%lld%lld%lld%lld",&x,&y,&g,&s);
	}
};
road R[maxn2];
ll n,m,g,s,father[maxn],vis[maxn];
bool cmp(road a,road b)
{
	return a.s < b.s;
}
ll findfather(ll index)
{
	if(father[index] == index)
	{
		return index;
	}
	return father[index] = findfather(father[index]);
}
int main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&g,&s);
	for(ll i = 0;i < m; ++i)
	{
		R[i].scan();
	}
	sort(R,R + n);
	long long ans = LLONG_MAX;
	ll r = 0;
	for(ll i = 0;i < m; ++i)
	{
		ll now = R[i].g;
		R[r++] = R[i];
		inplace_merge(R,R + r - 1,R + r,cmp);
		for(ll i = 1;i <= n; ++i)
		{
			father[i] = i;
		}
		ll cnt = 0;
		for(ll j = 0;j < r; ++j)
		{
			vis[j] = 0;
		}
		ll j,k;
		for(j = 0;j < r; ++j)
		{
			road cur = R[j];
			ll f1 = findfather(cur.x);
			ll f2 = findfather(cur.y);
			if(f1 != f2)
			{
				father[f1] = f2;
				cnt++;
			}
			else
			{
				vis[j] = 1;
			}
			if(cnt == n - 1)
			{
				break;
			}
		}
		if(cnt == n - 1)
		{
			ans = min(ans,(now * g + R[j].s * s) * 1ll);
		}
		for(j = k = 0;j < r; ++j)
		{
			if(!vis[j])
			{
				R[k++] = R[j];
			}
		}
		r = k;
	}
	printf("%lld\n",ans == LLONG_MAX ? -1 : ans);
	return 0;
}


#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;
typedef long long ll;
const ll maxn2 = 50005;
struct road{
	ll x,y,g,s;
	const bool operator < (const road &b)const
	{
		return g < b.g;
	}
	void show()
	{
		printf("x = %lld,y = %lld,g = %lld,s = %lld\n",x,y,g,s);
	}
	void scan()
	{
		scanf("%lld%lld%lld%lld",&x,&y,&g,&s);
	}
};
road R[maxn2];
ll n,m,g,s,father[maxn2],vis[maxn2];
bool cmp(road a,road b)
{
	return a.s < b.s;
}
ll findfather(ll index)
{
	if(father[index] == index)
	{
		return index;
	}
	return father[index] = findfather(father[index]);
}
int main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&g,&s);
	for(ll i = 0;i < m; ++i)
	{
		R[i].scan();
	}
	sort(R,R + n);
	long long ans = LLONG_MAX;
	ll r = 0;
	for(ll i = 0;i < m; ++i)
	{
		ll now = R[i].g;
		R[r++] = R[i];
		inplace_merge(R,R + r - 1,R + r,cmp);
		for(ll i = 1;i <= n; ++i)
		{
			father[i] = i;
		}
		ll cnt = 0;
		for(ll j = 0;j < r; ++j)
		{
			vis[j] = 0;
		}
		ll j,k;
		for(j = 0;j < r; ++j)
		{
			road cur = R[j];
			ll f1 = findfather(cur.x);
			ll f2 = findfather(cur.y);
			if(f1 != f2)
			{
				father[f1] = f2;
				cnt++;
			}
			else
			{
				vis[j] = 1;
			}
			if(cnt == n - 1)
			{
				break;
			}
		}
		if(cnt == n - 1)
		{
			ans = min(ans,(now * g + R[j].s * s) * 1ll);
		}
		for(j = k = 0;j < r; ++j)
		{
			if(!vis[j])
			{
				R[k++] = R[j];
			}
		}
		r = k;
	}
	printf("%lld\n",ans == LLONG_MAX ? -1 : ans);
	return 0;
}


#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;
const int maxn = 205;
const int maxn2 = 50005;
struct road{
	int x,y,g,s;
	const bool operator < (const road &b)const
	{
		return g < b.g;
	}
	void show()
	{
		printf("x = %d,y = %d,g = %d,s = %d\n",x,y,g,s);
	}
	void scan()
	{
		scanf("%d%d%d%d",&x,&y,&g,&s);
	}
};
road R[maxn2];
int n,m,g,s,father[maxn],vis[maxn];
bool cmp(road a,road b)
{
	return a.s < b.s;
}
int findfather(int index)
{
	if(father[index] == index)
	{
		return index;
	}
	return father[index] = findfather(father[index]);
}
int main(int argc, char const *argv[])
{
	scanf("%d%d%d%d",&n,&m,&g,&s);
	for(int i = 0;i < m; ++i)
	{
		R[i].scan();
	}
	sort(R,R + n);
	long long ans = LLONG_MAX;
	int r = 0;
	for(int i = 0;i < m; ++i)
	{
		int now = R[i].g;
		R[r++] = R[i];
		inplace_merge(R,R + r - 1,R + r,cmp);
		for(int i = 1;i <= n; ++i)
		{
			father[i] = i;
		}
		int cnt = 0;
		for(int j = 0;j < r; ++j)
		{
			vis[j] = 0;
		}
		int j,k;
		for(j = 0;j < r; ++j)
		{
			road cur = R[j];
			int f1 = findfather(cur.x);
			int f2 = findfather(cur.y);
			if(f1 != f2)
			{
				father[f1] = f2;
				cnt++;
			}
			else
			{
				vis[j] = 1;
			}
			if(cnt == n - 1)
			{
				break;
			}
		}
		if(cnt == n - 1)
		{
			ans = min(ans,(now * g + R[j].s * s) * 1ll);
		}
		for(j = k = 0;j < r; ++j)
		{
			if(!vis[j])
			{
				R[k++] = R[j];
			}
		}
		r = k;
	}
	printf("%d\n",ans == LLONG_MAX ? -1 : ans);
	return 0;
}


#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;
typedef long long ll;
const ll maxn = 50005;
struct road{
	ll x,y,g,s;
	const bool operator < (const road &b)const
	{
		return g < b.g;
	}
	void show()
	{
		printf("x = %lld,y = %lld,g = %lld,s = %lld\n",x,y,g,s);
	}
	void scan()
	{
		scanf("%lld%lld%lld%lld",&x,&y,&g,&s);
	}
};
road R[maxn];
ll n,m,g,s,father[maxn],vis[maxn];
bool cmp(road a,road b)
{
	return a.s < b.s;
}
ll findfather(ll index)
{
	if(father[index] == -1)
	{
		return index;
	}
	return father[index] = findfather(father[index]);
}
int main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&g,&s);
	for(ll i = 0;i < m; ++i)
	{
		R[i].scan();
	}
	sort(R,R + m);
	ll ans = LLONG_MAX;
	ll r = 0;
	for(ll i = 0;i < m; ++i)
	{
		ll now = R[i].g;
		R[r++] = R[i];
		inplace_merge(R,R + r - 1,R + r,cmp);
		for(ll i = 1;i <= n; ++i)
		{
			father[i] = -1;
		}
		ll cnt = 0;
		for(ll j = 0;j < r; ++j)
		{
			vis[j] = 0;
		}
		ll j,k;
		for(j = 0;j < r; ++j)
		{
			road cur = R[j];
			ll f1 = findfather(cur.x);
			ll f2 = findfather(cur.y);
			if(f1 != f2)
			{
				father[f1] = f2;
				cnt++;
			}
			else
			{
				vis[j] = 1;
			}
			if(cnt == n - 1)
			{
				break;
			}
		}
		if(cnt == n - 1)
		{
			ans = min(ans,(now * g + R[j].s * s) * 1ll);
		}
		for(j = k = 0;j < r; ++j)
		{
			if(!vis[j])
			{
				R[k++] = R[j];
			}
		}
		r = k;
	}
	printf("%lld\n",ans == LLONG_MAX ? -1 : ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p)
        {
            cy = tem;
            cy.pb({g[i][u].sc,{u,g[u][i].second}});
        }
        tem.pb({g[u][i].sc,{u,g[u][i].second}});
        dfs(g[u][i].second,u);
        tem.pop_back();
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;
    for(int i=0; i<m; i++)
    {
        for(int i=1;i<=n;i++)
            vis[i] = 0;

        if(ed[i].th==ed[i].fo)
            continue;

        mxs.insert(ed[i].sc);

        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});

        ll x = findp(ed[i].th);
        ll y = findp(ed[i].fo);

        if(x!=y)
        {
            p[x] = y;
        }

        tkn.pb(ed[i]);

        break;
    }

    for(++i; i<m; i++)
    {
        ll x = ed[i].th,y = ed[i].fo;
        //cout << x << " " << y << " dgdgfdsf" << endl;
        x = findp(x);
        y = findp(y);
        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }
        else
        {
           // cout << "          123 " << endl;
            int idx = -1;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;
                int id = -1;
                for(int j=0; j<g[x1].size(); j++)
                {
                    if(g[x1][j].second==y1)
                        id = j;
                }
                if(id!=-1)
                    g[x1].erase(g[x1].begin()+id);

                id = -1;
                for(int j=0; j<g[y1].size(); j++)
                {
                    if(g[y1][j].second==x1)
                        id = j;
                }
                if(id!=-1)
                    g[y1].erase(g[y1].begin()+id);
                mxs.erase(mxs.find(tkn[idx].sc));
                tkn.erase(tkn.begin()+idx);
                continue;
            }

            cy.clear();
            tem.clear();

            dfs(x,0);

            sort(cy.begin(),cy.end());

            ll x1 = cy[cy.size()-1].th;
            ll y1 = cy[cy.size()-1].fo;

            int id = -1;
            for(int j=0; j<g[x1].size(); j++)
            {
                if(g[x1][j].second==y1)
                    id = j;
            }
            if(id!=-1)
                g[x1].erase(g[x1].begin()+id);

            id = -1;
            for(int j=0; j<g[y1].size(); j++)
            {
                if(g[y1][j].second==x1)
                    id = j;
            }
            if(id!=-1)
                g[y1].erase(g[y1].begin()+id);

            mxs.erase(mxs.find(cy[cy.size()-1].first));

            idx=0;

            for(idx;idx<tkn.size();idx++)
                if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                   &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                    break;
            if(idx!=tkn.size())
                tkn.erase(tkn.begin()+idx);
        }
        set<ll>cnt;
        for(int j=1;j<=n;j++)
            cnt.insert(findp(j));
        if(cnt.size()==1){
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            sum += ((*it)*S);
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
    cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p)
        {
            cy = tem;
            cy.pb({g[u][i].sc,{u,g[u][i].second}});
        }
        tem.pb({g[u][i].sc,{u,g[u][i].second}});
        dfs(g[u][i].second,u);
        tem.pop_back();
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;
    for(int i=0; i<m; i++)
    {

        if(ed[i].th==ed[i].fo)
            continue;

        mxs.insert(ed[i].sc);

        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});

        ll x = findp(ed[i].th);
        ll y = findp(ed[i].fo);

        if(x!=y)
        {
            p[x] = y;
        }

        tkn.pb(ed[i]);

        break;
    }

    for(++i; i<m; i++)
    {
        if(ed[i].th==ed[i].fo)
            continue;
        for(int j=1;j<=n;j++)
            vis[j] = 0;
        ll x = ed[i].th,y = ed[i].fo;
        //cout << x << " " << y << " dgdgfdsf" << endl;
        x = findp(x);
        y = findp(y);
        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});
        mxs.insert(ed[i].sc);
        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
        }
        else
        {
           // cout << "          123 " << endl;
            int idx = -1;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;
                int id = -1;
                for(int j=0; j<g[x1].size(); j++)
                {
                    if(g[x1][j].second==y1)
                        id = j;
                }
                if(id!=-1)
                    g[x1].erase(g[x1].begin()+id);

                id = -1;
                for(int j=0; j<g[y1].size(); j++)
                {
                    if(g[y1][j].second==x1)
                        id = j;
                }
                if(id!=-1)
                    g[y1].erase(g[y1].begin()+id);
                mxs.erase(mxs.find(tkn[idx].sc));
                tkn.erase(tkn.begin()+idx);
                continue;
            }

            cy.clear();
            tem.clear();

            dfs(x,0);

            sort(cy.begin(),cy.end());

            int sz = cy.size();
            sz--;
            ll x1 = cy[sz].th;
            ll y1 = cy[sz].fo;

           // cout << 1 << endl;
            int id = -1;
            for(int j=0; j<g[x1].size(); j++)
            {
                if(g[x1][j].second==y1)
                    id = j;
            }
            if(id!=-1)
                g[x1].erase(g[x1].begin()+id);

            id = -1;
            for(int j=0; j<g[y1].size(); j++)
            {
                if(g[y1][j].second==x1)
                    id = j;
            }
            if(id!=-1)
                g[y1].erase(g[y1].begin()+id);

            mxs.erase(mxs.find(cy[cy.size()-1].first));

            idx=0;

            for(idx;idx<tkn.size();idx++)
                if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                   &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                    break;
            if(idx!=tkn.size())
                tkn.erase(tkn.begin()+idx);
        }
        set<ll>cnt;
        for(int j=1;j<=n;j++)
            cnt.insert(findp(j));
        if(cnt.size()==1){
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            ll smu = *it;
            smu*=S;
            sum += smu;
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
    cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 2e18+1;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p,ll st)
{
    if(vis[u])
        return;
    vis[u] = 1;
//    cout << u << endl;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p&&g[u][i].second==st)
        {
            cy = tem;
            cy.pb({g[u][i].sc,{u,g[u][i].second}});
            return;
        }
        if(!vis[g[u][i].second])
        {
            tem.pb({g[u][i].sc,{u,g[u][i].second}});
            dfs(g[u][i].second,u,st);
            tem.pop_back();
        }
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;

    for(i; i<m; i++)
    {
        if(ed[i].th==ed[i].fo)
            continue;

        for(int j=0; j<=n; j++)
            vis[j] = 0;

        ll x = ed[i].th,y = ed[i].fo;

        x = findp(x);
        y = findp(y);

        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }

        else
        {
            int idx = -1;
            bool f=0;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                    f = 1;
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;

                mxs.erase(mxs.find(tkn[idx].sc));

                tkn.erase(tkn.begin()+idx);

                mxs.insert(ed[i].sc);

                tkn.pb(ed[i]);

            }
            else{
            if(f)
                continue;

            for(int i=1; i<=n; i++)
            {
                g[i].clear();
            }

            tkn.pb(ed[i]);

            for(int j=0; j<tkn.size(); j++)
            {
                g[tkn[j].th].pb({{tkn[j].fr,tkn[j].sc},tkn[j].fo});
                g[tkn[j].fo].pb({{tkn[j].fr,tkn[j].sc},tkn[j].th});
            }

            mxs.insert(ed[i].sc);

            cy.clear();
            tem.clear();

            dfs(ed[i].th,0,ed[i].th);

            sort(cy.begin(),cy.end());

            if(cy.size())
            {

                int sz = cy.size();
                sz--;
                ll x1 = cy[sz].th;
                ll y1 = cy[sz].fo;

//                for(int j=0; j<cy.size(); j++)
//                    cout << cy[j].th << " " << cy[j].fo << "______ " << cy[j].first << "\n";
                int id = -1;

                mxs.erase(mxs.find(cy[sz].first));

                idx=0;

                for(idx; idx<tkn.size(); idx++)
                    if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                            &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                        break;

                if(idx!=tkn.size())
                    tkn.erase(tkn.begin()+idx);
            }
        }
        }
        set<ll>cnt;
        for(int j=1; j<=n; j++)
            cnt.insert(findp(j));

        if(cnt.size()==1)
        {
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            ll smu = *it;
            smu*=S;
            sum += smu;
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
        cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p)
        {
            cy = tem;
            cy.pb({g[u][i].sc,{u,g[u][i].second}});
        }
        tem.pb({g[u][i].sc,{u,g[u][i].second}});
        dfs(g[u][i].second,u);
        tem.pop_back();
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;

    for(i; i<m; i++)
    {
        if(ed[i].th==ed[i].fo)
            continue;

        for(int j=1; j<=n; j++)
            vis[j] = 0;

        ll x = ed[i].th,y = ed[i].fo;

        x = findp(x);
        y = findp(y);

        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }

        else
        {
            // cout << "          123 " << endl;
            int idx = -1;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;
                int id = -1;

                mxs.erase(mxs.find(tkn[idx].sc));

                tkn.erase(tkn.begin()+idx);

                mxs.insert(ed[i].sc);

                tkn.pb(ed[i]);

                continue;
            }

            for(int i=1;i<=n;i++){
                g[i].clear();
            }

            tkn.pb(ed[i]);

            for(int j=0;j<tkn.size();j++){
                g[tkn[j].th].pb({{tkn[j].fr,tkn[j].sc},tkn[j].fo});
                g[tkn[j].fo].pb({{tkn[j].fr,tkn[j].sc},tkn[j].th});
            }

            mxs.insert(ed[i].sc);

            cy.clear();
            tem.clear();

            dfs(x,0);

            sort(cy.begin(),cy.end());

            int sz = cy.size();
            sz--;
            ll x1 = cy[sz].th;
            ll y1 = cy[sz].fo;

            // cout << 1 << endl;
            int id = -1;

            mxs.erase(mxs.find(cy[sz].first));

            idx=0;

            for(idx; idx<tkn.size(); idx++)
                if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                        &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                            break;

            if(idx!=tkn.size())
                tkn.erase(tkn.begin()+idx);
        }

        set<ll>cnt;
        for(int j=1; j<=n; j++)
            cnt.insert(findp(j));

        if(cnt.size()==1)
        {
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            ll smu = *it;
            smu*=S;
            sum += smu;
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
        cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p)
        {
            cy = tem;
            cy.pb({g[i][u].sc,{u,g[u][i].second}});
        }
        tem.pb({g[u][i].sc,{u,g[u][i].second}});
        dfs(g[u][i].second,u);
        tem.pop_back();
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;
    for(int i=0; i<m; i++)
    {
        for(int i=1;i<=n;i++)
            vis[i] = 0;

        if(ed[i].th==ed[i].fo)
            continue;

        mxs.insert(ed[i].sc);

        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});

        ll x = findp(ed[i].th);
        ll y = findp(ed[i].fo);

        if(x!=y)
        {
            p[x] = y;
        }

        tkn.pb(ed[i]);

        break;
    }

    for(++i; i<m; i++)
    {
        ll x = ed[i].th,y = ed[i].fo;
        //cout << x << " " << y << " dgdgfdsf" << endl;
        x = findp(x);
        y = findp(y);
        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }
        else
        {
           // cout << "          123 " << endl;
            int idx = -1;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;
                int id = -1;
                for(int j=0; j<g[x1].size(); j++)
                {
                    if(g[x1][j].second==y1)
                        id = j;
                }
                if(id!=-1)
                    g[x1].erase(g[x1].begin()+id);

                id = -1;
                for(int j=0; j<g[y1].size(); j++)
                {
                    if(g[y1][j].second==x1)
                        id = j;
                }
                if(id!=-1)
                    g[y1].erase(g[y1].begin()+id);
                mxs.erase(mxs.find(tkn[idx].sc));
                tkn.erase(tkn.begin()+idx);
                continue;
            }

            cy.clear();
            tem.clear();

            dfs(x,0);

            sort(cy.begin(),cy.end());

            int sz = cy.size();
            sz--;
            ll x1 = cy[sz].th;
            ll y1 = cy[sz].fo;

            int id = -1;
            for(int j=0; j<g[x1].size(); j++)
            {
                if(g[x1][j].second==y1)
                    id = j;
            }
            if(id!=-1)
                g[x1].erase(g[x1].begin()+id);

            id = -1;
            for(int j=0; j<g[y1].size(); j++)
            {
                if(g[y1][j].second==x1)
                    id = j;
            }
            if(id!=-1)
                g[y1].erase(g[y1].begin()+id);

            mxs.erase(mxs.find(cy[cy.size()-1].first));

            idx=0;

            for(idx;idx<tkn.size();idx++)
                if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                   &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                    break;
            if(idx!=tkn.size())
                tkn.erase(tkn.begin()+idx);
        }
        set<ll>cnt;
        for(int j=1;j<=n;j++)
            cnt.insert(findp(j));
        if(cnt.size()==1){
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            sum += ((*it)*S);
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
    cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p)
        {
            cy = tem;
            cy.pb({g[u][i].sc,{u,g[u][i].second}});
        }
        tem.pb({g[u][i].sc,{u,g[u][i].second}});
        dfs(g[u][i].second,u);
        tem.pop_back();
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;
    for(int i=0; i<m; i++)
    {

        if(ed[i].th==ed[i].fo)
            continue;

        mxs.insert(ed[i].sc);

        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});

        ll x = findp(ed[i].th);
        ll y = findp(ed[i].fo);

        if(x!=y)
        {
            p[x] = y;
        }

        tkn.pb(ed[i]);

        break;
    }

    for(++i; i<m; i++)
    {
        if(ed[i].th==ed[i].fo)
            continue;
        for(int j=1;j<=n;j++)
            vis[j] = 0;
        ll x = ed[i].th,y = ed[i].fo;
        //cout << x << " " << y << " dgdgfdsf" << endl;
        x = findp(x);
        y = findp(y);
        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});
        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }
        else
        {
           // cout << "          123 " << endl;
            int idx = -1;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;
                int id = -1;
                for(int j=0; j<g[x1].size(); j++)
                {
                    if(g[x1][j].second==y1)
                        id = j;
                }
                if(id!=-1)
                    g[x1].erase(g[x1].begin()+id);

                id = -1;
                for(int j=0; j<g[y1].size(); j++)
                {
                    if(g[y1][j].second==x1)
                        id = j;
                }
                if(id!=-1)
                    g[y1].erase(g[y1].begin()+id);
                mxs.erase(mxs.find(tkn[idx].sc));
                tkn.erase(tkn.begin()+idx);
                continue;
            }

            cy.clear();
            tem.clear();

            dfs(x,0);

            sort(cy.begin(),cy.end());

            int sz = cy.size();
            sz--;
            ll x1 = cy[sz].th;
            ll y1 = cy[sz].fo;

           // cout << 1 << endl;
            int id = -1;
            for(int j=0; j<g[x1].size(); j++)
            {
                if(g[x1][j].second==y1)
                    id = j;
            }
            if(id!=-1)
                g[x1].erase(g[x1].begin()+id);

            id = -1;
            for(int j=0; j<g[y1].size(); j++)
            {
                if(g[y1][j].second==x1)
                    id = j;
            }
            if(id!=-1)
                g[y1].erase(g[y1].begin()+id);

            mxs.erase(mxs.find(cy[cy.size()-1].first));

            idx=0;

            for(idx;idx<tkn.size();idx++)
                if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                   &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                    break;
            if(idx!=tkn.size())
                tkn.erase(tkn.begin()+idx);
        }
        set<ll>cnt;
        for(int j=1;j<=n;j++)
            cnt.insert(findp(j));
        if(cnt.size()==1){
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            ll smu = *it;
            smu*=S;
            sum += smu;
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
    cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p)
        {
            cy = tem;
            cy.pb({g[i][u].sc,{u,g[u][i].second}});
        }
        tem.pb({g[u][i].sc,{u,g[u][i].second}});
        dfs(g[u][i].second,u);
        tem.pop_back();
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;
    for(int i=0; i<m; i++)
    {
        for(int i=1;i<=n;i++)
            vis[i] = 0;

        if(ed[i].th==ed[i].fo)
            continue;

        mxs.insert(ed[i].sc);

        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});

        ll x = findp(ed[i].th);
        ll y = findp(ed[i].fo);

        if(x!=y)
        {
            p[x] = y;
        }

        tkn.pb(ed[i]);

        break;
    }

    for(++i; i<m; i++)
    {
        ll x = ed[i].th,y = ed[i].fo;
        //cout << x << " " << y << " dgdgfdsf" << endl;
        x = findp(x);
        y = findp(y);
        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});
        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }
        else
        {
           // cout << "          123 " << endl;
            int idx = -1;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;
                int id = -1;
                for(int j=0; j<g[x1].size(); j++)
                {
                    if(g[x1][j].second==y1)
                        id = j;
                }
                if(id!=-1)
                    g[x1].erase(g[x1].begin()+id);

                id = -1;
                for(int j=0; j<g[y1].size(); j++)
                {
                    if(g[y1][j].second==x1)
                        id = j;
                }
                if(id!=-1)
                    g[y1].erase(g[y1].begin()+id);
                mxs.erase(mxs.find(tkn[idx].sc));
                tkn.erase(tkn.begin()+idx);
                continue;
            }

            cy.clear();
            tem.clear();

            dfs(x,0);

            sort(cy.begin(),cy.end());

            int sz = cy.size();
            sz--;
            ll x1 = cy[sz].th;
            ll y1 = cy[sz].fo;

           // cout << 1 << endl;
            int id = -1;
            for(int j=0; j<g[x1].size(); j++)
            {
                if(g[x1][j].second==y1)
                    id = j;
            }
            if(id!=-1)
                g[x1].erase(g[x1].begin()+id);

            id = -1;
            for(int j=0; j<g[y1].size(); j++)
            {
                if(g[y1][j].second==x1)
                    id = j;
            }
            if(id!=-1)
                g[y1].erase(g[y1].begin()+id);

            mxs.erase(mxs.find(cy[cy.size()-1].first));

            idx=0;

            for(idx;idx<tkn.size();idx++)
                if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                   &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                    break;
            if(idx!=tkn.size())
                tkn.erase(tkn.begin()+idx);
        }
        set<ll>cnt;
        for(int j=1;j<=n;j++)
            cnt.insert(findp(j));
        if(cnt.size()==1){
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            sum += ((*it)*S);
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
    cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p)
        {
            cy = tem;
            cy.pb({g[i][u].sc,{u,g[u][i].second}});
        }
        tem.pb({g[i][u].sc,{u,g[u][i].second}});
        dfs(g[u][i].second,u);
        tem.pop_back();
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;
    for(int i=0; i<m; i++)
    {
        for(int i=1;i<=n;i++)
            vis[i] = 0;

        if(ed[i].th==ed[i].fo)
            continue;

        mxs.insert(ed[i].sc);

        g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
        g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});

        ll x = findp(ed[i].th);
        ll y = findp(ed[i].fo);

        if(x!=y)
        {
            p[x] = y;
        }

        tkn.pb(ed[i]);

        break;
    }

    for(++i; i<m; i++)
    {
        ll x = ed[i].th,y = ed[i].fo;
        //cout << x << " " << y << " dgdgfdsf" << endl;
        x = findp(x);
        y = findp(y);
        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }
        else
        {
           // cout << "          123 " << endl;
            int idx = -1;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;
                int id = -1;
                for(int j=0; j<g[x1].size(); j++)
                {
                    if(g[x1][j].second==y1)
                        id = j;
                }
                if(id!=-1)
                    g[x1].erase(g[x1].begin()+id);

                id = -1;
                for(int j=0; j<g[y1].size(); j++)
                {
                    if(g[y1][j].second==x1)
                        id = j;
                }
                if(id!=-1)
                    g[y1].erase(g[y1].begin()+id);
                mxs.erase(mxs.find(tkn[idx].sc));
                tkn.erase(tkn.begin()+idx);
                continue;
            }

            cy.clear();
            tem.clear();

            dfs(x,0);

            sort(cy.begin(),cy.end());

            ll x1 = cy[cy.size()-1].th;
            ll y1 = cy[cy.size()-1].fo;

            int id = -1;
            for(int j=0; j<g[x1].size(); j++)
            {
                if(g[x1][j].second==y1)
                    id = j;
            }
            if(id!=-1)
                g[x1].erase(g[x1].begin()+id);

            id = -1;
            for(int j=0; j<g[y1].size(); j++)
            {
                if(g[y1][j].second==x1)
                    id = j;
            }
            if(id!=-1)
                g[y1].erase(g[y1].begin()+id);

            mxs.erase(mxs.find(cy[cy.size()-1].first));

            idx=0;

            for(idx;idx<tkn.size();idx++)
                if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                   &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                    break;
            if(idx!=tkn.size())
                tkn.erase(tkn.begin()+idx);
        }
        set<ll>cnt;
        for(int j=1;j<=n;j++)
            cnt.insert(findp(j));
        if(cnt.size()==1){
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            sum += ((*it)*S);
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
    cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p,ll st)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p&&g[u][i].second==st)
        {
            cy = tem;
            cy.pb({g[u][i].sc,{u,g[u][i].second}});
            return;
        }
        if(!vis[g[u][i].second])
        {
            tem.pb({g[u][i].sc,{u,g[u][i].second}});
            dfs(g[u][i].second,u,st);
            tem.pop_back();
        }
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;

    for(i; i<m; i++)
    {
        if(ed[i].th==ed[i].fo)
            continue;

        for(int j=1; j<=n; j++)
            vis[j] = 0;

        ll x = ed[i].th,y = ed[i].fo;

        x = findp(x);
        y = findp(y);

        if(x!=y)
        {
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }

        else
        {
            int idx = -1;
            bool f=0;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                    f = 1;
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;

                mxs.erase(mxs.find(tkn[idx].sc));

                tkn.erase(tkn.begin()+idx);

                mxs.insert(ed[i].sc);

                tkn.pb(ed[i]);

            }
            else{
            if(f)
                continue;

            for(int i=1; i<=n; i++)
            {
                g[i].clear();
            }

            tkn.pb(ed[i]);

            for(int j=0; j<tkn.size(); j++)
            {
                g[tkn[j].th].pb({{tkn[j].fr,tkn[j].sc},tkn[j].fo});
                g[tkn[j].fo].pb({{tkn[j].fr,tkn[j].sc},tkn[j].th});
            }

            mxs.insert(ed[i].sc);

            cy.clear();
            tem.clear();

            dfs(x,0,x);

            sort(cy.begin(),cy.end());

            if(cy.size())
            {

                int sz = cy.size();
                sz--;
                ll x1 = cy[sz].th;
                ll y1 = cy[sz].fo;

//                for(int j=0; j<cy.size(); j++)
//                    cout << cy[j].th << " " << cy[j].fo << "______ " << cy[j].first << "\n";

                int id = -1;

                mxs.erase(mxs.find(cy[sz].first));

                idx=0;

                for(idx; idx<tkn.size(); idx++)
                    if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                            &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                        break;

                if(idx!=tkn.size())
                    tkn.erase(tkn.begin()+idx);
            }
        }
        }
        set<ll>cnt;
        for(int j=1; j<=n; j++)
            cnt.insert(findp(j));

        if(cnt.size()==1)
        {
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            ll smu = *it;
            smu*=S;
            sum += smu;
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
        cout << ans << "\n";
    else
        cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define bye ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first.first
#define th second.first
#define sc first.second
#define fo second.second
#define MOD (ll)(998244353)

ll n,m,G,S,p[200200];
vector<pair<pair<ll,ll>,ll > >g[200200];
vector<pair<pair<ll,ll>,pair<ll,ll> > >ed,tkn;
vector<pair<ll,pair<ll,ll> > >cy,tem;
ll ans = 1e18;
bool flag = 0;
bool vis[220];

ll findp(ll u)
{
    if(p[u]==u)
        return u;
    return p[u] = findp(p[u]);
}

void dfs(ll u,ll p)
{
    if(vis[u])
        return;
    vis[u] = 1;
    for(int i=0; i<g[u].size(); i++)
    {
        if(vis[g[u][i].second]&&g[u][i].second!=p)
        {
            cy = tem;
            cy.pb({g[u][i].sc,{u,g[u][i].second}});
        }
        tem.pb({g[u][i].sc,{u,g[u][i].second}});
        dfs(g[u][i].second,u);
        tem.pop_back();
    }
}

int main()
{
    bye

    cin >> n >> m >> G >> S;

    for(int i=1; i<=n; i++)
        p[i]=i;

    for(int i=0; i<m; i++)
    {
        ll x,y,z,u;
        cin >> x >> y >> z >> u;

        ed.pb({{z,u},{x,y}});

    }

    sort(ed.begin(),ed.end());

    multiset<ll>mxs;

    int i=0;

    for(i; i<m; i++)
    {
        if(ed[i].th==ed[i].fo)
            continue;

        for(int j=1; j<=n; j++)
            vis[j] = 0;

        ll x = ed[i].th,y = ed[i].fo;

        x = findp(x);
        y = findp(y);

        if(x!=y)
        {
            g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
            g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});
            tkn.pb(ed[i]);
            p[x] = y;
            mxs.insert(ed[i].sc);
        }

        else
        {
            // cout << "          123 " << endl;
            int idx = -1;
            for(int j=0; j<tkn.size(); j++)
            {
                if(max(ed[i].th,ed[i].fo)==max(tkn[j].th,tkn[j].fo)
                        && min(ed[i].th,ed[i].fo)==min(tkn[j].th,tkn[j].fo))
                {
                    if(ed[i].sc<tkn[j].sc)
                    {
                        idx = j;
                        break;
                    }
                }
            }
            if(idx!=-1)
            {
                ll x1 = tkn[idx].th;
                ll y1 = tkn[idx].fo;
                int id = -1;
                for(int j=0; j<g[x1].size(); j++)
                {
                    if(g[x1][j].second==y1)
                        id = j;
                }
                if(id!=-1)
                    g[x1].erase(g[x1].begin()+id);

                id = -1;
                for(int j=0; j<g[y1].size(); j++)
                {
                    if(g[y1][j].second==x1)
                        id = j;
                }
                if(id!=-1)
                    g[y1].erase(g[y1].begin()+id);

                mxs.erase(mxs.find(tkn[idx].sc));

                tkn.erase(tkn.begin()+idx);

                g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
                g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});
                mxs.insert(ed[i].sc);

                continue;
            }

            g[ed[i].th].pb({{ed[i].fr,ed[i].sc},ed[i].fo});
            g[ed[i].fo].pb({{ed[i].fr,ed[i].sc},ed[i].th});
            mxs.insert(ed[i].sc);

            cy.clear();
            tem.clear();

            dfs(x,0);

            sort(cy.begin(),cy.end());

            int sz = cy.size();
            sz--;
            ll x1 = cy[sz].th;
            ll y1 = cy[sz].fo;

            // cout << 1 << endl;
            int id = -1;
            for(int j=0; j<g[x1].size(); j++)
            {
                if(g[x1][j].second==y1){
                    id = j;
                    break;
                }
            }
            if(id!=-1)
                g[x1].erase(g[x1].begin()+id);

            id = -1;
            for(int j=0; j<g[y1].size(); j++)
            {
                if(g[y1][j].second==x1){
                    id = j;
                    break;
                }
            }

            if(id!=-1)
                g[y1].erase(g[y1].begin()+id);

            mxs.erase(mxs.find(cy[sz].first));

            idx=0;

            for(idx; idx<tkn.size(); idx++)
                if(max(tkn[idx].th,tkn[idx].fo) == max(x1,y1)
                        &&min(tkn[idx].th,tkn[idx].fo) == min(x1,y1))
                            break;

            if(idx!=tkn.size())
                tkn.erase(tkn.begin()+idx);
        }

        set<ll>cnt;
        for(int j=1; j<=n; j++)
            cnt.insert(findp(j));

        if(cnt.size()==1)
        {
            ll sum = ed[i].fr*G;
            multiset<ll>::iterator it = mxs.end();
            it--;
            ll smu = *it;
            smu*=S;
            sum += smu;
            ans = min(ans,sum);
            flag = 1;
        }
    }

    if(flag)
        cout << ans << "\n";
    else
        cout << -1;
    return 0;
}