#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1033
Task: Write a Python function that compresses a string using run-length encoding and decompresses it
Generated: 2026-02-12T17:41:16.522674
"""

def compress(string):
    compressed = ""
    count = 1
    for i in range(1, len(string)):
        if string[i] == string[i - 1]:
            count += 1
        else:
            compressed += string[i - 1] + str(count)
            count = 1
    # Add the last character and count
    compressed += string[-1] + str(count)
    return compressed

def decompress(compressed):
    decompressed = ""
    i = 0
    while i < len(compressed):
        char = compressed[i]
        i += 1
        count = ""
        while i < len(compressed) and compressed[i].isdigit():
            count += compressed[i]
            i += 1
        decompressed += char * int(count)
    return decompressed

if __name__ == '__main__':
    test_string = "aaabbbcccaaa"
    compressed_result = compress(test_string)
    decompressed_result = decompress(compressed_result)
    print("Original string:", test_string)
    print("Compressed string:", compressed_result)
    print("Decompressed string:", decompressed_result)