We need to determine if the given sequence of crossovers (with '+' meaning plus wire is above minus wire at that crossing, '-' meaning minus above plus) can be untangled, given that on the left side (wall), plus is plugged into the top contact. On the right side (device), the contacts are also top and bottom, but we don't know which wire goes to which contact initially; the device cannot be moved, so the wiring at the device is fixed in some order (unknown?). Actually, we need to interpret the problem correctly.
We have two wires: plus and minus. They run from wall on the left to device on the right. The wall has two contacts: top and bottom. The problem says: "Mike knows the sequence in which the wires run above each other. Mike also noticed that on the left side, the "plus" wire is always plugged into the top contact (as seen on the picture). He would like to untangle the wires without unplugging them and without moving the device."
Thus at the left, plus is top, minus is bottom (since there are two contacts, plus is plugged into top, so minus must be bottom? The picture may show top contact is plus, bottom is minus. But could the wall have two contacts, one top, one bottom; plus is top; minus is bottom. So left endpoints: plus at top, minus at bottom.
At the right side (device), there are also two contacts, top and bottom, but we don't know which wire goes to which? The device is fixed, wires are plugged into those contacts in some order initially. Since we are not allowed to unplug, the wires' endpoints at the device are fixed. So the device has a top contact and a bottom contact, and the two wires are each connected to one of these contacts; we don't know which. But we can maybe deduce from the crossing sequence what the assignment is? The question is: can we untangle them, i.e., can we move the wires (they are flexible, can be deformed continuously on the plane, but cannot pass through each other? Actually they are physical wires that can be moved and stretched, but they cannot intersect? Usually, untangling means we can deform them (like strings) as long as we don't cut them or unplug endpoints. But wires can cross each other? In untangling, we want to remove all crossings, i.e., make them not cross (so they are separate). Since wires are on the floor, we can move them, but they are physical wires; we can lift them? The problem statement says "move and stretch on the floor", so they remain on the plane, but we can slide them. We cannot pass one through the other? Typically, wires cannot go through each other, but we can move them in such a way that they can cross over/under each other. Actually, the wires are like ropes lying on the floor; they can be moved, and they can cross over each other? The problem is about entanglements: we have a sequence of crossings observed as we walk from the wall to the device. The question: can we rearrange the wires (continuous deformation) to make them not cross (i.e., be "untangled")? But we must respect that endpoints are fixed. Moreover, the wires are two; this reduces to a problem of two strings with fixed endpoints on a line, and we have a given crossing pattern (a word in + and - indicating the order of over/under as we move along the line from left to right). The question is whether there exists an isotopy of the strings that eliminates all crossings, i.e., makes the two arcs non-intersecting (except at endpoints). However, since strings are one-dimensional curves embedded in the plane, and we can move them continuously, the question reduces to: given two points on the left: top is plus, bottom is minus; two points on the right: we don't know which is plus, which is minus? But we need to consider the topology.
Let’s read problem statement carefully: "Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order." This indicates that at both ends, there are two contacts (top and bottom). At the left, plus is plugged into the top contact. At the right, the device also has two contacts, but we don't know which wire goes to which; they are plugged in some order initially. However, we are allowed to move the wires but not unplug. So the right endpoints are fixed: plus is attached to either the top or bottom contact, and minus to the other. The problem is to see if we can untangle them by moving the wires on the floor.
We also have observed crossing sequence. This sequence describes the order of which wire is above the other at the points where they intersect when projected onto the horizontal axis? Actually: "Mike knows the sequence in which the wires run above each other. The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise." So as we go from the wall to the device along the direction (say left to right), each time the wires cross (i.e., there is an intersection of the two wires in the projection?), we note which wire is on top. The sequence length n is the number of crossings. So we have a word of over/under information at each crossing, in order from left to right.
Given that, we want to determine if it is possible to continuously deform the wires (without cutting, and without moving the device, so endpoints fixed) to a configuration where they do not cross (i.e., become "untangled"). That is essentially checking if the given crossing word corresponds to a "trivial" knot/link (i.e., unlink of two arcs) with the given fixed endpoints.
We have two arcs: plus from left top to some right contact (top or bottom), minus from left bottom to the other right contact. The arcs are in the plane, and we consider them as strings that can be moved; but they cannot pass through each other, but they can cross each other during deformation, we can change crossing types? Wait: In an isotopy of curves, the topology of the curves as embeddings is considered up to ambient isotopy. If we allow the wires to pass through each other, then any configuration can be untangled because we could just separate them by moving one through the other. But physical wires cannot pass through each other. However, in knot theory, when we talk about untangling strings, we usually allow them to pass through themselves? Actually, in knot theory, one studies embeddings up to isotopy, where the strings cannot pass through themselves or each other; they can be deformed but cannot self-intersect or intersect each other. That is the standard notion. In this problem, we are allowed to move and stretch wires, but they are physical, so they cannot pass through each other. However, we are allowed to "lift" them? The description: "A wire can be freely moved and stretched on the floor, but cannot be cut." So they remain on the floor; they cannot be lifted off the floor? "on the floor" suggests they stay on the surface; they cannot pass through each other because they are solid. So indeed, we have an ambient isotopy in the plane, with the endpoints fixed. The wires are like flexible strings lying on a table; they can cross over each other? But they are on the same plane; they cannot occupy the same point at the same time. However, crossing is when one passes over the other, but in a planar embedding, if both are on the same plane, they cannot cross without intersecting; they would meet at a point. In typical drawings of knots, we show over/under crossings to represent projections of 3D curves; but here the wires are on the floor, so they are confined to the 2D plane. In a planar embedding, if two curves intersect, it's a crossing point. But they cannot be on top or below because they're both in the same plane; they would simply intersect. The problem's description of one wire running above the other is a bit ambiguous: In a top view of wires on the floor, they lie on the floor, so they'd be flat; but they might be considered as physical wires that can be placed one on top of another, i.e., they can cross at different heights, like one can be laid over the other (they have thickness). So the wires can cross in 3D: at crossing points, one wire may be above the other. In a top view, we see an X but we also know which is on top. That is like a diagram of a link with crossing information. So the wires are not constrained to be planar; they can be in 3D, but they lie on the floor? The phrase "run along the floor" suggests they are on the floor, but then they cannot be above each other; they'd just intersect. The typical interpretation in such problems (like "untangling wires" or "wire crossing" puzzles) is that the wires are on a flat surface, but they can be crossed over/under because they have some thickness or they can be rearranged to avoid intersections; but the observed pattern is a record of crossing types along the length, assuming we travel from left to right, at each crossing we note which wire is above. This is typical in the context of "over-under sequences" in braid theory. In fact, the problem is about a braid of two strands. The wall and device are two sets of two points each. The wires are like two strands connecting left to right. The observed crossing sequence describes a braid word in the braid group on two strands. The question: can the braid be untangled (i.e., is it equivalent to the trivial braid) given that we are not allowed to change the endpoints? However, there is a nuance: at the left, plus is always top; but at the right, we don't know which is top. In a braid, the endpoints are fixed in order: typically, the left endpoints are (top, bottom) and the right endpoints are (top, bottom) in the same order, but here the device may have the wires swapped. The phrase "into which the wires are plugged in some order" suggests that the right endpoints might be permuted. So the connection at the right could be either straight (plus to top, minus to bottom) or crossed (plus to bottom, minus to top). But we don't know which; but we are to determine if there exists some assignment (maybe given the crossing pattern?) that allows untangling? Actually, we must work with the given physical configuration: the wires are plugged in some specific order at the device. We don't know that order, but it's part of the configuration. We are asked if we can untangle them without unplugging. So we have to determine if, given the crossing sequence, there exists an assignment of right endpoints (i.e., a permutation) that is consistent with the sequence, such that the overall braid is isotopic to the trivial braid? Or perhaps the crossing sequence itself fully determines the relative permutation between the two ends? Let's think.
In a braid on two strands, if you have crossings, the effect is to swap the positions of the strands. Each crossing (over/under) can be thought of as an elementary braid: for two strands, there is only one type of crossing? Actually, for two strands, the braid group B2 is generated by a single crossing σ (the positive crossing where the left strand goes over the right? Usually in braid groups, σ1 denotes a crossing where the first strand (leftmost) goes over the second? Or under? There are conventions. But essentially, there is only one crossing type (if we ignore over/under sign, both are inverses). In B2, σ is the crossing where the left strand crosses over the right? Actually, the standard braid group B_n: generators σ_i for i=1,...,n-1; σ_i means that the i-th strand (counting from left) goes over the (i+1)-th strand, crossing positively. The inverse σ_i^{-1} is the crossing where i-th goes under i+1-th. So for n=2, B2 is generated by σ1 and its inverse; they are distinct. So a sequence of characters '+' and '-' could be interpreted as σ1 (positive) or σ1^{-1} (negative) depending on which wire is above. But careful: The wires are labeled: plus and minus. At left, plus is top, minus is bottom. So we have two strands labeled plus (top) and minus (bottom). A crossing where plus runs above minus corresponds to the plus strand going over the minus strand. If the plus is on top (i.e., over minus), that crossing will swap their positions? In braid diagrams, when a crossing occurs, the strands exchange positions (unless they cross back). Specifically, if you have two strands, left positions: top strand A, bottom strand B. As you go from left to right, when A goes over B (i.e., A is above B at the crossing), then after the crossing, A becomes the bottom strand and B becomes the top strand? Actually, visualize: Suppose you have two parallel vertical lines (the strands) from left to right. At a crossing, the over strand continues in the same horizontal direction, but the under strand goes under and emerges on the other side. In typical braid diagrams, when you have a crossing of two strands, the strands swap their relative positions (left-right ordering) after the crossing, unless it's a virtual crossing? In a braid, strands are monotonic in the horizontal direction (no backtracking). For a crossing of two strands, the left strand becomes the right strand after the crossing if it goes over? Let's reason carefully: In a braid, we have n strands running from top to bottom (or left to right) without reversing direction. In the usual representation, the strands go from top (fixed positions) to bottom. The crossing σ_i means that strand i (counting from left) crosses over strand i+1. After the crossing, the strand that was i (the left one) becomes the right one? Actually, after the crossing, the ordering of the strands can change. In the standard braid, the endpoints at the top are fixed in order, and at the bottom they are also fixed in order, but the braid describes a permutation. For σ1, the permutation is a transposition: the two strands swap positions. More specifically, if we number the strands from left to right at the top, after σ1 (overcrossing of strand 1 over strand 2), strand 1 ends up at the position originally of strand 2 at the bottom (i.e., rightmost), and strand 2 ends up at the leftmost. So the permutation is (1 2). For the inverse σ1^{-1} (strand 1 under strand 2), the permutation is also a transposition: they swap positions as well? Actually, in the braid group, both σ1 and σ1^{-1} produce the same permutation (a transposition), but they are not isotopic as braids because the over/under information matters. However, the permutation (endpoint assignment) is the same: after any crossing, the two strands swap order. In a pure braid (where the permutation is identity), the strands return to the same order at the bottom.
Given that we have two strands labeled plus and minus, the permutation at the right side is determined by the parity of the number of crossings: after an odd number of crossings, the plus and minus are swapped; after an even number, they return to original order. However, we also have the over/under information (sign of crossings). In B2, the trivial braid is the identity: no crossings. But we can also have a braid that is isotopic to the identity even if it has crossings, e.g., σ1 σ1^{-1} is isotopic to identity (they cancel). So the problem reduces to: given a word in σ1 and σ1^{-1}, does it represent the trivial element of the braid group B2? Since B2 is isomorphic to the infinite cyclic group: B2 = ⟨ σ | no relations? Actually, B2 is free on one generator? The braid group B2 is actually isomorphic to ℤ, because there are no nontrivial relations for a single generator: σ σ^{-1}=1, so it's infinite cyclic. Indeed, B2 ≅ ℤ, where the integer corresponds to the exponent sum (number of σ minus number of σ^{-1})? Actually, note that σ and σ^{-1} are inverses, so any word reduces to σ^k where k is exponent sum (positive for positive crossings, negative for negative). Since it's a free group on one generator? Actually, it's not a free group; it's a free group on one generator? A group with one generator and no relations is infinite cyclic, which is the same as ℤ. Yes, B2 ≅ ℤ. The trivial element corresponds to exponent sum zero. But also there is the condition that the braid is isotopic to identity if and only if the exponent sum is zero? Not exactly: In B2, the element σ^k is trivial only if k = 0, because ℤ has no torsion. So the condition for a braid on two strands to be isotopic to the identity (i.e., can be untangled without moving endpoints) is that the exponent sum (number of positive crossings minus number of negative crossings) is zero. However, we must consider that at the right side, the endpoints might be swapped? Because we have fixed the left endpoints: plus top, minus bottom. If at the right side, plus is attached to top and minus to bottom, then the total permutation must be identity (i.e., they end in the same order). If the right side has plus attached to bottom and minus to top, then the permutation must be the transposition. But the problem statement says: "Both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order." This indicates that we are not told which wire goes to which contact on the device; it's part of the configuration but unknown to us. However, the crossing sequence is observed from the current tangled state. So the configuration is fully determined (though we don't know the right assignment). The question is: can we untangle this specific configuration? That is, given the crossing sequence (which includes over/under info) and the fact that left endpoints are fixed (plus top, minus bottom), does there exist an isotopy to a configuration with no crossings, while respecting that the right endpoints are fixed (i.e., we cannot change which contact each wire is plugged into). So we need to consider both possibilities: maybe the configuration itself determines the right assignment via the crossing sequence? Actually, the crossing sequence does not directly tell us the permutation at the end; but from the crossing sequence we can compute the permutation if we know the starting order. Since we know the left order: top = plus, bottom = minus. As we progress through crossings, the relative order of the strands (which one is on left vs right) can change. At each crossing, the two strands swap positions. So after all crossings, the order at the right side is determined: if the number of crossings is even, the order is same as start (plus on top, minus on bottom); if odd, swapped (plus on bottom, minus on top). However, the over/under type does not affect the permutation, only the exponent sum affects the isotopy class. But wait: In a braid with labeled strands, the permutation is determined solely by the parity of the number of crossings. Because each crossing swaps the two strands. So indeed, after n crossings, the order is either identity if n even, or swap if n odd.
Thus the right endpoints must be consistent with this order. That is, the device has two contacts: top and bottom. Since the wires are plugged in some order, the actual assignment of which wire goes to which contact must match the order after the crossings. Because the wires run continuously from left to right; at the right side, the wire that ends up at the top contact must be the one that is physically the top strand at the right end of the braid. So given the crossing sequence, the ordering at the right is forced. Therefore, the configuration is fully determined: the crossing sequence tells us the over/under at each crossing, and the order at the right is determined (by parity of total number of crossings). So the only unknown (the "some order") is actually determined by the crossing sequence? But the problem says "both the wall and the device have two contacts in them on the same level, into which the wires are plugged in some order." This could be interpreted that the wiring at the device is not necessarily top-to-top, bottom-to-bottom; it could be swapped. However, the crossing sequence is observed from the current entangled state. So if we observe the sequence, we can deduce the permutation at the device: If the total number of crossings is even, the plus wire must end at the top contact and minus at bottom; if odd, plus ends at bottom and minus at top. So the configuration is known. So the question reduces to: Is the braid (with labeled endpoints as determined by the parity) trivial? That is, can it be untangled to no crossings? As argued, for two strands, the braid group is ℤ, so it is trivial iff the exponent sum (count of '+' as positive crossings? Need to assign sign to +/-) equals zero. But careful: The sign of the crossing as given: '+' means plus runs above minus. In braid terms, if we define positive crossing as the one where the left strand goes over the right strand, we need to relate to plus/minus and order. However, the notion of left/right changes after each crossing. So the interpretation of a '+' crossing may correspond to either σ or σ^{-1} depending on the current positions of the strands. Actually, in a braid diagram, the crossing type depends on the relative order of the strands at that crossing. For two strands, if at the crossing point, the top-left-to-bottom-right strand goes over the other, that's one type; but which is left vs right? In standard braid representation, strands are monotonic in the horizontal direction. At a crossing, the two strands are crossing; there is a well-defined notion of which strand is the "left" one before crossing. Typically, we number strands by their position at the top. But as they cross, the ordering can change. However, the crossing can be described as either positive or negative based on the orientation of the crossing. In the braid group, the generator σ_i corresponds to a crossing where the i-th strand (from the left) crosses over the (i+1)-th strand. So in a word, we need to know the positions of the strands at each crossing relative to the indexing at that point. With two strands, we only have two positions: left and right. Initially, plus is left (top) and minus is right (bottom) if we consider left-to-right horizontal orientation? Actually, imagine the wires run from left (wall) to right (device). The wall has two contacts: top and bottom. Let's define coordinates: x coordinate from left (0) to right (1). At any x, the wires have y coordinates (vertical). The two wires can cross in the x-y plane, and at each crossing, we note which is above (higher y). This is a planar diagram of two curves with over/under information. In knot theory, such a diagram can be interpreted as a projection of a 3D embedding. The isotopy problem in the plane with over/under information is like a link diagram. For two strands, the question is whether the diagram represents the unlink (two arcs that can be separated) with endpoints fixed.
Because endpoints are fixed on the boundary lines (x=0 and x=1), the arcs are like "tangles" with four endpoints. In fact, this is a tangle with two endpoints on the left (top and bottom) and two on the right (top and bottom). The observed crossing sequence describes a "braid" if the arcs are monotonic in x and never have vertical tangents? But not necessarily; the arcs could go up and down arbitrarily, but the sequence just lists the order of crossings as we move from left to right, presumably at points where they intersect. This is akin to a word in the braid group if we assume the diagram is "braid-like": all crossings are transverse and oriented such that the overcrossing strand has a positive slope relative to the other? Actually, for a braid, all crossings are of a particular type: all strands go monotonically from left to right, and at each crossing, one strand passes over the other. The order of crossing occurrences along the length (in terms of x coordinate) is well-defined. In such a braid, the over/under information at each crossing, combined with the positions of the strands, yields the braid word. But does any configuration of two arcs with fixed endpoints on two parallel lines have a representation as a braid? Probably yes, because by isotopy we can straighten the arcs to be monotonic in the x direction without affecting the isotopy class. In the context of planar diagrams with endpoints on boundaries, we can always isotope the arcs to be "braided" (i.e., they are graphs of functions y(x) that are continuous and maybe non-intersecting except at crossings). However, since we are allowed to deform the wires arbitrarily on the floor (planar isotopies), we can arrange that each wire is a smooth curve with no vertical tangents? Actually, planar isotopies allow any continuous deformation without passing through itself or the other wire. So we can always deform the configuration so that the wires are monotonic in x (i.e., the x-coordinate increases along the curve) and cross only at isolated points. This is because we can "comb" the curves: we can parameterize by x, and if there are backward bends, we can straighten them. So we can assume the diagram is a braid.
Thus, the crossing sequence corresponds to a word in B2. So the problem reduces to checking if the word is equivalent to the trivial braid in B2. As said, B2 ≅ ℤ, so trivial iff exponent sum zero. But careful: The exponent sum depends on sign convention. What is the sign of a crossing? In B2, the generator σ is usually taken as the positive crossing where the left strand goes over the right strand. The inverse is the crossing where left goes under right. Now, given the current positions of the two wires, which one is left and right at the crossing? The crossing occurs at some x. As we go from left to right, when we encounter a crossing, we can consider the order of the two strands just before the crossing in terms of their y-coordinates: the one with higher y (top) or lower y (bottom) does not necessarily indicate left/right. The left/right ordering is about horizontal ordering: which strand is on the left (i.e., has smaller y? Actually, in a standard diagram, the strands are sorted by y at each x? For monotonic curves, at each x, the two curves have distinct y values; we can order them from bottom to top. But the notion of "left" and "right" in braid groups is based on ordering: strand 1 is the topmost? Usually, in braid diagrams, the strands are drawn from top to bottom, and their vertical order at a given horizontal level is used to number them (strand 1 is leftmost? Actually, in standard braid pictures, the strands are arranged from left to right at the top; the ordering is horizontal (left to right). But here we have vertical positions. Let's adopt a consistent coordinate: Left side (wall) at x=0, with two contacts: top (y=1) and bottom (y=0). Right side (device) at x=1, with two contacts: top (y=1) and bottom (y=0). The wires are curves from (0,y_start) to (1,y_end). They may cross. At any given x, each wire has a y coordinate. The two wires can cross when they have the same (x,y) at a point. In a typical braid representation, we would have the strands progressing from left to right, and at each crossing, the strands swap their y-order: one goes over the other. The over/under indicates which wire is physically above. The order of the strands (which one is "left" in terms of y) is not fixed; they can cross.
Now, we need to map the crossing sequence to a braid word. At each crossing, we have information: plus is above minus, or minus above plus. But does this uniquely determine the type of crossing in the braid group sense? It might, given the relative positions of the strands before the crossing. Suppose just before the crossing (i.e., at a slightly smaller x), the two strands have a certain vertical ordering: one is above the other. Which is above? Possibly the one with higher y is "above". At a crossing, the wires intersect; the over/under information tells which one is physically on top. In a planar diagram, we typically draw a crossing with a break to indicate undercrossing. The overcrossing strand continues uninterrupted; the undercrossing strand is broken. The sign (positive/negative) of a crossing in knot theory is defined relative to an orientation of the strands. Here the strands are oriented from left to right (since we travel from wall to device). For an oriented crossing, we can assign a +1 or -1 based on the relative orientation. But here, we are not given orientations? The wires themselves are oriented implicitly from left to right (the direction of the path). So we can consider the two oriented curves from left to right. For an oriented crossing (two oriented strands crossing), the sign is +1 if the overcrossing strand goes from left to right over the undercrossing strand that also goes left to right, but to determine sign, there is a convention: If we rotate the overcrossing strand to align with the undercrossing strand in the direction of the orientation, the crossing is positive if the rotation is counterclockwise. More standard: For an oriented crossing, look at the overcrossing strand; if the undercrossing strand passes from left to right (i.e., the orientation directions), we can compute sign via the right-hand rule. But maybe we don't need orientation; the braid group on two strands uses just one generator, but both positive and negative are possible. The exponent sum in the braid group corresponds to the algebraic crossing number: each crossing contributes +1 if it is a positive crossing (like σ) and -1 if it is a negative crossing (σ^{-1}). In a 2-braid, the algebraic crossing number is exactly the difference between the number of crossings where the strand that started on top (plus) crosses over the other in a certain way? Hmm.
Let's derive properly. We have two strands labeled A (plus) and B (minus). At the left, A is top (y=1), B is bottom (y=0). We'll parameterize by x from 0 to 1. Suppose at some x, the two strands cross. Before the crossing, there is an ordering of the strands in terms of y. Since they are curves that can cross, just before the crossing, one strand is above the other. When they cross, they exchange vertical order. After the crossing, the one that was above becomes below, and vice versa (if we ignore over/under and consider projection). Actually, in a planar projection without over/under, two curves cross at a point and they swap sides (the order of y after crossing is swapped). But with over/under, physically one passes over the other, but in terms of projection, they still cross and swap the vertical ordering if we consider the actual spatial configuration? In a 3D configuration where one wire is above the other, they don't actually intersect in space; the projection onto the floor shows an intersection but they are at different heights. However, the order of the wires in the vertical direction (height off the floor) is not the same as y coordinate. The problem says "the wires run along the floor". But if they are on the floor, they cannot be at different heights. So they must be physically on the floor; so the over/under description indicates that one wire is lying on top of the other at the crossing point, i.e., they are physically crossing, one pressed over the other; but both are on the floor? That seems contradictory: if they are on the floor, they cannot occupy the same point unless one is above. Typically, wires crossing on a floor: one can be laid over the other, so they are not coplanar; there is a small elevation. So it's a 3D crossing. So the projection onto the floor yields an X. At the crossing point, the wires have different z coordinates. The over/under is which is higher. So in the projection, we treat it as a crossing with over/under info. This is exactly a knot diagram. So the configuration is a 2-strand tangle diagram in the plane (the floor's plane), with over/under information at crossings. The endpoints are fixed on the left and right boundaries.
Now, we can consider this as a planar tangle. The question is: can we untangle it, i.e., is the tangle equivalent to the trivial tangle (wires not crossing) via Reidemeister moves? But since endpoints are fixed on boundaries, this is essentially a question of whether the braid (if we put the diagram in a "nice" form) is trivial. The tangle with four endpoints can be studied via the braid group.
Given that we only have two strands, the classification is simple: The only invariant is the exponent sum (or linking number) modulo something? Actually, for two strands with fixed endpoints on two parallel lines, the isotopy classes correspond to integers: the number of half-twists (signed). Because a tangle with two endpoints on each side is basically a "rational tangle" of type p/q? For two strands, rational tangles with two endpoints on each side correspond to fractions. But here the endpoints are on two opposite sides, not on the same line? Usually rational tangles have endpoints on four points on a circle. But we can map. I think it's equivalent to the braid group B2, where the integer representing the number of twists (signed) determines the tangle. And the trivial tangle (wires straight across without crossing) corresponds to 0 twists. So the answer is Yes iff the total signed number of crossings is 0.
But we need to map the given sequence to signed crossings. We have characters '+' and '-'. What is the sign of a '+' crossing? '+' means plus is above minus. Suppose we consider the orientation from left to right. For a crossing of two oriented strands, the crossing sign can be defined. However, in the braid group, we need to know whether the crossing corresponds to σ (positive) or σ^{-1} (negative). In B2, the generator σ is often defined as a crossing where the left strand goes over the right strand. But what is "left" and "right"? That ordering is determined by the vertical order at the crossing? In a braid diagram with strands from top to bottom, the left/right ordering is horizontal; but in our diagram with wires from left to right, the ordering is vertical. So we need to map.
Better: Let's consider a standard model: Two strands initially at y=1 (plus) and y=0 (minus) at x=0. They go to some y positions at x=1. As we move from left to right, at each crossing, the strands intersect in the projection. We can assign a sign to each crossing as follows: For a crossing, we look at the two oriented strands (both going left to right). There are two possibilities: either the upper strand (higher y at the crossing) goes over the lower strand, or the lower goes over the upper. But also the orientation matters. However, for two strands oriented in the same direction (left to right), the sign of a crossing can be defined as +1 if the overcrossing strand goes from left to right and the undercrossing strand also left to right, and the overcrossing strand is the one that goes from bottom left to top right? Hmm, maybe simpler: In a braid group with strands monotonic in x, we can label the strands by their order at the left (top/bottom). But because they swap, the notion of "which strand is on top" changes. In braid theory, one usually numbers strands by their position at the top (left), and then as we progress down (right), the positions may change. The crossing generator σ_i corresponds to the i-th strand (counting from the left at that vertical level) crossing over the (i+1)-th strand. So to translate our diagram to a braid word, we need to know, at each crossing, which position (top or bottom) the two strands occupy just before the crossing. Since there are only two strands, the positions are simply: the one that is currently upper (higher y) and the one that is lower. The crossing will swap them. The over/under information: if the upper strand goes over the lower, what is the crossing type? If the upper strand is the one that started as plus, etc. But we need to assign a sign.
But maybe the exponent sum can be computed simply as: net number of times the plus wire goes over the minus wire minus the net number of times the minus goes over the plus? But is that just the difference between counts of '+' and '-'? The sequence gives '+' for plus over minus, '-' for minus over plus. So if we count #plus_over (denoted P) and #minus_over (M), then the difference P - M could be something like the exponent sum. But is the exponent sum exactly P - M? Let's test with examples.
Example 1: "-++-". So characters: -, +, +, -. So P = number of '+' = 2, M = number of '-' = 2. So P-M = 0. Output: Yes.
Example 2: "+-". So P=1, M=1, P-M=0. But output is No. That contradicts the hypothesis that exponent sum zero implies Yes. So it's not simply difference of counts.
Example 3: "++". P=2, M=0, P-M=2. Output: Yes.
Example 4: "-". P=0, M=1, P-M = -1. Output: No.
So the pattern: Only test2 (which has equal counts) gives No, while test1 also equal counts gives Yes. So it's not just count difference.
What else matters? Perhaps the order matters. In test2 "+-", we have plus over minus then minus over plus. That might create a nontrivial braid (like a full twist). Actually, a single positive crossing followed by a single negative crossing: σ σ^{-1} = identity? In the braid group, they cancel, so that would be trivial. But the answer says No. So that suggests that our mapping of '+' to σ (or something) might be wrong, or perhaps the parity of the number of crossings and the endpoint order matters. In test2, n=2 (even), so the order at the right is same as left: plus at top, minus at bottom. So the permutation is identity. The word "+-" might be σ σ^{-1} which is identity, so should be Yes. But answer says No. So something is off.
Perhaps the meaning of "+" and "-" is not the sign of crossing in the braid sense, but maybe they denote the direction of crossing relative to the travel direction? Let's re-read: "The i-th (1 ≤ i ≤ n) position of the sequence contains the character "+", if on the i-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise." So it's just whether plus is above or not at each crossing. That's exactly what we used.
But maybe we need to consider that the wires are not allowed to be moved off the floor, and they are physical wires, so they cannot pass through each other. The untangling operation may allow moving the wires, but they cannot pass through each other. However, if we have a crossing sequence "+-", that means at the first crossing, plus is over minus; at the second, minus is over plus. In a 2-strand braid, that is indeed isotopic to the trivial braid if the endpoints are fixed in order? Let's check geometrically. Draw two strings from left to right. First crossing: plus goes over minus. After that, the strings have swapped positions: now plus is below, minus is above. Then second crossing: minus goes over plus. If minus is above and goes over plus, then minus goes over plus (since minus is above, it could cross over plus). After that crossing, the strings swap again, returning to original order (plus above, minus below). So the diagram has two crossings, forming a kind of loop. Is this configuration equivalent to no crossings? In knot theory, a Reidemeister move of type II allows removing two crossings of opposite sign that are adjacent and form a bigon. However, this requires that the two crossings are of opposite type (one over, one under) and that the strand segments between them can be moved to create a Reidemeister II move. In a braid word σ σ^{-1}, it is indeed isotopic to the identity. So why would the answer be No? Possibly because the endpoints are fixed on the wall and device, and the wires cannot be moved arbitrarily because they are constrained to the floor? But we can slide them, so we should be able to perform a Reidemeister II move. Let's try to draw: At left, plus top, minus bottom. After the first crossing (plus over minus), the plus goes down, minus up. Then they cross again (minus over plus). In a typical picture, these two crossings might be nested such that they cannot be eliminated without moving the ends. But we can isotopically pull the loop to the right or left? For two strands with fixed endpoints on two parallel lines, the configuration with two opposite crossings that are consecutive might be isotopic to the trivial one. In fact, in braid theory, σ1 σ1^{-1} = identity. The braid group relation says that σ1 σ1^{-1} is trivial. So we should be able to untangle it. Yet the sample says No.
Maybe the interpretation of the sequence is not that the crossings are ordered by their x-coordinate from left to right. Instead, "on the i-th step from the wall" might refer to the order in which the wires cross over each other when traveling along the wires, not necessarily in monotonic x order. But they say "the sequence in which the wires run above each other." So it's the order as you move from wall to device along the path (maybe along the floor?). Typically, if you walk from the wall to the device along the floor, you would intersect the wires at crossing points; the order of those intersections is the sequence. So it's basically the order of crossings along the x direction.
Alternatively, maybe the wires are not free to be moved arbitrarily because they are fixed to the floor? They are lying on the floor, but we can move them. However, perhaps they cannot be lifted off the floor, so they are confined to the plane. In that case, over/under is irrelevant because they are in the plane; but the description says one runs above the other, implying 3D. But maybe the "above" refers to the drawing in the top view: the crossing point where one wire is depicted as crossing over the other is just a representation of which wire is physically on top; but to untangle, we can slide them, and they are on the floor, so the over/under can be changed by moving one wire under the other? If they are on the floor, the notion of over/under might be determined by which is on top; but we can flip them? Usually, if two strings lie on