#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

int main() {
    fast_io
    cin >> n >> k;

    ll arr[10001] = {0};
    for(ll i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        arr[x] ++;
    }

    for(ll i = 0 ; i <= 10000 ; i++) {
        for(ll j = i ; j <= 10000 ; j++) {
            ll m = __builtin_popcount(i ^ j);
            if(m == k) {
                if(i == j) {
                    ans += (arr[i] * (arr[i] - 1)) / 2;
                }
                else {
                    ans += (arr[i] * arr[j]);
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 20 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= (1ll << 20) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    unordered_map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    while(x) {
        if(x & 1) {
            cnt ++;
        }
        x >>= 1ll;
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i < (1ll << 14) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i < 15 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= (1ll << 14) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 16 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= (1ll << 16) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    unordered_map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    while(x) {
        if(x & 1) {
            cnt ++;
        }
        x >>= 1ll;
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= (1ll << 14) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 15 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= (1ll << 15) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    return __builtin_popcount(x);
}

void calcNum() {
    for(ll i = 0 ; i <= 10000 ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        mp[x] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    while(x) {
        if(x & 1) {
            cnt ++;
        }
        x >>= 1ll;
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i < (1ll << 14) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    unordered_map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    while(x) {
        if(x & 1) {
            cnt ++;
        }
        x >>= 1;
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i < (1 << 14) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        mp[x] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 20 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= 100000 ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    cin >> n >> k;
    ll arr[n] = {0};

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    if(k == 0) {
        for(auto i : mp) {
            ans += ((i.second - 1) * (i.second)) / 2;
        }
        cout << ans << endl;
    }
    else {
        calcNum();
        for(auto i : v) {
            if(mp[i]) {
                for(auto itr : mp) {
                    ll xr = itr.first ^ i;
                    if(mp[xr]) {
                        ans += (itr.second * mp[xr]);
                    }
                }
            }
        }
        ans /= 2;
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    return __builtin_popcount(x);
}

void calcNum() {
    for(ll i = 0 ; i <= 11000 ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        mp[x] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 15 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= (1ll << 15) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    unordered_map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    while(x) {
        if(x & 1) {
            cnt ++;
        }
        x >>= 1;
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i < (1 << 14) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        mp[x] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 20 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= 100000 ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    return __builtin_popcount(x);
}

void calcNum() {
    for(ll i = 0 ; i <= (1ll << 14) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        mp[x] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 20 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= 100000 ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    cin >> n >> k;
    ll arr[n] = {0};

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 14 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= 10000 ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    cin >> n >> k;
    ll arr[n] = {0};

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    while(x) {
        if(x & 1) {
            cnt ++;
        }
        x >>= 1;
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i < (1 << 14) ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        mp[x] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    while(x) {
        if(x & 1) {
            cnt ++;
        }
        x >>= 1;
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= 10000 ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;

    map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        mp[x] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);

vector <ll> v;
ll n , k;
ll ans = 0;

ll calcBits(ll x) {
    ll cnt = 0;
    for(ll i = 0 ; i <= 20 ; i++) {
        if((x & (1ll << i)) != 0) {
            cnt ++;
        }
    }
    return cnt;
}

void calcNum() {
    for(ll i = 0 ; i <= 100000 ; i++) {
        if(calcBits(i) == k) {
            v.push_back(i);
        }
    }
}

int main() {
    fast_io
    cin >> n >> k;
    ll arr[n] = {0};

    unordered_map <ll , ll> mp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> arr[i];
        mp[arr[i]] ++;
    }

    calcNum();

    for(auto i : v) {
        for(auto itr : mp) {
            ll xr = itr.first ^ i;
            if(mp[xr]) {
                if(i != 0) {
                    ans += (itr.second * mp[xr]);
                }
                else {
                    ans += ((mp[xr] - 1) * mp[xr]);
                }
            }
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t[100000];
int cou(int x)
{
    if (x==0) return 0;
    return (int(x&1)+cou(x>>1));

}
vector<vector<int > > v;

int main(){

int n,k;
cin>>n>>k;
long long ans=0;
for (int i=0;i<n;i++){int s; cin>>s;t[s]++ ; }
//cout<<__builtin_popcount(100^200);
for (int i=0;i<10001;i++) for (int j=i;j<10001;j++)
{
    if (__builtin_popcount(i^j)==k) {if (i==j)ans+=t[i]*(t[i]-1)/2; else ans+=t[i]*t[j];}
}
cout<<ans;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t[100000];
int cou(int x)
{
    if (x==0) return 0;
    return (int(x&1)+cou(x>>1));

}
vector<vector<int > > v;

int main(){

int n,k;
cin>>n>>k;
long long ans=0;
for (int i=0;i<n;i++){int s; cin>>s;t[s]++ ; }
//cout<<__builtin_popcount(100^200);
for (int i=0;i<10001;i++) for (int j=i;j<10001;j++)
{
    if (__builtin_popcount(i^j)==k) ans+=t[i]*t[j];
}
cout<<ans;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t[100000];
int cou(int x)
{
    if (x==0) return 0;
    return (int(x&1)+cou(x>>1));

}
vector<vector<int > > v;

int main(){

int n,k;
cin>>n>>k;
long long ans=0;
for (int i=0;i<n;i++){int s; cin>>s;t[s]++ ; }

for (int i=0;i<10001;i++) for (int j=i+1;j<10001;j++)
{
    if (__builtin_popcount(i^j)==k) ans+=t[i]*t[j];
}
cout<<ans;
return 0;

}


#include <bits/stdc++.h>
using namespace std;
int t[100000];
int cou(int x)
{
    if (x==0) return 0;
    return (int(x&1)+cou(x>>1));

}
vector<vector<int > > v;

int main(){

int n,k;
cin>>n>>k;
long long ans=0;
for (int i=0;i<n;i++){int s; cin>>s;t[s]++ ; }

for (int i=0;i<10001;i++) for (int j=i+1;j<10001;j++)
{
    if (__builtin_popcount(i^j)==k) ans+=t[i]*t[j];
}
cout<<ans;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long t[999999];
int cou(int x)
{
    if (x==0) return 0;
    return (int(x&1)+cou(x>>1));

}
vector<vector<int > > v;

int main(){

int n,k;
cin>>n>>k;
long long ans=0;
for (int i=0;i<n;i++){int s; cin>>s;t[s]++ ; }
//cout<<__builtin_popcount(100^200);
for (int i=0;i<10001;i++) for (int j=i;j<10001;j++)
{
    if (__builtin_popcount(i^j)==k) {if (i==j)ans+=t[i]*(t[i]-1)/2; else ans+=t[i]*t[j];}
}
cout<<ans;
return 0;
}


#include <iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<set>
#include<stdlib.h>
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    vector<int> is(200000);
    vector<int> perm;
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
        is[v[i]]++;
    }
    for(int i = 0; i <= 10000; i++)
    {
        int t = i, nc = 0;
        while (t > 0)
        {
            int rest = t%2;
            nc += rest;
            t /= 2;
        }
        if (nc == k)
        {
            perm.push_back(i);
        }
    }
    unsigned long long res = 0;
    int m = perm.size();
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            int temp = perm[j]^v[i];
            if (is[temp])
            {
                if (temp == v[i])
                    res += is[temp]-1;
                else res += is[temp];
            }
        }
    }
    cout << res/2 << endl;
    return 0;
}


#include <iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<set>
#include<stdlib.h>
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> v;
    vector<int> is(200000);
    vector<int> perm;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (!is[a])
            v.push_back(a);
        is[a]++;
    }
    for(int i = 0; i <= 65535; i++)
    {
        int t = i, nc = 0;
        while (t > 0)
        {
            int rest = t%2;
            nc += rest;
            t /= 2;
        }
        if (nc == k)
        {
            perm.push_back(i);
        }
    }
    unsigned long long res = 0;
    int m = perm.size();
    n = v.size();
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            int temp = perm[j]^v[i];
            if (is[temp])
            {
                if (temp == v[i])
                    res += (is[temp]-1)*is[temp];
                else res += is[temp]*is[v[i]];
            }
        }
    }
    cout << res/2 << endl;
    return 0;
}


#include <iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<set>
#include<stdlib.h>
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    vector<int> is(200000);
    vector<int> perm;
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
        is[v[i]]++;
    }
    for(int i = 0; i <= 16384; i++)
    {
        int t = i, nc = 0;
        while (t > 0)
        {
            int rest = t%2;
            nc += rest;
            t /= 2;
        }
        if (nc == k)
        {
            perm.push_back(i);
        }
    }
    unsigned long long res = 0;
    int m = perm.size();
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            int temp = perm[j]^v[i];
            if (is[temp])
            {
                if (temp == v[i])
                    res += is[temp]-1;
                else res += is[temp];
            }
        }
    }
    cout << res/2 << endl;
    return 0;
}


#include <iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<set>
#include<stdlib.h>
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> v;
    vector<int> is(200000);
    vector<int> perm;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (!is[a])
            v.push_back(a);
        is[a]++;
    }
    for(int i = 0; i <= 70000; i++)
    {
        int t = i, nc = 0;
        while (t > 0)
        {
            int rest = t%2;
            nc += rest;
            t /= 2;
        }
        if (nc == k)
        {
            perm.push_back(i);
        }
    }
    unsigned long long res = 0;
    int m = perm.size();
    n = v.size();
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            int temp = perm[j]^v[i];
            if (is[temp])
            {
                if (temp == v[i])
                    res += (is[temp]-1)*is[temp];
                else res += is[temp]*is[v[i]];
            }
        }
    }
    cout << res/2 << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define eps 1e-8
#define pi acos(-1)
ll n,tmp,pw[20],cnt[10005],arr[10005],tmp2,mx;
string s;

void solve(int i , int val , int k)
{
    if (!k)
    {
        while(i<14)
        {
            val += (pw[i]*(s[i]=='1'));
            i++;
        }
        tmp += cnt[val];
        return;
    }
    if (i>13) return;

    solve(i+1 , val , k-(s[i]=='1'));
    if (val+pw[i] <= 10000) solve(i+1 , val+pw[i] , k-(s[i]=='0'));
}

int main()
{
    int k;
    ll ans=0;
    pw[0]=1;
    for (int i=1; i<=14; i++)
    {
        pw[i] = 2*pw[i-1];
    }

    cin >> n >> k;
    for (int i=1; i<=n; i++)
    {
        cin >> arr[i];
        cnt[arr[i]]++;
    }

    if (!k)
    {
        for (int i=0; i<=10000; i++)
        {
            ans += (cnt[i]*(cnt[i]-1)/2);
        }
        return cout << ans << "\n" , 0;
    }

    for (ll i=0; i<=10000; i++)
    {
        s.clear() , tmp2=i;;
        while(tmp2)
        {
            if (tmp2%2) s += '1';
            else s += '0';
            tmp2 /= 2;
        }
        while(s.size() < 14)
            s += '0';
        tmp=0;
        solve(0 , 0 , k);
        ans += (cnt[i]*tmp);
    }
    cout << ans/2 << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define eps 1e-8
#define pi acos(-1)
ll n,tmp,pw[20],cnt[1000005],arr[10005],tmp2,mx;
string s;

void solve(ll i , ll val , ll k)
{
    if (!k)
    {
        while(i<14)
        {
            val += (pw[i]*(s[i]=='1'));
            i++;
        }
        tmp += cnt[val];
        return;
    }
    if (i>13) return;

    solve(i+1 , val , k-(s[i]=='1'));
    if (val+pw[i] <= 10000) solve(i+1 , val+pw[i] , k-(s[i]=='0'));
}

int main()
{
    ll k;
    ll ans=0;
    pw[0]=1;
    for (int i=1; i<=18; i++)
    {
        pw[i] = 2*pw[i-1];
    }

    cin >> n >> k;
    for (int i=1; i<=n; i++)
    {
        cin >> arr[i];
        cnt[arr[i]]++;
    }

    if (!k)
    {
        for (int i=0; i<=10000; i++)
        {
            ans += (cnt[i]*(cnt[i]-1)/2);
        }
        return cout << ans << "\n" , 0;
    }

    for (ll i=0; i<=10000; i++)
    {
        if (!cnt[i]) continue;
        s.clear() , tmp2=i;
        while(tmp2)
        {
            if (tmp2%2) s += '1';
            else s += '0';
            tmp2 /= 2;
        }
        while(s.size() < 20)
            s += '0';
        tmp=0;
        solve(0 , 0 , k);
        ans += (cnt[i]*tmp);
    }
    cout << ans/(ll)2 << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define eps 1e-8
#define pi acos(-1)
int n,tmp,pw[20],cnt[10005],arr[10005],arr2[10005],mx;
string s;

void solve(int i , int val , int k)
{
    if (i<0)
    {
        if (!k) tmp += cnt[val]; return;
        return;
    }
    if (!k)
    {
        while(i>=0)
        {
            val += (pw[i]*(s[i]=='1'));
            i--;
        }
        tmp += cnt[val];
        return;
    }

    solve(i-1 , val , k-(s[i]=='1'));
    if (val+pw[i] <= mx) solve(i-1 , val+pw[i] , k-(s[i]=='0'));
}

int main()
{
    int k;
    ll ans=0;
    pw[0]=1;
    for (int i=1; i<=14; i++)
    {
        pw[i] = 2*pw[i-1];
    }

    cin >> n >> k;
    for (int i=1; i<=n; i++)
    {
        cin >> arr[i];
        mx = max(mx , arr[i]);
        cnt[arr[i]]++ , arr2[i]=arr[i];
    }

    if (!k)
    {
        for (int i=1; i<=n; i++)
        {
            ans += (cnt[arr[i]]-1);
            cnt[arr[i]]--;
        }
        return cout << ans << "\n" , 0;
    }

    for (int i=1; i<=n; i++)
    {
        s.clear();
        while(arr[i])
        {
            if (arr[i]%2) s += '1';
            else s += '0';
            arr[i] /= 2;
        }
        while(s.size() < 14)
            s += '0';
        tmp=0;
        solve(13 , 0 , k);
        ans += (cnt[arr2[i]]*tmp);
    }
    cout << ans/2 << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define eps 1e-8
#define pi acos(-1)
ll n,tmp,pw[20],cnt[1000005],arr[10005],tmp2,mx;
string s;

void solve(int i , int val , int k)
{
    if (!k)
    {
        while(i<14)
        {
            val += (pw[i]*(s[i]=='1'));
            i++;
        }
        tmp += cnt[val];
        return;
    }
    if (i>13) return;

    solve(i+1 , val , k-(s[i]=='1'));
    if (val+pw[i] <= 10000) solve(i+1 , val+pw[i] , k-(s[i]=='0'));
}

int main()
{
    ll k;
    ll ans=0;
    pw[0]=1;
    for (int i=1; i<=14; i++)
    {
        pw[i] = 2*pw[i-1];
    }

    cin >> n >> k;
    for (int i=1; i<=n; i++)
    {
        cin >> arr[i];
        cnt[arr[i]]++;
    }

    if (!k)
    {
        for (int i=0; i<=10000; i++)
        {
            ans += (cnt[i]*(cnt[i]-1)/2);
        }
        return cout << ans << "\n" , 0;
    }

    for (ll i=0; i<=10000; i++)
    {
        s.clear() , tmp2=i;;
        while(tmp2)
        {
            if (tmp2%2) s += '1';
            else s += '0';
            tmp2 /= 2;
        }
        while(s.size() < 14)
            s += '0';
        tmp=0;
        solve(0 , 0 , k);
        ans += (cnt[i]*tmp);
    }
    cout << ans/(ll)2 << "\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
struct Fra
{
    ll p,q;
    Fra(ll x = 0,ll y = 1):p(x),q(y){ normal(p,q); }
    void normal(ll &p,ll &q) { ll g = gcd(p,q); p/=g; q/=g; }
    Fra operator = (int x) {  p = x; q = 1; return *this; }
    Fra operator = (ll x) { p = x; q = 1; return *this; }
    Fra operator - () { return {-p,q}; }
    Fra operator + (Fra &r) {
        ll m,n;
        m = p*r.q+r.p*q;
        n = q*r.q;
        normal(m,n);
        return {m,n};
    }
    Fra operator += (Fra& r) { return *this = *this+r; }
    Fra operator - (Fra &r) { return (-r) + *this; }
    Fra operator -= (Fra &r) { return *this = *this-r; }
    Fra operator * (Fra &r) {
        ll m,n;
        m = p*r.p;
        n = q*r.q;
        normal(m,n);
        return {m,n};
    }
    Fra operator *= (Fra &r) { return (*this) = (*this)*r; }
    Fra operator /(Fra &r) { return Fra(r.q,r.p) * (*this); }
    Fra operator /=(Fra &r) { return (*this) = (*this)/r; }
    bool operator == (const Fra& r) const { return p*r.q == r.p*q; }
    bool operator < (const Fra& r) const { return  p*r.q < r.p*q; }
};

const int maxn = 1e3+5;

const ll INF = 1e16;
int main()
{
    //freopen("in.txt","r",stdin);
    int n; scanf("%d",&n);
    Fra Low(0),High(INF);
    for(int i = 1; i <= n; i++){
        int t; scanf("%d",&t);
        Low = max(Fra(t*10,i),Low);
        High = min(Fra(t*10+10,i),High);
    }
    Low = Fra(n+1)*Low;
    High = Fra(n+1)*High;
    int u = (High.p-1)/High.q;
    int d = (Low.p)/Low.q;
    if(u/10 != d/10) {
        puts("not unique");
    }else {
        printf("unique\n%d",d/10);
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define vii vector<pair<int,int>>

const int INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000003;

// ----------------------------------------------------------------------------------------------------------

int A[1005], N;

int main()
{
    cin >> N;
    double lo = 10000000, hi = 0;
    f(i,1,N)
    {
        cin >> A[i];
        lo = min(lo, (10.0 + 10.0*A[i]) / (double) i - .00001);
        hi = max(hi, (10.0 + 10.0*(A[i]-1)) / (double) i);
    }
    int a = 0, b = 0;
    f(x,A[N]+1,10000000) if(lo * (N+1) - 10.0*x < 10 + .00001)
    {
        a = x;
        break;
    }
    f(x,A[N]+1,10000000) if(hi * (N+1) - 10.0*x < 10 + .00001)
    {
        b = x;
        break;
    }
    if(a == b) cout << "unique\n" << a;
    else cout << "not unique";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define vii vector<pair<int,int>>

const int INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000003;

// ----------------------------------------------------------------------------------------------------------

int A[1005], N;

int main()
{
    cin >> N;
    double lo = 10000000, hi = 0;
    f(i,1,N)
    {
        cin >> A[i];
        lo = min(lo, (10.0 + 10.0*A[i]) / (double) i - .00001);
        hi = max(hi, (10.0 + 10.0*(A[i]-1)) / (double) i);
    }
    int a = 0, b = 0;
    f(x,A[N]+1,10000000) if(lo * (N+1) - 10.0*x < 10 - .00001)
    {
        a = x;
        break;
    }
    f(x,A[N]+1,10000000) if(hi * (N+1) - 10.0*x < 10 - .00001)
    {
        b = x;
        break;
    }
    if(a == b) cout << "unique\n" << a;
    else cout << "not unique";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fd(i,a,b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define faster_io() ios_base::sync_with_stdio(false)
#define pb push_back
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define vii vector<pair<int,int>>

const int INF = 1000000002;
const ll INFLL = 100000000000000000ll;
const ll MOD = 1000003;

// ----------------------------------------------------------------------------------------------------------

int A[1005], N;

int main()
{
    cin >> N;
    double lo = 10000000, hi = 0;
    f(i,1,N)
    {
        cin >> A[i];
        lo = min(lo, (10.0 + 10.0*A[i]) / (double) i);
        hi = max(hi, (10.0 + 10.0*(A[i]-1)) / (double) i);
    }
    int a = 0, b = 0;
    f(x,A[N]+1,10000000) if(lo * (N+1) - 10.0*x < 10 + .00001)
    {
        a = x;
        break;
    }
    f(x,A[N]+1,10000000) if(hi * (N+1) - 10.0*x < 10 + .00001)
    {
        b = x;
        break;
    }
    if(a == b) cout << "unique\n" << a;
    else cout << "not unique";
}


#include <cstdio>
#include <cmath>

using namespace std;

#define mx(x,y) (x>y ? x : y)
#define mi(x,y) (x<y ? x : y)

int n,t,NE,l,r;
double MI,MX;

void re(int &x)
{
    x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
}

int main()
{
    re(n);
    re(t);
    MI=t; MX=t+1;
    for(int i=2;i<=n;i++)
    {
        re(t);
        MI=mx(1.0*t/i,MI);
        MX=mi(1.0*(t+1)/i,MX);
    }
    MI*=n+1; MX*=n+1;
    l=(int)floor(MI);
    r=(int)floor(MX);
    if(MX==floor(MX)) r--;
    if(l!=r) printf("not unique");
    else printf("unique\n%d",l);
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int n=0;
    double maximum,minimum,x;
    cin >>n;
    if(n==1)
    {
        cin>>x;
        cout<<"not unique"<< "\n";
    }
    else
    {
        maximum=10000000;
        minimum=10;
        for(int i=1;i<n+1;i++)
        {
            cin>>x;
            {
                //cout << x << " " << i << endl;
                if(minimum< ((x)*10)/(i))
                    minimum= ((x)*10)/(i);
                if(maximum> (x+1)*10/(i))
                    maximum = (x+1)*10/(i);
            }
            //cout << minimum << "  " << maximum << endl;

        }
       /* if(n == 17)
    cout << maximum << " " << minimum << endl;*/

    maximum*=(double)(n+1);
    minimum*=(double)(n+1);
    //cout << maximum << " " << minimum << endl;
    int res = floor(maximum),m=floor(minimum);
    if(res-maximum ==0)
    {
        res--;
    }
    /*if(m-minimum ==0)
    {
        m--;
    }*/
    if(res/10-m/10<1)
            cout << "unique\n" <<res/10<<"\n";
        else
            cout<< "not unique" <<"\n";
    }
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int n=0;
    float maximum,minimum,x;
    cin >>n;
    if(n==1)
    {
        cin>>x;
        cout<<"not unique"<< "\n";
    }
    else
    {
        maximum=10000000;
        minimum=10;
        for(int i=1;i<n+1;i++)
        {
            cin>>x;
            {
                //cout << x << " " << i << endl;
                if(minimum< ((x)*10)/(i))
                    minimum= ((x)*10)/(i);
                if(maximum> (x+1)*10/(i))
                    maximum = (x+1)*10/(i);
            }
            //cout << minimum << "  " << maximum << endl;

        }
       /* if(n == 17)
    cout << maximum << " " << minimum << endl;*/

    maximum*=(float)(n+1);
    minimum*=(float)(n+1);
    //cout << maximum << " " << minimum << endl;
    int res = floor(maximum),m=floor(minimum);
    if(res-maximum ==0)
    {
        res--;
    }
    /*if(m-minimum ==0)
    {
        m--;
    }*/
    if(res/10-m/10<1)
            cout << "unique\n" <<res/10<<"\n";
        else
            cout<< "not unique" <<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,a;
double Minx=10;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		Minx=a*10.0/i;
	}
	if(Minx==10){
		cout<<"not unique";
		return 0;
	}
	cout<<"unique"<<endl;
	cout<<int((n+1)*Minx/10);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a;
double Minx,Maxx;
int main(){
	cin>>n>>a;
	Minx=a;
	Maxx=a+1;
	for(int i=2;i<=n;i++){
		cin>>a;
		Minx=max(Minx,a*1.0/i);
		Maxx=min(Maxx,(a+1)*1.0/i);
	}
	Minx*=n+1,Maxx*=n+1;
	if(Maxx==int(Maxx))Maxx=int(Maxx)-1;
	Minx=int(floor(Minx));
	Maxx=int(floor(Maxx));
	if(Minx!=Maxx){
		cout<<"not unique";
		return 0;
	}
	cout<<"unique"<<endl;
	cout<<Minx;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a;
double Minx=10,Maxx=10;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		Minx=max(Minx,a*10.0/i);
		Maxx=min(Maxx,(a+1)*10.0/i);
	}
	if(Minx==Maxx){
		cout<<"not unique";
		return 0;
	}
	cout<<"unique"<<endl;
	cout<<int((n+1)*Minx/10);
	return 0;
}


#include<bits/stdc++.h>
int n,t,l,r;
double min,max;
int main(){
    scanf("%d%d",&n,&t);
    min=t;max=t+1;
    for(int i=2;i<=n;i++){
        scanf("%d",&t);
        min=std::max(1.0*t/i,min);
        max=std::min(1.0*(t+1)/i,max);
    }
    l=(int)floor(min*(n+1));
    r=(int)floor(max*(n+1))-(max==floor(max));
    l==r?printf("not unique"):printf("unique\n%d",l);
}


#include<bits/stdc++.h>
int n,t,l,r;
double min,max;
int main(){
    scanf("%d%d",&n,&t);
    min=t;max=t+1;
    for(int i=2;i<=n;i++){
        scanf("%d",&t);
        min=std::max(1.0*t/i,min);
        max=std::min(1.0*(t+1)/i,max);
    }
    l=(int)floor(min*(n+1));
    r=(int)floor(max*(n+1))-(int)((max*(n+1))==floor(max*(n+1)));
    l!=r?printf("not unique"):printf("unique\n%d",l);
}


#include<bits/stdc++.h>
using namespace std;
int n,a,l,r=1000010;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		l=max(l,10*a/i);
		r=min(r,10*(a+1)/i);
	}
	(l*=n+1)-=a*10,(r*=n+1)-=a*10;
	l/=10,(r-=1)/=10;
	if(l==r) printf("unique\n%d\n",a+l);
	else printf("not unique\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a;
double Minx,Maxx;
int main(){
	cin>>n>>a;
	Minx=a;
	Maxx=a+1;
	for(int i=2;i<=n;i++){
		cin>>a;
		Minx=max(Minx,a*1.0/i);
		Maxx=min(Maxx,(a+1)*1.0/i);
	}
	Minx*=n+1,Maxx*=n+1;
	int Min=floor(Minx);
	int Max=floor(Maxx);
	if(Maxx==floor(Maxx))Max--;
	if(Min!=Max){
		cout<<"not unique";
		return 0;
	}
	cout<<"unique"<<endl;
	cout<<Min;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
double mn=1e20,mx,t;
int n,low,high;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>t;
		mn=min(mn,(t+1-1e-8)/i);
		mx=max(mx,t/i);
	}
	n++;
	low=(int)(n*mx+1e-9),high=(int)(n*mn+1-1e-9);
	if(low+1==high) cout<<"unique\n"<<low;
	else cout<<"not unique";
}//hellobig_tq


#include <iostream>
#include <cmath>
using namespace std;
int i,n,N,a,b;
double MaxZ=1e9, MinZ=0.0;
int main()
{
  cin >> n;
  for(i=1;i<=n;i++)
  {
      cin>>N;
      MinZ=max(MinZ,(double)(N*10.0/i));
      MaxZ=min(MaxZ,(double)((N+1)*10.0)/i);
  }
  a=floor(MinZ*(n+1)/10.0);
  b=ceil(MaxZ*(n+1)/10.0);
  if (a+1>=b)
    {
        cout << "unique" << endl << a << endl;
    }
    else{ cout << "not unique" << endl;}
    return 0;
}


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

using namespace std;

int a[1010];

int main() {
    memset(a, 0, sizeof(a));

    double  low = 10.0,
            high = 1000007.0;
    int     n = 0;

    scanf("%d", &n);
    for(int i = 1; i<=n; ++i) {
        scanf("%d", &a[i]);
    }

    for(int i = 1; i<=n; ++i) {
        low = (double)max((double)low, (double)a[i]*10.0/i);
        high = (double)min((double)high, (double)(a[i]+1)*10.0/i);
    }

    low = (n+1)*1.0*low/10.0;
    high = (n+1)*1.0*high/10.0;

    int res = (int)low;
    if((double)res+1<high) {
        printf("not unique");
    }
    else {
        printf("unique\n");
        printf("%d", res);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
vector<pair<int,int>> mp[200001];
int stk[200001],vst[200001],edgew[400001];
pair<int,int> dfs(int k,int p,int curd)
{
    vst[k]=curd;
    stk[curd]=k;
    for (auto c:mp[k])
        if (c.first!=p)
        {
            edgew[curd]=c.second;
            if (vst[c.first])
                return make_pair(vst[c.first],curd);
            pair<int,int> res=dfs(c.first,k,curd+1);
            if (res.first)
                return res;
        }
    vst[k]=0;
    return make_pair(0,0);
}
bool used[200001],ban[200001];
int sts[200001];
void calcsts(int k,int p)
{
    sts[k]=1;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
        {
            calcsts(c.first,k);
            sts[k]+=sts[c.first];
        }
}
void gotov(int &k,int numv)
{
    int p=-1;
    while (true)
    {
        bool f=false;
        for (auto c:mp[k])
            if (c.first!=p&&!used[c.first]&&!ban[c.first]&&sts[c.first]>numv/2)
            {
                f=true;
                p=k;
                k=c.first;
                break;
            }
        if (!f)
            return;
    }
}
pair<int,long long> traverse(int k,int p)
{
    int ret1=1;
    long long ret2=0;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
        {
            pair<int,long long> res=traverse(c.first,k);
            ret1+=res.first;
            ret2+=res.second+c.second*res.first;
        }
    return make_pair(ret1,ret2);
}
long long ans[200001],weight[200001];
int siz[400001];
void subtree_add(int k,int p,long long val)
{
    ans[k]+=val;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
            subtree_add(c.first,k,val);
}
void setvw(int k,int p,int val,int siz)
{
    ans[k]+=(long long)val*siz;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
            setvw(c.first,k,val+c.second,siz);
}
void gravity(int k)
{
    calcsts(k,0);
    gotov(k,sts[k]);
    used[k]=true;
    int idx=0,totsiz=1;
    long long totval=0;
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
        {
            ++idx;
            pair<int,long long> res=traverse(c.first,0);
            siz[idx]=res.first;
            res.second+=c.second*res.first;
            weight[idx]=res.second;
            totval+=res.second;
            totsiz+=res.first;
        }
    ans[k]+=totval;
    idx=0;
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
        {
            ++idx;
            subtree_add(c.first,0,totval-weight[idx]+c.second*(totsiz-siz[idx]));
        }
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
            gravity(c.first);
}
long long cycleans[200001];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        int a,b,t;
        scanf("%d%d%d",&a,&b,&t);
        mp[a].push_back(make_pair(b,t));
        mp[b].push_back(make_pair(a,t));
    }
    pair<int,int> tmp=dfs(1,0,1);
    for (int i=tmp.first;i<=tmp.second;++i)
    {
        stk[i-tmp.first]=stk[i];
        edgew[i-tmp.first]=edgew[i];
    }
    int cyclelen=tmp.second-tmp.first+1;
    long long totweight=0;
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        gravity(stk[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    memset(used,0,sizeof(used));
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        pair<int,long long> tmp=traverse(stk[i],0);
        siz[i]=tmp.first;
        totweight+=weight[i]=tmp.second;
        setvw(stk[i],0,0,n-siz[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    for (int i=0;i<cyclelen;++i)
        cycleans[i]+=totweight-weight[i];
    for (int i=cyclelen;i<cyclelen+cyclelen;++i)
    {
        edgew[i]=edgew[i-cyclelen];
        siz[i]=siz[i-cyclelen];
    }
    for (int i=1;i<cyclelen+cyclelen;++i)
    {
        edgew[i]+=edgew[i-1];
        siz[i]+=siz[i-1];
    }
    long long sum1=0,sum2=0;
    int pos=0;
    for (int i=1;i<cyclelen;++i)
        sum2+=(long long)(edgew[cyclelen-1]-edgew[i-1])*(siz[i]-siz[i-1]);
    for (int i=0;;)
    {
        while (pos+1<i+cyclelen&&edgew[i+cyclelen-1]-edgew[pos]>edgew[pos]-(i?edgew[i-1]:0))
        {
            sum1+=(long long)(edgew[pos]-(i?edgew[i-1]:0))*(siz[pos+1]-siz[pos]);
            sum2-=(long long)(edgew[i+cyclelen-1]-edgew[pos])*(siz[pos+1]-siz[pos]);
            ++pos;
        }
        cycleans[i]+=sum1+sum2;
        if (i==cyclelen-1)
            break;
        if (pos==i)
        {
            sum1+=(long long)(edgew[pos]-(i?edgew[i-1]:0))*(siz[pos+1]-siz[pos]);
            sum2-=(long long)(edgew[i+cyclelen-1]-edgew[pos])*(siz[pos+1]-siz[pos]);
            ++pos;
        }
        sum1-=(edgew[i]-(i?edgew[i-1]:0))*(siz[pos]-siz[i]);
        sum2+=(edgew[i]-(i?edgew[i-1]:0))*(siz[i+cyclelen]-siz[pos]);
        ++i;
    }
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        subtree_add(stk[i],0,cycleans[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    for (int i=1;i<=n;++i)
        printf("%lld ",ans[i]);
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
vector<pair<int,int>> mp[200001];
int stk[200001],vst[200001],edgew[400001];
pair<int,int> dfs(int k,int p,int curd)
{
    vst[k]=curd;
    stk[curd]=k;
    for (auto c:mp[k])
        if (c.first!=p)
        {
            edgew[curd]=c.second;
            if (vst[c.first])
                return make_pair(vst[c.first],curd);
            pair<int,int> res=dfs(c.first,k,curd+1);
            if (res.first)
                return res;
        }
    vst[k]=0;
    return make_pair(0,0);
}
bool used[200001],ban[200001];
int sts[200001];
void calcsts(int k,int p)
{
    sts[k]=1;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
        {
            calcsts(c.first,k);
            sts[k]+=sts[c.first];
        }
}
void gotov(int &k,int numv)
{
    int p=-1;
    while (true)
    {
        bool f=false;
        for (auto c:mp[k])
            if (c.first!=p&&!used[c.first]&&!ban[c.first]&&sts[c.first]>numv/2)
            {
                f=true;
                p=k;
                k=c.first;
                break;
            }
        if (!f)
            return;
    }
}
pair<int,long long> traverse(int k,int p)
{
    int ret1=1;
    long long ret2=0;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
        {
            pair<int,long long> res=traverse(c.first,k);
            ret1+=res.first;
            ret2+=res.second+c.second*res.first;
        }
    return make_pair(ret1,ret2);
}
long long ans[200001],weight[200001];
int siz[400001];
void subtree_add(int k,int p,long long val)
{
    ans[k]+=val;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
            subtree_add(c.first,k,val);
}
void setvw(int k,int p,int val,int siz)
{
    ans[k]+=(long long)val*siz;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
            setvw(c.first,k,val+c.second,siz);
}
void gravity(int k)
{
    calcsts(k,0);
    gotov(k,sts[k]);
    used[k]=true;
    int idx=0,totsiz=1;
    long long totval=0;
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
        {
            ++idx;
            pair<int,long long> res=traverse(c.first,0);
            siz[idx]=res.first;
            res.second+=c.second*res.first;
            weight[idx]=res.second;
            totval+=res.second;
            totsiz+=res.first;
        }
    ans[k]+=totval;
    idx=0;
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
        {
            ++idx;
            subtree_add(c.first,0,totval-weight[idx]+c.second*(totsiz-siz[idx]));
        }
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
            gravity(c.first);
}
long long cycleans[200001];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        int a,b,t;
        scanf("%d%d%d",&a,&b,&t);
        mp[a].push_back(make_pair(b,t));
        mp[b].push_back(make_pair(a,t));
    }
    pair<int,int> tmp=dfs(1,0,1);
    for (int i=tmp.first;i<=tmp.second;++i)
    {
        stk[i-tmp.first]=stk[i];
        edgew[i-tmp.first]=edgew[i];
    }
    int cyclelen=tmp.second-tmp.first+1;
    long long totweight=0;
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        gravity(stk[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    memset(used,0,sizeof(used));
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        pair<int,long long> tmp=traverse(stk[i],0);
        siz[i]=tmp.first;
        totweight+=weight[i]=tmp.second;
        setvw(stk[i],0,0,n-siz[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    for (int i=0;i<cyclelen;++i)
        cycleans[i]+=totweight-weight[i];
    for (int i=cyclelen;i<cyclelen+cyclelen;++i)
    {
        edgew[i]=edgew[i-cyclelen];
        siz[i]=siz[i-cyclelen];
    }
    for (int i=1;i<cyclelen+cyclelen;++i)
    {
        edgew[i]+=edgew[i-1];
        siz[i]+=siz[i-1];
    }
    long long sum1=0,sum2=0;
    int pos=0;
    for (int i=1;i<cyclelen;++i)
        sum2+=(long long)(edgew[cyclelen-1]-edgew[i-1])*(siz[i]-(i?siz[i-1]:0));
    for (int i=0;;)
    {
        while (pos+1<i+cyclelen&&edgew[i+cyclelen-1]-edgew[pos]>edgew[pos]-edgew[i-1])
        {
            sum1+=(long long)(edgew[pos]-(i?edgew[i-1]:0))*(siz[pos+1]-siz[pos]);
            sum2-=(long long)(edgew[i+cyclelen-1]-edgew[pos])*(siz[pos+1]-siz[pos]);
            ++pos;
        }
        cycleans[i]+=sum1+sum2;
        if (i==cyclelen-1)
            break;
        if (pos==i)
        {
            sum1+=(long long)(edgew[pos]-(i?edgew[i-1]:0))*(siz[pos+1]-siz[pos]);
            sum2-=(long long)(edgew[i+cyclelen-1]-edgew[pos])*(siz[pos+1]-siz[pos]);
            ++pos;
        }
        sum1-=(edgew[i]-(i?edgew[i-1]:0))*(siz[pos]-siz[i]);
        sum2+=(edgew[i]-(i?edgew[i-1]:0))*(siz[i+cyclelen]-siz[pos]);
        ++i;
    }
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        subtree_add(stk[i],0,cycleans[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    for (int i=1;i<=n;++i)
        printf("%lld ",ans[i]);
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
vector<pair<int,int>> mp[200001];
int stk[200001],vst[200001],edgew[400001];
pair<int,int> dfs(int k,int p,int curd)
{
    vst[k]=curd;
    stk[curd]=k;
    for (auto c:mp[k])
        if (c.first!=p)
        {
            edgew[curd]=c.second;
            if (vst[c.first])
                return make_pair(vst[c.first],curd);
            pair<int,int> res=dfs(c.first,k,curd+1);
            if (res.first)
                return res;
        }
    vst[k]=0;
    return make_pair(0,0);
}
bool ban[200001];
int sts[200001];
pair<int,long long> traverse(int k,int p)
{
    int ret1=1;
    long long ret2=0;
    for (auto c:mp[k])
        if (c.first!=p&&!ban[c.first])
        {
            pair<int,long long> res=traverse(c.first,k);
            ret1+=res.first;
            ret2+=res.second+c.second*res.first;
        }
    return make_pair(ret1,ret2);
}
long long ans[200001],weight[200001];
int siz[400001];
void subtree_add(int k,int p,long long val)
{
    ans[k]+=val;
    for (auto c:mp[k])
        if (c.first!=p&&!ban[c.first])
            subtree_add(c.first,k,val);
}
void setvw(int k,int p,int val,int siz)
{
    ans[k]+=(long long)val*siz;
    for (auto c:mp[k])
        if (c.first!=p&&!ban[c.first])
            setvw(c.first,k,val+c.second,siz);
}
void traverse2(int k,int p)
{
    siz[k]=1;
    weight[k]=0;
    for (auto c:mp[k])
        if (c.first!=p&&!ban[c.first])
        {
            traverse2(c.first,k);
            siz[k]+=siz[c.first];
            weight[k]+=weight[c.first]+c.second*siz[c.first];
        }
}
void down_propgate(int k,int p,int num)
{
    if (p)
        ans[k]+=ans[p];
    for (auto c:mp[k])
        if (c.first!=p&&!ban[c.first])
        {
            ans[c.first]=weight[k]-(weight[c.first]+c.second*siz[c.first])+(num-siz[c.first])*c.second;
            if (c.first!=p&&!ban[c.first])
                down_propgate(c.first,k,num);
        }
    ans[k]+=weight[k];
}
long long cycleans[200001];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        int a,b,t;
        scanf("%d%d%d",&a,&b,&t);
        mp[a].push_back(make_pair(b,t));
        mp[b].push_back(make_pair(a,t));
    }
    pair<int,int> tmp=dfs(1,0,1);
    for (int i=tmp.first;i<=tmp.second;++i)
    {
        stk[i-tmp.first]=stk[i];
        edgew[i-tmp.first]=edgew[i];
    }
    int cyclelen=tmp.second-tmp.first+1;
    long long totweight=0;
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        traverse2(stk[i],0);
        down_propgate(stk[i],0,siz[stk[i]]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        pair<int,long long> tmp=traverse(stk[i],0);
        siz[i]=tmp.first;
        totweight+=weight[i]=tmp.second;
        setvw(stk[i],0,0,n-siz[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    for (int i=0;i<cyclelen;++i)
        cycleans[i]+=totweight-weight[i];
    for (int i=cyclelen;i<cyclelen+cyclelen;++i)
    {
        edgew[i]=edgew[i-cyclelen];
        siz[i]=siz[i-cyclelen];
    }
    for (int i=1;i<cyclelen+cyclelen;++i)
    {
        edgew[i]+=edgew[i-1];
        siz[i]+=siz[i-1];
    }
    long long sum1=0,sum2=0;
    int pos=0;
    for (int i=1;i<cyclelen;++i)
        sum2+=(long long)(edgew[cyclelen-1]-edgew[i-1])*(siz[i]-siz[i-1]);
    for (int i=0;;)
    {
        while (pos+1<i+cyclelen&&edgew[i+cyclelen-1]-edgew[pos]>edgew[pos]-(i?edgew[i-1]:0))
        {
            sum1+=(long long)(edgew[pos]-(i?edgew[i-1]:0))*(siz[pos+1]-siz[pos]);
            sum2-=(long long)(edgew[i+cyclelen-1]-edgew[pos])*(siz[pos+1]-siz[pos]);
            ++pos;
        }
        cycleans[i]+=sum1+sum2;
        if (i==cyclelen-1)
            break;
        if (pos==i)
        {
            sum1+=(long long)(edgew[pos]-(i?edgew[i-1]:0))*(siz[pos+1]-siz[pos]);
            sum2-=(long long)(edgew[i+cyclelen-1]-edgew[pos])*(siz[pos+1]-siz[pos]);
            ++pos;
        }
        sum1-=(edgew[i]-(i?edgew[i-1]:0))*(siz[pos]-siz[i]);
        sum2+=(edgew[i]-(i?edgew[i-1]:0))*(siz[i+cyclelen]-siz[pos]);
        ++i;
    }
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        subtree_add(stk[i],0,cycleans[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    for (int i=1;i<=n;++i)
        printf("%lld ",ans[i]);
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
vector<pair<int,int>> mp[200001];
int stk[200001],vst[200001],edgew[400001];
pair<int,int> dfs(int k,int p,int curd)
{
    vst[k]=curd;
    stk[curd]=k;
    for (auto c:mp[k])
        if (c.first!=p)
        {
            edgew[curd]=c.second;
            if (vst[c.first])
                return make_pair(vst[c.first],curd);
            pair<int,int> res=dfs(c.first,k,curd+1);
            if (res.first)
                return res;
        }
    vst[k]=0;
    return make_pair(0,0);
}
bool used[200001],ban[200001];
int sts[200001];
void calcsts(int k,int p)
{
    sts[k]=1;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
        {
            calcsts(c.first,k);
            sts[k]+=sts[c.first];
        }
}
void gotov(int &k,int numv)
{
    int p=-1;
    while (true)
    {
        bool f=false;
        for (auto c:mp[k])
            if (c.first!=p&&!used[c.first]&&!ban[c.first]&&sts[c.first]>numv/2)
            {
                f=true;
                p=k;
                k=c.first;
                break;
            }
        if (!f)
            return;
    }
}
pair<int,long long> traverse(int k,int p)
{
    int ret1=1;
    long long ret2=0;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
        {
            pair<int,long long> res=traverse(c.first,k);
            ret1+=res.first;
            ret2+=res.second+c.second*res.first;
        }
    return make_pair(ret1,ret2);
}
long long ans[200001],weight[200001];
int siz[200001];
void subtree_add(int k,int p,long long val)
{
    ans[k]+=val;
    for (auto c:mp[k])
        if (c.first!=p&&!used[c.first]&&!ban[c.first])
            subtree_add(c.first,k,val);
}
void gravity(int k)
{
    calcsts(k,0);
    gotov(k,sts[k]);
    used[k]=true;
    int idx=0,totsiz=1;
    long long totval=0;
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
        {
            ++idx;
            pair<int,long long> res=traverse(c.first,0);
            siz[idx]=res.first;
            res.second+=c.second*res.first;
            weight[idx]=res.second;
            totval+=res.second;
            totsiz+=res.first;
        }
    idx=0;
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
        {
            ++idx;
            subtree_add(c.first,0,totval-weight[idx]+c.second*(totsiz-siz[idx]));
        }
    for (auto c:mp[k])
        if (!used[c.first]&&!ban[c.first])
            gravity(c.first);
}
long long cycleans[200001];
int main()
{
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        int a,b,t;
        scanf("%d%d%d",&a,&b,&t);
        mp[a].push_back(make_pair(b,t));
        mp[b].push_back(make_pair(a,t));
    }
    pair<int,int> tmp=dfs(1,0,1);
    for (int i=tmp.first;i<=tmp.second;++i)
    {
        stk[i-tmp.first]=stk[i];
        edgew[i-tmp.first]=edgew[i];
    }
    int cyclelen=tmp.second-tmp.first+1;
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        gravity(stk[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    long long totweight=0;
    for (int i=0;i<cyclelen;++i)
        totweight+=weight[i]=traverse(stk[i],0).second;
    for (int i=0;i<cyclelen;++i)
        cycleans[i]+=totweight-weight[i];
    for (int i=cyclelen;i<cyclelen+cyclelen;++i)
        edgew[i]=edgew[i-cyclelen];
    for (int i=1;i<cyclelen+cyclelen;++i)
        edgew[i]+=edgew[i-1];
    long long sum1=0,sum2=0;
    int pos=0;
    for (int i=1;i<cyclelen;++i)
        sum2+=edgew[cyclelen-1]-edgew[i-1];
    for (int i=0;;)
    {
        while (pos+1<i+cyclelen&&edgew[i+cyclelen-1]-edgew[pos]>edgew[pos]-edgew[i-1])
        {
            sum1+=edgew[pos]-edgew[i-1];
            sum2-=edgew[i+cyclelen-1]-edgew[pos];
            ++pos;
        }
        cycleans[i]+=sum1+sum2;
        if (i==cyclelen-1)
            break;
        if (pos==i)
        {
            sum1+=edgew[pos]-edgew[i-1];
            sum2-=edgew[i+cyclelen-1]-edgew[pos];
            ++pos;
        }
        sum1-=(edgew[i]-(i?edgew[i-1]:0))*(pos-i);
        sum2+=(edgew[i]-(i?edgew[i-1]:0))*(i+cyclelen-pos);
        ++i;
    }
    memset(used,0,sizeof(used));
    for (int i=0;i<cyclelen;++i)
    {
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=true;
        subtree_add(stk[i],0,cycleans[i]);
        ((i+1)%cyclelen)[stk][ban]=((i+cyclelen-1)%cyclelen)[stk][ban]=false;
    }
    for (int i=1;i<=n;++i)
        printf("%lld ",ans[i]);
    printf("\n");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
typedef long long ll;
#define MAX 200005
using namespace std;
int n,m,k;
#define INF 2147483//2147483647
#define G 9.8
bool debug = false;

int W;
struct root {
    int id;
    ll edge, ss;
    vector<int> subNodes;
};
vector<pair<int, ll>> mp[MAX];
vector<root> rs;
int v[MAX];
int cpoint[MAX];
ll sumNode[MAX], countNode[MAX], dd[MAX], toOtherFromFAther[MAX], ans[MAX];
root *rr;
int findCircle(int i, int p) {
    if (v[i]) return i;
    v[i]=1;
    for (vector<pair<int, ll>>::iterator it=mp[i].begin(); it!=mp[i].end(); it++) {
        int w = it->first;
        if (w == p) continue;
        int t = findCircle(w,i);
        if ( t!= -1) {
            cpoint[w] = 1;
            root r; r.id=w; r.edge=it->second; rs.push_back(r);
            return t == i ? -1 : t; // otherwise first circle node's father will be added
        }
    }
    return -1;
}
void dfs(int i, int p) {
    rr->subNodes.push_back(i);
    sumNode[i]=0;
    countNode[i]=1;
    for (vector<pair<int, ll>>::iterator it=mp[i].begin(); it!=mp[i].end(); it++) {
        int w = it->first;
        if (w == p || cpoint[w]) continue;
        dd[w] += dd[i] + it->second;
        dfs(w, i);
        countNode[i] += countNode[w];
        sumNode[i] += sumNode[w] + it->second * countNode[w];
    }
}
void dfs1(int i, int p) {
    for (vector<pair<int, ll>>::iterator it=mp[i].begin(); it!=mp[i].end(); it++) {
        int w = it->first;
        if (w == p || cpoint[w]) continue;

        toOtherFromFAther[w] = toOtherFromFAther[i] + sumNode[i] - sumNode[w] - it->second * countNode[w] + it->second * (countNode[rr->id]-countNode[w]);
        dfs1(w, i);
    }
}
void calTree(int i) {
    rr = &rs[i];
    dd[rr->id]=0;
    dfs(rr->id, -1);
    toOtherFromFAther[rr->id]=0;
    dfs1(rr->id, -1);
    for (vector<int>::iterator it=rr->subNodes.begin(); it!=rr->subNodes.end(); it++) {
        ans[*it] = sumNode[*it] + toOtherFromFAther[*it];
    }
    rr->ss = ans[rr->id];
}
void calCircle() {
    ll cursum=0, cnt=0, cirlen = 0, sum=0;
    int q = 0;
    ll ee[MAX+MAX];
    for (int i=0;i<m;i++) {
        cirlen += rs[i].edge;
        sum += rs[i].ss;
        ee[i+1+m] = ee[i+1] = rs[i].edge;
    }
    ee[0] = 0;
    partial_sum(ee, ee+m+m+1, ee);
    while (2*(ee[q]-ee[0]) <= cirlen ) {
        cursum += (ee[q]-ee[0])* countNode[rs[q].id];
        cnt += countNode[rs[q].id];
        q++;
    }
    for (int i=q; i<m; i++) {
        cursum += (cirlen - (ee[i]-ee[0]))*countNode[rs[i].id];
    }
    for (int i=0;i<m;i++) {
        while(2*(ee[q]-ee[i]) <= cirlen ) {
            cursum = cursum - (cirlen - (ee[q]-ee[i]))*countNode[rs[q%m].id] + (ee[q]-ee[i])*countNode[rs[q%m].id];
            cnt+=countNode[rs[q%m].id];
            q++;
        }
        for (vector<int>::iterator it=rs[i].subNodes.begin(); it!=rs[i].subNodes.end();it++) {
            ans[*it] += sum - rs[i].ss + cursum + dd[*it] * (n - countNode[rs[i].id]);
        }
        cnt -= countNode[rs[i].id];
        cursum += (n-cnt) * rs[i].edge;
        cursum -= cnt * rs[i].edge;
    }
}
int main()
{
    scanf("%d", &n);
    int a,b,t;

    for (int i=0; i<n; i++) {
        scanf("%d%d%d", &a,&b,&t); a--; b--;
        mp[a].push_back(make_pair(b, t));
        mp[b].push_back(make_pair(a, t));
    }
    findCircle(0, -1);
    m = (int)rs.size();
    for (int i=0;i<m;i++) {
        calTree(i);
    }
    calCircle();

    for(int i=0;i<n;i++) {
        printf("%I64d ", ans[i]);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int,int> > v[200010];
int fa[200010],w[400010];
bool vis[200010];
vector<int> cycle;
int n,siz[200010];
bool oncycle[200010];
ll buf0[400010],buf1[400010],buf2[400010];
ll ans[200010],*sums=buf0+1,*sumw=buf1+1,*sum=buf2+1;
bool dfs1(int np,int fath)
{
	vis[np]=1;
	fa[np]=fath;
	for(auto &x:v[np])
	{
		if(x.first==fath)continue;
		if(vis[x.first])
		{
			int p=np;
			while(p!=x.first)cycle.push_back(p),p=fa[p];
			cycle.push_back(x.first);
			return 1;
		}
		else if(dfs1(x.first,np))return 1;
	}
	return 0;
}
void dfs2(int np,int fath)
{
	siz[np]=1;
	for(auto &x:v[np])
	{
		if(x.first==fath||oncycle[x.first])continue;
		dfs2(x.first,np);
		siz[np]+=siz[x.first];
		ans[np]+=ans[x.first]+x.second*siz[x.first];
	}
}
void dfs3(int np,int fath)
{
	for(auto &x:v[np])
	{
		if(x.first==fath||oncycle[x.first])continue;
		ans[x.first]=ans[np]+(n-siz[x.first])*x.second-siz[x.first]*x.second;
		dfs3(x.first,np);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1,ti,tj,tk;i<=n;i++)
	{
		scanf("%d%d%d",&ti,&tj,&tk);
		v[ti].push_back(make_pair(tj,tk));
		v[tj].push_back(make_pair(ti,tk));
	}
	dfs1(1,0);
	for(auto &x:cycle)oncycle[x]=1;
	for(auto &x:cycle)dfs2(x,0);
	int csiz=cycle.size();
	cycle.insert(cycle.end(),cycle.begin(),cycle.end());
	ll tot=0;
	for(int i=0;i<csiz;i++)
	{
		int nxt=cycle[i+1],cur=cycle[i];
		tot+=ans[cycle[i]];
		for(auto &x:v[cur])
		{
			if(x.first==nxt)
			{
				w[csiz+i]=w[i]=x.second;
				break;
			}
		}
	}
	sums[0]=siz[cycle[0]];
	sumw[0]=w[0];
	sum[0]=sums[0]*w[0];
	for(int i=1;i<csiz<<1;i++)
	{
		sums[i]=sums[i-1]+siz[cycle[i]];
		sumw[i]=sumw[i-1]+w[i];
		sum[i]=sum[i-1]+w[i]*sums[i];
	}
	for(int l=0,r=0;l<=csiz;l++)
	{
		while(sumw[r]-sumw[l-1]<=(sumw[csiz-1]>>1))++r;
		ans[cycle[l]]=tot+sums[r]*(sumw[r-1]-sumw[l-1])-(sum[r-1]-sum[l-1])
		+(sum[l+csiz-1]-sum[r])-sums[r]*(sumw[l+csiz-1]-sumw[r]);
		dfs3(cycle[l],0);
	}
	for(int i=1;i<=n;i++)printf("%lld ",ans[i]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int,int> > v[200010];
int fa[200010],w[400010];
bool vis[200010];
vector<int> cycle;
int n,siz[200010];
bool oncycle[200010];
ll buf0[400010],buf1[400010],buf2[400010];
ll ans[200010],*sums=buf0+1,*sumw=buf1+1,*sum=buf2+1;
bool dfs1(int np,int fath)
{
	vis[np]=1;
	fa[np]=fath;
	for(auto &x:v[np])
	{
		if(x.first==fath)continue;
		if(vis[x.first])
		{
			int p=np;
			while(p!=x.first)cycle.push_back(p),p=fa[p];
			cycle.push_back(x.first);
			return 1;
		}
		else if(dfs1(x.first,np))return 1;
	}
	return 0;
}
void dfs2(int np,int fath)
{
	siz[np]=1;
	for(auto &x:v[np])
	{
		if(x.first==fath||oncycle[x.first])continue;
		dfs2(x.first,np);
		siz[np]+=siz[x.first];
		ans[np]+=ans[x.first]+x.second*siz[x.first];
	}
}
void dfs3(int np,int fath)
{
	for(auto &x:v[np])
	{
		if(x.first==fath||oncycle[x.first])continue;
		ans[x.first]=ans[np]+(n-siz[np])*x.second-siz[np]*x.first;
		dfs3(x.first,np);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1,ti,tj,tk;i<=n;i++)
	{
		scanf("%d%d%d",&ti,&tj,&tk);
		v[ti].push_back(make_pair(tj,tk));
		v[tj].push_back(make_pair(ti,tk));
	}
	dfs1(1,0);
	for(auto &x:cycle)oncycle[x]=1;
	for(auto &x:cycle)dfs2(x,0);
	int csiz=cycle.size();
	cycle.insert(cycle.end(),cycle.begin(),cycle.end());
	ll tot=0;
	for(int i=0;i<csiz;i++)
	{
		int nxt=cycle[i+1],cur=cycle[i];
		tot+=ans[cycle[i]];
		for(auto &x:v[cur])
		{
			if(x.first==nxt)
			{
				w[csiz+i]=w[i]=x.second;
				break;
			}
		}
	}
	sums[0]=siz[cycle[0]];
	sumw[0]=w[0];
	sum[0]=sums[0]*w[0];
	for(int i=1;i<csiz<<1;i++)
	{
		sums[i]=sums[i-1]+siz[cycle[i]];
		sumw[i]=sumw[i-1]+w[i];
		sum[i]=sum[i-1]+w[i]*sums[i];
	}
	for(int l=0,r=0;l<=csiz;l++)
	{
		while(sumw[r]-sumw[l-1]<=(sumw[csiz-1]>>1))++r;
		ans[cycle[l]]=tot+sums[r]*(sumw[r-1]-sumw[l-1])-(sum[r-1]-sum[l-1])
		+(sum[l+csiz-1]-sum[r])-sums[r]*(sumw[l+csiz-1]-sumw[r]);
		dfs3(cycle[l],0);
	}
	for(int i=1;i<=n;i++)printf("%lld ",ans[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

#define N 200005

int n;
vi g[N], cost[N];
int siz[N];
ll dis[N], disall[N];
int used[N];
ll ans[N];
int stk[N], tp;
vi c;
int root[N];
ll sum[N + N];
int ccost[N];
ll sum1[N + N], sum2[N + N];
int sumsiz[N + N];
ll Dis[N];
ll sumdisall[N + N];

void dfs1(int u, int p) {
	stk[tp ++] = u;
	used[u] = -1;
	rep(i, g[u].size()) {
		int v = g[u][i];
		if (!~used[v] && v != p) {
			do {
				c.pb(stk[-- tp]);
			} while (stk[tp] != v) ;
		}
		if (used[v]) continue;
		dfs1(v, u);
	}
	used[u] = 1;
	if (tp && stk[tp - 1] == u) -- tp;
}

void dfs2(int u, int p) {
	siz[u] = 1;
	rep(i, g[u].size()) {
		int v = g[u][i], w = cost[u][i];
		if (used[v] || v == p) continue;
		dis[v] = dis[u] + w;
		root[v] = root[u];
		dfs2(v, u);
		siz[u] += siz[v];
		disall[u] += 1LL * w * siz[v] + disall[v];
	}
}

void dfs3(int u, int p, ll D) {
	ll disalll = 0;
	rep(i, g[u].size()) {
		int v = g[u][i], w = cost[u][i];
		if (used[v] || v == p) continue;
		disalll += disall[v] + 1LL * w * siz[v];
	}
	rep(i, g[u].size()) {
		int v = g[u][i], w = cost[u][i];
		if (used[v] || v == p) continue;
		dfs3(v, u, D + 1LL * (siz[c[root[u]]] - siz[v]) * w + disalll - disall[v] - 1LL * w * siz[v]);
	}
	Dis[u] = D + disall[u];
}

int Bin(int i) {
	int lb, rb;
	lb = i, rb = c.size();
	while (lb < rb) {
		int md = (lb + rb + 1) >> 1;
		if (sum[md] - sum[i] > sum[c.size()] - sum[md] + sum[i]) rb = md - 1;
		else lb = md;
	}
	if (lb == c.size()) {
		lb = 0, rb = i;
		while (lb < rb) {
			int md = (lb + rb + 1) >> 1;
			if (sum[i] - sum[md] < sum[c.size()] - sum[i] + sum[md]) rb = md - 1;
			else lb = md;
		}
	}
	return lb;
}

ll Sum1(int l, int r) {
	return sum1[r] - (l ? sum1[l - 1] : 0) - 1LL * (sumsiz[r + 1] - sumsiz[l]) * sum[l];
}

ll Sum2(int l, int r) {
	return sum2[l] - sum2[r + 1] - 1LL * (sumsiz[r + 1] - sumsiz[l]) * (sum[2 * c.size() - 1] - sum[r]);
}

int main() {
	n = read();
	rep(i, n) {
		int u = read() - 1, v = read() - 1, w = read();
		g[u].pb(v), g[v].pb(u);
		cost[u].pb(w), cost[v].pb(w);
	}
	dfs1(0, -1);
//	rep(i, c.size()) eprintf("%d ", c[i] + 1); eprintf("\n");
	memset(used, 0, sizeof used);
	rep(i, c.size()) {
		rep(j, g[c[i]].size()) {
			if (g[c[i]][j] == c[(i + 1) % (int) c.size()]) {
				ccost[i] = cost[c[i]][j];
			}
		}
	}
	rep(i, c.size() * 2) sum[i + 1] = sum[i] + ccost[i % c.size()];
	rep(i, c.size()) {
		used[c[i]] = 1;
		root[c[i]] = i;
	}
	rep(i, c.size()) dfs2(c[i], -1);
	rep(i, c.size()) dfs3(c[i], -1, 0);
	rep(i, c.size() * 2) sumsiz[i + 1] = sumsiz[i] + siz[c[i % c.size()]];
	rep(i, c.size() * 2) sumdisall[i + 1] = sumdisall[i] + disall[c[i % c.size()]];
	sum1[0] = disall[c[0]];
	rep(i, c.size() * 2) if (i) sum1[i] = sum1[i - 1] + 1LL * sum[i] * siz[c[i % c.size()]] + disall[c[i % c.size()]];
	sum2[c.size() * 2 - 1] = disall[c[c.size() - 1]];
	for (int i = c.size() * 2 - 2; ~i; -- i) sum2[i] = sum2[i + 1] + 1LL * (sum[c.size() * 2 - 1] - sum[i]) * siz[c[i % c.size()]] + disall[c[i % c.size()]];
	rep(i, c.size()) {
		int u = c[i], j = Bin(i);
		ans[c[i]] += Sum1(i, j < i ? j + c.size() : j);
		ans[c[i]] += Sum2(j + 1, i < j + 1 ? i + c.size() : i);
		ans[c[i]] -= disall[c[i]];
	}
	rep(i, n) if (!ans[i]) {
		ans[i] = ans[c[root[i]]] - disall[c[root[i]]] + 1LL * (n - siz[c[root[i]]]) * dis[i] + Dis[i];
	}
	rep(i, n) printf("%lld", ans[i]), putchar(i + 1 == n ? 10 : 32);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

#define N 200005

int n;
vi g[N], cost[N];
int siz[N];
ll dis[N], disall[N];
int used[N];
ll ans[N];
int stk[N], tp;
vi c;
int root[N];
ll sum[N + N];
int ccost[N];
ll sum1[N + N], sum2[N + N];
int sumsiz[N + N];
ll Dis[N];
ll sumdisall[N + N];

void dfs1(int u, int p) {
	stk[tp ++] = u;
	used[u] = -1;
	rep(i, g[u].size()) {
		int v = g[u][i];
		if (!~used[v] && v != p) {
			do {
				c.pb(stk[-- tp]);
			} while (stk[tp] != v) ;
		}
		if (used[v]) continue;
		dfs1(v, u);
	}
	used[u] = 1;
}

void dfs2(int u, int p) {
	siz[u] = 1;
	rep(i, g[u].size()) {
		int v = g[u][i], w = cost[u][i];
		if (used[v] || v == p) continue;
		dis[v] = dis[u] + w;
		root[v] = root[u];
		dfs2(v, u);
		siz[u] += siz[v];
		disall[u] += 1LL * w * siz[v] + disall[v];
	}
}

void dfs3(int u, int p, ll D) {
	rep(i, g[u].size()) {
		int v = g[u][i], w = cost[u][i];
		if (used[v] || v == p) continue;
		dfs3(v, u, D + 1LL * (siz[c[root[u]]] - siz[u]) * w);
	}
	Dis[u] = D + disall[u];
}

int Bin(int i) {
	int lb, rb;
	lb = i, rb = c.size();
	while (lb < rb) {
		int md = (lb + rb + 1) >> 1;
		if (sum[md] - sum[i] > sum[c.size()] - sum[md] + sum[i]) rb = md - 1;
		else lb = md;
	}
	if (lb == c.size()) {
		lb = 0, rb = i;
		while (lb < rb) {
			int md = (lb + rb + 1) >> 1;
			if (sum[i] - sum[md] < sum[c.size()] - sum[i] + sum[md]) rb = md - 1;
			else lb = md;
		}
	}
	return lb;
}

ll Sum1(int l, int r) {
	return sum1[r] - sum1[l - 1] - 1LL * (sumsiz[r + 1] - sumsiz[l]) * sum[l];
}

ll Sum2(int l, int r) {
	return sum2[l] - sum2[r + 1] - 1LL * (sumsiz[r + 1] - sumsiz[l]) * (sum[2 * c.size() - 1] - sum[r]);
}

int main() {
	n = read();
	rep(i, n) {
		int u = read() - 1, v = read() - 1, w = read();
		g[u].pb(v), g[v].pb(u);
		cost[u].pb(w), cost[v].pb(w);
	}
	dfs1(0, -1);
	memset(used, 0, sizeof used);
	rep(i, c.size()) {
		rep(j, g[c[i]].size()) {
			if (g[c[i]][j] == c[(i + 1) % (int) c.size()]) {
				ccost[i] = cost[c[i]][j];
			}
		}
	}
	rep(i, c.size() * 2) sum[i + 1] = sum[i] + ccost[i % c.size()];
	rep(i, c.size()) {
		used[c[i]] = 1;
		root[c[i]] = i;
	}
	rep(i, c.size()) dfs2(c[i], -1);
	rep(i, c.size()) dfs3(c[i], -1, 0);
	rep(i, c.size() * 2) sumsiz[i + 1] = sumsiz[i] + siz[c[i % c.size()]];
	rep(i, c.size() * 2) sumdisall[i + 1] = sumdisall[i] + disall[c[i % c.size()]];
	rep(i, c.size() * 2) if (i) sum1[i] = sum1[i - 1] + 1LL * sum[i] * siz[c[i % c.size()]] + disall[c[i % c.size()]];
	for (int i = c.size() * 2 - 2; ~i; -- i) sum2[i] = sum2[i + 1] + 1LL * (sum[c.size() * 2 - 1] - sum[i]) * siz[c[i % c.size()]] + disall[c[i % c.size()]];
	rep(i, c.size()) {
		int u = c[i], j = Bin(i);
		ans[c[i]] += Sum1(i, j < i ? j + c.size() : j);
		ans[c[i]] += Sum2(j + 1, i < j + 1 ? i + c.size() : i);
	}
	rep(i, n) if (!ans[i]) {
		ans[i] = ans[c[root[i]]] + 1LL * (n - siz[c[root[i]]]) * dis[i] + Dis[i];
	}
	rep(i, n) printf("%lld", ans[i]), putchar(i + 1 == n ? 10 : 32);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//万合以致，向阳而生——背叛时代，忠于时间//
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define mid l+r>>1
#define lid id<<1|1
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r

inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=200005;

int N, ptr, ptrl, ptrr, vis[MAX], onc[MAX], sz[MAX], id[MAX*2];
ll tot, tot2, costl, costr, dp1[MAX], dp2[MAX], val[MAX*2], sum[MAX*2];
vi cycle;
vector<pi> e[MAX];
stack<int> S;

inline void pre(int x, int p)
{
//    cout<<x<<endl;
    vis[x]=1;
    S.push(x);
    foreach(it, e[x]) if(it->f!=p)
    {
        if(!vis[it->f]) pre(it->f, x);
        else if(vis[it->f]==1)
        {
            while(S.size()&&S.top()!=it->f)
            {
                cycle.pb(S.top());
                onc[S.top()]=1;
                S.pop();
            }
            if(S.size()) cycle.pb(S.top()), onc[S.top()]=1, S.pop();
        }
    }
    if(S.size()&&S.top()==x) S.pop();
    vis[x]=2;
}

inline void dfs1(int x, int p, int c)
{
//    cout<<x<<" "<<c<<endl;
    tot+=c;
    val[++ptr]=c, id[ptr]=x;
    foreach(it, e[x]) if(it->f!=p&&onc[it->f]&&!vis[it->f])
        vis[it->f]=1, dfs1(it->f, x, it->s);
}

inline void dfs2(int x, int p, int c)
{
    sz[x]=1;
    foreach(it, e[x]) if(it->f!=p&&!onc[it->f])
        dfs2(it->f, x, it->s),
        sz[x]+=sz[it->f],
        dp1[x]+=dp1[it->f]+1LL*it->s*sz[it->f];
}

inline ll get(ll *dat, int l, int r)
{
    if(r<l) swap(r, l);
    return dat[r]-dat[l];
}

inline void dfs(int x, int p, int c)
{
    if(p)
    {
        ll tmp=dp1[p]-1LL*sz[x]*c-dp1[x];
        dp2[x]=dp2[p]+1LL*c*(N-sz[x])+tmp;
    }
    foreach(it, e[x]) if(it->f!=p&&!onc[it->f])
        dfs(it->f, x, it->s);
}

int main()
{
    N=in();
    Forn(i, N)
    {
        int a=in(), b=in(), c=in();
        e[a].pb(mp(b, c));
        e[b].pb(mp(a, c));
    }
    pre(1, 0);
    memset(vis, 0, sizeof(vis));
    id[0]=cycle.back();
    dfs1(cycle.back(), 0, 0);
    foreach(it, cycle) dfs2(*it, 0, 0);
    Forn(i, ptr) sum[i]=sz[id[i]], tot2+=dp1[id[i]];//, cout<<val[i]<<" "<<sum[i]<<" "<<id[i]<<endl;
    tot2-=dp1[id[1]];
    for(int i=ptr+1; i<=ptr*2; i++)
        id[i]=id[i-ptr+1], val[i]=val[i-ptr+1], sum[i]=sum[i-ptr+1];
    Forn(i, ptr*2) val[i]+=val[i-1], sum[i]+=sum[i-1];

    ptrl=1;
    while(ptrl+1<=ptr*2&&get(val, 1, ptrl+1)<=tot/2)
        ptrl++, dp2[id[1]]+=1LL*get(val, 1, ptrl)*sz[id[ptrl]];
    costl=dp2[id[1]];
    for(int i=ptrl+1; i<ptr; i++)
        costr+=1LL*get(val, i, ptr)*sz[id[i]];
    dp2[id[1]]+=costr+tot2-dp1[id[1]];
    for(int k=2; k<ptr; k++)
    {
        int id=::id[k], lst=ptrl;
        costl-=1LL*get(val, k-1, k)*get(sum, k-1, ptrl);
        costr+=1LL*get(val, k+ptr-2, k+ptr-1)*get(sum, ptrl, k+ptr-2);
        while(ptrl+1<=ptr*2&&get(val, k, ptrl+1)<=tot/2)
        {
            ptrl++, costl+=1LL*get(val, k, ptrl)*sz[::id[ptrl]];
                    costr-=1LL*get(val, ptrl, ptr+k-1)*sz[::id[ptrl]];
        }
        dp2[id]=costl+costr+tot2-dp1[id];
    }
    foreach(it, cycle) dfs(*it, 0, 0);
    Forn(i, N) printf("%lld ", dp2[i]+dp1[i]);
    return 0;
}
// 1__2__3__1__2__3__1
//  3  2  1  3  2  1


#include<bits/stdc++.h>
using namespace std;
//万合以致，向阳而生——背叛时代，忠于时间//
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define mid l+r>>1
#define lid id<<1|1
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r

inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=200005;

int N, ptr, ptrl, ptrr, vis[MAX], onc[MAX], sz[MAX], id[MAX*2], par[MAX];
ll tot, tot2, costl, costr, dp1[MAX], dp2[MAX], val[MAX*2], from_root[MAX], sum[MAX*2];
vi cycle;
vector<pi> e[MAX];
stack<int> S;

inline void pre(int x, int p)
{
//    cout<<x<<endl;
    vis[x]=1;
    S.push(x);
    foreach(it, e[x]) if(it->f!=p)
    {
        if(!vis[it->f]) pre(it->f, x);
        else if(vis[it->f]==1)
        {
            while(S.size()&&S.top()!=it->f)
            {
                cycle.pb(S.top());
                onc[S.top()]=1;
                S.pop();
            }
            if(S.size()) cycle.pb(S.top()), onc[S.top()]=1, S.pop();
        }
    }
    if(S.size()&&S.top()==x) S.pop();
    vis[x]=2;
}

inline void dfs1(int x, int p, int c)
{
//    cout<<x<<" "<<c<<endl;
    tot+=c;
    val[++ptr]=c, id[ptr]=x;
    foreach(it, e[x]) if(it->f!=p&&onc[it->f]&&!vis[it->f])
        vis[it->f]=1, dfs1(it->f, x, it->s);
}

inline void dfs2(int x, int p, int c)
{
    from_root[x]=from_root[p]+c;
    par[x]=p;
    sz[x]=1;
    foreach(it, e[x]) if(it->f!=p&&!onc[it->f])
        dfs2(it->f, x, it->s),
        sz[x]+=sz[it->f],
        dp1[x]+=dp1[it->f]+1LL*it->s*sz[it->f];
}

inline ll get(ll *dat, int l, int r)
{
    if(r<l) swap(r, l);
    return dat[r]-dat[l];
}

inline void dfs(int x, int p, int c)
{
    if(p)
    {
        ll tmp=dp1[p]-1LL*sz[x]*c-dp1[x];
        dp2[x]=dp2[p]+1LL*c*(N-sz[x])+tmp;
    }
    foreach(it, e[x]) if(it->f!=p&&!onc[it->f])
        dfs(it->f, x, it->s);
}

int main()
{
    N=in();
    Forn(i, N)
    {
        int a=in(), b=in(), c=in();
        e[a].pb(mp(b, c));
        e[b].pb(mp(a, c));
    }
    pre(1, 0);
    memset(vis, 0, sizeof(vis));
    id[0]=cycle.back();
    dfs1(cycle.back(), 0, 0);
    foreach(it, cycle) dfs2(*it, 0, 0);
//    Forn(i, N) cout<<dp1[i]<<" ";
//    puts("");
    Forn(i, ptr) sum[i]=sz[id[i]], tot2+=dp1[id[i]];//, cout<<val[i]<<" "<<sum[i]<<" "<<id[i]<<endl;
    tot2-=dp1[id[1]];
    for(int i=ptr+1; i<=ptr*2; i++)
        id[i]=id[i-ptr+1], val[i]=val[i-ptr+1], sum[i]=sum[i-ptr+1];
    Forn(i, ptr*2) val[i]+=val[i-1], sum[i]+=sum[i-1];

    ptrl=1;
    while(ptrl+1<=ptr*2&&get(val, 1, ptrl+1)<=tot/2)
        ptrl++, dp2[id[1]]+=1LL*get(val, 1, ptrl)*sz[id[ptrl]];
    costl=dp2[id[1]];
    for(int i=ptrl+1; i<ptr; i++)
        costr+=1LL*get(val, i, ptr)*sz[id[i]];
    dp2[id[1]]+=costr+tot2-dp1[id[1]];
//    cout<<"tot="<<tot<<endl;
//    puts("");
//    cout<<id[1]<<" "<<costl<<" "<<costr<<endl;
    for(int k=2; k<ptr; k++)
    {
        int id=::id[k], lst=ptrl;
        costl-=1LL*get(val, k-1, k)*get(sum, k-1, ptrl);
        costr+=1LL*get(val, k+ptr-2, k+ptr-1)*get(sum, ptrl, k+ptr-2);
//        cout<<costl<<" "<<costr<<endl;
//        cout<<get(val, k+ptr-2, k+ptr-1)<<" "<<get(sum, ptrl, k+ptr-2)<<endl;
        while(ptrl+1<=ptr*2&&get(val, k, ptrl+1)<=tot/2)
        {
            ptrl++, costl+=1LL*get(val, k, ptrl)*sz[::id[ptrl]];
                    costr-=1LL*get(val, ptrl, ptr+k-1)*sz[::id[ptrl]];
        }
//        cout<<id<<" "<<costl<<" "<<costr<<endl;
        dp2[id]=costl+costr+tot2-dp1[id];
    }
    foreach(it, cycle) dfs(*it, 0, 0);
    Forn(i, N) printf("%lld ", dp2[i]+dp1[i]);
//    puts("");
    return 0;
}
// 1__2__3__1__2__3__1
//  3  2  1  3  2  1


#include<bits/stdc++.h>
using namespace std;
//万合以致，向阳而生——背叛时代，忠于时间//
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define mid l+r>>1
#define lid id<<1|1
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r

inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=200005;

int N, ptr, ptrl, vis[MAX], onc[MAX], sz[MAX], id[MAX*2];
ll tot, tot2, dp1[MAX], dp2[MAX], val[MAX*2], sum[MAX*2];
vi cycle;
vector<pi> e[MAX];
stack<int> S;

inline void pre(int x, int p)
{
//    cout<<x<<endl;
    vis[x]=1;
    S.push(x);
    foreach(it, e[x]) if(it->f!=p)
    {
        if(!vis[it->f]) pre(it->f, x);
        else if(vis[it->f]==1)
        {
            while(S.size()&&S.top()!=it->f)
            {
                cycle.pb(S.top());
                onc[S.top()]=1;
                S.pop();
            }
            if(S.size()) cycle.pb(S.top()), onc[S.top()]=1, S.pop();
        }
    }
    if(S.size()&&S.top()==x) S.pop();
    vis[x]=2;
}

inline void dfs1(int x, int p, int c)
{
//    cout<<x<<" "<<c<<endl;
    tot+=c;
    val[++ptr]=c, id[ptr]=x;
    foreach(it, e[x]) if(it->f!=p&&onc[it->f]&&!vis[it->f])
        vis[it->f]=1, dfs1(it->f, x, it->s);
}

inline void dfs2(int x, int p, int c)
{
    sz[x]=1;
    foreach(it, e[x]) if(it->f!=p&&!onc[it->f])
        dfs2(it->f, x, it->s),
        sz[x]+=sz[it->f],
        dp1[x]+=dp1[it->f]+1LL*it->s*sz[it->f];
}

inline ll get(ll *dat, int l, int r)
{
    if(r<l) swap(r, l);
    return dat[r]-dat[l];
}

inline void dfs(int x, int p, int c)
{
    if(p)
    {
        ll tmp=dp1[p]-1LL*sz[x]*c-dp1[x];
        dp2[x]=dp2[p]+1LL*c*(N-sz[x])+tmp;
    }
    foreach(it, e[x]) if(it->f!=p&&!onc[it->f])
        dfs(it->f, x, it->s);
}

int main()
{
    N=in();
    Forn(i, N)
    {
        int a=in(), b=in(), c=in();
        e[a].pb(mp(b, c));
        e[b].pb(mp(a, c));
    }
    pre(1, 0);
    memset(vis, 0, sizeof(vis));
    id[0]=cycle.back();
    dfs1(cycle.back(), 0, 0);
    foreach(it, cycle) dfs2(*it, 0, 0);
    Forn(i, ptr) sum[i]=sz[id[i]], tot2+=dp1[id[i]];//, cout<<val[i]<<" "<<sum[i]<<" "<<id[i]<<endl;
    tot2-=dp1[id[1]];
    for(int i=ptr+1; i<=ptr*2; i++)
        id[i]=id[i-ptr+1], val[i]=val[i-ptr+1], sum[i]=sum[i-ptr+1];
    Forn(i, ptr*2) val[i]+=val[i-1], sum[i]+=sum[i-1];

    ptrl=1;
    while(ptrl+1<=ptr*2&&get(val, 1, ptrl+1)<=tot/2)
        ptrl++, dp2[id[1]]+=1LL*get(val, 1, ptrl)*sz[id[ptrl]];

    for(int i=ptrl+1; i<ptr; i++)
        dp2[id[1]]+=1LL*get(val, i, ptr)*sz[id[i]];
    dp2[id[1]]+=tot2-dp1[id[1]];
    for(int k=2; k<ptr; k++)
    {
        int id=::id[k], lst=ptrl;
        dp2[id]=dp2[::id[k-1]]-1LL*get(val, k-1, k)*get(sum, k-1, ptrl)+
               1LL*get(val, k+ptr-2, k+ptr-1)*get(sum, ptrl, k+ptr-2);
        while(ptrl+1<=ptr*2&&get(val, k, ptrl+1)<=tot/2)
        {
            ptrl++, dp2[id]+=1LL*get(val, k, ptrl)*sz[::id[ptrl]];
                    dp2[id]-=1LL*get(val, ptrl, ptr+k-1)*sz[::id[ptrl]];
        }
        dp2[id]+=tot2-dp1[id];
    }
    foreach(it, cycle) dfs(*it, 0, 0);
    Forn(i, N) printf("%lld ", dp2[i]+dp1[i]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
//万合以致，向阳而生——背叛时代，忠于时间//
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define mid l+r>>1
#define lid id<<1|1
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r

inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=200005;

int N, ptr, ptrl, cnt, tp, vis[MAX], onc[MAX], sz[MAX], id[MAX*2], cycle[MAX], S[MAX];
ll tot, tot2, costl, costr, dp1[MAX], dp2[MAX], val[MAX*2], sum[MAX*2];
vector<pi> e[MAX];

inline void pre(int x, int p)
{
//    cout<<x<<endl;
    vis[x]=1;
    S[tp++]=x;
    foreach(it, e[x]) if(it->f!=p)
    {
        if(!vis[it->f]) pre(it->f, x);
        else if(vis[it->f]==1)
        {
            while(tp>0&&S[tp-1]!=it->f)
            {
                cycle[cnt++]=S[tp-1];
                onc[S[tp-1]]=1;
                tp--;
            }
            if(tp>0) cycle[cnt++]=S[tp-1], onc[S[tp-1]]=1, tp--;
        }
    }
    if(tp>0&&S[tp-1]==x) tp--;
    vis[x]=2;
}

inline void dfs1(int x, int p, int c)
{
    tot+=c;
    val[++ptr]=c, id[ptr]=x;
    foreach(it, e[x]) if(it->f!=p&&onc[it->f]&&!vis[it->f])
        vis[it->f]=1, dfs1(it->f, x, it->s);
}

inline void dfs2(int x, int p, int c)
{
    sz[x]=1;
    foreach(it, e[x]) if(it->f!=p&&!onc[it->f])
        dfs2(it->f, x, it->s),
        sz[x]+=sz[it->f],
        dp1[x]+=dp1[it->f]+1LL*it->s*sz[it->f];
}

inline ll get(ll *dat, int l, int r)
{
    if(r<l) swap(r, l);
    return dat[r]-dat[l];
}

inline void dfs(int x, int p, int c)
{
    if(p)
    {
        ll tmp=dp1[p]-1LL*sz[x]*c-dp1[x];
        dp2[x]=dp2[p]+1LL*c*(N-sz[x])+tmp;
    }
    foreach(it, e[x]) if(it->f!=p&&!onc[it->f])
        dfs(it->f, x, it->s);
}

int main()
{
    N=in();
    Forn(i, N)
    {
        int a=in(), b=in(), c=in();
        e[a].pb(mp(b, c));
        e[b].pb(mp(a, c));
    }
    pre(1, 0);
    memset(vis, 0, sizeof(vis));
    id[0]=cycle[cnt-1];
    dfs1(cycle[cnt-1], 0, 0);
    forn(i, cnt) dfs2(cycle[i], 0, 0);
    Forn(i, ptr) sum[i]=sz[id[i]], tot2+=dp1[id[i]];//, cout<<val[i]<<" "<<sum[i]<<" "<<id[i]<<endl;
    tot2-=dp1[id[1]];
    for(int i=ptr+1; i<=ptr*2; i++)
        id[i]=id[i-ptr+1], val[i]=val[i-ptr+1], sum[i]=sum[i-ptr+1];
    Forn(i, ptr*2) val[i]+=val[i-1], sum[i]+=sum[i-1];

    ptrl=1;
    while(ptrl+1<=ptr*2&&get(val, 1, ptrl+1)<=tot/2)
        ptrl++, dp2[id[1]]+=1LL*get(val, 1, ptrl)*sz[id[ptrl]];
    costl=dp2[id[1]];
    for(int i=ptrl+1; i<ptr; i++)
        costr+=1LL*get(val, i, ptr)*sz[id[i]];
    dp2[id[1]]+=costr+tot2-dp1[id[1]];
    for(int k=2; k<ptr; k++)
    {
        int id=::id[k], lst=ptrl;
        costl-=1LL*get(val, k-1, k)*get(sum, k-1, ptrl);
        costr+=1LL*get(val, k+ptr-2, k+ptr-1)*get(sum, ptrl, k+ptr-2);
        while(ptrl+1<=ptr*2&&get(val, k, ptrl+1)<=tot/2)
        {
            ptrl++, costl+=1LL*get(val, k, ptrl)*sz[::id[ptrl]];
                    costr-=1LL*get(val, ptrl, ptr+k-1)*sz[::id[ptrl]];
        }
        dp2[id]=costl+costr+tot2-dp1[id];
    }
    forn(i, cnt) dfs(cycle[i], 0, 0);
    Forn(i, N) printf("%lld ", dp2[i]+dp1[i]);
    return 0;
}