using
System;
using
System.Collections.Generic;
public
class
GFG{
class
pair : IComparable<pair>
{
public
int
first, second;
public
pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
public
int
CompareTo(pair other)
{
if
(
this
.first < other.first)
{
return
1;
}
else
if
(
this
.first > other.first)
{
return
-1;
}
else
{
return
0;
}
}
}
static
int
numberOfSubarrays(
int
[]arr,
int
n)
{
int
cnt = 1;
pair[] v =
new
pair[n];
for
(
int
i = 0; i < n; i++) {
v[i] =
new
pair(0,0);
v[i].first = arr[i];
v[i].second = i;
}
Array.Sort(v);
for
(
int
i = 1; i < n; i++) {
if
(v[i].second == v[i - 1].second + 1) {
continue
;
}
else
{
cnt++;
}
}
return
cnt;
}
public
static
void
Main(String[] args)
{
int
[]arr = { 6, 3, 4, 2, 1 };
int
N = arr.Length;
Console.Write(numberOfSubarrays(arr, N));
}
}