### 2015-16 Woburn Challenge Finals - Senior Division

## Problem 4: Server Hacking

The Center for Exploration of Monkey Cryptography (CEMC) is an organization dedicated to wartime cryptography research amongst the primate community. As the monkeys are once again at war with the cows, this institution has become indispensable to their success in combat. After all, taking over Scarberia in the 21st century will require some of the most sophisticated code-breaking techniques in existence to infiltrate the enemies' communications. As it turns out, the cows possess a slight technological edge over the monkeys, due to their experimentation with Cow-Bots in 2002. They were therefore able to reverse engineer the structure of the CEMC's servers!

The cows have learned that the server is a network consisting of `N` (1 ≤ `N` ≤ 100,000) computers arranged in a line topology. Specifically, the computers are numbered from 1 to `N`, and are connected in a line in ascending order. For example, computer 1 is connected only to computer 2, computer 2 is connected only to computers 1 and 3, and computer `N` is connected only to computer `N` − 1. The network is encrypted using a simple public key cryptosystem. Each computer `i` has a distinct public key, an integer `A _{i}` (1 ≤

`A`≤ 10

_{i}^{9}). The private key to access computer

`i`is a sequence of integers based on the prime factorization of

`A`. Consider

_{i}`A`= 1200 with the prime factorization of 2

_{i}^{4}× 3

^{1}× 5

^{2}when the prime factors are listed in ascending order. Its private key is then the sequence [2, 4, 3, 1, 5, 2].

Typical brute force attacks rely on trying every possibility to gain access. In this case, a private key is easier to guess if it comes "earlier" in an exhaustive list of possible guesses. So for two different computers `i` and `j`, we will call the public key of `i` **weaker** than the public key of `j` if and only if the private key sequence of `i` is lexicographically smaller than the private key sequence of `j`. A sequence `X` is considered to be lexicographically smaller than another sequence `Y` if `X _{i}` <

`Y`for the smallest index

_{i}`i`such that

`X`differs from

_{i}`Y`. If every value in

_{i}`X`is equal to the values at corresponding indices in

`Y`and

`X`is a shorter sequence (i.e. if

`X`is a prefix of

`Y`), then

`X`is also considered lexicographically smaller than

`Y`. For example, [2, 2, 7, 1] is lexicographically smaller than [2, 3] and [2, 3] is lexicographically smaller than [2, 3, 5, 7].

Having discovered the weak cryptographic scheme of the CEMC's servers, the cows now wish to assert their dominance and generate chaos amongst the monkeys by performing a distributed denial-of-service (DDOS) attack on the network to take it down. However, they will need a **weakpoint** from which to initiate the attack. In particular, a weakpoint is a computer whose public key is weaker than that of every other computer that it is directly connected to. Please help the cows write a program to find a weakpoint and crash the CEMC's servers. If there are multiple such weakpoints, then any one of them will suffice.

In test cases worth 5/25 of the points: `N` ≤ 1000.

### Input Format

The first line of input consists of a single integer `N`.

`N` lines follow, with the `i`-th of these lines containing `A _{i}` (for

`i`= 1..

`N`).

### Output Format

Output a single integer between 1 and `N`, your chosen weakpoint.

### Sample Input

4 840350 341796875 1584 735166567

### Sample Output

1

### Explanation

Computer 1's public key has the prime factorization 840350 = 2^{1} × 5^{2} × 7^{5}, so its private key is [2, 1, 5, 2, 7, 5].

Computer 2's public key has the prime factorization 341796875 = 5^{11} × 7^{1}, so its private key is [5, 11, 7, 1].

Computer 3's public key has the prime factorization 1584 = 2^{4} × 3^{2} × 11^{1}, so its private key is [2, 4, 3, 2, 11, 1].

Computer 4's public key has the prime factorization 735166567 = 26783^{1} × 27449^{1}, so its private key is [26783, 1, 27449, 1].

Therefore, both computers 1 and 3 are valid weakpoints that will be accepted.

All Submissions

Best Solutions

**Point Value:** 20 (partial)

**Time Limit:** 0.20s

**Memory Limit:** 32M

**Added:** May 07, 2016

**Author:** Alex

**Languages Allowed:**

C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

Alexon May 07, 2016 - 3:54:03 am UTC Time LimitP234reron Feb 11, 2017 - 3:28:29 am UTC Re: Time LimitImaxBlueon May 08, 2016 - 11:24:58 pm UTC Wall Clockbbi5291on May 09, 2016 - 7:30:50 pm UTC Re: Wall Clock