[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]:
SevenPows = integer array which includes = 0, 7, 49, 343, 2401, 16807, 117649
visited = bool array of size 8
N, M, dh, dm = integers
in the function Judge that includes integers h and m and returns bool
    fill from visited to visited + 8 with false
    for i = 0 to dm exclusive
        if visited[m modulo 7], return false
        visited[m modulo 7] = true
        m = m / 7
    end of the block
    for i = 0 to dh exclusiv
        if visited[h modulo 7], return false
        visited[h modulo 7] = true
        h = h / 7
    end of the block
    return true
end of the block
define the main function
    i, j = integer
    read N, M
    for i = 0 to 6
        if N <= SevenPows[i]
            dh = i
            break loop
        end of the block
    end of the block
    if i is 7
        print 0
        return to indicate successful execution
    end of the block
    for i = 0 to 6
        if M <= SevenPows[i]
            dm = i
            break loop
        end of the block
    end of the block
    if i is 7
        print 0
        return to indicate successful execution
    end of the block
    ans = integer with ans = 0
    for i = 0 to N exclusive
        for j = 0 to M exclusive
            if Judge(i, j), increment ans
        end of the block
    end of the block
    print ans
    return to indicate successful execution
end of the block

[CODE]:

int SevenPows[] = {0, 7, 49, 343, 2401, 16807, 117649};
bool visited[8];
int N, M, dh, dm;
bool Judge(int h, int m) {
    fill(visited, visited + 8, false);
    for (int i = 0; i < dm; ++i) {
        if (visited[m % 7]) return false;
        visited[m % 7] = true;
        m /= 7;
    }
    for (int i = 0; i < dh; ++i) {
        if (visited[h % 7]) return false;
        visited[h % 7] = true;
        h /= 7;
    }
    return true;
}
int main() {
    int i, j;
    cin >> N >> M;
    for (i = 0; i < 7; ++i) {
        if (N <= SevenPows[i]) {
            dh = i;
            break;
        }
    }
    if (i == 7) {
        cout << 0 << endl;
        return 0;
    }
    for (i = 0; i < 7; ++i) {
        if (M <= SevenPows[i]) {
            dm = i;
            break;
        }
    }
    if (i == 7) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for (i = 0; i < N; ++i) {
        for (j = 0; j < M; ++j) {
            if (Judge(i, j)) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


[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]:
n, m = integers
la, lb = integers both with value of 1
vis = integer array of length 10
ans = integer with value o f0
in function dfs2 that returns nothing and takes arguments k, num = integers
    if k equals lb
        add 1 to ans
        return
    end of the block
    for i = 0 to 6 inclusive
        if vis[i] equals 0 and num * 7 + i is less than m
            set vis[i] to 1
            call dfs2 with arguments k+1 and num*7+i
            set vis[i] to 0
        end of the block
    end of the block
end of the block
in function dfs1 that returns nothing and take arguments k, num = integer
    if k equals la
        call dfs2 with arguments 0 and 0
        return
    end of the block
    for i = 0 to 6 inclusive
        if vis[i] equals 0 and num*7+i is less than n
            set vis[i] to 1
            call dfs1 with arguments k+1 and num*7+i
            set vis[i] to 0
        end of the block
    end of the block
end of the block
define the main function
    read n and m
    fn, fm = integers with fn value of n and fm value of m
    if n is greater than 0 subtract 1 from n
    if m is greater than 0 subtract 1 from m
    while n/7
        add 1 to la
        set n to n/7
    end of the block
    while m/7
        add 1 to lb
        set m to m/7
    end of the block
    set n to fn and m to fm
    if la+lb is greater than 7
        print 0
        return to indicate successful execution
    end of the block
    call dfs1 with argument of 0 and 0
    print ans
    return to indicate successful execution
end of the block

[CODE]:

int n, m;
int la = 1, lb = 1;
int vis[10];
int ans = 0;
void dfs2(int k, int num) {
    if (k == lb) {
        ans++;
        return;
    }
    for (int i = 0; i <= 6; i++) {
        if (vis[i] == 0 && num * 7 + i < m) {
            vis[i] = 1;
            dfs2(k + 1, num * 7 + i);
            vis[i] = 0;
        }
    }
}
void dfs1(int k, int num) {
    if (k == la) {
        dfs2(0, 0);
        return;
    }
    for (int i = 0; i <= 6; i++) {
        if (vis[i] == 0 && num * 7 + i < n) {
            vis[i] = 1;
            dfs1(k + 1, num * 7 + i);
            vis[i] = 0;
        }
    }
}
int main() {
    cin >> n >> m;
    int fn = n, fm = m;
    if (n > 0) n--;
    if (m > 0) m--;
    while (n / 7) {
        la++;
        n /= 7;
    }
    while (m / 7) {
        lb++;
        m /= 7;
    }
    n = fn, m = fm;
    if (la + lb > 7) {
        cout << 0 << endl;
        return 0;
    }
    dfs1(0, 0);
    cout << ans << endl;
    return 0;
}


[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]:
let n, m be integers
used = bool array of size 7
counter, digitn, digitm = integers with counter = 0, digitn = 0, and digitm = 0
in the function checkh that takes integer x and return bool
    if x is greater than or equal to 0 and x is less than n, then return true
    return false
end of the block
in the function checkm that takes integer x and return bool
    if x is greater than or equal to 0 and x is less than m, then return true
    return false
end of the block
in the function permutem that takes integers a, number
    if number is equal to digitm
        if call checkm with argument a is true, then increment counter
        return
    end of the block
    for i = 0 to 7 exclusive
        if not used[i]
            set used[i] to true
            call permutem with arguments a * 7 + i, number + 1
            set used[i] to false
        end of the block
end of the block
in the function permuteh that takes integers a, number
    if number is equal to digitn
        if call checkh with argument a is true, then call permutem with arguments 0, 0
        return
    end of the block
    for i = 0 to 7 exclusive
        if not used[i]
            set used[i] to true
            call permuteh with arguments a * 7 + i, number + 1
            set used[i] to false
        end of the block
end of the block
define the main function
    read n, m
    faken = integer = n - 1, fakem = integer = m - 1
    if n is equal to 1, then assign 1 to faken
    if m is equal to 1, then assign 1 to fakem
    while faken is greater than 0
        assign faken / 7 to faken
        increment digitn
    end of the block
    while fakem is greater than 0
        assign fakem / 7 to fakem
        increment digitm
    end of the block
    if the sum of digitn and digitm is greater than 7
        output 0
    else
        call permuteh with arguments 0, 0
        output counter
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int n, m;
bool used[7];
int counter = 0, digitn = 0, digitm = 0;
bool checkh(int x) {
    if (x >= 0 && x < n) return true;
    return false;
}
bool checkm(int x) {
    if (x >= 0 && x < m) return true;
    return false;
}
void permutem(int a, int number) {
    if (number == digitm) {
        if (checkm(a)) counter++;
        return;
    }
    for (int i = 0; i < 7; i++)
        if (!used[i]) {
            used[i] = true;
            permutem(a * 7 + i, number + 1);
            used[i] = false;
        }
}
void permuteh(int a, int number) {
    if (number == digitn) {
        if (checkh(a)) permutem(0, 0);
        return;
    }
    for (int i = 0; i < 7; i++)
        if (!used[i]) {
            used[i] = true;
            permuteh(a * 7 + i, number + 1);
            used[i] = false;
        }
}
int main() {
    cin >> n >> m;
    int faken = n - 1, fakem = m - 1;
    if (n == 1) faken = 1;
    if (m == 1) fakem = 1;
    while (faken > 0) {
        faken /= 7;
        digitn++;
    }
    while (fakem > 0) {
        fakem /= 7;
        digitm++;
    }
    if (digitn + digitm > 7)
        cout << 0 << "\n";
    else {
        permuteh(0, 0);
        cout << counter << "\n";
    }
    return 0;
}


[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]:
find_len is a long long function with long long argument num
    create long long l = 1
    for a = 7 to num exclusive multiplying a by 7, add 1 to l
    return l
end of the block
define the main function
    declare long longs n, m, x, y, res, i and j
    read n and m
    change x to find_len(n)
    change y to find_len(m)
    change res to 0
    if x + y <= 7
        for i from 0 to n exclusive
            for j from 0 to m exclusive
                create vector of long long f with 7 elements, filled with 0
                for k = 0 and a = i while k != x, incrementing k and dividing a by 7, increment f[a % 7]
                for k = 0 and b = j while k != y, incrementing k and dividing b by 7, increment f[b % 7]
                if *max_element(f.begin(), f.end()) <= 1, increment res
            end of the block
        end of the block
    end of the block
    print res
    return to indicate successful execution
end of the block

[CODE]:

long long find_len(long long num) {
    long long l = 1;
    for (long long a = 7; a < num; a *= 7) l += 1;
    return l;
}
int main() {
    long long n, m, x, y, res, i, j;
    cin >> n >> m;
    x = find_len(n);
    y = find_len(m);
    res = 0;
    if (x + y <= 7) {
        for (i = 0; i != n; i++) {
            for (j = 0; j != m; j++) {
                vector<long long> f(7, 0);
                for (long long k = 0, a = i; k != x; k++, a /= 7) f[a % 7]++;
                for (long long k = 0, b = j; k != y; k++, b /= 7) f[b % 7]++;
                if (*max_element(f.begin(), f.end()) <= 1) res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}


[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]:
create integers n, m
declare log7 with integer x as argument
    create integer res with res = 0
    if x is 0, return 1 from function
    while x is true
        set x to x / 7
        increment res
    end of the block
    return res from function
end of the block
declare base10 with integer x as argument, returning integer
    create integers spow, res with spow = 1, res = 0
    while x is rue
        increment res by spow * ( x % 10 )
        set x to x / 10
        set spow to spow * 7
    end of the block
    return res from function
end of the block
create map vis from pair of ( integer and integer ) to boolean
create integer ans
declare solve with integer sz as argument, returning void
    create integer vector p
    for i = 0 to 7 exclusive, add element i to end of p
    start loop
        create integers x, y
        set x to y to 0
        for i = 0 to result of run log7 with n as argument exclusive
            set x to x * 10
            increment x by p[i]
        end of the block
        for i = result of run log7 with n as argument to sz exclusive
            set y to y * 10
            increment y by p[i]
        end of the block
        if n is greater than or equal to result of run base10 with x as argument and m is greater than or equal to result of run base10 with y as argument
            if not vis[ make pair from ( x, y ) ]
                increment ans
                set vis[make pair from ( x, y ) ] to true
            end of the block
        end of the block
    while result of run next_permutation with beginning of p, end of p as arguments is true
end of the block
define the main function
    read n read m
    decrement n
    decrement m
    create integer sz with sz = result of run log7 with n as argument + result of run log7 with m as argument
    if sz is greater than 7
        print 0 print newline
        return to indicate successful execution
    end of the block
    run solve with sz as argument
    print ans print newline
    return to indicate successful execution
end of the block

[CODE]:

int n, m;
int log7(int x) {
    int res = 0;
    if (x == 0) return 1;
    while (x) {
        x /= 7;
        res++;
    }
    return res;
}
int base10(int x) {
    int spow = 1, res = 0;
    while (x) {
        res += spow * (x % 10);
        x /= 10;
        spow *= 7;
    }
    return res;
}
map<pair<int, int>, bool> vis;
int ans;
void solve(int sz) {
    vector<int> p;
    for (int i = 0; i < 7; i++) p.push_back(i);
    do {
        int x, y;
        x = y = 0;
        for (int i = 0; i < log7(n); i++) {
            x *= 10;
            x += p[i];
        }
        for (int i = log7(n); i < sz; i++) {
            y *= 10;
            y += p[i];
        }
        if (n >= base10(x) && m >= base10(y)) {
            if (!vis[make_pair(x, y)]) {
                ans++;
                vis[make_pair(x, y)] = true;
            }
        }
    } while (next_permutation(p.begin(), p.end()));
}
int main() {
    cin >> n >> m;
    n--;
    m--;
    int sz = log7(n) + log7(m);
    if (sz > 7) {
        cout << 0 << endl;
        return 0;
    }
    solve(sz);
    cout << ans << endl;
    return 0;
}


[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]:
create ints n and m
create bool array use with 20 elements
void function calc with int arguments len1, len2, cur, t and integer reference &ans
    if cur is equal to len1 + len2
        increment ans by one
    else if cur = len1
        loop i from 0 to 7 exclusive
            if use[i] is false and i < m
                set use[i] to 1
                call function calc with arguments len1, len2, cur + 1, i and ans
                set use[i] to 0
            end of the block
    else if cur is greater than len1
        loop i from 0 to 7 exclusive
            if use[i] is false and t * 7 + i < m
                set use[i] to 1
                call calc with arguments len1, len2, cur + 1, t * 7 + i and ans
                set use[i] to 0
            end of the block
    else
        loop i from 0 to 7 exclusive
            if use[i] is false and t * 7 + i < n
                change use[i] to 1
                call calc with arguments len1, len2, cur + 1, t * 7 + i and ans
                change use[i] to 0
            end of the block
    end of the block
end of the block
define the main function
    read n and m
    create integers len1 and len2 = 0, N = n and M = m, then decrement n and m
    while n is not 0
        increment len1 by one
        divide n by 7
    end of the block
    while m is not 0
        increment len2 by one
        divide m by 7
    end of the block
    set len1 to max of len1 and 1
    set len2 to max of len2 and 1
    assign N to n and M to m
    if len1 + len2 is greater than 7
        print 0
    else
        set value of sizeof(use) bytes at the pointer use to 0
        create integer ans = 0
        call calc with arguments len1, len2, 0, 0 and ans
        print ans
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int n, m;
bool use[20];
void calc(int len1, int len2, int cur, int t, int &ans) {
    if (cur == len1 + len2)
        ans++;
    else if (cur == len1) {
        for (int i = 0; i < 7; i++)
            if (!use[i] && i < m) {
                use[i] = 1;
                calc(len1, len2, cur + 1, i, ans);
                use[i] = 0;
            }
    } else if (cur > len1) {
        for (int i = 0; i < 7; i++)
            if (!use[i] && t * 7 + i < m) {
                use[i] = 1;
                calc(len1, len2, cur + 1, t * 7 + i, ans);
                use[i] = 0;
            }
    } else {
        for (int i = 0; i < 7; i++)
            if (!use[i] && t * 7 + i < n) {
                use[i] = 1;
                calc(len1, len2, cur + 1, t * 7 + i, ans);
                use[i] = 0;
            }
    }
}
int main() {
    cin >> n >> m;
    int len1 = 0, len2 = 0, N = n--, M = m--;
    while (n) {
        len1++;
        n /= 7;
    }
    while (m) {
        len2++;
        m /= 7;
    }
    len1 = max(len1, 1);
    len2 = max(len2, 1);
    n = N, m = M;
    if (len1 + len2 > 7)
        cout << 0 << endl;
    else {
        memset(use, 0, sizeof(use));
        int ans = 0;
        calc(len1, len2, 0, 0, ans);
        cout << ans << endl;
    }
    return 0;
}


[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]:
define the main function
    declare long long n
    input n
    declare char array mat with n and n indices
    loop i through 0 and one less than n
        loop j through 0 and 1 less than n, inputting mat at indices i and j
    set bools col_x and row_x to be false
    loop i between 0 and one less than n
        declare long long cnt to be 0
        loop j from 0 to one less than n
            if mat at i and j is E then increment cnt
        if cnt equals n
            set row_x true
            break
        end of the block
    end of the block
    loop i between 0 and one less than n
        declare long long cnt to be 0
        loop j between 0 and one less than n
            if mat at j and i is E increment cnt
        if cnt equals n
            set col__x to true
            break
        end of the block
    end of the block
    if both col_x and row_x are true
        output -1 and a newline
    otherwise if row_x is true
        loop i from 0 to one less than n
            loop j from 0 to one less than n
                if mat at j and i equals .
                    output j plus 1, a space, i plus one, and a newline
                    break
                end of the block
            end of the block
        end of the block
    else
        loop i from 0 to one less than n
            loop j from 0 to one less than n
                if mat at i and j is .
                    output i plus 1, a space, and j plus 1 and a newline
                    break
                end of the block
            end of the block
        end of the block
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    long long n;
    cin >> n;
    char mat[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) cin >> mat[i][j];
    bool col_x = false, row_x = false;
    for (int i = 0; i < n; i++) {
        long long cnt = 0;
        for (int j = 0; j < n; j++)
            if (mat[i][j] == 'E') cnt++;
        if (cnt == n) {
            row_x = true;
            break;
        }
    }
    for (int i = 0; i < n; i++) {
        long long cnt = 0;
        for (int j = 0; j < n; j++)
            if (mat[j][i] == 'E') cnt++;
        if (cnt == n) {
            col_x = true;
            break;
        }
    }
    if (col_x && row_x)
        cout << -1 << "\n";
    else if (row_x) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (mat[j][i] == '.') {
                    cout << j + 1 << " " << i + 1 << "\n";
                    break;
                }
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (mat[i][j] == '.') {
                    cout << i + 1 << " " << j + 1 << "\n";
                    break;
                }
            }
        }
    }
    return 0;
}


[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]:
create a map from long longs to long longs called mpu
let vec be a vector of long longs
declare string array s with size 101
let path be long long array with size 1000006
define the main function
    declare long long variable n
    read n
    for i from 0 to n exclusive, read s[i]
    let row and col be boolean arrays with size 100
    for i from 0 to n exclusive
        for j from 0 to n exclusive
            if s[i][j] is equal to '.'
                set row[i] to 1
                set col[j] to 1
            end of the block
        end of the block
    end of the block
    create int p = 0
    loop i from 0 to n exclusive
        if row[i] is false, set p to 1
    end of the block
    if p is equal to 1
        for integer i = 0 to n exclusive
            if col[i] is false, change p to 2
        end of the block
        if p = 2
            print "-1\n"
            return to indicate successful execution
        end of the block
        loop i from 0 to n exclusive
            for j from 0 to n exclusive
                if col[j] = 1 and s[i][j] is equal to '.'
                    set col[j] to 0
                    print i + 1, " " and j + 1
                end of the block
            end of the block
        end of the block
        return to indicate successful execution
    else
        for integer i = 0 to n exclusive
            loop j from 0 to n exclusive
                if s[i][j] = '.'
                    print i + 1, " " and j + 1
                    break the loop
                end of the block
            end of the block
        end of the block
    end of the block
    return to indicate successful execution
end of the block

[CODE]:


[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]:
bigmod is a long long function with long long arguments a, b and m
    if b = 0, return 1 % m
    create long long x = bigmod(a, b / 2, m)
    set x to x squared modulo m
    if b is odd, assign (x * a) modulo m to x
    return x
end of the block
define the main function
    declare integer variable n
    read n
    declare string array s with size n + 2
    for i from 0 to n exclusive, read s[i]
    let r and c be vectors of integers arrays with size n + 1
    for i = 0 to n exclusive
        for j from 0 to n exclusive
            if s[i][j] = '.'
                push j to r[i]
                push i to c[j]
            end of the block
    declare integer p = 1
    loop i from 0 to n exclusive
        if r[i] is empty
            change p to 0
            break the loop
        end of the block
    end of the block
    if p is true
        for integer i = 0 to n exclusive, print i + 1, " " and r[i][0] + 1
        return to indicate successful execution
    end of the block
    set p to 1
    for i = 0 to n exclusive
        if c[i] is empty
            change p to 0
            break
        end of the block
    end of the block
    if p is true
        loop i from 0 to n exclusive, print c[i][0] + 1, " " and i + 1
        return to indicate successful execution
    end of the block
    print "-1"
end of the block

[CODE]:

long long bigmod(long long a, long long b, long long m) {
    if (b == 0) return 1 % m;
    long long x = bigmod(a, b / 2, m);
    x = (x * x) % m;
    if (b % 2) x = (x * a) % m;
    return x;
}
int main() {
    int n;
    cin >> n;
    string s[n + 2];
    for (int i = 0; i < n; i++) cin >> s[i];
    vector<int> r[n + 1], c[n + 1];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (s[i][j] == '.') {
                r[i].push_back(j);
                c[j].push_back(i);
            }
    int p = 1;
    for (int i = 0; i < n; i++) {
        if (r[i].empty()) {
            p = 0;
            break;
        }
    }
    if (p) {
        for (int i = 0; i < n; i++) cout << i + 1 << " " << r[i][0] + 1 << endl;
        return 0;
    }
    p = 1;
    for (int i = 0; i < n; i++) {
        if (c[i].empty()) {
            p = 0;
            break;
        }
    }
    if (p) {
        for (int i = 0; i < n; i++) cout << c[i][0] + 1 << " " << i + 1 << endl;
        return 0;
    }
    puts("-1");
}


[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]:
maxn is a constant integer with maxn = 1100
a is an integer array with two dimensions both of size maxn, b is an integer array of size maxn
s is a string array of size 110
define the main function
    declare variable n
    while input n
        for i = 0 to n exclusive, input s[i]
        top and flag are both integers and are both set to 0
        for i = 0 to n exclusive
            for j = 0 to n exclusive
                if s[i][j] is equal to the character .
                    increment top
                    break
                end of the block
        if top is equal to n
            assign 1 to flag
            for i = 0 to n exclusive
                for j = 0 to n exclusive
                    if s[i][j] is equal to the character .
                        display i + 1, " ", and j + 1
                        break
                    end of the block
        end of the block
        assign 0 to top
        for j = 0 to n exclusive
            for i = 0 to n exclusive
                if s[i][j] is equal to the character .
                    increment top
                    break
                end of the block
        if top is equal to n and flag is false
            assign 1 to flag
            for j = 0 to n exclusive
                for i = 0 to n exclusive
                    if s[i][j] is equal to the character .
                        display i + 1, " ", and j + 1
                        break
                    end of the block
        end of the block
        if not flag, puts -1
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

const int maxn = 1100;
int a[maxn][maxn], b[maxn];
string s[110];
int main() {
    int n;
    while (cin >> n) {
        for (int i = 0; i < n; i++) cin >> s[i];
        int top = 0, flag = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (s[i][j] == '.') {
                    top++;
                    break;
                }
        if (top == n) {
            flag = 1;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    if (s[i][j] == '.') {
                        cout << i + 1 << " " << j + 1 << endl;
                        break;
                    }
        }
        top = 0;
        for (int j = 0; j < n; j++)
            for (int i = 0; i < n; i++)
                if (s[i][j] == '.') {
                    top++;
                    break;
                }
        if (top == n && !flag) {
            flag = 1;
            for (int j = 0; j < n; j++)
                for (int i = 0; i < n; i++)
                    if (s[i][j] == '.') {
                        cout << i + 1 << " " << j + 1 << endl;
                        break;
                    }
        }
        if (!flag) puts("-1");
    }
    return 0;
}


[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]:
a, b = integer 2d array of [101][101]
define the main function
    n = integer
    read n
    for i = 0 to n exclusive
        for j = 0 to n exclusive
            tmp = character
            read tmp
            if tmp is E, a[i][j] = -1
        end of the block
    end of the block
    flagh, flagl = integers with flagh[101] = {0}, flagl[101] = {0}
    flaghs, flagls = integers with flaghs = 0, flagls = 0
    for i = 0 to n exclusive
        for j = 0 to n exclusive
            if a[i][j] is 0
                flagh[i] = 1
                break loop
            end of the block
        end of the block
    end of the block
    for i = 0 to n exclusive
        if flagh[i] is 0
            flaghs = -1
            break loop
        end of the block
    end of the block
    if flaghs is 0
        for i = 0 to n exclusive
            for j = 0 to n
                if a[i][j] is 0
                    print i + 1," ",j + 1
                    break loop
                end of the block
            end of the block
        end of the block
        return to indicate successful execution
    end of the block
    for i = 0 to n exclusive
        for j = 0 to n exclusive
            if a[j][i] is 0
                flagl[i] = 1
                break loop
            end of the block
        end of the block
    end of the block
    for i = 0 to n
        if flagl[i] is 0
            flagls = -1
            break loop
        end of the block
    end of the block
    if flagls is 0
        for i = 0 to n exclusive
            for j = 0 to n exclusive
                if a[j][i] is 0
                    print j + 1," ",i + 1
                    break loop
                end of the block
            end of the block
        end of the block
        return to indicate successful execution
    end of the block
    print -1
    return to indicate successful execution
end of the block

[CODE]:


[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]:
define the main function
    create integer n
    while read n is true
        create string array a with size 101
        create integer set b
        create integer set c
        for i = 0 to n exclusive
            read a[i]
            for j = 0 to n exclusive
                if a[i][j] is '.'
                    insert i into b
                    insert j into c
                end of the block
            end of the block
        end of the block
        if size of b is less than n and size of c is less than n
            print "-1" print newline
        else
            if size of b is n
                for i = 0 to n exclusive
                    for j = 0 to n exclusive
                        if a[i][j] is '.'
                            print i + 1 print " " print j + 1 print newline
                            break loop
                        end of the block
                    end of the block
                end of the block
            else
                for i = 0 to n exclusive
                    for j = 0 to n exclusive
                        if a[j][i] is '.'
                            print j + 1 print " " print i + 1 print newline
                            break loop
                        end of the block
                    end of the block
                end of the block
            end of the block
        end of the block
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n;
    while (cin >> n) {
        string a[101];
        set<int> b;
        set<int> c;
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            for (int j = 0; j < n; ++j) {
                if (a[i][j] == '.') {
                    b.insert(i);
                    c.insert(j);
                }
            }
        }
        if (b.size() < n && c.size() < n)
            cout << "-1" << endl;
        else {
            if (b.size() == n) {
                for (int i = 0; i < n; ++i) {
                    for (int j = 0; i < n; ++j) {
                        if (a[i][j] == '.') {
                            cout << i + 1 << " " << j + 1 << endl;
                            break;
                        }
                    }
                }
            } else {
                for (int i = 0; i < n; ++i) {
                    for (int j = 0; i < n; ++j) {
                        if (a[j][i] == '.') {
                            cout << j + 1 << " " << i + 1 << endl;
                            break;
                        }
                    }
                }
            }
        }
    }
    return 0;
}


[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]:
a = character array of length 120 by 120
in function check that returns an integer and takes argument n = integer
    flag1 = integer
    for i = 1 to n inclusive
        set flag1 to 0
        for j = 1 to n inclusive
            if a[i][j] equals .
                set flag1 to 1
                break
            end of the block
        end of the block
        if not flag1 then break
    end of the block
    flag2 = integer
    for i = 1 to n inclusive
        set flag2 to 0
        for j = 1 to n inclusive
            if a[j][i] equals .
                set flag2 to 1
                break
            end of the block
        end of the block
        if not flag2 then break
    end of the block
    if flag1 and flag2 both equal 0
        return to indicate successful execution
    else
        if flag1
            return 1
        else
            return 2
        end of the block
    end of the block
end of the block
define the main function
    n = integer
    while read n
        for i = 1 to n inclusive
            for j = 1 to n inclusive read a[i][j]
        end of the block
        judge = integer with value of the return of function check with argument n
        if judge is not 0
            if judge equals 1
                for i = 1 to n inclusive
                    for j = 1 to n inclusive
                        if a[i][j] equals .
                            print i space j
                            break
                        end of the block
                    end of the block
                end of the block
            else
                for i = 1 to n inclusive
                    for j = 1 to n inclusive
                        if a[j][i] equals .
                            print j space i
                            break
                        end of the block
                    end of the block
                end of the block
            end of the block
        else
            print -1
        end of the block
    end of the block
end of the block

[CODE]:

char a[120][120];
int check(int n) {
    int flag1;
    for (int i = 1; i <= n; i++) {
        flag1 = 0;
        for (int j = 1; j <= n; j++) {
            if (a[i][j] == '.') {
                flag1 = 1;
                break;
            }
        }
        if (!flag1) { break; }
    }
    int flag2;
    for (int i = 1; i <= n; i++) {
        flag2 = 0;
        for (int j = 1; j <= n; j++) {
            if (a[j][i] == '.') {
                flag2 = 1;
                break;
            }
        }
        if (!flag2) { break; }
    }
    if (flag1 == 0 && flag2 == 0) {
        return 0;
    } else {
        if (flag1) {
            return 1;
        } else {
            return 2;
        }
    }
}
int main() {
    int n;
    while (cin >> n) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) { cin >> a[i][j]; }
        }
        int judge = check(n);
        if (judge) {
            if (judge == 1) {
                for (int i = 1; i <= n; i++) {
                    for (int j = 1; j <= n; j++) {
                        if (a[i][j] == '.') {
                            cout << i << " " << j << endl;
                            break;
                        }
                    }
                }
            } else {
                for (int i = 1; i <= n; i++) {
                    for (int j = 1; j <= n; j++) {
                        if (a[j][i] == '.') {
                            cout << j << " " << i << endl;
                            break;
                        }
                    }
                }
            }
        } else {
            cout << "-1" << endl;
        }
    }
}


[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]:
define the main function
    create integer N
    read N
    declare character array mat with size N + 1 by N + 1
    let rows and columns be arrays of integer vectors with size N + 1
    for integer i = 1 to N inclusive
        for integer j = 1 to N inclusive
            read mat[i][j]
            if mat[i][j] != 'E'
                push j to the end of rows[i]
                push i to the end of columns[j]
            end of the block
        end of the block
    end of the block
    create booleans rowFull and columnFull = false
    for i = 1 to N inclusive
        if size of rows[i] is 0, set rowFull to true
        if size of columns[i] is 0, set columnFull to true
    end of the block
    if rowFull && columnFull
        print "-1"
    else if rowFull
        for i = 1 to N inclusive print columns[i][0], " " and i
    else
        for integer i = 1 to N inclusive print i, " " and rows[i][0]
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int N;
    cin >> N;
    char mat[N + 1][N + 1];
    vector<int> rows[N + 1], columns[N + 1];
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> mat[i][j];
            if (mat[i][j] != 'E') {
                rows[i].push_back(j);
                columns[j].push_back(i);
            }
        }
    }
    bool rowFull = false, columnFull = false;
    for (int i = 1; i <= N; i++) {
        if (!rows[i].size()) rowFull = true;
        if (!columns[i].size()) columnFull = true;
    }
    if (rowFull && columnFull) {
        cout << "-1" << endl;
    } else if (rowFull) {
        for (int i = 1; i <= N; i++) { cout << columns[i][0] << " " << i << endl; }
    } else {
        for (int i = 1; i <= N; i++) { cout << i << " " << rows[i][0] << endl; }
    }
    return 0;
}


[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]:
a = character array of size 120
in the function check that takes integer n and returns integer
    flag1 = integer
    for i = 1 to n
        flag1 = 0
        for j = 1 to n
            if a[i][j] is .
                flag1 = 1
                break loop
            end of the block
        end of the block
        if not flag1, break loop
    end of the block
    flag2 = integer
    for i = 1 to n
        flag2 = 0
        for j = 1 to n
            if a[j][i] is .
                flag2 = 1
                break loop
            end of the block
        end of the block
        if not flag2, break loop
    end of the block
    if flag1 is 0 and flag2 is 0
        return to indicate successful execution
    else
        if flag1
            return 1
        else
            return 2
        end of the block
    end of the block
end of the block
define the main function
    n = integer
    while read n
        for i = 1 to n
            for j = 1 to n, read a[i][j]
        end of the block
        judge = integer with judge = check on n
        if judge
            if judge is 1
                for i = 1 to n
                    for j = 1 to n
                        if a[i][j] is .
                            print i," ",j
                            break loop
                        end of the block
                    end of the block
                end of the block
            else
                for i = 1 to n
                    for j = 1 to n
                        if a[j][i] is .
                            print j," ",i
                            break loop
                        end of the block
                    end of the block
                end of the block
            end of the block
        else
            print -1
        end of the block
    end of the block
end of the block

[CODE]:


[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]:
define the main function
    let n and m be integers
    declare string called st
    read n and m
    res is an integer array with size m
    fill res with 0
    for i = 0 to n exclusive
        read st
        if there is no character "1" in st
            print -1 and a new line
            return to indicate successful execution
        end of the block
        cur is an integer array with 3 * m elements
        curAns is an array of integers with size m
        for j = 0 to 3 * m exclusive set cur[j] to st[j % m] - '0'
        declare integer called counter = 0
        for a = m - 1 to 0 inclusive counting down
            if cur[a] = 1
                break the loop
            else
                increase counter
        end of the block
        for k = m to 2 * m exclusive
            if cur[k] = 1
                curAns[k % m] = 0
                set counter to 0
            else
                increment counter and set curAns[k % m] = counter
        end of the block
        assign value of 0 to counter
        for a = 2 * m to 3 * m exclusive
            if cur[a] = 1
                stop the loop
            else
                increment counter
        end of the block
        for integer k = 2 * m - 1 to m inclusive counting down
            if cur[k] = 1
                curAns[k % m] = 0
                set value of counter to 0
            else
                increment counter
                curAns[k % m] = min of curAns[k % m] and counter
            end of the block
        end of the block
        for integer j = 0 to m exclusive increase res[j] by curAns[j]
    end of the block
    declare integer variable called min = INT_MAX
    for integer i = 0 to m exclusive
        if min is greater than res[i], set min to res[i]
    end of the block
    print min and a new line
    return to indicate successful execution
end of the block

[CODE]:

int main() {
    int n, m;
    string st;
    cin >> n >> m;
    int res[m];
    for (int i = 0; i < m; i++) { res[i] = 0; }
    for (int i = 0; i < n; i++) {
        cin >> st;
        if (st.find('1') == string::npos) {
            cout << -1 << endl;
            return 0;
        }
        int cur[3 * m];
        int curAns[m];
        for (int j = 0; j < 3 * m; j++) { cur[j] = st[j % m] - '0'; }
        int counter = 0;
        for (int a = m - 1; a >= 0; a--) {
            if (cur[a] == 1)
                break;
            else
                counter++;
        }
        for (int k = m; k < 2 * m; k++) {
            if (cur[k] == 1) {
                curAns[k % m] = 0;
                counter = 0;
            } else
                curAns[k % m] = ++counter;
        }
        counter = 0;
        for (int a = 2 * m; a < 3 * m; a++) {
            if (cur[a] == 1)
                break;
            else
                counter++;
        }
        for (int k = 2 * m - 1; k >= m; k--) {
            if (cur[k] == 1) {
                curAns[k % m] = 0;
                counter = 0;
            } else {
                counter++;
                curAns[k % m] = min(curAns[k % m], counter);
            }
        }
        for (int j = 0; j < m; j++) { res[j] += curAns[j]; }
    }
    int min = INT_MAX;
    for (int i = 0; i < m; i++) {
        if (min > res[i]) min = res[i];
    }
    cout << min << endl;
    return 0;
}


[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]:
assign value 11000 to constant integer maxn
create integer INF = 1 << 30
let m and n be integers
da is an 2d array of integers with size 110 by maxn
joo is an 2d array of integers with size 110 by maxn
define the main function
    read m and n
    create string s
    for i = 0 to m exclusive
        read s
        for integer j = 0 to n exclusive set da[i][j] to 1 if s[j] = '1', 0 if it is not
    end of the block
    declare integers t and jj
    for i = 0 to m exclusive
        t = INF
        for j = 0 while j < n * 2
            jj = j % n
            if da[i][jj] = 1, set t to 0
            set joo[i][jj] = t and increment t
        end of the block
        t = INF
        for integer j = n * 2 to 0 inclusive counting down
            jj = j % n
            if da[i][jj] = 1, set t to 0
            joo[i][jj] = min of joo[i][jj] and t
        end of the block
    end of the block
    declare long longs mi = INF and sum
    for integer j = 0 to n exclusive
        assign value of 0 to sum
        for integer i = 0 to m exclusive add joo[i][j] to sum
        set mi to min of sum and mi
    end of the block
    if mi >= INF
        print -1 and a new line
    else
        print mi and a new line
    return to indicate successful execution
end of the block

[CODE]:

const int maxn = 11000;
int INF = 1 << 30;
int m, n;
int da[110][maxn];
int joo[110][maxn];
int main() {
    cin >> m >> n;
    string s;
    for (int i = 0; i < m; i++) {
        cin >> s;
        for (int j = 0; j < n; j++) da[i][j] = (s[j] == '1' ? 1 : 0);
    }
    int t, jj;
    for (int i = 0; i < m; i++) {
        t = INF;
        for (int j = 0; j < n * 2; j++) {
            jj = j % n;
            if (da[i][jj] == 1) t = 0;
            joo[i][jj] = t++;
        }
        t = INF;
        for (int j = n * 2; j >= 0; j--) {
            jj = j % n;
            if (da[i][jj] == 1) t = 0;
            joo[i][jj] = min(joo[i][jj], t++);
        }
    }
    long long mi = INF, sum;
    for (int j = 0; j < n; j++) {
        sum = 0;
        for (int i = 0; i < m; i++) { sum += joo[i][j]; }
        mi = min(sum, mi);
    }
    if (mi >= INF)
        cout << -1 << endl;
    else
        cout << mi << endl;
    return 0;
}


[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]:
define the main function
    create integers n, m
    read n read m
    create 2d character array a of size n by m
    for i = 0 to n exclusive
        for j = 0 to m exclusive, read a[i][j]
    end of the block
    for i = 0 to n exclusive
        if not count of '1' from a[i] to a[i] + m
            print -1 print '\n'
            return to indicate successful execution
        end of the block
    end of the block
    create 2d integer arrays nearest, l, r, with nearest size n by m, l size n by m, r size n by m
    for i = 0 to n exclusive
        create integer lst with lst = -1
        for j = 0 to m exclusive
            if a[i][j] is '1', set lst to j
        end of the block
        create boolean c with c = true
        for j = 0 to m exclusive
            set lst to j if a[i][j] is '1', else lst
            set c to (c bitwise and a[i][j]) is 0
            set l[i][j] to m - lst + j if c is true, else absolute value of j - lst
        end of the block
        set lst to -1
        set c to true
        for j = 0 to m exclusive
            if a[i][j] is '1'
                set lst to j
                break loop
            end of the block
        end of the block
        for j = m - 1 to 0 inclusive, decrementing j
            set lst to j if a[i][j] is '1', else lst
            set c to (c bitwise and a[i][j]) is 0
            set r[i][j] to lst + 1 + m - ( j + 1 ) if c is true, else absolute value of j - lst
        end of the block
    end of the block
    for i = 0 to n exclusive
        for j = 0 to m exclusive, set nearest[i][j] to minimum of r[i][j] and l[i][j]
    end of the block
    create integer ans with ans = 0x3f3f3f3f
    for j = 0 to m exclusive
        create integer cur with cur = 0
        for i = 0 to n exclusive, increment cur by nearest[i][j]
        set ans to minimum of ans and cur
    end of the block
    print ans print '\n'
end of the block

[CODE]:


[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]:
create constant integer maxn with maxn = 2e5 + 10
create integers n, m
create string array s with size 110
create 2d integer array l with size 110 by 10010
create 2d integer array r with size 110 by 10010
define the main function
    read n read m
    for i = 0 to n exclusive, read s[i]
    create boolean bad with bad = false
    for i = 0 to n exclusive
        create integer last with last = -1
        for j = 0 to m exclusive
            if s[i][j] is '0'
                set l[i][j] to -1 if last is -1, else j - last
            else
                set l[i][j] to 0, set last to j
        if last is less than 0, set bad to true
        set last to -1
        for j = m - 1 to 0 inclusive, decrementing j
            if s[i][j] is '0'
                set r[i][j] to -1 if last is -1, else last - j
            else
                set r[i][j] to 0, set last to j
        for j = 0 to m exclusive
            if l[i][j] is less than 0, set l[i][j] to j + l[i][m-1] + 1
        for j = m - 1 to 0 inclusive, decrementing j
            if r[i][j] is less than 0, set r[i][j] to (m - 1) - j + r[i][0] + 1
    end of the block
    if bad is true
        print -1 print "\n"
        return to indicate successful execution
    end of the block
    create long long ans with ans = n * m + 1
    for j = 0 to m exclusive
        create long long cur with cur = 0
        for i = 0 to n exclusive, increment cur by minimum of l[i][j] and r[i][j]
        set ans to minimum of ans and cur
    end of the block
    print ans print "\n"
end of the block

[CODE]:


[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]:
dist = array of 2 by 10004 int
define the main function
    n, m = int
    read n and m
    for i = 0 to n exclusive
        str = string
        read str
        firstone = -1
        ff = 0
        while ff < m and str[ff] is not '1' increment ff
        if ff is m
            print -1
            return to indicate successful execution
        end of the block
        firstone = ff
        dist[0][ff] = 0
        j = ff+1 modulo m
        while true
            if str[j] is '1'
                dist[0][j] = 0
                k = j
                while dist[0][k] < dist[0][k-1+m modulo m
                    k = k-1+m modulo m
                    dist[0][k] = dist[0][k+1 modulo m]+1
                end of the block
                if j is firstone break
            else
                dist[0][j] = dist[0][j+m-1 modulo m]+1
            end of the block
            j = j+1 modulo m
        end of the block
        for z = 0 to m exclusive
            increment dist[1][z] by dist[0][z]
            dist[0][z] = 0
        end of the block
    end of the block
    minn = dist[1][0]
    for h = 1 to m exclusive
        if dist[1][h] < minn minn = dist[1][h]
    end of the block
    print minn
    return to indicate successful execution
end of the block

[CODE]:

int dist[2][10004];
int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        string str;
        cin >> str;
        int firstone = -1;
        int ff = 0;
        while (ff < m && str[ff] != '1') ff++;
        if (ff == m) {
            cout << -1 << endl;
            return 0;
        }
        firstone = ff;
        dist[0][ff] = 0;
        int j = (ff + 1) % m;
        while (true) {
            if (str[j] == '1') {
                dist[0][j] = 0;
                int k = j;
                while (dist[0][k] < dist[0][(k - 1 + m) % m]) {
                    k = (k - 1 + m) % m;
                    dist[0][k] = dist[0][(k + 1) % m] + 1;
                }
                if (j == firstone) break;
            } else {
                dist[0][j] = dist[0][(j + m - 1) % m] + 1;
            }
            j = (j + 1) % m;
        }
        for (int z = 0; z < m; z++) {
            dist[1][z] += dist[0][z];
            dist[0][z] = 0;
        }
    }
    int minn = dist[1][0];
    for (int h = 1; h < m; h++) {
        if (dist[1][h] < minn) { minn = dist[1][h]; }
    }
    cout << minn << endl;
    return 0;
}


[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]:
integer constant INF = 1 << 29
define the main function
    declare integer variables n and m
    read n and m
    a is an array of strings with size n
    read n elements into a
    ans is an array of integers with size m
    set m elements of ans to 0
    chk is integer
    for i = 0 to n exclusive
        set value of chk to 0
        for integer j = 0 to m exclusive, increment chk by 1 if a[i][j] = '1'
        if chk = 0
            print "-1\n"
            return to indicate successful execution
        end of the block
    end of the block
    for i = 0 to n exclusive
        declare integer called last
        declare boolean variable called found = 0
        for j = m - 1 to 0 inclusive counting down
            if a[i][j] = '1'
                set value of last to j
                stop the loop
            end of the block
        end of the block
        , curr is an array of integers with size m
        for j = 0 to m exclusive, curr[j] = INT_MAX
        for j = 0 to m exclusive
            if a[i][j] = '1'
                set value of last to j
                found = 1
            end of the block
            if found is 0
                curr[j] = min(curr[j], (m - last) + j)
            else
                curr[j] = min of curr[j] and abs(j - last)
            end of the block
        end of the block
        found = 0
        for j = 0 to m exclusive
            if a[i][j] = '1'
                last = j
                break the loop
            end of the block
        end of the block
        for integer j = m - 1 to 0 inclusive counting down
            if a[i][j] = '1'
                set value of last to j
                assign value of 1 to found
            end of the block
            if found is 0
                curr[j] = min(curr[j], (last + 1) + (m - 1 - j))
            else
                curr[j] = min(curr[j], abs(j - last))
            end of the block
        end of the block
        for integer j = 0 to m exclusive increment ans[j] by curr[j]
    end of the block
    res is integer = INT_MAX
    for i = 0 to m exclusive, set res to min(res, ans[i])
    print res and a new line
    return to indicate successful execution
end of the block

[CODE]:

const int INF = 1 << 29;
int main() {
    int n, m;
    cin >> n >> m;
    string a[n];
    for (int i = 0; i < (n); i++) cin >> a[i];
    int ans[m];
    for (int i = 0; i < (m); i++) ans[i] = 0;
    int chk;
    for (int i = 0; i < (n); i++) {
        chk = 0;
        for (int j = 0; j < (m); j++) { chk += (a[i][j] == '1'); }
        if (chk == 0) {
            cout << "-1\n";
            return 0;
        }
    }
    for (int i = 0; i < (n); i++) {
        int last;
        bool found = 0;
        for (int j = m - 1; j >= 0; --j) {
            if (a[i][j] == '1') {
                last = j;
                break;
            }
        }
        int curr[m];
        for (int j = 0; j < (m); j++) curr[j] = INT_MAX;
        for (int j = 0; j < (m); j++) {
            if (a[i][j] == '1') {
                last = j;
                found = 1;
            }
            if (!found) {
                curr[j] = min(curr[j], (m - last) + j);
            } else {
                curr[j] = min(curr[j], abs(j - last));
            }
        }
        found = 0;
        for (int j = 0; j < m; ++j) {
            if (a[i][j] == '1') {
                last = j;
                break;
            }
        }
        for (int j = m - 1; j >= 0; --j) {
            if (a[i][j] == '1') {
                last = j;
                found = 1;
            }
            if (!found) {
                curr[j] = min(curr[j], (last + 1) + (m - 1 - j));
            } else {
                curr[j] = min(curr[j], abs(j - last));
            }
        }
        for (int j = 0; j < (m); j++) ans[j] += curr[j];
    }
    int res = INT_MAX;
    for (int i = 0; i < (m); i++) res = min(res, ans[i]);
    cout << res << endl;
    return 0;
}


[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]:
MAXN = a constant set to 100005
MOD = and constant set to 998244353
a = an array of integers with a length of MAXN
dp = a 2 dimentional array of integers with a length of 201
newdp = a 2 dimentional array of integers with a length of 201
define the main function
    n = integer
    read n
    for i = 0 to n exclusive, read index i of a
    for i = 0 to n exclusive
        if i = 0
            if index i of a = -1
                for x = 1 to 200 inclusive, set newdp[x][0] = 1
            else
                newdp[a[i]][0] = 1
            end of the block
        else
            if index i of a = -1
                flag0 = integer set to 0
                flag1 = integer set to 0
                for y = 1 to 200 inclusive
                    add dp[y][1] to flag1
                    modulo flag1 by MOD
                end of the block
                for x = 1 to 200 inclusive
                    subtract dp[x - 1][1] from flag1
                    add MOD to flag1
                    modulo flag1 by MOD
                    subtract dp[x - 1][0] from flag1
                    add MOD to flag1
                    modulo flag1 by MOD
                    add dp[x - 1][1] to flag0
                    modulo flag0 by MOD
                    add dp[x - 1][0] to flag0
                    modulo flag0 by MOD
                    add dp[x][0] to flag1
                    modulo flag1 by MOD
                    set newdp[x][0] to flag0
                    set newdp[x][1] to flag1
                end of the block
            else
                x = integer set to index i of a
                for y = 1 to 200 inclusive
                    flag = integer set to 1 if x <= y or 0
                    add dp[y][1] to newdp[x][flag]
                    modulo newdp[x][flag] by MOD
                    if y <= x
                        add dp[y][0] to newdp[x][flag]
                        modulo newdp[x][flag] by MOD
                    end of the block
                end of the block
            end of the block
        end of the block
        run memcpy with dp, newdp and 201 * 2 * 4 as arguments
        run memset with newdp, 0, and 201 * 2 * 4 as arguments
    end of the block
    ans = integer set to 0
    for x = 1 to 200 inclusive
        add dp[x][1] to ans
        modulo ans by MOD
    end of the block
    read ans
    return to indicate successful execution
end of the block

[CODE]:

const int MAXN = 100005;
const int MOD = 998244353;
int a[MAXN];
int dp[201][2];
int newdp[201][2];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) { cin >> a[i]; }
    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            if (a[i] == -1) {
                for (int x = 1; x <= 200; ++x) { newdp[x][0] = 1; }
            } else {
                newdp[a[i]][0] = 1;
            }
        } else {
            if (a[i] == -1) {
                int flag0 = 0;
                int flag1 = 0;
                for (int y = 1; y <= 200; ++y) {
                    flag1 += dp[y][1];
                    flag1 %= MOD;
                }
                for (int x = 1; x <= 200; ++x) {
                    flag1 -= dp[x - 1][1];
                    flag1 += MOD;
                    flag1 %= MOD;
                    flag1 -= dp[x - 1][0];
                    flag1 += MOD;
                    flag1 %= MOD;
                    flag0 += dp[x - 1][1];
                    flag0 %= MOD;
                    flag0 += dp[x - 1][0];
                    flag0 %= MOD;
                    flag1 += dp[x][0];
                    flag1 %= MOD;
                    newdp[x][0] = flag0;
                    newdp[x][1] = flag1;
                }
            } else {
                int x = a[i];
                for (int y = 1; y <= 200; ++y) {
                    int flag = x <= y ? 1 : 0;
                    newdp[x][flag] += dp[y][1];
                    newdp[x][flag] %= MOD;
                    if (y <= x) {
                        newdp[x][flag] += dp[y][0];
                        newdp[x][flag] %= MOD;
                    }
                }
            }
        }
        memcpy(dp, newdp, 201 * 2 * 4);
        memset(newdp, 0, 201 * 2 * 4);
    }
    int ans = 0;
    for (int x = 1; x <= 200; ++x) {
        ans += dp[x][1];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


[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]:
MAXINT = const int with MAXINT = 2147483640
MAXLL = const long long with MAXLL = 9223372036854775800LL
MAXN = const long long with MAXN = 1e6
eps = const double with eps = 1e-9
mod = const long long with mod = 998244353
dp = 3d array of long long of size [100006][202][2], pref = 2d array of size [300][2]
n = long long, a = integer array of size MAXN
define the main function
    call srand on time(0)
    read n
    for i = 1 to n, read a[i]
    if a[1] is -1
        for i = 1 to 200 dp[1][j][0] = 1
    else
        dp[1][a[1]][0] = 1
    for i = 2 to n
        for j = 1 to 200
            (pref[j][1] = pref[j - 1][1] + dp[i - 1][j][1]) = (pref[j][1] = pref[j - 1][1] + dp[i - 1][j][1]) modulo mod
            (pref[j][0] = pref[j - 1][0] + dp[i - 1][j][0]) = (pref[j][0] = pref[j - 1][0] + dp[i - 1][j][0]) modulo mod
        end of the block
        if a[i] is -1
            for cur = 1 to 200
                sum = long long with sum = 0
                (sum = sum + (pref[200][1] - pref[cur - 1][1] + mod)) = (sum = sum + (pref[200][1] - pref[cur - 1][1] + mod)) modulo mod
                (sum = sum + dp[i - 1][cur][0]) = (sum = sum + dp[i - 1][cur][0]) modulo mod
                (dp[i][cur][1] = dp[i][cur][1] + sum) = (dp[i][cur][1] = dp[i][cur][1] + sum) modulo mod
                sum = pref[cur - 1][1] + pref[cur - 1][0]
                (dp[i][cur][0] = dp[i][cur][0] + sum) = (dp[i][cur][0] = dp[i][cur][0] + sum) modulo mod
            end of the block
        else
            sum = long long with sum = 0
            cur = long long with cur = a[i]
            for j = cur to 200, sum = sum + (dp[i - 1][j][1]) = sum + (dp[i - 1][j][1]) modulo mod
            (sum = sum + dp[i - 1][cur][0]) = (sum = sum + dp[i - 1][cur][0]) modulo mod
            (dp[i][cur][1] = dp[i][cur][1] + sum) = (dp[i][cur][1] = dp[i][cur][1] + sum) modulo mod
            sum = 0
            for j = 1 to cur exclusive, (sum = sum + dp[i - 1][j][0] + dp[i - 1][j][1]) = (sum = sum + dp[i - 1][j][0] + dp[i - 1][j][1]) modulo mod
            (dp[i][cur][0] = dp[i][cur][0] + sum) = (dp[i][cur][0] = dp[i][cur][0] + sum) modulo mod
        end of the block
    end of the block
    ans = long long with ans = 0
    for i = 1 to 200, (ans = ans + dp[n][i][1]) = (ans = ans + dp[n][i][1]) modulo mod
    print ans
    return to indicate successful execution
end of the block

[CODE]:


[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]:
create integers n, i, rez, sum, sum1, integer array DP of sizes 2, 2, and 205, integer array A of size 100005, and create integers cr, j
in function f that takes in arguments integer address a, integer b, and return f
    a is assigned the sum of a and b
    if a is greater than or equal to 998244353, subtract 998244353 from a
end of the block
define the main function
    input n
    for i = 1 to n inclusive, input A[i]
    if A[1] doesn't equal -1
        Dp[1][1][A[1]] is set to 1
    else
        for i = 1 to 200 inclusive, set Dp[1][1][i] to 1
    assign 1 to cr
    for i = 2 to n inclusive
        assign 1 - cr to cr
        if A[i] doesn't equal -1
            for j = 1 to 200 inclusive
                if A[i] is less than j, call function f with arguments Dp[cr][0][A[i]], Dp[1 - cr][0][j]
                if a[i] is equal to j
                    call function f with arguments Dp[cr][0][A[i]], Dp[1 - cr][0][j]
                    call function f with arguments Dp[cr][0][A[i]], Dp[1 - cr][1][j]
                end of the block
                if A[i] is greater than j
                    call function f with arguments Dp[cr][1][A[i]], Dp[1 - cr][0][j]
                    call function f with arguments Dp[cr][1][A[i]], Dp[1 - cr][1][j]
                end of the block
                set Dp[1 - cr][1][j] and Dp[1 - cr][0][j] to 0
            end of the block
        else
            assign 0 to sum
            for j = 1 to 200 inclusive, call function f with arguments sum, Dp[1 - cr][0][j]
            assign 0 to sum1
            for j = 1 to 200 inclusive
                call function f with arguments Dp[cr][0][j], sum
                call function f with arguments Dp[cr][0][j], Dp[1 - cr][1][j]
                call function f with arguments sum, 998244353 - Dp[1 - cr][0][j]
                call function f with arguments Dp[cr][1][j], sum1
                call function f with arguments sum1, Dp[1 - cr][1][j]
                call function f with arguments sum1, Dp[1 - cr][0][j]
                set Dp[1 - cr][0][j] and Dp[1 - cr][1][j] to 0
            end of the block
        end of the block
    end of the block
    for i = 1 to 200 inclusive, call function f with arguments rez, Dp[cr][0][i]
    output rez
    return to indicate successful execution
end of the block

[CODE]:


[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]:
MAXINT = const integer with MAXINT = 2147483640
MAXLL = const long long with MAXLL = 9223372036854775800LL
MAXN = const long long with MAXN = 1e6
eps = const double with eps = 1e-9
mod = const long long with mod = 998244353
dp = 3d const long long array of size [100006][202][2], pref = 2d const long long array of size [300][2]
n, a = long long with a = long long array of size MAXN
define the main function
    srand of time(0)
    read n
    for i = 1 to n, read a[i]
    if a[1] is -1
        for i = 1 to 200, dp[1][j][0] = 1
    else
        dp[1][a[1]][0] = 1
    for i = 2 to n
        for j = 1 to 200
            (pref[j][1] = pref[j - 1][1] + dp[i - 1][j][1]) = (pref[j][1] = pref[j - 1][1] + dp[i - 1][j][1]) modulo mod
            (pref[j][0] = pref[j - 1][0] + dp[i - 1][j][0]) = (pref[j][0] = pref[j - 1][0] + dp[i - 1][j][0]) modulo mod
        end of the block
        if a[i] is -1
            for cur = 1 to 200
                sum = long long with sum = 0
                (sum = sum + (pref[200][1] - pref[cur - 1][1] + mod)) = (sum = sum + (pref[200][1] - pref[cur - 1][1] + mod)) modulo mod
                (sum = sum + dp[i - 1][cur][0]) = (sum = sum + dp[i - 1][cur][0]) modulo mod
                (dp[i][cur][1] = dp[i][cur][1] + sum) = (dp[i][cur][1] = dp[i][cur][1] + sum) modulo mod
                sum = pref[cur - 1][1] + pref[cur - 1][0]
                (dp[i][cur][0] = dp[i][cur][0] sum) = (dp[i][cur][0] = dp[i][cur][0] + sum) modulo mod
            end of the block
        else
            sum = long long with sum = 0
            cur = long long with cur = a[i]
            for j = cur to 200, sum = sum + (dp[i - 1][j][1]) = (dp[i - 1][j][1]) modulo mod
            (sum = sum + dp[i - 1][cur][0]) = (sum = sum + dp[i - 1][cur][0]) modulo mod
            (dp[i][cur][1] = dp[i][cur][1] + sum) = (dp[i][cur][1] = dp[i][cur][1] + sum) modulo mod
            sum = 0
            for j = 1 to cur exclusive, sum = sum + dp[i - 1][j][0] + dp[i - 1][j][1]) = (sum = sum + dp[i - 1][j][0] + dp[i - 1][j][1]) modulo mod
            (dp[i][cur][0] = dp[i][cur][0] + sum) = (dp[i][cur][0] = dp[i][cur][0] + sum) modulo mod
        end of the block
    end of the block
    ans = long long with ans = 0
    (ans = ans + dp[n][i][1]) = (ans = ans + dp[n][i][1]) modulo mod
    print ans
    return to indicate successful execution
end of the block

[CODE]:


[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]:
create const int N = 1e5 + 5
create const long long mod = 998244353
declare 3d long long array dp with size N by 201 by 3
let a be int array with size N
define the main function
    declare integer variable n
    read n
    for i from 1 to n + 1 exclusive, read input to a[i]
    set sizeof(dp) bytes at the pointer dp to 0
    for i = 1 to 201 exclusive
        if a[1] = -1 or a[1] = i, set dp[1][i][2] to 1
    end of the block
    create long long sum = 0
    for i = 2 to n inclusive
        assign 0 to sum
        for integer j = 200 to 1 inclusive, decrementing j
            if a[i] = -1 or a[i] = j, change dp[i][j][0] to sum
            assign (sum + dp[i - 1][j][1] + dp[i - 1][j][0]) % mod to sum
        end of the block
        for j from 1 to 201 exclusive
            if a[i] = -1 or a[i] = j, set dp[i][j][1] to (dp[i - 1][j][1] + dp[i - 1][j][0] + dp[i - 1][j][2]) % mod
        end of the block
        change sum to 0
        for integer j = 1 to 200 inclusive
            if a[i] = -1 or a[i] = j, set dp[i][j][2] to sum
            assign (sum + dp[i - 1][j][1] + dp[i - 1][j][0] + dp[i - 1][j][2]) % mod to sum
        end of the block
    end of the block
    declare long long variable ans = 0
    for i = 1 to 200 inclusive, change ans to (ans + dp[n][i][1] + dp[n][i][0]) % mod
    print ans
    return to indicate successful execution
end of the block

[CODE]:


[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]:
create integer N, create integer array arr with size 100001
create 3d long long array dp with size 100001 by 201 by 2
define the main function
    read N
    for i = 1 to N inclusive, read arr[i]
    for i = 1 to N inclusive
        if arr[i] is not -1
            if i is 1
                set dp[i][arr[i]][0] to 1
            else
                for j = 1 to arr[i] exclusive
                    increment dp[i][arr[i]][0] by dp[i - 1][j][0] + dp[i - 1][j][1]
                    set dp[i][arr[i]][0] to dp[i][arr[i]][0] % 998244353
                end of the block
                increment dp[i][arr[i]][1] by dp[i - 1][arr[i]][0]
                set dp[i][arr[i]][1] to dp[i][arr[i]][1] % 998244353
                for j = arr[i] to 200 inclusive
                    increment dp[i][arr[i]][1] by dp[i - 1][j][1]
                    set dp[i][arr[i]][1] to dp[i][arr[i]][1] % 998244353
                end of the block
            end of the block
        else
            if i is 1
                for j = 1 to 200 inclusive, set dp[i][j][0] to 1
            else
                create long long temp with temp = 0
                for j = 1 to 200 inclusive
                    increment dp[i][j][1] by dp[i-1][j][0]
                    set dp[i][j][1] to dp[i][j][1] % 998244353
                    increment dp[i][j][0] by temp
                    set dp[i][j][0] to dp[i][j][0] % 998244353
                    increment temp by dp[i - 1][j][0]
                    set temp to temp % 998244353
                end of the block
                set temp to 0
                for j = 200 to 1 inclusive, decrementing i
                    increment temp by dp[i - 1][j][1]
                    set temp to temp % 998244353
                    increment dp[i][j][1] by temp
                    set dp[i][j][1] to dp[i][j][1] % 998244353
                end of the block
                set temp to 0
                for j = 1 to 200 inclusive
                    increment dp[i][j][0] by temp
                    set dp[i][j][0] to dp[i][j][0] % 998244353
                    increment temp by dp[i - 1][j][1]
                    set temp to temp % 998244353
                end of the block
            end of the block
        end of the block
    end of the block
    create long long ans with ans = 0
    for i = 1 to 200 inclusive, set ans to (ans + dp[N][i][1]) % 998244353
    print ans print '\n'
    return to indicate successful execution
end of the block

[CODE]:


[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]:
create long long mod with mod = 998244353
create integer array a with size 100000
define the main function
    create integer n
    read n
    for i = 0 to n exclusive, read a[i]
    create long long vectors up, notup, prev_up, prev_notup, with up initialized with 201, notup initialized with 201, prev_up initialized with (201,0), prev_notup initialized with (201,0)
    set prev_up[0] to 1
    for i = 0 to n exclusive
        for j = 1 to 200 inclusive
            increment prev_up[j] by prev_up[j - 1], set prev_up[j] to prev_up[j] % mod
            increment prev_notup[j] by prev_notup[j-1], set prev_notup[j] to prev_notup[j] % mod
        end of the block
        set up[0] to notup[0] to 0
        for j = 1 to 200 inclusive
            set up[j] to notup[j] to 0
            if a[i] is not -1 and a[i] is not j, break current loop iteration
            increment up[j] by prev_up[j - 1] + prev_notup[j - 1], set up[j] to up[j] % mod
            increment notup[j] by prev_up[j] + prev_notup[j], set notup[j] to notup[j] % mod
            decrement notup[j] by prev_up[j - 1] + prev_notup[j - 1], set notup[j] to notup[j] % mod
            increment notup[j] by prev_notup[200] - prev_notup[j], set notup[j] to notup[j] % mod
        end of the block
        set prev_up to up
        set prev_notup to notup
    end of the block
    create long long ans with ans = 0
    for i = 1 to 200 inclusive, increment ans by prev_notup[i], set ans to ans % mod
    print ( ans + mod ) % mod print newline
end of the block

[CODE]:

long long mod = 998244353;
int a[100000];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<long long> up(201), notup(201), prev_up(201, 0), prev_notup(201, 0);
    prev_up[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= 200; j++) {
            (prev_up[j] += prev_up[j - 1]) %= mod;
            (prev_notup[j] += prev_notup[j - 1]) %= mod;
        }
        up[0] = notup[0] = 0;
        for (int j = 1; j <= 200; j++) {
            up[j] = notup[j] = 0;
            if (a[i] != -1 && a[i] != j) continue;
            (up[j] += prev_up[j - 1] + prev_notup[j - 1]) %= mod;
            (notup[j] += prev_up[j] + prev_notup[j]) %= mod;
            (notup[j] -= prev_up[j - 1] + prev_notup[j - 1]) %= mod;
            (notup[j] += prev_notup[200] - prev_notup[j]) %= mod;
        }
        prev_up = up;
        prev_notup = notup;
    }
    long long ans = 0;
    for (int i = 1; i <= 200; i++) (ans += prev_notup[i]) %= mod;
    cout << (ans + mod) % mod << endl;
}


[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]:
create 3d long long array DP with size 100005 by 205 by 2, create long long arrays sum1, sum2 with sum1 size 205, sum2 size 205
create long long array ar with size 100005
create long long N
define the main function
    read N
    for i = 0 to N exclusive, read ar[i]
    if ar[0] is -1
        set sum1[0] to 0
        for i = 1 to 200 inclusive
            set DP[0][i][0] to 1
            set sum1[i] to sum1[i-1] + DP[0][i][0]
        end of the block
    else
        set DP[0][ar[0]][0] to 1
        set sum1[0] to 0
        for i = 1 to 200 inclusive, set sum1[i] to sum1[i-1] + DP[0][i][0]
    end of the block
    for i = 1 to N exclusive
        if ar[i] is -1
            for j = 1 to 200 inclusive
                increment DP[i][j][0] by sum1[j-1]
                set DP[i][j][0] to DP[i][j][0] % 998244353
                increment DP[i][j][1] by DP[i-1][j][0]
                set DP[i][j][1] to DP[i][j][1] % 998244353
                increment DP[i][j][0] by sum2[j-1]
                set DP[i][j][0] to DP[i][j][0] % 998244353
            end of the block
            for j = 1 to 200 inclusive
                increment DP[i][j][1] by (sum2[200] - sum2[j - 1] + 998244353)
                set DP[i][j][1] to DP[i][j][1] % 998244353
            end of the block
        else
            increment DP[i][ar[i]][0] by (sum1[ar[i] - 1]) + (sum2[ar[i] - 1])
            set DP[i][ar[i]][0] to DP[i][ar[i]][0] % 998244353
            increment DP[i][ar[i]][1] by DP[i - 1][ar[i]][0]
            set DP[i][ar[i]][1] to DP[i][ar[i]][1] % 998244353
            increment DP[i][ar[i]][1] by (sum2[200] - sum2[ar[i] - 1] + 998244353)
            set DP[i][ar[i]][1] to DP[i][ar[i]][1] % 998244353
        end of the block
        set sum1[0] to 0
        set sum2[0] to 0
        for j = 1 to 200 inclusive
            set sum1[j] to sum1[j-1] + DP[i][j][0]
            set sum1[j] to sum1[j] % 998244353
            set sum2[j] to sum2[j-1] + DP[i][j][1]
            set sum2[j] to sum2[j] % 998244353
        end of the block
    end of the block
    print (sum2[200]) % 998244353 print newline
    return 0 from function
end of the block

[CODE]: