Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person. 
Person A will NOT friend request person B (B != A) if any of the following conditions are true:

age[B] <= 0.5 * age[A] + 7
age[B] > age[A]
age[B] > 100 && age[A] < 100

Otherwise, A will friend request B.
Note that if A requests B, B does not necessarily request A.  Also, people will not friend request themselves.
How many total friend requests are made?
Example 1:
Input: [16,16]
Output: 2
Explanation: 2 people friend request each other.

Example 2:
Input: [16,17,18]
Output: 2
Explanation: Friend requests are made 17 -> 16, 18 -> 17.
Example 3:
Input: [20,30,100,110,120]
Output: 3
Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.

 
Notes:

1 <= ages.length <= 20000.
1 <= ages[i] <= 120.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '\'\'\'\nStart: 2:25 p.m.\n\'\'\'\n\n\'\'\'\n- Visualize everything.\n- Work with concrete examples.\n- Commit to a hunch. Crystallize it into an approach that can be evaluated (validated/invalidated). OK if approach seems unlikely to work.\n\'\'\'\n\n\'\'\'\n[16, 16]\n\nA will not send FR to someone who is older (same age OK).\n=> sort the array\n\nA will not send FR to someone who is \\"much\\" younger.\nIf A is under 100, he will not send FR to anyone over 100.\nNot FR self.\n\'\'\'\n\n\'\'\'\nBrute-force: evaluate every pair\nTime: O(n^2)\nSpace: O(1)\n\'\'\'\n\n\'\'\'\n- A will not friend anyone older so no need to look forward, only backward.\n\nTime:O(n log n)\nSpace: O(n)\n\n- Sort\n- For each num, compute minimum bound, BS.\n\nlb = 16/8 + 7 = 15\n\n[16,17,18]\n i\n \n 17/2 = 8.5 ~= 8\n 15\n\'\'\'\n\n\'\'\'\nTest Cases\nno numbers before i (works)\n[5]\n i\n \n nothing >= lower bound (works)\n [1, 2, 50]\n        i\n        \nlb = 32\nmultiple occurrences of lb (works)\n[1, 2, 32, 32, 40, 41, 50]\n       m\n l\n       r\n                       i\n       ret\n               \nlb = 32\nonly > lb (works)\n[1, 2, 40, 41, 50] \n               i\n       ret\n       \n[40, 41, 50] (works)\n         i\n ret\n\'\'\'\n\n\'\'\'\nPASS\n[1, 2, 32, 32, 40, 41, 50]\n[1, 2, 50]\n[1, 2, 40, 41, 50] \n[40, 41, 50]\n[16,16]\n\'\'\'\n\nclass Solution:\n    def firstLTE(self, lowerBound, ages, endIndex):\n        if endIndex < 0:\n            return 0\n        \n        l = 0\n        r = endIndex\n        \n        while l < r:\n            m = (l + r) // 2  # originally ages[l], ages[r] instead of l, r -- I\'m very compromised today.\n            \n            if ages[m] <= lowerBound:\n                l = m + 1\n            else:\n                r = m\n                \n        if l <= r and ages[l] > lowerBound:\n            return l\n                \n        return endIndex + 1\n    \n    def findEarliest(self, key, ages, endIndex):\n        if endIndex < 0:\n            return -1\n        \n        l = 0\n        r = endIndex\n        \n        while l < r:\n            m = (l + r) // 2\n            \n            if ages[m] >= key:\n                r = m\n            else:\n                l = m + 1\n        \n        if l <= endIndex and ages[l] == key:\n            return l\n        \n        return -1\n    \n    \'\'\'\n    [16, 16]\n     l\n     r\n         i\n      \n     lowerBound = 23\n    [1, 2, 32, 32]\n        m        \n           l\n           r\n    \'\'\'\n    \n    def numFriendRequests(self, ages: List[int]) -> int:\n        if not ages:\n            return 0\n        \n        numRequests = 0\n        \n        ages.sort()  # O(n log n)/O(n)\n        \n        for i, a in enumerate(ages):\n            lowerBound = a*0.5 + 7  # divided instead of multiplied originally\n            startIndex = self.firstLTE(lowerBound, ages, i - 1)\n            #print(\'i = {}, startIndex = {}, delta = {}\'.format(i, startIndex, i - startIndex))\n            numRequests += i - startIndex\n            \n            if a > lowerBound:\n                startIndex = self.findEarliest(a, ages, i - 1)\n                if startIndex >= 0 and startIndex < i:\n                    numRequests += i - startIndex\n        \n        return numRequests\n    \n\'\'\'\n[73,106,39,6,26,15,30,100,71,35,46,112,6,60,110]\n\'\'\'   \n        \n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'numFriendRequests'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 5926