You are given k sequences of integers. The length of the i-th sequence equals to n_i.
You have to choose exactly two sequences i and j (i ≠ j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence i (its length will be equal to n_i - 1) equals to the sum of the changed sequence j (its length will be equal to n_j - 1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 0) sequence is 0.
Input
The first line contains an integer k (2 ≤ k ≤ 2 ⋅ 10^5) — the number of sequences.
Then k pairs of lines follow, each pair containing a sequence.
The first line in the i-th pair contains one integer n_i (1 ≤ n_i < 2 ⋅ 10^5) — the length of the i-th sequence. The second line of the i-th pair contains a sequence of n_i integers a_{i, 1}, a_{i, 2}, ..., a_{i, n_i}.
The elements of sequences are integer numbers from -10^4 to 10^4.
The sum of lengths of all given sequences don't exceed 2 ⋅ 10^5, i.e. n_1 + n_2 + ... + n_k ≤ 2 ⋅ 10^5.
Output
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j). It means that the sum of the elements of the i-th sequence without the element with index x equals to the sum of the elements of the j-th sequence without the element with index y.
Two chosen sequences must be distinct, i.e. i ≠ j. You can print them in any order.
If there are multiple possible answers, print any of them.
Examples
Input
2
5
2 3 1 3 2
6
1 1 2 2 2 1
Output
YES
2 6
1 2
Input
3
1
5
5
1 1 1 1 1
2
2 3
Output
NO
Input
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
Output
YES
2 2
4 1
Note
In the first example there are two sequences [2, 3, 1, 3, 2] and [1, 1, 2, 2, 2, 1]. You can remove the second element from the first sequence to get [2, 1, 3, 2] and you can remove the sixth element from the second sequence to get [1, 1, 2, 2, 2]. The sums of the both resulting sequences equal to 8, i.e. the sums are equal.
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 are given k sequences. For each sequence i, we have n_i integers. We need to select two distinct sequences i and j, and remove exactly one element from each (any positions) such that after removal, the sums of the two sequences (with lengths n_i-1 and n_j-1) are equal. So we need to find (i, x) and (j, y) such that sum_i - a_{i,x} = sum_j - a_{j,y}. Equivalently, sum_i - sum_j = a_{i,x} - a_{j,y}.
We can precompute total sum S_i for each sequence i.
We need to check if there exist two sequences i≠j and indices x,y such that S_i - a_{i,x} = S_j - a_{j,y}. Or equivalently, for a given target value T = S_i - a_{i,x}, we want to find another occurrence T from a different sequence.
We can think of each sequence i, for each element position x, compute value v = S_i - a_{i,x}. Then we need two v's from different sequences that are equal.
However, there might be multiple v's within the same sequence; but we need them from different sequences. So we need to find a pair of v's from distinct sequences that are equal.
Since total number of elements across all sequences ≤ 2e5, we can compute all these values and group them by the value and sequence index? Actually we need to output the two sequences and the indices.
But there is a catch: The sequences can be many (up to 2e5), and total elements 2e5, so many sequences might have length 1, etc.
We can simply iterate over all sequences and for each element compute v = S_i - a_{i,x}. Then store the triple (v, i, x) in a list. Then sort the list by v. Then scan for equal v values, but we need to ensure that the two triples correspond to different i (different sequences). If we find any equal v with i != j, we output.
Complexities: O(N log N) where N = total elements ≤ 2e5, acceptable.
But is there any edge case? The empty sequence sum is 0. But we are not dealing with empty sequences because we remove exactly one element, and n_i >=1, so after removal length n_i-1 >=0. So a sequence of length 1 after removal becomes empty sum = 0. So v = S_i - a_{i,x} = 0 for such case? For n_i=1, S_i is just that element, so v=0. That's fine.
One more nuance: If there are multiple equal v within same sequence, we can ignore unless we find another from different sequence. So scanning sorted list: for each group of equal v, if there are at least two entries from different sequences, we can take any two. But if all entries are from same sequence, we cannot. But also we could have two entries from same sequence that are identical and maybe also another from another sequence, but we just need one pair.
Simpler: As we process all values, we can maintain a dictionary mapping value to (i, x) that we encountered. For each new (v, i, x), if v is already in dictionary and the stored (j, y) has j != i, then we have a solution. But if it's the same sequence, we could overwrite? Or maybe we need to keep one per sequence group? Because maybe later we get a different sequence with same v but dictionary has the same sequence, then we would miss because stored entry is same sequence. But we could store multiple? Actually we can check: If we find a match with same value but from different sequence, we output. So if we store the first occurrence per value, then when we later encounter same value from possibly same sequence, we check if stored i != current i. If not equal, we ignore; if equal, then we could maybe replace the stored entry with this new one? But that could lose the opportunity if later we get a different sequence. Example: sequence A yields v=5, we store (A, idxA). Then later sequence A again yields v=5, we see stored i = A (same), we ignore, and we keep stored (A, idxA). Then later sequence B yields v=5, we compare and stored i = A (different) => success. So that works. If we replaced the stored entry with the later A, still same i, not a problem. However, what if we first store (A, idxA) for v=5, then we get (B, idxB) for v=5? Then we compare and find i different => success. So it's fine. But we must ensure that we don't output something like i=j. That condition is satisfied.
Thus algorithm: For each sequence i from 1 to k:
read n_i and the array.
compute total sum S_i.
For each position x from 1 to n_i:
compute v = S_i - a_{i,x}
If v is in map and map[v].seq_idx != i:
output "YES"
print map[v].seq_idx, map[v].pos
print i, x
exit
else:
If not already in map (or maybe we can store anyway? But we need to store at least one per value; but if the map already contains an entry with same sequence i, it might be okay to overwrite or keep old. But if it's the first occurrence ever, we store. If we later encounter the same value from same sequence, we could update or not; doesn't matter. However, if we keep the first occurrence from same sequence, that's fine. But there is a case: Suppose we have only two sequences A and B, and both have same v, but only A has multiple v values. We want to ensure that if we first see v from A, then later v from A again, map still holds A. Then later v from B triggers match. Works. But what if we first see v from A, then later v from A (same i) we don't store because map already has A? Actually we can still store (update) because we want to keep some entry. But it's fine to keep the old. But we must be careful: If we only store the first occurrence per value, and later we get the same value from same sequence, we don't need to store it; but if later we get from different sequence, we check and succeed. So it's okay to keep only one entry per value (the first we saw). However, there is a scenario: Two sequences A and B both have the same v, but we first encounter v from A, store it. Then we encounter v from B, we check: map[v].seq_idx != B? It is A, so we succeed. So okay. But what if we encounter v from B first, then later from A? Then similarly succeed. So that works.
But is there any scenario where we might need two different v values? No, we just need one pair.
Edge Cases: Could there be collisions where v is same for many? Not a problem.
Time complexity O(total elements). Memory O(total elements) if we store all entries? Actually we only store at most one per value. But values can be many (total elements up to 2e5, each v can be different, worst-case we store 2e5 entries). That's fine.
But is the dictionary key v unique? v could be up to? S_i up to n_i * 1e4, n_i up to 2e5, but sum of lengths is 2e5, so S_i max magnitude is 2e5 * 1e4 = 2e9, fits in 32-bit signed? Actually 2e9 just fits int32 (max 2^31-1=2.147e9). But also values can be negative, so up to -2e9. But Python int handles arbitrary, fine.
Now, does this algorithm always find a solution if it exists? Let's think: We need two pairs (i,x) and (j,y) with i!=j and v_i,x = v_j,y. If such exist, then consider the first occurrence among all (v, i, x) in our iteration order? Not guaranteed that the first occurrence of v is from one of the sequences and later the other. But as we iterate, we will eventually see the second one and then check map. If we have stored the first occurrence (whatever it is), then when we see the second occurrence (i2) we compare and if i2 != i1, we output. So if the solution consists of sequences i and j, and suppose we encounter i's (i,x) first and j's (j,y) later, then we store i's entry when we see it, then when we see j's entry we check and succeed because i != j. If we encounter j's entry first, then later i's entry, we store j's first, then later i's triggers success. So indeed we will find it. But what if the two entries are from the same sequence? That wouldn't be a solution because i=j is not allowed. So we ignore those. Thus algorithm works.
However, wait: Could there be a scenario where the solution uses two different elements from the same sequence? No, because sequences must be distinct. So we only need i!=j.
Thus the algorithm is straightforward.
But there is a nuance: The map stores for each v a pair (i, x). If we store only the first occurrence, we might lose the possibility if the first occurrence is from a sequence that later also provides a matching v with a different sequence, that's fine. But what if the first occurrence is from sequence A, and later we get v from sequence A again, and we want to match that later occurrence with another sequence B later, but the map still holds the first occurrence from A, which is also from A. That's okay, because when we encounter B's v later, map still has A, and A != B. So it's fine. If we later encounter B's v before A's second occurrence, that's fine. So the only potential problem is if we store a value from A, and later we get the same v from A, but we don't update the map, and then later we get v from B; we check map and stored entry is from A (which is good). So no issue.
Thus algorithm: For i from 1..k:
read n_i, then list a.
compute S = sum(a)
for x, val in enumerate(a, start=1):
v = S - val
if v in seen and seen[v][0] != i:
print YES
print seen[v][0], seen[v][1]
print i, x
return
elif v not in seen: # if not present, store; else if present but same i? we could skip storing to keep first, or store new? But we don't want to overwrite with same i because that might lose the chance later if a different i appears? Actually if we have existing entry with same i, and later we get another from a different i, then when we encounter that different i, we will see map[v] has same i as current? Actually if we keep the first entry (same i) and later we encounter a different i, we compare and i different? But map[v][0] = i (same as first), and current i is different, so it's different, thus it will succeed. So it's fine to keep the first. If we overwrite with the later same i entry, it's still same i, still fine. So we can store regardless (if v not in seen, store; else maybe we don't need to store because already present). But it's simpler: If v not in seen, store (i, x). This ensures that we only store the first occurrence for each v. That will work? Let's test scenario: Suppose we have two sequences A and B with same v. But we first encounter v from A: we store (A, x). Then later we encounter v from A again: v already in seen, we check and see that seen[v][0] == A (same as current i). We do nothing (since condition fails) and we do not store (because we only store if not in seen). That's fine. Later we encounter v from B: we check and seen[v][0] is A != B => success. Good.
But what if the order is: first encounter v from A, store. Then later v from B, success. So fine.
Now consider scenario where the solution involves two different v values? No, the condition requires equality of the sums after removal, which yields same v. So exactly the same value.
Thus algorithm appears correct.
But we need to be careful: The total number of elements is up to 2e5, but sequences up to 2e5, so some sequences may have length 0? Actually n_i >=1. So all sequences have at least one element.
Implementation details:
Use sys.stdin.read to read efficiently.
Keep a dictionary: seen = {} mapping value to tuple (i, pos)
Loop over sequences:
read n
read list of n ints
compute S = sum(arr)
for idx, val in enumerate(arr, start=1):
v = S - val
if v in seen and seen[v][0] != i:
print results and exit
if v not in seen:
seen[v] = (i, idx)
After loop, print "NO"
Edge Cases:
Could there be multiple solutions? We output any.
When printing, note that indices are 1-based for sequences and positions.
But wait: is there any potential pitfall regarding sequence length 1? For n_i=1, after removal sum = 0. So v = S - a = a - a = 0. So that's fine.
Now, does this algorithm guarantee that we find a pair if exists? Let's examine a more tricky scenario: Could there be a case where two sequences i and j have v values equal, but we never store the v from one because we store only the first occurrence and later we see the same v from same sequence and then later the other sequence, but we stored the first occurrence from same sequence and that's fine. But what if the first occurrence of that v is from sequence i, then later we see another occurrence from sequence i (same i), we skip storing (since v already in seen). Then later we see v from sequence j, we compare with stored (i) and succeed. So it's fine.
If we only store when v not in seen, then the stored entry is always the first occurrence of that value overall. So any subsequent occurrence from a different sequence will trigger success. So the only potential failure is if there are two occurrences of same v from two different sequences, but the first occurrence is from sequence A, and the second occurrence is also from sequence A? That cannot happen if there is another from B. Actually if both A and B have the value v, the first occurrence in the entire iteration could be from A or B. If it's from A, then later B's occurrence will be second and we succeed. If first is from B, then later A's occurrence will be second and succeed. So no failure.
Thus algorithm correct.
But is it possible that we need to consider that we must remove exactly one element from each sequence. That's what we did.
Now we iterate: Suppose we go seq1 first. For v=9 store (1,1). v=8 store (1,2). v=10 store (1,3). v=8 already (seq1) so skip store but check? When we see v=8 again at seq1 pos4, seen[v][0]=1 and current i=1, condition fails, skip. v=9 already, skip. Then seq2: first element v=8, seen[v] exists and seq_idx=1 !=2 => success. Output (1,2) and (2,1). But expected output is (2,6) and (1,2). Actually the found pair is seq1 pos2 (removing 3) and seq2 pos1 (removing first 1). Let's verify: seq1 sum=11, remove pos2 (3) => sum=8; seq2 sum=9, remove first element (1) => sum=8. That also works. So any pair is fine.
Thus example passes.
Example 2: Should output NO. Algorithm would not find any matching v from different sequences.
Compute v:
Seq1: for each 2 => v=12-2=10
Seq2: each 2 => v=10-2=8
Seq3: each 2 => v=6-2=4
Seq4: each 2 => v=10-2=8
Now store seq1: first v=10 -> store (1,1)
seq2: v=8 not seen -> store (2,1) (maybe pos1)
seq3: v=4 not seen -> store (3,1)
seq4: v=8 seen, seq_idx=2 !=4 -> success: (2,1) and (4,1) perhaps? That yields seq2 sum=10 remove first => 8; seq4 sum=10 remove first => 8. Works. Output could be (2,1) and (4,1) but expected output is (2,2) and (4,1). Our found pair is (2,1) and (4,1) which is also valid. So yes.
Thus algorithm passes examples.
Now, let's double-check constraints: sum of lengths ≤ 2e5, k up to 2e5. So we can't store arrays of all sequences? We read them sequentially, process, discard after? We need only the values for each element within the same sequence to compute v. We process on the fly. So memory for storing arrays not needed except for current sequence. However, we need to store seen dictionary: at most number of distinct v values up to total elements, which is ≤2e5. So memory okay.
Now, think about the possibility of integer overflow? Python fine.
One more nuance: The problem statement says "Assume that the sum of the empty (of the length equals 0) sequence is 0." That's just to define sum after removal if length becomes 0.
Our approach is fine.
Thus answer seems simple.
But is there any scenario where this straightforward solution fails due to time? O(N) with dictionary should be fast.
But we must be careful: The dictionary key is v which can be large, but hashing is okay.
Implementation in Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
it = iter(data)
k = int(next(it))
seen = {} # value -> (seq_index, pos)
for seq_idx in range(1, k+1):
n = int(next(it))
arr = [int(next(it)) for _ in range(n)]
total = sum(arr)
for pos, val in enumerate(arr, start=1):
v = total - val
if v in seen:
prev_seq, prev_pos = seen[v]
if prev_seq != seq_idx:
print("YES")
print(prev_seq, prev_pos)
print(seq_idx, pos)
return
if v not in seen: # only store first occurrence
seen[v] = (seq_idx, pos)
print("NO")
But careful: The dictionary check and store happen inside the loop. But what if we have the case where we get v in seen from same seq, but we haven't stored any from that seq for that v? Actually we stored the first occurrence from same seq, so seen[v][0] == seq_idx. In that case we skip success, and we also skip storing because v already in seen. That's fine.
But is there a scenario where we might miss a solution because we only store the first occurrence per v? Consider that two different pairs of sequences might share the same v, but the first occurrence might be from sequence A, and later we encounter v from sequence B, we succeed as described. However, what if there is a solution that involves a v that appears multiple times, but the first occurrence is from sequence B, and later occurrences are from sequence B only? Then no success. But if there is also a sequence A with same v, then either first occurrence is from B and later A triggers success, or vice versa. So no missing.
Thus algorithm correct.
But wait: The problem might have another nuance: The sequences are not necessarily distinct? They can be any sequences. The requirement is to choose exactly two sequences i and j, i != j. So if there are two identical sequences, they obviously have solutions? Not necessarily; if they have length >=2 and have elements, removing an element from each could produce equal sums? For identical sequences, if we remove the same element? Then sums would be equal. Indeed if they are identical, any removal from both (maybe same index) yields equal sums. So there would be many solutions. Our algorithm would detect because for each sequence, v values are same; first occurrence from sequence1 stored; when processing sequence2, we will encounter a v already seen with seq1, success.
Now, about the order of output: they said "in the second line — two integers i, x (1 ≤ i ≤ k, 1 ≤ x ≤ n_i), in the third line — two integers j, y (1 ≤ j ≤ k, 1 ≤ y ≤ n_j)." It does not matter which is first. So fine.
Edge Cases: If there is a solution with two sequences of length 1? Both have n=1. Then S_i = a, v = S_i - a = 0. So both have v=0. Our algorithm: first sequence stores (1,1) for v=0. second sequence sees v=0 already, seq_idx=2 != 1 => success. Output (1,1) and (2,1). That works: remove the only element from each, both sums become 0. So correct.
Now, what about a solution that involves removing the same value but from same sequence? Not allowed because i != j. So algorithm will ignore same sequence matches.
Thus algorithm seems straightforward and works.
But wait, there is a known problem: "Find two different sequences such that after removing one element from each, sums equal." This is basically a classic problem: "Two Sums with multiple arrays" or something. The above approach is correct.
But I'm suspicious: Could there be a scenario where the solution requires to match v values that are not directly computed as total sum minus element? Actually, the condition is: sum_i - a_{i,x} = sum_j - a_{j,y}. So rearranged: sum_i - sum_j = a_{i,x} - a_{j,y}. That could be approached differently, but our v is exactly sum_i - a_{i,x}. So it's fine.
Now, think about the possibility of overflow? No.
Now, is there any pitfall with Python's dictionary regarding that we need to store v values that are large? Hashing of integers works.
Now, consider the time: sum of lengths 2e5, so the loops are fine.
Thus solution is done.
But we need to produce output according to format. The examples show "YES" and then lines with pairs.
Now, the problem might also have something about multiple possible answers, any is fine.
Thus solution is as described.
But I recall a known Codeforces problem: "1102C? Actually problem 988F? No. This is from Codeforces Round #... It might be Problem "K Sequences" or something. The solution is exactly as described.
But I'm thinking about the possibility of an issue: If we store only the first occurrence, and we have a scenario where the first occurrence of a particular v is from sequence A, and later we get v from sequence B, but we also have later v from sequence C, we would output (A,?) and (B,?) which is valid. That's fine.
All good.
But wait, there is one more nuance: The dictionary will store at most one entry per v. However, what if there is a solution where the only two sequences that share a v are such that the first occurrence of that v is from sequence A, but we later process sequence A again (i.e., same sequence) with same v, but we skip storing. Then later we process sequence B and see v, we succeed. That's fine. But what if the first occurrence of that v is from sequence A, and then later we process sequence B and see v, but also we need to ensure that the stored index x is within the sequence A. It is.
Now, what if there is a solution using a v that appears in both sequences, but the first occurrence is from sequence A, but we later process sequence A again with same v and we would have overwritten? In our algorithm we don't overwrite because we only store if not in seen. So we keep the first from A. That's fine.
Thus all good.
Now, we must be careful about reading input: The sum of lengths is ≤2e5, but there might be many sequences, so using sys.stdin.buffer read is advisable.
Now, final code.
But wait, could there be a scenario where the solution exists but our algorithm fails because we do not consider the case where the same v appears in two different sequences but we store v from the first sequence, and when we encounter the second sequence's v we output success. That's fine.
Now, is there any hidden trap: The total sum S_i might be large, and v = S_i - a. That can be repeated even if sums differ. But that's what we want.
Now, check potential bug: For each sequence, we compute total sum and then for each element compute v. However, note that when we compute v, we use total sum of the entire sequence. But after removal, the sum becomes v. So correct.
Now, think about the possibility that two sequences may have the same sum after removal, but with the same i? Not allowed.
Now, let's test on some random small cases to be sure.
Case: k=2, n1=2, [1,2] sum=3; n2=2, [3,0] sum=3. v1: 3-1=2; 3-2=1. v2: 3-3=0; 3-0=3. No match => NO. But could we remove one from each to get equal sums? After removal from first: remove 1 => sum=2; remove 2 => sum=1. After removal from second: remove 3 => sum=0; remove 0 => sum=3. No equal sums. So NO correct.
Case: k=2, [1,2,3] sum=6; [2,3,1] sum=6. v: first: 5,4,3; second: 4,3,5. Matches: (1,2)=4? Actually first seq: positions: 1->5,2->4,3->3; second seq:1->4,2->3,3->5. We can match v=4: seq1 pos2, seq2 pos1 => remove 2 from first gives sum=4; remove 2 from second? Wait second seq sum=6, remove first element 2 => sum=4? Actually second seq elements: [2,3,1]; remove first element 2 => sum=4. So equal sums. Our algorithm would store first seq v=5,4,3. Then second seq first v=4: seen[4] exists with seq1, success. So good.
Now, case: k=3: seq1 length 1 [5] sum=5 v=0; seq2 length 5 [1,1,1,1,1] sum=5 v=4 each? Actually 5-1=4, so v=4 for each; seq3 length 2 [2,3] sum=5 v=3,2. No 0 in others? seq1 v=0. No match. But is there solution? Could we remove from seq1 (only element) sum=0; from seq2 remove some element? Then sum=4, not 0; from seq3 remove element sum=2 or 3, not 0. So NO. Our algorithm: store v=0 from seq1; seq2 v=4 store; seq3 v=3,2 store; no success => NO.
Now, case: seq1 [1,4] sum=5 v=4,1; seq2 [2,3] sum=5 v=3,2; seq3 [0,5] sum=5 v=5,0. There are matches? v=0 from seq3 and v=0? only one; v=4 from seq1 and v=4? no; v=1 from seq1 and v=1? no; v=2 from seq2 and v=2? no; v=3 from seq2 and v=3? no; v=5 from seq3 and v=5? none else. So NO. Our algorithm would output NO.
Now, case: multiple sequences with same v values: k=100000, each with one element random? May have many collisions? But the dictionary will have many entries. It's fine.
Now, let's also consider memory: dictionary mapping v to (i, pos). Since v is int, fine.
Now, potential tricky part: The problem statement says: "If there are multiple possible answers, print any of them." So it's fine.
Now, I think we can implement this.
However, there is a known Codeforces problem "Mysterious Present" or something? Actually it's problem 988D? Not sure. But I've seen a problem "Two Sequences" where they ask for exactly this. The solution often uses hashing.
But wait, I recall a known nuance: The total number of elements is up to 200k, but if we use Python, using dictionary with up to 200k entries is fine. However, the algorithm described might fail due to the presence of duplicate v values within the same sequence that could cause us to not store the first occurrence? Actually we store the first occurrence. Suppose there is a value v that appears only in two sequences A and B, but the first occurrence is from A. That's fine. Suppose v appears in A and B, but we process A first, store v from A. Then we process B, and when we compute v for each element, we will check if v in seen and if seen[v][0] != B, which is true, so we output. But we output the stored index from A and the current from B. So it works.
Now, what if v appears in A and B, but we process B first? Then we store from B, later A triggers success.
Now, what if v appears in A only? No solution.
Thus fine.
Now, is there any scenario where we need to consider that after removing one element, the sum might be equal, but we might have to ensure that the indices are valid? Yes, our indices are valid.
Now, one might think about using a map from (v, i) or something, but not needed.
Thus final answer is straightforward.
Now, we can produce final code.
But wait: The problem constraints: n_i can be up to 2e5, but sum of all n_i <= 2e5, so okay.
We can also implement using sys.stdin.buffer to read lines. But simpler: sys.stdin.read and split. That will hold all numbers in memory, total numbers = 1 (k) + sum(n_i) + k (for each n_i) = about 2e5 + 2e5? Actually sum(n_i) <= 2e5, plus k numbers for n_i, plus 1 for k. So at most 400k numbers, which is fine.
Thus implementation.
Now, let's double-check that the reading method will correctly handle large input. The input is formatted as:
k
then for each i:
n_i
a_i1 a_i2 ... a_i n_i
So using split() we get all tokens. We'll parse sequentially.
Now, ensure that we convert to int.
Now, potential pitfalls: Using dictionary with keys that could be large negative values; fine.
Now, think about any edge-case where two different v values lead to the same sum after removal? No, because sum after removal is exactly v.
Now, let's test with an extreme case: k=200000, each n_i=1, values random. Then there will be many v=0 (since each sum equals its element, v=0). So we will have many sequences with v=0. Our algorithm: first sequence stores v=0 (1,1). Second sequence sees v=0, seq_idx=2, seen[0][0]=1, success. Output (1,1) and (2,1). That is valid. So it's fine.
Now, another extreme: all sequences have length 2, values arranged such that no two v match. Then we store up to 2*200000? Actually total elements 200k, distinct v maybe up to 200k. So dictionary size up to 200k, fine.
Thus it's okay.
Now, before finalizing, think about whether there is any alternative solution? But this is fine.
Now, I'd like to consider the possibility of a scenario where we might need to output the answer with i and x where x is the index of the removed element. That's exactly what we output.
Now, test with sample 1: input as given, our code prints "YES", then "1 2" and "2 1"? Actually it would print stored (1,2) (since first occurrence of v=8 was at seq1 pos2) and (2,1). But sample output shows "2 6" and "1 2". Both are valid.
Now, consider a scenario: if we only store first occurrence of v, we might output a pair where the first sequence's element is not the only possible, but any is valid. So okay.
Now, time complexity: O(N) dictionary operations.
Now, will the solution be accepted? I think yes.
However, I recall a known Codeforces problem "1015C" or something. Wait, the problem I'm thinking is from Codeforces Round #... Actually it's problem "Two Sequences" from Edu Round? The solution often uses a map from sum difference to something.
But I want to be thorough: There is a known hack for such problem: If we store only first occurrence, it's fine. But one might need to be careful about the case where a value appears only in two sequences but the first occurrence is from the same sequence as the second? Not possible. So okay.
Now, maybe there is a nuance: For a sequence, we compute v = S_i - a_{i,x}. But after removal, the sum becomes v. But we could also consider that for a given sequence i, if we remove element x, the sum becomes v. So we want two distinct sequences that have some v in common. So indeed it's a set intersection problem.
Now, can there be a scenario where the same v appears multiple times in the same sequence, and we store the first, but later we get v from a different sequence, and we output (i, first_x) and (j, y). That's fine.
Now, what about if we store only when v not in seen, then for a sequence i, we might skip storing some v that appears later in same sequence, but that's okay.
Thus final answer.
Now, I'll write the solution in Python.
But wait: Could there be a case where the solution involves two sequences i and j, but the v we find from sequence i is not the only v; maybe there are two possible v values that lead to same sum after removal? No.
Now, I'm going to produce the solution.
But one more thought: The input reading: we should be careful that after reading n_i, the next line contains the n_i integers. But they could be split across lines? The problem says "the second line of the i-th pair contains a sequence of n_i integers". Typically they are on one line. But it's safe to use split because we just read tokens sequentially; we don't need to consider line breaks.
So implement:
def solve():
import sys
data = sys.stdin.buffer.read().split()
if not data:
return
it = iter(data)
k = int(next(it))
seen = {}
for seq in range(1, k+1):
n = int(next(it))
# read n numbers
# we can read them one by one
# but we need sum
total = 0
# We need to compute v for each element, but we need the values. We could accumulate sum while reading? But we need the values individually.
# So we can read the list
arr = [int(next(it)) for _ in range(n)]
total = sum(arr)
for pos, val in enumerate(arr, start=1):
v = total - val
entry = seen.get(v)
if entry is not None and entry[0] != seq:
sys.stdout.write("YES\n")
sys.stdout.write(f"{entry[0]} {entry[1]}\n")
sys.stdout.write(f"{seq} {pos}\n")
return
if v not in seen: # using .get already, but we can set if not present
seen[v] = (seq, pos)
sys.stdout.write("NO")
But note: Using if v not in seen after .get may double hash lookup. But it's okay. Alternatively we can do:
if v in seen:
if seen[v][0] != seq: output; # but also we might not want to store if already in seen, and we don't need to check again
else:
seen[v] = (seq, pos)
That's more efficient. Let's code that.
Now, I'll test on given examples.
Example1:
k=2
seq1: n=5 arr = [2,3,1,3,2] total=11
process:
v=9 not seen -> seen[9]=(1,1)
v=8 not seen -> seen[8]=(1,2)
v=10 not seen -> seen[10]=(1,3)
v=8 seen, seq=1 same -> skip (not output)
v=9 seen, seq=1 same -> skip
seq2: n=6 arr=[1,1,2,2,2,1] total=9
pos1 v=8 seen, seq=2 diff -> output (1,2) and (2,1). That matches our earlier.
But example output shows (2,6) and (1,2). That's a different pair but valid. So okay.
Now, Example2: Should print NO.
Example3: Should print YES 2 2? Actually sample output: YES; 2 2; 4 1. Our algorithm could output (2,1) and (4,1). That's also valid.
Now, we need to ensure that the indices are within correct range. For seq2 n=5, pos=1 is valid; seq4 pos=1 valid. So it's okay.
Now, check if any scenario could produce i==j? We guard by checking entry[0] != seq, so no.
Thus solution seems correct.
But hold on: I've seen some solutions for this problem that use a map from (v, i) or something. But our approach is simpler.
But wait: There is a nuance: The total number of sequences can be up to 2e5, and total elements 2e5. So many sequences have length 1. That's fine.
Now, but is there any risk that the dictionary may become too large? Up to 2e5 entries, fine.
Now, code.
But I realize one potential subtle bug: The condition we check is: if v in seen and seen[v][0] != seq, we output. However, if we have stored a v from sequence i, and later we see the same v from the same sequence i but from a different element, we skip. That's correct. But what about the scenario where we first see v from sequence i, store it. Then we see v from sequence j, but j also has multiple occurrences of v. When we see the first occurrence from j, we will output (i, stored_x) and (j, current_y). That's a valid pair. But could it be that the stored index x from sequence i is not the correct one to pair with j? Actually any pair where the v values match works. So it's fine.
Now, consider scenario: There is a solution using two sequences i and j but the v value they share appears only in those two sequences, but we might have stored the v from sequence i with a particular element x, and later we see v from sequence j with element y, we output. That's a solution. So fine.
Now, there is a nuance: The problem requires that we remove exactly one element from each of the two sequences. The pair we output corresponds to removing those elements. That's exactly the pair we output.
Now, one more nuance: What if there is a solution where the two sequences are the same? That's not allowed. So we ignore.
Now, that's all.
Thus final answer.
I will produce final code.
But as I think, I recall that this problem is Codeforces 988C? Actually it's 988C - "Equal Sums". Yes, exactly! Problem 988C from Codeforces: "Equal Sums". The solution is exactly this: map from sum to (sequence index, position). And we need to ensure that if two sums are equal, they must be from different sequences. That's what we did. However, there is a twist in that problem: They also required that you could not output two pairs from the same sequence. That is the same.
But I remember a nuance: In 988C, they ask to output the indices of the removed element, and the solution uses a map from sum to (seq, index). The typical solution is to iterate over each sequence, compute sum_i, then for each element, compute sum_i - a_i and check if that value is in map, and if map entry's sequence index is different, output. Then break. That is exactly our algorithm.
Now, I recall that in that problem, some solutions used a map from the sum to a pair, but they also stored multiple entries per sum? Actually they store only one per sum, like we did.
But there might be a corner case: If a sum appears multiple times in different sequences, we could output first pair found. That's fine.
Now, double-check memory: In Python, dictionary with up to 2e5 entries, okay.
Thus final answer is correct.
Now, I'll produce final response with explanation and code. ```python
import sys
def solve() -> None:
data = sys.stdin.buffer.read().split()
if not data:
return
it = iter(data)
k = int(next(it))
# map: sum after removal -> (sequence index, position)
seen = {}
code
for seq_idx in range(1, k + 1):
n = int(next(it))
# read the whole sequence
arr = [int(next(it)) for _ in range(n)]
total = sum(arr)
for pos, val in enumerate(arr, start=1):
v = total - val # sum after removing this element
if v in seen:
prev_seq, prev_pos = seen[v]
if prev_seq != seq_idx: # different sequences => solution
sys.stdout.write("YES\n")
sys.stdout.write(f"{prev_seq} {prev_pos}\n")
sys.stdout.write(f"{seq_idx} {pos}\n")
return
else:
seen[v] = (seq_idx, pos)
sys.stdout.write("NO")