# Task
 Mr.Nam has `n` candies, he wants to put one candy in each cell of a table-box. The table-box has `r` rows and `c` columns.

 Each candy was labeled by its cell number. The cell numbers are in range from 1 to N and the direction begins from right to left and from bottom to top.

 Nam wants to know the position of a specific `candy` and which box is holding it.

 The result should be an array and contain exactly 3 elements. The first element is the `label` of the table; The second element is the `row` of the candy; The third element is the `column` of the candy.
 
 If there is no candy with the given number, return `[-1, -1, -1]`.

 Note: 
 
 When the current box is filled up, Nam buys another one. 
 
 The boxes are labeled from `1`.

 Rows and columns are `0`-based numbered from left to right and from top to bottom.
 
# Example

 For `n=6,r=2,c=2,candy=3`, the result should be `[1,0,1]`
 
 the candies will be allocated like this:
```
Box 1
+-----+-----+
|  4  | (3) | --> box 1,row 0, col 1
+-----+-----+
|  2  |  1  |
+-----+-----+
Box 2
+-----+-----+
|  x  |  x  |
+-----+-----+
|  6  | (5) | --> box 2,row 1, col 1
+-----+-----+```
 For `candy = 5(n,r,c same as above)`, the output should be `[2,1,1]`.
 
 For `candy = 7(n,r,c same as above)`, the output should be `[-1,-1,-1]`.
 
 For `n=8,r=4,c=2,candy=3`, the result should be `[1,2,1]` 
```
Box 1
+-----+-----+
|  8  |  7  |
+-----+-----+
|  6  |  5  |
+-----+-----+
|  4  | (3) |--> box 1,row 2, col 1
+-----+-----+
|  2  |  1  |
+-----+-----+
```

# Input/Output


 - `[input]` integer `n`

  The number of candies. 
  
  `0 < n <= 100`


 - `[input]` integer `r`

  The number of rows. 
  
  `0 < r <= 100`


 - `[input]` integer `c`

 The number of columns.

 `0 < c <= 100`


 - `[input]` integer `candy`

 The label of the candy Nam wants to get position of.
 
 `0 < c <= 120`

 - `[output]` an integer array

  Array of 3 elements: a label, a row and a column.

Difficulty: EASY
Starter code: def get_candy_position(n, r, c, candy):
	

Solutions:
def get_candy_position(n, r, c, candy):
	if candy > n:
		return [-1, -1, -1]
	linIdx = r * c - ((candy - 1) % (r * c) + 1)
	return [(candy - 1) // (r * c) + 1, linIdx // c, linIdx % c]


def get_candy_position(n, r, c, candy):
	if candy > n:
		return [-1, -1, -1]
	label = (candy + r * c - 1) // (r * c)
	candy = (candy - 1) % (r * c)
	row = r - 1 - candy // c
	col = c - 1 - candy % c
	return [label, row, col]


def get_candy_position(n, r, c, candy):
	(q1, r1) = divmod(candy - 1, r * c)
	(q2, r2) = divmod(r1, c)
	return [-1, -1, -1] if n < candy else [q1 + 1, r - q2 - 1, c - r2 - 1]


import numpy as np
import math

def get_candy_position(n, r, c, candy):
	if n < candy:
		return [-1, -1, -1]
	box = np.array([['*'] * c] * r)
	n1 = math.ceil(n / (c * r))
	count = 1
	for i in range(1, n1 + 1):
		b = box.copy()
		for j in range(r - 1, -1, -1):
			for k in range(c - 1, -1, -1):
				if count == candy:
					return [i, j, k]
				b[j][k] = count
				count += 1


def get_candy_position(n, r, c, candy):
	if candy > n:
		return [-1, -1, -1]
	(box, res) = divmod(candy, r * c)
	if res == 0:
		return [box, 0, 0]
	(row, res) = divmod(res, c)
	return [box + 1, r - row, 0] if res == 0 else [box + 1, r - row - 1, c - res]


from math import ceil

def get_candy_position(n, r, c, candy):
	if candy > n:
		return [-1, -1, -1]
	box = ceil(candy / (r * c))
	candy -= (box - 1) * r * c
	row = r - ceil(candy / c)
	column = c - candy % c if candy % c > 0 else 0
	return [box, row, column]


def get_candy_position(a, row, col, candy):
	from math import ceil
	bx_sz = row * col
	if row * col < a:
		n = ceil(a / (row * col)) * (col * row)
	else:
		n = row * col
	l = [i if i <= a else 'X' for i in list(range(1, n - n % row + 1))]
	split_l = [list(l[i:i + bx_sz])[::-1] for i in range(0, len(l), bx_sz)]
	b = [i[j:j + col] for i in split_l for j in range(0, len(i), col)]
	c = [b[i:i + row] for i in range(0, len(b), row)]
	for i in range(len(c)):
		for j in range(len(c[i])):
			for k in range(len(c[i][j])):
				if c[i][j][k] == candy:
					return [i + 1, j, k]
	return [-1, -1, -1]


def get_candy_position(n, r, c, candy):
	if min(n, r, c, candy) <= 0 or candy > n:
		return [-1] * 3
	(box, candy) = divmod(candy - 1, r * c)
	(row, col) = divmod(candy, c)
	return [box + 1, r - row - 1, c - col - 1]


from math import ceil

def get_candy_position(n, r, c, candy):
	d = r * c
	(boxes_cnt, boxes) = (ceil(n / d), [])
	lst = [[i * c + j + 1 for j in range(c - 1, -1, -1)] for i in range(r - 1, -1, -1)]
	for i in range(boxes_cnt):
		boxes.append([i + 1, [[v + i * d if v + i * d <= n else 'x' for v in row] for row in lst]])
	bx = next((box for box in boxes if any((candy in b for b in box[1]))), None)
	if not bx:
		return [-1, -1, -1]
	i = next((k for (k, b) in enumerate(bx[1]) if candy in b))
	j = bx[1][i].index(candy)
	return [bx[0], i, j]


def get_candy_position(n, row, column, element):
	(arr, arr_p, row_p, col_p) = ([[[0] * column for i in range(row)]], 0, row - 1, column - 1)
	i = 1
	while i < n + 1:
		arr[arr_p][row_p][col_p] = i
		col_p -= 1
		if col_p < 0:
			col_p = column - 1
			row_p -= 1
		if all([k != 0 for j in arr for k in sum(j, [])]):
			arr.append([[0] * column for i in range(row)])
			row_p = row - 1
			arr_p += 1
		i += 1
	final = [[i + 1, j, y.index(element)] for (i, x) in enumerate(arr) for (j, y) in enumerate(x) if element in y]
	return final[0] if final else [-1, -1, -1]