Under construction

Still being built. Things may change

Trait Growth Leap

Time limit1sMemory limit1024 MB

Summary
Given N trait levels, each trait's item count, and M Growth Leaps, find the highest level T that every trait can reach.
Level

Medium6 of 10

Topics
Math, Binary search, Greedy
Solved
No attempts yet

Problem

'MapleStory' has a system called 'traits'. Raising the levels of traits such as 'Charisma', 'Charm', and 'Craftsmanship' lets you build up the abilities assigned to each trait. Jihun has played this game for a long time, so every trait on his main character is at max level. When all trait levels are equal, the trait graph becomes a regular polygon, as in the picture below.

A trait level is raised with 'trait items'. To raise any trait from level xx to level x+1x+1, you need xx of that trait's items. Alternatively, the special trait item 'Growth Leap' raises the level of any chosen trait by exactly 11. A trait at max level cannot use a trait item, so Jihun decided to move his spare trait items to storage and use them to raise trait levels on another character.

The character that will use the trait items has NN traits, and the traits have no max level, so their levels can keep rising. Jihun also likes large regular polygons, so he wants the trait graph of this character to be the largest regular NN-gon possible. Given the number of Growth Leaps MM, the current level of each trait, and the number of trait items for each trait, find the size of the largest regular NN-gon Jihun can make, that is, the highest level at which a regular NN-gon can be formed.

Input

The first line contains two integers NN and MM, separated by a space. (3≤N≤100 0003 \leq N \leq 100\,000; 0≤M≤10120 \leq M \leq 10^{12})

The second line contains NN integers L1,L2,⋯ ,LNL_1, L_2, \cdots , L_N, separated by spaces, giving the current level of each trait. (1≤Li≤1091 \leq L_i \leq 10^9)

The third line contains NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots , A_N, separated by spaces, giving the number of trait items for each trait. (0≤Ai≤10180 \leq A_i \leq 10^{18})

Output

Print the size of the largest regular NN-gon Jihun can make, that is, the highest level at which a regular NN-gon can be formed.

If no regular polygon can be formed, print -1.

Hint

Log in to MapleStory and look for the hidden item in this problem!

Examples3

  1. Example 1

    Input
    3 0
    1 1 1
    2 2 2
    
    Expected output
    2
    
  2. Example 2

    Input
    3 2
    1 1 1
    3 0 1
    
    Expected output
    2
    
  3. Example 3

    Input
    3 0
    1 2 1
    1 3 0
    
    Expected output
    -1