Problem:


Score : 700 points

Problem Statement

Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3.
Let x_{i,j} defined as follows:

x_{1,j} := a_j \quad (1 \leq j \leq N)

x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i)

Find x_{N,1}.

Constraints

2 \leq N \leq 10^6

a_i = 1,2,3 (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
a_1a_2\ldotsa_N

Output

Print x_{N,1}.

Sample Input 1

4
1231

Sample Output 1

1

x_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1.

x_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2.

x_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1.

Finally, x_{4,1} = |0-1| = 1, so the answer is 1.

Sample Input 2

10
2311312312

Sample Output 2

0



Sample input:
4
1231


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

A = set([(0, 0, 0, 0, 0), (0, 0, 0, 1, 0), (0, 0, 0, 1, 2), (0, 0, 0, 2, 0), (0, 0, 0, 3, 0), (0, 0, 1, 0, 0), (0, 0, 1, 0, 2), (0, 0, 1, 1, 0), (0, 0, 1, 1, 2), (0, 0, 1, 2, 0), (0, 0, 1, 2, 2), (0, 0, 1, 3, 0), (0, 0, 1, 3, 2), (0, 0, 2, 0, 0), (0, 0, 2, 1, 0), (0, 0, 2, 1, 2), (0, 0, 2, 2, 0), (0, 0, 2, 3, 0), (0, 0, 2, 3, 2), (0, 0, 3, 0, 0), (0, 0, 3, 2, 0), (0, 0, 3, 2, 2), (0, 0, 3, 3, 0), (0, 1, 0, 0, 0), (0, 1, 0, 0, 2), (0, 1, 0, 1, 0), (0, 1, 0, 1, 2), (0, 1, 0, 2, 0), (0, 1, 0, 2, 2), (0, 1, 0, 3, 0), (0, 1, 1, 0, 0), (0, 1, 1, 0, 2), (0, 1, 1, 1, 0), (0, 1, 1, 1, 2), (0, 1, 1, 2, 0), (0, 1, 1, 2, 2), (0, 1, 1, 3, 0), (0, 1, 1, 3, 2), (0, 1, 2, 0, 0), (0, 1, 2, 0, 2), (0, 1, 2, 1, 0), (0, 1, 2, 1, 2), (0, 1, 2, 2, 0), (0, 1, 2, 2, 2), (0, 1, 2, 3, 2), (0, 1, 3, 0, 2), (0, 1, 3, 1, 0), (0, 1, 3, 1, 2), (0, 1, 3, 2, 0), (0, 1, 3, 2, 2), (0, 1, 3, 3, 0), (0, 1, 3, 3, 2), (0, 2, 0, 0, 0), (0, 2, 0, 1, 0), (0, 2, 0, 1, 2), (0, 2, 0, 2, 0), (0, 2, 0, 3, 0), (0, 2, 0, 3, 2), (0, 2, 1, 0, 0), (0, 2, 1, 0, 2), (0, 2, 1, 1, 0), (0, 2, 1, 1, 2), (0, 2, 1, 2, 0), (0, 2, 1, 2, 2), (0, 2, 1, 3, 0), (0, 2, 1, 3, 2), (0, 2, 2, 0, 0), (0, 2, 2, 1, 0), (0, 2, 2, 1, 2), (0, 2, 2, 2, 0), (0, 2, 2, 3, 0), (0, 2, 2, 3, 2), (0, 2, 3, 0, 0), (0, 2, 3, 0, 2), (0, 2, 3, 1, 0), (0, 2, 3, 1, 2), (0, 2, 3, 2, 0), (0, 2, 3, 2, 2), (0, 2, 3, 3, 2), (0, 3, 0, 0, 0), (0, 3, 0, 1, 0), (0, 3, 0, 1, 2), (0, 3, 0, 2, 0), (0, 3, 0, 2, 2), (0, 3, 0, 3, 0), (0, 3, 1, 0, 0), (0, 3, 1, 0, 2), (0, 3, 1, 1, 0), (0, 3, 1, 1, 2), (0, 3, 1, 2, 0), (0, 3, 1, 2, 2), (0, 3, 1, 3, 0), (0, 3, 1, 3, 2), (0, 3, 2, 0, 0), (0, 3, 2, 0, 2), (0, 3, 2, 2, 0), (0, 3, 2, 2, 2), (0, 3, 2, 3, 0), (0, 3, 3, 0, 0), (0, 3, 3, 1, 0), (0, 3, 3, 1, 2), (0, 3, 3, 3, 0), (1, 0, 0, 0, 1), (1, 0, 0, 1, 1), (1, 0, 0, 1, 3), (1, 0, 0, 2, 1), (1, 0, 0, 2, 3), (1, 0, 0, 3, 1), (1, 0, 1, 0, 1), (1, 0, 1, 1, 1), (1, 0, 1, 1, 3), (1, 0, 1, 2, 1), (1, 0, 1, 2, 3), (1, 0, 1, 3, 1), (1, 0, 1, 3, 3), (1, 0, 2, 0, 1), (1, 0, 2, 0, 3), (1, 0, 2, 1, 1), (1, 0, 2, 1, 3), (1, 0, 2, 2, 1), (1, 0, 2, 2, 3), (1, 0, 2, 3, 1), (1, 0, 2, 3, 3), (1, 0, 3, 0, 1), (1, 0, 3, 1, 1), (1, 0, 3, 1, 3), (1, 0, 3, 3, 1), (1, 1, 0, 0, 1), (1, 1, 0, 1, 1), (1, 1, 0, 1, 3), (1, 1, 0, 2, 1), (1, 1, 0, 2, 3), (1, 1, 0, 3, 1), (1, 1, 0, 3, 3), (1, 1, 1, 0, 1), (1, 1, 1, 0, 3), (1, 1, 1, 1, 1), (1, 1, 1, 2, 1), (1, 1, 1, 2, 3), (1, 1, 1, 3, 1), (1, 1, 2, 0, 1), (1, 1, 2, 0, 3), (1, 1, 2, 1, 1), (1, 1, 2, 1, 3), (1, 1, 2, 2, 1), (1, 1, 2, 2, 3), (1, 1, 2, 3, 1), (1, 1, 2, 3, 3), (1, 1, 3, 0, 1), (1, 1, 3, 0, 3), (1, 1, 3, 1, 1), (1, 1, 3, 2, 1), (1, 1, 3, 2, 3), (1, 1, 3, 3, 1), (1, 2, 0, 0, 1), (1, 2, 0, 0, 3), (1, 2, 0, 1, 1), (1, 2, 0, 1, 3), (1, 2, 0, 2, 1), (1, 2, 0, 2, 3), (1, 2, 0, 3, 1), (1, 2, 1, 0, 1), (1, 2, 1, 1, 1), (1, 2, 1, 1, 3), (1, 2, 1, 2, 1), (1, 2, 1, 2, 3), (1, 2, 1, 3, 1), (1, 2, 1, 3, 3), (1, 2, 2, 0, 1), (1, 2, 2, 0, 3), (1, 2, 2, 1, 1), (1, 2, 2, 1, 3), (1, 2, 2, 2, 1), (1, 2, 2, 2, 3), (1, 2, 2, 3, 1), (1, 2, 2, 3, 3), (1, 2, 3, 0, 3), (1, 2, 3, 1, 1), (1, 2, 3, 1, 3), (1, 2, 3, 2, 1), (1, 2, 3, 2, 3), (1, 2, 3, 3, 1), (1, 2, 3, 3, 3), (1, 3, 0, 0, 1), (1, 3, 0, 1, 1), (1, 3, 0, 1, 3), (1, 3, 0, 2, 1), (1, 3, 0, 2, 3), (1, 3, 0, 3, 1), (1, 3, 1, 0, 1), (1, 3, 1, 0, 3), (1, 3, 1, 1, 1), (1, 3, 1, 2, 1), (1, 3, 1, 2, 3), (1, 3, 1, 3, 1), (1, 3, 2, 0, 1), (1, 3, 2, 0, 3), (1, 3, 2, 1, 1), (1, 3, 2, 1, 3), (1, 3, 2, 2, 1), (1, 3, 2, 2, 3), (1, 3, 2, 3, 1), (1, 3, 2, 3, 3), (1, 3, 3, 0, 1), (1, 3, 3, 1, 1), (1, 3, 3, 2, 1), (1, 3, 3, 2, 3), (1, 3, 3, 3, 1), (2, 0, 0, 0, 2), (2, 0, 0, 1, 0), (2, 0, 0, 1, 2), (2, 0, 0, 2, 2), (2, 0, 0, 3, 2), (2, 0, 1, 0, 0), (2, 0, 1, 0, 2), (2, 0, 1, 1, 0), (2, 0, 1, 1, 2), (2, 0, 1, 2, 0), (2, 0, 1, 2, 2), (2, 0, 1, 3, 0), (2, 0, 1, 3, 2), (2, 0, 2, 0, 2), (2, 0, 2, 1, 0), (2, 0, 2, 1, 2), (2, 0, 2, 2, 2), (2, 0, 2, 3, 0), (2, 0, 2, 3, 2), (2, 0, 3, 0, 2), (2, 0, 3, 1, 0), (2, 0, 3, 1, 2), (2, 0, 3, 2, 0), (2, 0, 3, 2, 2), (2, 0, 3, 3, 2), (2, 1, 0, 0, 0), (2, 1, 0, 0, 2), (2, 1, 0, 1, 0), (2, 1, 0, 1, 2), (2, 1, 0, 2, 0), (2, 1, 0, 2, 2), (2, 1, 0, 3, 0), (2, 1, 1, 0, 0), (2, 1, 1, 0, 2), (2, 1, 1, 1, 0), (2, 1, 1, 1, 2), (2, 1, 1, 2, 0), (2, 1, 1, 2, 2), (2, 1, 1, 3, 0), (2, 1, 1, 3, 2), (2, 1, 2, 0, 0), (2, 1, 2, 0, 2), (2, 1, 2, 1, 0), (2, 1, 2, 1, 2), (2, 1, 2, 2, 0), (2, 1, 2, 2, 2), (2, 1, 2, 3, 2), (2, 1, 3, 0, 2), (2, 1, 3, 1, 0), (2, 1, 3, 1, 2), (2, 1, 3, 2, 0), (2, 1, 3, 2, 2), (2, 1, 3, 3, 0), (2, 1, 3, 3, 2), (2, 2, 0, 0, 2), (2, 2, 0, 1, 0), (2, 2, 0, 1, 2), (2, 2, 0, 2, 2), (2, 2, 0, 3, 0), (2, 2, 0, 3, 2), (2, 2, 1, 0, 0), (2, 2, 1, 0, 2), (2, 2, 1, 1, 0), (2, 2, 1, 1, 2), (2, 2, 1, 2, 0), (2, 2, 1, 2, 2), (2, 2, 1, 3, 0), (2, 2, 1, 3, 2), (2, 2, 2, 0, 2), (2, 2, 2, 1, 0), (2, 2, 2, 1, 2), (2, 2, 2, 2, 2), (2, 2, 2, 3, 0), (2, 2, 2, 3, 2), (2, 2, 3, 0, 0), (2, 2, 3, 0, 2), (2, 2, 3, 1, 0), (2, 2, 3, 1, 2), (2, 2, 3, 2, 0), (2, 2, 3, 2, 2), (2, 2, 3, 3, 2), (2, 3, 0, 0, 2), (2, 3, 0, 2, 0), (2, 3, 0, 2, 2), (2, 3, 0, 3, 2), (2, 3, 1, 0, 0), (2, 3, 1, 0, 2), (2, 3, 1, 1, 0), (2, 3, 1, 1, 2), (2, 3, 1, 2, 0), (2, 3, 1, 2, 2), (2, 3, 1, 3, 0), (2, 3, 1, 3, 2), (2, 3, 2, 0, 0), (2, 3, 2, 0, 2), (2, 3, 2, 1, 0), (2, 3, 2, 1, 2), (2, 3, 2, 2, 0), (2, 3, 2, 2, 2), (2, 3, 2, 3, 2), (2, 3, 3, 0, 2), (2, 3, 3, 1, 0), (2, 3, 3, 1, 2), (2, 3, 3, 2, 0), (2, 3, 3, 2, 2), (2, 3, 3, 3, 2), (3, 0, 0, 0, 3), (3, 0, 0, 2, 1), (3, 0, 0, 2, 3), (3, 0, 0, 3, 3), (3, 0, 1, 0, 3), (3, 0, 1, 1, 1), (3, 0, 1, 1, 3), (3, 0, 1, 3, 1), (3, 0, 1, 3, 3), (3, 0, 2, 0, 1), (3, 0, 2, 0, 3), (3, 0, 2, 1, 1), (3, 0, 2, 1, 3), (3, 0, 2, 2, 1), (3, 0, 2, 2, 3), (3, 0, 2, 3, 1), (3, 0, 2, 3, 3), (3, 0, 3, 0, 3), (3, 0, 3, 1, 1), (3, 0, 3, 1, 3), (3, 0, 3, 2, 1), (3, 0, 3, 2, 3), (3, 0, 3, 3, 3), (3, 1, 0, 0, 1), (3, 1, 0, 1, 1), (3, 1, 0, 1, 3), (3, 1, 0, 2, 1), (3, 1, 0, 2, 3), (3, 1, 0, 3, 1), (3, 1, 0, 3, 3), (3, 1, 1, 0, 1), (3, 1, 1, 0, 3), (3, 1, 1, 1, 3), (3, 1, 1, 2, 1), (3, 1, 1, 2, 3), (3, 1, 1, 3, 3), (3, 1, 2, 0, 1), (3, 1, 2, 0, 3), (3, 1, 2, 1, 1), (3, 1, 2, 1, 3), (3, 1, 2, 2, 1), (3, 1, 2, 2, 3), (3, 1, 2, 3, 1), (3, 1, 2, 3, 3), (3, 1, 3, 0, 1), (3, 1, 3, 0, 3), (3, 1, 3, 1, 3), (3, 1, 3, 2, 1), (3, 1, 3, 2, 3), (3, 1, 3, 3, 3), (3, 2, 0, 0, 1), (3, 2, 0, 0, 3), (3, 2, 0, 1, 1), (3, 2, 0, 1, 3), (3, 2, 0, 2, 1), (3, 2, 0, 2, 3), (3, 2, 0, 3, 1), (3, 2, 1, 0, 1), (3, 2, 1, 1, 1), (3, 2, 1, 1, 3), (3, 2, 1, 2, 1), (3, 2, 1, 2, 3), (3, 2, 1, 3, 1), (3, 2, 1, 3, 3), (3, 2, 2, 0, 1), (3, 2, 2, 0, 3), (3, 2, 2, 1, 1), (3, 2, 2, 1, 3), (3, 2, 2, 2, 1), (3, 2, 2, 2, 3), (3, 2, 2, 3, 1), (3, 2, 2, 3, 3), (3, 2, 3, 0, 3), (3, 2, 3, 1, 1), (3, 2, 3, 1, 3), (3, 2, 3, 2, 1), (3, 2, 3, 2, 3), (3, 2, 3, 3, 1), (3, 2, 3, 3, 3), (3, 3, 0, 0, 3), (3, 3, 0, 1, 1), (3, 3, 0, 1, 3), (3, 3, 0, 3, 3), (3, 3, 1, 0, 1), (3, 3, 1, 0, 3), (3, 3, 1, 1, 3), (3, 3, 1, 2, 1), (3, 3, 1, 2, 3), (3, 3, 1, 3, 3), (3, 3, 2, 0, 1), (3, 3, 2, 0, 3), (3, 3, 2, 1, 1), (3, 3, 2, 1, 3), (3, 3, 2, 2, 1), (3, 3, 2, 2, 3), (3, 3, 2, 3, 1), (3, 3, 2, 3, 3), (3, 3, 3, 0, 3), (3, 3, 3, 1, 3), (3, 3, 3, 2, 1), (3, 3, 3, 2, 3), (3, 3, 3, 3, 3)])
B = set([(0, 0, 0, 0, 1), (0, 0, 0, 1, 1), (0, 0, 0, 1, 3), (0, 0, 0, 2, 1), (0, 0, 0, 2, 3), (0, 0, 0, 3, 1), (0, 0, 1, 0, 1), (0, 0, 1, 0, 3), (0, 0, 1, 1, 1), (0, 0, 1, 1, 3), (0, 0, 1, 2, 1), (0, 0, 1, 2, 3), (0, 0, 1, 3, 1), (0, 0, 1, 3, 3), (0, 0, 2, 0, 1), (0, 0, 2, 0, 3), (0, 0, 2, 1, 1), (0, 0, 2, 1, 3), (0, 0, 2, 2, 1), (0, 0, 2, 2, 3), (0, 0, 2, 3, 1), (0, 0, 2, 3, 3), (0, 0, 3, 0, 1), (0, 0, 3, 1, 1), (0, 0, 3, 1, 3), (0, 0, 3, 2, 1), (0, 0, 3, 2, 3), (0, 0, 3, 3, 1), (0, 1, 0, 0, 1), (0, 1, 0, 0, 3), (0, 1, 0, 1, 1), (0, 1, 0, 1, 3), (0, 1, 0, 2, 1), (0, 1, 0, 2, 3), (0, 1, 0, 3, 1), (0, 1, 0, 3, 3), (0, 1, 1, 0, 1), (0, 1, 1, 0, 3), (0, 1, 1, 1, 1), (0, 1, 1, 1, 3), (0, 1, 1, 2, 1), (0, 1, 1, 2, 3), (0, 1, 1, 3, 1), (0, 1, 1, 3, 3), (0, 1, 2, 0, 1), (0, 1, 2, 0, 3), (0, 1, 2, 1, 1), (0, 1, 2, 1, 3), (0, 1, 2, 2, 1), (0, 1, 2, 2, 3), (0, 1, 2, 3, 1), (0, 1, 2, 3, 3), (0, 1, 3, 0, 1), (0, 1, 3, 0, 3), (0, 1, 3, 1, 1), (0, 1, 3, 1, 3), (0, 1, 3, 2, 1), (0, 1, 3, 2, 3), (0, 1, 3, 3, 1), (0, 1, 3, 3, 3), (0, 2, 0, 0, 1), (0, 2, 0, 0, 3), (0, 2, 0, 1, 1), (0, 2, 0, 1, 3), (0, 2, 0, 2, 1), (0, 2, 0, 2, 3), (0, 2, 0, 3, 1), (0, 2, 0, 3, 3), (0, 2, 1, 0, 1), (0, 2, 1, 0, 3), (0, 2, 1, 1, 1), (0, 2, 1, 1, 3), (0, 2, 1, 2, 1), (0, 2, 1, 2, 3), (0, 2, 1, 3, 1), (0, 2, 1, 3, 3), (0, 2, 2, 0, 1), (0, 2, 2, 0, 3), (0, 2, 2, 1, 1), (0, 2, 2, 1, 3), (0, 2, 2, 2, 1), (0, 2, 2, 2, 3), (0, 2, 2, 3, 1), (0, 2, 2, 3, 3), (0, 2, 3, 0, 1), (0, 2, 3, 0, 3), (0, 2, 3, 1, 1), (0, 2, 3, 1, 3), (0, 2, 3, 2, 1), (0, 2, 3, 2, 3), (0, 2, 3, 3, 1), (0, 2, 3, 3, 3), (0, 3, 0, 0, 1), (0, 3, 0, 1, 1), (0, 3, 0, 1, 3), (0, 3, 0, 2, 1), (0, 3, 0, 2, 3), (0, 3, 0, 3, 1), (0, 3, 1, 0, 1), (0, 3, 1, 0, 3), (0, 3, 1, 1, 1), (0, 3, 1, 1, 3), (0, 3, 1, 2, 1), (0, 3, 1, 2, 3), (0, 3, 1, 3, 1), (0, 3, 1, 3, 3), (0, 3, 2, 0, 1), (0, 3, 2, 0, 3), (0, 3, 2, 1, 1), (0, 3, 2, 1, 3), (0, 3, 2, 2, 1), (0, 3, 2, 2, 3), (0, 3, 2, 3, 1), (0, 3, 2, 3, 3), (0, 3, 3, 0, 1), (0, 3, 3, 1, 1), (0, 3, 3, 1, 3), (0, 3, 3, 2, 1), (0, 3, 3, 2, 3), (0, 3, 3, 3, 1), (1, 0, 0, 0, 0), (1, 0, 0, 0, 2), (1, 0, 0, 1, 0), (1, 0, 0, 1, 2), (1, 0, 0, 2, 0), (1, 0, 0, 2, 2), (1, 0, 0, 3, 0), (1, 0, 0, 3, 2), (1, 0, 1, 0, 0), (1, 0, 1, 0, 2), (1, 0, 1, 1, 0), (1, 0, 1, 1, 2), (1, 0, 1, 2, 0), (1, 0, 1, 2, 2), (1, 0, 1, 3, 0), (1, 0, 1, 3, 2), (1, 0, 2, 0, 0), (1, 0, 2, 0, 2), (1, 0, 2, 1, 0), (1, 0, 2, 1, 2), (1, 0, 2, 2, 0), (1, 0, 2, 2, 2), (1, 0, 2, 3, 0), (1, 0, 2, 3, 2), (1, 0, 3, 0, 0), (1, 0, 3, 0, 2), (1, 0, 3, 1, 0), (1, 0, 3, 1, 2), (1, 0, 3, 2, 0), (1, 0, 3, 2, 2), (1, 0, 3, 3, 0), (1, 0, 3, 3, 2), (1, 1, 0, 0, 0), (1, 1, 0, 0, 2), (1, 1, 0, 1, 0), (1, 1, 0, 1, 2), (1, 1, 0, 2, 0), (1, 1, 0, 2, 2), (1, 1, 0, 3, 0), (1, 1, 0, 3, 2), (1, 1, 1, 0, 0), (1, 1, 1, 0, 2), (1, 1, 1, 1, 0), (1, 1, 1, 1, 2), (1, 1, 1, 2, 0), (1, 1, 1, 2, 2), (1, 1, 1, 3, 0), (1, 1, 1, 3, 2), (1, 1, 2, 0, 0), (1, 1, 2, 0, 2), (1, 1, 2, 1, 0), (1, 1, 2, 1, 2), (1, 1, 2, 2, 0), (1, 1, 2, 2, 2), (1, 1, 2, 3, 0), (1, 1, 2, 3, 2), (1, 1, 3, 0, 0), (1, 1, 3, 0, 2), (1, 1, 3, 1, 0), (1, 1, 3, 1, 2), (1, 1, 3, 2, 0), (1, 1, 3, 2, 2), (1, 1, 3, 3, 0), (1, 1, 3, 3, 2), (1, 2, 0, 0, 0), (1, 2, 0, 0, 2), (1, 2, 0, 1, 0), (1, 2, 0, 1, 2), (1, 2, 0, 2, 0), (1, 2, 0, 2, 2), (1, 2, 0, 3, 0), (1, 2, 0, 3, 2), (1, 2, 1, 0, 0), (1, 2, 1, 0, 2), (1, 2, 1, 1, 0), (1, 2, 1, 1, 2), (1, 2, 1, 2, 0), (1, 2, 1, 2, 2), (1, 2, 1, 3, 0), (1, 2, 1, 3, 2), (1, 2, 2, 0, 0), (1, 2, 2, 0, 2), (1, 2, 2, 1, 0), (1, 2, 2, 1, 2), (1, 2, 2, 2, 0), (1, 2, 2, 2, 2), (1, 2, 2, 3, 0), (1, 2, 2, 3, 2), (1, 2, 3, 0, 0), (1, 2, 3, 0, 2), (1, 2, 3, 1, 0), (1, 2, 3, 1, 2), (1, 2, 3, 2, 0), (1, 2, 3, 2, 2), (1, 2, 3, 3, 0), (1, 2, 3, 3, 2), (1, 3, 0, 0, 0), (1, 3, 0, 0, 2), (1, 3, 0, 1, 0), (1, 3, 0, 1, 2), (1, 3, 0, 2, 0), (1, 3, 0, 2, 2), (1, 3, 0, 3, 0), (1, 3, 0, 3, 2), (1, 3, 1, 0, 0), (1, 3, 1, 0, 2), (1, 3, 1, 1, 0), (1, 3, 1, 1, 2), (1, 3, 1, 2, 0), (1, 3, 1, 2, 2), (1, 3, 1, 3, 0), (1, 3, 1, 3, 2), (1, 3, 2, 0, 0), (1, 3, 2, 0, 2), (1, 3, 2, 1, 0), (1, 3, 2, 1, 2), (1, 3, 2, 2, 0), (1, 3, 2, 2, 2), (1, 3, 2, 3, 0), (1, 3, 2, 3, 2), (1, 3, 3, 0, 0), (1, 3, 3, 0, 2), (1, 3, 3, 1, 0), (1, 3, 3, 1, 2), (1, 3, 3, 2, 0), (1, 3, 3, 2, 2), (1, 3, 3, 3, 0), (1, 3, 3, 3, 2), (2, 0, 0, 0, 1), (2, 0, 0, 0, 3), (2, 0, 0, 1, 1), (2, 0, 0, 1, 3), (2, 0, 0, 2, 1), (2, 0, 0, 2, 3), (2, 0, 0, 3, 1), (2, 0, 0, 3, 3), (2, 0, 1, 0, 1), (2, 0, 1, 0, 3), (2, 0, 1, 1, 1), (2, 0, 1, 1, 3), (2, 0, 1, 2, 1), (2, 0, 1, 2, 3), (2, 0, 1, 3, 1), (2, 0, 1, 3, 3), (2, 0, 2, 0, 1), (2, 0, 2, 0, 3), (2, 0, 2, 1, 1), (2, 0, 2, 1, 3), (2, 0, 2, 2, 1), (2, 0, 2, 2, 3), (2, 0, 2, 3, 1), (2, 0, 2, 3, 3), (2, 0, 3, 0, 1), (2, 0, 3, 0, 3), (2, 0, 3, 1, 1), (2, 0, 3, 1, 3), (2, 0, 3, 2, 1), (2, 0, 3, 2, 3), (2, 0, 3, 3, 1), (2, 0, 3, 3, 3), (2, 1, 0, 0, 1), (2, 1, 0, 0, 3), (2, 1, 0, 1, 1), (2, 1, 0, 1, 3), (2, 1, 0, 2, 1), (2, 1, 0, 2, 3), (2, 1, 0, 3, 1), (2, 1, 0, 3, 3), (2, 1, 1, 0, 1), (2, 1, 1, 0, 3), (2, 1, 1, 1, 1), (2, 1, 1, 1, 3), (2, 1, 1, 2, 1), (2, 1, 1, 2, 3), (2, 1, 1, 3, 1), (2, 1, 1, 3, 3), (2, 1, 2, 0, 1), (2, 1, 2, 0, 3), (2, 1, 2, 1, 1), (2, 1, 2, 1, 3), (2, 1, 2, 2, 1), (2, 1, 2, 2, 3), (2, 1, 2, 3, 1), (2, 1, 2, 3, 3), (2, 1, 3, 0, 1), (2, 1, 3, 0, 3), (2, 1, 3, 1, 1), (2, 1, 3, 1, 3), (2, 1, 3, 2, 1), (2, 1, 3, 2, 3), (2, 1, 3, 3, 1), (2, 1, 3, 3, 3), (2, 2, 0, 0, 1), (2, 2, 0, 0, 3), (2, 2, 0, 1, 1), (2, 2, 0, 1, 3), (2, 2, 0, 2, 1), (2, 2, 0, 2, 3), (2, 2, 0, 3, 1), (2, 2, 0, 3, 3), (2, 2, 1, 0, 1), (2, 2, 1, 0, 3), (2, 2, 1, 1, 1), (2, 2, 1, 1, 3), (2, 2, 1, 2, 1), (2, 2, 1, 2, 3), (2, 2, 1, 3, 1), (2, 2, 1, 3, 3), (2, 2, 2, 0, 1), (2, 2, 2, 0, 3), (2, 2, 2, 1, 1), (2, 2, 2, 1, 3), (2, 2, 2, 2, 1), (2, 2, 2, 2, 3), (2, 2, 2, 3, 1), (2, 2, 2, 3, 3), (2, 2, 3, 0, 1), (2, 2, 3, 0, 3), (2, 2, 3, 1, 1), (2, 2, 3, 1, 3), (2, 2, 3, 2, 1), (2, 2, 3, 2, 3), (2, 2, 3, 3, 1), (2, 2, 3, 3, 3), (2, 3, 0, 0, 1), (2, 3, 0, 0, 3), (2, 3, 0, 1, 1), (2, 3, 0, 1, 3), (2, 3, 0, 2, 1), (2, 3, 0, 2, 3), (2, 3, 0, 3, 1), (2, 3, 0, 3, 3), (2, 3, 1, 0, 1), (2, 3, 1, 0, 3), (2, 3, 1, 1, 1), (2, 3, 1, 1, 3), (2, 3, 1, 2, 1), (2, 3, 1, 2, 3), (2, 3, 1, 3, 1), (2, 3, 1, 3, 3), (2, 3, 2, 0, 1), (2, 3, 2, 0, 3), (2, 3, 2, 1, 1), (2, 3, 2, 1, 3), (2, 3, 2, 2, 1), (2, 3, 2, 2, 3), (2, 3, 2, 3, 1), (2, 3, 2, 3, 3), (2, 3, 3, 0, 1), (2, 3, 3, 0, 3), (2, 3, 3, 1, 1), (2, 3, 3, 1, 3), (2, 3, 3, 2, 1), (2, 3, 3, 2, 3), (2, 3, 3, 3, 1), (2, 3, 3, 3, 3), (3, 0, 0, 0, 2), (3, 0, 0, 1, 0), (3, 0, 0, 1, 2), (3, 0, 0, 2, 0), (3, 0, 0, 2, 2), (3, 0, 0, 3, 2), (3, 0, 1, 0, 0), (3, 0, 1, 0, 2), (3, 0, 1, 1, 0), (3, 0, 1, 1, 2), (3, 0, 1, 2, 0), (3, 0, 1, 2, 2), (3, 0, 1, 3, 0), (3, 0, 1, 3, 2), (3, 0, 2, 0, 0), (3, 0, 2, 0, 2), (3, 0, 2, 1, 0), (3, 0, 2, 1, 2), (3, 0, 2, 2, 0), (3, 0, 2, 2, 2), (3, 0, 2, 3, 0), (3, 0, 2, 3, 2), (3, 0, 3, 0, 2), (3, 0, 3, 1, 0), (3, 0, 3, 1, 2), (3, 0, 3, 2, 0), (3, 0, 3, 2, 2), (3, 0, 3, 3, 2), (3, 1, 0, 0, 0), (3, 1, 0, 0, 2), (3, 1, 0, 1, 0), (3, 1, 0, 1, 2), (3, 1, 0, 2, 0), (3, 1, 0, 2, 2), (3, 1, 0, 3, 0), (3, 1, 0, 3, 2), (3, 1, 1, 0, 0), (3, 1, 1, 0, 2), (3, 1, 1, 1, 0), (3, 1, 1, 1, 2), (3, 1, 1, 2, 0), (3, 1, 1, 2, 2), (3, 1, 1, 3, 0), (3, 1, 1, 3, 2), (3, 1, 2, 0, 0), (3, 1, 2, 0, 2), (3, 1, 2, 1, 0), (3, 1, 2, 1, 2), (3, 1, 2, 2, 0), (3, 1, 2, 2, 2), (3, 1, 2, 3, 0), (3, 1, 2, 3, 2), (3, 1, 3, 0, 0), (3, 1, 3, 0, 2), (3, 1, 3, 1, 0), (3, 1, 3, 1, 2), (3, 1, 3, 2, 0), (3, 1, 3, 2, 2), (3, 1, 3, 3, 0), (3, 1, 3, 3, 2), (3, 2, 0, 0, 0), (3, 2, 0, 0, 2), (3, 2, 0, 1, 0), (3, 2, 0, 1, 2), (3, 2, 0, 2, 0), (3, 2, 0, 2, 2), (3, 2, 0, 3, 0), (3, 2, 0, 3, 2), (3, 2, 1, 0, 0), (3, 2, 1, 0, 2), (3, 2, 1, 1, 0), (3, 2, 1, 1, 2), (3, 2, 1, 2, 0), (3, 2, 1, 2, 2), (3, 2, 1, 3, 0), (3, 2, 1, 3, 2), (3, 2, 2, 0, 0), (3, 2, 2, 0, 2), (3, 2, 2, 1, 0), (3, 2, 2, 1, 2), (3, 2, 2, 2, 0), (3, 2, 2, 2, 2), (3, 2, 2, 3, 0), (3, 2, 2, 3, 2), (3, 2, 3, 0, 0), (3, 2, 3, 0, 2), (3, 2, 3, 1, 0), (3, 2, 3, 1, 2), (3, 2, 3, 2, 0), (3, 2, 3, 2, 2), (3, 2, 3, 3, 0), (3, 2, 3, 3, 2), (3, 3, 0, 0, 2), (3, 3, 0, 1, 0), (3, 3, 0, 1, 2), (3, 3, 0, 2, 0), (3, 3, 0, 2, 2), (3, 3, 0, 3, 2), (3, 3, 1, 0, 0), (3, 3, 1, 0, 2), (3, 3, 1, 1, 0), (3, 3, 1, 1, 2), (3, 3, 1, 2, 0), (3, 3, 1, 2, 2), (3, 3, 1, 3, 0), (3, 3, 1, 3, 2), (3, 3, 2, 0, 0), (3, 3, 2, 0, 2), (3, 3, 2, 1, 0), (3, 3, 2, 1, 2), (3, 3, 2, 2, 0), (3, 3, 2, 2, 2), (3, 3, 2, 3, 0), (3, 3, 2, 3, 2), (3, 3, 3, 0, 2), (3, 3, 3, 1, 0), (3, 3, 3, 1, 2), (3, 3, 3, 2, 0), (3, 3, 3, 2, 2), (3, 3, 3, 3, 2)])
C = set([(0, 0, 0, 0, 2), (0, 0, 0, 2, 2), (0, 0, 0, 3, 2), (0, 0, 2, 0, 2), (0, 0, 2, 2, 2), (0, 0, 3, 0, 2), (0, 0, 3, 1, 0), (0, 0, 3, 1, 2), (0, 0, 3, 3, 2), (0, 1, 0, 3, 2), (0, 1, 2, 3, 0), (0, 1, 3, 0, 0), (0, 2, 0, 0, 2), (0, 2, 0, 2, 2), (0, 2, 2, 0, 2), (0, 2, 2, 2, 2), (0, 2, 3, 3, 0), (0, 3, 0, 0, 2), (0, 3, 0, 3, 2), (0, 3, 2, 1, 0), (0, 3, 2, 1, 2), (0, 3, 2, 3, 2), (0, 3, 3, 0, 2), (0, 3, 3, 2, 0), (0, 3, 3, 2, 2), (0, 3, 3, 3, 2), (1, 0, 0, 0, 3), (1, 0, 0, 3, 3), (1, 0, 1, 0, 3), (1, 0, 3, 0, 3), (1, 0, 3, 2, 1), (1, 0, 3, 2, 3), (1, 0, 3, 3, 3), (1, 1, 0, 0, 3), (1, 1, 1, 1, 3), (1, 1, 1, 3, 3), (1, 1, 3, 1, 3), (1, 1, 3, 3, 3), (1, 2, 0, 3, 3), (1, 2, 1, 0, 3), (1, 2, 3, 0, 1), (1, 3, 0, 0, 3), (1, 3, 0, 3, 3), (1, 3, 1, 1, 3), (1, 3, 1, 3, 3), (1, 3, 3, 0, 3), (1, 3, 3, 1, 3), (1, 3, 3, 3, 3), (2, 0, 0, 0, 0), (2, 0, 0, 2, 0), (2, 0, 0, 3, 0), (2, 0, 2, 0, 0), (2, 0, 2, 2, 0), (2, 0, 3, 0, 0), (2, 0, 3, 3, 0), (2, 1, 0, 3, 2), (2, 1, 2, 3, 0), (2, 1, 3, 0, 0), (2, 2, 0, 0, 0), (2, 2, 0, 2, 0), (2, 2, 2, 0, 0), (2, 2, 2, 2, 0), (2, 2, 3, 3, 0), (2, 3, 0, 0, 0), (2, 3, 0, 1, 0), (2, 3, 0, 1, 2), (2, 3, 0, 3, 0), (2, 3, 2, 3, 0), (2, 3, 3, 0, 0), (2, 3, 3, 3, 0), (3, 0, 0, 0, 1), (3, 0, 0, 1, 1), (3, 0, 0, 1, 3), (3, 0, 0, 3, 1), (3, 0, 1, 0, 1), (3, 0, 1, 2, 1), (3, 0, 1, 2, 3), (3, 0, 3, 0, 1), (3, 0, 3, 3, 1), (3, 1, 0, 0, 3), (3, 1, 1, 1, 1), (3, 1, 1, 3, 1), (3, 1, 3, 1, 1), (3, 1, 3, 3, 1), (3, 2, 0, 3, 3), (3, 2, 1, 0, 3), (3, 2, 3, 0, 1), (3, 3, 0, 0, 1), (3, 3, 0, 2, 1), (3, 3, 0, 2, 3), (3, 3, 0, 3, 1), (3, 3, 1, 1, 1), (3, 3, 1, 3, 1), (3, 3, 3, 0, 1), (3, 3, 3, 1, 1), (3, 3, 3, 3, 1)])


def five(s):
    x = ''
    for p in range(len(s)-4):
        t = (s[p], s[p+1], s[p+2], s[p+3], s[p+4])
        if t in A:
            x += '0'
        elif t in B:
            x += '1'
        else:
            x += '2'
    return x
    
def four(s):
    x = ''
    for p in range(len(s)-1):
        x += str(abs(int(s[p])-int(s[p+1])))
    return x
    
N = int(input())
s = input()
    
while len(s) != 1:
    if len(s) >= 5:
        s = five(s)
    else:
        s = four(s)
            
print(s)


"""
A = []
B = []
C = []

for i in range(4):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for m  in range(4):
                    x = abs(abs(abs(abs(i-j)-abs(j-k))-abs(abs(j-k)-abs(k-l)))-abs(abs(abs(j-k)-abs(k-l))-abs(abs(k-l)-abs(l-m))))
                    if x == 0:
                        A.append((i,j,k,l,m))
                    if x == 1:
                        B.append((i,j,k,l,m))              
                    if x == 2:
                        C.append((i,j,k,l,m))      
                
print(A)
print(B)
print(C)
"""

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[int(i) for i in input()]
while len(l)>1:
    t=l[:]
    l=[]
    i=1
    while len(t)>i:
        if t[i-1]!=0 or t[i]!=0:
            l.append(abs(t[i-1]-t[i]))
        i+=1
if len(l)==0:
    print(0)
else:
    print(l[0])

Submission status: Time Limit Exceeded

Solution code:
def main():
  import numpy as np

  N = int(input())
  x = np.array([int(i) for i in input()])
  for i in range(N-1):
      x_ = np.roll(x, -1)
      x = abs(x - x_)

  print(x[0])

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_string = input()
a = []
for str1 in a_string:
    a.append(int(str1))

temp = a
len_temp = len(a)
if len(a) > n:
    print(0)
else:
    for i in range(n-1):
        pre = temp
        temp = []
        for j in range(len_temp-1):
            temp.append(abs(pre[j] - pre[j+1]))
            
        len_temp = len(temp)

    print(temp[0])

Submission status: Time Limit Exceeded

Solution code:
input()
z=[int(i) for i in input()]
while len(z)!=1:
    t=[]
    for num,(x,y) in enumerate(zip(z[:-1],z[1:])):
        t+=[abs(x-y)]
    z=t
print(*z)

Submission status: Time Limit Exceeded

Solution code:
a=input()
n=input()
current_list=[]
for i in n :
  current_list.append(int(i))
 
while (len(current_list)>1) :
  current=[]
  for i,num in enumerate(current_list[:-1]) :
    current.append(abs(num-current_list[i+1]))
  
  current_list=current
  
 
print (current_list[0])

Submission status: Time Limit Exceeded

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=list(S())

  while True:
    if len(l)==1:
      return l[0]
    a=[]
    x=-1
    for i in range(len(l)-1):
      b=abs(int(l[i+1])-int(l[i]))
      if x!=b and b!=0:
        a.append(b)
    l=a

# main()
print(main())

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
b = str(input())
int_list =list(map(int, list(b)))
for k in range(N-1):
    new_li = []
    for n in range(len(int_list)-1):
        new_li.append(abs(int_list[n]-int_list[n+1]))
    int_list = new_li

print(int_list[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
num = [int(c) for c in s]

temp = num

I = N-1
for i in range(I):
  J = len(temp) - 1
  result=[abs(l - r) for l,r in zip(temp[1:],temp)]
  temp = result

print(result[0])

Submission status: Time Limit Exceeded

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=list(S())

  while True:
    if len(l)==1:
      return l[0]
    a=[]
    x=-1
    for i in range(len(l)-1):
      b=abs(int(l[i+1])-int(l[i]))
      if x!=b:
        a.append(b)
    l=a

# main()
print(main())

Submission status: Time Limit Exceeded

Solution code:
a=input()
n=input()
current_list=[]
for i in n :
  current_list.append(int(i))
 
while (len(current_list)!=1) :
  current=[]
  for i,num in enumerate(current_list[:-1]) :
    current.append(abs(num-current_list[i+1]))
  
  current_list=current
  
 
print (current_list[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
xxx = [list(map(int, list(input())))]

for i in range(len(xxx[0]) - 1):
    xxx.append([])
    for j in range(len(xxx[i]) - 1):
        xxx[i + 1].append(abs(xxx[i][j] - xxx[i][j + 1]))
print(xxx[-1][-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(2147483647)

n = int(input())
a = input()
x1 = 0
ans = ""

for k in range(n-1):
    for v in range(n-1-k):
        x1 = int(a[v])-int(a[v+1])
        if x1 <= 0:
            x1 = -x1
        ans += str(x1)
    a = ans
    ans = ""
print(a)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a_=input()
a=[]
for i in range(n):
    a.append(int(a_[i]))
while n!=0:
    for i in range(n-1):
        a[i]=abs(a[i]-a[i+1])
    n-=1
print(a[0])

Submission status: Time Limit Exceeded

Solution code:
# a, b, c= map(int, input().split())
n = int(input())
an = str(input())

# n=4
# an="1231"
# n=10
# an="2311312312"
# n=100
# an="2311312312231131231223113123122311312312231131231223113123122311312312231131231223113123122311312312"


# print(n)
# print(an[1:2])
xx = [[-1 for i in range(n+1)] for j in range(n+1)]

def x(i,j):
    global an;
    global xx;
    if xx[i][j] >= 0:
        return xx[i][j]
    elif i == 1:
        xx[i][j] = int(an[j-1:j])
        return xx[i][j]
    else:
        xx[i][j] = abs(x(i-1,j) - x(i-1,j+1))
        return xx[i][j]





# print(x(1,4))
print(x(n,1))

Submission status: Time Limit Exceeded

Solution code:
def func(x1, x2):
    x = abs(x1 - x2)
    return x

def getVal(n, array_str):
    x_org = [0] * n
    i = 0
    for c in array_str:
        x_org[i] = int(c)
        i = i + 1
    # x_org = array
    for i in range(n-1):
        x_next = [0] * (n-i-1)
        for j in range(n-i-1):
            x_next[j] = func(x_org[j], x_org[j+1])
        x_org = x_next
    return x_next[0]
        

# print(getVal(4, "1231"))
# print(getVal(10, "2311312312"))

n = int(input())
ar = str(input())
print(getVal(n, ar))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
S = input().strip()
A = list(map(int, list(S)))

for i in range(N):
  for j in range(N-i-1):
    A[j] = abs(A[j]-A[j+1])
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
x = np.array([int(i) for i in input()])
for i in range(N-1):
    x_ = np.roll(x, -1)
    x = np.delete(abs(x - x_), -1)

print(x[0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
numbers = input()
input_arr = np.array([int(i) for i in numbers])
def myfunc(arr):
    if(len(arr)) == 1:
        return arr[0]
    return myfunc(np.abs(arr[1:] - arr[:-1]))
print(myfunc(input_arr))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int,list(input())))
for i in range(n-2):
    for j in range(len(s)-1):
        s.append(abs(s[0]-s[1]))
        s.pop(0)
        #print(s)
    s.pop(0)
    #print(s)
print(abs(s[0]-s[1]))

Submission status: Time Limit Exceeded

Solution code:
a=input()
list_1=input()
list_2=list(list_1)
for k in range(int(a)):
  list_2[k]=int(list_2[k])
count=len(list_2)-1
for k in range(int(a)-1):
  for s in range(0,count):
    t=list_2[s]-list_2[s+1]
    list_2[s]=abs(t)
  del list_2[-1]
  count-=1
  if count>=1:
    continue
  elif count==0:
    print(list_2[0])
    break

Submission status: Time Limit Exceeded

Solution code:
# a, b, c= map(int, input().split())
n = int(input())
an = str(input())

# n=4
# an="1231"
# n=10
# an="2311312312"
# n=100
# an="2311312312231131231223113123122311312312231131231223113123122311312312231131231223113123122311312312"


# print(n)
# print(an[1:2])
xx = [[-1 for i in range(n+1)] for j in range(n+1)]

def x(i,j):
    global an;
    global xx;
    if xx[i][j] >= 0:
        return xx[i][j]
    elif i == 1:
        xx[i][j] = int(an[j-1:j])
        return int(an[j-1:j])
    else:
        xx[i][j] = abs(x(i-1,j) - x(i-1,j+1))
        return abs(x(i-1,j) - x(i-1,j+1))





# print(x(1,4))
print(x(n,1))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N=int(stdin.readline().rstrip())
An = [int(x) for x in list(stdin.readline().rstrip())]
for i in range(N-1):
  An1 = [abs(An[x]-An[x+1]) for x in range(N-i-1)]
  An = An1
print(An[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
b = str(input())

int_list =[]
for l in list(b):
    int_list.append(int(l))
    
def cal_next_layer(li):
    new_li = []
    for n in range(len(li)-1):
        new_li.append(abs(li[n]-li[n+1]))
    return new_li

for k in range(N-1):
    int_list = cal_next_layer(int_list)
    
print(int_list[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, list(input())))

for c in range(N-1, 0, -1):
    kari = [0] * c
    for co in range(c):
        kari[co] = abs(a[co] - a[co + 1])
    a = kari[:]
print(a[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = tuple(input())
L = (int(a[0]),)
for i in range(N-1):
    T = (int(a[i+1]),)
    for j in range(i+1):
        T = T + (abs(L[j]-T[j]),)
    L = T
print(L[N-1])

Submission status: Time Limit Exceeded

Solution code:
def work(s):
    t = []

    for i in range(len(s) - 1):
        t.append(abs(s[i] - s[i + 1]))

    if len(s) == 1:
        print(s[0])
        return
    else:
        work(t)


n = int(input())
s = input()

lst = []

for i in range(n):
    lst.append(int(s[i]))

work(lst)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x_list = [int(x) for x in input()]

for i in range(1,n):
  x_list = [abs(x_list[j]-x_list[j+1]) for j in range(n-i)]

print(x_list[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, list(input())))
x = [a]
for i in range(1, n + 1):
    cur = []
    for j in range(n - i):
        cur.append(abs(x[i-1][j] - x[i-1][j+1]))
    x.append(cur)
print(x[-2][0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
a = input()
la = np.array([int(c) for c in a])

def f(l1):
    return np.abs(np.diff(l1))

while(len(la)> 1):
   la =  f(la)

print(*la)

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
s = input()
l1 =[list(map(int,s))]
for i in range(0,t-1):
    x = []
    for j in range(0,len(l1[i]) - 1):
        n = abs(l1[i][j]-l1[i][j+1])
        x.append(n)
    l1.append(x)
print(l1[-1][0])

Submission status: Time Limit Exceeded

Solution code:
def calc(nums):
  if len(nums) == 1:
    return nums
  
  result = []
  for j in range(len(nums) - 1):
    result.append(abs(nums[j] - nums[j + 1]))
  return calc(result)

  
N = int(input())
num_strs = input()
nums = []

for num_str in num_strs:
  nums.append(int(num_str))

x = calc(nums)
print(x[0])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=input()
h=[0]*n
for i in range(0,n):
    h[i]=int(l[i])
d=[[0 for _ in range(n)] for k in range(n)]
for i in range(n):
    d[0][i]=h[i]
for i in range(1,n):
    for j in range(0,n-i):
        d[i][j]=abs(d[i-1][j]-d[i-1][j+1])
print(d[n-1][0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
X = list(map(int, list(input())))

while len(X) != 1:
    X = [abs(i - j) for i, j in zip(X[:-1], X[1:])]
print(*X)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(input())

x = [int(_) for _ in a]

for n in range(N - 1):
    x = [abs(x[_] - x[_ + 1]) for _ in range(len(x) - 1)]
    
print(sum(x))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
num = [int(c) for c in s]

temp = num
#print('1',num)

for i in range(N-1):
  result = []
  for j in range(len(temp)-1):
    result.append(abs(temp[j+1] - temp[j]))

  temp = result

print(result[0])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=input()
# N = 4
# A = "1231"
X = [[ int(a) for a in list(A)]]
# print(X)
for i in range(2,N+1):
  # print(X)
  # print("i:",i)
  x = []
  for j in range(1,N+1-i+1):
    x.append( abs(X[i-2][j-1] - X[i-2][j]) )
    # print("  j:", j, X[i-2][j-1], X[i-2][j])
  X.append(x)
print(X[-1][0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input()

while len(a)>1:
    b = []
    for i in range(len(a)-1):
        b.append(str(abs(int(a[i+1]) - int(a[i]))))
    a = b
print(int(a[0]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(input())
x=[[0]*n]*n
for i in range(n):
    x[0][i]=int(s[i])
for i in range(1,n):
    for j in range(0,n-i):
        x[i][j]=abs(x[i-1][j]-x[i-1][j+1])
print(x[n-1][0])