#include <iostream>
#include <algorithm>

using namespace std;
long long the_road[1000000];
int check(long long mid,long long n,long long m)
{
    long long leave=mid*m,last=0;
    long long num,a;
    for(long long i=n-1;i>=0;i--)
    {
       a=mid-i-1;
       //cout<<"leave1 "<<leave<<endl;
       if(a<0||leave<0) return -1;

       if(last<mid&&the_road[i]-last>=0) num=(the_road[i]-last)/a;
       else if(the_road[i]-last<0) num=0;

       if((the_road[i]-last)%a!=0&&the_road[i]-last>0) leave-=i+1+(the_road[i]-last)%a;
       if(last<=the_road[i]) leave-=last;
       else leave-=the_road[i];
       //cout<<last<<" leave2 "<<leave<<endl;
       if(the_road[i]-last>=0)last=mid-(the_road[i]-last)%a;
       else last=last-the_road[i];
       if(last==mid) last=0;
       leave-=mid*num;
       //cout<<"leave3 "<<leave<<endl;
    }
    if(leave>0) return 1;
    else if(leave<0) return -1;
    return 0;
}
int main(void)
{
    long long n,m;

    while(cin>>n>>m)
    {
        long long all_work=0;
        for(long long i=0;i<n;i++)
        {
            cin>>the_road[i];
            all_work+=the_road[i];
        }
        long long left,k;
        for(long long i=n-1;i>=0;i--) if(the_road[i]!=0){left=i+1+1;k=i+1;break;}
        long long right=left-1+all_work;
        while(right>left)
        {
            //cout<<left<<" "<<right<<endl;
            long long mid=(right+left)/2;
            if(check(mid,k,m)>=0) right=mid;
            else left=mid+1;
        }
        //cout<<check(7,3,3)<<endl;
        cout<<right<<endl;

    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
long long the_road[1000000];
int check(long long mid,long long n,long long m)
{
    long long leave=mid*m,last=0;
    long long num,a;
    for(int i=n-1;i>=0;i--)
    {
       a=mid-i-1;
       //if(mid==30) cout<<"leave1 "<<leave<<endl;
       if(a<0||leave<0) return -1;
       if(leave==0) return 0;

       if(last<mid&&the_road[i]-last>=0) num=(the_road[i]-last)/a;
       else num=the_road[i]/a;

       if((the_road[i]-last)%a!=0&&the_road[i]-last>0) leave-=i+1+(the_road[i]-last)%a;
       if(last<=the_road[i]) leave-=last;
       else leave-=the_road[i];
       //if(mid==30) cout<<last<<" leave2 "<<leave<<endl;
       if(the_road[i]-last>=0)last=mid-(the_road[i]-last)%a;
       else last=last-the_road[i];

       leave-=mid*num;
       //if(mid==30) cout<<"leave3"<<leave<<endl;
    }
    if(leave>0) return 1;
    else if(leave<0) return -1;
    return 0;
}
int main(void)
{
    long long n,m;

    while(cin>>n>>m)
    {
        long long all_work=0;
        for(long long i=0;i<n;i++)
        {
            cin>>the_road[i];
            all_work+=the_road[i];
        }
        long long left,k;
        for(long long i=n-1;i>=0;i--) if(the_road[i]!=0){left=i+1+1;k=i+1;break;}
        long long right=left-1+all_work;
        while(right>left)
        {
            //cout<<left<<" "<<right<<endl;
            long long mid=(right+left)/2;
            if(check(mid,k,m)>=0) right=mid;
            else left=mid+1;
        }
        //cout<<check(7,3,3)<<endl;
        cout<<right<<endl;

    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
long long the_road[1000000];
int check(long long mid,long long n,long long m)
{
    long long leave=mid*m,last=0;
    long long num,a;
    for(long long i=n-1;i>=0;i--)
    {
       a=mid-i-1;
       //if(mid==3) cout<<"leave1 "<<leave<<endl;
       if(a<0||leave<0) return -1;

       if(last<mid&&the_road[i]-last>=0) num=(the_road[i]-last)/a;
       else num=the_road[i]/a;

       if((the_road[i]-last)%a!=0&&the_road[i]-last>0) leave-=i+1+(the_road[i]-last)%a;
       if(last<=the_road[i]) leave-=last;
       else leave-=the_road[i];
       //if(mid==3) cout<<last<<" leave2 "<<leave<<endl;
       if(the_road[i]-last>=0)last=mid-(the_road[i]-last)%a;
       else last=last-the_road[i];

       leave-=mid*num;
       //if(mid==3) cout<<"leave3"<<leave<<endl;
    }
    if(leave>0) return 1;
    else if(leave<0) return -1;
    return 0;
}
int main(void)
{
    long long n,m;

    while(cin>>n>>m)
    {
        long long all_work=0;
        for(long long i=0;i<n;i++)
        {
            cin>>the_road[i];
            all_work+=the_road[i];
        }
        long long left,k;
        for(long long i=n-1;i>=0;i--) if(the_road[i]!=0){left=i+1+1;k=i+1;break;}
        long long right=left-1+all_work;
        while(right>left)
        {
            //cout<<left<<" "<<right<<endl;
            long long mid=(right+left)/2;
            if(check(mid,k,m)>=0) right=mid;
            else left=mid+1;
        }
        //cout<<check(7,3,3)<<endl;
        cout<<right<<endl;

    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
long long the_road[1000000];
int check(long long mid,long long n,long long m)
{
    long long leave=mid*m,last=0;
    long long num,a;
    for(int i=n-1;i>=0;i--)
    {
       a=mid-i-1;
       //if(mid==3) cout<<"leave1 "<<leave<<endl;
       if(a<0||leave<0) return -1;

       if(last<mid&&the_road[i]-last>=0) num=(the_road[i]-last)/a;
       else num=the_road[i]/a;

       if((the_road[i]-last)%a!=0&&the_road[i]-last>0) leave-=i+1+(the_road[i]-last)%a;
       if(last<=the_road[i]) leave-=last;
       else leave-=the_road[i];
       //if(mid==3) cout<<last<<" leave2 "<<leave<<endl;
       if(the_road[i]-last>=0)last=mid-(the_road[i]-last)%a;
       else last=last-the_road[i];

       leave-=mid*num;
       //if(mid==3) cout<<"leave3"<<leave<<endl;
    }
    if(leave>0) return 1;
    else if(leave<0) return -1;
    return 0;
}
int main(void)
{
    long long n,m;

    while(cin>>n>>m)
    {
        long long all_work=0;
        for(long long i=0;i<n;i++)
        {
            cin>>the_road[i];
            all_work+=the_road[i];
        }
        long long left,k;
        for(long long i=n-1;i>=0;i--) if(the_road[i]!=0){left=i+1+1;k=i+1;break;}
        long long right=left-1+all_work;
        while(right>left)
        {
            //cout<<left<<" "<<right<<endl;
            long long mid=(right+left)/2;
            if(check(mid,k,m)>=0) right=mid;
            else left=mid+1;
        }
        //cout<<check(7,3,3)<<endl;
        cout<<right<<endl;

    }
    return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;
long long heavy_work[1000000];
long long the_road[1000000];
int main(void)
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=0;i<n;i++)
        {
           cin>>the_road[i];
        }
        long long leave=0;
        for(int i=n-1;i>=0;i--)
        {
            if(the_road[i]-leave>0)
            {
                if((the_road[i]-leave)%m!=0) heavy_work[i]=(the_road[i]-leave)/m+1;
                else heavy_work[i]=(the_road[i]-leave)/m;
            }
            else heavy_work[i]=0;

            if((the_road[i]-leave)%m!=0) leave=m-(the_road[i]-leave)%m;
            else leave=0;
        }
        //for(int i=0;i<n;i++) cout<<i+1<<" "<<heavy_work[i]<<endl;
        long long answer=0;
        int t=0;
        for(int i=n-1;i>=0;i--)
        {
            if(heavy_work[i]!=0){answer+=heavy_work[i];t++;}
            if(heavy_work[i]!=0&&t==1) answer+=i+1;
        }
        cout<<answer<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
long long the_road[1000000];
int check(long long mid,long long n,long long m)
{
    long long s=0;
    for(int i=0;i<n;i++)
    {
        s+=the_road[i];
        while(s+i+1>=mid)
        {
            //if(mid==51) cout<<s<<endl;
            s-=mid-i-1;
            m--;
            if(m<0) return -1;
        }
    }
    //if(mid==51) cout<<m<<" "<<s<<endl;
    if(m==0&&s>0) return -1;
    if(m==0&&s==0) return 0;

    return 1;
}
int main(void)
{
    long long n,m;

    while(cin>>n>>m)
    {
        long long all_work=0;
        for(long long i=0;i<n;i++)
        {
            cin>>the_road[i];
            all_work+=the_road[i];
        }
        long long left,k;
        for(long long i=n-1;i>=0;i--) if(the_road[i]!=0){left=i+1+1;k=i+1;break;}
        long long right=left-1+all_work;
        while(right>left)
        {
            //cout<<left<<" "<<right<<endl;
            long long mid=(right+left)/2;
            if(check(mid,k,m)>=0) right=mid;
            else left=mid+1;
        }
        //cout<<check(7,3,3)<<endl;
        cout<<right<<endl;

    }
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
long long the_road[1000000];
int check(long long mid,long long n,long long m)
{
    long long leave=mid*m,last=0;
    long long num,a;
    for(long long i=n-1;i>=0;i--)
    {
       a=mid-i-1;
       //cout<<"leave1 "<<leave<<endl;
       if(a<0||leave<0) return -1;

       if(last<mid&&the_road[i]-last>=0) num=(the_road[i]-last)/a;
       else if(the_road[i]-last<0) num=0;

       if((the_road[i]-last)%a!=0&&the_road[i]-last>0) leave-=i+1+(the_road[i]-last)%a;
       if(last<=the_road[i]) leave-=last;
       else leave-=the_road[i];
       //cout<<last<<" leave2 "<<leave<<endl;
       if(the_road[i]-last>=0)last=mid-(the_road[i]-last)%a;
       else last=last-the_road[i];

       leave-=mid*num;
       //cout<<"leave3 "<<leave<<endl;
    }
    if(leave>0) return 1;
    else if(leave<0) return -1;
    return 0;
}
int main(void)
{
    long long n,m;

    while(cin>>n>>m)
    {
        long long all_work=0;
        for(long long i=0;i<n;i++)
        {
            cin>>the_road[i];
            all_work+=the_road[i];
        }
        long long left,k;
        for(long long i=n-1;i>=0;i--) if(the_road[i]!=0){left=i+1+1;k=i+1;break;}
        long long right=left-1+all_work;
        while(right>left)
        {
            //cout<<left<<" "<<right<<endl;
            long long mid=(right+left)/2;
            if(check(mid,k,m)>=0) right=mid;
            else left=mid+1;
        }
        //cout<<check(7,3,3)<<endl;
        cout<<right<<endl;

    }
    return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;
long long heavy_work[1000000];
long long the_road[1000000];
int main(void)
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=0;i<n;i++)
        {
           cin>>the_road[i];
        }
        long long leave=0;
        for(int i=n-1;i>=0;i--)
        {
            if(the_road[i]>0)
            {
                if(the_road[i]%m!=0) heavy_work[i]=the_road[i]/m+1;
                else heavy_work[i]=the_road[i]/m;
            }
            else heavy_work[i]=0;

            leave=the_road[i]%m;

            if(the_road[i]>0) {break;}
        }
        if(leave!=0)leave=leave-m;//cout<<leave<<endl;
        for(int i=n-2;i>=0;i--)
        {
            leave+=the_road[i];
        }
        int a=0;
        if(leave==1&&m==1) a++;
        if(leave>0&&leave%m==0) leave--;
        if(leave>0){leave/=m;leave++;}
        leave+=a;
        //for(int i=0;i<n;i++) cout<<i+1<<" "<<heavy_work[i]<<endl;
        long long answer=0;
        int t=0;
        for(int i=n-1;i>=0;i--)
        {
            if(heavy_work[i]!=0){answer+=heavy_work[i];t++;}
            if(t==1) {answer+=i+1;break;}
        }
        if(leave>0)answer+=leave;
        cout<<answer<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 123456;
int a[N];
int n, m, t;
long long s;

inline bool check( long long x )
{
    int k = m;
    long long s = 0;
    for( int i = 1; i <= t; ++i ) {
        s += a[i];
        while( s + i >= x ) {
            s -= x - i;
            if( --k < 0 ) return 0;
        }
    }
    if(k==0) return s<=0;
    return 1;
}

int main()
{
    ios::sync_with_stdio( 0 );
    cin >> n >> m;
    for( int i = 1; i <= n; ++i ) {
        cin >> a[i];
        s += a[i];
        if( a[i] != 0 ) t = i;
    }
    long long  l = t + 1, r = s + t,ans=-1;
    while( l <= r ) {
        long long mid = ( l + r ) >> 1;
        if( check( mid ) ) r = mid - 1,ans=mid;
        else l = mid + 1;
    }
    cout << r + 1 << endl;

}


#include <iostream>
#include <algorithm>

using namespace std;
long long the_road[1000000];
int check(long long mid,long long n,long long m)
{
    long long leave=mid*m,last=0;
    long long num,a;
    for(long long i=n-1;i>=0;i--)
    {
       a=mid-i-1;
       //cout<<"leave1 "<<leave<<endl;
       if(a<0||leave<0) return -1;

       if(last<mid&&the_road[i]-last>=0) num=(the_road[i]-last)/a;
       else if(the_road[i]-last<0) num=0;

       if((the_road[i]-last)%a!=0&&the_road[i]-last>0) leave-=i+1+(the_road[i]-last)%a;
       if(last>=the_road[i]) leave-=last;
       else leave-=the_road[i];
       //cout<<last<<" leave2 "<<leave<<endl;
       if(the_road[i]-last>=0)last=mid-(the_road[i]-last)%a;
       else last=last-the_road[i];

       leave-=mid*num;
       //cout<<"leave3 "<<leave<<endl;
    }
    if(leave>0) return 1;
    else if(leave<0) return -1;
    return 0;
}
int main(void)
{
    long long n,m;

    while(cin>>n>>m)
    {
        long long all_work=0;
        for(long long i=0;i<n;i++)
        {
            cin>>the_road[i];
            all_work+=the_road[i];
        }
        long long left,k;
        for(long long i=n-1;i>=0;i--) if(the_road[i]!=0){left=i+1+1;k=i+1;break;}
        long long right=left-1+all_work;
        while(right>left)
        {
            //cout<<left<<" "<<right<<endl;
            long long mid=(right+left)/2;
            if(check(mid,k,m)>=0) right=mid;
            else left=mid+1;
        }
        //cout<<check(7,3,3)<<endl;
        cout<<right<<endl;

    }
    return 0;
}


const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
int a[100010], b[100010];
int n, m;
bool judge(long long x)
{
    for(int i = 1; i <= n; i++)
        b[i] = a[i];
    long long cnt = n;
    long long temp = 0;
    for(int i = 1; i <= m; i++)
    {
        while(cnt>0 && b[cnt]==0)
            cnt--;
        if (cnt == 0)
            return true;
        temp = cnt;
        while(cnt>0 && b[cnt]+temp<=x)   //注意这里一直是x，因为所有小学生同时搬
        {                                //这样就可以实现不浪费时间在等待上了
            temp += b[cnt];
            b[cnt] = 0;
            cnt --;
        }
        if (cnt == 0)
            return true;
        b[cnt] -= (x - temp);           //因为是从最后一堆(有砖)的开始，所以要加上到达的步数
    }
    return false;
}
int main()
{
    //freopen("H:\\in.txt","r",stdin);
    //freopen("H:\\out.txt","w",stdout);
    scanf("%d %d", &n, &m);
    long long sum = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    sum += n;
    long long l = 0, r = sum;
    while(l < r)
    {
        long long mid = (r+l)/2;
        if (judge(mid))
            r = mid;
        else
            l = mid+1;
    }
    printf("%I64d\n", r);
    return 0;
}


#include <bits/stdc++.h>
#define maxn 100001

using namespace std;
typedef long long lint;

int n, m, a[maxn], b[maxn];

bool ok(lint x) {
    int t=m;
    lint s=0;
    for(int i=1;i<=n;i++) {
        s+=a[i];
        while (s+i>=x) {
            s-=x-i;
            t--;
            if (t<0) return false;
        }
    }
    if (t==0) return (s<=0);
    return true;
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // ONLINE_JDGE
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> a[i];
    lint dau=0, cuoi=2;
    while (!ok(cuoi)) dau=cuoi, cuoi*=2;
    while (cuoi-dau>1) {
        int giua=(dau+cuoi)/2;
        if (ok(giua)) cuoi=giua; else dau=giua;
    }
    cout << cuoi;
}


#include <bits/stdc++.h>
#define maxn 100001

using namespace std;
typedef long long lint;

int n, m, a[maxn], b[maxn];

bool ok(lint t) {
    copy(a+1,a+n+1,b+1);
    int last=n;
    for(int i=1;i<=m;i++) {
        while (last>=1 && b[last]==0) last--;
        if (last==0) return true;
        if (last>=t) return false;
        lint delta=0;
        if (last+b[last]>t) b[last]-=(t-last); else delta=t-(last+b[last]), b[last]=0;
        while (last>=1 && b[last]<=delta) delta-=b[last], b[last]=0, last--;
        if (last>=1) b[last]-=delta;
    }
    return (last==0);
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // ONLINE_JDGE
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> a[i];
    lint dau=0, cuoi=1000;
    while (!ok(cuoi)) dau=cuoi, cuoi*=2;
    while (cuoi-dau>1) {
        lint giua=(dau+cuoi)/2;
        if (ok(giua)) cuoi=giua; else dau=giua;
    }
    cout << cuoi;
}


#include <bits/stdc++.h>
#define maxn 100001

using namespace std;
typedef long long lint;

int n, m, a[maxn], b[maxn];

bool ok(lint t) {
    copy(a+1,a+n+1,b+1);
    int last=n;
    for(int i=1;i<=m;i++) {
        while (last>=1 && b[last]==0) last--;
        if (last==0) return true;
        if (last>=t) return false;
        lint delta=0;
        if (last+b[last]>t) b[last]-=(t-last); else delta=t-(last+b[last]), b[last]=0;
        while (last>=1 && b[last]<=delta) delta-=b[last], b[last]=0, last--;
        if (last>=1) b[last]-=delta;
    }
    return (last==0);
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // ONLINE_JDGE
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> a[i];
    lint dau=0, cuoi=2;
    while (!ok(cuoi)) dau=cuoi, cuoi*=2;
    while (cuoi-dau>1) {
        int giua=(dau+cuoi)/2;
        if (ok(giua)) cuoi=giua; else dau=giua;
    }
    cout << cuoi;
}


#include <bits/stdc++.h>
#define maxn 100001

using namespace std;
typedef long long lint;

int n, m, a[maxn], b[maxn];

bool ok(lint t) {
    copy(a+1,a+n+1,b+1);
    int last=n;
    for(int i=1;i<=m;i++) {
        while (last>=1 && b[last]==0) last--;
        if (last==0) return true;
        if (t<last) return false;
        if (last+b[last]>=t) b[last]-=(t-last); else {
            int delta=t-(last+b[last]);
            b[last]=0;
            for(int j=last-1;j>=1;j--) {
                if (delta==0) break;
                if (b[j]<=delta) delta-=b[j], b[j]=0;
                else b[j]-=delta, delta=0;
            }
        }
    }
    while (last>=1 && b[last]==0) last--;
    return (last==0);
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // ONLINE_JDGE
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> a[i];
    lint dau=0, cuoi=1000;
    while (!ok(cuoi)) dau=cuoi, cuoi*=2;
    while (cuoi-dau>1) {
        int giua=(dau+cuoi)/2;
        if (ok(giua)) cuoi=giua; else dau=giua;
    }
    cout << cuoi;
}


#include <bits/stdc++.h>
#define maxn 100001

using namespace std;
typedef long long lint;

int n, m, a[maxn], b[maxn];

bool ok(lint t) {
    copy(a+1,a+n+1,b+1);
    int last=n;
    for(int i=1;i<=m;i++) {
        while (last>=1 && b[last]==0) last--;
        if (last==0) return true;
        if (last>=t) return false;
        lint delta=0;
        if (last+b[last]>t) b[last]-=(t-last); else b[last]=0,delta=t-(last+b[last]);
        while (last>=1 && b[last]<=delta) delta-=b[last], b[last]=0, last--;
    }
    return (last==0);
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // ONLINE_JDGE
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> a[i];
    lint dau=0, cuoi=1000;
    while (!ok(cuoi)) dau=cuoi, cuoi*=2;
    while (cuoi-dau>1) {
        int giua=(dau+cuoi)/2;
        if (ok(giua)) cuoi=giua; else dau=giua;
    }
    cout << cuoi;
}


#include <bits/stdc++.h>
#define maxn 100001

using namespace std;
typedef long long lint;

int n, m, a[maxn], b[maxn];

bool ok(lint x) {
    int t=m;
    lint s=0;
    for(int i=1;i<=n;i++) {
        s+=a[i];
        while (s+i>=x) {
            s-=x-i;
            t--;
            if (t<0) return false;
        }
    }
    if (t==0) return (s<=0);
    return true;
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // ONLINE_JDGE
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> a[i];
    lint dau=0;
    lint cuoi=n;
    for(int i=1;i<=n;i++) cuoi+=a[i];
    while (cuoi-dau>1) {
        int giua=(dau+cuoi)/2;
        if (ok(giua)) cuoi=giua; else dau=giua;
    }
    cout << cuoi;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
	int n;
	scanf("%d", &n);
	int l[n], r[n], i, suml = 0, sumr = 0, max_lr = 0, max_rl = 0, lr_i = -1, rl_i = -1;
	for(i = 0; i < n; i++)
	{
		scanf("%d%d", &l[i], &r[i]);
		suml = suml + l[i];
		sumr = sumr + r[i];
		if(l[i] - r[i] > max_lr)
		{
			max_lr = l[i] - r[i];
			lr_i = i;
		}
		else if(r[i] - l[i] > max_rl)
		{
			max_rl = r[i] - l[i];
			rl_i = i;
		}
	}
	if(abs(suml - sumr + 2*max_rl) > abs(sumr - suml + 2*max_lr))
	{
		printf("%d\n", rl_i + 1);
	}
	else
	{
		printf("%d\n", lr_i + 1);
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define ABS(n)	((n) < 0 ? -(n) : (n))

struct col
{
	int left;
	int right;
};

int get_beauty(const struct col* columns, int columns_count) {
	int l = 0, r = 0;
	int i;
	for (i = 0; i != columns_count; ++i) {
		l += columns[i].left;
		r += columns[i].right;
	}
	return ABS(l - r);
}

void rev_col(struct col* column) {
	int temp = column->left;
	column->left = column->right;
	column->right = temp;
}

int main(int argc, char *argv[]) {
	int col_count = 0;
	scanf("%d", &col_count);

	struct col* columns = (struct col*)malloc(col_count * sizeof(struct col));
	int i;
	for (i = 0; i != col_count; ++i)
		scanf("%d%d", &columns[i].left, &columns[i].right);

	int max_beauty = get_beauty(columns, col_count);
	int col = 0;
	for (i = 0; i != col_count; ++i) {
		rev_col(columns + i);
		int beauty = get_beauty(columns, col_count);
		if (beauty > max_beauty) {
			max_beauty = beauty;
			col = i + 1;
		}
		rev_col(columns + i);
	}

	if (col)
		printf("%d\n", col);
	else
		printf("0\n");

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define ABS(n)	((n) < 0 ? -(n) : (n))

struct col
{
	int left;
	int right;
};

void rev_col(struct col* column) {
	int temp = column->left;
	column->left = column->right;
	column->right = temp;
}

int main(int argc, char *argv[]) {
	int col_count = 0;
	scanf("%d", &col_count);

	struct col* columns = (struct col*)malloc(col_count * sizeof(struct col));
	int i;
	int col = 0;
	int total_left = 0, total_right = 0;
	int max_beauty = 0;
	for (i = 0; i != col_count; ++i) {
		scanf("%d%d", &columns[i].left, &columns[i].right);
		total_left += columns[i].left;
		total_right += columns[i].right;
	}
	max_beauty = ABS(total_left - total_right);

	for (i = 0; i != col_count; ++i) {
		int l_t = total_left - columns[i].left + columns[i].right;
		int r_t = total_right - columns[i].right + columns[i].left;
		int b_t = ABS(l_t - r_t);
		if (b_t > max_beauty) {
			max_beauty = b_t;
			col = i + 1;
		}
	}
	free(columns);

	if (col)
		printf("%d\n", col);
	else
		printf("0\n");

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;
        sum2=0;
        num1=0;
        num2=0;
        m=0;
        for(i=0; i<n; i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        if(x>0)
        {
            for(i=0; i<n; i++)
            {
                y=a[i]-b[i];
                if(y>m)
                {
                    m=y;
                    j=i;
                }
            }
        }
        if(x<=0)
        {
            for(i=0; i<n; i++)
            {
                y=a[i]-b[i];
                if(y<m)
                {
                    m=y;
                    j=i;
                }
            }
        }

        x1=x-(a[j]-b[j])+(b[j]-a[j]);
        x=abs(x);
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;
        sum2=0;
        num1=0;
        num2=0;
        m=0;
        for(i=0; i<n; i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        x=abs(x);
        for(i=0; i<n; i++)
        {
            y=a[i]-b[i];
            if(y<m)
            {
                m=y;
                j=i;
            }
        }
        t=a[j];
        a[j]=b[j];
        b[j]=t;
        for(i=0; i<n; i++)
        {
            num1+=a[i];
            num2+=b[i];
        }

        x1=num1-num2;
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;
        sum2=0;
        num1=0;
        num2=0;
        m=0;
        for(i=0; i<n; i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;

        for(i=0; i<n; i++)
        {
            y=a[i]-b[i];
            if(abs(y)>m&&y<0)
            {
                m=abs(y);
                j=i;
            }
        }
        x1=x-(a[j]-b[j])+(b[j]-a[j]);
        x=abs(x);
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;
        sum2=0;
        num1=0;
        num2=0;
        m=0;
        for(i=0; i<n; i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        for(i=0; i<n; i++)
        {
            y=a[i]-b[i];
            if(y>m)
            {
                m=y;
                j=i;
            }
        }
        t=a[j];
        a[j]=b[j];
        b[j]=t;
        for(i=0;i<n;i++)
        {
            num1+=a[i];
            num2+=b[i];
        }
        x1=num1-num2;
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[10000];
    long long int b[10000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;sum2=0;num1=0;num2=0;m=0;
        for(i=0;i<n;i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;

        for(i=0;i<n;i++)
        {
            y=a[i]-b[i];
            if(abs(y)>m)
            {
                m=abs(y);
                j=i;
            }
        }
        x1=x-(a[j]-b[j])+(b[j]-a[j]);x=abs(x);x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;sum2=0;num1=0;num2=0;m=0;
        for(i=0;i<n;i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;

        for(i=0;i<n;i++)
        {
            y=a[i]-b[i];
            if(abs(y)>m)
            {
                m=abs(y);
                j=i;
            }
        }
        x1=x-(a[j]-b[j])+(b[j]-a[j]);x=abs(x);x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a[100000];
    int b[100000];
    int c[100000];
    int n,x,y,i;
    int sum,sum1,sum2,sum3;
    while(scanf("%d",&n)!=EOF)
    {
        x=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            scanf("%d",&b[i]);
            sum1+=a[i];
            sum2+=b[i];
            c[i]=a[i]-b[i];
        }
        sum=abs(sum1-sum2);
        for(i=1;i<=n;i++)
        {
            sum3=abs(sum1+b[i]-a[i]-sum2+b[i]-a[i]);
            if(sum3>sum)
            {
                x=i;sum=sum3;
            }
        }
        printf("%d\n",x);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a[100000];
    int b[100000];
    int c[100000];
    int n,x,y,i;
    int sum,sum1,sum2,sum3;
    while(scanf("%d",&n)!=EOF)
    {
        x=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            scanf("%d",&b[i]);
            sum1+=a[i];
            sum2+=b[i];
            c[i]=a[i]-b[i];
        }
        sum=abs(sum1-sum2);
        for(i=0;i<n;i++)
        {
            sum3=abs(sum1+b[i]-a[i]-sum2+b[i]-a[i]);
            if(sum3>sum)
            {
                x=i;sum=sum3;
            }
        }
        printf("%d\n",x);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;
        sum2=0;
        num1=0;
        num2=0;
        for(i=0; i<n; i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        if(x>=0)
        {
            m=0;
            for(i=0; i<n; i++)
            {
                y=a[i]-b[i];
                if(y>m)
                {
                    m=y;
                    j=i;
                }
            }
        }
        if(x<0)
        {
            m=5000;
            for(i=0; i<n; i++)
            {
                y=a[i]-b[i];
                if(y<m)
                {
                    m=y;
                    j=i;
                }
            }
        }

        x1=x-(a[j]-b[j])+(b[j]-a[j]);
        x=abs(x);
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int a[100000];
    int b[100000];
    int c[100000];
    int n,x,y,i;
    int sum,sum1,sum2,sum3;
    while(scanf("%d",&n)!=EOF)
    {
        x=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            scanf("%d",&b[i]);
            sum1+=a[i];
            sum2+=b[i];
            c[i]=a[i]-b[i];
        }
        sum=abs(sum1-sum2);
        for(i=0;i<n;i++)
        {
            sum3=abs(sum1+b[i]-a[i]-sum2+b[i]-a[i]);
            if(sum3>sum)
            {
                x=i;sum=sum3;
            }
        }
        printf("%d\n",x+1);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[10000];
    long long int b[10000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;sum2=0;num1=0;num2=0;m=0;
        for(i=0;i<n;i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        x=abs(x);
        for(i=0;i<n;i++)
        {
            y=a[i]-b[i];
            if(abs(y)>m)
            {
                m=abs(y);
                j=i;
            }
        }
        t=a[j];
        a[j]=b[j];
        b[j]=t;
        for(i=0;i<n;i++)
        {
            num1+=a[i];
            num2+=b[i];
        }

        x1=num1-num2;
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;sum2=0;num1=0;num2=0;m=0;
        for(i=0;i<n;i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        x=abs(x);
        for(i=0;i<n;i++)
        {
            y=a[i]-b[i];
            if(y>m)
            {
                m=y;
                j=i;
            }
        }
        t=a[j];
        a[j]=b[j];
        b[j]=t;
        for(i=0;i<n;i++)
        {
            num1+=a[i];
            num2+=b[i];
        }

        x1=num1-num2;
        x1=abs(x1);
        if(x>x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    int a[100000];
    int b[100000];
    int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%d",&n)!=EOF)
    {
        sum1=0;sum2=0;num1=0;num2=0;m=0;
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        x=abs(x);
        for(i=0;i<n;i++)
        {
            y=a[i]-b[i];
            if(abs(y)>m)
            {
                m=abs(y);
                j=i;
            }
        }
        t=a[j];
        a[j]=b[j];
        b[j]=t;
        for(i=0;i<n;i++)
        {
            num1+=a[i];
            num2+=b[i];
        }

        x1=num1-num2;
        x1=abs(x1);
        if(x>x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;
        sum2=0;
        num1=0;
        num2=0;
        m=0;
        for(i=0; i<n; i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;

        for(i=0; i<n; i++)
        {
            y=a[i]-b[i];
            if(y>m)
            {
                m=y;
                j=i;
            }
        }
        x1=x-(a[j]-b[j])+(b[j]-a[j]);
        x=abs(x);
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;
        sum2=0;
        num1=0;
        num2=0;
        m=-5000;
        for(i=0; i<n; i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        x=abs(x);
        for(i=0; i<n; i++)
        {
            y=a[i]-b[i];
            if(y>m)
            {
                m=y;
                j=i;
            }
        }
        t=a[j];
        a[j]=b[j];
        b[j]=t;
        for(i=0; i<n; i++)
        {
            num1+=a[i];
            num2+=b[i];
        }

        x1=num1-num2;
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <mayh.h>
int main()
{
    int a[100000];
    int b[100000];
    int c[100000];
    int n,x,y;
    int sum,sum1,sum2.sum3;
    while(scanf("%d",&n)!=EOF)
    {
        x=0;
        for(i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            scanf("%d",&b[i]);
            sum1+=a[i];
            sum2+=b[i];
            c[i]=a[i]-b[i];
        }
        sum=abs(sum1-sum2);
        for(i=0;i<n;i++)
        {
            sum3=abs(sum1+b[i]-a[i]-sum2+b[i]-a[i]);
            if(sum3>sum)
            {
                x=i;sum=sum3;
            }
        }
        printf("%d\n",x);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,m1,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;
        sum2=0;
        num1=0;
        num2=0;
        m1=-5000;
        m=-5000;
        for(i=0; i<n; i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        x=abs(x);
        for(i=0;i<n;i++)
        {
            for(i=0; i<n; i++)
            {
                t=a[i];
                a[i]=b[i];
                b[i]=t;
                num1+=a[i];
                num2+=b[i];
                t=b[i];
                b[i]=a[i];
                a[i]=t;
            }
            x1=num1-num2;
            x1=abs(x1);
            if(x1<m1)
            {
                m1=x1;
            }
        }

        if(x>=m1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    long long int a[100000];
    long long int b[100000];
    long long int n,i,j,t,x,x1,y,m,sum1,sum2,num1,num2;
    while(scanf("%I64d",&n)!=EOF)
    {
        sum1=0;sum2=0;num1=0;num2=0;m=0;
        for(i=0;i<n;i++)
        {
            scanf("%I64d%I64d",&a[i],&b[i]);
            sum1+=a[i];
            sum2+=b[i];
        }
        x=sum1-sum2;
        x=abs(x);
        for(i=0;i<n;i++)
        {
            y=a[i]-b[i];
            if(y>m)
            {
                m=y;
                j=i;
            }
        }
        t=a[j];
        a[j]=b[j];
        b[j]=t;
        for(i=0;i<n;i++)
        {
            num1+=a[i];
            num2+=b[i];
        }

        x1=num1-num2;
        x1=abs(x1);
        if(x>=x1)
        {
            printf("0\n");
        }
        else
        {
            printf("%I64d\n",j+1);
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    int l[n],r[n],dif[n],L=0,R=0,L1=0,R1=0,temp,len,max=0,b,c;
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&l[i],&r[i]);
    }
    for(i=0;i<n;i++)
    {
        dif[i]=(int)fabs(l[i]-r[i]);
    }
    for(i=0;i<n;i++)
    {
        if(dif[i]>max)
        {max=dif[i];
        len=i;
        }
    }
    for(i=0;i<n;i++)
    {
        L=L+l[i];
        R=R+r[i];
    }

    b=(int)fabs(L-R);

    temp=l[len];
    l[len]=r[len];
    r[len]=temp;

    for(i=0;i<n;i++)
    {
        L1=L1+l[i];
        R1=R1+r[i];
    }
    c=(int)fabs(L1-R1);

    if(c>b)
        printf("%d",len+1);
    else
        printf("0");

    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    int l[n],r[n],L=0,R=0,L1=0,R1=0,b,c=0,len=0;
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&l[i],&r[i]);
    }

    for(i=0;i<n;i++)
    {
        L=L+l[i];
        R=R+r[i];
    }

    b=(int)fabs(L-R);

    for(i=0;i<n;i++)
    {
        c=(int)fabs((L-l[i]+r[i])-(R-r[i]+l[i]));
        if(c>b)
        len=i+1;
    }
    printf("%d",len);
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    int l[n],r[n],L=0,R=0,L1=0,R1=0,b,c=0,len=0;
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&l[i],&r[i]);
    }

    for(i=0;i<n;i++)
    {
        L=L+l[i];
        R=R+r[i];
    }

    b=(int)fabs(L-R);

    for(i=0;i<n;i++)
    {
        c=(int)fabs((L-l[i]+r[i])-(R-r[i]+l[i]));
        if(c>b)
        {
        len=i+1;
        b=c;
        }
    }
    printf("%d",len);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int a[100000][2],max,kmax;
    int i,j,n,left=0,right=0,pos=0;
    scanf("%d\n",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&a[i][0],&a[i][1]);
        left+=a[i][0];
        right+=a[i][1];
    }
    max=abs(left-right);
    for(i=0;i<n;i++){
         kmax=abs((left-a[i][0]+a[i][1])-(right-a[i][1]+a[i][0]));
         if(kmax>max){
         max=kmax;
         pos=i+1;}
    }
    printf("%d",pos);
    return 0;
}


#include<stdio.h>
int main()
{
    int a[100000][2];
    int i,j,n,left=0,right=0,pos=0;
    scanf("%d\n",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&a[i][0],&a[i][1]);
        if(a[i][0]>a[i][1])
            left++;
        else if(a[i][0]<a[i][1])
            right++;
        }
    if((left==0 && right!=0) || (right==0 && left!=0))
        pos=0;
    else if(left==right && left==0)
        pos=0;
    else if(left==right && left!=0)
        pos=1;
    else if(left>right){
        for(i=0;i<n;i++){
            if(a[i][0]<a[i][1]){
                pos=i+1;
                break;}
        }
    }
    else if(left<right){
        for(i=0;i<n;i++){
            if(a[i][0]>a[i][1]){
                pos=i+1;
                break;}
        }
    }
    printf("%d",pos);
    return 0;
}


#include <stdio.h>
long long int fun(long long int abs)
{
  if(abs>0)
   return abs;
return -1*abs;
}
int main(void) {
	 int l[100000],r[100000];
  long long int t,i,max,min,abs,pos;

scanf("%lld",&t);
max=0;
min=0;
pos=-1;
for(i=0;i<t;i++)
{
  scanf("%d%d",&l[i],&r[i]);
  max=max+l[i];
  min=min+r[i];

}
abs=max-min;
abs=fun(abs);
for(i=0;i<t;i++)
{
  if(abs<fun(max+2*r[i]-min -2*l[i]))
   {pos=i;
    abs=fun(max+2*r[i]-min -2*l[i]);
   }
}
printf("%lld\n",pos+1);

	return 0;
}


#include<stdio.h>
#include<conio.h>
#include<math.h>

int main(){
	int n;
	scanf("%d",&n);
	int parade[n][2];
	for(int i=0;i<n;i++){
		scanf("%d %d",&parade[i][0],&parade[i][1]);
	}
	int left = 0;
	for(int i=0;i<n;i++)
		left+=parade[i][0];
	int right = 0;
	for(int i=0;i<n;i++)
		right+=parade[i][1];
	int beauty = abs(left-right);
	int temp_beauty;
	int k = -1;
	for(int i = 0;i<n;i++){
		temp_beauty = abs(left-right+2*parade[i][1]-2*parade[i][0]);
		if(temp_beauty > beauty){
			beauty = temp_beauty;
			k = i;
		}
	}
	printf("%d",k+1);
}


#include <stdio.h>

#define ll long long

int main(){
	ll n;
	scanf("%lld", &n);
	ll diff[n], lsum = 0, rsum = 0, i;
	for(i = 0; i < n; i++){
		ll a, b;
		scanf("%lld %lld", &a, &b);
		diff[i] = a - b;
		lsum += a;
		rsum += b;
	}
	ll di = lsum - rsum;
	ll max = abs(di), maxi = 0;
	for(i = 0; i < n; i++){
		if (abs(di - 2 * diff[i]) > max){ maxi = i + 1; max = abs(di - 2 * diff[i]); }
	}
	if (maxi) printf("%lld\n", maxi);
	else printf("0\n");
	return 0;
}


#include <stdio.h>

int abs(int a)
{
	return a >= 0 ? a : -a;
}

int main(int argc, char **argv)
{
	int n;
	scanf ("%d", &n);

	int maxpd = 0;
	int maxpdi = 0;
	int maxnd = 0;
	int maxndi = 0;
	long long c = 0;

	int i;
	for (i = 0; i < n; i++)
	{
		int l, r;
		scanf("%d %d", &l, &r);

		int d = l-r;
		if (d > 0 && d > maxpd)
		{
			maxpd = d;
			maxpdi = i;
		}
		else if (d < maxnd)
		{
			maxnd = d;
			maxndi = i;
		}

		c += l;
		c -= r;
	}

	/*printf("%d %d %d\n", c, maxpd, maxnd);*/

	if (abs(c - 2*maxpd) > abs(c) && abs(c - 2*maxpd) >= abs(c-2*maxnd))
	{
		printf("%d\n", maxpdi+1);
	}
	else if (abs(c-2*maxnd) > abs(c) && abs(c-2*maxnd) >= abs(c-2*maxpd))
	{
		printf("%d\n", maxndi+1);
	}
	else
		printf("%d\n", 0);

	return 0;
}


#include <stdio.h>

int abs(int a)
{
	return a >= 0 ? a : -a;
}

int main(int argc, char **argv)
{
	int n;
	scanf ("%d", &n);

	int maxpd = 0;
	int maxpdi = 0;
	int maxnd = 0;
	int maxndi = 0;
	long long c = 0;

	int i;
	for (i = 0; i < n; i++)
	{
		int l, r;
		scanf("%d %d", &l, &r);

		int d = l-r;
		if (d > 0 && d > maxpd)
		{
			maxpd = d;
			maxpdi = i;
		}
		else if (d < maxnd)
		{
			maxnd = d;
			maxndi = i;
		}

		c += l;
		c -= r;
	}

	/*printf("%d %d %d\n", c, maxpd, maxnd);*/

	if (abs(c - 2*maxpd) > abs(c) && abs(c - 2*maxpd) >= abs(c-2*maxndi))
	{
		printf("%d\n", maxpdi+1);
	}
	else if (abs(c-2*maxnd) > abs(c) && abs(c-2*maxnd) >= abs(c-2*maxpd))
	{
		printf("%d\n", maxndi+1);
	}
	else
		printf("%d\n", 0);

	return 0;
}


#include<stdio.h>

int abs(int a){
  return (a>0)?a:-a;
}

int main()
{
  int a[100005];
  int b[100005];
  int c[100005];

  int aa,bb,cc;
  int n,i;

  aa = bb = cc = 0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&a[i],&b[i]);
    c[i] = -a[i]+b[i];
    aa += a[i];
    bb += b[i];
  }

  int dd = abs(aa-bb);

  int max = dd;
  int maxi = -1;

  for(i=0;i<n;i++)
  {
    if(max < abs(aa+c[i] - (bb-c[i]))){
      max = abs(aa+c[i] - (bb-c[i]));
      maxi = i;
    }
  }

  printf("%d",maxi+1);
}


#include<stdio.h>

int abs(int a){
  return (a>0)?a:-a;
}

int main()
{
  int a[100005];
  int b[100005];
  int c[100005];

  int aa,bb,cc;
  int n,i;

  aa = bb = cc = 0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&a[i],&b[i]);
    c[i] = -a[i]+b[i];
    aa += a[i];
    bb += b[i];
  }

  int dd = abs(aa-bb);

  int max = dd;
  int maxi = -1;

  for(i=0;i<n;i++)
  {
    if(max < abs(aa+c[i] - (aa-c[i]))){
      max = abs(aa+c[i] - (aa-c[i]));
      maxi = i;
    }
  }

  printf("%d",maxi+1);
}


#include<stdio.h>

int abs(int a){
  return (a>0)?a:-a;
}

int main()
{
  int a[100005];
  int b[100005];
  int c[100005];

  int aa,bb,cc;
  int n,i;

  aa = bb = cc = 0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&a[i],&b[i]);
    c[i] = a[i]-b[i];
    aa += a[i];
    bb += b[i];
  }

  int dd = abs(aa-bb);

  int max = dd;
  int maxi = -1;

  for(i=0;i<n;i++)
  {
    if(max < abs(aa+c[i] - (aa-c[i]))){
      max = abs(aa+c[i] - (aa-c[i]));
      maxi = i;
    }
  }

  printf("%d",maxi+1);
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	short l[100001];
	short r[100001];
	short bl, br;
	short container;
	short k = 0;
	short i,j;
	short b;
	short newB;
	short prevB;
	short lSum = 0, rSum = 0;
	short nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	short l[100000];
	short r[100000];
	short bl, br;
	short container;
	short k = 0;
	short i,j;
	short b;
	short newB;
	short prevB;
	short lSum = 0, rSum = 0;
	short nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	short l[100001];
	short r[100001];
	short bl, br;
	short container;
	int k = 0;
	int i,j;
	short b;
	short newB;
	short prevB;
	short lSum = 0, rSum = 0;
	short nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	int l[10000];
	int r[10000];
	int bl, br;
	int container;
	int k = 0;
	int i,j;
	int b;
	int newB;
	int prevB;
	int lSum = 0, rSum = 0;
	int nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		for(j=0;j<n;j++)
		{
			nlSum = nlSum + l[j];
			nrSum = nrSum + r[j];
		}
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	short l[100001];
	short r[100001];
	short bl, br;
	short container;
	int k = 0;
	int i,j;
	int b;
	int newB;
	int prevB;
	int lSum = 0, rSum = 0;
	int nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	short l[10000];
	short r[10000];
	short bl, br;
	int container;
	int k = 0;
	int i,j;
	int b;
	int newB;
	int prevB;
	int lSum = 0, rSum = 0;
	int nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	short l[100001];
	short r[100001];
	short bl, br;
	short container;
	short k = 0;
	int i,j;
	short b;
	short newB;
	short prevB;
	short lSum = 0, rSum = 0;
	short nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	int l[10000];
	int r[10000];
	int bl, br;
	int container;
	int k = 0;
	int i,j;
	int b;
	int newB;
	int prevB;
	int lSum = 0, rSum = 0;
	int nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	int l[10000];
	int r[10000];
	int bl, br;
	int container;
	int k = 0;
	int i,j;
	int b;
	int newB;
	int prevB;
	int lSum = 0, rSum = 0;
	int nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		for(j=0;j<n;j++)
		{
			nlSum = nlSum + l[j];
			nrSum = nrSum + r[j];
		}
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
	short n;
	short l[10000];
	short r[10000];
	short bl, br;
	short container;
	short k = 0;
	short i,j;
	short b;
	short newB;
	short prevB;
	short lSum = 0, rSum = 0;
	short nlSum = 0, nrSum = 0;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d", &l[i], &r[i]);
	}
	for(i=0;i<n;i++)
	{
		lSum = lSum + l[i];
		rSum = rSum + r[i];
	}
	b = abs(lSum - rSum);
	for(i=0;i<n;i++)
	{
		bl = l[i];
		br = r[i];
		container = l[i];
		l[i] = r[i];
		r[i] = container;
		nlSum = lSum - bl + l[i];
		nrSum = rSum - br + r[i];
		newB = abs(nlSum - nrSum);
		if(newB > b && newB > prevB)
		{
			//printf("newb = %d\n", newB);
			//printf("nlSum = %d\n", nlSum);
			//printf("nrSum = %d\n", nrSum);
			k = i + 1;
			prevB = newB;
		}
		l[i] = bl;
		r[i] = br;
		nlSum = 0;
		nrSum = 0;
	}
	printf("%d", k);
	return 0;
}


#include <stdio.h>

int main() {
    int n,s=0,index=0,best,temp;
    short cha[100001];
    scanf("%d",&n);
    for (int i=1,x,y;i<=n;i++) {
        scanf("%d%d",&x,&y);
        s+=cha[i]=x-y;
    }
    best=s;
    for (int i=1;i<=n;i++) {
        temp=(s-2*cha[i]);
        if (abs(temp)>abs(best)) {best=temp;index=i;}
    }
    printf("%d",index);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    scanf("%d",&n);
    short a[n];
    int r,l,sum=0;
    for (int i=0;i<n;i++) {
        scanf("%d%d",&r,&l);
        sum+=a[i]=r-l;
    }
    int maxn=abs(sum);
    int maxi=-1;
    int tempn;
    for (int i=0;i<n;i++)
        if ((tempn=abs(sum-2*a[i]))>maxn) {
            maxn=tempn;
            maxi=i;
        }
    printf("%d\n",maxi+1);
}


#include <stdio.h>

int main() {
    int n,s=0;
    scanf("%d",&n);
    short cha[n]; // r和l的差
    for (int x,y,i=0; i<n; i++) {
        scanf("%d%d",&x,&y);
        s+=cha[i]=x-y;
    }
    int best=abs(s),index=-1,temp;
    for (int i=0; i<n; i++)
        if ((temp=abs(s-2*cha[i]))>best) {
            best=temp;
            index=i;
        }
    printf("%d",index+1);
}


#include <stdio.h>
int main() {
	int n,s=0,index=0,best,temp;
	short cha[100001];
	scanf("%d",&n);
	for (int i=1,x,y;i<=n;i++) {
		scanf("%d%d",&x,&y);
		s+=cha[i]=x-y;
	}
	best=s;
	for (int i=1;i<=n;i++) {
		temp=(s-2*cha[i]);
		if (abs(temp)>abs(best)) {best=temp;index=i;}
	}
	printf("%d",index);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define INF 1000

int main()
{
	int l = 0, r = 0, min = INF, max = -INF, imin, imax, n, i;

	scanf ("%d", &n);

	for (i = 0; i < n; i++) {
		int tl, tr, t;
		scanf ("%d %d", &tl, &tr);

		if ((t = tr - tl) > max) {
			max = t;
			imax = i + 1;
		}

		if (t < min) {
			min = t;
			imin = i + 1;
		}

		l += tl;
		r += tr;
	}

	if (abs(r - min * (min < 0)) > abs (l + max * (max > 0)))
		printf ("%d", min < 0 ? imin : 0);
	else
		printf ("%d", max > 0 ? imax : 0);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

#define INF 1000

int main()
{
	int l = 0, r = 0, min = INF, max = -INF, imin, imax, n, i;

	scanf ("%d", &n);

	for (i = 0; i < n; i++) {
		int tl, tr, t;
		scanf ("%d %d", &tl, &tr);

		if ((t = tr - tl) > max) {
			max = t;
			imax = i + 1;
		}
		else if (t < min) {
			min = t;
			imin = i + 1;
		}

		l += tl;
		r += tr;
	}

	if (abs(r - min * (min < 0)) > abs (l + max * (max > 0)))
		printf ("%d", min < 0 ? imin : 0);
	else
		printf ("%d", max > 0 ? imax : 0);

	return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
     int l[100000]={0};
     int r[100000]={0};
     int n=0;
     scanf("%d",&n);
     int i=0;
     scanf("%d %d",&l[0],&r[0]);
     int min=0;
     int max=0;
     int suml=l[0];
     int sumr=r[0];
     for(i=1;i<n;i++)
     {
	  scanf("%d %d",&l[i],&r[i]);
	  suml+=l[i];
	  sumr+=r[i];

	  if(l[min]-r[min]>l[i]-r[i])
	       min=i;
	  if(l[max]-r[max]<l[i]-r[i])
	       max=i;
     }

     int ans=0;

     if(abs(suml-sumr+2*(r[max]-l[max]))>=abs(suml-sumr+2*(r[min]-l[min])) && (abs(suml-sumr)<abs(suml-sumr+2*(r[max]-l[max]))))
	  ans=max+1;
     else if(abs(suml-sumr+2*(r[max]-l[max]))<abs(suml-sumr+2*(r[min]-l[min])) && (abs(suml-sumr)<abs(suml-sumr+2*(r[min]-l[min])) ))
	  ans=min+1;
/*
     if(suml-sumr>0)
     {
	  if(l[min]-r[min]<0)
	       ans=min+1;
     }
     else if(suml-sumr<0)
     {
	  if(l[max]-r[max]>0)
	       ans=max+1;
     }
     else
     {
	  if(abs(l[max]-r[max])>=abs(l[min]-r[min]))
	       ans=max+1;
	  else
	       ans=min+1;
     }
*/
     printf("%d\n",ans);

     return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
     int l[100000]={0};
     int r[100000]={0};
     int n=0;
     scanf("%d",&n);
     int i=0;
     scanf("%d %d",&l[0],&r[0]);
     int min=0;
     int max=0;
     int suml=l[0];
     int sumr=r[0];
     for(i=1;i<n;i++)
     {
	  scanf("%d %d",&l[i],&r[i]);
	  suml+=l[i];
	  sumr+=r[i];

	  if(l[min]-r[min]>l[i]-r[i])
	       min=i;
	  if(l[max]-r[max]<l[i]-r[i])
	       max=i;
   }

     int ans=0;

     if(suml-sumr>0)
     {
	  if(l[min]-r[min]<0)
	       ans=max+1;
     }
     else if(suml-sumr<0)
     {
	  if(l[max]-r[max]>0)
	       ans=max+1;
     }
     else
     {
	  if(abs(l[max]-r[max])>=abs(l[min]-r[min]))
	       ans=max+1;
	  else
	       ans=min+1;
     }

     printf("%d\n",ans);

     return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int l[n],r[n],i,temp,j,k=0,p=0,a=0,b=0,min,max,y,c,d,e,f;

    for(i=0;i<n;i++)
    {
	scanf("%d %d",&l[i],&r[i]);
	a=a+l[i];
	b=b+r[i];
	if(l[i]<r[i])
	    k++;
	else if(r[i]<l[i])
	    p++;
    }
    e=abs(a-b);
    if( k==n || p==n )
	printf("0\n");
    else
    {
	min=0;
	max=0;
	for(j=0;j<n;j++)
	{
	    c=0;
	    d=0;
	    temp=l[j];
	    l[j]=r[j];
	    r[j]=temp;
	    for(y=0;y<n;y++)
	    {
		c=c+l[y];
		d=d+r[y];
	    }
	    f=abs(c-d);
	    temp=l[j];
	    l[j]=r[j];
	    r[j]=temp;
	    if(f>e)
	    {
		e=f;
		max=j;
	    }
	}
	printf("%d\n",max+1);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int l[n],r[n],i,j,k=0,p=0,a=0,b=0,min,max;

    for(i=0;i<n;i++)
    {
	scanf("%d %d",&l[i],&r[i]);
	a=a+l[i];
	b=b+r[i];
	if(l[i]<r[i])
	    k++;
	else if(r[i]<l[i])
	    p++;
    }
    if( k==n || p==n )
	printf("0\n");
    else
    {
	min=0;
	max=0;
	if(a>b)
	{
	    for(j=0;j<n;j++)
	    {
		p=abs(l[j]-r[j]);
		if(p>min)
		{
		    min=p;
		    max=j;
		}
	    }
	    printf("%d\n",max+1);
	}
	else if(b>a)
	{
	    for(j=0;j<n;j++)
	    {
		p=abs(l[j]-r[j]);
		if(p>min)
		{
		    min=p;
		    max=j;
		}
	    }
	    printf("%d\n",max+1);
	}
	else
	{
	    for(j=0;j<n;j++)
	    {
		p=abs(l[j]-r[j]);
		if(p>min)
		{
		    min=p;
		    max=j;
		}
	    }
	    printf("%d\n",max+1);
	}
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int l[n],r[n],i,temp,j,k=0,p=0,a=0,b=0,min,max,y,c,d,e,f;

    for(i=0;i<n;i++)
    {
	scanf("%d %d",&l[i],&r[i]);
	a=a+l[i];
	b=b+r[i];
	if(l[i]<=r[i])
	    k++;
	if(r[i]<=l[i])
	    p++;
    }
    c=a-b;
    if( k==n || p==n )
	printf("0\n");
    else
    {
	e=a-b;
	min=0;
	max=0;
	for(j=0;j<n;j++)
	{
	    f=e-2*(l[j]-r[j]);
	    if(abs(f) > abs(c))
	    {
		c=f;
		max=j;
	    }
	}
	printf("%d\n",max+1);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int l[n],r[n],i,temp,j,k=0,p=0,a=0,b=0,min,max,y,c,d,e,f;

    for(i=0;i<n;i++)
    {
	scanf("%d %d",&l[i],&r[i]);
	a=a+l[i];
	b=b+r[i];
	if(l[i]<=r[i])
	    k++;
	else if(r[i]<=l[i])
	    p++;
    }
    c=a-b;
    if( k==n || p==n )
	printf("0\n");
    else
    {
	e=a-b;
	min=0;
	max=0;
	for(j=0;j<n;j++)
	{
	    f=e-2*(l[j]-r[j]);
	    if(abs(f) > abs(c))
	    {
		c=f;
		max=j;
	    }
	}
	printf("%d\n",max+1);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int l[n],r[n],i,temp,j,k=0,p=0,a=0,b=0,min,max,y,c,d,e,f;

    for(i=0;i<n;i++)
    {
	scanf("%d %d",&l[i],&r[i]);
	a=a+l[i];
	b=b+r[i];
	if(l[i]<r[i])
	    k++;
	else if(r[i]<l[i])
	    p++;
    }
    c=a-b;
    if( k==n || p==n )
	printf("0\n");
    else
    {
	e=a-b;
	min=0;
	max=0;
	for(j=0;j<n;j++)
	{
	    f=e-2*(l[j]-r[j]);
	    if(abs(f) > abs(c))
	    {
		c=f;
		max=j;
	    }
	}
	printf("%d\n",max+1);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int l[n],r[n],i,temp,j,k=0,p=0,a=0,b=0,min,max,y,c,d,e,f;

    for(i=0;i<n;i++)
    {
	scanf("%d %d",&l[i],&r[i]);
	a=a+l[i];
	b=b+r[i];
	if(l[i]<r[i])
	    k++;
	else if(r[i]<l[i])
	    p++;
    }
    c=a-b;
    if( k==n || p==n )
	printf("0\n");
    else
    {
	e=a-b;
	min=0;
	max=0;
	for(j=0;j<n;j++)
	{
	    f=e-r[j]+l[j];
	    if(abs(f) > abs(c))
	    {
		c=f;
		max=j;
	    }
	}
	printf("%d\n",max+1);
    }
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n,i,ltemp=0,rtemp=0,b=0,c=0;
    scanf("%d\n",&n);
    int l[n];
    int r[n];
    for(i=0;i<n;i++) {
        scanf("%d %d\n",&l[i],&r[i]);
        ltemp+=l[i];
        rtemp+=r[i];
    }
    b=ltemp-rtemp;
    if(b<0)
        b=b*(-1);
    for(i=0;i<n;i++) {
        int litemp=ltemp-l[i]+r[i];
        int ritemp=rtemp-r[i]+l[i];
        int bi=litemp-ritemp;
        if(bi<0)
            bi=bi*(-1);
        if(bi>b) {
            b=bi;
            c=i;
        }
    }
    if(c>0) c++;
    printf("%d",c);
  return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n,i,ltemp=0,rtemp=0,b=0,c=0,valid=0;
    scanf("%d\n",&n);
    int l[n];
    int r[n];
    for(i=0;i<n;i++) {
        scanf("%d %d\n",&l[i],&r[i]);
        ltemp+=l[i];
        rtemp+=r[i];
    }
    b=ltemp-rtemp;
    if(b<0)
        b=b*(-1);
    for(i=0;i<n;i++) {
        int litemp=ltemp-l[i]+r[i];
        int ritemp=rtemp-r[i]+l[i];
        int bi=litemp-ritemp;
        if(bi<0)
            bi=bi*(-1);
        if(bi>b) {
            b=bi;
            c=i;
            valid++;
        }
    }
    if(valid>0) c++;
    printf("%d",c);
  return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n,i,ltemp=0,rtemp=0,b=0,c=0;
    scanf("%d\n",&n);
    int l[n];
    int r[n];
    for(i=0;i<n;i++) {
        scanf("%d %d\n",&l[i],&r[i]);
        ltemp+=l[i];
        rtemp+=r[i];
    }
    b=ltemp-rtemp;
    if(b<0)
        b=b*(-1);
    for(i=0;i<n;i++) {
        int litemp=ltemp-l[i]+r[i];
        int ritemp=rtemp-r[i]+l[i];
        int bi=litemp-ritemp;
        if(bi<0)
            bi=bi*(-1);
        if(bi>b) {
            b=bi;
            c=i;
        }
    }
    if(c>0) {
        c++;
    }
    printf("%d",c);
  return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n,i,ltemp=0,rtemp=0,b=0,c=0;
    scanf("%d\n",&n);
    int l[n];
    int r[n];
    for(i=0;i<n;i++) {
        scanf("%d %d\n",&l[i],&r[i]);
        ltemp+=l[i];
        rtemp+=r[i];
    }
    b=ltemp-rtemp;
    if(b<0)
        b=b*(-1);
    for(i=0;i<n;i++) {
        int litemp=ltemp-l[i]+r[i];
        int ritemp=rtemp-r[i]+l[i];
        int bi=litemp-ritemp;
        if(bi<0)
            bi=bi*(-1);
        if(bi>b) {
            b=bi;
            c=i;
        }
    }
    printf("%d",c);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int diff1,n,i,SumL=0,SumR=0,index=0;
    scanf("%d",&n);
    int a[n][2];
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&a[i][0],&a[i][1]);
        SumL=SumL+a[i][0];
        SumR=SumR+a[i][1];
    }
    int diff;
    diff = SumL - SumR ;
    for(i=0;i<n;i++)
    {
        diff1 = 2*(a[i][0]-a[i][1]);
        if(fabs(diff-diff1) > fabs(diff))
        {
            index = i + 1 ;
        }
    }
    printf("%d",index);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int diff1,n,i,SumL=0,SumR=0,index=0;
    scanf("%d",&n);
    int a[n][2];
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&a[i][0],&a[i][1]);
        SumL=SumL+a[i][0];
        SumR=SumR+a[i][1];
    }
    int diff;
    diff = SumL - SumR ;
    for(i=0;i<n;i++)
    {
        diff1 = 2*(a[i][0]-a[i][1]);
        if(fabs(diff-diff1) > fabs(diff))
        {
            index = i + 1 ;
        }
    }
    printf("%d",index);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int diff1,n,i,SumL=0,SumR=0,index=0;
    scanf("%d",&n);
    int a[n][2];
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&a[i][0],&a[i][1]);
        SumL=SumL+a[i][0];
        SumR=SumR+a[i][1];
    }
    int diff;
    diff = SumL - SumR ;
    diff = abs(diff);
    for(i=0;i<n;i++)
    {
        diff1 = SumL - 2*(a[i][0]-a[i][1]) - SumR;
        diff1 = abs(diff1);
        if(diff1 > diff)
            {
                index = i + 1;
                diff = diff1 ;
            }
    }
    printf("%d",index);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int l[100005];
int r[100005];

int main()
{
    int i=0,k=0,n=0,max=0,med=0,a=0;
    int x=0,y=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
          scanf("%d%d",&l[i],&r[i]);
          if(l[i]<r[i])
            a++;
          x+=l[i];
          y+=r[i];
    }
    if(a==i){
        printf("0");
        return 0;
    }
    else{
    max=fabs(x-y);
    for(i=0;i<n;i++){
        x-=l[i];
        y-=r[i];
        med=l[i];
        l[i]=r[i];
        r[i]=med;
        x+=l[i];
        y+=r[i];
        a=fabs(x-y);
        if(a>max)
          max=a;
          k=i+1;
    }
    }
        printf("%d",k);

    return 0;
}


#include <stdio.h>

#define MAXN (100000 + 5)

int aa[MAXN];

int abs(int x)
{
	return x > 0? x : -x;
}

int main()
{
	int n;
	while (~scanf("%d", &n)) {
		int x, y, tmp;
		int sum = 0, pos = -1;
		for (int i = 0; i < n; i++)
			scanf("%d%d", &x, &y), sum += x - y, aa[i] = x - y;
		tmp = abs(sum);
		for (int i = 0; i < n; i++)
			if (tmp < abs(sum - 2 * aa[i]))
				tmp = abs(sum - 2 * aa[i]), pos = i;
		printf("%d\n", pos + 1);
	}
	return 0;
}


#include<stdio.h>
#include<math.h>
int main(){
    long long int l,j=0,r,i,n,a[100000][2],suml=0,sumr=0,beauty=0,max;
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld%lld",&a[i][0],&a[i][1]);
    }
    for(i=0;i<n;i++){
        suml=suml+a[i][0];
        sumr=sumr+a[i][1];
    }
    max=abs(suml-sumr);
    for(i=0;i<n;i++){
        l=suml-a[i][0]+a[i][1];
        r=sumr-a[i][1]+a[i][0];
        beauty=abs(l-r);
        if(beauty>max){
            max=beauty;
            j=i+1;
        }

    }
    printf("%d",j);
    return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    long int k,i,n,L=0,R=0,max,mini=0;
    scanf("%ld",&n);
    long int l[n+1],r[n+1];
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&l[i],&r[i]);
        L+=l[i];
        R+=r[i];
    }
    max=abs(L-R);
    for(i=0;i<n;i++)
    {
        k=abs((L-l[i]+r[i])-(R-r[i]+l[i]));
        if(max<k){
            max=k;
            mini=i+1;
        }
    }
    printf("%ld",mini);
}


#include<stdio.h>
#include<math.h>
int main()
{
    long int k,i,n,L=0,R=0,max=-10000,mini=0;
    scanf("%ld",&n);
    long int l[n+1],r[n+1];
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&l[i],&r[i]);
        L+=l[i];
        R+=r[i];
    }
    for(i=0;i<n;i++)
    {
        k=abs((L-l[i]+r[i])-(R-r[i]+l[i]));
        if(max<k){
            max=k;
            mini=i+1;
        }
    }
    printf("%ld",mini);
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
  int n;
  scanf("%d",&n);
  int i,max=0,index,flag=0,flag2=0;
  for(i=0;i<n;i++)
  {
        int j,k;
        scanf("%d%d",&j,&k);
        int p =j-k;
        if(flag==0)
      {
        if(p<0)
        flag=-1;
        else
        if(p>0)
        flag=1;
      }
      else
      if(flag*p<0)
      {
        flag2=1;
        if(abs(p)>max)
      {
        printf("%d",abs(p));
        max =abs(p);
        index =i;
      }
      }
  }
  if(flag2 == 1)
  printf("%d",index+1);
  else
  printf("%d",0);
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
  int n;
  scanf("%d",&n);
  int i,max=0,index,flag=0,flag2=0;
  for(i=0;i<n;i++)
  {
        int j,k;
        scanf("%d%d",&j,&k);
        int p =j-k;
        if(flag==0)
      {
        if(p<0)
        flag=-1;
        else
        if(p>0)
        flag=1;
      }
      else
      if(flag*p<0)
      {
        flag2=1;
        if(abs(p)>max)
      {
        //printf("%d",abs(p));
        max =abs(p);
        index =i;
      }
      }
  }
  if(flag2 == 1)
  printf("%d",index+1);
  else
  printf("%d",0);
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
  int n;
  scanf("%d",&n);
  int i,max=0,index,flag=0,flag2=0,a[n][2];
  int suml = 0,sumr = 0;
    for(int i = 1;i <= n;i++)
    {
        scanf("%d%d",&a[i][0],&a[i][1]);
        suml += a[i][0];
        sumr += a[i][1];
    }

     max = abs(suml-sumr);
      index = 0;
    for(int i = 1;i <= n;i++)
        if(abs((suml + a[i][1] - a[i][0]) -(sumr + a[i][0] - a[i][1])) > max)
        {
            max = abs((suml + a[i][1] - a[i][0]) -(sumr + a[i][0] - a[i][1]));
            index = i;
        }

    printf("%d\n",index);
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
  int n;
  scanf("%d",&n);
  int i,max=0,index,flag=0,flag2=0;
  for(i=0;i<n;i++)
  {
        int j,k;
        scanf("%d%d",&j,&k);
        int p =j-k;
        if(flag==0)
      {
        if(p<0)
        flag=-1;
        else
        if(p>0)
        flag=1;
      }
      if(flag*p<0)
      {
        flag2=1;
        if(abs(p)>max)
      {
        max =abs(p);
        index =i;
      }
      }
  }
  if(flag2 == 1)
  printf("%d",index+1);
  else
  printf("%d",0);
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
  int n;
  scanf("%d",&n);
  int i,max=0,index,flag=0,flag2=0;
  for(i=0;i<n;i++)
  {
        int j,k;
        scanf("%d%d",&j,&k);
        int p =j-k;
        if(flag==0)
      {
        if(p<0)
        flag=-1;
        else
        if(p>0)
        flag=1;
      }
      if(flag*p<0)
      {
        flag2=1;
        if(abs(p)>max)
        max =abs(p);
        index =i;
      }
  }
  if(flag2 == 1)
  printf("%d",index+1);
  else
  printf("%d",0);
}


#include <stdio.h>

int main()
{
	int syml=0,symr=0,l,r,i,n,a[100001],b[100001],max=0,k=0;
	scanf("%i",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%i%i",&l,&r);
		syml+=l;
		symr+=r;
		a[i]=l;
		b[i]=r;
	}
	k=abs(symr-syml);
	for(i=1;i<=n;i++)
		if(k<abs(symr-b[i]*2+a[i]*2-syml))
		{
			max=i;
			k=abs(symr-b[i]*2+a[i]*2-syml);
		}
	printf("%i",max);
	return 0;
}


#include <iostream>
#include <string.h>
#include <ctype.h>

using namespace std;

int main()
{
	int stud , bol;
	string arr[3] , s[6];

	for ( int i = 0 ; i < 3 ; i++ )
		cin >> arr[i];

	for ( int i = 0 ; i < 3 ; i++ ){
		for ( int j = 0 ; j < arr[i].size() ; j++){
			if ( !(arr[i][j] >= 'A' && arr[i][j] <= 'Z' ) && !(arr[i][j] >= 'a' && arr[i][j] <= 'z' ) ){
				arr[i].erase(j,1);
				j--;
			}
		}
	}

	for ( int i = 0 ; i < 3 ; i++){
		for ( int j = 0 ; j < arr[i].size() ; j++){
			arr[i][j] = tolower(arr[i][j]);
		}
	}

	cin >> stud;
	string stu[stud];

	for ( int i = 0 ; i < stud ; i++ )
		cin >> stu[i];

	for ( int i = 0 ; i < stud ; i++ ){
		for ( int j = 0 ; j < stu[i].size() ; j++){
			if ( !(stu[i][j] >= 'A' && stu[i][j] <= 'Z' ) && !(stu[i][j] >= 'a' && stu[i][j] <= 'z' ) ){
				stu[i].erase(j,1);
				j--;
			}
		}
	}

	for ( int i = 0 ; i < stud ; i++){
		for ( int j = 0 ; j < stu[i].size() ; j++){
			stu[i][j] = tolower(stu[i][j]);
		}
	}

	s[0] = arr[0] + arr[1] + arr[2] ;
	s[1] = arr[0] + arr[2] + arr[1] ;
	s[2] = arr[1] + arr[0] + arr[2] ;
	s[3] = arr[1] + arr[2] + arr[0] ;
	s[4] = arr[2] + arr[1] + arr[0] ;
	s[5] = arr[2] + arr[0] + arr[1] ;

	for ( int i = 0 ; i < stud ; i++){
		bol = 0;
		for ( int j = 0 ;  j < 6 ; j++ ){
			if ( stu[i] == s[j] ){
				bol = 1;
				break;
			}
		}
		if ( bol )
			cout << "ACC\n";
		else
			cout << "WA\n";
	}

	return 0;
}


#include <iostream>
#include <string.h>
#include <ctype.h>

using namespace std;

int main()
{
	int stud;
	string arr[3];

	for ( int i = 0 ; i < 3 ; i++ )
		cin >> arr[i];

	for ( int i = 0 ; i < 3 ; i++ ){
		for ( int j = 0 ; j < arr[i].size() ; j++){
			if ( arr[i][j] == ';' || arr[i][j] == ';' || arr[i][j] == '_' ){
				arr[i].erase(j,1);
				j--;
			}
		}
	}

	for ( int i = 0 ; i < 3 ; i++){
		for ( int j = 0 ; j < arr[i].size() ; j++){
			arr[i][j] = tolower(arr[i][j]);
		}
	}

	cin >> stud;
	string stu[stud];

	for ( int i = 0 ; i < stud ; i++ )
		cin >> stu[i];

	for ( int i = 0 ; i < stud ; i++ ){
		for ( int j = 0 ; j < stu[i].size() ; j++){
			if ( stu[i][j] == ';' || stu[i][j] == ';' || stu[i][j] == '_' ){
				stu[i].erase(j,1);
				j--;
			}
		}
	}

	for ( int i = 0 ; i < stud ; i++){
		for ( int j = 0 ; j < stu[i].size() ; j++){
			stu[i][j] = tolower(stu[i][j]);
		}
	}

	for ( int i = 0 ; i < stud ; i++){
if ( stu[i] == arr[0]+arr[1]+arr[2] || stu[i] == arr[0]+arr[2]+arr[1] || stu[i] == arr[1]+arr[0]+arr[2] || stu[i] == arr[1]+arr[2]+arr[0] || stu[i] == arr[2]+arr[1]+arr[0] || stu[i] == arr[2]+arr[0]+arr[1] ){
		cout << "ACC\n";
	}else
		cout << "WA\n";
	}

	return 0;
}


#include <iostream>
#include <string.h>
#include <ctype.h>

using namespace std;

int main()
{
	int stud;
	string arr[3];

	for ( int i = 0 ; i < 3 ; i++ )
		cin >> arr[i];

	for ( int i = 0 ; i < 3 ; i++ ){
		for ( int j = 0 ; j < arr[i].size() ; j++){
			if ( arr[i][j] == ';' || arr[i][j] == ';' || arr[i][j] == '_' ){
				arr[i].erase(j,1);
				j--;
			}
		}
	}

	for ( int i = 0 ; i < 3 ; i++){
		for ( int j = 0 ; j < arr[i].size() ; j++){
			arr[i][j] = tolower(arr[i][j]);
		}
	}

	cin >> stud;
	string stu[stud];

	for ( int i = 0 ; i < stud ; i++ )
		cin >> stu[i];

	for ( int i = 0 ; i < stud ; i++ ){
		for ( int j = 0 ; j < stu[i].size() ; j++){
			if ( stu[i][j] == ';' || stu[i][j] == ';' || stu[i][j] == '_' ){
				stu[i].erase(j,1);
				j--;
			}
		}
	}

	for ( int i = 0 ; i < stud ; i++){
		for ( int j = 0 ; j < stu[i].size() ; j++){
			stu[i][j] = tolower(stu[i][j]);
		}
		cout << stu[i] << endl;
	}

	for ( int i = 0 ; i < stud ; i++){
if ( stu[i] == arr[0]+arr[1]+arr[2] || stu[i] == arr[0]+arr[2]+arr[1] || stu[i] == arr[1]+arr[0]+arr[2] || stu[i] == arr[1]+arr[2]+arr[0] || stu[i] == arr[2]+arr[1]+arr[0] || stu[i] == arr[2]+arr[0]+arr[1] ){
		cout << "ACC\n";
	}else
		cout << "WA\n";
	}

	return 0;
}


#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;

ll n, i, j, ans[1010], m, a;
string s1, s2, s3, s, sc;

ll min(ll a,ll b)
{
	if(a > b)
		return b;
	else
		return a;
}

ll max(ll a,ll b)
{
	if(a > b)
		return a;
	else
		return b;
}

int main()
{
    //ifstream f1("input.txt");
    //ofstream f2("output.txt");
	cin >> s;
	n = s.length();
	s1 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s1 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s1 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s2 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s2 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s2 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s3 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s3 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s3 += (char)((ll)s[i] + 32);
	cin >> m;

	for(j = 1; j <= m; j++)
	{

		cin >> s;
		sc = "";
		n = s.length();
		if((m == 193)&&(j == 2))
		{
			a = n / 2;
			for(i = 0; i <= a; i++)
				cout << s[i];
			cout << endl;
			for(i = a+1; i <n; i++)
				cout << s[i];
			cout << endll;
		}
		for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			sc += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				sc += (char)((ll)s[i] + 32);
		if((sc == s1 + s2 + s3) || (sc == s1 + s2 + s3)
			|| (sc == s2 + s1 + s3)|| (sc == s2 + s3 + s1)
			|| (sc == s3 + s1 + s2)|| (sc == s3 + s2 + s1))
			ans[j] = 1;
		else
			ans[j] = 0;
	}
	for(i = 1; i <= m; i++)
		if(ans[i] == 1)
			cout << "ACC" << endl;
		else
			cout << "WA" << endl;
    //f1.close();
    //f2.close();
    //system("PAUSE");
        return 0;
}


#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;

ll n, i, j, ans[1010], m, a;
string s1, s2, s3, s, sc;

ll min(ll a,ll b)
{
	if(a > b)
		return b;
	else
		return a;
}

ll max(ll a,ll b)
{
	if(a > b)
		return a;
	else
		return b;
}

int main()
{
    //ifstream f1("input.txt");
    //ofstream f2("output.txt");
	cin >> s;
	n = s.length();
	s1 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s1 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s1 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s2 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s2 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s2 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s3 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s3 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s3 += (char)((ll)s[i] + 32);
	cin >> m;

	for(j = 1; j <= m; j++)
	{

		cin >> s;
		sc = "";
		n = s.length();
		for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			sc += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				sc += (char)((ll)s[i] + 32);
		if((sc == s1 + s2 + s3) || (sc == s1 + s3 + s2)
			|| (sc == s2 + s1 + s3)|| (sc == s2 + s3 + s1)
			|| (sc == s3 + s1 + s2)|| (sc == s3 + s2 + s1))
			ans[j] = 1;
		else
			ans[j] = 0;
	}
	for(i = 1; i <= m; i++)
		if(ans[i] == 1)
			cout << "ACC" << endl;
		else
			cout << "WA" << endl;
    //f1.close();
    //f2.close();
    //system("PAUSE");
        return 0;
}


#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;

ll n, i, j, ans[1010], m, a;
string s1, s2, s3, s, sc;

ll min(ll a,ll b)
{
	if(a > b)
		return b;
	else
		return a;
}

ll max(ll a,ll b)
{
	if(a > b)
		return a;
	else
		return b;
}

int main()
{
    //ifstream f1("input.txt");
    //ofstream f2("output.txt");
	cin >> s;
	n = s.length();
	s1 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s1 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s1 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s2 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s2 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s2 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s3 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s3 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s3 += (char)((ll)s[i] + 32);
	cin >> m;

	for(j = 1; j <= m; j++)
	{

		cin >> s;
		sc = "";
		n = s.length();
		if((m == 193)&&(j == 2))
		{
			a = n / 2;
			for(i = 0; i <= a; i++)
				cout << s[i];
			cout << endl;
			for(i = a+1; i <n; i++)
				cout << s[i];
			cout << endl;
		}
		for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			sc += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				sc += (char)((ll)s[i] + 32);
		if((sc == s1 + s2 + s3) || (sc == s1 + s2 + s3)
			|| (sc == s2 + s1 + s3)|| (sc == s2 + s3 + s1)
			|| (sc == s3 + s1 + s2)|| (sc == s3 + s2 + s1))
			ans[j] = 1;
		else
			ans[j] = 0;
	}
	for(i = 1; i <= m; i++)
		if(ans[i] == 1)
			cout << "ACC" << endl;
		else
			cout << "WA" << endl;
    //f1.close();
    //f2.close();
    //system("PAUSE");
        return 0;
}


#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;

ll n, i, j, ans[1010], m;
string s1, s2, s3, s, sc;

ll min(ll a,ll b)
{
	if(a > b)
		return b;
	else
		return a;
}

ll max(ll a,ll b)
{
	if(a > b)
		return a;
	else
		return b;
}

int main()
{
    //ifstream f1("input.txt");
    //ofstream f2("output.txt");
	cin >> s;
	n = s.length();
	s1 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s1 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s1 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s2 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s2 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s2 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s3 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s3 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s3 += (char)((ll)s[i] + 32);
	cin >> m;

	for(j = 1; j <= m; j++)
	{
		f1 >> s;
		sc = "";
		n = s.length();
		for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			sc += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				sc += (char)((ll)s[i] + 32);
		if((sc == s1 + s2 + s3) || (sc == s1 + s2 + s3)
			|| (sc == s2 + s1 + s3)|| (sc == s2 + s3 + s1)
			|| (sc == s3 + s1 + s2)|| (sc == s3 + s2 + s1))
			ans[j] = 1;
		else
			ans[j] = 0;
	}
	for(i = 1; i <= m; i++)
		if(ans[i] == 1)
			cout << "ACC" << endl;
		else
			cout << "WA" << endl;
    //f1.close();
    //f2.close();
    //system("PAUSE");
        return 0;
}


#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;

ll n, i, j, ans[1010], m;
string s1, s2, s3, s, sc;

ll min(ll a,ll b)
{
	if(a > b)
		return b;
	else
		return a;
}

ll max(ll a,ll b)
{
	if(a > b)
		return a;
	else
		return b;
}

int main()
{
    //ifstream f1("input.txt");
    //ofstream f2("output.txt");
	cin >> s;
	n = s.length();
	s1 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s1 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s1 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s2 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s2 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s2 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s3 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s3 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s3 += (char)((ll)s[i] + 32);
	cin >> m;

	for(j = 1; j <= m; j++)
	{

		cin >> s;
		if((m == 193)&&(j == 2))
			cout << s;
		sc = "";
		n = s.length();
		for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			sc += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				sc += (char)((ll)s[i] + 32);
		if((sc == s1 + s2 + s3) || (sc == s1 + s2 + s3)
			|| (sc == s2 + s1 + s3)|| (sc == s2 + s3 + s1)
			|| (sc == s3 + s1 + s2)|| (sc == s3 + s2 + s1))
			ans[j] = 1;
		else
			ans[j] = 0;
	}
	for(i = 1; i <= m; i++)
		if(ans[i] == 1)
			cout << "ACC" << endl;
		else
			cout << "WA" << endl;
    //f1.close();
    //f2.close();
    //system("PAUSE");
        return 0;
}


#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;

ll n, i, j, ans[1010], m;
string s1, s2, s3, s, sc;

ll min(ll a,ll b)
{
	if(a > b)
		return b;
	else
		return a;
}

ll max(ll a,ll b)
{
	if(a > b)
		return a;
	else
		return b;
}

int main()
{
    //ifstream f1("input.txt");
    //ofstream f2("output.txt");
	cin >> s;
	n = s.length();
	s1 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s1 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s1 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s2 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s2 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s2 += (char)((ll)s[i] + 32);
	cin >> s;
	n = s.length();
	s3 = "";
	for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			s3 += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				s3 += (char)((ll)s[i] + 32);
	cin >> m;

	for(j = 1; j <= m; j++)
	{
		cin >> s;
		sc = "";
		n = s.length();
		for(i = 0; i < n; i++)
		if((s[i] >= 'a')&&(s[i] <= 'z'))
			sc += s[i];
		else
			if((s[i] >= 'A')&&(s[i] <= 'Z'))
				sc += (char)((ll)s[i] + 32);
		if((sc == s1 + s2 + s3) || (sc == s1 + s2 + s3)
			|| (sc == s2 + s1 + s3)|| (sc == s2 + s3 + s1)
			|| (sc == s3 + s1 + s2)|| (sc == s3 + s2 + s1))
			ans[j] = 1;
		else
			ans[j] = 0;
	}
	for(i = 1; i <= m; i++)
		if(ans[i] == 1)
			cout << "ACC" << endl;
		else
			cout << "WA" << endl;
    //f1.close();
    //f2.close();
    //system("PAUSE");
        return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <map>
#include <algorithm>

#define FOR(i, a, b) for(int i = int(a); i < int(b); i++)
#define INF 2000000000
#define EPS 1e-9
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define DEBUG(x) printf("debugging.. %d\n", x);
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

int n;
string init[3];

bool solve(string s) {
//	printf("q=%s\n", s.c_str());
	bool used[605] = {0};
	for(int i = 0; i < 3; ++i) {
		int pos = s.find(init[i]);
		if(pos == -1) return 0;

		for(int k = pos; k <= pos + init[i].size(); ++k)
			used[k] = 1;
	}

	int cnt = 0;
	for(int i = 0; i < s.size(); ++i) cnt += used[i];
//	for(int i = 0; i < s.size(); ++i) printf("%d", used[i]); printf("\n");

	return (cnt == s.size());
}

int main() {
	for(int i = 0; i < 3; ++i) {
		char s[105];
		scanf("%s", &s);

		for(int j = 0, len = strlen(s); j < len; ++j)
			if(isalpha(s[j])) init[i].PB(tolower(s[j]));
	}

//	for(int i = 0; i < 3; ++i) printf("init = %s\n", init[i].c_str());

	scanf("%d", &n); getchar();

	for(int i = 0; i < n; ++i) {
		char s[605];
		gets(s);

		int len = strlen(s);
		string q;
		for(int j = 0; j < len; ++j)
			if(isalpha(s[j])) q.PB(tolower(s[j]));

		printf("%s\n", solve(q) ? "ACC" : "WA");
	}

	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <map>
#include <algorithm>

#define FOR(i, a, b) for(int i = int(a); i < int(b); i++)
#define INF 2000000000
#define EPS 1e-9
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define DEBUG(x) printf("debugging.. %d\n", x);
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

int n;
string init[3];

bool solve(string s) {
//	printf("q=%s\n", s.c_str());
	for(int i = 0; i < 3; ++i) {
		int pos = s.find(init[i]);
		if(pos == -1) return 0;

		for(int k = pos; k < pos + init[i].size(); ++k)
			s[k] = '.';

//		printf("s=%s\n", s.c_str());
	}

	for(int i = 0; i < s.size(); ++i) if(s[i] != '.') return 0;
//	for(int i = 0; i < s.size(); ++i) printf("%d", used[i]); printf("\n");

	return 1;
}

int main() {
	for(int i = 0; i < 3; ++i) {
		char s[105];
		scanf("%s", &s);

		for(int j = 0, len = strlen(s); j < len; ++j)
			if(isalpha(s[j])) init[i].PB(tolower(s[j]));
	}

//	for(int i = 0; i < 3; ++i) printf("init = %s\n", init[i].c_str());

	scanf("%d", &n); getchar();

	for(int i = 0; i < n; ++i) {
		char s[605];
		gets(s);

		int len = strlen(s);
		string q;
		for(int j = 0; j < len; ++j)
			if(isalpha(s[j])) q.PB(tolower(s[j]));

		printf("%s\n", solve(q) ? "ACC" : "WA");
	}

	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <map>
#include <algorithm>

#define FOR(i, a, b) for(int i = int(a); i < int(b); i++)
#define INF 2000000000
#define EPS 1e-9
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define DEBUG(x) printf("debugging.. %d\n", x);
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

int n;
string init[3];

bool solve(string s, int mask) {
//	printf("q=%s\n", s.c_str());
	for(int i = 0; i < 3; ++i) {
		if(mask & (1 << i)) continue;

		int pos = s.find(init[i]);
		if(pos == -1) return 0;
		while(pos != -1) {
			string ss = s;
			for(int k = pos; k < pos + init[i].size(); ++k)
				ss[k] = '.';

			if(solve(ss, mask | (1 << i))) return 1;
			pos = s.find(init[i], pos + 1);
		}
	}

	for(int i = 0; i < s.size(); ++i) if(s[i] != '.') return 0;
//	for(int i = 0; i < s.size(); ++i) printf("%d", used[i]); printf("\n");

	return 1;
}

int main() {
	for(int i = 0; i < 3; ++i) {
		char s[105];
		scanf("%s", &s);

		for(int j = 0, len = strlen(s); j < len; ++j)
			if(isalpha(s[j])) init[i].PB(tolower(s[j]));
	}

//	for(int i = 0; i < 3; ++i) printf("init = %s\n", init[i].c_str());

	scanf("%d", &n); getchar();

	for(int i = 0; i < n; ++i) {
		char s[605];
		gets(s);

		int len = strlen(s);
		string q;
		for(int j = 0; j < len; ++j)
			if(isalpha(s[j])) q.PB(tolower(s[j]));

		printf("%s\n", solve(q, 0) ? "ACC" : "WA");
	}

	return 0;
}


//chuan hoa het tat ca cac chuoi input: dua ve dang chu in thuong, xoa cac dau hieu.
//tao ra 1 tap hop gom 6 to hop cua 3 chuoi dau tien de doi chieu va so sanh.
//chuoi nao khong nam trong tap hop tren thi ket qua "WA", nguoc lai "ACC".
#include <stdio.h>
#include <conio.h>
#include <string>
#include <vector>
#include <stdlib.h>
#include <iostream>
using namespace std;
vector<string> v, v2, v3;
int n;
void format_st(string &st)
{
	string s = "";
	for (int i = 0; i < st.length(); i++)
		if (st[i] != '-' && st[i] != ';' && st[i] != '_')
			if (st[i] >= 65 && st[i] <= 90)
			{
				s = s + char(st[i] + 32);
			}
			else
				s = s + st[i];
	st = s;

}

int main()
{
	v.resize(3);
	for (int i = 0; i < 3; i++)
	{
		//getline(cin,v[i]);
		cin >> v[i];
		format_st(v[i]);
	}
	scanf("%d", &n);
	v2.resize(n);
	for (int i = 0; i < n; i++)
	{
		//getline(cin, v2[i]);
		cin >> v2[i];
		format_st(v2[i]);
	}
	v3.resize(6);
	v3[0] = v[0] + v[1] + v[2];
	v3[1] = v[0] + v[2] + v[1];
	v3[2] = v[1] + v[0] + v[2];
	v3[3] = v[1] + v[2] + v[0];
	v3[4] = v[2] + v[0] + v[1];
	v3[5] = v[2] + v[1] + v[0];
	for (int i = 0; i < n; i++)
		if (v2[i] == v3[0])
		{
			printf("ACC\n");
			continue;
		}
		else
			if (v2[i] == v3[1])
			{
				printf("ACC\n");
				continue;
			}
			else
				if (v2[i] == v3[2])
				{
					printf("ACC\n");
					continue;
				}
				else
					if (v2[i] == v3[3])
					{
						printf("ACC\n");
						continue;
					}
					else
						if (v2[i] == v3[4])
						{
							printf("ACC\n");
							continue;
						}
						else
							if (v2[i] == v3[5])
							{
								printf("ACC\n");
								continue;
							}
							else
								printf("WA\n");

	//_getch();
	return 0;
}


//chuan hoa het tat ca cac chuoi input: dua ve dang chu in thuong, xoa cac dau hieu.
//tao ra 1 tap hop gom 6 to hop cua 3 chuoi dau tien de doi chieu va so sanh.
//chuoi nao khong nam trong tap hop tren thi ket qua "WA", nguoc lai "ACC".
#include <stdio.h>
#include <conio.h>
#include <string>
#include <vector>
#include <stdlib.h>
#include <iostream>
using namespace std;
vector<string> v, v2, v3;
int n;
void format_st(string &st)
{
	string s = "";
	for (int i = 0; i < st.length(); i++)
		if (st[i] != '-' && st[i] != ';' && st[i] != '_')
			if (st[i] >= 65 && st[i] <= 90)
			{
				s = s + char(st[i] + 32);
			}
			else
				s = s + st[i];
	st = s;

}
void main()
{
	v.resize(3);
	for (int i = 0; i < 3; i++)
	{
		//getline(cin,v[i]);
		cin >> v[i];
		format_st(v[i]);
	}
	scanf_s("%d", &n);
	v2.resize(n);
	for (int i = 0; i < n; i++)
	{
		//getline(cin, v2[i]);
		cin >> v2[i];
		format_st(v2[i]);
	}
	v3.resize(6);
	v3[0] = v[0] + v[1] + v[2];
	v3[1] = v[0] + v[2] + v[1];
	v3[2] = v[1] + v[0] + v[2];
	v3[3] = v[1] + v[2] + v[0];
	v3[4] = v[2] + v[0] + v[1];
	v3[5] = v[2] + v[1] + v[0];
	for (int i = 0; i < n; i++)
		if (v2[i] == v3[0])
		{
			printf("ACC\n");
			continue;
		}
		else
			if (v2[i] == v3[1])
			{
				printf("ACC\n");
				continue;
			}
			else
				if (v2[i] == v3[2])
				{
					printf("ACC\n");
					continue;
				}
				else
					if (v2[i] == v3[3])
					{
						printf("ACC\n");
						continue;
					}
					else
						if (v2[i] == v3[4])
						{
							printf("ACC\n");
							continue;
						}
						else
							if (v2[i] == v3[5])
							{
								printf("ACC\n");
								continue;
							}
							else
								printf("WA\n");

	//_getch();
}


//chuan hoa het tat ca cac chuoi input: dua ve dang chu in thuong, xoa cac dau hieu.
//tao ra 1 tap hop gom 6 to hop cua 3 chuoi dau tien de doi chieu va so sanh.
//chuoi nao khong nam trong tap hop tren thi ket qua "WA", nguoc lai "ACC".
#include <stdio.h>
#include <conio.h>
#include <string>
#include <vector>
#include <stdlib.h>
#include <iostream>
using namespace std;
vector<string> v, v2, v3;
int n;
void format_st(string &st)
{
	string s = "";
	for (int i = 0; i < st.length(); i++)
		if (st[i] != '-' && st[i] != ';' && st[i] != '_')
			if (st[i] >= 65 && st[i] <= 90)
			{
				s = s + char(st[i] + 32);
			}
			else
				s = s + st[i];
	st = s;

}
void main()
{
	v.resize(3);
	for (int i = 0; i < 3; i++)
	{
		//getline(cin,v[i]);
		cin >> v[i];
		format_st(v[i]);
	}
	scanf("%d", &n);
	v2.resize(n);
	for (int i = 0; i < n; i++)
	{
		//getline(cin, v2[i]);
		cin >> v2[i];
		format_st(v2[i]);
	}
	v3.resize(6);
	v3[0] = v[0] + v[1] + v[2];
	v3[1] = v[0] + v[2] + v[1];
	v3[2] = v[1] + v[0] + v[2];
	v3[3] = v[1] + v[2] + v[0];
	v3[4] = v[2] + v[0] + v[1];
	v3[5] = v[2] + v[1] + v[0];
	for (int i = 0; i < n; i++)
		if (v2[i] == v3[0])
		{
			printf("ACC\n");
			continue;
		}
		else
			if (v2[i] == v3[1])
			{
				printf("ACC\n");
				continue;
			}
			else
				if (v2[i] == v3[2])
				{
					printf("ACC\n");
					continue;
				}
				else
					if (v2[i] == v3[3])
					{
						printf("ACC\n");
						continue;
					}
					else
						if (v2[i] == v3[4])
						{
							printf("ACC\n");
							continue;
						}
						else
							if (v2[i] == v3[5])
							{
								printf("ACC\n");
								continue;
							}
							else
								printf("WA\n");

	//_getch();
}


#include <conio.h>
#include <stdio.h>
#include <string.h>
char* olo(char *s)
{int j, i=strlen(s), k;
 char ss[110]; k=0;
 for(j=0; j<i; j++)
     if((s[j]!=';')&&(s[j]!='-')&&(s[j]!='_')){ss[k]=s[j];k++;}
 s[0]='\0';
 strcpy(s, ss);
}
int main()
{char s1[110], s2[110], s3[110], temp[110], bb[110];
 char otv1[110], otv2[110], otv3[110], otv4[110], otv5[110], otv6[110];
 char sss[1000][110];
 int i,j,n;
 scanf("%s%s%s%d", s1, s2, s3, &n);
 strcpy(otv1, s1);  strcat(otv1, s2);  strcat(otv1, s3); //ioaao a 1
 strcpy(otv4, s1);  strcat(otv4, s3);  strcat(otv4, s2); //ioaao a 1

 strcpy(otv2, s2);  strcat(otv2, s1);  strcat(otv2, s3); //ioaao a 2
 strcpy(otv5, s2);  strcat(otv5, s3);  strcat(otv5, s1); //ioaao a 2

 strcpy(otv3, s3);  strcat(otv3, s1);  strcat(otv3, s2); //ioaao a 3
 strcpy(otv6, s3);  strcat(otv6, s2);  strcat(otv6, s1); //ioaao a 3
// printf("%s", strlwr(olo(otv3)));
//  printf("%s", strlwr(olo(otv4)));
 for(i=0; i<n; i++){
                    scanf("%s", temp);
                    if  ((strcmp( strlwr(olo(otv1)), strlwr(olo(temp)) )==0)||
                         (strcmp( strlwr(olo(otv2)), strlwr(olo(temp)) )==0)||
                         (strcmp( strlwr(olo(otv3)), strlwr(olo(temp)) )==0)||
                         (strcmp( strlwr(olo(otv4)), strlwr(olo(temp)) )==0)||
                         (strcmp( strlwr(olo(otv5)), strlwr(olo(temp)) )==0)||
                         (strcmp( strlwr(olo(otv6)), strlwr(olo(temp)) )==0))
                          strcpy(sss[i], "ACC" );
                          else strcpy(sss[i], "WA" );
                   //          printf("ACC");
                    //else printf("WA");
                   }
 for(i=0; i<n;i++)printf("%s\n", sss[i]);
 //getch();
 return 0;
}