# Better performance in solution for the Dole Out Cadbury challenge

## Problem Description

You are a teacher in reputed school. During Celebration Day you were assigned a task to distribute Cadbury such that maximum children get the chocolate. You have a box full of Cadbury with different width and height. You can only distribute largest square shape Cadbury. So if you have a Cadbury of length 10 and width 5, then you need to break Cadbury in 5X5 square and distribute to first child and then remaining 5X5 to next in queue

## Constraints

$$0
$$0

## Input Format

First line contains an integer P that denotes minimum length of Cadbury in the box
Second line contains an integer Q that denotes maximum length of Cadbury in the box
Third line contains an integer R that denotes minimum width of Cadbury in the box
Fourth line contains an integer S that denotes maximum width of Cadbury in the box

Output
Print total number of children who will get chocolate.

Timeout
1

Example

Input

5
7
3
4


Output

24


Explanation

Length is in between 5 to 7 and width is in between 3 to 4.
So we have 5X3,5X4,6X3,6X4,7X3,7X4 type of Cadbury in the box.
If we take 5X3:

First, we can give 3X3 square Cadbury to 1st child .Then we are left with 3X2. Now largest square is 2X2 which will be given to next child. Next, we are left with two 1X1 part of Cadbury which will be given to another two children.
And so on.

Here is my code, which works but returns . I’m looking for optimizations.

def cadbury(l,b):
count = 0
while True:
lon=max(l,b)
sh=min(l,b)
count+=1
diff=lon-sh
if diff==0:
return count
else :
l=min(l,b)
b=diff
minl=int(input())
maxl=int(input())
minw=int(input())
maxw=int(input())
count=0
for i in range(minl,maxl+1):
for j in range(minw,maxw+1):
print(count)


## Related Questions

### Tail implementation using a dynamic queue library

2  Asked on December 15, 2021

### Huffman Coding library implemented in C

1  Asked on December 15, 2021

### Compression Library for C using Huffman Coding

3  Asked on December 15, 2021

1  Asked on December 14, 2021 by deed02392

### Type-safe Dictionary for various types

5  Asked on December 12, 2021

### Custom exception for each invalid input value

1  Asked on December 12, 2021

### Correct flow between Kotlin, Realm and ViewModels using Coroutines

1  Asked on December 10, 2021 by bhogan

### Changing the environment if it sees the incorrect environment in the setting

1  Asked on December 10, 2021 by cva6

### Faster solution to pattern search in a large file

1  Asked on December 10, 2021

1  Asked on December 10, 2021

### Is Lock necessary to make operation thread safe for this scenario

1  Asked on December 8, 2021 by bks

### Census Data Display from Text File

3  Asked on December 6, 2021 by proppaganda

### I’m just starting out with tasks. I need to know if there’s a better way to do TAP for socket handling (serving a request)

0  Asked on December 6, 2021 by honey-the-codewitch

### A task to store user’s favorited projects in postgres using python

0  Asked on December 6, 2021 by technazi

### Solving Fizz Buzz using Java

5  Asked on December 6, 2021 by user226918

### An app that helps determine lands in a Magic: The Gathering deck

1  Asked on December 4, 2021

### Return probability (Javascript)

2  Asked on December 2, 2021 by stan-loona

### Weather map GUI application needs performance improvement

0  Asked on December 2, 2021 by benny

### LeetCode 124: Binary Tree Maximum Path Sum

2  Asked on December 2, 2021

### LeetCode 124: Binary Tree Maximum Path Sum 2

1  Asked on December 2, 2021