## Algorithm

Problem Name: beecrowd | 1188

# Inferior Area

By Neilor Tonin, URI Brazil

Timelimit: 1

Read an uppercase character that indicates an operation that will be performed in an array M[12][12]. Then, calculate and print the sum or average considering only that numbers that are included in the green area of this array, like shown in the following figure.

## Input

The first line of the input contains a single uppercase character O ('S' or 'M'), indicating the operation Sum or Average (Média in portuguese) to be performed with the elements of the array. Follow 144 floating-point numbers (double) of the array.

## Output

Print the calculated result (sum or average), with one digit after the decimal point.

 Input Sample Output Sample S 5.0 130.0 -3.5 2.5 4.1 ... 126.2

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````
#include <bits/stdc++.h>
using namespace std;

int main()
{
char c;
cin >> c;
double sum = 0;
double a[12][12];
for(int i = 0 ; i  <  12; i++){
for(int j = 0 ; j  <  12 ; j++){
cin >> a[i][j];
if(j > (11-i) && j< i) sum += a[i][j];
}
}

if(c == 'S') printf("%.1lf\n" , sum);
else if(c == 'M') printf("%.1lf\n" , sum/30>;
return 0;
}
``````
Copy The Code &

Input

cmd
S 5.0 130.0 -3.5 2.5 4.1 ...

Output

cmd
126.2

### #2 Code Example with Javascript Programming

```Code - Javascript Programming```

``````
var lines = input.split('\n');
var operation = lines.shift();
var positions = [];
var value = 0;
var m = 1;
for(var i = 7; i < 12; i++){
value = i * 12;
for(var j = 12-i; j < 12/2+m; j++){
positions.push(value + j);
}
m++;
}

var sum = 0;
var count = 0;

for(var i = 0; i < 144; i++){
var num = parseFloat(lines.shift());
if(positions.indexOf(i)!=-1){
sum += num;
count++;
}
}

if(operation=='S'){
console.log(sum.toFixed(1));
}else{
console.log((sum/count).toFixed(1));
}
``````
Copy The Code &

Input

cmd
S 5.0 130.0 -3.5 2.5 4.1 ...

Output

cmd
126.2