@echo off
if "%1" == "" (
    exit       
)

for %%i in (..) do (
    set problem_name=%%~ni
)

if NOT EXIST ..\check.exe (      
    if exist ..\check.dpr (
        dcc32 -cc ..\check.dpr
    )
    if exist ..\check.cpp (
        g++ ..\check.cpp -o ..\check
    )
)

if NOT "%2" == "" (
    if EXIST ..\%problem_name%_%1.exe   goto compiled
    if EXIST ..\%problem_name%_%1.class goto compiled
)

if EXIST ..\%problem_name%_%1.dpr dcc32 -cc ..\%problem_name%_%1.dpr
if EXIST ..\%problem_name%_%1.cpp g++ ..\%problem_name%_%1.cpp -o ..\%problem_name%_%1.exe
if EXIST ..\%problem_name%_%1.c g++ ..\%problem_name%_%1.c -o ..\%problem_name%_%1.exe
if EXIST ..\%problem_name%_%1.java javac ..\%problem_name%_%1.java

:compiled


if "%2" == "" (    
    for %%i in (??) do (        
        call docheck %1 %%i
    )
) else (
    echo Running on test: %2
    copy %2 ..\%problem_name%.in > nul
    cd ..
    if EXIST %problem_name%_%1.exe   run        -t 2          %problem_name%_%1.exe
    if EXIST %problem_name%_%1.class run -Xifce -t 2 java -ea %problem_name%_%1
    check.exe %problem_name%.in %problem_name%.out tests\%2.a
    cd tests
)
