This pair of problems evaluates algorithmic proficiency with nested data structures and grid-based graph traversal, covering concepts such as depth-weighted aggregation and shortest-path computation under obstacles.

You are given a nested list structure that may contain integers or other nested lists. Define the depth of top-level elements as 1, their children as depth 2, etc.
Task: Compute the sum of each integer multiplied by its depth.
Input:
[1, [4, [6]]]
Output:
Example:
[1, [4, [6]]]
1
at depth 1 →
1*1
4
at depth 2 →
4*2
6
at depth 3 →
6*3
1 + 8 + 18 = 27
Constraints (typical):
You are given an m x n grid with values:
0
= empty land (you may start here)
1
= building
2
= obstacle (cannot pass)
Movement is 4-directional (up/down/left/right). Distance is the number of steps along empty cells (you cannot pass through obstacles or buildings).
Task: Choose an empty cell 0 such that the sum of shortest path distances from that cell to every building is minimized. Return that minimum sum.
If there is no empty cell from which all buildings are reachable, return -1.
Input:
grid
:
m x n
integer matrix
Output:
-1
Example:
grid = [[1,0,2,0,1],[0,0,0,0,0],[0,0,1,0,0]]
→ output
7
(one optimal empty cell has total distance 7)
Constraints (typical):
1 <= m,n <= 50