#### Registered Users Only

Please login to view and utilize this feature.

## Problem Description

In a land called priority, there are many queues

Unsurprisingly, all of these queues are priority queues

Today is a strange day indeed. One of these queues will be serving according to some very strange rules

It can either call the person with the largest queue number modulo 13371337, the largest sum of digits of their queue number or the largest queue number if queue numbers were read in reverse (i.e. 1234 instead of 4321)

In the event of a tie, a tiebreaker is called and the person with the highest queue number will be served

You are the queue manager today... Help manage one of these queues

**NOTE: Each person can only be served once and leaves the queue when he/she is served**

## Input

The first line of the input contains one integer, the number of people N initially in the queue

For the next N lines, each line consists of an integer representing a person's queue number

The next line contains a single integer, Q, the number of queries

The next Q lines contain an integer 1,2 or 3

- 1 represents serving the person with the largest queue number modulo 13371337
- 2 represents serving the person with the largest sum of digits in their queue number
- 3 represents serving the person with the largest queue number if queue numbers were read in reverse

**NOTE: No one will enter the queue, everybody is in the queue from the beginning [To make your life easier, and to set less testcases]**

## Constraints

Queue Number <= 2^63-1

Q<=1,000,000

Q<=1,000,000

Q<=N

## Output

Output the queue number of the person who is served in every query

## Subtasks

Subtask 1 (5%) N=1,Q=1, all other constraints apply

Subtask 2 (10%) Q=1, all other constraints apply

Subtask 3 (10%) All queries will be of type 1, all other constraints apply

Subtask 4 (20%) N<=1000, all other constraints apply

Subtask 5 (55%) All above constraints apply

## Sample Testcase 1

Input

3 2 13371338 13371340 3 1 1 1Output

13371340 2 13371338

## Explanation

Served in order of queue number %13371337

## Sample Testcase 2

Input

3 2 13371338 26742675 3 1 1 1Output

2 26742675 13371338

## Explanation

13371338 % 13371337 = 26742675 % 13371337 = 1, since 26742675 > 13371338, 26742675 is served first

### Tags

### Subtasks and Limits

Subtask | Score | #TC | Time | Memory | Scoring |
---|---|---|---|---|---|

1 | 5 | 10 | 2s | 128MB | Minimum |

2 | 10 | 10 | 2s | 128MB | Minimum |

3 | 10 | 10 | 4s | 128MB | Minimum |

4 | 20 | 10 | 2s | 128MB | Minimum |

5 | 55 | 10 | 6s | 128MB | Minimum |

6 | 0 | 2 | 2s | 128MB | Minimum |

### Judge Compile Command

g++ ans.cpp -o priority -Wall -static -O2 -lm -m64 -s -w -std=gnu++14 -fmax-errors=512