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.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            input_iter = LazyLoadAllLines();
            //------------------------------------------------//
            var n = Read<long>();
            //var b = Read<long>();
            //var v = Read<long>();
            //var s = Read();
            var pls = Read<long>(n);
            //var bls = Read<long>(n);
            //var sls = Read(n);
            /*List<List<long>> abls = new List<List<long>>();
            for (int i = 0; i < n - 1; ++i)
            {
                var x = Read<long>(2);
                if (x[0] > x[1]) x.Reverse();
                abls.Add(x);
            }*/
            //List<List<long>> abls = new List<List<long>>();
            //List<long> cls = new List<long>();
            /*List<long> edgeNum = Enumerable.Repeat(0L, (int)n).ToList();
            for (int i = 0; i < n - 1; ++i)
            {
                abls.Add(Read<long>(2));
                abls[i].Add(i);
                abls[i].Add(-1);
                --abls[i][0];
                --abls[i][1];
                //cls.Add(Read<long>());
                ++edgeNum[(int)abls[i][0]];
                ++edgeNum[(int)abls[i][1]];
            }*/

            //als.Sort((l, r) => (int)(r - l));

            var min = n + 1;
            int cnt = 0;
            for(int i = 0; i < n; ++i)
            {
                if(min >= pls[i])
                {
                    min = pls[i];
                    ++cnt;
                }
            }

            Console.WriteLine(cnt);
        }

        static IEnumerator<string> input_iter;

        static IEnumerator<string> LazyLoadAllLines()
        {
            string line;
            do
            {
                line = Console.ReadLine();
                foreach (var s in line.Split(' '))
                    yield return s;
            } while (line != null);
        }
        static _T Read<_T>() where _T : struct
        {
            input_iter.MoveNext();
            return (_T)Convert.ChangeType(input_iter.Current, typeof(_T));
        }
        static string Read()
        {
            input_iter.MoveNext();
            return input_iter.Current;
        }
        static List<_T> Read<_T>(long num) where _T : struct {
            List<_T> res = new List<_T>();
            for (long i = 0; i < num; ++i)
            {
                input_iter.MoveNext();
                res.Add((_T)Convert.ChangeType(input_iter.Current, typeof(_T)));
            }
            return res;
        }
        static List<string> Read(long num)
        {
            List<string> res = new List<string>();
            for(long i = 0; i < num; ++i)
            {
                input_iter.MoveNext();
                res.Add(input_iter.Current);
            }
            return res;
        }

        public class PriorityQueue<T> where T : IComparable
        {
            private IComparer<T> comparer = null;
            private bool isAccendingOrder;

            private List<T> heap;
            private int heapCurrentSize = 0;

            public PriorityQueue(IComparer<T> comparer, int initialHeapSize = 256)
            {
                heap = new List<T>(initialHeapSize);
                this.comparer = comparer;
            }

            public PriorityQueue(bool isAccending = true, int initialHeapSize = 256)
            {
                heap = new List<T>(initialHeapSize);
                isAccendingOrder = isAccending;
            }

            private int Compare(T x, T y)
            {
                if (comparer != null) return comparer.Compare(x, y);
                return isAccendingOrder ? x.CompareTo(y) : y.CompareTo(x);
            }

            public bool Empty()
            {
                return Count() == 0;
            }

            public int Count()
            {
                return heapCurrentSize;
            }

            public void Push(T x)
            {
                //node number
                var idx = heapCurrentSize++;
                if (heapCurrentSize > heap.Count) heap.Capacity *= 2;

                while (idx > 0)
                {
                    //parent node number
                    var parentIdx = (idx - 1) / 2;

                    if (Compare(heap[parentIdx], x) <= 0) break;

                    heap[idx] = heap[parentIdx];
                    idx = parentIdx;
                }

                heap[idx] = x;
            }

            public T Pop()
            {
                T ret = heap[0];
                T x = heap[--heapCurrentSize];

                int idx = 0;
                while (idx * 2 + 1 < heapCurrentSize)
                {
                    //children
                    int a = idx * 2 + 1;
                    int b = idx * 2 + 2;

                    if (b < heapCurrentSize && Compare(heap[b], heap[a]) < 0) a = b;

                    if (Compare(heap[a], x) >= 0) break;

                    heap[idx] = heap[a];
                    idx = a;
                }

                heap[idx] = x;

                return ret;
            }

            public T Peek()
            {
                return heap[0];
            }

            public bool Contains(T x)
            {
                for (int i = 0; i < heapCurrentSize; i++) if (x.Equals(heap[i])) return true;
                return false;
            }

            public void Clear()
            {
                while (heapCurrentSize > 0) Pop();
            }

            public IEnumerator<T> GetEnumerator()
            {
                var temp = new List<T>();

                while (heapCurrentSize > 0)
                {
                    temp.Add(Pop());
                }

                foreach (var value in temp)
                {
                    Push(value);
                    yield return value;
                }
            }

            public T[] ToArray()
            {
                T[] array = new T[heapCurrentSize];
                int i = 0;

                foreach (var r in this)
                {
                    array[i] = r;
                    ++i;
                }

                return array;
            }
        }
    }
}