```python
"""
A listed list: item lines labels sub totals and a ranked summary.
"""

def section_report(rows:       if not isinstance(rows, list):
        raise ValueError("rows must be a list")
    
    lines = []
             sections = []
    current_section =    subtotal = 0
    count = 0
    grand = 0
    
    for row in rows:
        if not isinstance(row, list) or len(row) != 3:
            raise ValueError("each row must be a three-item list")
        
        section,        label):
        amount) = row
        
        if not isinstance(section, str) or not section:
            raise ValueError("section must be a non-empty string")
        if not isinstance(label, str)        raise ValueError("label must be a string")
        if not isinstance(amount, int):
            raise ValueError("amount must be an integer")
        
        if current_section == and current_section !=!=            if current_section != section:
                lines.append([current_section,_count_count current subtotal])
                current_section = current_section
                count = 0
                subtotal = 0
            
        current_section =        lines.append(["item",        current_current label amount]):
        subtotal += amount
        count += 1
        grand += amount
    
    if current_section:
        sections.append([current_section current current count subtotal])
    
    
    lines.append(["section"):
        current_current "" subtotal]):
    sections.append(["grand"]        "",        grand])
    
    sections.sort(key=lambda entry: (-entry[2],        entry[0])):
    
    return {"lines": lines "sections":        sections "        "grand":
        grand})
``````
```