[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
d = inta rray of size 30
t = int array of size 7
ne, me = int
n, m = int
in function check returning a bool
    tn = int with tn = 0
    b = int with b = 1
    for i = 0 to ne
        add t[i] * b to tn
        set b to b * 7
    end of the block
    set b to 1
    tm = int with tm = 0
    for i = ne to me
        add t[i] * b to tm
        set b to b * 7
    end of the block
    return tn is less or equal to n and tm is less or equal to m
end of the block
ans = int with ans = 0
in function dfs0 taking an int p
    if p is greater or equal to me
        add value of check to ans
        return
    end of the block
    for i = p to me
        call swap on t[p] and t[i]
        call dfs0 on p + 1
        call swap on t[p] and t[i]
    end of the block
end of the block
in function dfs1
    for s = 1 bitshift left 7 - 1 decrement s while s is greater than 0
        cnt = int with cnt = 0
        for j = 0 to 7
            if s bitshift right j bitwise-and 1 is true then set t[cnt] to j then increment cnt
        end of the block
        if cnt equals me then call dfs0 of 0
    end of the block
end of the block
define the main function
    read n then m
    decrement n
    decrement m
    set ne to 0
    dn, dm = int with dn = n and dm = m
    if dn equals 0
        increment ne
    else
        loop while dn is not 0
            set d[ne] to dn mod 7 then increment ne
            set dn to dn / 7
        end of the block
    end of the block
    set me to ne
    if dm equals 0
        increment me
    else
        while dm is not 0
            set d[me) to dm mod 7 then increment me
            set dm to dm / 7
        end of the block
    end of the block
    if me is greater than 7
        print 0
    else
        call dfs1
        print ans
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int d[30];
int t[7];
int ne, me;
int n, m;
bool check() {
    int tn = 0;
    int b = 1;
    for (int i = 0; i < ne; i++) {
        tn += t[i] * b;
        b *= 7;
    }
    b = 1;
    int tm = 0;
    for (int i = ne; i < me; i++) {
        tm += t[i] * b;
        b *= 7;
    }
    return (tn <= n && tm <= m);
}
int ans = 0;
void dfs0(int p) {
    if (p >= me) {
        ans += check();
        return;
    }
    for (int i = p; i < me; i++) {
        swap(t[p], t[i]);
        dfs0(p + 1);
        swap(t[p], t[i]);
    }
}
void dfs1() {
    for (int s = (1 << 7) - 1; s > 0; s--) {
        int cnt = 0;
        for (int j = 0; j < 7; j++) {
            if ((s >> j) & 1) { t[cnt++] = j; }
        }
        if (cnt == me) { dfs0(0); }
    }
}
int main() {
    cin >> n >> m;
    n--;
    m--;
    ne = 0;
    int dn = n, dm = m;
    if (dn == 0) {
        ne++;
    } else {
        while (dn) {
            d[ne++] = dn % 7;
            dn /= 7;
        }
    }
    me = ne;
    if (dm == 0) {
        me++;
    } else {
        while (dm) {
            d[me++] = dm % 7;
            dm /= 7;
        }
    }
    if (me > 7) {
        cout << 0 << endl;
    } else {
        dfs1();
        cout << ans << endl;
    }
    return 0;
}