Problem:
Problem A: Grey Area Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the
world everyday. He is extremely good at sophisticated visualization tools, but yet his favorite is
a simple self-made histogram generator. Figure 1 is an example of histogram automatically produced by his histogram.   A histogram is a visual display of frequencies of value occurrences as bars. In this example, values
in the interval 0-9 occur five times, those in the interval 10-19 occur three times, and 20-29
and 30-39 once each. Dr. Grey’s histogram generator is a simple tool. First, the height of the histogram is fixed, that
is, the height of the highest bar is always the same and those of the others are automatically
adjusted proportionately. Second, the widths of bars are also fixed. It can only produce a
histogram of uniform intervals, that is, each interval of a histogram should have the same width
(10 in the above example). Finally, the bar for each interval is painted in a grey color, where
the colors of the leftmost and the rightmost intervals are black and white, respectively, and the
darkness of bars monotonically decreases at the same rate from left to right. For instance, in
Figure 1, the darkness levels of the four bars are 1, 2/3, 1/3, and 0, respectively. In this problem, you are requested to estimate ink consumption when printing a histogram on paper. The amount of ink necessary to draw a bar is proportional to both its area and darkness. Input  The input consists of multiple datasets, each of which contains integers and specifies a value
table and intervals for the histogram generator, in the following format.   n  w  v 1  v 2 . .  v n    n is the total number of value occurrences for the histogram, and each of the n lines following
the first line contains a single value. Note that the same value may possibly occur multiple
times.   w is the interval width. A value v is in the first (i.e. leftmost) interval if 0 ≤ v < w , the second
one if w ≤ v < 2 w , and so on. Note that the interval from 0 (inclusive) to w (exclusive) should
be regarded as the leftmost even if no values occur in this interval. The last (i.e. rightmost)
interval is the one that includes the largest value in the dataset.  You may assume the following.  1 ≤ n ≤ 100 10 ≤ w ≤ 50 0 ≤ v i ≤ 100 for 1 ≤ i ≤ n   You can also assume that the maximum value is no less than w . This means that the histogram
has more than one interval.
The end of the input is indicated by a line containing two zeros.  Output  For each dataset, output a line containing the amount of ink consumed in printing the histogram.  One unit of ink is necessary to paint one highest bar black. Assume that 0.01 units of ink per
histogram is consumed for various purposes except for painting bars such as drawing lines and
characters (see Figure 1). For instance, the amount of ink consumed in printing the histogram
in Figure 1 is:     Each output value should be in a decimal fraction and may have an error less than 10 -5 .  Sample Input  3 50
100
0
100
3 50
100
100
50
10 10
1
2
3
4
5
16
17
18
29
30
0 0  Output for the Sample Input  0.51
0.26
1.4766666666666667

Solution (Python):


import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

while True:
    n, w = map(int, raw_input().split())
    if n == 0:
        break
    lst = []
    for i in range(n):
        num = input()
        num /= w
        lst.append(num)
    max_num = max(lst)

    ans = 0.0
    cnt = [0 for i in range(100)]
    for i in range(n):
        num = max_num - lst[i]
        ans += num
        cnt[num] += 1
    
    max_cnt = max(cnt)
    print ans / max_num / max_cnt + 0.01
    pass

Solution (Python):
while 1:
	n,w = map(int,raw_input().split())
	if (n,w) == (0,0):
		break
	hist = []
	value = [int(raw_input()) for i in range(n)]
	value.sort()
	tmphist = 0.0
	tmpthle = w
	for v in value:
		while v >= tmpthle:
			hist.append(tmphist)
			tmphist = 0.0
			tmpthle += w
		tmphist += 1.0
	else :
		hist.append(tmphist)
	while hist[-1] == 0:
		hist.pop()
	highest = max(hist)
	col = len(hist)
	print sum([(col-1.0-i) / (col-1.0) * hist[i] / highest for i in range(col)]) + 0.01

Solution (Python):
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1
        m = max(m,p)
    ans = 0.01
    for i in range(m):
        ans += (v[i]*1.0/max(v))*(1-i*1.0/m)
    print ans

Solution (Python):
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1
        m = max(m,p)
    ans = 0.01
    for i in range(m):
        ans += (v[i]*1.0/max(v))*(1-i*1.0/m)
    print ans

Solution (Python):
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1
        m = max(m,p)
    ans = 0.01
    for i in range(m):
        ans += (v[i]*1.0/max(v))*(1-i*1.0/m)
    print ans

Solution (Python):
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0.0]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1.0
        m = max(m,p)
    vm = max(v)
    ans = 0.01
    for i in range(m):
        ans += (v[i]/vm)*(1-i*1.0/m)
    print ans

Solution (Python):
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0.]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1.
        m = max(m,p)
    vm = max(v)
    ans = 0.01+sum((v[i]/vm)*(1-i*1.0/m) for i in range(m))
    print ans

Solution (Python):
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0.]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1.
        m = max(m,p)
    vm = max(v)
    ans = 0.01+sum((v[i]/vm)*(1-i*1.0/m) for i in range(m))
    print ans

Solution (Python):
while True:
    N, W = map(int, input().split())
    if not N:
        break
    s = list(sorted([int(input()) for i in range(N)]))
    m = s[-1] // W + 1
    ss = [0] * m
    for c in s:
        ss[c // W] += 1
    unit = max(ss)
    a = 0
    for i, c in enumerate(ss):
        a += (1 - i / (m - 1)) * (c / unit)
    print(a + 0.01)

Solution (Python):



while True:
    (n, w) = map(int, raw_input().split())
    if n == 0: break

    vcnt = [0]*11
    vr = 0
    for i in range(n):
        v = int(raw_input())
        if v/w > vr:
            vr = v/w
        vcnt[v/w] += 1
    
    vmax = max(vcnt)
    ans = 0
    for i in range(11):
        ans += ((vr-i)/float(vr))*(vcnt[i]/float(vmax))

    print ans+0.01

Solution (Python):
while 1:
    n,w=map(int,input().split())
    if n==w==0:break
    a=[0]*100
    s=h=int(0)
    while n:
        b=int(input())
        a[b//w]+=1
        s=max(s,b//w)
        h=max(h,a[b//w])
        n-=1
    ans=0.01
    for i in range(int(s)+1):
        ans+=a[i]/h*(s-i)/s
    print(ans)

Solution (Python):
while True:
    N,W = map(int,input().split())
    if N == 0: break
    src = [int(input()) for i in range(N)]
    highest = max(src)
    bands = highest//W + 1
    hist = [0 for i in range(bands)]
    for i in range(N):
        hist[src[i] // W] += 1
    ans = maxn = 0
    for i,n in enumerate(hist):
        ans += n * (bands-1-i)
        maxn = max(n, maxn)
    print(ans / maxn / (bands-1) + 0.01)

Solution (Python):
while 1:
    n,w=map(int,input().split())
    if n==w==0:break
    a=[0]*100
    s=h=int(0)
    while n:
        b=int(input())
        a[b//w]+=1
        s=max(s,b//w)
        h=max(h,a[b//w])
        n-=1
    ans=0.01
    for i in range(int(s)+1):
        ans+=a[i]/h*(s-i)/s
    print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,w = LI()
        if n == 0:
            break
        a = [I() for _ in range(n)]
        ma = max(a)
        l = (ma // w + 1)
        b = [0] * l
        for c in a:
            b[c//w] += 1
        h = max(b)
        r = 0.01
        for i in range(l):
            bi = b[i]
            d = (l-i-1) / (l-1)
            r += d * bi / h
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Solution (Python):
import sys
import collections

while True:
    n, w = map(int, sys.stdin.readline().split())
    
    if n == 0:
        break
    
    count = collections.Counter()
    for i in xrange(n):
        count[int(raw_input()) / w] += 1
    largest_value = count.most_common(1)[0][1]
    largest_key = max(count.keys())
    ink = 0
    for i, v in count.iteritems():
        if i >= largest_key:
            continue
        ink += (largest_key - float(i)) / (largest_key) * v / largest_value
    print ink + 0.01

Solution (Python):
while True:
    n,w=map(int,raw_input().split())
    if n==w==0:break
    L=[0]*(w+1)
    for i in range(n):
        v=input()
        L[v/w]+=1
    maxh=max(L)
    r=w
    while r>0 and L[r]==0:
        r-=1
    ink=0.01
    for i in range(r+1):
        if r<>0:
            ink+=float(r-i)/r*float(L[i])/maxh
        else:
            ink+=L[i]
    print ink

Solution (Python):
while True:
  n, w = list(map(int, input().split()))
  if n==0:
    break
  v = [int(input()) for i in range(n)]
  h = [0 for i in range(100)]
  ma = 0
  mi = 1e9
  for i in range(n):
    h[v[i]//w] += 1
    ma = max(ma, v[i]//w)
    mi = min(mi, v[i]//w)
  sm = ma-mi
  h = [h[i]/max(h) for i in range(100)]
  ans = 0.01
  for i in range(mi, ma):
    ans += (sm-i+mi)/(sm+mi)*h[i]
  print(ans)

Solution (Python):

while True:
    n, w = map(int, input().split())
    if n is 0 and w is 0:
        break

    l = [int(input()) for i in range(n)]

    max_num = 0
    for i in  range(n):
        max_num = max(max_num, l[i])
    hist_size = int((max_num/w) + 1)
    hist = [0.0] * int(hist_size)

    for i in  range(n):
        hist[int(l[i]/w)] += 1

    max_height=  0
    for i in range(hist_size):
        max_height = max(max_height,hist[i])

    ans = 0.0
    for i in range(hist_size-1):
        ans += hist[i]/max_height*(hist_size - 1 - i)/(hist_size-1)

    ans += 0.01
    print(ans)

Solution (Python):

while 1:
    n,w=map(int,input().split())
    if n==0:
        break
    dic={}
    mx=-1
    max_section=-1
    for i in range(1+100//w):
        dic[i]=0
    for i in range(n):
        x=int(input())
        dic[x//w]+=1
        mx=max(mx,dic[x//w])
        max_section=max(max_section,x//w)
    ans=0
    for i in range(1+100//w):
        ans+=(dic[i]/mx)*(1-i*(1/(max_section)))
    print(ans+0.01)