#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "nwtnev.h"

int main (int argc, char *argv[]) {
    int n;
    if (argc<2 || sscanf(argv[1], "%d", &n)!=1) {
        fprintf(stderr,"%s n\n", argv[0]);
        return -1;
    }

    double *x = malloc((n+1) * sizeof(double));
    double *y = malloc((n+1) * sizeof(double));
    if (x==NULL || y==NULL) {
        fprintf(stderr, "malloc failed\n");
        free(x);
        free(y);
        return -1;
    }
    
    for (int i=0; i<=n; i++) {
        fscanf(stdin, "%lf %lf\n", &x[i], &y[i]);
    }

    double xi;
    while (scanf("%lf", &xi) == 1) {
        double result = neville(n, x, y, xi);
        printf("%.16g %.16g\n", xi, result);
    }

    free(x);
    free(y);
    
    return 0;
}
