Find the sum of both the primary and secondary diagonal elements of a square matrix.
Difficulty: Medium
Phase: 6 · Mixed Logical Challenges
XP Reward: 20 XP
Topics: Mixed Logical Challenges, Medium
Supported Languages: Python, JavaScript, C, C++, Java
Problem Description
Given N followed by N x N matrix, find sum of both primary and secondary diagonals (if N is odd, center element counted once). Input Format: Read input from standard input (stdin). Output Format: Print the result to standard output (stdout).
Constraints
- -10^9 <= N <= 10^9
Examples
Example 1
Input: 3 1 2 3 4 5 6 7 8 9
Output: 25
Explanation: Sample execution for input 3 1 2 3 4 5 6 7 8 9