from collections import defaultdict

def analyze_file(input_filename):
    with open(input_filename, 'rb') as f:
        data = f.read()

    entry_counts = defaultdict(int)
    total_bytes = len(data)
    total_records = 0

    i = 0
    while i + 5 <= total_bytes:
        entry_id = data[i]
        entry_counts[entry_id] += 1
        total_records += 1

        i += 5

    print(f"\nAnalyzed {total_records} records ({total_bytes} bytes total)")
    print(f"{'ID':<6}{'Count':>10}")
    print("-" * 18)
    for entry_id in sorted(entry_counts):
        print(f"0x{entry_id:02X} {entry_id:>3} {entry_counts[entry_id]:>10}")

    leftover = total_bytes % 5
    if leftover != 0:
        print(f"\n⚠️ Warning: {leftover} leftover bytes at the end of the file (possibly corrupted/incomplete record)")

if __name__ == '__main__':
    analyze_file("Test.B162")
