Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.
A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych.
The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams.
So the professor began: "Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has al fingers on her left hand and ar fingers on the right one. The boy correspondingly has bl and br fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable."
The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa.
Input
The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly.
Output
Print YES or NO, that is, the answer to Petr Palych's question.
Examples
Input
5 1
10 5
Output
YES
Input
4 5
3 3
Output
YES
Input
1 2
11 6
Output
NO
Note
The boy and the girl don't really care who goes to the left.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to understand the problem. There's a Venusian girl with al fingers on left hand and ar on right. Marsian boy with bl and br fingers. They hold hands: they can decide who is on left or right. If boy goes to left of girl, then he will take her left hand with his right hand. So the boy uses his right hand, girl uses her left hand. If boy goes to the right of girl, then boy uses his left hand, girl uses her right hand.
We need to determine if they can hold hands (i.e., interlace fingers) such that both are comfortable. Comfort conditions:
No pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. So girl's fingers must be separated by at least one boy's finger between any two adjacent girl fingers when arranged in the interlacing? Actually "between any two girl's fingers there is a boy's finger" suggests that in the ordering of fingers along the hand-holding line, between any two girl fingers, there must be at least one boy finger. That implies that the girl's fingers must not be adjacent; they must have at least one boy finger in between. This is similar to having the boy's fingers act as separators. So the condition is: In the sequence of fingers (from leftmost to rightmost) of the interlocked hands, no two girl fingers are consecutive; there must be at least one boy finger between any two girl fingers.
And in addition, no three fingers of the boy should touch each other. So in the sequence, no three boy fingers are consecutive. i.e., at most two boy fingers can be adjacent.
We need to decide if there exists an interlacing arrangement (i.e., a merge of two sequences? Actually the ordering is determined by how the fingers interlace? Typically when holding hands, fingers alternate? But here conditions are relaxed: we can arrange the fingers in any order as long as we respect that the girl's hand and boy's hand each have a fixed number of fingers, but the relative order of fingers on each hand is fixed (like the order of fingers from left to right on each hand). Usually when you hold hands, the fingers interlace in an alternating pattern: one from each hand, maybe starting with someone. But here they might be able to choose how to interlace? The problem statement: "They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other." This seems to be about the arrangement of fingers when they hold hands. Usually you have two hands, each with fingers that are lined up. When you hold hands, you interlace fingers: the fingers from one hand go between the fingers of the other. But the order of fingers from each hand is predetermined: left to right order. The interlacing pattern is basically a merging of the two sequences preserving the order within each hand. Typically we might think of it as we have two rows of fingers (like on left and right hands) but here they are holding one hand each. Actually it's two people holding each other's hand: one is the girl's left hand (or right) and the boy's right hand (or left). So they are each using one hand. The fingers on that hand are in a natural order from thumb to pinky (or whatever). When they interlace, the fingers from each hand alternate, but the order of fingers on each hand is fixed. So we need to decide if we can interlace the two sequences (girl's fingers and boy's fingers) such that the final sequence satisfies: no two girl fingers are consecutive, and no three boy fingers are consecutive. Also we can choose the orientation: either boy uses his right hand (fingers count br) to hold girl's left hand (fingers count al), or boy uses his left hand (bl) to hold girl's right hand (ar). So essentially we have two possible pairings: (girl_left, boy_right) or (girl_right, boy_left). And we need to check if at least one works.
But careful: In the first scenario: boy on left of girl, so boy uses right hand to hold girl's left hand. So the fingers involved are: girl left (al fingers) and boy right (br fingers). The order of fingers: when they interlock, the fingers from each hand appear in order from left to right along the hand-holding axis. Usually, the person on the left will have his hand's fingers oriented such that the leftmost finger might be the boy's thumb? But we need to decide which finger is on the extreme left. However, the problem says: "The boy and the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa." This suggests that when they hold hands, they are facing each other? Actually think: two people standing side by side, holding adjacent hands. If the boy is on left of the girl, then his right hand holds her left hand (since they are adjacent). So the hand being held is: boy's right, girl's left. If the boy is on right, then his left holds her right. So indeed, in each scenario we only use one hand from each. So we only have one set of fingers per person: one hand. So the interlacing is between two sequences: the girl's fingers (from her chosen hand) and the boy's fingers (from his chosen hand). There is no mention about which hand is left or right orientation of the sequence. In hand-holding, the order of fingers from left to right along the line of the hand is determined by the orientation of the hands: if two people stand side by side, holding hands, the handshake is like interlocking fingers. Typically, if the boy is on left, his right hand and her left hand are clasped. The natural order from leftmost to rightmost (i.e., from the boy's left side to the girl's right side) would be: the boy's fingers (in order from his pinky to thumb? Actually it depends on orientation). But it's symmetric. However, the problem probably simplifies: we just have two sequences of lengths A and B (the numbers of fingers on the respective hands). We can interlace them in any way preserving the relative order within each hand? But in hand-holding, the order is fixed by the hand orientation. However, is it possible to choose which finger goes between which? Actually when you interlock fingers, the order from one side to the other is determined by how you interlace. But you can choose how many of your fingers are on the outside (i.e., extremes). Typically, when you hold hands, you might have the outermost fingers be from the same person? For example, if you interlock, sometimes the thumb of one person may be on the outside. But I think we have the ability to decide the interlacing pattern arbitrarily as long as the order of each person's fingers is preserved (since you cannot reorder your fingers). So the problem reduces to: Given two sequences of lengths G and B (girl fingers count, boy fingers count) to be merged into a combined sequence preserving order within each sequence (i.e., interleaving), can we achieve that no two G's are adjacent, and no three B's are adjacent? And we can also choose which side the boy is on (i.e., which hand for each) but that might affect which finger counts we use? Possibly also the orientation (which side is leftmost) might affect the order? But since the sequences have a natural order (from thumb to pinky or whatever) but the hand orientation could be reversed? If the boy is on left, his right hand is used; the order of his fingers from left to right along the hand-holding line might be reversed compared to if he used his left hand. Because a right hand palm faces left when extended? Let's think physically: Two people stand side by side, boy on left, girl on right. They extend their adjacent hands: boy extends his right hand, girl extends her left hand. They interlock fingers. Now consider the line from leftmost to rightmost across the clasped hands. On the far left, you might have the boy's pinky? Actually it depends on how the hands are oriented. But typical hand-holding: the backs of the hands face outward, the thumbs wrap around. Actually standard hand-holding (like romantic walking) often they interlock fingers such that the thumbs are on top and the fingers are interlaced. The order from the outside left to right: if the boy is on left, his right hand is used, his fingers are on the left side? Let's simulate: You are facing forward, side by side. The boy on left, girl on right. The boy extends his right hand to the right, palm likely facing down or towards the girl. The girl extends her left hand to the left, palm likely facing up? Hmm it's messy. But maybe the problem simplifies: the order of fingers for each hand is from the thumb to the pinky (or vice versa) but you can also choose which end is leftmost by flipping the hand? Actually if you hold hands, both people have their palms facing each other. When you interlock, the fingers cross. Typically, if you hold hands with right hand of one person and left hand of another, the order from left to right would be: leftmost is the thumb of the left-hand person? I'm not certain.
Given the whimsical nature (Venusian girl, etc.), the problem is likely a combinatorial puzzle abstracting away hand orientation details. The note "The boy and the girl don't care who goes to the left. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa." So the only thing that changes is which hands are used. So we either pair (al, br) or (ar, bl). There's no additional swapping of order because the order of fingers along the hand might be symmetric. Actually, consider that for a given hand, the fingers are in a fixed order from one side to the other (e.g., from thumb to little finger). If you flip the hand (using left vs right), the order of fingers from left to right might be reversed. Because if you use your left hand, the thumb is on the right side of the hand (when palm up), but if you use your right hand, the thumb is on the left side. So the natural order of fingers from left to right for a left hand (when the person is facing forward, hand extended outward) might be opposite to that of a right hand. But here the boy may be on the left or right, and using different hands. Possibly the orientation matters because the ordering of the boy's fingers relative to the girl's could be either the same direction or reversed. However, the problem likely expects that the sequences can be interleaved in any order? Actually, typical interlacing of two sequences when holding hands: the order of each person's fingers is fixed relative to the hand's orientation, but you can decide how to interlace by shifting the positions. However, you cannot reverse the order of fingers on one's hand. But if you can choose which side the boy stands, that might effectively allow you to choose the relative ordering direction of the boy's fingers compared to the girl's. For example, if both use the same side (both left hand?), then their finger orders might be opposite. But here we have a choice between two pairings: (girl_left, boy_right) or (girl_right, boy_left). In each case, the two hands are opposite (left vs right). So if we consider the natural order from the girl's perspective, and from the boy's perspective, they might be aligned or opposite. But does the problem consider that? Possibly not; they might assume that the order of fingers on each hand is fixed but the interlacing can start with either person's finger at the leftmost side, and the sequences can be interleaved arbitrarily as long as the internal order of each hand is preserved. However, if both use hands that are on the same side of the body (e.g., both left hands) then the natural order might be the same direction? Wait: If two people face each other and hold opposite hands (right-left), then the palms face each other, and the order of fingers might be such that the thumbs are both on the outer sides? Actually when you shake hands (right-right), the thumbs are up; but here it's right-left. Let's not overcomplicate.
Given the problem's examples, we can try to deduce the model.
Option1: (girl_left=5, boy_right=5) because boy uses right hand if he's left of girl. So pair (5,5). Option2: (girl_right=1, boy_left=10) -> (1,10). Which one yields YES? Likely one works.
Check if there exists an interlacing of sequences of lengths G and B such that no two G's adjacent and no three B's adjacent. For (5,5), can we interlace 5 G and 5 B? Condition: no two G adjacent means G's must be separated by at least one B. With 5 G and 5 B, we need at least (5-1) = 4 B's to separate G's if G's are placed with one B between each, but we also have ends: The condition only requires between any two girl's fingers there is a boy's finger, i.e., they can't be adjacent. It doesn't say anything about the ends: The girl's fingers can be at the extremes as long as there is no pair of adjacent girl fingers. So if we have G's separated by B's, we could have pattern starting with G, then B, then G, etc. With 5 G, the minimal B needed is 4. With 5 B, that's sufficient. Also need to avoid three B's consecutive. With 5 B and 5 G, it's easy to arrange alternating G B G B ... that yields no consecutive B's (max 1). So (5,5) works.
Option (1,10): G=1, B=10. Condition: no two G's adjacent trivially satisfied (only one G). No three B's consecutive: we need to arrange 10 B's and 1 G such that there are no three B's together. With one G, we can split the B's into at most two groups, each of length at most 2. So maximum total B would be 2+2=4 if G is in middle. Actually if you have one G, you can have at most two runs of B's: left of G and right of G. To avoid three consecutive B's, each run length ≤2. So max B is 4. But we have 10 B's, so impossible. So (1,10) would be NO. But overall answer is YES, so (5,5) works. So it's consistent.
Consider options: (girl_left=4, boy_right=3) -> (4,3); or (girl_right=5, boy_left=3) -> (5,3). Check (4,3): G=4, B=3. Need no two G adjacent -> need at least 3 B to separate 4 G? Actually minimum B to separate G's is G-1 = 3. So exactly 3 B works for separating: we can place G B G B G B G? That's 4 G, 3 B: pattern G B G B G B G, that uses 3 B and 4 G, no two G adjacent, and B's are isolated (no two consecutive? Wait B's are separated by G, so no consecutive B's, definitely no three B's). That works. So (4,3) YES.
Check (5,3): G=5, B=3. Minimal B to separate G's = 4, but we have only 3, so impossible. But overall YES, so (4,3) works.
Example 3:
1 2 (girl: left=1, right=2)
11 6 (boy: left=11, right=6)
Output: NO
Options: (girl_left=1, boy_right=6) -> (1,6); (girl_right=2, boy_left=11) -> (2,11). Need to see if either works.
First (1,6): G=1, B=6. Condition: No two G's adjacent trivial. No three B's consecutive: with one G, max B allowed = 4 as argued (since can have at most 2 groups of ≤2 each). Actually we can place the G anywhere; the sequence is a run of B's, then optionally G, then run of B's. To avoid three B's consecutively, each run length must be ≤2. So total B ≤ 4. But we have 6, so fails. So (1,6) NO.
Second (2,11): G=2, B=11. Condition: no two G adjacent: need at least 1 B between them, so we need at least 1 B to separate the two G's. But also must avoid three B's consecutive. With two G's, the B's are divided into three groups: left of first G, between G's, and right of second G. To avoid three B's consecutive, each group ≤2. So total B max = 2+2+2 = 6. Actually if we allow the G's to be at ends, groups could be 0? But maximum total B while satisfying each group ≤2 is 2+2+2=6 (if all three groups have length 2). So with 11 B, impossible. So (2,11) NO. Overall NO.
Thus the examples fit the model: For given G (girl fingers count) and B (boy fingers count), can we interlace them (preserving order? But we didn't use order preservation; we just constructed arbitrary sequences with given counts of G and B, with constraints on adjacency. The interlacing pattern is simply any binary string with exactly G G's and B B's, with no two G adjacent and no three B consecutive. There's no additional constraint about preserving the order of fingers within each hand. But is that always valid? In a real hand-holding, the order of fingers is fixed. But the problem statement: "no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger." That's exactly the condition that G's are not adjacent. The "no three fingers of the boy should touch each other" means no three consecutive B's. It doesn't mention any ordering constraint. So perhaps the interlacing can be arranged arbitrarily, meaning they can choose any interleaving that satisfies these adjacency constraints. Since they are dreaming, maybe it's okay.
But wait: Is there any hidden constraint about the order of fingers? The typical hand interlacing preserves the natural order of fingers; you cannot reorder your fingers. For instance, if you have fingers labeled 1,2,3,4,5 from thumb to pinky (or vice versa), when you interlock, the order they appear from left to right must be either 1,2,3,4,5 or reverse, depending on orientation. But the problem might consider that the fingers are indistinguishable? Possibly they are just counts; no ordering matters because all fingers are symmetric. The problem statement doesn't mention any labeling, just counts. So it's just combinatorial: given counts, can we arrange them in a line (order) satisfying the constraints? And we can choose which hand each uses.
Thus the problem reduces to: We have two possible pairs (g,b) = (al, br) or (ar, bl). For each, check if there exists a binary string (with symbols G and B) of length g+b, containing exactly g G's and b B's, such that no two G's are adjacent, and no three B's are consecutive. If yes for either, print YES else NO.
But is that all? Let's double-check: Are there any constraints about the ends? The conditions only mention between any two girl's fingers there is a boy's finger. That does not say anything about the ends; a girl's finger at the extreme left or right is fine as long as it's not adjacent to another girl finger. So ends allowed.
No three boy's fingers touch each other: that means we cannot have three consecutive B's anywhere, including at ends? It says "no three fingers of the boy should touch each other." If there are three B's at an end, they are touching each other (adjacent). So yes, no three consecutive B's anywhere.
Thus the problem is as described.
Now we need to decide for given g and b whether such a sequence exists.
This is a classic feasibility problem. We can approach by considering the constraints as placement of G's as separators.
Let's denote we have g G's. They must be placed such that they are not adjacent. So effectively, we can think of inserting B's into gaps between G's and at the ends.
If we arrange the G's with at least one B between any two G's. So we have positions: before first G, between each consecutive pair of G's, after last G. That's (g+1) gaps. Let x0 be number of B's before first G, x1,..., x_{g-1} be B's between G's (each at least 1? Actually to ensure no two G's adjacent, we need at least 1 B between each pair. But wait the condition says "between any two girl's fingers there is a boy's finger." That means for any two girl fingers, there is at least one boy finger between them. So the gaps between G's (the internal gaps) must have at least 1 B. The ends can have any number (including 0). So we have constraints: for i=1..g-1 (if g>=2), the internal gap counts must be >=1. Let's denote the gaps as:
gap0 (left of first G)
gap i for i=1 to g-1 (between G_i and G_{i+1}) must be ≥1.
gap g (right of last G) can be ≥0.
Additionally, we have constraint on B runs: no three B's consecutive. That means each gap's size must be ≤2? Actually if a gap has more than 2 B's, that would create a run of consecutive B's of that length, which is allowed only if it's ≤2? Wait: The constraint is no three consecutive B's. So any run of consecutive B's cannot have length ≥3. However, in our representation, all B's are grouped into runs that correspond to gaps. Since G's separate runs of B's, each run is exactly one gap. Because if we have G's separating, runs of B's are exactly the gaps. However, note that if we have zero G's? But g≥1 presumably because the girl has at least one finger on the hand? Input says positive integers not exceeding 100. So al and ar are positive? It says "two positive integers not exceeding 100." So yes, both numbers are positive. So g≥1. Good.
Thus the runs of B's are exactly the gaps. So the condition "no three consecutive B's" translates to each gap must have size ≤2? But careful: Could there be a scenario where we have no G's? Not possible, as girl has at least one finger on each hand? Actually al and ar are both positive? The statement: "The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly." So both are positive. So g≥1 always. So runs of B's are separated by at least one G. So each run's length is exactly the number of B's in that gap. The condition says no run length can be 3 or more. So each gap must be ≤2. However, is it allowed to have a gap of size 2? Yes, that's two consecutive B's, which is fine. So each gap must be 0,1,2, but with internal gaps (between G's) at least 1, so they must be 1 or 2.
Thus the problem reduces to: Given g and b, can we assign nonnegative integers to the g+1 gaps (with indices 0...g) such that:
For i=1,...,g-1 (internal gaps): xi >= 1.
For all i: xi <= 2.
Sum_{i=0}^{g} xi = b.
And also we might optionally allow the ordering to be different? But we assumed G's are placed with order, which is fixed: we cannot permute G's relative to each other because they are in order along the hand, but that's okay; any arrangement of gaps will produce a sequence with G's in order. Since G's are indistinguishable, the pattern is determined by gaps.
Thus the existence condition is: b must be between some min and max.
Minimum b: if internal gaps are at least 1, and ends can be 0. So min_b = (g-1) * 1 = g-1 (when g>=2). For g=1, there are no internal gaps, so min_b = 0 (since ends can be 0). But we also have constraint of max_b: each gap ≤2. So max_b = 2*(g+1) for g>=1? Actually ends also ≤2. So max_b = 2*(g+1). However, internal gaps must be at least 1, so the maximum total given that constraint: internal gaps max 2 each, ends max 2 each. So for g≥2, max_b = 2 (ends) + (g-1)2 = 2g? Wait let's compute: g+1 gaps total. Among them, internal gaps: g-1 gaps must be between 1 and 2 inclusive. Ends: two gaps (0 and g) can be 0-2. So max_b = 2 (for left end) + 2(g-1) + 2 (for right end) = 2g + 2? That would be 2*(g+1). But check: If g=2, we have gaps: left, middle, right. Internal gaps count = 1 (between the two G's) must be >=1, so its max 2. Ends max 2 each. So max total = 2+2+2 = 6 = 2*(g+1) = 2*3=6. That seems consistent.
But is it actually possible to have both ends 2 and internal 2? That would give a sequence: BB G BB G BB. That's valid: no two G adjacent (they are separated by BB), and no three B's consecutive? The runs are BB, BB, BB each length 2, okay. So yes.
Thus condition for given g,b: b must satisfy:
b >= max(0, g-1) because internal gaps need at least 1. Actually for g=1, min_b=0.
b <= 2*(g+1).
But is that sufficient? Not exactly, because internal gaps must be at least 1, so we need to be able to allocate b into gaps with each internal gap at least 1 and at most 2, ends 0-2. This is a classic bounded integer composition. The condition for existence is that b is between L and U, where L = (g-1)1 (or 0 if g=0 but g>=1) and U = 2(g+1). However, there may be gaps: for certain b values within that range, can we always find such an assignment? Let's test.
We have total b. Let’s set baseline: assign each internal gap exactly 1. That uses (g-1) b. Remaining b_rem = b - (g-1). This remainder must be distributed among all g+1 gaps (including ends) but with each gap able to take at most additional capacity: each internal gap can take at most 1 more (since max 2), and each end can take at most 2 (since min 0). Actually ends initially at 0, but they can go up to 2. So we need to assign the remainder to gaps such that no gap exceeds its max.
So if we start with internal gaps =1, ends=0. Then we have capacity: each internal gap can add up to 1 extra (to reach 2), each end can add up to 2. Total capacity = (g-1)1 + 22 = g-1 + 4 = g+3? Wait careful: The number of ends is 2. Each end can take up to 2 (since they start at 0, max 2). So capacity from ends: 2*2 = 4. Internal gaps: (g-1) gaps, each can take up to 1 more (since they are at 1, max 2). So capacity from internals: (g-1)1 = g-1. So total additional capacity = (g-1) + 4 = g+3. But note: For g=1, there are no internal gaps, then baseline b_rem = b - 0? Actually if g=1, the min b is 0. So we can set baseline: internal gaps none, ends both 0. Then we need to distribute b among ends with each ≤2. Total capacity 4. So for g=1, b can be 0..4, which matches U=2(1+1)=4. So yes.
For g>=2, baseline uses (g-1) b, remainder = b - (g-1). The remainder must be between 0 and capacity = (g-1)1 + 4? Actually internal gaps capacity is 1 each, ends capacity 2 each. So total capacity = (g-1) + 4 = g+3. But U we computed as 2(g+1) = 2g+2. Let's compute difference: U - baseline = (2g+2) - (g-1) = g+3. Yes matches capacity. So any b between L = g-1 and U = 2g+2 is achievable? Let's check the integer feasibility: we need to allocate remainder R (0 ≤ R ≤ g+3) among gaps where each internal gap can take at most 1, each end at most 2. This is like: we have (g-1) internal slots each with capacity 1, and 2 end slots each with capacity 2. Is it possible to allocate any integer R up to total capacity? Since the capacities are not uniform, but can we achieve any R? Let's test small g.
g=2: internal gaps count =1 (between G's). Ends: two. Capacities: internal max extra 1, ends each max 2. Total capacity =1+4=5, but U - baseline = (2g+2) - (g-1) = (6) - (1) =5. So R can be 0..5. Can we achieve any R? Let's list possible totals:
R=0: baseline internal=1, ends=0.
R=1: add 1 to an end or internal? internal can take 1 (becomes 2). Or add to one end (1). So possible.
R=2: add 2 to one end; or 1 to both ends; or 1 to internal + 1 to an end; etc.
R=3: 2 to one end +1 to other; or 2 to end +1 to internal; etc.
R=4: 2+2; or 2+1+1? But internal can take at most1, so 2+2 =4, also 2+1+1? That would be 2 on one end, 1 on internal, 1 on other end (but that's total 4, but other end can take 1? yes, ends can take up to 2, so 1 is allowed. So multiple ways.
R=5: 2+2+1 (internal). That's max. So all R possible. So for g=2, all b from 1 to 6 achievable? Wait L = g-1 =1, so b min=1. b=1 works? baseline internal=1, ends=0 total=1 => sequence: G B G? Actually with g=2, b=1: we need exactly one B. But internal gap must be at least 1, so with b=1 we can assign it to internal gap=1, ends=0 -> sequence G B G. That's valid, no three B's (only one). So b=1 works. b=2,3,4,5,6 all work as above. So range [1,6] works. But is b=0 possible? With g=2, need two G's but they would be adjacent because no B to separate, violating condition (no two G's adjacent). So b=0 invalid. So indeed b must be ≥1.
g=3: L = g-1=2, U=2*(3+1)=8. Baseline internal gaps (two gaps) each 1 -> total 2. Ends 0. So baseline b=2. Capacity: internal each can add up to 1 (total 2), ends each up to 2 (total 4). So total capacity 6, so b can be up to 8. R from 0 to 6. Need to check if all R in 0..6 achievable? Possibly yes because the capacities are sufficient and we have flexibility. For R up to 4, we can add to ends. For R=5: need 5 extra. Could be 2+2+1 (one internal) =5. That's possible. R=6: 2+2+1+1? Actually internal two, so can add 1 to each internal and 2 to each end: that sums 2+2+1+1=6. So yes all R achievable. So b from 2 to 8 works.
g=4: L=3, U=10. Baseline internal 3 gaps each 1 -> baseline b=3. Capacity: internal add up to 1 each (3), ends add up to 2 each (4) => total capacity 7, so b up to 10. R from 0..7. All possible? Likely yes. But need to ensure that R=7 can be done: internal all at max (add 1 each =3), ends both at max (add 2 each =4) total 7. So yes. Lower values achievable by distributing.
Thus it appears that any integer b between g-1 and 2g+2 inclusive is feasible, provided g>=1? But what about g=1: L=0, U=4. So b ∈ [0,4]. That seems correct from earlier reasoning. So condition is: b >= g-1 and b <= 2g+2.
But we must also consider the possibility that the girl's count could be zero? The problem says positive integers, so no zero. So g>=1.
But wait: In our examples, for (1,6) we had g=1, b=6. 6 > 4, so fails. (2,11): g=2, b=11 > 6, fails. (4,3): g=4, b=3: check: g-1=3, b=3 satisfies b >= 3? Actually b=3 equals lower bound 3. So works. (5,5): g=5, b=5: lower bound 4, upper bound 2*6=12, so b=5 works.
So this condition matches examples.
But is there any scenario where b is between g-1 and 2g+2 but still impossible due to some other nuance? Let's test borderline: g=2, b=6 works as we saw. g=3, b=8 works (max). g=1, b=4 works: four B's; pattern: BB G BB? That's two runs of B's: left and right. But with only one G, we have two gaps. Max each 2, total 4. Sequence: BB G BB is length 5? Actually counts: 2+1+2=5, yes. Check: no three B's? Runs are 2 and 2, okay. So works. b=0 works for g=1? Sequence just G, that's fine (no two G's adjacent trivially, no three B's). So g=1,b=0 works, but note the girl has at least one finger and the boy has zero? But boy's hand count would be zero? But the input says positive integers for boy's hands as well? "The second line contains two integers not exceeding 100." It says "two integers" but not explicitly "positive". It says "two integers not exceeding 100." Could be zero? Usually "positive integers" would be said, but first line explicitly says positive, second line does not. Let's check statement: "The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly."
So the girl's numbers are positive; the boy's numbers are nonnegative? It says "integers", could be zero. So the boy might have zero fingers on a hand. That's allowed. So b could be 0. In that case, for a pairing, we might have b=0. Then check condition: if g>=2, then we need at least g-1 B's to separate G's, so b=0 would be invalid. If g=1, b=0 works. So our condition still holds: b >= g-1. For g=1, g-1=0, so b=0 ok. Upper bound: b <= 2g+2 still holds. b=0 <= 4. So condition works.
But also consider b very small but possibly g=1: b=0 ok. So we need to handle b=0.
Now, is there any additional constraint about the boy's fingers not touching three? That we already accounted. But also the condition "no three fingers of the boy should touch each other" might also imply that there cannot be three consecutive boy fingers anywhere, including across gaps? But since G's separate, it's fine.
Thus the problem reduces to checking for each pairing (g,b) if g-1 <= b <= 2g+2. However, is it symmetric? Could we also consider swapping roles? No, the girl's condition is strict: no two girl fingers adjacent. The boy's condition is looser: no three boy fingers consecutive. So the constraints are not symmetric. So we must check the pairing with girl count g and boy count b.
But wait: Could we also consider the orientation where the boy is on left or right, but does that swap the roles of counts? No, it's just which hand of each is used. So we check two pairs.
Thus algorithm: read al, ar, bl, br.
Set ans = false.
Check pair1: g = al, b = br. If (g-1 <= b <= 2*g+2) then ans = true.
Check pair2: g = ar, b = bl. If (g-1 <= b <= 2*g+2) then ans = true.
If ans true print YES else NO.
But is that always correct? Let's test some edge cases manually.
Case: g=1, b=5. Then g-1=0, 2g+2=4, so b=5 >4 => NO. That matches earlier reasoning: with one G, max B is 4.
Case: g=2, b=0: g-1=1, so b=0 <1 => NO. Indeed two G's would be adjacent, invalid.
Case: g=2, b=1: g-1=1, so b=1 meets lower bound. Upper bound 6. So YES. Indeed pattern G B G works. No three B's.
Case: g=2, b=2: works (G BB G? That's G, then two B's, then G. But check: between the two G's, there are two B's, which is allowed. However, we must ensure no three B's: run of length 2 is fine. So sequence: G BB G works. Or G B G B? Wait that would require two G's and two B's, but to have two B's, we could have one B between G's and one B at an end: G B G B. That's also valid. So YES.
Case: g=2, b=6: we already said works: BB G BB G BB? That's 2+1+2+1+2 = 8? Actually let's compute: g=2 means two G's. Sequence length = g+b = 8. With ends both BB (2 each), internal gap BB (2) gives: BB G BB G BB: B count = 2+2+2=6, G count=2. Runs: BB, BB, BB each length 2, no three B's. Also G's separated by BB, good. So YES.
Case: g=3, b=2: lower bound =2, so b=2 ok. Upper bound 8. Can we have g=3, b=2? Minimum b to separate three G's is 2 (internal gaps at least 1 each). So we need exactly 2 B's, both used internally. So pattern: G B G B G. That uses two B's, placed between G's. Ends 0. Sequence: G B G B G. No three B's (only single B's). So YES.
Case: g=3, b=1: b=1 <2 => NO.
Case: g=100, b= some large numbers up to 100? Since b <= 2g+2 = 202, and boy's numbers <=100, so b <=100 always <=202 for g>=1? Actually g max 100, so 2g+2 = 202, which is >100, so upper bound never restricts for typical inputs? Wait, but b could be as high as 100, and 100 <=202 always if g>=1? For g=1, 2g+2=4, so b=100 would be >4, so upper bound can restrict for small g. So it's necessary.
But is the condition also sufficient for all? Let's thoroughly test.
We need to prove: For any integers g>=1, b>=0, there exists a binary string with exactly g G's, b B's, no two G's adjacent, and no run of B's longer than 2, if and only if g-1 <= b <= 2g+2.
We already argued necessity:
No two G adjacent => at least g-1 B's between them if g>=2, and for g=1, at least 0. So b >= max(0, g-1). This gives b >= g-1 (since g-1 may be 0).
No three B's => each run of B's (which are exactly the gaps) must have length <=2. With g G's, there are at most g+1 runs (including ends). So maximum total B is 2*(g+1). So b <= 2g+2.
So necessity is clear.
Sufficiency: For any b in [g-1, 2g+2], can we assign gap sizes?
We need to find nonnegative integers x0,...,xg such that:
For i=1,...,g-1: xi >= 1 and <= 2.
For i=0 and g: 0 <= xi <= 2.
Sum xi = b.
This is a linear constraints feasibility. We can construct explicitly.
Let base: For internal gaps, set xi = 1 for i=1..g-1. For ends, set x0 = xg = 0. Then base sum = g-1.
If b = g-1, done.
If b > g-1, we need to add D = b - (g-1) extra B's, with D <= (g+3) as argued. We need to distribute these D increments across gaps without exceeding max 2 per gap.
We can fill as follows:
First, add to ends up to 2 each. Let add_ends = min(2, D) to one end, etc. But we need to ensure we can achieve any D up to total capacity.
We have capacities: ends each max 2, internals each max additional 1 (since they start at 1). So total extra capacity = (g-1)1 + 22 = g+3.
Now, is it possible to achieve any integer D between 0 and g+3? Since we have items with capacities 1 and 2, we can achieve any sum from 0 to total capacity because we have at least two "2"s and many "1"s. The set of achievable sums from multiset of 1's and 2's is all integers from 0 to total, because we have enough 1's to fill gaps. Formal: With at least one 1, we can achieve any integer up to total as long as we have enough 1's to adjust parity. Actually, the achievable sums from a set of numbers each ≤2, with at most two 2's and the rest 1's, is all integers from 0 to total because the only potential missing sums would be due to lack of 1's to make odd numbers? Let's test: If we have only 2's and no 1's, then only even sums achievable. But we have (g-1) internal gaps each can contribute at most 1 extra, which are 1's. So we have at least one 1 if g>=2 (since g-1 >=1). If g=1, there are no internal gaps; we only have two ends each up to 2. Then total capacity 4, achievable sums: 0,1,2,3,4? With two slots each 0-2, can we get sum 1? Yes: (1,0). Sum 3: (1,2) or (2,1). So all sums 0..4 are achievable. For g>=2, we have at least one internal gap providing 1 capacity. So we can achieve any D. A simple constructive method: Start with all gaps at min (internal=1, ends=0). Then we can add 1 to any gap until we reach desired total. Since we have ends that can take up to 2, and internals up to 2 (since they start at 1, max 2), we can increment by 1 each time by choosing a gap that hasn't reached its max. As long as we haven't exceeded capacity, we can achieve any intermediate sum because increments are by 1. So yes, any integer D is achievable. So sufficiency holds.
Thus the condition is both necessary and sufficient.
But wait: Could there be a scenario where the boy's hand has zero fingers? b=0. Then if g=1, condition passes. But is the boy comfortable with zero fingers? The condition "no three fingers of the boy should touch each other" is vacuously true because there are no fingers. So yes.
Thus algorithm is straightforward.
But is there any nuance about the direction of the hand? Possibly the order of fingers might be reversed if the boy uses left hand vs right hand? That is, the natural order of the boy's fingers might be reversed relative to the girl's order. Could that affect the feasibility? Because in our model, we treat the sequences as arbitrary interleavings, but we assume that the order of G's is fixed, and the order of B's is fixed, but we can choose the relative interleaving. However, if the order of B's is reversed (i.e., the boy's fingers appear in opposite order), does that affect the constraints? The constraints only care about adjacency of same-type fingers, not about which specific finger. So reversing the order of B's does not change the pattern of B runs; it's still the same multiset of B's. The order of B's within a run is irrelevant because they are all B. So flipping the order does not matter. Even if we consider the order of B's as a sequence, the condition "no three B's touch each other" is about consecutive B's in the final interleaving, regardless of which specific B they are. So the order of B's along the hand doesn't affect the feasibility because we can choose any interleaving that respects the order. But does the order constraint (preserving the order) impose restrictions beyond just the count? For example, suppose we have g=2, b=2. We need to interleave two sequences: G1 G2 (ordered) and B1 B2 (ordered). Can we produce the pattern G B G B? That would be: G1, B1, G2, B2. That respects order: G1 before G2, B1 before B2. That's fine. Can we produce G B B G? That would be: G1, B1, B2, G2. That also respects order: G1 before G2, B1 before B2. So pattern G B B G is also valid. So both patterns are achievable. So the order constraint does not restrict further because we can always arrange the B's in any positions as long as the relative order among B's is preserved (i.e., we cannot have B2 before B1). But in the pattern G B G B, B's are separated, order preserved. In G B B G, B's are together, order preserved. So any pattern of positions for B's (i.e., any subset of positions for B's) yields a valid interleaving as long as we assign B's in order to those positions. Since we don't care which B goes where, any binary string with g G's and b B's can be realized as an interleaving of two sequences with given order? Actually yes: Given any sequence of G's and B's with total counts, we can assign the G's in order to the G positions, and the B's in order to the B positions. This yields a valid merge preserving order. So any binary string is feasible. So no further restrictions. Thus our reduction to binary strings is correct.
But wait: There's also the factor of which side of the girl the boy stands. Could that affect which hand is used and thus the order of fingers? Possibly the order of fingers on the girl's hand might be reversed depending on whether she uses left or right hand? Since the girl's hand is either left or right. Similarly for the boy. If the order is reversed for one hand relative to the other, then the interleaving might have the order of the girl's fingers reversed if she uses her right hand versus left hand. But again, since the fingers are indistinguishable except for type, reversing the order of G's does not change anything because G's are identical. So it's irrelevant. So we only care about counts.
Thus the solution is simple.
Now we should test with the given examples and maybe some edge cases.
Example1: al=5, ar=1, bl=10, br=5.
Pair1: g=5, b=5 => condition: g-1=4, 2g+2=12 => 5 in [4,12] => YES.
Pair2: g=1, b=10 => 1-1=0, 2*1+2=4 => 10 not in [0,4] => NO. So overall YES.
Example2: al=4, ar=5, bl=3, br=3.
Pair1: (4,3): 4-1=3, 2*4+2=10 => 3 in [3,10]? 3 is lower bound, so YES. So answer YES.
Example3: al=1, ar=2, bl=11, br=6.
Pair1: (1,6): 0 to 4 => 6>4 => NO.
Pair2: (2,11): 1 to 6 => 11>6 => NO. So NO.
Matches.
Now consider some other test cases.
Case: al=1, ar=1, bl=0, br=0.
Pair1: (1,0): 0 in [0,4]? yes. So YES. That means they can hold hands comfortably even if boy has no fingers? The girl has 1 finger, boy has 0. They hold hands with girl's left and boy's right? But boy's right has 0 fingers. How can they hold hands? Possibly they can't physically hold hands if boy has no fingers? But the problem probably still considers it; the boy just has no fingers on that hand, so they can't interlace? But it says "determine if they can hold hands so that the both were comfortable." If one has zero fingers, can they hold hands? Possibly they can still hold hands (like just grasping the hand with no fingers? That seems odd). But we follow the combinatorial condition; if b=0, g=1, then the sequence would be just G (girl's finger). The condition: no two girl's fingers touch (okay), no three boy's fingers (vacuously true). So it's comfortable. But is it possible to hold hands? The boy's hand has no fingers; does he have a palm? The problem might consider only fingers, but perhaps they need at least one finger to hold? However, input says integers not exceeding 100, no explicit positivity for boy's numbers, so zero is allowed. So we should accept.
But maybe there is a hidden requirement: they need to actually hold hands, which requires at least one finger from each? But the problem doesn't state that. It says "determine if they can hold hands so that the both were comfortable." If one hand has zero fingers, can they hold hands? Possibly they can still grasp with palm? But the story says "holding hands", typical requires fingers. However, I'd follow the combinatorial interpretation, as it's a programming contest problem. Likely they allow zero.
Let's test: If both pairs yield b=0 and g=1, it's YES. If g=2, b=0, then NO. That seems plausible.
Now we should also consider the possibility that the condition might be symmetric? But no.
Also, could we consider that the boy and girl don't care who goes left or right, meaning we also have the possibility that the girl goes left and boy right? Actually we already consider both orientations. That's it.
But wait: "The boy and the girl don't care who goes to the left and who goes to the right." That means they can choose either the boy on left or the boy on right. That's exactly the two pairings we considered. So we covered both.
Now, is there any possibility that they could also exchange which hand they use? For example, if the boy is on the left, could he use his left hand instead? The description says: "if the boy goes to the left of the girl, he will take her left hand with his right one". So it's fixed. So only those two.
Thus solution done.
But wait, we should verify the derived inequality carefully for all g.
g>=1: b must satisfy g-1 <= b <= 2g+2.
But what about g=0? Not possible as per input (positive integers for girl). So ignore.
Now, is there any situation where b is too low but we could still satisfy the no-two-girl adjacent by placing the girl's fingers not all in the line? But it's a line of fingers when holding hands; there is no alternative arrangement. The girl's fingers are on her hand, they are in a line. When they interlock, the order is linear. So our modeling is correct.
But hold on: The problem says "no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger." This could be interpreted as: In the interlocking, if you look at the girl's fingers in the order they appear along the hand, between any two consecutive girl fingers (in that order) there must be at least one boy finger. That is essentially the same as no two consecutive G's in the interleaved sequence. Yes.
The second condition: "no three fingers of the boy should touch each other." Means that in the interleaved sequence, there should be no three consecutive B's.
Thus it's correct.
One more nuance: Could there be a scenario where the girl's fingers are not all used? They are all present; we must use all fingers. So g is fixed.
Thus the condition is exact.
Now we can code.
But before coding, let's double-check if there is any scenario where b is within [g-1, 2g+2] but still impossible due to ordering constraints if we consider that the boy's fingers must appear in a specific order and we might need to assign them to gaps such that the order is preserved and also the runs of B's might need to be broken? However, any gap assignment yields a sequence. Since we assign B's to gaps in order, as long as the gaps are contiguous segments of B's, the order of B's within each gap is preserved (since they appear in order). That's fine. So no issue.
Thus algorithm is trivial: read, check two conditions.
But wait: Are we sure about the maximum being 2g+2? Consider g=1: there are two gaps: left and right. Each max 2, so max 4. That seems right.
But what about g=0? Not needed.
Now, some might think the upper bound is 2g (like alternating with at most two B's between G's) but we have ends also can have two. So 2g+2.
Let's test with g=1, b=4: Sequence: B B G B B? That is 2 left, 1 G, 2 right: total B=4, G=1. That's valid: runs of B's length 2 each. No three B's. So works. Good.
Now check g=1, b=3: possible? For example, B B G B: runs 2 and 1 => valid. So yes.
Now check g=1, b=2: BB G or G BB, etc.
So condition works.
Now for g=2, b=6 we did.
Now check g=2, b=5: Can we do? Baseline internal=1, need extra 4. Capacity: internal max extra 1, ends max extra 2 each. So we can add e.g., ends both 2 => extra 4, internal stays 1. That yields ends 2, internal 1, total 2+1+2=5. Sequence: BB G B G BB? Wait careful: With g=2, the gaps are: left, middle, right. Setting left=2, middle=1, right=2 gives B B G B G B B? Actually check: left gap: 2 B's, then G, then middle gap: 1 B, then G, then right gap: 2 B's. So sequence: B B G B G B B. That's B count = 2+1+2 = 5, G count =2. Runs: first BB (2), then single B after first G? Actually after first G, we have middle gap of 1 B, then G, then right gap of 2 B's. So the runs: left BB (len2), then after first G there is a B (len1) then second G, then BB (len2). However, note that the middle gap B is isolated (single). So no three consecutive B's. So valid.
Or alternative distribution: left 2, middle 2, right 1 => B B G B B G B, runs: BB, BB, B? Actually sequence: BB G BB G B. That yields runs: BB, then after first G we have BB (len2), then after second G we have B (len1). So still no three B's. So valid.
Thus b=5 works.
Now b=0 for g=2 fails.
Thus condition seems correct.
Now we can implement.
But we should also consider that the input numbers are up to 100, so simple.
We must output YES or NO.
Edge Cases:
Girl: al=100, ar=100, Boy: bl=0, br=0. Check pair1: g=100,b=0 => need b >= 99? 0<99 => NO. Pair2: g=100,b=0 => NO. So output NO.
But is that plausible? Girl has 1 finger on left, boy has 0 on right. They hold left hand of girl with right hand of boy (0 fingers). The girl's single finger doesn't touch any other girl finger, and boy has no fingers, so condition satisfied. So YES.
Now, could there be scenario where both pairs satisfy? Then YES.
Now, implementation: just compute.
But before finalizing, I want to ensure there's no twist about which side is left/right that might affect the order of gaps. For example, if the boy is on the left, his right hand is used; maybe his fingers are oriented such that the order of his fingers from leftmost to rightmost is opposite to the girl's order? But as argued, since they are indistinguishable, order doesn't matter. However, there is one nuance: When interleaving, the sequence must preserve the order within each hand. But if the orders are opposite, does that affect which interleavings are possible? Actually, any binary string with the correct counts can be realized as an interleaving of two sequences regardless of whether one of the sequences is reversed? Because if we have two sequences A and B, and we want to interleave them preserving order, the set of possible interleavings is exactly all ways to merge the two sequences while keeping relative order. If we reverse one sequence, the set of possible interleavings is different because the order constraint changes. But in our model, we didn't consider the orientation; we assumed that both sequences are in the same direction (e.g., from leftmost to rightmost along the hand). But the hand orientation may cause the natural order of fingers on the boy's hand (relative to the line) to be reversed compared to the girl's hand. However, we have the freedom to choose which direction we consider as the line direction. The line direction is from the boy's left side to the girl's right side (or vice versa). We need to define the ordering of fingers along that line. For a given physical configuration, the ordering of each person's fingers along that line is determined by anatomy and orientation. If the boy is on left and uses his right hand, the order of his fingers from leftmost to rightmost might be: starting from his pinky (which is on the left) to his thumb (on the right). For the girl using her left hand, the order from leftmost to rightmost might be from her thumb (on the left) to her pinky (on the right) depending on hand orientation. So the two orders might be opposite. But does this affect feasibility? Let's think: We have two sequences, each with a fixed order. We interleave them along a line. The constraints are about adjacency of same-type fingers. If the orders are opposite, does that restrict possible patterns? For a given pattern (binary string), we can assign the girl's fingers in order to the positions marked G. For the boy, we assign his fingers in order to the positions marked B. If the boy's order is reversed relative to the line, that would mean that the positions marked B must be assigned in reverse order to preserve his natural order? Actually, if we define the line direction as from left to right, then each person's fingers have a natural order along that line. For the girl, her fingers appear in some order (say increasing from thumb to pinky). For the boy, his fingers appear in some order (maybe also from thumb to pinky, but if his hand is oriented oppositely, his thumb might be on the right, so the order from left to right would be pinky, ring, middle, index, thumb — i.e., reversed relative to his natural order). So the sequence of boy's fingers along the line is the reverse of his natural order. But in the interleaving, we are merging the two sequences as they appear along the line. The constraint of preserving order within each hand means that along the line, the girl's fingers must appear in her order, and the boy's fingers must appear in his order as they appear on the line. If the boy's order along the line is reversed relative to his natural hand order, then the merging must respect that reversed order. However, we can still achieve any pattern? Let's analyze.
Suppose the boy's natural order (from his perspective) is B1, B2, B3,... (say from thumb to pinky). But on the line (left to right), the order might be reversed: Bk,..., B2, B1. So the constraint is that in the final sequence (left to right), the boy's fingers must appear in that specific order (reverse). That is a constraint: the positions occupied by boy's fingers must be such that if we read them left to right, they follow a specific permutation (decreasing index). But does this restrict the possible patterns? For a given pattern of B positions (i.e., which indices are B), as long as we assign the specific boy fingers in that order, we need the sequence of boy finger labels to be decreasing. But since the labels are not relevant for the adjacency condition (they're all B), does the order constraint matter? It might impose that the boy's fingers cannot be placed arbitrarily; we must assign the specific finger to a specific position consistent with order. However, because all B fingers are considered identical for the purpose of the constraints (we only care about adjacency of B's, not which specific B), any assignment of boy fingers to B positions will satisfy the order constraint if we assign the first (leftmost) B position to the appropriate finger. But if the order of boy fingers along the line is fixed (say reversed), then the pattern of B positions must be such that when we assign the boy's fingers in that fixed order, it matches the order of positions. But if we only care about counts, we can always assign the boy's fingers to the B positions in the order they appear along the line. For any set of positions, if we list them left to right, that's exactly the order they appear. The boy's fingers must appear in that order. So we need to label the B positions with the boy's finger IDs in that order. That is always possible regardless of the pattern: we simply assign the first (leftmost) boy finger (according to his order along the line) to the leftmost B position, the next to the next B position, etc. This works as long as the number of B positions equals the number of boy fingers. That's always true. So any pattern of B positions (any binary string) can be realized while respecting the order of the boy's fingers along the line, because the order along the line is exactly the order we assign them. There's no further restriction like the boy's order might require some specific pattern of gaps? No.
But what about the girl's order? Similarly, any pattern works.
Thus orientation does not impose additional restrictions.
But there is a subtlety: If the boy is on the left, his right hand's fingers order from left to right might be e.g., pinky, ring, middle, index, thumb. That's a specific order. The girl's left hand from left to right might be thumb, index, middle, ring, pinky (if her palm faces right). So the two orders are opposite. Does that affect the feasibility of satisfying "between any two girl's fingers there is a boy's finger"? No, because that condition doesn't involve the order of individual fingers. So it's fine.
Thus the simple count condition stands.
Now, we should also consider if the condition "no three fingers of the boy should touch each other" might also be interpreted as no three boy's fingers are consecutive in the order of his own hand, i.e., along his hand, not along the interlocked line. That would be different. But reading: "no three fingers of the boy should touch each other." In the context of holding hands, touching refers to physical contact between fingers. When hands are interlaced, fingers touch if they are adjacent in the interlocked line. So it's about consecutive in the interlaced sequence. So it's consistent.
Thus solution is as described.
Now, we might implement a function feasible(g, b) returning true if g-1 <= b <= 2*g+2.
But be careful: For g=0? Not possible. But if somehow g=0 (if we allowed girl hand with 0 fingers), then condition would be? The problem says positive, so ignore.
Now, but note: The girl's two hands have positive numbers, but we are only using one of them for the pairing. So g is either al or ar, which are positive. So g≥1.
Now, consider the possibility that b could be negative? No.
Thus implementation.
But wait: The problem statement says: "The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100." It doesn't say "non-negative", but "integers" typically could include zero. Since they didn't say positive, zero is allowed. So we handle b=0.
Now, the examples: third example has boy numbers 11 and 6, both positive. So fine.
Now, confirm if the inequality works for all cases: What about b being exactly g-1? For g=1, g-1=0, that works. For g=2, b=1 works. For g=3, b=2 works. So yes.
Now, also check upper bound for large g: b=2g+2 works, as we can put 2 B's in each gap. So yes.
Thus answer.
But hold on: Could there be a scenario where b is less than g-1 but still possible because the girl's fingers might not all be used? The problem says they have that many fingers, and they are all there. So all must be used.
Thus final solution: read a_l, a_r, b_l, b_r. For each pairing, check condition.
Implementation in C++:
code
#include <iostream>
using namespace std;
bool check(int g, int b) {
return (b >= g-1 && b <= 2*g+2);
}
int main() {
int al, ar, bl, br;
cin >> al >> ar >> bl >> br;
if (check(al, br) || check(ar, bl))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
But wait: The note says "The boy and the girl don't really care who goes to the left." That we covered.
Now, is there any possibility that both pairings are considered simultaneously? No, they choose one arrangement.
Thus we are done.
But let's think: Could there be a scenario where the boy goes to the left but uses his left hand? The description explicitly says which hand is used. So only two.
Now, double-check with possible tricky input: al=1, ar=1, bl=1, br=1. Pair1: (1,1): 1 in [0,4] => YES. So answer YES. Let's see if it's physically possible: girl left 1, boy right 1. Interlace: G B or B G? Both are fine: no two G adjacent (only one), no three B's (only one). So YES.
Another: al=2, ar=2, bl=2, br=2. Pair1: (2,2): 2 in [1,6] => YES. Patterns: G B G B works. So YES.
Now: al=2, ar=2, bl=1, br=1. Pair1: (2,1): b=1 meets lower bound 1 => YES. Pattern: G B G (internal gap=1, ends 0). Works.
Now: al=2, ar=2, bl=0, br=0. Both pairs: (2,0) fails (b=0<1) and (2,0) fails => NO. Indeed with two girl fingers and no boy fingers, they would touch.
Now: al=2, ar=2, bl=5, br=5. Pair1: (2,5): b=5 within [1,6] => YES. Pattern: e.g., BB G BB G B? Actually need total B=5. Could be ends: left=2, middle=1, right=2 => 5. Sequence: BB G B G BB. That's runs: BB, B, BB -> lengths 2,1,2, no three consecutive. So YES.
Now: al=2, ar=2, bl=6, br=6. (2,6): b=6 within [1,6] => YES (upper bound inclusive). Pattern: ends 2, middle 2 => total 2+2+2=6 => BB G BB G BB. Works. So YES.
Now: al=2, ar=2, bl=7, br=7. (2,7): b=7 >6 => NO. So boy can't have 7 fingers with 2 girl fingers.
Now: al=3, ar=3, bl=7, br=7. (3,7): lower bound 2, upper bound 8 => 7 in [2,8] => YES. Pattern: maybe ends 2, internal gaps both 2? That sums 2+2+2+2? Wait with g=3, gaps: left, mid1, mid2, right (total 4). To sum to 7, we need one gap 1 and three gaps 2: e.g., left=2, mid1=2, mid2=2, right=1 => total 7. That yields runs: BB, BB, BB, B? Actually sequence: left BB, G, mid1 BB, G, mid2 BB, G, right B. That's runs: BB, BB, BB, B (length 2,2,2,1) no three consecutive? No run exceeds 2, so fine. So YES.
Thus condition seems solid.
Now, potential oversight: The condition "between any two girl's fingers there is a boy's finger" might be interpreted as: For any two fingers of the girl (not necessarily consecutive in the line), there must be at least one boy finger between them. That is equivalent to saying that there is no pair of girl fingers that are adjacent? Actually if they are not adjacent but there is a boy finger between them, it's fine. But if they are separated by another girl finger? That would be three girl fingers in a row? Actually if you have three girl fingers, the outer two have another girl finger between them, which is not a boy finger, so that would violate "between any two girl's fingers there is a boy's finger"? The phrase "between any two girl's fingers there is a boy's finger" could be interpreted as: For any two distinct girl fingers, there exists at least one boy finger that lies between them in the sequence. This is a stronger condition than simply no two consecutive G's. For example, consider sequence: G B G B G. Take the first and third G: there is a B between them (the B after first G) and also the second G? Actually the condition says between any two girl's fingers there is a boy's finger. If we have three G's with B's only between consecutive ones, then between the first and third G, there is a boy finger? The sequence is G B G B G. Between first and third, the subsequence is B G B. There is a boy finger (the first B) between them? Actually between the first G (position1) and third G (position5), the positions in between are 2,3,4. Among these, there is at least one B (position2). So condition holds. However, if we have G G B G: the first and second G are adjacent, so there is no B between them, violation. So the condition "between any two girl's fingers there is a boy's finger" is equivalent to: There is no pair of girl fingers that are adjacent? Not exactly; it says between any two, there must be a boy finger. If the girl fingers are not adjacent, there could still be an issue if there are multiple girl fingers with no boy between some pair that are not adjacent but have only other girl fingers in between? That would require at least three girl fingers with no B between the outermost two? But if there are three G's with B's only between consecutive ones, like G B G B G, between the first and third, there is a B? The positions between them include a B (position2) and also a G (position3). The condition only requires that there is at least one boy finger between them, not that all intervening are boy fingers. So it's satisfied as long as there is at least one B. However, if we have G G B G, between first and third G? First and third G are positions1 and4; intervening positions2,3: positions2 is G, position3 is B. There is a B (position3) between them, so that condition between first and third is satisfied. But between first and second, there is no B. So condition fails because the pair (first, second) are two girl's fingers with no boy finger between them. So the condition effectively requires that for every pair of girl fingers, there is at least one boy finger somewhere strictly between them in the ordering. This is equivalent to: There cannot be two girl fingers that are consecutive? Not exactly; if there are three G's with a B only between the second and third? Consider G G B G: The first and second are consecutive, so there is a pair with no B. So violation. So the condition "between any two girl's fingers there is a boy's finger" is equivalent to: There is no pair of adjacent girl fingers? Let's analyze: If there is any pair of adjacent girl fingers, then those two violate the condition because there is no boy finger between them (they are next to each other). Conversely, if no two girl fingers are adjacent, then for any pair of girl fingers, there is at least one position between them (since they are separated by at least one position) and that position contains a boy finger? Not necessarily: Suppose we have G B B G. The two G's are not adjacent (positions1 and4). The positions between are 2 and 3, both B's. So there is a boy finger, good. Suppose we have G B G B G: between first and third G, positions2,3,4: there is a B at position2. So condition holds. Now, could there be a scenario where no two G's are adjacent, yet there exists a pair of G's with no B between them? If no two are adjacent, then between any two G's, there is at least one position. However, that position could be a G? No, because if there is a G between them, then that G would be adjacent to one of them? Actually if we have G1 ... G2 ... G3, with G1 and G3 not adjacent, but there is a G2 between them. That means G1 and G2 might be adjacent or not. But if G1 and G2 are not adjacent, then there is at least one position between them, which could be a B. However, the condition for pair (G1, G3) requires a boy finger somewhere between them. If the only intervening symbols are G2 (which is a girl finger) and maybe B's, then there could be a boy finger as well. But is it possible that between G1 and G3, all intervening positions are G's? That would mean a block of consecutive G's, which would include adjacent G's, contradicting the assumption of no adjacent G's? Actually if we have G1, then G2, then G3 consecutively, that's three consecutive G's, which includes adjacent pairs. So if no two G's are adjacent, then there cannot be three G's in a row, and any two G's will have at least one position between them, but that position must be a B because if it were a G, then that G would be adjacent to one of the two. Wait consider G1 at position i, G3 at position j>i+1. If all positions between i and j are G's, then position i+1 is G, so G1 and G2 (i+1) are adjacent, violating no adjacent G's. So it's impossible. Thus if no two G's are adjacent, then between any two G's, there must be at least one B. Because the immediate next position after the left G is a B (since not adjacent), and that B lies between them. So indeed the condition "no two G's adjacent" is equivalent to "between any two G's there is at least one B". Let's formalize: If no two G's are adjacent, then for any two distinct G's, consider the leftmost and rightmost among them. The leftmost G has a position, the next position is either B (since not adjacent) or another G? But if it's another G, then they are adjacent, contradiction. So the immediate neighbor to the right of the leftmost G is B. That B lies between the leftmost G and any G to its right. So condition holds. Conversely, if between any two G's there is a B, then in particular for any two consecutive G's in the ordering, there must be a B between them, meaning they cannot be adjacent. So the two formulations are equivalent. Good.
Thus our interpretation is correct.
Now, the second condition: "no three fingers of the boy should touch each other." That means no three consecutive B's. Equivalent to runs of B's length ≤2.
Thus the combinatorial model is validated.
Thus the answer is straightforward.
Now, could there be any scenario where the condition for the boy also interacts with the girl's condition in a more complex way? For instance, if we have many B's, we could place them at ends, but that's already accounted.
Thus final solution: implement check function and test two pairings.
Now, the constraints are small, but we can also solve by checking inequalities.
However, there is nuance: Our derived condition assumes that there is at least one G, which is always true. But what if b is huge (like >2g+2)? Then impossible. That's covered.
But wait: Could there be a scenario where we could also swap the roles? The problem says "the boy and the girl don't care who goes to the left and who goes to the right." That's already accounted. There's no option to have the girl on left and boy on right but using different hands? The description explicitly says if boy on left, he uses right hand and she uses left; if boy on right, he uses left and she uses right. So yes.
Now, but is there a scenario where they could also choose to hold hands with the girl's left and boy's left (both left hands) if they face each other? That would be unnatural but maybe possible? However, the problem states the rule: "if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa." So it's fixed.
Thus only two pairings.
Now, one more thought: The girl has two hands, each with fingers. The boy has two hands. They are going to take a walk holding hands. Typically, when two people walk hand in hand, they each use one hand, either both right or both left? Usually you hold hands with your right hand holding their left hand if you are side by side? Actually, if you are walking side by side, you typically hold hands with the hand that is closest: the right hand of the person on the left holds the left hand of the person on the right. That's exactly the description. So it's consistent.
Now, the problem likely from some contest, maybe Codeforces? I recall a problem "Handshakes" or something? But it's fine.
Thus solution is ready.
But before finalizing, let's verify with some random brute force for small numbers to ensure the inequality is both necessary and sufficient. We could do mental check.
Let's write a small script mentally:
For g=1: b can be 0,1,2,3,4. Patterns:
b=0: "G" ok.
b=1: "G B" or "B G" ok.
b=2: "B B G", "B G B", "G B B" — all have max run 2, ok.
b=3: "B B B G"? That has run of 3 B's if placed together, but we can avoid: "B B G B" has runs: BB, B -> lengths 2 and1; "B G B B" similarly; "G B B B"? That's G then BBB (3) -> not allowed. So need to check if any arrangement for b=3, g=1 exists. We can do "B B G B": positions: B B G B => runs: first two B's (len2), then after G a single B (len1). So ok. So b=3 works. Similarly "B G B B" works. So b=3 ok.
b=4: "B B G B B" works (runs 2 and2). b=5: would require at least 5 B's, but with only two gaps, max each 2, total max 4. So b=5 impossible. So condition holds.
g=2: b can be 1..6. Check b=6 we saw. b=5 works. b=4 works. b=3 works? For g=2, b=3. Patterns: G B G B? That's b=2 actually. For b=3, we need 3 B's. Patterns: G B B G B? That would be 3 B's but three G's? Actually need exactly 2 G's. Possible patterns: B G B G B => G count? That's 2 G's? Actually B G B G B: positions: B G B G B => G's at 2 and4, B's at1,3,5: runs: first B alone, then B between G's? Actually runs: position1 B (len1), after G at2, we have B at3 (len1), after G at4, B at5 (len1). So no three B's, and G's not adjacent (they are separated by B at3). So b=3 works. Also G B B G B? That would be G, B, B, G, B: G's at1,4 separated by BB? Actually between G's there is BB (len2), so ok. So b=3 works. b=2 works. b=1 works. b=0 fails. So condition works.
Thus fine.
Now, confirm with g=100, b=202 works? That's max, pattern: all gaps =2, sequence: BB G BB G ... G BB. That's valid. So yes.
Thus solution done.
But before concluding, let's ensure that the condition we derived is correct for all g. For g>=1, it's b between g-1 and 2g+2 inclusive.
Now, is there any scenario where b is exactly 2g+2 and g is huge, but we need to ensure that the runs of B's are at most 2. With all gaps =2, runs are length 2. So fine.
Now, potential pitfalls: The input might have extra spaces, but standard.
Now, implement.
But wait: There is a nuance: The problem statement says "two integers not exceeding 100" for the boy. It doesn't say they are non-negative, but could they be negative? That wouldn't make sense; number of fingers cannot be negative. So we assume non-negative integers.
Thus code as above.
Now, we might also consider if the numbers can be zero for girl? First line says positive, so no.
Now, also, note that the girl's left and right counts are both positive, but we only use one of them in each pairing. That's fine.
Now, double-check example 2: Input: 4 5; 3 3. Our code would check (4,3) -> true. So output YES.
Example 3: (1,6) false, (2,11) false => NO.
Matches.
Now, could there be a scenario where both pairings are false but still they could be comfortable if they, say, swap hands differently? For instance, if the boy goes to the left but uses his left hand? That would be unnatural, but maybe they could both use same-side hands if they face each other? However, the problem explicitly states the rule, so we stick to it.
Thus answer.
Now, let's write final solution in C++.
But the problem might be from some contest where they expect more reasoning, but simple code is fine.
Now, also note: The input numbers up to 100, but we could also solve by brute-force constructing all possible interleavings? That would be huge, but we can do simple inequality.
Now, final code.
Wait: One more nuance: The problem says "The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa." Could it be interpreted that they can also choose the orientation where the girl goes to the left of the boy, which is essentially the same as the boy going to the right? So we already consider both.
Thus answer.
Now, let's also consider if there is any possibility that the boy's hand and the girl's hand have fingers that are not all used because they could hold hands in a way that some fingers are not interlocked? Usually when you hold hands, all fingers are involved. The problem likely assumes all fingers are used; the condition is about the arrangement of all fingers.
Thus final.
I'll produce final answer.
But before finalizing, let's also see if the problem could be interpreted differently: Maybe the condition "between any two girl's fingers there is a boy's finger" means that for any two fingers of the girl, there must be at least one boy's finger physically between them, but not necessarily in the linear order? However, it's essentially the same.
Note: For g=1, g-1=0, so br>=0 is automatically true if br non-negative. But we also need to ensure br <= 4. So if br=5, fails.
Also, if bl is zero and ar=1, then bl >= 0 and <=4, so true.
Now, could there be any integer overflow? No, numbers up to 100.
Now, implement.
But wait: The condition might also need to consider that the boy's fingers count could be less than the minimum required for separation. That's what we did.
Thus final.
Now, I'll produce final answer in required language.
Given that the problem expects just YES or NO, we output accordingly.
I'll produce code in C++.
But to be thorough, maybe we should also consider if the boy's number of fingers might be larger than 2g+2 but still possible if we allow the girl's fingers to be not all used? No.
Thus final.
Now, I'll write the solution. The solution reduces to checking two possible pairings: either the boy is on the left (girl's left hand with boy's right hand) or on the right (girl's right hand with boy's left hand). For a given pair of counts (g) (girl fingers) and (b) (boy fingers), a comfortable arrangement exists if and only if the following adjacency constraints are satisfied:
No two girl fingers are adjacent, which requires at least (g-1) boy fingers (to separate them).
No three boy fingers are consecutive, which means the boy fingers can be placed in at most (g+1) gaps (including ends), each containing at most 2 fingers, giving an upper bound (b \le 2(g+1) = 2g+2).
Thus the condition is (g-1 \le b \le 2g+2).
We check both pairings; if either satisfies the inequality, the answer is YES, otherwise NO.
cpp
#include <iostream>
bool check(int g, int b) {
return b >= g - 1 && b <= 2 * g + 2;
}
int main() {
int al, ar, bl, br;
std::cin >> al >> ar >> bl >> br;
if (check(al, br) || check(ar, bl))
std::cout << "YES\n";
else
std::cout << "NO\n";
return 0;
}