#include <bits/stdc++.h>   using std::map;   using std::max;   using std::min;   using std::set;   using std::string;   using std::vector;   constexpr long long magic_mod = 1000000007;   constexpr long long big = 1ll << 60;   struct Matrix {     long long size;     vector<long long> f;     Matrix(long long size, long long start_value = big)         : size(size), f(size * size, start_value) {}     Matrix(const Matrix& o) { *this = o; };     static vector<Matrix> cache;     inline long long& m(long long a, long long b) { return f[a * size + b]; }     inline const long long& m(long long a, long long b) const {       return f[a * size + b];     }     void print() {       for (long long i = 0; i < size; ++i) {         for (long long j = 0; j < size; ++j) {           std::cout << m(j, i) <<    ;         }         std::cout << std::endl;       }     }     void operator=(const Matrix& o) {       this->size = o.size;       this->f = o.f;     }     Matrix operator*(const Matrix& o) const {       Matrix res(size);       for (long long i = 0; i < size; ++i) {         for (long long j = 0; j < size; ++j) {           for (long long k = 0; k < size; ++k) {             res.m(i, j) = min(res.m(i, j), m(k, j) + o.m(i, k));           }         }       }       return res;     }     Matrix get_pow(long long p) {       Matrix res(*this);       bool inited = false;       for (long long i = 1;; ++i) {         if (!p) {           break;         }         if (p % 2) {           if (!inited) {             res = cache[i];             inited = true;           } else {             res = res * cache[i];           }         }         p /= 2;       }       return res;     }     void fill_cache();   };   const long long xxxx = 40;   vector<Matrix> Matrix::cache;   void Matrix::fill_cache() {     cache = vector<Matrix>(xxxx, Matrix(size));     Matrix res(*this);     for (long long i = 1; i < xxxx; ++i) {       cache[i] = res;       res = res * res;     }   }   vector<long long> standings;   vector<long long> jw;   long long sn;   map<long long, long long> magic_stones;   inline long long btc(long long x) {     long long res = 0;     while (x) {       if (x % 2) ++res;       x /= 2;     }     return res;   }   long long get_index(long long standing) {     for (long long i = 0; i < standings.size(); ++i) {       if (standings[i] == standing) return i;     }     std::cerr <<  WTF, INVALID STANDING   << standing << std::endl;     return -1;   }   void CalcJmpMatrix(Matrix& jumpm, long long pos = -1) {     for (long long i = 0; i < standings.size(); ++i) {       long long ss = standings[i];       long long smallest = 1;       while ((ss & smallest) == 0) smallest *= 2;       for (long long j = 0; j < jw.size(); ++j) {         long long ns = ss;         ns &= ~smallest;         if (ns & (smallest << j)) continue;         ns |= smallest << j;         if ((ns & 1) == 0 && ns < (1 << jw.size())) {           auto& x = jumpm.m(i, get_index(ns >> 1));           long long aw = 0;           if (pos >= 0 && j != 0) {             long long pos2 = pos;             long long sm2 = smallest >> 1;             while (sm2) {               ++pos2;               sm2 /= 2;             }             pos2 += j;             if (magic_stones.find(pos2) != magic_stones.end()) {               aw = magic_stones[pos2];             }           }           x = min(x, (long long)jw[j] + aw);         }       }     }   }   vector<long long> mul(const vector<long long>& x, const Matrix& m) {     vector<long long> res(sn, big);     for (long long i = 0; i < sn; ++i) {       for (long long j = 0; j < sn; ++j) {         res[i] = min(res[i], x[j] + m.m(j, i));       }     }     return res;   }   void print_state(long long pos, vector<long long>& res) {}   int main() {     long long x, k, n, q;     scanf( %lld%lld%lld%lld , &x, &k, &n, &q);     jw = vector<long long>(k + 1, 0);     for (long long i = 1; i <= k; ++i) scanf( %lld , &(jw[i]));     for (long long i = 0; i < q; ++i) {       long long p, pw;       scanf( %lld%lld , &p, &pw);       magic_stones[p - 1] = pw;     }     for (long long i = 0; i < (1 << k); ++i) {       if (btc(i) == x) {         standings.push_back(i);       }     }     sn = standings.size();     Matrix jumpm(sn);     CalcJmpMatrix(jumpm);     jumpm.fill_cache();     vector<long long> res(sn, big);     res[0] = 0;     long long cp = 0;     long long des_pos = n - x;     print_state(cp, res);     for (auto ms : magic_stones) {       if (ms.first == cp) continue;       if (ms.first - k > cp) {         res = mul(res, jumpm.get_pow(ms.first - k - cp));         cp = ms.first - k;         print_state(cp, res);       }       for (; cp < ms.first && cp < des_pos;) {         Matrix msm(sn);         CalcJmpMatrix(msm, cp);         res = mul(res, msm);         ++cp;         print_state(cp, res);       }     }     if (cp < des_pos) {       res = mul(res, jumpm.get_pow(des_pos - cp));       cp = des_pos;       print_state(cp, res);     }     print_state(cp, res);     std::cout << res[0] << std::endl;   }