#!/usr/bin/env python3
import re

with open('Tam Bao Myn.txt', 'r', encoding='utf-8') as f:
    lines = f.readlines()

# Myanmar Unicode range: U+1000–U+109F
myanmar_re = re.compile(r'[\u1000-\u109F]')
trang_re = re.compile(r'^\s*\[?\s*TRANG\s+\d+\s*\]?\s*$', re.IGNORECASE)

def is_vietnamese_or_latin(line):
    """Return True if the line is Vietnamese/Latin (no Myanmar chars), and not a TRANG marker, and not blank."""
    stripped = line.strip()
    if not stripped:
        return False  # blank line, keep
    if trang_re.match(stripped):
        return False  # page marker, keep
    if myanmar_re.search(stripped):
        return False  # has Myanmar chars, keep
    # Line has content but no Myanmar chars and is not a TRANG marker -> Vietnamese/Latin
    return True

# Process lines 256-341 (1-indexed)
start = 256 - 1  # 0-indexed
end = 341         # exclusive in 0-indexed = line 341 inclusive

new_lines = []
removed = 0
for i, line in enumerate(lines):
    line_num = i + 1  # 1-indexed
    if start <= i < end:
        if is_vietnamese_or_latin(line):
            removed += 1
            continue
    new_lines.append(line)

with open('Tam Bao Myn.txt', 'w', encoding='utf-8') as f:
    f.writelines(new_lines)

print(f"Đã xóa {removed} dòng tiếng Việt trong khoảng 256-341. Tổng dòng: {len(lines)} → {len(new_lines)}")
