#include <stdio.h>
#include <bits/stdc++.h>

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder

using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000

long long get(int h,int m,vector<int> x){
	vector<string> S(h,string(7,'0'));
	rep(i,7*h){
		if(binary_search(x.begin(),x.end(),i%m)){
			S[i/7][i%7]='1';
		}
	}
	dsu D(h*7);
	
	rep(i,h){
		rep(j,7){
			if(i!=h-1){
				if(S[i][j]=='0'&&S[i+1][j]=='0'){
					D.merge(i*7+j,(i+1)*7+j);
				}
			}
			if(j!=6){
				if(S[i][j]=='0'&&S[i][j+1]=='0'){
					D.merge(i*7+j,i*7+j+1);
				}
			}
		}
	}
	long long ret = 0LL;
	rep(i,h){
		rep(j,7){
			if(S[i][j]=='1')continue;
			if(D.leader(i*7+j)==i*7+j)ret++;
		}
	}
	return ret;
	
}

int main(){
	
	long long n,m,q;
	cin>>n>>m>>q;
	vector<int> a(q);
	rep(i,q)cin>>a[i];
	
	long long ans = 0LL;
	if(n<=m){
		ans = get(n,m,a);
	}
	else{
		ans = get(m,m,a);
		n -= m;
		ans += n/m * (get(2*m,m,a)-get(m,m,a));
		n %= m;
		ans += get(m+n,m,a) - get(m,m,a);
	}
	cout<<ans<<endl;
	
    return 0;
}


### Prompt

Your task is to create a CPP solution to the following problem:

Input Format

The input format is following:



n m q
a_1 a_2 ... a_q


Output Format

Print the number of connected part in one line.


Constraints

* n ≤ 10^{12}
* 7n is divisible by m.
* 1 ≤ q ≤ m ≤ 10^5
* 0 ≤ a_1 < a_2 < ... < a_q < m



Scoring

Subtask 1 [100 points]


* n ≤ 100000.

Subtask 2 [90 points]


* m is divisible by 7.
* a_{i + 1} - a_i = 1.

Subtask 3 [200 points]


* m is divisible by 7.

Subtask 4 [110 points]


* There are no additional constraints.



Sample Input 1


7 7 3
1 3 5


Sample Output 1


4


The calendar looks like this:


<image>

Sample Input 2


10 14 8
5 6 7 8 9 10 11 12


Sample Output 2


10


The calendar looks like this:


<image>

Output Format

Print the number of connected part in one line.


Constraints

* n ≤ 10^{12}
* 7n is divisible by m.
* 1 ≤ q ≤ m ≤ 10^5
* 0 ≤ a_1 < a_2 < ... < a_q < m



Scoring

Subtask 1 [100 points]


* n ≤ 100000.

Subtask 2 [90 points]


* m is divisible by 7.
* a_{i + 1} - a_i = 1.

Subtask 3 [200 points]


* m is divisible by 7.

Subtask 4 [110 points]


* There are no additional constraints.

Input Format

The input format is following:



n m q
a_1 a_2 ... a_q

Examples

Input

7 7 3
1 3 5


Output

4


Input

10 14 8
5 6 7 8 9 10 11 12


Output

10

### Response

```cpp
#include <stdio.h>
#include <bits/stdc++.h>

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
  public:
    dsu() : _n(0) {}
    dsu(int n) : _n(n), parent_or_size(n, -1) {}

    int merge(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y) return x;
        if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b) {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a) {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0) return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a) {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    std::vector<std::vector<int>> groups() {
        std::vector<int> leader_buf(_n), group_size(_n);
        for (int i = 0; i < _n; i++) {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        std::vector<std::vector<int>> result(_n);
        for (int i = 0; i < _n; i++) {
            result[i].reserve(group_size[i]);
        }
        for (int i = 0; i < _n; i++) {
            result[leader_buf[i]].push_back(i);
        }
        result.erase(
            std::remove_if(result.begin(), result.end(),
                           [&](const std::vector<int>& v) { return v.empty(); }),
            result.end());
        return result;
    }

  private:
    int _n;
    // root node: -1 * component size
    // otherwise: parent
    std::vector<int> parent_or_size;
};

}  // namespace atcoder

using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000

long long get(int h,int m,vector<int> x){
	vector<string> S(h,string(7,'0'));
	rep(i,7*h){
		if(binary_search(x.begin(),x.end(),i%m)){
			S[i/7][i%7]='1';
		}
	}
	dsu D(h*7);
	
	rep(i,h){
		rep(j,7){
			if(i!=h-1){
				if(S[i][j]=='0'&&S[i+1][j]=='0'){
					D.merge(i*7+j,(i+1)*7+j);
				}
			}
			if(j!=6){
				if(S[i][j]=='0'&&S[i][j+1]=='0'){
					D.merge(i*7+j,i*7+j+1);
				}
			}
		}
	}
	long long ret = 0LL;
	rep(i,h){
		rep(j,7){
			if(S[i][j]=='1')continue;
			if(D.leader(i*7+j)==i*7+j)ret++;
		}
	}
	return ret;
	
}

int main(){
	
	long long n,m,q;
	cin>>n>>m>>q;
	vector<int> a(q);
	rep(i,q)cin>>a[i];
	
	long long ans = 0LL;
	if(n<=m){
		ans = get(n,m,a);
	}
	else{
		ans = get(m,m,a);
		n -= m;
		ans += n/m * (get(2*m,m,a)-get(m,m,a));
		n %= m;
		ans += get(m+n,m,a) - get(m,m,a);
	}
	cout<<ans<<endl;
	
    return 0;
}


```