# Watercolor

Bob is the owner of a shop named “Color Maker”. He has 256 types of watercolor in his shop. The types are numbered from 0 to 255. Bob stores the watercolors in small boxes. One box contains only one type of watercolor and there can be more than one box containing the same type of watercolor. Bob keeps the boxes on a shelf side by side. As he has a limited supply of watercolors, he sells the boxes of watercolors with a condition applied. Bob arranges another set of sample boxes containing watercolors and keeps them on another shelf side by side. He does not sell these sample boxes. After that, Bob numbers the boxes. Let the number of boxes on the first shelf is N and the number of the sample boxes is M. Then Bob numbers the boxes on the first shelf from 1 to N and the sample boxes from 1 to M. When Alice wants to buy watercolors in this shop, Bob asks her to choose a box. If she chooses the kth box, Bob finds out a position j in the sample boxes and the number of boxes p such that: Bk = Sj, Bk+1 = Sj+1, Bk+2 = Sj+2,…………..,Bk+p-1 = Sj+p-1, where Bi represents the ith box on the first shelf, Si represents the ith box of the sample boxes and k ≥ 1, k+p-1 ≤ N, j ≥ 1 and j+p-1 ≤ M. Bob then sells p boxes to Alice.

This is a companion discussion topic for the original entry at https://toph.co/p/watercolor