Problem:
Max Score: $250$ Points

Problem Statement

Snuke has a very long calendar. It has a grid with $n$ rows and $7$ columns. One day, he noticed that calendar has a following regularity.

The cell at the $i$-th row and $j$-th column contains the integer $7i+j-7$.

A good sub-grid is a $3 \times 3$ sub-grid and the sum of integers in this sub-grid mod $11$ is $k$.

How many good sub-grid are there? Write a program and help him.

Input

The input is given from standard input in the following format.

$n \quad k$

Output

Print the number of good sub-grid. If there are no solution exists, print 0.

Constraints

$1 \le n \le 10^9$

$0 \le k \le 10$

Subtasks

Subtask 1 [ $150$ points ]

The testcase in the subtask satisfies $1 \le n \le 100$.

Subtask 2 [ $100$ points ]

There are no additional constraints.

Sample Input 1

7 7

Sample Output 1

2

In this case, the calendar likes this matrix.

Sun.

Mon.

Tue.

Wed.

Thu.

Fri.

Sat.

Week 1

1

2

3

4

5

6

7

Week 2

8

9

10

11

12

13

14

Week 3

15

16

17

18

19

20

21

Week 4

22

23

24

25

26

27

28

Week 5

29

30

31

32

33

34

35

Week 6

36

37

38

39

40

41

42

Week 7

43

44

45

46

47

48

49

The cell at $i$-th row and $j$-th column is denoted $(i, j)$.

If upper-left is $(1, 5)$, the sum of integers is $5+6+7+12+13+14+19+20+21=117$.

If upper-left is $(3, 2)$, the sum of integers is $16+17+18+23+24+25+30+31+32=216$.

Therefore, there are 2 good sub-grids.

Sample Input 2

6 0

Sample Output 2

2

If upper-left is $(1, 3)$ or $(4, 4)$, it is a good sub-grid.

Sample Input 3

18 10

Solution in C++14 (Clang 3.8.0) (judge verdict: Runtime Error)

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename T> class segtree {
    private:
        int n,sz; vector<T> node, lazy_update, lazy_add; vector<bool> lazyFlag;
        void eval(int k, int l, int r) {
            if(lazyFlag[k]){
                lazy_update[k] += lazy_add[k];
                node[k] = lazy_update[k];
                if(r - l > 1) {
                    lazy_add[2*k+1] = lazy_add[2*k+2] = 0;
                    lazy_update[2*k+1] = lazy_update[2*k+2] = lazy_update[k];
                    lazyFlag[2*k+1] = lazyFlag[2*k+2] = true;
                }
                lazy_add[k] = 0;
                lazyFlag[k] = false;
            }else if(lazy_add[k] != 0){
                node[k] += lazy_add[k];
                if(r - l > 1){
                    lazy_add[2*k+1] += lazy_add[k]; lazy_add[2*k+2] += lazy_add[k];
                }
                lazy_add[k] = 0;
            }
        }
     
    public:
        segtree(vector<T> v) : sz((int)v.size()){
            n = 1;
            while(n < sz) n *= 2;
            node.resize(2*n-1,numeric_limits<T>::min());
            lazy_update.resize(2*n-1, 0); lazyFlag.resize(2*n-1,false);
            lazy_add.resize(2*n-1, 0);
            for(int i = 0; i < sz; i++){
                node[i+n-1] = v[i];
            }
            for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1],node[2*i+2]);
        }
        void update(int a, int b, T x, int k=0, int l=0, int r=-1) {
            if(r < 0) r = n;
            eval(k, l, r);
            if(b <= l || r <= a) return;
            if(a <= l && r <= b){
                lazy_add[k] = 0; lazy_update[k] = x; lazyFlag[k] = true;
                eval(k, l, r);
            }else{
                update(a, b, x, 2*k+1, l, (l+r)/2); update(a, b, x, 2*k+2, (l+r)/2, r);
                node[k] = max(node[2*k+1],node[2*k+2]);
            }
        }
        void add(int a, int b, T x, int k=0, int l=0, int r=-1){
            if(r < 0) r = n;
            eval(k, l, r);
            if(b <= l || r <= a) return;
            if(a <= l && r <= b){
                lazy_add[k] += x; eval(k, l, r);
            }else{
                add(a, b, x, 2*k+1, l, (l+r)/2); add(a, b, x, 2*k+2, (l+r)/2, r);
                node[k] = max(node[2*k+1],node[2*k+2]);
            }
        }
        T query(int a, int b, int k=0, int l=0, int r=-1) {
            if(r < 0) r = n;
            eval(k, l, r);
            if(b <= l || r <= a) return numeric_limits<T>::min();
            if(a <= l && r <= b) return node[k];
            return max(query(a, b, 2*k+1, l, (l+r)/2), query(a, b, 2*k+2, (l+r)/2, r));
        }
        void print(){
            for(int i = 0; i < sz; i++){
                cout<<query(i,i+1)<< " ";
            }
            cout<<endl;
        }
    };


int main(){
    int n,q;
    cin >> n >> q;
    vector<ll>v(n+1);
    segtree<ll> sg(v);
    rep(zz,q){
        int a;
        ll b;
        scanf("%d %lld",&a,&b);
        while(b!=0){
            ll pp = sg.query(a-1,a);
    
            int ok = a-1;
            int ng = -1;
            while(ok-ng>1){
                int mid = (ok+ng)/2;
                if(sg.query(mid,a)==pp){
                    ok = mid;
                }else{
                    ng = mid;
                }
            }
            if(ok==0){
                sg.add(0,a,b/a);
                b-=(b/a)*a;
                if(b!=0){
                    sg.add(0,b,1);
                }
                b = 0;
            }else{
                ll qq = sg.query(ok-1,ok);
                if( (a-ok)*(qq-pp) <= b ){
                    sg.add(ok,a,qq-pp);
                    b -= (a-ok)*(qq-pp);
                }else{
                    ll dis = a-ok;
                    sg.add(ok,a,(b/dis));
                    b -= dis*(b/dis);
                    if(b!=0){
                        sg.add(ok,ok+b,1);
                    }
                    b = 0;
                }
            }
        }
    }
    rep(i,n){
        printf("%lld\n",sg.query(i,i+1));
    }
    return 0;
}