## Algorithm

Problem Name: beecrowd | 2167

# Engine Failure

By M.C. Pinto, UNILA Brazil

Timelimit: 1

Engineer Joe realizes that always happened a speed fall when the measures of an engine speed slope were made at 10 ms time interval. But this fall happened at varying points at each new engine test.

Joe got curious with that lack of pattern and wants to know, for each engine test, what is the first point in which this speed fall happens.

## Input

The input is an engine test and is given in two lines. The first one has the number N of speed measures (1 < N ≤ 100). The second line has N integers: the engine RPM (revolutions per minute) Ri of each measure (0 ≤ Ri ≤ 10000, for all Ri, such that 1 ≤ iN). A measure is considered a speed fall if it is lower than the previous measure.

## Output

The output is the measure index where the first speed fall happened in the test. If no speed fall happens the output must be the number zero.

 Input Samples Output Samples 3 1 4 2 3

 5 100 199 199 198 0 4

 4 1 2 2 2 0

## Code Examples

### #1 Code Example with C Programming

```Code - C Programming```

``````
#include <stdio.h>

int main(void)

{
int i, n, x=0;

scanf("%i", &n);

int arr[n];

for (i = 0; i  <  n; ++i)
scanf("%i", &arr[i]);

for (i = 0; i  <  n-1; ++i)
{
if (arr[i] > arr[i+1])
{
x=i+2;
break;
}
}

printf("%i\n", x);

return 0;
}
``````
Copy The Code &

Input

cmd
3 1 4 2

Output

cmd
3

### #2 Code Example with C++ Programming

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

``````
#include <iostream>

int main(){
int n, i;
std::cin >> n;
int vet[n];
for(i = 0;i  <  n;i++){
std::cin >> vet[i];
}
for(i = 0;i  <  n-1;i++){
if (vet[i+1] < vet[i]) {
std::cout << i+2 << std::endl;
return 0;
}
}
std::cout << 0 << std::endl;
return 0;
}
``````
Copy The Code &

Input

cmd
3 1 4 2

Output

cmd
3

### #3 Code Example with Javascript Programming

```Code - Javascript Programming```

``````
var lines = input.split('\n');
const A = lines.shift().split(" ");
const velocity = lines.shift().split(" ");
let temp;
let verify = 0;

for(let i = 0; i  <  velocity.length, i < parseInt(A); i++){
if(i == 0){
temp = parseInt(velocity[0]);
}
else{
if(temp <= velocity[i]){
temp = parseInt(velocity[i]);
}

else{
console.log(i + 1);
verify++;
break;
}
}
}
if(verify == 0){
console.log(0>;
}
``````
Copy The Code &

Input

cmd
3 1 4 2

Output

cmd
3

### #4 Code Example with Python Programming

```Code - Python Programming```

``````
n = int(input())
r = []
r = input().split()
q = 0

for i in range(1, n):
if (int(r[i-1]) > int(r[i])):
q = i + 1
break

print(q)
``````
Copy The Code &

Input

cmd
3 1 4 2

Output

cmd
3