Problem:
Score : 300 points

Problem Statement

Given is a permutation P_1, \ldots, P_N of 1, \ldots, N.
Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:

For any integer j (1 \leq j \leq i), P_i \leq P_j.

Constraints

1 \leq N \leq 2 \times 10^5

P_1, \ldots, P_N is a permutation of 1, \ldots, N.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
P_1 ... P_N

Output

Print the number of integers i that satisfy the condition.

Sample Input 1

5
4 2 5 1 3

Sample Output 1

3

i=1, 2, and 4 satisfy the condition, but i=3 does not - for example, P_i > P_j holds for j = 1.

Similarly, i=5 does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.

Sample Input 2

4
4 3 2 1

Sample Output 2

4

All integers i (1 \leq i \leq N) satisfy the condition.

Sample Input 3

6
1 2 3 4 5 6

Sample Output 3

1

Only i=1 satisfies the condition.

Sample Input 4

8
5 7 4 2 6 8 1 3

Sample Output 4

4

Sample Input 5

1
1

Sample Output 5

1

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.ReadLine();
        }

        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int[] arr = cin.ReadIntArray(n);
            int[] max = new int[n];
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                //maxの値を求めておく
                if(i == 0)
                {
                    max[i] = arr[i];
                }
                else
                {
                    max[i] = Math.Min(arr[i], max[i - 1]);
                }
                
                if(max[i] >= arr[i])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }

    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }

    class Mod
    {
        public int N { get; }
        private readonly List<long> fac = new List<long>() { 1, 1 };
        private readonly List<long> inv = new List<long>() { 0, 1 };
        private readonly List<long> facInv = new List<long>() { 1, 1 };

        /// <summary>
        /// コンストラクタでmod N のNの値を決める
        /// </summary>
        /// <param name="n"></param>
        public Mod(int n) { N = n; }

        /// <summary>
        /// 四則演算は下で
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public long Add(long a, long b) => (a % N + b % N + N) % N;
        public long Sub(long a, long b) => Add(a, -b);
        public long Mul(long a, long b) => (a % N * b % N + N) % N;
        public long Div(long a, long b) => Mul(a, Inv(b));

        public long Sum(params long[] args) => args.Aggregate(Add);

        public long Inv(long a)
        {
            if (a < inv.Count) return inv[(int)a];
            long b = N, x = 1, y = 0, tmp;
            while (b != 0)
            {
                var q = a / b;
                tmp = y;
                y = x - q * y;
                x = tmp;
                tmp = b;
                b = a - q * b;
                a = tmp;
            }
            return (x % N + N) % N;
        }

        public long Pow(long a, long n)
        {
            var result = 1L;
            while (n > 0)
            {
                if ((n & 1) == 1) result = Mul(result, a);
                a = Mul(a, a);
                n >>= 1;
            }
            return result;
        }

        public void InitSeq(int n)
        {
            for (var i = fac.Count; i <= n; i++)
            {
                fac.Add(fac[i - 1] * i % N);
                inv.Add(N - inv[N % i] * (N / i) % N);
                facInv.Add(facInv[i - 1] * inv[i] % N);
            }
        }

        public long Fac(int n)
        {
            InitSeq(n);
            return fac[n];
        }

        public long Per(int n, int k)
        {
            if (n < k || n < 0 || k < 0) return 0;
            InitSeq(n);
            return fac[n] * facInv[n - k] % N;
        }

        public long Com(int n, int k)
        {
            if (n < k || n < 0 || k < 0) return 0;
            InitSeq(n);
            return fac[n] * (facInv[k] * facInv[n - k] % N) % N;
        }
    }
}