PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000218. Đếm số nguyên tố trên hai đường chéo (Elemental Matrix)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm số nguyên tố trên hai đường chéo (Elemental Matrix)

Elemental Matrix

Source: LQDOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an n×nn\times n square matrix of nonnegative integers, the main diagonal consists of cells whose row index equals their column index, and the secondary diagonal consists of cells whose row and column indices sum to n+1n+1 (using 11-based indices).

Count the cells lying on at least one of the two diagonals whose values are prime. When nn is odd, the central cell belongs to both diagonals and must be counted only once.

Input

The first line contains nn. The next nn lines each contain nn integers; line ii contains ai,1,ai,2,…,ai,na_{i,1},a_{i,2},\ldots,a_{i,n} describing row ii.

Output

Print one integer: the number of prime-valued cells on the main or secondary diagonal, counting every cell at most once.

Subtasks

  • Subtask 1 (30 points): 1≤n≤1001\le n\le100; 0≤ai,j≤1060\le a_{i,j}\le10^6 for all 1≤i,j≤n1\le i,j\le n.

  • Subtask 2 (70 points): 1≤n≤5001\le n\le500; 0≤ai,j≤1060\le a_{i,j}\le10^6 for all 1≤i,j≤n1\le i,j\le n.

Examples

Input

3
2 4 5
6 7 8
11 10 13

Output

5

Explanation

In row 11, the diagonal cells contain 22 and 55, both prime. Row 22 has the central cell 77, which belongs to both diagonals but is counted once. Row 33 contributes 1111 and 1313, both prime. There are five distinct qualifying cells, with values 2,5,7,11,132,5,7,11,13, so the answer is 55.