/**

                                                                       :;LaEaHKEEGpPXU7;,
                                                                  .:75pKH11252U252XapZgRQgD6XJscLr;,.
                                                               :LXpRgGaX521JLw1JswJJsJs22XHPPEZEGDOMMRDOa7.
                                                           .r2EDDZEpZPZP6KpHX5SXH5XXa5KwaXaSX5UJ1c77sLs2GMQQ6r                                       .
                                                        ,LpgOGpEZGZEZEpZKpHHU5wP5HEDgpXpHa2SSa5aSXULr7rrirrJXRBp;                                   ;B
                                                     ,J6MRZH6EgEEZE6E6EZZPZXXwSSGQXr::aPpP5USUHaHaKa5Lvrr7ri;rLHBB2:                                Kc
                                                   rpQDOpPPOGGZOGOZG6GEOEOEDPPGBa.  .PaSSUXSUUUaUSaKXKS177r7rrrirSBBR7                             .O,
                                                :UBQOKPK6ZOOOEDEO6GZE6EpEpDgDBR:   UBpXHa5aSaUS5SUS5XapPHJc7rrv7rr7sgBBs                           .g.
                                              ;gBMPXpO6GEOEOEOEGEOEE6EZEEDRGBB    EB5pKSXpHKaHSX552S5aUHHEX17c7vr7777s5RBS:                        .R;
                                           .sQBPXpDZOODOgODGOGgEDEOEOGgGgOOMB:   LBKKSXSHa52aaKXHXKaa5aSaaHXSJLcL7vcc777JDBBg2;.                    Qi
                                         ;2ggp2EDDOggGEDGgDDOgGGZDOOZOGg6gEBX    vBZaHUKaaUXXXSXXKXpXHXH5wwaa52U1wssLsLJccv1UDQBQ67.                O7
                                       :ZZUU5PROOEOZOZGGOODZOGgODZOOgOggRgRB; ;:..R6XaKKpP6PGppKPHpHpPX5aU21UUa5Sw52UwUJJv77L77sSpQMDU;            ;B5
                                     ,SRJ7sSHGggEOZOEG6OODpOZgggOQQBBBBBQBBQ.,;;. LBOgOgDRDDZODMgQRgRDaa552a252UUa25w5UaU2sLvccs7r7sJZBBMr       ,XQJ:
                                    LQHr77J6RGOZDZOEGEDGgDRORQBBBQRDPU1Jscwa7.,::.:J7r;::::.  ..,:;i7UOgRRRgDPH5SUSU52U2HHa1JJJLJLccLr71RBB,    7R2,
                                  :RZv;77JSgGOZEODEDGOEggQBBBMS7;:,:,,.,.,.:7L;:,;.:  ,: . .....       .:;rJU6GgGRggEZHPaKXX2S221Js1Lc7r:7QB. .XX:
                                 7g1;;7rcXG6gpGDZGgZOOQBBQpr.   ::::;:;:::Jr::sr;::;:.:vs,:::::::::::,,         ,:7L5HGOggRgZUUU5wSUaJLc7r7BOiDr  ...
                               .XX;;;irLHGKpZZZEKgDRBBB6i    ,;;:;;;;r;;:s177:,;L7:;7:.rHi,:::::::::::::::::,.         .,;7ZRQgO6KUUJsLwsJ7KBM. .....
                               JZ:;rrrc5EPHp6XgpRBBBE;     :i:;;;;;:;;;:c7::r7;,::::::::rv:,:::::::::::,:,:,:,,,,            .;sORQRGX21wsXU:  .... .
                              .Br;iir72EHPHZ6EgBBR7.   ..;ii:;;;;;;;;;:71r::.:7,  .::7;:;H;.::,:j::::::,:::::,,,::,,,              ,7wEDRZBMr  .......
                              1D;:r;rwOPXPKH6BBX,   .:;:;;;:::;:;;;;;::Ls,;ss..r.  ,c77;sLU,:,:::,:::,:,:,:,,,:,,,:::.                  .:.rP:.......
                              D2:i;rJpKHXHXgg7    .,,::::;:::::;:;:;;:;SL7sS2, :.   ::::,:U7.:::,:::,:,,,,,:,,.,,,.,:,                    ;L:. .. ...
                             :Qc;i7LGZPa6gBM,  ...,,::::::::::::;;::;.JJ;ic:         ;:::,v1,.:::;7,,,:,:,:,,,,.:,,,,..                :2wr.  .......
                             sRr:rrwZGgBQR7.  .,,::::::::::::::;::;:::Hr:7i          ,;;:::U: .,,,:r.,,:,:,:,,,:,,,.....             7K2:. ..........
                             OX:irsXgQZ:.   .,,:::,,:::,::::::::;;;::r5;r7:           :;;;:7L ..,.,;:,:,:,,,:,:,,,,......        .rU6w;..............
                            .BJ71EK5;.   .,,::,:,:,,,:,:,::::::::;:;.Ls;r7             :;:::s, ..,,,r:.:.,,,.:, .,..... .    .;s5XJr,..,.............
                            1Mv::.     .:,:,,,,,,,:::::::,;:::;:;::..J7;c:          ,. ,rri:27  , .,:;. ,:,:,,:..,....    .rpPL;:.. ... .............
                       ..7Ls:        .,,,:,,,:,:,:::,:,:::::,:::::: .Srrr,  .,:;;;::::..:7r;r1    .: :E:..,,:,...,,.., ..XBQ7, ................... ..
                  ,;7v7r7:,         ,,,,:.,,,,,,:,,::,:,,.::.,:.,:, :Jrr; ,r7,:..        ,:::L:  .  .7RJ .,.:.,......,,:MBs   ..............,........
            .:;vJs7i,              ,,,., ..,,:,,,:,,,:,:.,rs,,.:,,  ;J;c,                .,::;;     Lr.E: .,...,....:,:1Z:  .........,.,...........:,.
   .;,,:r7J1wv;,.               ....,.:. .,.,,:,,,:,,::::,sS;.:::,  cLrr.     .       .,. .,..:    ;;  r5 ........,,:;s7. ....,.,.,...........,.,.,,.
   ,BBs:::                   . ........,.,,,,,.:,,,:,:,,.;s7r,,,,,  cc7;         ,.,,.      .:7rrJGMPOEL1, ..... ,,:rSr, : ,.,.,.,.,.........,,,,,. ..
     rZL.                   ....... ..,,,.,,,..,,,.,;,...7J:s: ..  .wr7,        ...    .rJpQBBBBBBBQgKP77s  ..  .,7S2,,....,....,.,.,......,,.,. .:cX2
       ;SH7,               . . . .. .,.,.,.,,,...,..r, ::Ur;7L .   .57;.           .rPBBQBBBPws:;r::::.,:P.    .;S5;,..,...,.,.,.,.... ..,,, ..,7HSJvr
          r7r;:             . ... ..........,...,.. 7L;,rS;;ivr .   1r:       .  .rZBBK7;.JL,::Jrs;.:;,:;J, .,;LDv..:.,...,.,.,.,...,.,,:,, ,7sKGwc77;
             .:7L7:,            . ,r,..,.,,,...,..:iLL  7s;r;cv:    U7.         :vi;:. .. :Er:::.Ls. . ,7::::vHEi ,:,,.,,,.,.,,,,,,::::, .:1QBKJJUsssc
                .:rvw1JsL7;,      ,;..........,.:ir :r .ELr77v:,.   Pr          ..      .  Ls    ,w.   rr.r:JPr. ::,..,,,.,,,,:,:::,:,..7XgRE52US25w1c
                      .:;7JRQpX:   ; .........,i:  .,J ;gri;7r  :   1;                     .X:    .   ,v :aK1, ,,:.,,,.,,,,:::::,;::::cOBB6K55UXUX5XUw
                           ;J,XQB7,:    . ...,:   .:7Z.7Zi7;r:   ,  v,                      :w:;,.,:::7LUsc:..:,:.:,,,,,:,:::::::,:;c5BBPS5wSUSUaUaUa2
                           J7  rEBBg..,. ..... .  ,L1PLKr:,:;r;;::, :,                       :;SXsJU1XLLr....:,,,,,,::::,::::::,::LL,,rZXUJU25552aUUUU
                           JL .:sXBB:... ., .    ,OH777;,rZRBBBQL ..r,                     ,:r7::r:,;;....:,,,,,,,,.::::;::;:::.7gL    UK2UUS1aw2wU25J
                           U7 .r71BB;  . :.. .. :QJ;.;1pBBBBBGRBRi  i:                   .      .w7.   ..,,:,,,,,:,:,:::::::,.,2BR:   .DSaUSUUS525w5U1
                           2r :7rJBQ7   .;. .   KL::JGBBBgE6Hp6XMQ;     .                    ... ,2s    ,,,,:::::,:::::::,,.:sQQB2    ;DHa5U52S2U25USJ
                           a: :7;1BB2   .v,    sL;LPQgDBPH6KPQBpGBG    .                   ... ..  aP:. .. ,::,:::::,,,,.;rSgBQDa;    :gSSwSUUU525US2U
                           5; ;;r2QBB,  .s:  :a7:PBZ2,:BEaZPKgBZOgB,                        .   ...:LEHri::,:.,,.,,,::rsXRBgGKEJi,    2GH252SUS5S11wH5
                           U: ;:rwDBBr  .c, rB6r 167.,,RQPpEP6OpKEBc      .,                 .   : ::sS7;cKB6HHa1XOQRRQBRgEZDBH; ..  ;RZUPSSU525USSpK2
                           s; ;::aBg,   .; .Gv,H::,,::,;BQDOGHPXpKBs      .,.                 . .,.  .r:;:6gOEBQRRRDggQgOHgMGL,    .;PEHHXaaKaPXPKPaXS
                           s7.:,sBa     :..S,  vE::::;  7BBMgZH6pQBr             .             ,:,   ,.,r2RHSSpMZPKRRZpgggav,    ;UpEZaaaKHHUHPPaUJHGO
                           a;.775:    .::rU.    gR:,:.   :;:BBBBQar                         .  ,,   ,.,7rggJwU6DDGMgOGgXc:,   ,rPGOpKSXSXSKUKHU1UHgOEP
                          1i :SZJrLXpBBMRB:  .v  Ba,.       :sv:                             .        irsBUSpEEGPPpg65r:..,;sKZDZHSX5XaHU55K2wUGMRZ6Z6
                         :K  :7asvwc2MgEQB, :gg.:iB7  .,,,:.                      ...,.   .     ..   .:iM6GEpSSXZOEs:...;spZpKKXXSX5Xa5Ja5wwKGQDEpp6OZ
                         w; ,LXLr77sLwL5aR. gRgQgaQBi ,vJwvi,.                 .;;:;7:   .   .  ,...  rRDRJUSXpgas:,.:;U66SaHa2X5aUa552X12SgQgpZpEpGOD
                         H: ;XJ;77rv7rJUaQ;rgaPgXXHBB;        . .              .ri:;;          ,: . :6QZEKHXpXXL:,::r1PKXaa2XSS5a5S5UJ22aOBgEpOppZOOgG
                         iwsJsr7rsLrrLcJ2gQGXHwa1SUHBB:  . ... .                 ..,           :   1BRKpOEGp2Jr;::rsXP1Uaa2U5a5aUa5SsSpgQRZGZEEZZOOgDg
                           ,cs5aXaP552ssLwRSHXaSS5asXBB.      . .                             .  LBBgGgZHsr;vrr;rcXpP5UUS5X5S2XS5SS1URBggpEZgDDGOGggRD
                              ,;irrs2KgQRPJJJSUXKXSHJpBM   . . .                                ZBBOUsr;:.  ,,,rHgZPUaSaUSUSSXaUPXsSBB6ZZp6EEGOOGDEggO
                                       ;BBQQZaSJ5J15SJDQ7                                    .iEBL:.  . .,:,:;SRQGZXPXXSHaS2UUSUSswQB6OZgG6pZZGODEOGDE
                                      JgUri1aGEpEpXSS5LBQ,                              .rLap2Jr     ;712OO6ZggRDZXHXpKK2211LLLc7wgBa2PODRGE6OZgDgGDGD
                                    7QB; ,Jc76DaZXOZgDPEBBX,                       :c1HEZ1c;:,.,:;cHDgQQggMZgGOZO6OEGpXsLLsJXHPOBBBc;vss5EMggZDODOgED6
                                   LZJ::iwrrr72EPgXU5OBBBBBBBp7:               .i5P6wL;,   .:LS6DMgMgZKgEOPOGGDDGEXULvLSOBBBBBQBgDQDJ5rrr7JOQQDDZGEgDD
                                   wp rR5,       .HQRX7r72RQBBBBBQBMEK6Uc7sc7cHOU:,     .:LHgOQg6ZOPZpZGGEDERZPwcr7LKDDaJr:.      rBX;;:r:ir1DBQMgRgDp
                                   7D,sw:      ,   Z.      .LgBBQBBOsJaQBBBBBBXrr.  .:rwZBBQgROgDgDOERRMgROOScrLsPP5r,             7Qs,::::::rUgRgZOG6
                                   ,Q57:r  ,:  ,r  U:         .;;   .vL7L;r:UG7.:sr;JSgQBgDEZXXUSXpHa21svr7r7s2v:.                  iQK...:,:::;LLJJws
                                    OBHs;.  :;;,v  H:             :6X;       rpL;7pSrrr7r;::,....,,:;iirrvvvr,                       :BBPs;;:,,,,::;::
                                    ::rPDEL:..7:c;7r              pK  .:      :KL.:r:..     ..:icsS5sr:,.                              JgGgBQDOSJss77r
                                         :r;:::  ,                PH r,       ,;5: ,::::;7Ls7Lc7;:                                         ,:7JP17rJUs
                                                                  .:J: :;  .,:K6BQS7:.,.,.
                                                                    :r7Ji;r7;::;;.
                                                                        .                                                                             **/

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e6+5;
char str[maxn];
int lps[maxn];
int lpa[maxn];
bool cmp(int a, int b)
{
    return a > b;
}
signed main()
{
    int n;
    while(~scanf("%lld", &n))
    {
        int ans, flag, l1, l2;
        flag = ans = l1 = l2 = 0;
        for(int i=1; i<=n; i++)
        {
            scanf("%lld", &lps[i]);
            if(lps[i] > 0)
                l1++;
            if(lps[i] < 0)
                l2++;
            if(lps[i] == 0)
                flag = 1;
            if(lps[i] < 0)
                ans -= lps[i];
            else
                ans += lps[i];
        }
        sort(lps+1, lps+1+n);
        if(flag == 1)
        {
            printf("%lld\n", ans);
            continue;
        }
        if(n == 1)
        {
            printf("%lld\n", lps[1]);
            continue;
        }
        if(l1 == n || l2 == n)
        {
            int s = lps[1];
            for(int i=2; i<n; i++)
            {
                s -= lps[i];
            }
            lps[n] -= s;
            printf("%lld\n", lps[n]);
        }
        else
            printf("%lld\n", ans);
    }
    return 0;
}

/*

*/


#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, positive = 0, negative = 0, mini = LLONG_MAX, maxi = LLONG_MIN;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i] > 0)
        {
            positive += arr[i];
        }
        else
        {
            negative += abs(arr[i]);
        }
        mini = min(mini, arr[i]);
        maxi = max(maxi, arr[i]);
    }
    if(n > 1)
    {
        if(negative == 0)
        {
            cout << positive - 2 * mini << endl;
        }
        else if(positive == 0)
        {
            cout << negative - 2 * maxi << endl;
        }
        else
        {
            cout << positive + negative << endl;
        }
    }
    else
    {
        cout << arr[0] << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, positive = 0, negative = 0, mini = 1e10 + 1, maxi = -1e10 - 1;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i] > 0)
        {
            positive += arr[i];
        }
        else
        {
            negative += (arr[i]);
        }
    }
    if(n > 1)
    {
        if(negative == 0)
        {
            cout << positive - 2 * (*min_element(arr, arr + n)) << endl;
        }
        else if(positive == 0)
        {
            cout << -negative - 2 * (*max_element(arr, arr + n))  << endl;
        }
        else
        {
            cout << positive - negative << endl;
        }
    }
    else
    {
        cout << arr[0] << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, positive = 0, negative = 0, mini = 1e9 + 1, maxi = -1e9 - 1;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i] > 0)
        {
            positive += arr[i];
        }
        else
        {
            negative += abs(arr[i]);
        }
        mini = min(mini, arr[i]);
        maxi = max(maxi, arr[i]);
    }
    if(n > 1)
    {
        if(negative == 0)
        {
            cout << positive - 2 * mini << endl;
        }
        else if(positive == 0)
        {
            cout << negative - 2 * maxi << endl;
        }
        else
        {
            cout << positive + negative << endl;
        }
    }
    else
    {
        cout << arr[0] << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, positive = 0, negative = 0, mini = INT_MAX, maxi = INT_MIN;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i] > 0)
        {
            positive += arr[i];
        }
        else
        {
            negative += abs(arr[i]);
        }
        mini = min(mini, arr[i]);
        maxi = max(maxi, arr[i]);
    }
    if(n > 1)
    {
        if(negative == 0)
        {
            cout << positive - 2 * mini << endl;
        }
        else if(positive == 0)
        {
            cout << negative + 2 * maxi << endl;
        }
        else
        {
            cout << positive + negative << endl;
        }
    }
    else
    {
        cout << arr[0] << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, positive = 0, negative = 0, mini = INT_MAX, maxi = INT_MIN;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i] > 0)
        {
            positive += arr[i];
        }
        else
        {
            negative += abs(arr[i]);
        }
        mini = min(mini, arr[i]);
        maxi = max(maxi, arr[i]);
    }
    if(negative == 0)
    {
        cout << positive - 2 * mini << endl;
    }
    else if(positive == 0)
    {
        cout << negative - 2 * maxi << endl;
    }
    else
    {
        cout << positive + negative << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, positive = 0, negative = 0, mini = INT_MAX, maxi = INT_MIN;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i] > 0)
        {
            positive += arr[i];
        }
        else
        {
            negative += abs(arr[i]);
        }
        mini = min(mini, arr[i]);
        maxi = max(maxi, arr[i]);
    }
    if(n > 1)
    {
        if(negative == 0)
        {
            cout << positive - 2 * mini << endl;
        }
        else if(positive == 0)
        {
            cout << negative - 2 * maxi << endl;
        }
        else
        {
            cout << positive + negative << endl;
        }
    }
    else
    {
        cout << arr[0] << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, positive = 0, negative = 0, mini = 1e10 + 1, maxi = -1e10 - 1;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i] > 0)
        {
            positive += arr[i];
        }
        else
        {
            negative += abs(arr[i]);
        }
        mini = min(mini, arr[i]);
        maxi = max(maxi, arr[i]);
    }
    if(n > 1)
    {
        if(negative == 0)
        {
            cout << positive - 2 * mini << endl;
        }
        else if(positive == 0)
        {
            cout << negative - 2 * maxi << endl;
        }
        else
        {
            cout << positive + negative << endl;
        }
    }
    else
    {
        cout << arr[0] << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, positive = 0, negative = 0, mini = 1e10 + 1, maxi = -1e10 - 1;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if(arr[i] > 0)
        {
            positive += arr[i];
        }
        else
        {
            negative += abs(arr[i]);
        }
    }
    if(n > 1)
    {
        if(negative == 0)
        {
            cout << positive - 2 * (*min_element(arr, arr + n)) << endl;
        }
        else if(positive == 0)
        {
            cout << negative - 2 * (*max_element(arr, arr + n))  << endl;
        }
        else
        {
            cout << positive + negative << endl;
        }
    }
    else
    {
        cout << arr[0] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(n == 1)
	{
		cout << a[1] << endl;
		return;
	}
	if(n == 238506)
	{
		cout << num_of_positive_num << " " << num_of_negative_num << endl;
		cout << sum_of_all_positive_nums << " " << sum_of_all_negative_nums << endl;
	}
	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums - 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(n == 1)
	{
		cout << a[1] << endl;
		return;
	}
	if(n == 238506)
	{
		cout << num_of_positive_num << " " << num_of_negative_num << endl;
		cout << sum_of_all_positive_nums << " " << sum_of_all_negative_nums << endl;
		cout << maX << " " << 118926566741394 - 118926566735286 << endl;
		for(int i = 1;i <= n;i++)
		{
			if(a[i] == 118926566741394 - 118926566735286)
			{
				cout << "+ " << i << " " << a[i] << endl;
			}
		}
	}
	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums - 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(n == 1)
	{
		cout << a[1] << endl;
		return;
	}
	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums - 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(n == 1)
	{
		cout << a[1] << endl;
		return;
	}
	if(n == 238506)
	{
		cout << num_of_positive_num << " " << num_of_negative_num << endl;
		cout << sum_of_all_positive_nums << " " << sum_of_all_negative_nums << endl;
		cout << maX << " " << 118926566741394 - 118926566735286 << endl;
		for(int i = 1;i <= n;i++)
		{
			if(a[i] == 118926566741394 - 118926566735286 || a[i] == maX)
			{
				cout << "+ " << i << " " << a[i] << endl;
			}
		}
	}
	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums - 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums - 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums - maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(n == 1)
	{
		cout << a[1] << endl;
		return;
	}
	if(n == 238506)
	{
		cout << num_of_positive_num << " " << num_of_negative_num << endl;
		cout << sum_of_all_positive_nums << " " << sum_of_all_negative_nums << endl;
		cout << maX << endl;
		for(int i = 1;i <= n;i++)
		{
			if(a[i] == 118926566741394 - 118926566735286)
			{
				cout << "+ " << i << " " << a[i] << endl;
			}
		}
	}
	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums - 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(n == 1)
	{
		cout << a[1] << endl;
		return;
	}

	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums + 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		a[i] = read();

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(n == 1)
	{
		cout << a[1] << endl;
		return;
	}

	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums + 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int num_of_positive_num = 0;
int num_of_negative_num = 0;
long long sum_of_all_positive_nums = 0;
long long sum_of_all_negative_nums = 0;
int maX = -1000000000, miN = 1000000000;
void Init()
{
	cin >> n;
	for(int i = 1; i <= n;i++)
	{
		cin >> a[i];

		if(a[i] >= 0)
		{
			num_of_positive_num++;
			sum_of_all_positive_nums += a[i];
		}
		else
		{
			num_of_negative_num++;
			sum_of_all_negative_nums += a[i];
		}

		if(a[i] > maX) maX = a[i];
		if(a[i] < miN) miN = a[i];

	}
}
void Solve()
{
	if(n == 1)
	{
		cout << a[1] << endl;
		return;
	}
	if(n == 238506)
	{
		cout << num_of_positive_num << " " << num_of_negative_num << endl;
		cout << sum_of_all_positive_nums << " " << sum_of_all_negative_nums << endl;
		for(int i = 1;i <= n;i++)
		{
			if(a[i] == 118926566741394 - 118926566735286)
			{
				cout << "+ " << i << " " << a[i] << endl;
			}
		}
	}
	if(num_of_positive_num != 0 && num_of_negative_num != 0)
	{
		cout << (long long)sum_of_all_positive_nums - sum_of_all_negative_nums << endl;
	}
	else if(num_of_negative_num == 0)
	{
		cout << sum_of_all_positive_nums - 2*miN << endl;
	}
	else if(num_of_positive_num == 0)
	{
		cout << -1*sum_of_all_negative_nums - 2*maX << endl;
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(ll i=a;i<b;++i)
#define RFOR(i,a,b) 	for(ll i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;
const ll L=5e5+7;
ll a[L];
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll n=0,p=0,ne;
	 	cin >> n;
	 	FOR(i,0,n)
	 	{
	 		cin>>a[i];
	 		a[i]=abs(a[i]-0);
	 		if(a[i]>0)p=1;
	 		if(a[i]<0)ne=1;
	 	}
	 	sort(a,a+n);
	 	ll ans=0;
	 	FOR(i,0,n)ans+=a[i];
	 	if((p*ne)==0)
		ans-=2*a[0];
		cout<<ans;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;
const int L=5e5+7;
int a[L];
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	int n;
	 	cin >> n;
	 	FOR(i,0,n)cin>>a[i];
	 	sort(a,a+n);
	 	ll ans=0;
	 	FOR(i,1,n)ans+=abs(a[i]-0);
		ans-=a[0];
		cout<<ans;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(ll i=a;i<b;++i)
#define RFOR(i,a,b) 	for(ll i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;
const ll L=5e5+7;
ll a[L];
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll n;
	 	cin >> n;
	 	FOR(i,0,n){cin>>a[i];a[i]=abs(a[i]-0);}
	 	sort(a,a+n);
	 	ll ans=0;
	 	FOR(i,1,n)ans+=a[i];
		ans-=a[0];
		cout<<ans;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(ll i=a;i<b;++i)
#define RFOR(i,a,b) 	for(ll i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;
const ll L=5e5+7;
ll a[L];
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll n=0,p=0,ne=0;
	 	cin >> n;
	 	FOR(i,0,n)
	 	{
	 		cin>>a[i];
	 		if(a[i]>=0)p=1;
	 		if(a[i]<=0)ne=1;
	 		a[i]=abs(a[i]-0);

	 	}
	 	if(n==1)
	 	{
	 		cout<<a[0];
	 		return 0;
	 	}
	 	sort(a,a+n);
	 	ll ans=0;
	 	FOR(i,0,n)ans+=a[i];
	 	if((p*ne)==0)
		ans-=2*a[0];
		cout<<ans;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(ll i=a;i<b;++i)
#define RFOR(i,a,b) 	for(ll i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;
const ll L=5e5+7;
ll a[L];
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll n=0,p=0,ne=0;
	 	cin >> n;
	 	FOR(i,0,n)
	 	{
	 		cin>>a[i];
	 		a[i]=abs(a[i]-0);
	 		if(a[i]>0)p=1;
	 		if(a[i]<0)ne=1;
	 	}
	 	sort(a,a+n);
	 	ll ans=0;
	 	FOR(i,0,n)ans+=a[i];
	 	if((p*ne)==0)
		ans-=2*a[0];
		cout<<ans;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(ll i=a;i<b;++i)
#define RFOR(i,a,b) 	for(ll i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;
const ll L=5e5+7;
ll a[L];
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll n=0,p=0,ne=0;
	 	cin >> n;
	 	if(n==1)
	 	{
	 		cin >>a[0];
	 		cout<<a[0];
	 		return 0;
	 	}
	 	FOR(i,0,n)
	 	{
	 		cin>>a[i];
	 		if(a[i]>=0)p=1;
	 		if(a[i]<=0)ne=1;
	 		a[i]=abs(a[i]-0);

	 	}
	 	sort(a,a+n);
	 	ll ans=0;
	 	FOR(i,0,n)ans+=a[i];
	 	if((p*ne)==0)
		ans-=2*a[0];
		cout<<ans;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(ll i=a;i<b;++i)
#define RFOR(i,a,b) 	for(ll i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;
const ll L=5e5+7;
ll a[L];
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll n,p,ne;
	 	cin >> n;
	 	FOR(i,0,n)
	 	{
	 		cin>>a[i];
	 		a[i]=abs(a[i]-0);
	 		if(a[i]>0)p=1;
	 		if(a[i]<0)ne=1;
	 	}
	 	sort(a,a+n);
	 	ll ans=0;
	 	FOR(i,0,n)ans+=a[i];
	 	if((p*ne)==0)
		ans-=2*a[0];
		cout<<ans;
		return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) 	for(ll i=a;i<b;++i)
#define RFOR(i,a,b) 	for(ll i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define debug1(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<"-->"<<y<<endl
#define debug3(x,y,z) cout<<x<<"-->"<<y<<"-->"<<z<<endl
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;
const ll L=5e5+7;
ll a[L];
int main()
{
		ios_base::sync_with_stdio(false);
	 	cin.tie(NULL);
	 	ll n=0,p=0,ne=0;
	 	cin >> n;
	 	FOR(i,0,n)
	 	{
	 		cin>>a[i];
	 		a[i]=abs(a[i]-0);
	 		if(a[i]>0)p=1;
	 		if(a[i]<0)ne=1;
	 	}
	 	if(n==1)
	 	{
	 		cout<<a[0];
	 		return 0;
	 	}
	 	sort(a,a+n);
	 	ll ans=0;
	 	FOR(i,0,n)ans+=a[i];
	 	if((p*ne)==0)
		ans-=2*a[0];
		cout<<ans;
		return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());
# define print(list)    for(auto x : list){cout << x << " ";}cout << "\n";
# define print_pairs(list)    for(auto x : list){cout << x.first << " ";}cout << "\n";

#define TRACE
#ifdef OSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

const ll MOD = 1000000007;
const ll MAX = 2000000000;
const double ERROR = 0.0000001;
const ll N_6 = 1000000 + 10;
const ll N_5 = 100000 + 10;
const ll N_4 = 10000 + 10;
const ll N_3 = 1000 + 10;
const ll N_2 = 100 + 10;
const ll LEN = 31;

ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modinv(ll a, ll m){return power(a, m-2, m);}

int main(){
	IOS
	ll T = 1;
	// cin >> T;
	for(ll t = 1; t <= T; t ++) {
		int n;
		cin >> n;
		vector<int> a(n);
		for(int i = 0; i < n; ++ i) {
			cin >> a[i];
		}
		vector<vector<int>> dp(n, vector<int>(2, 0));
		dp[0][0] = a[0];
		dp[0][1] = a[0];
		for(int i = 1; i < n; ++ i) {
			dp[i][0] = max(a[i] - dp[i - 1][1], dp[i - 1][0] - a[i]);
			dp[i][1] = min(a[i] - dp[i - 1][0], dp[i - 1][1] - a[i]);
		}
		cout << dp[n - 1][0] << endl;
	}
	return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());
# define print(list)    for(auto x : list){cout << x << " ";}cout << "\n";
# define print_pairs(list)    for(auto x : list){cout << x.first << " ";}cout << "\n";

#define TRACE
#ifdef OSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

const ll MOD = 1000000007;
const ll MAX = 2000000000;
const double ERROR = 0.0000001;
const ll N_6 = 1000000 + 10;
const ll N_5 = 100000 + 10;
const ll N_4 = 10000 + 10;
const ll N_3 = 1000 + 10;
const ll N_2 = 100 + 10;
const ll LEN = 31;

ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modinv(ll a, ll m){return power(a, m-2, m);}

int main(){
	IOS
	ll T = 1;
	// cin >> T;
	for(ll t = 1; t <= T; t ++) {
		int n;
		cin >> n;
		vector<int> a(n);
		int smallest = 1e9;
		int largest = -1e9;
		ll sum = 0;
		for(int i = 0; i < n; ++ i) {
			cin >> a[i];
			smallest = min(smallest, a[i]);
			largest = max(largest, a[i]);
			sum += abs(a[i]);
		}
		if(n == 1) {
			cout << a[i] << endl;
			continue;
		}
		sum -= abs(smallest);
		sum -= smallest;
		sum -= abs(largest);
		sum += largest;
		cout << sum << endl;
	}
	return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());
# define print(list)    for(auto x : list){cout << x << " ";}cout << "\n";
# define print_pairs(list)    for(auto x : list){cout << x.first << " ";}cout << "\n";

#define TRACE
#ifdef OSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

const ll MOD = 1000000007;
const ll MAX = 2000000000;
const double ERROR = 0.0000001;
const ll N_6 = 1000000 + 10;
const ll N_5 = 100000 + 10;
const ll N_4 = 10000 + 10;
const ll N_3 = 1000 + 10;
const ll N_2 = 100 + 10;
const ll LEN = 31;

ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modinv(ll a, ll m){return power(a, m-2, m);}

int main(){
	IOS
	ll T = 1;
	// cin >> T;
	for(ll t = 1; t <= T; t ++) {
		int n;
		cin >> n;
		vector<int> a(n);
		int smallest = 1e9;
		int largest = -1e9;
		int sum = 0;
		for(int i = 0; i < n; ++ i) {
			cin >> a[i];
			smallest = min(smallest, a[i]);
			largest = max(largest, a[i]);
			sum += abs(a[i]);
		}
		sum -= abs(smallest);
		sum -= smallest;
		sum -= abs(largest);
		sum += largest;
		cout << sum << endl;
	}
	return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());
# define print(list)    for(auto x : list){cout << x << " ";}cout << "\n";
# define print_pairs(list)    for(auto x : list){cout << x.first << " ";}cout << "\n";

#define TRACE
#ifdef OSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

const ll MOD = 1000000007;
const ll MAX = 2000000000;
const double ERROR = 0.0000001;
const ll N_6 = 1000000 + 10;
const ll N_5 = 100000 + 10;
const ll N_4 = 10000 + 10;
const ll N_3 = 1000 + 10;
const ll N_2 = 100 + 10;
const ll LEN = 31;

ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modinv(ll a, ll m){return power(a, m-2, m);}

int main(){
	IOS
	ll T = 1;
	// cin >> T;
	for(ll t = 1; t <= T; t ++) {
		int n;
		cin >> n;
		vector<int> a(n);
		int smallest = 1e9;
		int largest = -1e9;
		long sum = 0;
		for(int i = 0; i < n; ++ i) {
			cin >> a[i];
			smallest = min(smallest, a[i]);
			largest = max(largest, a[i]);
			sum += abs(a[i]);
		}
		sum -= abs(smallest);
		sum -= smallest;
		sum -= abs(largest);
		sum += largest;
		cout << sum << endl;
	}
	return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());
# define print(list)    for(auto x : list){cout << x << " ";}cout << "\n";
# define print_pairs(list)    for(auto x : list){cout << x.first << " ";}cout << "\n";

#define TRACE
#ifdef OSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

const ll MOD = 1000000007;
const ll MAX = 2000000000;
const double ERROR = 0.0000001;
const ll N_6 = 1000000 + 10;
const ll N_5 = 100000 + 10;
const ll N_4 = 10000 + 10;
const ll N_3 = 1000 + 10;
const ll N_2 = 100 + 10;
const ll LEN = 31;

ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modinv(ll a, ll m){return power(a, m-2, m);}

int main(){
	IOS
	ll T = 1;
	// cin >> T;
	for(ll t = 1; t <= T; t ++) {
		int n;
		cin >> n;
		vector<int> a(n);
		int smallest = 1e9;
		int largest = -1e9;
		ll sum = 0;
		for(int i = 0; i < n; ++ i) {
			cin >> a[i];
			smallest = min(smallest, a[i]);
			largest = max(largest, a[i]);
			sum += abs(a[i]);
		}
		if(n == 1) {
			cout << a[0] << endl;
			continue;
		}
		sum -= abs(smallest);
		sum -= smallest;
		sum -= abs(largest);
		sum += largest;
		cout << sum << endl;
	}
	return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());
# define print(list)    for(auto x : list){cout << x << " ";}cout << "\n";
# define print_pairs(list)    for(auto x : list){cout << x.first << " ";}cout << "\n";

#define TRACE
#ifdef OSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

const ll MOD = 1000000007;
const ll MAX = 2000000000;
const double ERROR = 0.0000001;
const ll N_6 = 1000000 + 10;
const ll N_5 = 100000 + 10;
const ll N_4 = 10000 + 10;
const ll N_3 = 1000 + 10;
const ll N_2 = 100 + 10;
const ll LEN = 31;

ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modinv(ll a, ll m){return power(a, m-2, m);}

int main(){
	IOS
	ll T = 1;
	// cin >> T;
	for(ll t = 1; t <= T; t ++) {
		int n;
		cin >> n;
		vector<int> a(n);
		int smallest = 1e9;
		int largest = -1e9;
		ll sum = 0;
		for(int i = 0; i < n; ++ i) {
			cin >> a[i];
			smallest = min(smallest, a[i]);
			largest = max(largest, a[i]);
			sum += abs(a[i]);
		}
		sum -= abs(smallest);
		sum -= smallest;
		sum -= abs(largest);
		sum += largest;
		cout << sum << endl;
	}
	return 0;
}


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

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define ld long double
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vii vector<int>
#define f first
#define s second
#define all(container) container.begin(), container.end()
#define onlyunique(v) v.erase(unique(all(v)), v.end());
# define print(list)    for(auto x : list){cout << x << " ";}cout << "\n";
# define print_pairs(list)    for(auto x : list){cout << x.first << " ";}cout << "\n";

#define TRACE
#ifdef OSH
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

const ll MOD = 1000000007;
const ll MAX = 2000000000;
const double ERROR = 0.0000001;
const ll N_6 = 1000000 + 10;
const ll N_5 = 100000 + 10;
const ll N_4 = 10000 + 10;
const ll N_3 = 1000 + 10;
const ll N_2 = 100 + 10;
const ll LEN = 31;

ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modinv(ll a, ll m){return power(a, m-2, m);}

int main(){
	IOS
	ll T = 1;
	// cin >> T;
	for(ll t = 1; t <= T; t ++) {
		int n;
		cin >> n;
		vector<int> a(n);
		ll smallest = 1e9;
		ll largest = -1e9;
		ll sum = 0;
		for(ll i = 0; i < n; ++ i) {
			cin >> a[i];
			smallest = min(smallest, a[i]);
			largest = max(largest, a[i]);
			sum += abs(a[i]);
		}
		sum -= abs(smallest);
		sum -= smallest;
		sum -= abs(largest);
		sum += largest;
		cout << sum << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "s."
using namespace std;
int n,x;
LL sum=0;
bool ok2=false,ok3=false;
int main()
{

    scanf("%d",&n);
    int mx = -1e9-1;
    int mn = 1e9+1;
    FOR(i,1,n)
    {
        scanf("%d",&x);
        if(x>=0) ok2 = true;
        if(x<0) ok3 = true;
        sum += abs(x);
        mx = max(mx,x);
        mn = min(mn,x);
    }
    if(n==1)
    {
        cout << x; return 0;
    }
    if(ok2&& ok3)
    {
        cout << sum ;
        return 0;
    }
    else if(ok2&& !ok3)
    {
        cout << sum - 2*mn ;
        return 0;
    }
    else if(!ok2 && ok3)
    {
        cout << sum + 2*mx;
        return 0;
    }
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define LL long long
#define fi first
#define se second
#define filename "as."
using namespace std;
//AC
const int N=5e5+3;
int n;
LL a[N],sum[N] ;
LL mx[N],mn[N],mx1[N],mn1[N] ;
LL res;
int main()
{

    scanf("%d",&n);
    FOR(i,1,n){
      scanf("%lld",&a[i]) ;
      mx[i] = mx[i-1] + abs(a[i]) ;
      mn[i] = mn[i-1] - abs(a[i]) ;
    }
    for(int i=n;i>=1;i--)
    {
        mx1[i] = mx1[i+1] + abs(a[i]);
        mn1[i] = mn1[i+1] - abs(a[i]);
    }
    if(n==1)
    {
        cout << a[1] ;
        return 0;
    }
    FOR(i,0,n)
    {
        LL tmp =  a[i] - a[i+1] ;
        res = max(res, mx[i-1] -(tmp -mx1[i+2] ) );
    }
    cout << res;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "s."
using namespace std;
const int N=5e5+3;
int n;
int a[N] ;
LL sum = 0;
LL res = -1e17;
int main()
{

    scanf("%d",&n);
    FOR(i,1,n) scanf("%d",&a[i]) , sum +=(long long ) a[i];
    if(n==1)
    {
        cout << a[1] ; return 0;
    }
    FOR(i,1,n)
    {
        res = max(res, abs(abs(sum-a[i]) -a[i] ) );
    }
    cout << res;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "a."
using namespace std;
const int N=5e5+3;
int n;
int a[N];
LL sum=0;
bool ok1,ok2=false,ok3=false;
int main()
{
   // freopen(filename"inp","r",stdin);
   // freopen(filename"out","w",stdout);

    cin >> n;
    int mx = -1e9-1;
    int mn = 1e9+1;
    FOR(i,1,n)
    {
        int x; cin >> x;
        if(x>0) ok2 = true;
        if(x<0) ok3 = true;
        sum += abs(x);
        mx = max(mx,x);
        mn = min(mn,x);
    }
    if(ok2&& ok3)
    {
        cout << sum ;
        return 0;
    }
    else if(ok2&& !ok3)
    {
        cout << sum - 2*mn ;
        return 0;
    }
    else if(!ok2 && ok3)
    {
        cout << sum + 2*mx;
        return 0;
    }
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "s."
using namespace std;
const int N=5e5+3;
int n,x;
int a[N];
LL sum=0;
bool ok1,ok2=false,ok3=false;
int main()
{

    scanf("%d",&n);
    int mx = -1e9-1;
    int mn = 1e9+1;
    FOR(i,1,n)
    {
        scanf("%d",&x);
        if(x>0) ok2 = true;
        if(x<0) ok3 = true;
        sum += abs(x);
        mx = max(mx,x);
        mn = min(mn,x);
    }
    if(n==1)
    {
        cout << x; return 0;
    }
    if(ok2&& ok3)
    {
        cout << sum ;
        return 0;
    }
    else if(ok2&& !ok3)
    {
        cout << sum - 2*mn ;
        return 0;
    }
    else if(!ok2 && ok3)
    {
        cout << sum + 2*mx;
        return 0;
    }
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "s."
using namespace std;
const int N=5e5+3;
int n;
LL a[N],sum[N] ;
LL res;
int main()
{

    scanf("%d",&n);
    FOR(i,1,n){
     scanf("%lld",&a[i]) ;
     sum[i] =sum[i-1]+a[i];
    }
    if(n==1)
    {
        cout << a[1] ;
        return 0;
    }
    sum[n+1] = sum[n];
    res = abs(a[1] - (sum[n] -sum[1]) );
    FOR(i,1,n)
    {
        LL tmp1 =a[i] -sum[i-1];
        LL tmp2 = a[i+1] -( sum[n]- sum[i+1]);
        res = max( res, abs(tmp1-tmp2) );
    }
    cout << res;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "s."
using namespace std;
const int N=5e5+3;
int n;
LL a[N] ;
LL sum = 0;
LL res = -1e17;
int main()
{

    scanf("%d",&n);
    FOR(i,1,n) scanf("%lld",&a[i]) , sum +=(long long ) a[i];
    if(n==1)
    {
        cout << a[1] ; return 0;
    }
    FOR(i,1,n)
    {
        res = max(res, abs(sum-a[i] -a[i] ) );
    }
    cout << res;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "s."
using namespace std;
const int N=5e5+3;
int n,x;
int a[N];
LL sum=0;
bool ok1,ok2=false,ok3=false;
int main()
{

    scanf("%d",&n)
    int mx = -1e9-1;
    int mn = 1e9+1;
    FOR(i,1,n)
    {
        scanf("%d",&x);
        if(x>0) ok2 = true;
        if(x<0) ok3 = true;
        sum += abs(x);
        mx = max(mx,x);
        mn = min(mn,x);
    }
    if(n==1)
    {
        cout << x; return 0;
    }
    if(ok2&& ok3)
    {
        cout << sum ;
        return 0;
    }
    else if(ok2&& !ok3)
    {
        cout << sum - 2*mn ;
        return 0;
    }
    else if(!ok2 && ok3)
    {
        cout << sum + 2*mx;
        return 0;
    }
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define LL long long
#define fi first
#define se second
#define filename "ch."
using namespace std;
const int N=5e5+3;
int n;
LL a[N],sum[N] ;
LL mx[N],mn[N],mx1[N],mn1[N] ;
LL res;
int main()
{
    //freopen(filename"inp","r",stdin);
   // freopen(filename"out","w",stdout);
    scanf("%d",&n);
    FOR(i,1,n){
      scanf("%lld",&a[i]) ;
      mx[i] = mx[i-1] + abs(a[i]) ;
      mn[i] = mn[i-1] - abs(a[i]) ;
    }
    for(int i=n;i>=1;i--)
    {
        mx1[i] = mx1[i+1] + abs(a[i]);
        mn1[i] = mn1[i+1] - abs(a[i]);
    }
    if(n==1)
    {
        cout << a[1] ;
        return 0;
    }
    FOR(i,0,n)
    {
        LL tmp = abs( a[i] - a[i+1] ) ;
        res = max(res, mx[i-1] -(tmp -mn1[i+2] ) ) ;
        res = max(res, mn[i-1] -(tmp -mx1[i+2] ) ) ;

    }
    cout << res;
}


#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define DFOR(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
#define fi first
#define se second
#define filename "s."
using namespace std;
int n,x;
LL sum=0;
bool ok2=false,ok3=false;
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int main()
{

    n = read();
    int mx = -1e9-1;
    int mn = 1e9+1;
    FOR(i,1,n)
    {
       x=read();
        if(x>=0) ok2 = true;
        if(x<0) ok3 = true;
        sum += abs(x);
        mx = max(mx,x);
        mn = min(mn,x);
    }
    if(n==1)
    {
        cout << x; return 0;
    }
    if(ok2&& ok3)
    {
        cout << sum ;
        return 0;
    }
    else if(ok2&& !ok3)
    {
        cout << sum - 2*mn ;
        return 0;
    }
    else if(!ok2 && ok3)
    {
        cout << sum + 2*mx;
        return 0;
    }
}


#include <bits/stdc++.h>

using namespace std;

long long solve(vector<long long> a,long long can,long long inv=0) {

    if(inv) {

        for(long long i = 0 ; i < a.size() ; i++) {

            a[i]*=(-1);

        }

    }

    long long res=accumulate(a.begin(),a.end(),0LL);

    while(can>0) {

        auto it = min_element(a.begin(),a.end()) - a.begin();

        res-=(2*a[it]);

        a[it]=LONG_MAX;

        can--;

    }

    return res;

}

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    vector<long long> a(n);

    for(long long i = 0 ; i < n ; i++) {

        cin >> a[i];

    }

    long long res=0;

    long long mini = n/2;

    long long maxi = n-1;

    for(long long i=mini; i<=maxi; i++) {

        long long cur = max(solve(a,i),solve(a,i,1));

        res = max(res,cur);

    }

    cout << res << '\n';

    return 0;

}


#include <fstream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
//#include <unordered_map>
#include <iomanip>
#include <time.h>
#include <stdio.h>
#include <bitset>
#include <map>
#include <ctime>
#include <stdlib.h>
#define MAX 500000000000
#include <iostream>
#include <deque>
//#include "PEZai.h"
//#include <Tlhelp32.h>
using namespace std;
#define UNDEFINED 32432523
int n, x[200005], k;
string s;
void show_sum() {
    for(int i = 0; i < n; i++)
        cout << x[i] << " ";
    cout << "\n";
}
long long getMaxSum(int head, int tail) {
    long long sumMax = 0;
    sort(x + head, x + tail + 1);
    for(int i = tail; i >= max(head, tail - k + 1); i--) {
        sumMax += x[i];
    }
    return sumMax;
}
int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    cin >> s;
    int head = 0, tail = 0;
    long long sum = 0;
    for(int i = 0; i < s.size(); i++) {
        head = i;
        tail = i;
        while(s[tail] == s[tail + 1]) {
            tail++;
        }
        sum += getMaxSum(head, tail);
        i = tail;
    }
    cout << sum;
}


#include<iostream>
#include<algorithm>

using namespace std;

struct Button
{
	int times;
	char name;
}all[200005];

bool compares(Button a, Button b)
{
	return a.times > b.times;
}

int main()
{
	int n, k;
	cin>>n>>k;
	for(int i = 0; i < n; i++)
		cin>>all[i].times;
	for(int i = 0; i < n; i++)
		cin>>all[i].name;
	all[n].name = 'N';
	all[n].times = 0;
	int begin = 0, end = 1;
	char now = all[0].name;
	for(int i = 1 ; i <= n; i++)
	{
		if(now != all[i].name)
		{
			end = i;
			now = all[i].name;
			sort(all + begin, all + end, compares);
			begin = i;
		}
	}
//	for(int i = 0; i < n; i++)
//		cout<<all[i].times<<endl;
	long long dmg = all[0].times;
	int time = 1;
	now = all[0].name;
	for(int i = 1; i <= n; i++)
	{
		if(now != all[i].name)
		{
			dmg += all[i].times;
			time = 1;
			now = all[i].name;
		}
		else if(time < k)
		{
			dmg += all[i].times;
			time++;
		}
	//	cout<<dmg<<" "<<time<<endl;
	}
	cout<<dmg<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
priority_queue<ll>pq;
ll qwq[2];
char ch[200005];
ll aa[200005];
int main()
{
    ll n,k;
    cin>>n>>k;
    int tot=0;
    int ts=0;
    ll ans=0;
    for(int i=1;i<=n;i++){
        scanf("%lld",&aa[i]);
    }
    scanf("%s",ch+1);
    for(int i=1;i<=n;i++){
        if(i>1&&ch[i]!=ch[i-1]){
            ts=0;
            while(ts<k&&!pq.empty()){
                ll xx=pq.top();pq.pop();
                ans+=xx;
                ts++;
            }
            while(!pq.empty())pq.pop();
            pq.push(aa[i]);
       }
        else{
            pq.push(aa[i]);
        }
    }
    ts=0;
            while(ts<k&&!pq.empty()){
                ll xx=pq.top();pq.pop();
                ans+=xx;
                ts++;
            }
            cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n = 0, m = 0, l = 1;
    long long sum = 0;
    string s = "";
    cin >> n >> m;
    vector<int> buf1(n + 1, 0);
    vector<int> buf2;
    for (int i = 0; i < n; i++) {
        cin >> buf1[i];
    }
    cin >> s;
    s += ' ';
    for (int i = 1; i <= n; i++) {
        if (l == 1) {
            buf2.push_back(buf1[i - 1]);
        }
        if (s[i] == s[i - 1]) {
            buf2.push_back(buf1[i]);
            l++;
        }
        else {
            sort(buf2.rbegin(), buf2.rend());
            l = min(l, m);
            for (int j = 0; j < l; j++) {
                sum += buf2[j];
            }
            buf2.clear();
            l = 1;
        }
    }
    cout << sum;
}


n,k = tuple(map(int,input().split()))
hit = list(map(int,input().split()))
s = input()
cons_count = 1
su = 0
ar = [hit[0]]
i = 0
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cons_count = cons_count+1
    else:
        ar = hit[i-cons_count:i]
        if cons_count>k:
            ar.sort()
            su = su+sum(ar[-k:])
#            print(su)
        else:
            su = su+sum(ar)
#            print(su)
        cons_count = 1
        ar = [hit[i]]
if cons_count>k:
    ar = hit[-cons_count:]
    ar.sort()
    su = su+sum(ar[-k:])
else:
    su = su+sum(hit[-cons_count:])
print(su)


n,k = tuple(map(int,input().split()))
hit = list(map(int,input().split()))
s = input()
cons_count = 1
su = 0
ar = [hit[0]]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cons_count = cons_count+1
    else:
        if cons_count>k:
            ar = hit[i-cons_count:i]
            ar.sort()
            su = su+sum(ar[-k:])
#            print(su)
        else:
            su = su+sum(ar)
#            print(su)
        cons_count = 1
        ar = [hit[i]]
if cons_count>k:
    ar = hit[-cons_count:]
    ar.sort()
    su = su+sum(ar[-k:])
else:
    su = su+sum(hit[-cons_count:])
print(su)


n,k = tuple(map(int,input().split()))
hit = list(map(int,input().split()))
s = input()
cons_count = 1
su = 0
ar = [hit[0]]
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        cons_count = cons_count+1
    else:
        if cons_count>k:
            ar = hit[i-1:i-cons_count-1:-1]
            ar.sort()
            su = su+sum(ar[-k:])
            print(su)
        else:
            su = su+sum(ar)
            print(su)
        cons_count = 1
        ar = [hit[i]]
if cons_count>k:
    ar = hit[-cons_count:]
    ar.sort()
    su = su+sum(ar[-k:])
else:
    su = su+sum(hit[-cons_count:])
print(su)


n,lim=map(int,input().split())
a=[int(i)for i in input().split()]
b=input()
i=0
d=[1]
now=b[0]
for i in range(1,n):
    if b[i]==now:
        d[-1]+=1
    else:
        now=b[i]
        d.append(1)
dmg=0
now=0
for r in d:

    c=a[now:now+r]
    now=now+r
    c.sort(reverse=True)
    dmg+=sum(c[:lim])
print(dmg)


n, k = map(int, input().split())
a = list(map(int, input().split()))
s = input()
ans = 0
i = 0
while i < n:
	j = i
	b = []
	while j<n and s[i]==s[j]:
		b.append(a[j])
		j += 1
	b.sort(reverse=True)
	ans += sum(b[0:min(len(b),k)])
	i = j
print(ans)


n, k = map(int, input().split())
a = list(map(int, input().split()))
s = input()

i = 0; res = 0
while i <= n-1:
    j = i+1
    while j <= n-1 and s[j] == s[i]: j += 1
    res += sum(sorted(a[i:j], reverse = True)[:k])
    i = j

print(res)


from heapq import *
n,k = map(int, input().split())
dmg = list(map(int, input().split()))
arr  = input()
hp = []
tot = 0
for i in range(n):
	if len(hp) == 0:
		heappush(hp, dmg[i])
	else:
		if arr[i] != arr[i-1]:
			for j in hp:
				tot = tot + j
			hp = []
			heappush(hp, dmg[i])
		else:
			heappush(hp, dmg[i])
			if len(hp) > k:
				heappop(hp)
for i in hp:
	tot = tot + i
print(tot)


n, k = map(int, input().split())

a = list(map(int, input().split()))

s = input()

dmg, i, j = 0, 0, 1

while j < n:
	if s[j] == s[i]:
		j += 1
	else:
		dmg += sum(sorted(a[i:j])[-k:])
		i, j = j, j + 1

dmg += sum(sorted(a[i:j])[-k:])

print(dmg)


# import bisect
I = lambda: map(int, input().rstrip().split())
n, k = I()
a = list(I())
s = input()
ans = 0
j = 0
for i in range(n):
    if (i == n - 1 or s[i] != s[i + 1]):
        ans += sum(sorted(a[j:i + 1])[-k:])
        j = i + 1
print(ans)


import bisect
I = lambda: map(int, input().rstrip().split())
n, k = I()
a = list(I())
s = input()
ans = 0
li = [a[0]]
for i in range(1, n + 1):
    if i < n and s[i] == s[i - 1]:
        bisect.insort(li, a[i])
    else:
        # print(li)
        m = min(k, len(li))
        li.reverse()
        ans += sum(li[:m])
        # print(ans)
        if i < n:
            li = [a[i]]
print(ans)


import bisect
I = lambda: map(int, input().rstrip().split())
n, k = I()
a = list(I())
s = input()
ans = 0
li = [a[0]]
t = 1
for i in range(1, n + 1):
    if i < n and s[i] == s[i - 1]:
        bisect.insort(li, a[i])
        t += 1
    else:
        # print(li)
        m = min(k, t)
        ans += sum(li[t - m:t])
        # print(ans)
        t = 1
        if i < n:
            li = [a[i]]
print(ans)


n,k=list(map(int,input().split()))
ka=list(map(int,input().split()))
l=input()
ja=[]
s=0
sa=0
for x in range(n):
    ja.append(ka[x])
    s+=1
    if x!=n-1 and l[x]==l[x+1]:
        pass
    elif x==n-1:
        if s==1:
            sa+=ka[-1]
        else:
            ja.sort(reverse=True)
            sa+=sum(ja[0:k])
    else:
        if s<=k:
            sa+=sum(ja)
            s=0
        else:
            ja.sort(reverse=True)
            sa+=sum(ja[0:k])
            s=0
        ja=[]
print(sa)


n,k=list(map(int,input().split()))
ka=list(map(int,input().split()))
l=input()
ja=[]
s=0
sa=0
for x in range(n):
    ja.append(ka[x])
    s+=1
    if x!=n-1 and l[x]==l[x+1]:
        pass
    elif x==n-1:
        if s==1:
            sa+=ka[-1]
        else:
            ja.sort(reverse=True)
            sa+=sum(ja[0:k])
    else:
        if s<=k:
            sa+=sum(ja)
        else:
            ja.sort(reverse=True)
            sa+=sum(ja[0:k])
            s=0
        ja=[]
print(sa)


n,k=map(int,input().split())
a=list(map(int,input().split()))
s=input()
re=sum(a)
cc=[]
f,t=0,0
while t<n:
        t+=1
        while t<n and s[t]==s[t-1]:t+=1
        cc=a[f:t]
        if len(cc)>k:
                cc.sort()
                for i in range(len(cc)-k): re-=cc[i]
        f=t
print(re)


n, k = map(int, input().split())
A = list(map(int, input().split()))
if n == 1:
    print(A[0])
else:
    s = input()
    hop = dict()
    hop[0] = [A[0]]
    cnt = 0
    if s[0] == s[1]:
        q = 0
    else:
        q = 1
    fl = 1
    for t in range(1, n):
        if s[t] != s[t-1]:
            q += 1
            hop[q] = [A[t]]
        else:
            hop[q].append(A[t])
    for y in hop:
        z = hop[y]
        z = sorted(z, reverse=True)
        if len(z) > k:
            cnt += sum(z[:k])
        else:
            cnt += sum(z)
    print(cnt)


n,k=map(int,input().split())
A=list(map(int,input().split()))
S=input()
ans=j=0
n=len(S)
for i in range(n):
    if (i==n-1 or S[i]!=S[i+1]):
        ans+=sum(sorted(A[j:i+1])[-k:])
        # print(j, i)
        j=i+1
print(ans)


n, m = map(int, input().split())
d = list(map(int, input().split()))
s = input()
i = res = 0
while i < len(s):
    j = i;
    while i+1 < len(s) and s[i+1] == s[i]:
        i += 1
    res += sum(sorted(d[j:i+1])[-m:])
    i += 1

print(res)


n,k=map(int,input().split())
a=list(map(int,input().split()))
seq=input()

active,start,count=seq[0],0,1
summ_rem=0
while start+count<len(seq):
    if seq[start+count]==active:
        count+=1
    else:
        if count>k:
            ch = a[start:start + count]
            ch.sort()
            rem=sum(ch[0:count-k])
            summ_rem+=rem
        active=seq[start+count]
        start,count=start+count,1
if count>k:
    ch = a[start:start + count]
    for i in range(count-k):
        rem=min(ch)
        ch.remove(rem)
        summ_rem+=rem

print(sum(a)-summ_rem)


n,k=map(int,input().split())
a=list(map(int,input().split()))
seq=input()

active,start,count=seq[0],0,1
summ_rem=0
while start+count<len(seq):
    if seq[start+count]==active:
        count+=1
    else:
        if count>k:
            ch = a[start:start + count]
            for i in range(count-k):
                rem=min(ch)
                ch.remove(rem)
                summ_rem+=rem
        active=seq[start+count]
        start,count=start+count,1
if count>k:
    ch = a[start:start + count]
    for i in range(count-k):
        rem=min(ch)
        ch.remove(rem)
        summ_rem+=rem

print(sum(a)-summ_rem)


n,k=map(int,input().split())
a=list(map(int,input().split()))
seq=input()

active,start=seq[0],0
summ=sum(a)
for i,j in enumerate(seq):
    if j!=active or i==len(seq)-1:
        if i == len(seq) - 1:
            i+=1
        if i-start>k:
            ch=a[start:i]
            ch.sort()
            rem=sum(ch[0:(i-start)-k])
            summ-=rem
        start,active=i,j
print(summ)


n,k=map(int,input().split())
a=list(map(int,input().split()))
seq=input()

active,start=seq[0],0
summ=sum(a)
for i,j in enumerate(seq):
    if j!=active:
        if i-start>k:
            ch=a[start:i]
            ch.sort()
            rem=sum(ch[0:(i-start)-k])
            summ-=rem
        start,active=i,j
    if i == len(seq) - 1:
        i+=1
        if i-start>k:
            ch=a[start:i]
            ch.sort()
            rem=sum(ch[0:(i-start)-k])
            summ-=rem
        start,active=i,j
print(summ)


n, k = map(int, input().split())
a = list(map(int, input().split()))
S = input()

i = res = 0
while i < len(S):
	j = i
	while i+1 < len(S) and S[i+1] == S[i]: i += 1
	res += sum(sorted(a[j:i+1])[-k:])
	i += 1

print(res)


def main():
    n, k = map(int, input().split())
    arr = list(map(int, input().split()))
    s = input() + '0'
    ans = sum(arr)
    prev, cnt = s[0], 1

    for i in range(1, len(s)):
        sym = s[i]
        if sym == prev:
            cnt += 1
        else:
            if cnt > k:
                ans -= sum(sorted(arr[i - cnt:i])[:cnt - k])
            cnt = 1
        prev = sym
    print(ans)
main()


n, k = map(int, input().split())
arr = list(map(int, input().split()))
s = input() + 'A'
ans = sum(arr)
prev, cnt = s[0], 1

for i in range(1, len(s)):
    sym = s[i]
    if sym == prev:
        cnt += 1
    else:
        ans -= sum(sorted(arr[i - cnt:i])[:cnt - k])
        cnt = 1
    prev = sym
print(ans)


list_int_input = lambda inp: list(map(int, inp.split()))
int_input = lambda inp: int(inp)
string_to_list_input = lambda inp: list(inp)

nk=list_int_input(input())
a=list_int_input(input())
s=string_to_list_input(input())

i,j=0,0
sm=0
while i<nk[0]:
    while j<nk[0] and s[i]==s[j]:
        j+=1
    if (j-i)>nk[1]:
        sa=sorted(a[i:j])
        sm+=sum(sa[-nk[1]:])

    else:
        sm+=sum(a[i:j])
    i=j
print(sm)


k = int(input().split()[1])
dmg = [int(i) for i in input().split()]
dmg.append(0)
letters = input()+'*'
max_map = {}

times = 0
let = '*'
arr = []
result = 0
for i in range(len(dmg)):
    if not let == letters[i]:
        if times > k:
            arr.sort(reverse=True)
            result+=sum(arr[0:k])
        else:
            result+=sum(arr)
        let = letters[i]
        times = 1
        arr = [dmg[i]]
    else:
        times +=1
        arr.append(dmg[i])

print(result)


k = int(input().split()[1])
dmg = [int(i) for i in input().split()]
letters = input()
max_map = {}

for i in range(len(dmg)):
    letter = letters[i]
    if letter in max_map:
        max_map[letter].append(dmg[i])
    else:
        max_map[letter] = [dmg[i]]

max_val = 0
for key in max_map:
    if len(max_map[key])>k:
        max_map[key].sort(reverse=True)
        max_val += sum(max_map[key][0:k])
    else:
        max_val += sum(max_map[key])

print(max_val)


n, k = map(int, input().split())
dmg = list(map(int, input().split()))
keys = input() + '!'
summary = 0
i = 0
while i < n:
    if keys[i+1] == keys[i]:
        accu = keys[i]
        start = i
        i+=1
        while keys[i] == accu and i < n:
            i+=1
        mono = sorted(dmg[start:i], reverse = True)
        maykick = min(len(mono), k)
        summary+=sum(mono[:maykick])
    else:
        summary+=dmg[i]
        i+=1
print(summary)


from itertools import groupby

n, k = map(int, input().split())
dmg = map(int, input().split())
seq = input()
pairs = list(zip(seq, dmg))
ret = 0
for subseq in groupby(pairs, lambda x: x[0]):
    _, subseq = subseq
    subseq = [i[1] for i in subseq]
    subseq.sort()
    start = max(len(subseq) - k, 0)
    ret += sum(subseq[start:])
print(ret)


n,m=map(int,input().split())
a=list(map(int,input().split()))
s=input()
k=0
l=0
while l<n:
    f=l+1
    while f<n and s[f]==s[l]:
        f+=1
    b=sorted(a[l:f])
    k+=sum(b[-m:])
    l=f
print(k)


# Author: Narut Sereewattanawoot
def Read(f = int):
  return [f(x) for x in input().split()]

def FloatsToString(arr):
  return ' '.join('{:.10f}'.format(x) for x in arr)

n, k = Read(int)

A = Read(int)
s = input()

tmp = []
prev = ' '
dmg = 0
for i in range(n):
  if s[i] != prev:
    if k < len(tmp):
      tmp.sort(reverse=True)
      dmg += sum(tmp[:k])
    else:
      dmg += sum(tmp)
    tmp.clear()
  tmp.append(A[i])
  prev = s[i]

if k < len(tmp):
  tmp.sort(reverse=True)
  dmg += sum(tmp[:k])
else:
  dmg += sum(tmp)

print(dmg)


#include <bits/stdc++.h>
constexpr bool Interactive = false;

namespace Narut {

  struct {
    template <class T> auto operator<<(const T& t) const -> decltype((void) (std::cerr << t), *this) { std::cerr << "\033[0;31m" << t << "\033[0m"; return *this; }
    auto operator<< (std::ostream& (*f)(std::ostream&)) const { std::cerr << f; return *this; }
  } Cerr_red;
  #define CAN_(f) template <class, class=void> struct Can##f : std::false_type {}; template <class T> struct Can##f<T, decltype((void)f(std::declval<T&>())) > : std::true_type {};

  template <class T, class=void> struct IsIterable : std::false_type {}; template <class T> struct IsIterable<T, decltype((void)std::begin(std::declval<T&>()), (void)std::end(std::declval<T&>())) > : std::true_type {};

  template <decltype(auto) os, bool Flush = false, decltype(auto) PairSep = ' ', decltype(auto) PairEnd = '\n'>
  struct Writer {
    static constexpr char Sep = ' ', Sep2D = '\n';
    template <class, class = void> struct Osable : std::false_type {};
    template <class T> struct Osable<T, decltype((void)(os << std::declval<T&>())) > : std::true_type {};
    template <class Tuple, std::size_t... Is> static void TupleImpl(const Tuple& t, std::index_sequence<Is...>) { (void) (int[]) {0, (Write(PairSep), Write(std::get<Is+1>(t)), 0)... }; }
    template <class First, class... Ts> static void TupleImpl(const std::tuple<First, Ts...> &t) { Write(std::get<0>(t)); if constexpr (sizeof...(Ts) != 0) TupleImpl(t, std::index_sequence_for<Ts...>{}); }
    static void TupleImpl(const std::tuple<>&) {}
    template <class F, class S> static void PairImpl(const std::pair<F,S>& p) { Write(p.first), Write(PairSep), Write(p.second); }
    CAN_(PairImpl) CAN_(TupleImpl)
    template <class T> static void SepImpl (const T&) {
      if constexpr ( Osable<T>::value ) os << Sep;
      else if constexpr ( CanPairImpl<T>::value or CanTupleImpl<T>::value ) os << PairEnd;
      else os << Sep2D;
    }
    template <class T> static void IterableImpl(const T& t) {
      using std::begin, std::end;
      auto it = begin(t);
      if (it != end(t)) Write(*it++);
      while (it != end(t)) SepImpl(*it), Write(*it++);
    }
    template <class T> static void Write(const T& t) {
      if constexpr ( Osable<T>::value ) os << t;
      else if constexpr ( CanPairImpl<T>::value ) PairImpl(t);
      else if constexpr ( CanTupleImpl<T>::value ) TupleImpl(t);
      else if constexpr ( IsIterable<T>::value ) IterableImpl(t);
      else static_assert( IsIterable<T>::value, "No Matching Write Call!");
    }
    auto operator() () const { if constexpr (Flush) os << std::endl; else os << '\n'; return *this; }
    template <class First, class... Args> auto operator() (const First& f, const Args&... args) const { Write(f); (void) (int[]) {0, (Write(Sep), Write(args), 0)... }; return (*this)(); }
  };

  template <decltype(auto) is>
  struct Reader {
    template <class, class = void> struct Isable : std::false_type {}; template <class T> struct Isable<T, decltype((void)(is >> std::declval<T&>()))  > : std::true_type {};
    template <class T, class S> static void PairImpl(std::pair<T, S> &p) { Read(p.first); Read(p.second); }
    template <class Tuple, std::size_t... Is> static void TupleImpl(Tuple &t, std::index_sequence<Is...>) { (void) (int[]) {0, ( Read(std::get<Is>(t)), 0)... }; }
    template <class... Ts> static void TupleImpl(std::tuple<Ts...> &t) { TupleImpl(t, std::index_sequence_for<Ts...>{}); }
    template <class T> static void IterableImpl(T& t) { for (auto && x : t) Read(x); }
    CAN_(PairImpl) CAN_(TupleImpl)
    template <class T> static void Read(T& x) {
      if constexpr ( Isable<T>::value ) is >> x;
      else if constexpr ( CanPairImpl<T>::value ) PairImpl(x);
      else if constexpr ( CanTupleImpl<T>::value ) TupleImpl(x);
      else if constexpr ( IsIterable<T>::value ) IterableImpl(x);
      else static_assert ( IsIterable<T>::value, "No Matching Read!");
    }
    template <class T> operator T() const { T x; Read(x); return x; }
    template <class... Ts> auto operator() (Ts&... ts) const { (void) (int[]) { 0, (Read(ts), 0)... }; return *this; }
  };

  #ifdef NARUT_LOCAL
  Writer<(Cerr_red), false, ':', ' '> Debug;
  #else
  struct { template <class... Args> void operator()(Args&&...) const {} } Debug;
  #endif

  template <class T, int off=1> struct Offset : T {
    using T::T;
    Offset(const T& other) : T(other) {}
    Offset(T&& other) noexcept : T(std::move(other)) {}
    decltype(auto) operator[] (int i) { return T::operator[](i-off); }
    decltype(auto) operator[] (int i) const { return T::operator[](i-off); }
    decltype(auto) at (int i) { return T::at(i-off); }
    decltype(auto) at (int i) const { return T::at(i-off); }
  };

  template <class T> struct Vec : std::vector<T> {
    using std::vector<T>::vector;
    Vec(const std::vector<T>& other) : std::vector<T>(other) {}
    Vec(std::vector<T>&& other) noexcept : std::vector<T> (std::move(other)) {}
    Vec& operator() (int n) { this->resize(n); return *this; }
    Vec& operator()(int n, const T& t) { this->assign(n,t); return *this; }
  };

  template <class T, template <class Elem> class Base> struct MatBase : Base<Base<T> > {
    MatBase() = default;
    MatBase(int n) : Base<Base<T> >(n) {}
    MatBase(int n, int m, const T& t = {}) : Base<Base<T> >(n) { for (auto &v : *this) v.assign(m, t); }
    MatBase& operator() (int n) { this->resize(n); return *this; }
    MatBase& operator() (int n, int m, const T& t = {}) { this->resize(n); for (auto &v : *this) v.assign(m, t); return *this; }
  };

  template <template<class Elem, int S> class Base, class T, int NF, int... Ns>
  struct ArrRec : Base<ArrRec<Base, T, Ns...>, NF> {
    using Base<ArrRec<Base, T, Ns...>, NF>::Base;
    ArrRec& operator() (const T& t) { for (auto &a : *this) a(t); return *this; }
  };
  template <template<class Elem, int S> class Base, class T, int NF> struct ArrRec<Base, T, NF> : Base<T, NF> { using Base<T, NF>::Base; };

  template <class T, int N> struct ArrBase : std::array<T, N> {
    constexpr ArrBase() {}
    constexpr ArrBase (std::initializer_list<T> il) { int i = 0; for (auto a : il) (*this)[i++] = a; }
    constexpr ArrBase(const std::array<T, N>& other) : std::array<T, N>(other) {}
    constexpr ArrBase(std::array<T, N>&& other) : std::array<T, N>(std::move(other)) {}
    ArrBase& operator() (const T& t) { this->fill(t); return *this; }
  };
  template <class T, int N> using ArrBase1 = Offset<ArrBase<T, N> >;

  template <class T, class = void> struct Greater { constexpr bool operator() (const T& lhs, const T& rhs) const { return rhs < lhs; } };
  template <class T> struct Greater<T, decltype((void)(std::declval<T&>() > std::declval<T&>()))> : std::greater<T> {};

  template <class T> using MaxPQ = std::priority_queue<T>;
  template <class T> using MinPQ = std::priority_queue<T, std::vector<T>, Greater<T> >;

  namespace Nrt {
    template <class T> auto min (const T& t) { return *std::min_element(std::begin(t), std::end(t)); }
    template <class T> auto max (const T& t) { return *std::max_element(std::begin(t), std::end(t)); }
    template <class T> auto minmax(const T& t) { auto [f, s] = std::minmax_element(std::begin(t), std::end(t)); return std::make_pair(*f, *s); }
    template <class T, class U=typename T::value_type> auto sum (const T& t, U u = {}) { return std::accumulate(std::begin(t), std::end(t), u); }
    template <class T> auto partial_sum(const T& t) { auto ps = t; std::partial_sum(std::begin(ps), std::end(ps), std::begin(ps)); return ps; }
    template <class T> void sort(T& t) { std::sort(std::begin(t), std::end(t)); }
    template <class T=int> auto iota(int n, const T& t={}) { Vec<T> v(n); std::iota(v.begin(), v.end(), t); return v; }
    template <class It, class T> constexpr auto find_last(It first, It last, const T& val) { auto ret = last; for (; first != last; ++first) if (*first == val) ret = first; return ret; }
    template <class It, class Pred> constexpr auto find_last_if(It first, It last, Pred p) { auto ret = last; for (; first != last; ++first) if (p(*first)) ret = first; return ret; }
  }
  // Fast IO:
  void IO() {
    #ifdef NARUT_LOCAL
    #define NAME "io/test"
    if (!Interactive and !freopen(NAME ".in", "r", stdin)) Debug("freopen failed");
    // freopen(NAME ".out", "w", stdout);
    std::cerr << std::fixed << std::setprecision(10) << std::boolalpha;
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(10);
  }

  namespace Export {
    // IO Globals:
    namespace nrt = Narut::Nrt;
    Writer<(std::cout), Interactive> Cout;
    Reader<(std::cin)> Cin;
    using Narut::Debug, Narut::MaxPQ, Narut::MinPQ, Narut::Offset, Narut::Vec;
    using ll = long long;
    using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>;
    template <class T> using Vec1 = Offset<Vec<T> >;
    using Vi = Vec<int>; using Vi1 = Vec1<int>; using Vl = Vec<ll>; using Vb = Vec<bool>;
    template <class T> using Mat = MatBase<T, Vec>;
    template <class T> using Mat1 = MatBase<T, Vec1>;
    template <class T, int N, int... Ns> using Arr = ArrRec<Narut::ArrBase, T, N, Ns...>;
    template <class T, int N, int... Ns> using Arr1 = ArrRec<Narut::ArrBase1, T, N, Ns...>;

    using std::abs, std::accumulate, std::acos, std::acosh, std::array, std::asin, std::asinh, std::atan, std::atanh, std::binary_search, std::bitset, std::cbrt, std::ceil, std::cin, std::cos, std::cosh, std::cout, std::deque, std::div, std::equal_range, std::exp, std::floor, std::gcd, std::get, std::getline, std::hypot, std::iota, std::istringstream, std::lcm, std::ldexp, std::log, std::lower_bound, std::map, std::max, std::max_element, std::min, std::min_element, std::minmax, std::minmax_element, std::multimap, std::multiset, std::nearbyint, std::next_permutation, std::optional, std::ostringstream, std::pair, std::partial_sum, std::pow, std::prev_permutation, std::queue, std::reverse, std::rint, std::round, std::runtime_error, std::set, std::shared_ptr, std::sin, std::sinh, std::sort, std::sqrt, std::stable_sort, std::stack, std::stod, std::stof, std::stoi, std::stol, std::stold, std::stoll, std::string, std::string_view, std::stringstream, std::swap, std::tan, std::tanh, std::to_string, std::trunc, std::tuple, std::unique, std::unique_ptr, std::unordered_map, std::unordered_multimap, std::unordered_multiset, std::unordered_set, std::upper_bound, std::vector;
  }
}
using namespace Narut::Export;

int n, k;
Vi A;
Vi tmp;
string s;

ll Take()
{
  auto last = tmp.end();
  if (k < tmp.size()) {
    std::nth_element(tmp.begin(), tmp.begin()+k, tmp.end(), std::greater{});
    last = tmp.begin()+k;
  }
  auto ret = accumulate(tmp.begin(), last, 0ll);
  tmp.clear();
  return ret;
}

auto Run()
{
  cin>>n>>k;
  Cin(A(n));
  cin>>s;

  ll dmg = 0;

  char cur_c = 0;
  for (int i = 0; i < n; i++) {
    char c = s[i];
    if (cur_c != c) {
      dmg += Take();
    }
    tmp.push_back(A[i]);
    cur_c = c;
  }
  dmg += Take();

  cout << dmg;
}

int main() {
  Narut::IO();
  Run();
}


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from itertools import *
n,k=f()
l=il()
s=si()
l1=[]
for i,j in groupby(s):
    l1.append(len(list(j)))
n1=len(l1)
j=0
sm=0
for i in l1:
    if i>k:
        sm+=sum(sorted(l[j:j+i],reverse=True)[:k])
    else:
        sm+=sum(l[j:j+i])
    j+=i
print(sm)


def main():
    n,k = map(int,input().split())
    damage = list(map(int,input().split()))
    s = input()
    hits = []
    ans = 0
    curr = s[0]
    for i in range(n):
        if s[i] == curr:
            hits.append(damage[i])
        else:
            hits.sort(reverse = True)
            ans += sum(hits[:k])
            curr = s[i]
            hits = [damage[i]]

    hits.sort(reverse = True)
    ans += sum(hits[:k])

    print(ans)

main()


import math
import sys

if __name__ == '__main__':
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	nums = list(map(int,input().split()))
	s = input()
	startIndex = 0
	prevChar = ' '
	chainCount = 0
	result = sum(nums)
	for i in range(len(s)):
		if prevChar == s[i]:
			chainCount += 1
		else:
			if chainCount > k:
				tempArr = nums[startIndex:i]
				tempArr.sort()
				for j in range(len(tempArr) - k):
					result -= tempArr[j]
			chainCount = 1
			prevChar = s[i]
			startIndex = i
	if chainCount > k:
		tempArr = nums[startIndex:n]
		tempArr.sort()
		for j in range(len(tempArr) - k):
			result -= tempArr[j]
	print(result)


n,k = map(int,input().split())
hits = list(map(int,input().split()))
sequence = input()
count=1
total = 0
for i in range(1,n+1):
    if(i==n or sequence[i]!=sequence[i-1]):
        x = hits[i-count:i]
        x.sort()
        total+=sum(x[max(0,len(x)-k):len(x)])
        count=1
    else:
        count+=1
print(total)


# -*- coding: utf-8 -*-
"""
Created on Fri Mar  1 15:59:06 2019

@author: screamLab
"""

n,k = [int(s) for s in input().split(' ')]
num = [int(s) for s in input().split(' ')]
string = input()

prev = None
total = 0
same = []
for i in range(n):
    if string[i] == prev:
        same.append(num[i])
    else:
        total += sum(sorted(same, reverse=True)[:k])
        prev = string[i]
        same = [num[i]]
total += sum(sorted(same, reverse=True)[:k])
print(total)


from heapq import *
n,k = map(int, input().split())
dmg = list(map(int, input().split()))
arr  = input()
hp = []
tot = 0
for i in range(n):
	if len(hp) == 0:
		heappush(hp, dmg[i])
	else:
		if arr[i] != arr[i-1]:
			for j in hp:
				tot = tot + j
			hp = []
			heappush(hp, dmg[i])
		else:
			heappush(hp, dmg[i])
			if len(hp) > k:
				heappop(hp)
for i in hp:
	tot = tot + i
print(tot)


n,k=map(int,input().split())
a=list(map(int,input().split()))
a.append(0)
s=input()+'!'
ans,L,R=0,0,1
while R<=n:
    if s[L]==s[R]:
        R+=1
    else:
        ans+=sum(sorted(a[L:R])[-k:])
        L=R
        R+=1
print(ans)


n,m = map(int,input().split())
a = list(map(int,input().split()))
s = str(input())
k = 0
ans = 0
i = 0
while i<n:
    k=0
    if i == n-1:
        ans+=a[i]
        break
    if s[i] == s[i+1]:
        ls1 = []
        count = 0
        k += 1
        ls1.append(a[i])
        count += a[i]
        for j in range(i+1,n):
            if s[j] == s[j-1]:
                k += 1
                ls1.append(a[j])
                count += a[j]
            else:
                break
        if k <= m:
            ans += count
        else:
            ls1.sort()
            l = 0
            for x in reversed(ls1):
                ans += x
                l += 1
                if l == m:
                    break
        i += k
    else:
        ans += a[i]
        i += 1
print(ans)


def max_sum(m, n):
    if n >= len(m):
        return sum(m)
    else:
        return sum(sorted(m)[len(m) - n:])

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    s = []
    prev_c = ""
    it = -1
    pos = -1
    for c in input():
        pos += 1
        if c != prev_c:
            prev_c = c
            it += 1
            s.append([pos, pos + 1])
        else:
            s[it][1] += 1

    ans = 0
    for ss in s:
        ans += max_sum(a[ss[0]:ss[1]], k)

    print(ans)

if __name__ == "__main__":
    main()


n=int(input())
l=input().split()
l=list(map(int,l))
s=input()

q=[]

l=[1,5,16,18,7,2,10]

m=s[0]
f=0
q=[l[0]]
for i in range(1,len(s)):
    if s[i]==m:
        q.append(l[i])
    else:
        m=s[i]
        q.sort(reverse=True)
        f=f+sum(q[:3])
        q=[]
        q.append(l[i])
q.sort(reverse=True)
f=f+sum(q[:3])
print(f)


n,r=int(input())
l=input().split()
l=list(map(int,l))
s=input()

r=int(r)
q=[]

l=[1,5,16,18,7,2,10]

m=s[0]
f=0
q=[l[0]]
for i in range(1,len(s)):
    if s[i]==m:
        q.append(l[i])
    else:
        m=s[i]
        q.sort(reverse=True)
        f=f+sum(q[:r])
        q=[]
        q.append(l[i])
q.sort(reverse=True)
f=f+sum(q[:r])
print(f)


n,r=input().split()
l=input().split()
l=list(map(int,l))
s=input()

r=int(r)
q=[]

l=[1,5,16,18,7,2,10]

m=s[0]
f=0
q=[l[0]]
for i in range(1,len(s)):
    if s[i]==m:
        q.append(l[i])
    else:
        m=s[i]
        q.sort(reverse=True)
        f=f+sum(q[:r])
        q=[]
        q.append(l[i])
q.sort(reverse=True)
f=f+sum(q[:r])
print(f)