'Problem with Pot task and Power of a number in Kattis with C#

I am stuck with the Pot task from Kattis where I should make a program which calculates following:

X = number1^pow1 + number2^pow2 + … + numberN^powN

X = P1 + P2 + .... + PN

For example my program should convert X = 212 + 1253 to X = 21^2 + 125^3.

This is Kattis sample input and output:

Sample Input: 2, 212, 1253

Sample Output: 1953566

But my code prints out the wrong answer, it prints out 1954378.

Here is my code:

using System;

namespace Pot
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int total = 0;
            Console.WriteLine(n);

            if (n < 1 || n > 10)
            {
                Console.WriteLine("Wrong amount of lines. Choose a number between 1 and 10");
                n = int.Parse(Console.ReadLine());
            }
            else
            {
                int p = int.Parse(Console.ReadLine());
                int x = (int)Math.Pow(p / 10, p % 10);

                for (int i = 1; i < n; i++)
                {
                    p = int.Parse(Console.ReadLine());
                    x = (int)Math.Pow(p / 10, p % 10);
                    total = x + p;
                }
                Console.WriteLine(total);
            }
        }
    }
}

All help is appreciated. Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source