We are given 40000 4x3 PNG files split evenly into 4 directories:

$ find . -iname "*.png" | wc -l
40000

$ ls -lh
total 0
drwxrwxr-x 1 osiriz osiriz 291K Mar 31 11:38 0
drwxrwxr-x 1 osiriz osiriz 291K Mar 31 11:38 1
drwxrwxr-x 1 osiriz osiriz 291K Mar 31 11:38 2
drwxrwxr-x 1 osiriz osiriz 291K Mar 31 11:38 3

So we just need to reassemble the image from all the sections. Since the images are divided into 4 directories of 10000 images, I guessed it was 4 100x100 (400x300 pixels) images combined into a single image.

So I used Pillow to assemble the image:

#!/usr/bin/env python
from PIL import Image

result = Image.new('RGB', (800, 600))

# Make the bigger squares and combine them on the result image
for i in range(4):
    subimage = Image.new('RGB', (400, 300))

    # Loop over all squares in directory
    for j in range(10000):
        subcol = j % 100
        subrow = j // 100
        with Image.open(f"{i}/square-{j}.png") as im:
            subimage.paste(im=im, box=(subcol*4, subrow*3))

    col = i % 2
    row = i // 2

    result.paste(im=subimage, box=(col*400, row*300))

result.save("flag.png", "PNG")

An we get the following image: