EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. CodeNection
  2. 2024
  3. Preliminary Round

Codey and Peaks

https://www.hackerrank.com/contests/codenection-2024-preliminary-round-open-category/challenges/cn24-15

Question

Codey is about to explore the legendary Code Mountain, a famous destination for touching grass.

Code Mountain is a one-dimensional mountain made up of n units, which can be represented by an array a of length n, where aia_iai​ is the height of the iii-th unit. What's special about this mountain is that it is known to have only two peaks. Formally, there are only two values of aia_iai​ (where 1<i<n1 \lt i \lt n1<i<n) such that aa−1<ai>ai+1a_{a-1} \lt a_i > a_{i+1}aa−1​<ai​>ai+1​.

Unfortunately, Codey only knows the heights of the two peaks, while the heights of the remaining units are denoted by −1-1−1. Help Codey figure out how many possible combinations of the array a exist modulo 109+710^9 + 7109+7, so that he can better prepare for the exploration.

You can assure the max height for each unit is 10510^5105.

Input Format

The first line contains an integer n, which represents the number of units in the Code Mountain.

The second line contains n integers, a1,a2,...,ana_1, a_2, ..., a_na1​,a2​,...,an​ each representing the height of the iii-th unit.

Constraints

5≤n≤1055 \le n \le 10^55≤n≤105
2≤ai≤105∣ai=−12 \le a_i \le 10^5 | a_i = -12≤ai​≤105∣ai​=−1
  • Only two ai≠−1a_i \ne -1ai​=−1, where 1<i<n1 \lt i \lt n1<i<n

Output Format

Output the total number of combinations of the array a that fulfill the conditions modulo 109+710^9 + 7109+7.

Sample Inputs:

Input

5
-1 2 -1 2 -1

Output

1

Explanation

The only combination is [1,2,1,2,1][1,2,1,2,1][1,2,1,2,1]

Input

8
-1 -1 3 -1 -1 -1 3 -1

Output

2800000

Explanation

Some of the possible combinations for this test case include:

  • [105,2,3,2,1,1,3,1][10^5,2,3,2,1,1,3,1][105,2,3,2,1,1,3,1]

  • [1,2,3,1,1,1,3,2][1,2,3,1,1,1,3,2][1,2,3,1,1,1,3,2]

  • [2,2,3,2,2,2,3,2][2,2,3,2,2,2,3,2][2,2,3,2,2,2,3,2]


WIP - Slice into 3 parts

WIP

PreviousCodey and Toy KingdomNextFinal Round

Last updated 5 months ago

🇲🇾