#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int b,p,d,n;
cin >> b >> p >> d >> n;
int las = 0;
multiset<array<int,2>>s;
s.insert({0,0});
int delta = 0;
while(n--){
int a;
cin >> a;
///merge las-a range into dp
int len = a-las-1;
int base = (len/p)*d;
int tillpos = p-len%p;
///add base to starting point delta.
if(base){
s.insert({0,base});
}
///now make range tillpos-p in this shifted version
///(tillpos+delta)%p -> delta
tillpos-=delta;
tillpos%=p;
tillpos+=p;
tillpos%=p;
int tillneg = p-delta;
tillneg%=p;
tillneg+=p;
tillneg%=p;
if(tillneg>tillpos){
///one single range
auto it1 = s.lower_bound({tillpos,-inf});
auto it2 = s.lower_bound({tillneg,-inf});
if(it1==it2){
//nothing happens
}
else{
array<int,2>ol = (*it1);
ol[1]+=d;
s.erase(it1);
if(ol[1]<0){
s.insert(ol);
}
s.insert({tillneg,-d});
}
}
else{
///prefix and suffix
s.insert({0,d});
s.insert({tillneg,-d});
auto it1 = s.lower_bound({tillpos,-inf});
if(it1==s.end()){
//do nothing
}
else{
array<int,2>ol = (*it1);
ol[1]+=d;
s.erase(it1);
if(ol[1]<0){
s.insert(ol);
}
}
}
//shift
delta += (len+1)%p;
delta%=p;
las=a;
}
int a=b;
///merge las-a range into dp
int len = a-las-1;
int base = (len/p)*d;
int tillpos = p-len%p;
///add base to starting point delta.
if(base){
s.insert({0,base});
}
///now make range tillpos-p in this shifted version
///(tillpos+delta)%p -> delta
tillpos-=delta;
tillpos%=p;
tillpos+=p;
tillpos%=p;
int tillneg = p-delta;
tillneg%=p;
tillneg+=p;
tillneg%=p;
if(tillneg>tillpos){
///one single range
auto it1 = s.lower_bound({tillpos,-inf});
auto it2 = s.lower_bound({tillneg,-inf});
if(it1==it2){
//nothing happens
}
else{
array<int,2>ol = (*it1);
ol[1]+=d;
s.erase(it1);
if(ol[1]<0){
s.insert(ol);
}
s.insert({tillneg,-d});
}
}
else{
///prefix and suffix
s.insert({0,d});
s.insert({tillneg,-d});
auto it1 = s.lower_bound({tillpos,-inf});
if(it1==s.end()){
//do nothing
}
else{
array<int,2>ol = (*it1);
ol[1]+=d;
s.erase(it1);
if(ol[1]<0){
s.insert(ol);
}
}
}
//shift
delta += (len+1)%p;
delta%=p;
las=a;
int curr = 0;
int ans = inf;
las = 0;
for(array<int,2>a:s){
if(las!=a[0])
ans=min(ans,curr);
curr+=a[1];
curr+=(a[0]-las);
las=a[0];
}
ans=min(ans,curr);
ans+=b;
cout << ans;
return 0;
}