#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN = 1e9;
const ll mod = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n + 1), b(n + 1, 0);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    ll ans = 0;
    for (int i = 0; i < m; i++)
    {
        ll x, y;
        cin >> x >> y;
        if (a[x] < a[y])
            swap(x, y);
        if (a[x] >= 0 && a[y] >= 0)
        {
            b[x]++;
            b[y]++;
        }
        else if (a[x] <= 0 && a[y] <= 0)
        {
            b[x]--;
            b[y]--;
        }
        else if (a[x] >= 0 && a[y] <= 0)
        {
            if (a[x] >= abs(a[y]))
            {
                b[x]++;
                b[y]++;
            }
            else
            {
                b[x]--;
                b[y]--;
            }
        }
        /* else if (a[x] <= 0 && a[y] >= 0)
        {
            if (abs(a[x]) >= a[y])
            {
                b[x]--;
                b[y]--;
            }
            else
            {
                b[x]++;
                b[y]++;
            }
        } */
    }
    for (int i = 1; i <= n; i++)
    {
        cout << a[i] << " " << b[i] << "\n";
        ans += a[i] * b[i];
    }
    cout << ans;
    return 0;
}