One morning, Polycarp woke up and realized that 1543 is the most favorite number in his…
- User
One morning, Polycarp woke up and realized that 1543 is the most favorite number in his life.
The first thing that Polycarp saw that day as soon as he opened his eyes was a large wall carpet of size n by m cells; n and m are even integers. Each cell contains one of the digits from 0 to 9 .
Polycarp became curious about how many times the number 1543 would appear in all layers∗ of the carpet when traversed clockwise.
∗ The first layer of a carpet of size n×m is defined as a closed strip of length 2⋅(n+m−2) and thickness of 1 element, surrounding its outer part. Each subsequent layer is defined as the first layer of the carpet obtained by removing all previous layers from the original carpet.
Input The first line of the input contains a single integer t (1≤t≤100 ) — the number of test cases. The following lines describe the test cases.
The first line of each test case contains a pair of numbers n and m (2≤n,m≤103 , n,m — even integers).
This is followed by n lines of length m , consisting of digits from 0 to 9 — the description of the carpet.
It is guaranteed that the sum of n⋅m across all test cases does not exceed 106 .
give me c++ code and here is sample input 1 2 4 1543 7777
1 is the number of testcase
- Assistant