title: Array Range Queries Elements Frequency Value
signature: class Solution {
  
      public int ArrayRangeQueriesElementsFrequencyValue(int start, int end_arg1, List<int> arr) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(int start, int end_arg1, List<int> arr, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(start, end_arg1, arr); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  0, 31, new List<int>{1, 2, 2, 3, 3, 3, 12, 13, 18, 18, 26, 28, 29, 36, 37, 39, 40, 49, 55, 57, 63, 69, 69, 73, 85, 86, 87, 87, 89, 89, 90, 91, 92, 93, 93, 93, 95, 99}, 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  1, 25, new List<int>{24, -62, 2, 1, 94, 56, -22, -70, -22, -34, -92, -18, 56, 2, 60, 38, -88, 16, -28, 30, -30, 58, -80, 94, 6, 56}, 
                  2
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  3, 4, new List<int>{0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  10, 15, new List<int>{84, 13, 81, 40, 87, 82, 50, 30, 90, 80, 81, 70, 14, 54, 72, 93, 78, 27, 61}, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  2, 3, new List<int>{-20, 20, 34, 60, 90}, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  0, 6, new List<int>{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  14, 18, new List<int>{11, 18, 18, 19, 25, 30, 42, 42, 56, 58, 63, 66, 67, 68, 69, 75, 78, 83, 83}, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  29, 33, new List<int>{-24, -82, 24, -84, 94, 2, -30, 86, 58, -56, -96, 60, -38, 76, 94, 74, -98, -84, -38, 46, 4, -84, -90, -28, -50, 46, 16, 28, -14, -82, -64, 42, 64, -2, -40, 96, 60, 2, -86, 32, 38, -66}, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  31, 19, new List<int>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  21, 32, new List<int>{2, 91, 42, 85, 97, 92, 24, 39, 63, 89, 31, 59, 51, 89, 72, 62, 26, 92, 75, 4, 6, 13, 20, 95, 22, 30, 52, 60, 37, 27, 49, 15, 67, 26}, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
source_py: def array_range_queries_elements_frequency_value(start, end, arr):
      frequency = dict()
      for i in range(start, (end + 1)):
          if (arr[i] in frequency.keys()):
              frequency[arr[i]] += 1
          else:
              frequency[arr[i]] = 1
      count = 0
      for x in frequency:
          if (x == frequency[x]):
              count += 1
      return count
source_cpp: int array_range_queries_elements_frequency_value(int start, int end, vector<int> arr) {
    unordered_map < int, int > frequency;
    for ( int i = start;
    i <= end;
    i ++ ) frequency [ arr [ i ] ] ++;
    int count = 0;
    for ( auto x : frequency ) if ( x . first == x . second ) count ++;
    return count;
  }