using System; namespace Csharp { class Program { static void Main(string[] args) { long N, K; string[] inputs = Console.ReadLine().Split(); N = Convert.ToInt64(inputs[0]); K = Convert.ToInt64(inputs[1]); long R = 0L, C = 0L, result = 1L; string moves = Console.ReadLine(); for (int i = 0; i < K; i++) { switch (moves[i]) { case 'U': --R; break; case 'D': ++R; break; case 'L': --C; break; case 'R': ++C; break; } long lineNo = R + C; long first, dist; if (lineNo < N) { first = 1L + Sigma(lineNo); dist = (lineNo % 2 == 1) ? R : C; } else { first = Sigma(N) + Sigma(N - 1) + Sigma(2L * N - lineNo + 1); dist = ((lineNo % 2 == 1) ? R : C) - (lineNo - N); } result += (first + dist); } Console.WriteLine(result); } static long Sigma(long n) { return n * (n + 1L) / 2L; } } } |