Equal Sums

 

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given kk sequences of integers. The length of the ii -th sequence equals to nini .

You have to choose exactly two sequences ii and jj (i≠ji≠j ) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence ii (its length will be equal to ni−1ni−1 ) equals to the sum of the changed sequence jj (its length will be equal to nj−1nj−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 00 ) sequence is 00 .

Input

The first line contains an integer kk (2≤k≤2⋅1052≤k≤2⋅105 ) — the number of sequences.

Then kk pairs of lines follow, each pair containing a sequence.

The first line in the ii -th pair contains one integer nini (1≤ni<2⋅1051≤ni<2⋅105 ) — the length of the ii -th sequence. The second line of the ii -th pair contains a sequence of nini integers ai,1,ai,2,…,ai,niai,1,ai,2,…,ai,ni .

The elements of sequences are integer numbers from −104−104 to 104104 .

The sum of lengths of all given sequences don't exceed 2⋅1052⋅105 , i.e. n1+n2+⋯+nk≤2⋅105n1+n2+⋯+nk≤2⋅105 .

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 ii , xx (1≤i≤k,1≤x≤ni1≤i≤k,1≤x≤ni ), in the third line — two integers jj , yy (1≤j≤k,1≤y≤nj1≤j≤k,1≤y≤nj ). It means that the sum of the elements of the ii -th sequence without the element with index xx equals to the sum of the elements of the jj -th sequence without the element with index yy .

Two chosen sequences must be distinct, i.e. i≠ji≠j . You can print them in any order.

If there are multiple possible answers, print any of them.

Examples

Input

Copy

2
5
2 3 1 3 2
6
1 1 2 2 2 1

Output

Copy

YES
2 6
1 2

Input

Copy

3
1
5
5
1 1 1 1 1
2
2 3

Output

Copy

NO

Input

Copy

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

Copy

YES
2 2
4 1

Note

In the first example there are two sequences [2,3,1,3,2][2,3,1,3,2] and [1,1,2,2,2,1][1,1,2,2,2,1] . You can remove the second element from the first sequence to get [2,1,3,2][2,1,3,2] and you can remove the sixth element from the second sequence to get [1,1,2,2,2][1,1,2,2,2] . The sums of the both resulting sequences equal to 88 , i.e. the sums are equal.

-----------------------------------------------------------------------------------------------------------------

给你一个k,接下来有k个数组,找出两个数组,各自减去其中一个元素,剩下的元素之和相等,输出数组次序和元素位置。

-----------------------------------------------------------------------------------------------------------------

第一反应,暴力找,应该会超时,改进了查找一下(以为会超时),结果过了。

用map又写了一遍,思路差不多,查找方式不一样。

----------------------------------------------------

#include<deque>
#include<queue>  
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<stack>
const int inf = 0x3f3f3f3f;
const int MAXN=2e5+7;
using namespace std;

struct temp
{
    long long int num;
    int q;
    int l;
}a[MAXN];
int b[MAXN];
bool cmp(temp x,temp y)
{
    return x.num<y.num;
}

int main()
{
    int n,k=0;
    long long int sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int t;
        sum=0;
        scanf("%d",&t);
        for(int j=1;j<=t;j++)
        {

            scanf("%d",&b[j]);
            sum+=b[j];
        }
        for(int j=1;j<=t;j++)
        {
            k++;
            a[k].num=(sum-b[j]);//存入 该数组删除钙元素之后的和
            a[k].q=i;
            a[k].l=j;
        }
    }
    sort(a+1,a+1+k,cmp);//把所有元素排序
    for(int i=1;i<k;i++)
    {
        if(a[i].num==a[i+1].num&&a[i].q!=a[i+1].q)//和相等并且不是同一行就是找到的解
        {
            printf("YES\n%d %d\n%d %d\n",a[i].q,a[i].l,a[i+1].q,a[i+1].l);
            return 0;
        }
    }
    printf("NO\n");

    return 0;
}

-------------------------------------------------------------------------

#include<deque>
#include<queue>  
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
#include<stack>
const int inf = 0x3f3f3f3f;
using namespace std;
map<int,pair<int,int>>m;
int a[200005];
int p1,p2,p3,p4;
int main()
{
    int n,flag=0;;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int t,sum=0;
        scanf("%d",&t);
        for(int j=1;j<=t;j++)
        {
            scanf("%d",&a[j]);
            sum+=a[j];
        }
        if(!flag)
        {
            for(int j=1;j<=t;j++)
            {
                a[j]=(sum-a[j]);
                if(m.count(a[j]))
                {
                    if(m[a[j]].first!=i)
                    {
                        p1=i;p2=j,p3=m[a[j]].first,p4=m[a[j]].second;
                        flag=1;
                        break;
                    }
                }
                m[a[j]].first=i;
                m[a[j]].second=j;
            }
        }
    }
    if(flag)
        printf("YES\n%d %d\n%d %d\n",p1,p2,p3,p4);
    else
        printf("NO\n");

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值