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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.Scanner;

public class Main {
	static long mod;
	static long right;
	static long left;
	static long tate = 1;
	static long mid;
	static long index;
	static long max;
	static long x;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long k = sc.nextLong();

		max = 0;
		for (int i = 2; i >= 0; i--) {
			for (int j = 2; j >= 0; j--) {
				// System.out.println(n-i+" "+(7-j));
				long sell = 7 * (n - i) + (7 - j) - 7;
				// System.out.println(sell);
				max += sell;
			}
		}
		System.out.println(max);

		long j = 0;
		x = k;
		long pattern = 0;
		while (x <= max) {// 一回数が見つかれば、あとは99を足していくだけでいい
			// System.out.println(x);
			if (!(x - 81 < 0) && (x - 81) % 9 == 0) {
				for (int i = 0; i < 5; i++) {
					if (((x - 81) / 9 - i) % 7 == 0 && ((x - 71) / 9 - i) / 7 + 1 <= n) {
						// System.out.println("縦"+(((x-71)/9-i)/7+1)+"
						// 横"+(i+1));
						// System.out.println(x);
						right = (4 - i);// * 9;
						left = -i;// * 9;
						mid = i;
						mod = 0;
						pattern++;
						break;
					}
				}
			}
			if (pattern == 1)
				break;
			x += 11;// どうやってxの増やす数を変える？
		}
		System.out.println(x);

		if (pattern != 0) {
			while (x + increase() <= max) {
				System.out.println("a");
				pattern++;
			}
		}

		System.out.println(pattern);
	}

	static long increase() {
		mod += 11;
		boolean flag = false;
		while (mod <= max-x) {// 縦、横を先に指定する。
			for (int i = 0; i < 5; i++) {
				long move = i - mid;
				if ((mod - move * 9) % 63 == 0)flag = true;
			}
			tate++;
			if(flag)break;
			mod += 11;
		}
		System.out.println(mod);
		return mod;
	}
}