using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        int P = cin.nextint;
        ModInt.Mod = P;

        var A = cin.scanint;
        var X = new ModInt[P];
        var Y = new ModInt[P];
        for (int i = 0; i < P; i++)
        {
            X[i] = i;
            Y[i] = A[i];
        }
        var L = new LagrangePolynomial(X, Y);

        L.Items.join();


        //int N = cin.nextint;
        //var Y = Array.ConvertAll(cin.scanlong, i => new ModInt(i));
        //var L = new FastLagrangePolynomial(Y);
        //WriteLine(L[cin.nextint]);
    }

}

class LagrangePolynomial
{
    readonly ModInt[] X, Y;
    readonly int dim;
    public LagrangePolynomial(ModInt[] X, ModInt[] Y)
    {
        this.X = X;
        this.Y = Y;
        dim = X.Length;
        for (int i = 0; i < dim; i++)
        {
            ModInt tmp = 1;
            for (int j = 0; j < dim; j++)
            {
                if (i == j) continue;
                tmp *= X[i] - X[j];
            }
            Y[i] *= ModInt.Inverse(tmp);
        }
    }
    /// <summary>
    /// return y=f(x), O(dim^2).
    /// </summary>
    /// <param name="x">f(x)に代入するxの値</param>
    /// <returns>f(x)の値</returns>
    public ModInt this[ModInt x]
    {
        get
        {
            ModInt ret = new ModInt(0);
            for (int i = 0; i < dim; i++)
            {
                ModInt product = Y[i];
                for (int j = 0; j < dim; j++)
                {
                    if (i == j) continue;
                    product *= x - X[j];
                }
                ret += product;
            }
            return ret;
        }
    }
    /// <summary>
    /// 多項式補間により、f(x)の係数を配列にして返します。O(dim^2)
    /// </summary>
    public ModInt[] Items
    {
        get
        {
            ModInt[] mul = new ModInt[dim + 1];
            mul[0] = 1;
            for (int i = 0; i < dim; i++)
            {
                ModInt[] next = new ModInt[dim + 1];
                next[0] -= mul[0] * X[i];
                for (int j = 0; j < dim; j++)
                {
                    next[j + 1] = mul[j] - mul[j + 1] * X[i];
                }
                swap(ref mul, ref next);
            }

            ModInt[] ret = new ModInt[dim];
            for (int i = 0; i < dim; i++)
            {
                if (X[i].num == 0)
                {
                    for (int j = 0; j < dim; j++)
                    {
                        ret[j] += mul[j + 1] * Y[i];
                    }
                }
                else
                {
                    ModInt x_inv = ModInt.Inverse(X[i]);
                    ModInt pre = 0;
                    for (int j = 0; j < dim; j++)
                    {
                        pre = (pre - mul[j]) * x_inv;
                        ret[j] += pre * Y[i];
                    }
                }
            }
            return ret;
        }
    }

    void swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}

class FastLagrangePolynomial
{
    readonly ModInt[] Y;
    readonly int dim;
    readonly BinomialCoefficient co;
    /// <summary>
    /// x=[0, dim-1)のf(x)により、高速なラグランジュ補間を行います。
    /// </summary>
    /// <param name="Y">f(0),f(1)...,f(dim-1)の値</param>
    public FastLagrangePolynomial(ModInt[] Y)
    {
        this.Y = Y;
        dim = Y.Length;
        co = new BinomialCoefficient(dim - 1);
    }
    /// <summary>
    /// return y=f(x), O(dim).
    /// </summary>
    /// <param name="x">f(x)に代入するxの値</param>
    /// <returns>f(x)の値</returns>
    public ModInt this[ModInt x]
    {
        get
        {
            int t = (int)x.num;
            if (t < dim) return Y[t];

            ModInt[] lmul = new ModInt[dim];
            lmul[0] = 1;
            for (int i = 0; i < dim - 1; i++)
            {
                lmul[i + 1] = lmul[i] * (t - i);
            }
            ModInt[] rmul = new ModInt[dim];
            rmul[dim - 1] = new ModInt(1);
            for (int i = dim - 1; i > 0; i--)
            {
                rmul[i - 1] = rmul[i] * (t - i);
            }

            ModInt ret = new ModInt(0);
            for (int i = 0; i < dim; i++)
            {
                ModInt tmp = Y[i] * lmul[i] * rmul[i] * co.ifact[i] * co.ifact[dim - i - 1];
                if ((dim - i - 1) % 2 == 0) ret += tmp;
                else ret -= tmp;
            }
            return ret;
        }
    }
}

/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
/// <OriginalAuthor>camypaper</OriginalAuthor>
struct ModInt
{
    /// <summary>
    /// 剰余を取る値．
    /// </summary>
    public static long Mod = (int)1e9 + 7;

    /// <summary>
    /// 実際の数値．
    /// </summary>
    public long num;
    /// <summary>
    /// 値が <paramref name="n"/> であるようなインスタンスを構築します．
    /// </summary>
    /// <param name="n">インスタンスが持つ値</param>
    /// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
    public ModInt(long n) { num = n; }
    /// <summary>
    /// このインスタンスの数値を文字列に変換します．
    /// </summary>
    /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
    public override string ToString() { return num.ToString(); }
    public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
    public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
    public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
    public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

    /// <summary>
    /// 与えられた 2 つの数値からべき剰余を計算します．
    /// </summary>
    /// <param name="v">べき乗の底</param>
    /// <param name="k">べき指数</param>
    /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
    public static ModInt Pow(ModInt v, long k) => Pow(v.num, k);

    /// <summary>
    /// 与えられた 2 つの数値からべき剰余を計算します．
    /// </summary>
    /// <param name="v">べき乗の底</param>
    /// <param name="k">べき指数</param>
    /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
    public static ModInt Pow(long v, long k)
    {
        long ret = 1;
        for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
            if ((k & 1) == 1) ret = ret * v % Mod;
        return new ModInt(ret);
    }
    /// <summary>
    /// 与えられた数の逆元を計算します．
    /// </summary>
    /// <param name="v">逆元を取る対象となる数</param>
    /// <returns>逆元となるような値</returns>
    /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
    public static ModInt Inverse(ModInt v) => Pow(v, Mod - 2);
}

class BinomialCoefficient
{
    public ModInt[] fact, ifact;
    /// <summary>
    /// <paramref name="n"/>は <paramref name="Mod"/>未満でお願いします。
    /// </summary>
    /// <param name="n"></param>
    public BinomialCoefficient(ModInt _n)
    {
        int n = (int)_n.num;
        fact = new ModInt[n + 1];
        ifact = new ModInt[n + 1];
        fact[0] = 1;
        for (int i = 1; i <= n; i++)
            fact[i] = fact[i - 1] * i;
        ifact[n] = ModInt.Inverse(fact[n]);
        for (int i = n - 1; i >= 0; i--)
            ifact[i] = ifact[i + 1] * (i + 1);
        ifact[0] = ifact[1];
    }
    public ModInt this[int n, int r]
    {
        get
        {
            if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
            return fact[n] * ifact[n - r] * ifact[r];
        }
    }
    public ModInt RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return this[n + k - 1, k];
    }
}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}


Measured memory_bytes: 31072