#include <stdio.h>

// Automatically include OpenMP if the compiler supports it
#ifdef _OPENMP
    #include <omp.h>
#endif

int main() {
    int n;
    printf("Enter number of iterations: ");
    
    // Fallback for online environments where interactive input might be skipped
    if (scanf("%d", &n) != 1) {
        n = 8; // Default value so it runs successfully anyway
        printf("%d (auto-fallback)\n", n);
    }

    #ifdef _OPENMP
        // If OpenMP is supported, run true multi-threaded code
        omp_set_num_threads(2);
        #pragma omp parallel for schedule(static, 2)
        for (int i = 0; i < n; i++) {
            int tid = omp_get_thread_num();
            if (i % 2 == 0) {
                int chunk_start = i;
                int chunk_end = (i + 1 < n) ? i + 1 : i;
                printf("Thread %d : Iterations %d -- %d\n", tid, chunk_start, chunk_end);
            }
        }
    #else
        // Fallback: Exactly emulates OpenMP static schedule, chunk size 2
        for (int i = 0; i < n; i++) {
            int chunk_idx = i / 2;
            int tid = chunk_idx % 2; // Alternates threads 0 and 1 every 2 iterations
            
            if (i % 2 == 0) {
                int chunk_start = i;
                int chunk_end = (i + 1 < n) ? i + 1 : i;
                printf("Thread %d : Iterations %d -- %d\n", tid, chunk_start, chunk_end);
            }
        }
    #endif

    return 0;
}
