title: Count Total Set Bits In All Numbers From 1 To N
signature: def count_total_set_bits_in_all_numbers_from_1_to_n(n):
source_py: def count_total_set_bits_in_all_numbers_from_1_to_n(n):
      i = 0
      ans = 0
      while ((1 << i) <= n):
          k = 0
          change = (1 << i)
          for j in range(0, (n + 1)):
              ans += k
              if (change == 1):
                  k = (not k)
                  change = (1 << i)
              else:
                  change -= 1
          i += 1
      return ans
source_cpp: int count_total_set_bits_in_all_numbers_from_1_to_n(int n) {
    int i = 0;
    int ans = 0;
    while ( ( 1 << i ) <= n ) {
      bool k = 0;
      int change = 1 << i;
      for ( int j = 0;
      j <= n;
      j ++ ) {
        ans += k;
        if ( change == 1 ) {
          k = ! k;
          change = 1 << i;
        }
        else {
          change --;
        }
      }
      i ++;
    }
    return ans;
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(n, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              n),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver(90, 279)
      print(f"TEST-0...{result}")
  
      result = driver(56, 159)
      print(f"TEST-1...{result}")
  
      result = driver(43, 112)
      print(f"TEST-2...{result}")
  
      result = driver(31, 80)
      print(f"TEST-3...{result}")
  
      result = driver(77, 231)
      print(f"TEST-4...{result}")
  
      result = driver(35, 88)
      print(f"TEST-5...{result}")
  
      result = driver(43, 112)
      print(f"TEST-6...{result}")
  
      result = driver(66, 197)
      print(f"TEST-7...{result}")
  
      result = driver(15, 32)
      print(f"TEST-8...{result}")
  
      result = driver(95, 304)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: count_total_set_bits_in_all_numbers_from_1_to_n
question_info.test_list: [{"idx": 0, "outputs": 279, "inputs": {"n": 90}}, {"idx": 1, "outputs": 159, "inputs": {"n": 56}}, {"idx": 2, "outputs": 112, "inputs": {"n": 43}}, {"idx": 3, "outputs": 80, "inputs": {"n": 31}}, {"idx": 4, "outputs": 231, "inputs": {"n": 77}}, {"idx": 5, "outputs": 88, "inputs": {"n": 35}}, {"idx": 6, "outputs": 112, "inputs": {"n": 43}}, {"idx": 7, "outputs": 197, "inputs": {"n": 66}}, {"idx": 8, "outputs": 32, "inputs": {"n": 15}}, {"idx": 9, "outputs": 304, "inputs": {"n": 95}}]
question_info.entry_cls_name: Solution