<p>You are given an integer <code>n</code> and an array <code>sick</code> sorted in increasing order, representing positions of infected people in a line of <code>n</code> people.</p>

<p>At each step, <strong>one </strong>uninfected person <strong>adjacent</strong> to an infected person gets infected. This process continues until everyone is infected.</p>

<p>An <strong>infection sequence</strong> is the order in which uninfected people become infected, excluding those initially infected.</p>

<p>Return the number of different infection sequences possible, modulo <code>10<sup>9</sup>+7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 5, sick = [0,4]</span></p>

<p><strong>Output:</strong> <span class="example-io">4</span></p>

<p><strong>Explanation:</strong></p>

<p>There is a total of 6 different sequences overall.</p>

<ul>
	<li>Valid infection sequences are <code>[1,2,3]</code>, <code>[1,3,2]</code>, <code>[3,2,1]</code> and <code>[3,1,2]</code>.</li>
	<li><code>[2,3,1]</code> and <code>[2,1,3]</code> are not valid infection sequences because the person at index 2 cannot be infected at the first step.</li>
</ul>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 4, sick = [1]</span></p>

<p><strong>Output:</strong> <span class="example-io">3</span></p>

<p><strong>Explanation:</strong></p>

<p>There is a total of 6 different sequences overall.</p>

<ul>
	<li>Valid infection sequences are <code>[0,2,3]</code>, <code>[2,0,3]</code> and <code>[2,3,0]</code>.</li>
	<li><code>[3,2,0]</code>, <code>[3,0,2]</code>, and <code>[0,3,2]</code> are not valid infection sequences because the infection starts at the person at index 1, then the order of infection is 2, then 3, and hence 3 cannot be infected earlier than 2.</li>
</ul>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= sick.length &lt;= n - 1</code></li>
	<li><code>0 &lt;= sick[i] &lt;= n - 1</code></li>
	<li><code>sick</code> is sorted in increasing order.</li>
</ul>

from typing import List
from functools import lru_cache

MOD = 10**9 + 7

# Precompute factorials and inverse factorials
@lru_cache(None)
def fact(i: int) -> int:
    """Compute factorial of i modulo MOD."""
    return 1 if i < 2 else i * fact(i - 1) % MOD

@lru_cache(None)
def ifact(i: int) -> int:
    """Compute inverse factorial of i modulo MOD using Fermat's Little Theorem."""
    return pow(fact(i), -1, MOD)

class Solution:
    def numberOfSequence(self, n: int, sick: List[int]) -> int:
        # Calculate the number of uninfected people
        uninfected_count = n - len(sick)
        
        # Initialize result with the factorial of uninfected people
        res = fact(uninfected_count)
        
        # Adjust for the initial uninfected segment before the first sick person
        res = res * ifact(sick[0]) % MOD
        
        # Adjust for the uninfected segment after the last sick person
        res = res * ifact(n - sick[-1] - 1) % MOD
        
        # Process each group of uninfected people between sick people
        for group in [b - a - 1 for a, b in zip(sick, sick[1:]) if b - a > 1]:
            # Adjust for the factorial of the group size
            res = res * ifact(group) % MOD
            
            # Calculate the number of possible infection sequences for the group
            res = res * pow(2, group - 1, MOD) % MOD
        
        return res

# Explanation:
# 1. We precompute factorials and their modular inverses to handle large numbers efficiently.
# 2. The main function calculates the number of valid infection sequences.
# 3. We start by considering the factorial of all uninfected people.
# 4. We adjust for the segments before the first and after the last sick person.
# 5. For each group of uninfected people between sick people, we adjust the result by:
#    - Dividing by the factorial of the group size (to account for permutations within the group).
#    - Multiplying by 2^(group size - 1) to account for the number of ways the infection can spread within the group.
# 6. The result is returned modulo 10^9 + 7.
164