#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#define lowbit(x) x&(-x)
#define mes(x, a) memset(x, a, sizeof x)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
const int N = 1e5+10;
const int M = 1e5;
const int INF = 1e9+7;
const int mod = 1e9+7;

inline int read()
{
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')w=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

int dis[N][10];
int vis[N];
int sss[N];

void Fun(int x, int y)
{
    if ( x==y ) return;
    for (int i=0; i<7; i++ )
    {
        if ( dis[x][i]==y ) return;
        if (dis[x][i]) continue;
        else
        {
            dis[x][i]=y;
            return;
        }
    }
}

int Find(int x, int y, int z)
{
    for ( int i=0; i<7; i++ )
        for ( int j=0; j<7; j++ )
            if ( dis[x][i]==dis[y][j] && dis[x][i] && dis[y][j] && dis[x][i]!=z)
                return dis[x][i];
    return 0;
}

int main()
{
    mes(vis, 0);
    mes(sss, 0);
    mes(dis, 0);
    int n, k, a, b, c, x, y, z;
    n = read();
    for (int i=1; i<=n-2; i++ )
    {
        a = read();
        b = read();
        c = read();
        if ( !vis[a] || !vis[b] || !vis[c] )
            x=a, y=b, z=c;
        vis[a] ++;
        vis[b] ++;
        vis[c] ++;
        Fun(a, b);
        Fun(a, c);
        Fun(b, a);
        Fun(b, c);
        Fun(c, b);
        Fun(c, a);
    }
    for (int i=1; i<=n; i++ ) sss[i] = vis[i];

    k=n;
    while (k--)
    {
        if ( vis[x] == 1 ) a=x, b=y, c=z;
        if ( vis[y] == 1 ) a=y, b=x, c=z;
        if ( vis[z] == 1 ) a=z, b=y, c=x;
        printf("%d ", a);
        x = Find(b, c, a);
        if ( !x ) break;
        y = b, z = c;
        if ( vis[x]==1 )
        {
            if ( sss[y] > sss[z] ) printf("%d %d %d\n", y, z, x);
            else printf("%d %d %d\n", z, y, x);
            break;
        }
        vis[a]--, vis[b]--, vis[c]--;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <unordered_set>
#include <set>
#include <queue>
#include <bitset>
#include <array>
#include <iomanip>
#include <cmath>
#include <climits>
#include <assert.h>
#include <random>

using namespace std;

int hb(int x) {
    int r = 0;
    while (x > 0) {
        x >>= 1;
        ++r;
    }
    return r;
}

bool res(int x, int y) {
    if (x < 0 || y < 0) {
        return false;
    }
    int r1 = hb(x);
    int r2 = hb(y);
    if (r1 == r2) {
        return r1 == 0;
    }
    if (r1 == 0 || r2 == 0) {
        return false;
    }
    int z = 1 << (max(r1, r2) - 1);
    if (r1 > r2) {
        return res(x - z, y-z/2);
    } else {
        return res(x - z/2, y-z);
    }
}

long long gcd(long long a, long long b) {
    while (a > 0) {
        long long tmp = a;
        a = b % a;
        b = tmp;
    }
    return b;
}

int main() {
    //freopen("/Users/mefimov/a.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> v(n+1);
    for (int i = 0; i < n-2; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        v[x].push_back({min(y, z), max(y, z)});
        v[y].push_back({min(x, z), max(x, z)});
        v[z].push_back({min(x, y), max(x, y)});
    }

    int cur = 0;
    for (int i = 1; i <= n; ++i) {
        if (v[i].size() == 1) {
            cur = i;
            break;
        }
    }

    for (int j = 0; j < n; ++j) {
        cout << cur << " ";
        int x = v[cur][0].first;
        int y = v[cur][0].second;
        v[x].erase(find(v[x].begin(), v[x].end(), make_pair(min(cur, y), max(cur, y))));
        v[y].erase(find(v[y].begin(), v[y].end(), make_pair(min(cur, x), max(cur, x))));
        if (v[x].size() == 1) {
            cur = x;
        } else {
            cur = y;
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <unordered_set>
#include <set>
#include <queue>
#include <bitset>
#include <array>
#include <iomanip>
#include <cmath>
#include <climits>
#include <assert.h>
#include <random>

using namespace std;

int hb(int x) {
    int r = 0;
    while (x > 0) {
        x >>= 1;
        ++r;
    }
    return r;
}

bool res(int x, int y) {
    if (x < 0 || y < 0) {
        return false;
    }
    int r1 = hb(x);
    int r2 = hb(y);
    if (r1 == r2) {
        return r1 == 0;
    }
    if (r1 == 0 || r2 == 0) {
        return false;
    }
    int z = 1 << (max(r1, r2) - 1);
    if (r1 > r2) {
        return res(x - z, y-z/2);
    } else {
        return res(x - z/2, y-z);
    }
}

long long gcd(long long a, long long b) {
    while (a > 0) {
        long long tmp = a;
        a = b % a;
        b = tmp;
    }
    return b;
}

int main() {
    //freopen("/Users/mefimov/a.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> v(n+1);
    for (int i = 0; i < n-2; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        v[x].push_back({min(y, z), max(y, z)});
        v[y].push_back({min(x, z), max(x, z)});
        v[z].push_back({min(x, y), max(x, y)});
    }

    vector<int> d;
    for (int i = 1; i <= n; ++i) {
        if (v[i].size() == 1) {
            d.push_back(i);
        }
    }

    int cur = d[0];
    int last = d[1];
    int plast = v[v[last][0].first].size() == 2 ? v[last][0].first : v[last][0].second;
    for (int j = 0; j < n-3; ++j) {
        cout << cur << " ";
        int x = v[cur][0].first;
        int y = v[cur][0].second;
        v[cur].clear();
        v[x].erase(find(v[x].begin(), v[x].end(), make_pair(min(cur, y), max(cur, y))));
        v[y].erase(find(v[y].begin(), v[y].end(), make_pair(min(cur, x), max(cur, x))));
        if (v[x].size() == 1) {
            cur = x;
        } else {
            cur = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        if (v[i].size() == 1 && i != last && i != plast) {
            cout << i << " ";
            break;
        }
    }
    cout << plast << " " << last << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <unordered_set>
#include <set>
#include <queue>
#include <bitset>
#include <array>
#include <iomanip>
#include <cmath>
#include <climits>
#include <assert.h>
#include <random>

using namespace std;

int hb(int x) {
    int r = 0;
    while (x > 0) {
        x >>= 1;
        ++r;
    }
    return r;
}

bool res(int x, int y) {
    if (x < 0 || y < 0) {
        return false;
    }
    int r1 = hb(x);
    int r2 = hb(y);
    if (r1 == r2) {
        return r1 == 0;
    }
    if (r1 == 0 || r2 == 0) {
        return false;
    }
    int z = 1 << (max(r1, r2) - 1);
    if (r1 > r2) {
        return res(x - z, y-z/2);
    } else {
        return res(x - z/2, y-z);
    }
}

long long gcd(long long a, long long b) {
    while (a > 0) {
        long long tmp = a;
        a = b % a;
        b = tmp;
    }
    return b;
}

int main() {
    //freopen("/Users/mefimov/a.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> v(n+1);
    for (int i = 0; i < n-2; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        v[x].push_back({min(y, z), max(y, z)});
        v[y].push_back({min(x, z), max(x, z)});
        v[z].push_back({min(x, y), max(x, y)});
    }

    vector<int> d;
    for (int i = 1; i <= n; ++i) {
        if (v[i].size() == 1) {
            d.push_back(i);
        }
    }

    int cur = d[0];
    int last = d[1];
    int plast = v[v[last][0].first].size() == 2 ? v[last][0].first : v[last][0].second;
    for (int j = 0; j < n-3; ++j) {
        assert(v[cur].size() == 1);
        cout << cur << " ";
        int x = v[cur][0].first;
        int y = v[cur][0].second;
        v[cur].clear();
        v[x].erase(find(v[x].begin(), v[x].end(), make_pair(min(cur, y), max(cur, y))));
        v[y].erase(find(v[y].begin(), v[y].end(), make_pair(min(cur, x), max(cur, x))));
        if (v[x].size() == 1) {
            cur = x;
        } else {
            cur = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        if (v[i].size() == 1 && i != last && i != plast) {
            cout << i << " ";
            break;
        }
    }
    cout << plast << " " << last << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <unordered_set>
#include <set>
#include <queue>
#include <bitset>
#include <array>
#include <iomanip>
#include <cmath>
#include <climits>
#include <assert.h>
#include <random>

using namespace std;

int hb(int x) {
    int r = 0;
    while (x > 0) {
        x >>= 1;
        ++r;
    }
    return r;
}

bool res(int x, int y) {
    if (x < 0 || y < 0) {
        return false;
    }
    int r1 = hb(x);
    int r2 = hb(y);
    if (r1 == r2) {
        return r1 == 0;
    }
    if (r1 == 0 || r2 == 0) {
        return false;
    }
    int z = 1 << (max(r1, r2) - 1);
    if (r1 > r2) {
        return res(x - z, y-z/2);
    } else {
        return res(x - z/2, y-z);
    }
}

long long gcd(long long a, long long b) {
    while (a > 0) {
        long long tmp = a;
        a = b % a;
        b = tmp;
    }
    return b;
}

int main() {
    //freopen("/Users/mefimov/a.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> v(n+1);
    for (int i = 0; i < n-2; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        v[x].push_back({min(y, z), max(y, z)});
        v[y].push_back({min(x, z), max(x, z)});
        v[z].push_back({min(x, y), max(x, y)});
    }

    vector<int> d;
    for (int i = 1; i <= n; ++i) {
        if (v[i].size() == 1) {
            d.push_back(i);
        }
    }

    int cur = d[0];
    for (int j = 0; j < n-3; ++j) {
        cout << cur << " ";
        int x = v[cur][0].first;
        int y = v[cur][0].second;
        v[cur].clear();
        v[x].erase(find(v[x].begin(), v[x].end(), make_pair(min(cur, y), max(cur, y))));
        v[y].erase(find(v[y].begin(), v[y].end(), make_pair(min(cur, x), max(cur, x))));
        if (v[x].size() == 1) {
            cur = x;
        } else {
            cur = y;
        }
    }
    cout << cur << " ";
    int x = v[cur][0].first;
    int y = v[cur][0].second;
    if (x == d[1]) {
        swap(x, y);
    }
    cout << x << " " << y << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <unordered_set>
#include <set>
#include <queue>
#include <bitset>
#include <array>
#include <iomanip>
#include <cmath>
#include <climits>
#include <assert.h>
#include <random>

using namespace std;

int hb(int x) {
    int r = 0;
    while (x > 0) {
        x >>= 1;
        ++r;
    }
    return r;
}

bool res(int x, int y) {
    if (x < 0 || y < 0) {
        return false;
    }
    int r1 = hb(x);
    int r2 = hb(y);
    if (r1 == r2) {
        return r1 == 0;
    }
    if (r1 == 0 || r2 == 0) {
        return false;
    }
    int z = 1 << (max(r1, r2) - 1);
    if (r1 > r2) {
        return res(x - z, y-z/2);
    } else {
        return res(x - z/2, y-z);
    }
}

long long gcd(long long a, long long b) {
    while (a > 0) {
        long long tmp = a;
        a = b % a;
        b = tmp;
    }
    return b;
}

int main() {
    //freopen("/Users/mefimov/a.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> v(n+1);
    for (int i = 0; i < n-2; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        v[x].push_back({min(y, z), max(y, z)});
        v[y].push_back({min(x, z), max(x, z)});
        v[z].push_back({min(x, y), max(x, y)});
    }

    vector<int> d;
    for (int i = 1; i <= n; ++i) {
        if (v[i].size() == 1) {
            d.push_back(i);
        }
    }

    assert(d.size() == 2);
    int cur = d[0];
    int last = d[1];
    int plast = v[v[last][0].first].size() == 2 ? v[last][0].first : v[last][0].second;
    for (int j = 0; j < n-3; ++j) {
        assert(v[cur].size() == 1);
        cout << cur << " ";
        int x = v[cur][0].first;
        int y = v[cur][0].second;
        v[cur].clear();
        int pxs = v[x].size();
        int pys = v[y].size();
        v[x].erase(find(v[x].begin(), v[x].end(), make_pair(min(cur, y), max(cur, y))));
        v[y].erase(find(v[y].begin(), v[y].end(), make_pair(min(cur, x), max(cur, x))));
        assert(v[x].size() + 1 == pxs);
        assert(v[y].size() + 1 == pys);
        if (v[x].size() == 1) {
            cur = x;
        } else {
            cur = y;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (v[i].size() == 1 && i != last && i != plast) {
            cout << i << " ";
            break;
        }
    }
    cout << plast << " " << last << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <unordered_set>
#include <set>
#include <queue>
#include <bitset>
#include <array>
#include <iomanip>
#include <cmath>
#include <climits>
#include <assert.h>
#include <random>

using namespace std;

int hb(int x) {
    int r = 0;
    while (x > 0) {
        x >>= 1;
        ++r;
    }
    return r;
}

bool res(int x, int y) {
    if (x < 0 || y < 0) {
        return false;
    }
    int r1 = hb(x);
    int r2 = hb(y);
    if (r1 == r2) {
        return r1 == 0;
    }
    if (r1 == 0 || r2 == 0) {
        return false;
    }
    int z = 1 << (max(r1, r2) - 1);
    if (r1 > r2) {
        return res(x - z, y-z/2);
    } else {
        return res(x - z/2, y-z);
    }
}

long long gcd(long long a, long long b) {
    while (a > 0) {
        long long tmp = a;
        a = b % a;
        b = tmp;
    }
    return b;
}

int main() {
    //freopen("/Users/mefimov/a.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> v(n+1);
    for (int i = 0; i < n-2; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        v[x].push_back({min(y, z), max(y, z)});
        v[y].push_back({min(x, z), max(x, z)});
        v[z].push_back({min(x, y), max(x, y)});
    }

    vector<int> d;
    for (int i = 1; i <= n; ++i) {
        if (v[i].size() == 1) {
            d.push_back(i);
        }
    }

    assert(d.size() == 2);
    int cur = d[0];
    int last = d[1];
    int plast = v[v[last][0].first].size() == 2 ? v[last][0].first : v[last][0].second;
    for (int j = 0; j < n-3; ++j) {
        assert(v[cur].size() == 1);
        cout << cur << " ";
        int x = v[cur][0].first;
        int y = v[cur][0].second;
        v[cur].clear();
        int pxs = v[x].size();
        int pys = v[y].size();
        v[x].erase(find(v[x].begin(), v[x].end(), make_pair(min(cur, y), max(cur, y))));
        v[y].erase(find(v[y].begin(), v[y].end(), make_pair(min(cur, x), max(cur, x))));
        assert(v[x].size() + 1 == pxs);
        assert(v[y].size() + 1 == pys);
        if (v[x].size() == 1) {
            cur = x;
        } else {
            cur = y;
        }
    }
    for (int i = 0; i < n; ++i) {
        if (v[i].size() == 1 && i != last && i != plast) {
            cout << i << " ";
            break;
        }
    }
    cout << plast << " " << last << endl;

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >

ll n;
vvi g;
vi color;
vi visit;
ll l, r;
ll c[2];
vi ans;

void dfs(ll u1, ll u2)
{

    visit[u1] = 1;
    visit[u2] = 1;

    if (r - l < 2)
    {
        for (auto it: g[u1])
            if (visit[it] == 0)
                c[0] = it;
        visit[c[0]] = 1;
        ans[l] = c[0] + 1;

        if (r == l)
            return;

        for (auto it: g[u2])
            if (visit[it] == 0)
                c[1] = it;

        ans[r] = c[1] + 1;
        return;
    }

    ll c1 = LLONG_MAX, c2 = LLONG_MAX;
    for (auto it: g[u1])
    {
        if (color[it] < c1 && visit[it] == 0)
            c[0] = it, c1 = color[it];
    }

    for (auto it: g[u1])
        color[it]--;

    ans[l] = c[0] + 1;
    l++;

    for (auto it: g[u2])
    {
        if (color[it] < c2 && visit[it] == 0)
            c[1]= it, c2 = color[it];
    }

    for (auto it: g[u2])
        color[it]--;

    ans[r] = c[1] + 1;
    r--;

    dfs(c[0], c[1]);
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    g.resize(n);
    color.resize(n, 0);
    visit.resize(n, 0);
    ans.resize(n);
    l = 0, r = n - 1;

    for (int i = 0; i < n - 2; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;

        color[a - 1] += 2, color[b - 1] += 2, color[c - 1] += 2;
        g[a - 1].pb(b - 1);
        g[b - 1].pb(a - 1);

        g[a - 1].pb(c - 1);
        g[c - 1].pb(a - 1);

        g[b - 1].pb(c - 1);
        g[c - 1].pb(b - 1);
    }

    ll k = 0;
    for (int i = 0; i < n; i++)
        if (g[i].size() == 2)
            c[k] = i, k = (k + 1) % 2;

    ans[l++] = c[0] + 1, ans[r--] = c[1] + 1;
    color[c[0]]--, color[c[1]]--;
    dfs(c[0], c[1]);

    for (auto it: ans)
        cout << it << " ";
    cout << "\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >

ll n;
vvi g;
vi color;
vi visit;
ll l, r;
ll c[2];
vi ans;

void dfs(ll u1, ll u2)
{

    visit[u1] = 1;
    visit[u2] = 1;

    for (auto it: g[u1])
        color[it]--;

    ll c1 = LLONG_MAX, c2 = LLONG_MAX;
    for (auto it: g[u1])
    {
        if (color[it] < c1 && visit[it] == 0)
            c[0] = it, c1 = color[it];
    }

    ans[l] = c[0] + 1;
    l++;

    if (r < l)
        return;

    for (auto it: g[u2])
        color[it]--;

    for (auto it: g[u2])
    {
        if (color[it] < c2 && visit[it] == 0)
            c[1]= it, c2 = color[it];
    }

    ans[r] = c[1] + 1;
    r--;

    if (r >= l)
        dfs(c[0], c[1]);
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    g.resize(n);
    color.resize(n, 0);
    visit.resize(n, 0);
    ans.resize(n);
    l = 0, r = n - 1;

    for (int i = 0; i < n - 2; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;

        color[a - 1] += 2, color[b - 1] += 2, color[c - 1] += 2;
        g[a - 1].pb(b - 1);
        g[b - 1].pb(a - 1);

        g[a - 1].pb(c - 1);
        g[c - 1].pb(a - 1);

        g[b - 1].pb(c - 1);
        g[c - 1].pb(b - 1);
    }

    ll k = 0;
    for (int i = 0; i < n; i++)
        if (g[i].size() == 2)
            c[k] = i, k = (k + 1) % 2;

    ans[l++] = c[0] + 1, ans[r--] = c[1] + 1;
    color[c[0]]--, color[c[1]]--;
    dfs(c[0], c[1]);

    for (auto it: ans)
        cout << it << " ";
    cout << "\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >

ll n;
vvi g;
vi color;
vi visit;
ll l, r;
ll c[2];
vi ans;

void dfs(ll u1, ll u2)
{

    visit[u1] = 1;
    visit[u2] = 1;

    if (r - l < 2)
    {
        for (auto it: g[u1])
            if (visit[it] == 0)
                c[0] = it;
        visit[c[0]] = 1;
        ans[l] = c[0] + 1;

        if (r == l)
            return;

        for (auto it: g[u2])
            if (visit[it] == 0)
                c[1] = it;

        ans[r] = c[1] + 1;
        return;
    }

    ll c1 = LLONG_MAX, c2 = LLONG_MAX;
    for (auto it: g[u1])
    {
        if (color[it] < c1 && visit[it] == 0)
            c[0] = it, c1 = color[it];
    }

    ans[l] = c[0] + 1;
    l++;

    for (auto it: g[u2])
    {
        if (color[it] < c2 && visit[it] == 0)
            c[1]= it, c2 = color[it];
    }

    for (auto it: g[u1])
        color[it]--;
    for (auto it: g[u1])
        color[it]--;

    ans[r] = c[1] + 1;
    r--;

    dfs(c[0], c[1]);
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    g.resize(n);
    color.resize(n, 0);
    visit.resize(n, 0);
    ans.resize(n);
    l = 0, r = n - 1;

    for (int i = 0; i < n - 2; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;

        color[a - 1] += 2, color[b - 1] += 2, color[c - 1] += 2;
        g[a - 1].pb(b - 1);
        g[b - 1].pb(a - 1);

        g[a - 1].pb(c - 1);
        g[c - 1].pb(a - 1);

        g[b - 1].pb(c - 1);
        g[c - 1].pb(b - 1);
    }

    ll k = 0;
    for (int i = 0; i < n; i++)
        if (g[i].size() == 2)
            c[k] = i, k = (k + 1) % 2;

    ans[l++] = c[0] + 1, ans[r--] = c[1] + 1;
    color[c[0]]--, color[c[1]]--;
    dfs(c[0], c[1]);

    for (auto it: ans)
        cout << it << " ";
    cout << "\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >

ll n;
vvi g;
vi color;
vi visit;
ll l, r;
ll c[2];
vi ans;

void dfs(ll u1, ll u2)
{

    visit[u1] = 1;
    visit[u2] = 1;

    for (auto it: g[u1])
        color[it]--;

    ll c1 = LLONG_MAX, c2 = LLONG_MAX;
    for (auto it: g[u1])
    {
        if (color[it] < c1 && visit[it] == 0)
            c[0] = it, c1 = color[it];
    }

    ans[l] = c[0] + 1;
    l++;

    visit[c[0]] = 1;

    if (r < l)
        return;

    for (auto it: g[u2])
        color[it]--;

    for (auto it: g[u2])
    {
        if (color[it] < c2 && visit[it] == 0)
            c[1]= it, c2 = color[it];
    }

    ans[r] = c[1] + 1;
    r--;

    if (r >= l)
        dfs(c[0], c[1]);
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    g.resize(n);
    color.resize(n, 0);
    visit.resize(n, 0);
    ans.resize(n);
    l = 0, r = n - 1;

    for (int i = 0; i < n - 2; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;

        color[a - 1] += 2, color[b - 1] += 2, color[c - 1] += 2;
        g[a - 1].pb(b - 1);
        g[b - 1].pb(a - 1);

        g[a - 1].pb(c - 1);
        g[c - 1].pb(a - 1);

        g[b - 1].pb(c - 1);
        g[c - 1].pb(b - 1);
    }

    ll k = 0;
    for (int i = 0; i < n; i++)
        if (g[i].size() == 2)
            c[k] = i, k = (k + 1) % 2;

    ans[l++] = c[0] + 1, ans[r--] = c[1] + 1;
    color[c[0]]--, color[c[1]]--;
    dfs(c[0], c[1]);

    for (auto it: ans)
        cout << it << " ";
    cout << "\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >

ll n;
vvi g;
vi color;
vi visit;
ll l, r;
ll c[2];
vi ans;

void dfs(ll u1, ll u2)
{

    visit[u1] = 1;
    visit[u2] = 1;

    if (r - l < 2)
    {
        for (auto it: g[u1])
            if (visit[it] == 0)
                c[0] = it;
        visit[c[0]] = 1;
        ans[l] = c[0] + 1;

        if (r == l)
            return;

        for (auto it: g[u2])
            if (visit[it] == 0)
                c[1] = it;

        ans[r] = c[1] + 1;
        return;
    }

    ll c1 = LLONG_MAX, c2 = LLONG_MAX;
    for (auto it: g[u1])
    {
        if (color[it] < c1 && visit[it] == 0)
            c[0] = it, c1 = color[it];
    }

    ans[l] = c[0] + 1;
    l++;

    for (auto it: g[u2])
    {
        if (color[it] < c2 && visit[it] == 0)
            c[1]= it, c2 = color[it];
    }

    for (auto it: g[u1])
        color[it]--;
    for (auto it: g[u2])
        color[it]--;

    ans[r] = c[1] + 1;
    r--;

    dfs(c[0], c[1]);
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    g.resize(n);
    color.resize(n, 0);
    visit.resize(n, 0);
    ans.resize(n);
    l = 0, r = n - 1;

    for (int i = 0; i < n - 2; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;

        color[a - 1] += 2, color[b - 1] += 2, color[c - 1] += 2;
        g[a - 1].pb(b - 1);
        g[b - 1].pb(a - 1);

        g[a - 1].pb(c - 1);
        g[c - 1].pb(a - 1);

        g[b - 1].pb(c - 1);
        g[c - 1].pb(b - 1);
    }

    ll k = 0;
    for (int i = 0; i < n; i++)
        if (g[i].size() == 2)
            c[k] = i, k = (k + 1) % 2;

    ans[l++] = c[0] + 1, ans[r--] = c[1] + 1;
    color[c[0]]--, color[c[1]]--;
    dfs(c[0], c[1]);

    for (auto it: ans)
        cout << it << " ";
    cout << "\n";
}


//Warmdust Code
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define db double
#define ll long long
#define ull unsigned long long
#define ft float
#define PI acos(-1)
#define L(i,a,b) for(int i=a;i<=b;i++)
#define R(i,a,b) for(int i=a;i>=b;i--)
#define mst(a,num) memset(a,num,sizeof(a))
#define inf 0x3f3f3f3f
#define linf  0x3f3f3f3f3f3f3f3f
#define Warmdust int main(){
#define RETURN return 0;}
#define TvT ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn = 105;
const int mod = 1e9+7;
int deep[maxn];
int vis[maxn];
int sz[maxn][maxn];
int idex = 0;
int n;
queue<int> q;
void bfs(){
	while(q.size() != 0){
	    int x  = q.front();
		L(i,1,n) {
			if(sz[x][i] == 1 && vis[i] != 1 ) {
				q.push(i);
				vis[i] = 1;
				break;
			}
		}
		cout << q.front() << " ";
		q.pop();
	}
}
Warmdust
    cin >> n;
    L(i,1,n-2) {
     	int x,y,z;
     	cin >> x >> y >> z;
     	deep[x]++;
     	deep[y]++;
     	deep[z]++;
     	sz[x][y] = sz[y][x] = 1;
     	sz[x][z] = sz[z][x] = 1;
     	sz[y][z] = sz[z][y] = 1;
	}
	L(i,1,n) {
		if(deep[i] == 1 ) {
			idex =i;
			break;
		}
	}
	q.push(idex);
	vis[idex] = 1;
	int x[3];
	int a =1;
	L(i,1,n) {
		if(sz[idex][i] == 1) {
			x[a++] = i;
		}
	}
	if(deep[x[1]] < deep[x[2]]) {
		q.push(x[1]);
		q.push(x[2]);
	}
	else {
		q.push(x[2]);
		q.push(x[1]);
	}
	vis[x[1]] = vis[x[2]] = 1;
	bfs();
RETURN


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

vector<int> e[maxn];
int vis[maxn], in[maxn];
vector<int> ans;

void bfs(int x) {
    queue<int> q;
    q.push(x);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        ans.push_back(u);
        for (auto &v : e[u]) {
            q.push(v);
        }
    }
}

int main(void) {
    FAST_IO;

    int n;
    cin >> n;
    for (int i = 0; i < n - 2; i++) {
        int a, b, c;
        cin >> a >> b>> c;
        in[a]++, in[b]++, in[c]++;
        e[a].push_back(b);
        e[b].push_back(a);
        e[a].push_back(c);
        e[c].push_back(a);
        e[b].push_back(c);
        e[c].push_back(b);
    }
    for (int i = 1; i <= n; i++) {
        if (in[i] == 1) {
            cout << i << endl;
            bfs(i);
            break;
        }
    }
    // cout << v.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

vector<int> e[maxn];
int vis[maxn], in[maxn];
vector<int> ans;

void bfs(int x) {
    queue<int> q;
    q.push(x);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        ans.push_back(u);
        for (auto &v : e[u]) {
            q.push(v);
        }
    }
}

int main(void) {
    FAST_IO;

    int n;
    cin >> n;
    for (int i = 0; i < n - 2; i++) {
        int a, b, c;
        cin >> a >> b>> c;
        in[a]++, in[b]++, in[c]++;
        e[a].push_back(b);
        e[b].push_back(a);
        e[a].push_back(c);
        e[c].push_back(a);
        e[b].push_back(c);
        e[c].push_back(b);
    }
    for (int i = 1; i <= n; i++) {
        if (in[i] == 1) {
            sort(e[i].begin(), e[i].end(), [](const int &x, const int &y) {
                return in[x] < in[y];
            });
            bfs(i);
            break;
        }
    }

    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

vector<int> e[maxn];
int vis[maxn], in[maxn];
vector<int> ans;

void bfs(int x) {
    queue<int> q;
    q.push(x);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        ans.push_back(u);
        for (auto &v : e[u]) {
            q.push(v);
        }
    }
}

int main(void) {
    FAST_IO;

    int n;
    cin >> n;
    for (int i = 0; i < n - 2; i++) {
        int a, b, c;
        cin >> a >> b>> c;
        in[a]++, in[b]++, in[c]++;
        e[a].push_back(b);
        e[b].push_back(a);
        e[a].push_back(c);
        e[c].push_back(a);
        e[b].push_back(c);
        e[c].push_back(b);
    }
    for (int i = 1; i <= n; i++) {
        if (in[i] == 1) {
            // cout << i << endl;
            bfs(i);
            break;
        }
    }
    // cout << v.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define db double
#define ll long long
#define ull unsigned long long
#define ft float
#define PI acos(-1)
#define L(i,a,b) for(int i=a;i<=b;i++)
#define R(i,a,b) for(int i=a;i>=b;i--)
#define mst(a,num) memset(a,num,sizeof(a))
#define inf 0x3f3f3f3f
#define linf  0x3f3f3f3f3f3f3f3f
#define Warmdust int main(){
#define RETURN return 0;}
#define TvT ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
const int maxn = 1e5 + 10;
const int mod = 1e9+7;
int deep[maxn];
int vis[maxn];
map<pair<int ,int>, int> sz;
int idex = 0;
int n;
queue<int> q;
void bfs(){
	while(q.size() != 0){
	    int x  = q.front();
		L(i,1,n) {
			if(sz[{x, i}] == 1 && vis[i] != 1 ) {
				q.push(i);
				vis[i] = 1;
				break;
			}
		}
		cout << q.front() << " ";
		q.pop();
	}
}
Warmdust
    cin >> n;
    L(i,1,n-2) {
     	int x,y,z;
     	cin >> x >> y >> z;
     	deep[x]++;
     	deep[y]++;
     	deep[z]++;
     	sz[{x, y}] = sz[{y, x}] = 1;
     	sz[{x, z}] = sz[{z, x}] = 1;
     	sz[{y, z}] = sz[{z, y}] = 1;
	}
	L(i,1,n) {
		if(deep[i] == 1 ) {
			idex =i;
			break;
		}
	}
	q.push(idex);
	vis[idex] = 1;
	int x[3];
	int a =1;
	L(i,1,n) {
		if(sz[{idex, i}] == 1) {
			x[a++] = i;
		}
	}
	if(deep[x[1]] < deep[x[2]]) {
		q.push(x[1]);
		q.push(x[2]);
	}
	else {
		q.push(x[2]);
		q.push(x[1]);
	}
	vis[x[1]] = vis[x[2]] = 1;
	bfs();
    return 0;
RETURN


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define db double
#define ll long long
#define ull unsigned long long
#define ft float
#define PI acos(-1)
#define L(i,a,b) for(int i=a;i<=b;i++)
#define R(i,a,b) for(int i=a;i>=b;i--)
#define mst(a,num) memset(a,num,sizeof(a))
#define inf 0x3f3f3f3f
#define linf  0x3f3f3f3f3f3f3f3f
#define Warmdust int main(){
#define RETURN return 0;}
#define TvT ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
const int maxn = 1e5 + 10;
const int mod = 1e9+7;
int deep[maxn];
map<pair<int ,int>, bool> sz;
int idex = 0;
int n;
queue<int> q;
void bfs(){
	while(q.size() != 0){
	    int x  = q.front();
		q.pop();
		L(i,1,n) {
			if(sz[{x, i}] == 1 && deep[i] != 1 ) {
				q.push(i);
				deep[i] = 1;
				break;
			}
		}
		cout << x << " ";
	}
}
Warmdust
    cin >> n;
    L(i,1,n-2) {
     	int x,y,z;
     	cin >> x >> y >> z;
     	deep[x]++;
     	deep[y]++;
     	deep[z]++;
     	sz[{x, y}] = sz[{y, x}] = 1;
     	sz[{x, z}] = sz[{z, x}] = 1;
     	sz[{y, z}] = sz[{z, y}] = 1;
	}
	L(i,1,n) {
		if(deep[i] == 1 ) {
			idex =i;
			break;
		}
	}
	q.push(idex);
	//deep[idex] = 1;
	int x[3];
	int a = 1;
	L(i,1,n) {
		if(sz[{idex, i}] == 1) {
			x[a++] = i;
		}
	}
	if(deep[x[1]] < deep[x[2]]) {
		q.push(x[1]);
		q.push(x[2]);
	}
	else {
		q.push(x[2]);
		q.push(x[1]);
	}
	mst(deep,-1);
	deep[idex] = 1;
	deep[x[1]] = deep[x[2]] = 1;
	bfs();
    return 0;
RETURN


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define db double
#define ll long long
#define ull unsigned long long
#define ft float
#define PI acos(-1)
#define L(i,a,b) for(int i=a;i<=b;i++)
#define R(i,a,b) for(int i=a;i>=b;i--)
#define mst(a,num) memset(a,num,sizeof(a))
#define inf 0x3f3f3f3f
#define linf  0x3f3f3f3f3f3f3f3f
#define Warmdust int main(){
#define RETURN return 0;}
#define TvT ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
const int maxn = 1e5 + 10;
const int mod = 1e9+7;
int deep[maxn];
bool vis[maxn];
map<pair<int ,int>, bool> sz;
int idex = 0;
int n;
queue<int> q;
void bfs(){
	while(!q.empty()){
	    int x  = q.front();
		q.pop();
		L(i,1,n) {
			if(sz[{x, i}] == 1 && vis[i] != 1 ) {
				q.push(i);
				vis[i] = 1;
				break;
			}
		}
		cout << x << " ";
	}
}
Warmdust
    cin >> n;
    L(i,1,n-2) {
     	int x,y,z;
     	cin >> x >> y >> z;
     	deep[x]++;
     	deep[y]++;
     	deep[z]++;
     	sz[{x, y}] = sz[{y, x}] = 1;
     	sz[{x, z}] = sz[{z, x}] = 1;
     	sz[{y, z}] = sz[{z, y}] = 1;
	}
	L(i,1,n) {
		if(deep[i] == 1 ) {
			idex =i;
			break;
		}
	}
	q.push(idex);
	vis[idex] = 1;
	int x[3];
	int a = 1;
	L(i,1,n) {
		if(sz[{idex, i}] == 1) {
			x[a++] = i;
		}
	}
	if(deep[x[1]] < deep[x[2]]) {
		q.push(x[1]);
		q.push(x[2]);
	}
	else {
		q.push(x[2]);
		q.push(x[1]);
	}
	vis[x[1]] = vis[x[2]] = 1;
	bfs();
    return 0;
RETURN


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define db double
#define ll long long
#define ull unsigned long long
#define ft float
#define PI acos(-1)
#define L(i,a,b) for(int i=a;i<=b;i++)
#define R(i,a,b) for(int i=a;i>=b;i--)
#define mst(a,num) memset(a,num,sizeof(a))
#define inf 0x3f3f3f3f
#define linf  0x3f3f3f3f3f3f3f3f
#define Warmdust int main(){
#define RETURN return 0;}
#define TvT ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
const int maxn = 1e5 + 10;
const int mod = 1e9+7;
int deep[maxn];
int vis[maxn];
map<pair<int ,int>, int> sz;
int idex = 0;
int n;
queue<int> q;
void bfs(){
	while(q.size() != 0){
	    int x  = q.front();
		q.pop();
		L(i,1,n) {
			if(sz[{x, i}] == 1 && vis[i] != 1 ) {
				q.push(i);
				vis[i] = 1;
				break;
			}
		}
		cout << x << " ";
	}
}
Warmdust
    cin >> n;
    L(i,1,n-2) {
     	int x,y,z;
     	cin >> x >> y >> z;
     	deep[x]++;
     	deep[y]++;
     	deep[z]++;
     	sz[{x, y}] = sz[{y, x}] = 1;
     	sz[{x, z}] = sz[{z, x}] = 1;
     	sz[{y, z}] = sz[{z, y}] = 1;
	}
	L(i,1,n) {
		if(deep[i] == 1 ) {
			idex =i;
			break;
		}
	}
	q.push(idex);
	vis[idex] = 1;
	int x[3];
	int a =1;
	L(i,1,n) {
		if(sz[{idex, i}] == 1) {
			x[a++] = i;
		}
	}
	if(deep[x[1]] < deep[x[2]]) {
		q.push(x[1]);
		q.push(x[2]);
	}
	else {
		q.push(x[2]);
		q.push(x[1]);
	}
	vis[x[1]] = vis[x[2]] = 1;
	bfs();
    return 0;
RETURN


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

vector<int> e[maxn];
int vis[maxn];
vector<int> v;

void bfs(int x) {
    queue<int> q;
    q.push(x);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        v.push_back(u);
        for (auto &x : e[u]) {
            if (vis[x]) continue;
            q.push(x);
        }
    }
}

int main(void) {
    FAST_IO;

    int n;
    cin >> n;
    for (int i = 0; i < n - 2; i++) {
        int a, b, c;
        cin >> a >> b>> c;
        e[a].push_back(b);
        e[b].push_back(a);
        e[a].push_back(c);
        e[c].push_back(a);
        e[b].push_back(c);
        e[c].push_back(b);
    }
    bfs(1);
    for (int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << endl;

    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

vector<int> e[maxn];
int vis[maxn], in[maxn];
vector<int> ans;

void bfs(int x) {
    queue<int> q;
    q.push(x);
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        ans.push_back(u);
        for (auto &v : e[u]) {
            q.push(v);
        }
    }
}

int main(void) {
    FAST_IO;

    int n;
    cin >> n;
    for (int i = 0; i < n - 2; i++) {
        int a, b, c;
        cin >> a >> b>> c;
        in[a]++, in[b]++, in[c]++;
        e[a].push_back(b);
        e[b].push_back(a);
        e[a].push_back(c);
        e[c].push_back(a);
        e[b].push_back(c);
        e[c].push_back(b);
    }
    for (int i = 1; i <= n; i++) {
        if (in[i] == 1) {
            sort(e[i].begin(), e[i].end());
            bfs(i);
            break;
        }
    }

    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"

using namespace std;

#define A first
#define B second

typedef long long ll;
constexpr int MOD = 1000000007;

void solve() {
  int N;
  cin >> N;
  map<int, int> mp;
  for(int i = 0; i < N - 2; i++){
    int a, b, c;
    cin >> a >> b >> c;
    mp[a]++, mp[b]++, mp[c]++;
  }
  map<int, vector<int>> cnt;
  for(auto x: mp){
    cnt[x.B].push_back(x.A);
  }
  vector<int> ans(N);
  for(int i = 1; i <= N / 2; i++){
    ans[i - 1] = cnt[i][0];
    ans[N - i] = cnt[i][1];
  }
  if(N % 2 == 1){
    ans[N / 2] = cnt[N / 2 + 1][0];
  }
  for(int i = 0; i < N; i++) cout << ans[i] << " ";

}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
#include "debug.h"

using namespace std;

#define A first
#define B second

typedef long long ll;
constexpr int MOD = 1000000007;

void solve() {
  int N;
  cin >> N;
  map<int, int> mp;
  map<int, set<int>> st;
  for(int i = 0; i < N - 2; i++){
    int a, b, c;
    cin >> a >> b >> c;
    mp[a]++, mp[b]++, mp[c]++;
    st[a].insert(b), st[a].insert(c);
    st[b].insert(c), st[b].insert(a);
    st[c].insert(a), st[c].insert(b);
  }
  vector<int> ans(N);
  int bg = 0;
  for(auto x: mp){
    if(x.B == 1) {
      bg = x.A;
      break;
    }
  }
  ans[0] = bg;
  vector<bool> used(N, false);
  for(int val: st[bg]){
    if(mp[val] == 2) {
      ans[1] = val;
      break;
    }
  }
  used[ans[0]] = true;
  used[ans[1]] = true;
  for(int i = 2; i < N; i++){
    int prev = ans[i - 1];
    int prev2 = ans[i - 2];
    for(int x: st[prev]){
      if(used[x]) continue;
      if(st[prev2].find(x) != st[prev2].end()){
        ans[i] = x;
        used[x] = true;
        break;
      }
    }
  }
  for(int i = 0; i < N; i++){
    cout << ans[i] << " ";
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"

using namespace std;

#define A first
#define B second

typedef long long ll;
constexpr int MOD = 1000000007;

void solve() {
  int N;
  cin >> N;
  map<int, int> mp;
  map<int, set<int>> st;
  for(int i = 0; i < N - 2; i++){
    int a, b, c;
    cin >> a >> b >> c;
    mp[a]++, mp[b]++, mp[c]++;
    st[a].insert(b), st[a].insert(c);
    st[b].insert(c), st[b].insert(a);
    st[c].insert(a), st[c].insert(b);
  }
  map<int, vector<int>> cnt;
  for(auto x: mp){
    cnt[x.B].push_back(x.A);
  }
  vector<int> ans(N);
  for(int i = 1; i <= N / 2; i++){
    if(i == 1){
      ans[i - 1] = cnt[i][0];
      ans[N - i] = cnt[i][1];
    }
    else {
      int prev = ans[i - 2];
      if(st[prev].find(cnt[i][0]) != st[prev].end()){
        ans[i - 1] = cnt[i][0];
        ans[N - i] = cnt[i][1];
      }
      else{
        ans[i - 1] = cnt[i][1];
        ans[N - i] = cnt[i][0];
      }
    }

  }
  if(N % 2 == 1){
    ans[N / 2] = cnt[N / 2 + 1][0];
  }
  for(int i = 0; i < N; i++) cout << ans[i] << " ";

}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"

using namespace std;

#define A first
#define B second

typedef long long ll;
constexpr int MOD = 1000000007;

void solve() {
  int N;
  cin >> N;
  map<int, int> mp;
  map<int, set<int>> st;
  for(int i = 0; i < N - 2; i++){
    int a, b, c;
    cin >> a >> b >> c;
    mp[a]++, mp[b]++, mp[c]++;
    st[a].insert(b), st[a].insert(c);
    st[b].insert(c), st[b].insert(a);
    st[c].insert(a), st[c].insert(b);
  }
  vector<int> ans(N);
  int bg = 0;
  for(auto x: mp){
    if(x.B == 1) {
      bg = x.A;
      break;
    }
  }
  ans[0] = bg;
  vector<bool> used(N, false);
  for(int val: st[bg]){
    if(mp[val] == 2) {
      ans[1] = val;
      break;
    }
  }
  used[ans[0]] = true;
  used[ans[1]] = true;
  for(int i = 2; i < N; i++){
    int prev = ans[i - 1];
    int prev2 = ans[i - 2];
    for(int x: st[prev]){
      if(used[x]) continue;
      if(st[prev2].find(x) != st[prev2].end()){
        ans[i] = x;
        used[x] = true;
        break;
      }
    }
  }
  for(int i = 0; i < N; i++){
    cout << ans[i] << " ";
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}


#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"

using namespace std;

#define A first
#define B second

typedef long long ll;
constexpr int MOD = 1000000007;

void solve() {
  int N;
  cin >> N;
  map<int, int> mp;
  map<int, set<int>> st;
  for(int i = 0; i < N - 2; i++){
    int a, b, c;
    cin >> a >> b >> c;
    mp[a]++, mp[b]++, mp[c]++;
    st[a].insert(b), st[a].insert(c);
    st[b].insert(c), st[b].insert(a);
    st[c].insert(a), st[c].insert(b);
  }
  map<int, vector<int>> cnt;
  for(auto x: mp){
    cnt[x.B].push_back(x.A);
  }
  vector<int> ans(N);
  for(int i = 1; i <= N / 2; i++){
    if(i == 1){
      ans[i - 1] = cnt[i][0];
      ans[N - i] = cnt[i][1];
    }
    else if(i == 2) {
      int prev = ans[i - 2];
      if(st[prev].find(cnt[i][0]) != st[prev].end()){
        ans[i - 1] = cnt[i][0];
        ans[N - i] = cnt[i][1];
      }
      else{
        ans[i - 1] = cnt[i][1];
        ans[N - i] = cnt[i][0];
      }
    }
    else {
      int prev = ans[i - 2];
      int prev2 = ans[i - 3];
      if(st[prev].find(cnt[i][0]) != st[prev].end() && st[prev2].find(cnt[i][0]) != st[prev2].end()){
        ans[i - 1] = cnt[i][0];
        ans[N - i] = cnt[i][1];
      }
      else{
        ans[i - 1] = cnt[i][1];
        ans[N - i] = cnt[i][0];
      }
    }

  }
  if(N % 2 == 1){
    ans[N / 2] = cnt[N / 2 + 1][0];
  }
  for(int i = 0; i < N; i++) cout << ans[i] << " ";

}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}


#define LOOP(i, n) for(int i = 0; i < n; ++i)
#define LOOPSTAR(i, m, n) for(int i = m; i < n; ++i)
#define LOOPITER(it, beg, end) for(auto it = beg; it != end; ++it)
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define FASTIO ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)

#include <bits/stdc++.h>

using namespace std;

typedef int lli;
typedef double lld;
typedef pair<lli, lli> pii;
typedef pair<lld, lld> pdd;

const lli MAX = 100;
const lli MOD = 1000000007;

int main() {
	lli t, n, a[MAX], c[MAX], f, l, x, y, z;
	vector<lli> b[MAX];
	cin >> n;
	fill_n(a, n, 0);
	fill_n(c, n, -1);
	LOOP(i, n)
		b[i].clear();
	LOOP(i, n - 2) {
		cin >> x >> y >> z;
		x--;
		y--;
		z--;
		a[x]++;
		a[y]++;
		a[z]++;
		b[x].push_back(y);
		b[x].push_back(z);
		b[y].push_back(x);
		b[y].push_back(z);
		b[z].push_back(x);
		b[z].push_back(y);
	}
	f = 0, l = n - 1;
	LOOP(i, n)
		if(a[i] == 1) {
			if(c[f] == -1)
				c[f] = i;
			else
				c[l] = i;
		}
	while(l > f + 3) {
		LOOP(i, b[c[f]].size()) {
			z = b[c[f]][i];
			a[z]--;
			if(a[z] == 1) {
				c[f + 1] = z;
			}
		}
		LOOP(i, b[c[l]].size()) {
			z = b[c[l]][i];
			a[z]--;
			if(a[z] == 1) {
				c[l - 1] = z;
			}
		}
		l--;
		f++;
	}
	x = -1, y = -1, z = -1;
	LOOP(i, n) {
		if(a[i] == 2) {
			if(x == -1)
				x = i;
			else if(y == -1)
				y = i;
		}
		if(a[i] == 3 && z == -1)
			z = i;
	}
	if(z != -1)
		c[f + 2] = z;
	LOOP(i, b[c[f - 1]].size()) {
		if(b[c[f - 1]][i] == x) {
			c[f + 1] = x;
			c[l - 1] = y;
		}
		else if(b[c[f - 1]][i] == y) {
			c[f + 1] = y;
			c[l - 1] = x;
		}
	}
	if(z == -1)
		LOOP(i, n)
			if(a[i] == 1)
				c[f + 1] = i;
	LOOP(i, n)
		cout << (c[i] + 1) << " ";
	cout << endl;
	return 0;
}


#define LOOP(i, n) for(int i = 0; i < n; ++i)
#define LOOPSTAR(i, m, n) for(int i = m; i < n; ++i)
#define LOOPITER(it, beg, end) for(auto it = beg; it != end; ++it)
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define FASTIO ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)

#include <bits/stdc++.h>

using namespace std;

typedef int lli;
typedef double lld;
typedef pair<lli, lli> pii;
typedef pair<lld, lld> pdd;

const lli MAX = 100;
const lli MOD = 1000000007;

int main() {
	lli t, n, a[MAX], c[MAX], f, l, x, y, z;
	vector<lli> b[MAX];
	cin >> n;
	fill_n(a, n, 0);
	fill_n(c, n, -1);
	LOOP(i, n)
		b[i].clear();
	LOOP(i, n - 2) {
		cin >> x >> y >> z;
		x--;
		y--;
		z--;
		a[x]++;
		a[y]++;
		a[z]++;
		b[x].push_back(y);
		b[x].push_back(z);
		b[y].push_back(x);
		b[y].push_back(z);
		b[z].push_back(x);
		b[z].push_back(y);
	}
	f = 0, l = n - 1;
	LOOP(i, n)
		if(a[i] == 1) {
			if(c[f] == -1)
				c[f] = i;
			else
				c[l] = i;
		}
	while(l > f + 3) {
		LOOP(i, b[c[f]].size()) {
			z = b[c[f]][i];
			a[z]--;
			if(a[z] == 1) {
				c[f + 1] = z;
			}
		}
		LOOP(i, b[c[l]].size()) {
			z = b[c[l]][i];
			a[z]--;
			if(a[z] == 1) {
				c[l - 1] = z;
			}
		}
		l--;
		f++;
	}
	x = -1, y = -1, z = -1;
	LOOP(i, n) {
		if(a[i] == 2) {
			if(x == -1)
				x = i;
			else if(y == -1)
				y = i;
		}
		if(a[i] == 3 && z == -1)
			z = i;
	}
	if(z != -1)
		c[f + 2] = z;
	LOOP(i, b[c[f - 1]].size()) {
		if(b[c[f - 1]][i] == x) {
			c[f + 1] = x;
			c[l - 1] = y;
		}
		else if(b[c[f - 1]][i] == y) {
			c[f + 1] = y;
			c[l - 1] = x;
		}
	}
	LOOP(i, n)
		cout << (c[i] + 1) << " ";
	cout << endl;
	return 0;
}


#define LOOP(i, n) for(int i = 0; i < n; ++i)
#define LOOPSTAR(i, m, n) for(int i = m; i < n; ++i)
#define LOOPITER(it, beg, end) for(auto it = beg; it != end; ++it)
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define FASTIO ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)

#include <bits/stdc++.h>

using namespace std;

typedef int lli;
typedef double lld;
typedef pair<lli, lli> pii;
typedef pair<lld, lld> pdd;

const lli MAX = 100000;
const lli MOD = 1000000007;

int main() {
	lli t, n, a[MAX], c[MAX], f, l, x, y, z;
	set<lli> b[MAX];
	cin >> n;
	fill_n(a, n, 0);
	fill_n(c, n, -1);
	LOOP(i, n)
		b[i].clear();
	LOOP(i, n - 2) {
		cin >> x >> y >> z;
		x--;
		y--;
		z--;
		a[x]++;
		a[y]++;
		a[z]++;
		b[x].insert(y);
		b[x].insert(z);
		b[y].insert(x);
		b[y].insert(z);
		b[z].insert(x);
		b[z].insert(y);
	}
	l = n;
	LOOP(i, n)
		if(a[i] == 1) {
			c[--l] = i;
			a[i] = 0;
			break;
		}
	while(l >= 4) {
		for(auto x: b[c[l]]) {
			a[x]--;
			if(a[x] == 1) {
				c[l - 1] = x;
				a[x] = 0;
			}
		}
		l--;
	}
	LOOP(i, n) {
		if(a[i] == 1)
			c[0] = i;
		else if(a[i] == 2) {
			if(b[c[4]].count(i))
				c[2] = i;
			else
				c[1] = i;
		}
	}
	LOOP(i, n)
		cout << (c[i] + 1) << " ";
	cout << endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(k==n)
    {
        cout<<0;
        exit(0);
    }
    ll ans=1e9+8;
    for(ll i=0;i<n-k;i++)
    {
        ans=min(ans,a[i+k]-a[i]);
    }
    cout<<ans;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <bits/stdc++.h>

using namespace std;

int n, k;
int c[100100], a[100100];

int main () {
    cin >> n >> k;
    for ( int i = 0; i < n; i++) {
        cin >> a[i];
        if ( i > 0 ) {
            c[i - 1] = a[i] - a[i - 1];
        }
    }
    sort(c, c + n - 1);
  //  for ( int i = 0; i < n; i++) {
      //  cout << " i = " << i << " c[i] = " << c[i] << endl;
    //}
    cout << accumulate(c, c + n - k, 0) << endl;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <bits/stdc++.h>

using namespace std;

int n, k;
int c[300300], a[300300];

int main () {
    cin >> n >> k;
    for ( int i = 0; i < n; i++) {
        cin >> a[i];
        if ( i > 0 ) {
            c[i - 1] = a[i] - a[i - 1];
        }
    }
    sort(c, c + n - 1);
  //  for ( int i = 0; i < n; i++) {
      //  cout << " i = " << i << " c[i] = " << c[i] << endl;
    //}
    cout << accumulate(c, c + n - k, 0) << endl;
}


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

using namespace std;

long long n, k, l, t, u, v, h, z;
long long a[300300], s[300300];

int main () {
    cin >> n >> k;
    for ( long long i = 1; i <= n; i++) {
        cin >> a[i];
        if ( i > 1 ) {
            s[i] = s[i - 1] + a[i] - a[i - 1];
        }
    }
    if ( k == 1 ) {
        cout << s[n];
        return 0;
    }
    else if ( k == n ) {
        cout << 0;
        return 0;
    }
    t = 0;
    h = 0;
    l = 0;
    z = 0;
    for  ( long long i = 2; i <= n; i++) {
        if ( u + a[i] - a[i - 1] <= (s[n] - s[z]) / (k - l)  && n - h >= k - l ) {
            u = u + a[i] - a[i - 1];
            h++;
        }
        else if ( u + a[i] - a[i - 1] > (s[n] - s[z]) / (k - l) ) {
            v++;
            t = t + u;
            u = 0;
            l++;
            z = i;
            h++;
        }
        if ( n - h < k - l) {
           cout << t + s[n] - s[z];
            return 0;
        }
     }
    cout << t + s[n] - s[z];
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, int lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(int lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    int st = -1e4, en = 1e4;
    while(st < en)
    {
        int mid = st +  (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-9);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<long double, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<long double, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(long double lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    long double st = -1e18, en = 1e18;
    while(isGreater(en, st) == 1)
    {
        long double mid = (st + en)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid;
    }
    pair<ll, int> temp = get(st + eps);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(ll lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    int st = -1e3, en = 1e3;
    while(st < en)
    {
        ll mid = st + (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-5);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,0,n)
        cin >> a[i];
    int ans = a.back() - a[0];
    vector<int> diff;
    for (int i = 0; i < n - 1; ++i)
        diff.push_back(a[i] - a[i + 1]);
    sort(all(diff));
    for (int i = 0; i < k - 1; ++i)
        ans += diff[i];
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define row first
#define col second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-4);
int dcmp(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,0,n)
        cin >> a[i];
    vector<int> diff;
    rep(i,1,n)
        diff.pb(a[i] - a[i - 1]);
    sort(all(diff));
    ll sum = 0;
    for (int i = 0; i < n - k; ++i)
        sum += diff[i];
    cout << sum;
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, int lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(int lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    int st = -1e9, en = 1e9;
    while(st < en)
    {
        int mid = st +  (en - st)/2LL;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(ll lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    long long st = -1e9, en = 1e9;
    while(isGreater(en, st) == 1)
    {
        ll mid = st + (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * cnt * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(ll lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    int st = -1e9, en = 1e9;
    while(st < en)
    {
        int mid = st + (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, int lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(int lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    int st = -1e9, en = 1e9;
    while(st < en)
    {
        int mid = st +  ((ll)en - (ll)st)/2LL;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(ll lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    int st = -1e9, en = 1e9;
    while(st < en)
    {
        ll mid = st + (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(ll lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    long long st = -1e9, en = 1e9;
    while(isGreater(en, st) == 1)
    {
        ll mid = st + (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(ll lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    int st = -1e5, en = 1e5;
    while(st < en)
    {
        ll mid = st + (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<long double, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<long double, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(long double lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    long double st = -1e18, en = 1e18;
    while(isGreater(en, st) == 1)
    {
        long double mid = (st + en)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid;
    }
    pair<ll, int> temp = get(st + eps);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, long double lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(ll lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    long long st = -1e9, en = 1e9;
    while(st < en)
    {
        ll mid = st + (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

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

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
#define debug(x) cerr << #x << " : " << (x) << endl
const double PI = 3.14159265358979323846;
const double eps = (1e-10);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

const int MAX_N = 3e5 + 3;
pair<ll, int> mem[MAX_N][2];
int a[MAX_N];
int visit[MAX_N][2], vid;
int n, k;
#define INF (1LL<<59)
pair<ll, int> solve(int i, bool state, int lamda)
{
    if (i == n)
    {
        if (state)
            return {INF, 1e9};
        return {0, 0};
    }
    auto &ret = mem[i][state];
    if (visit[i][state] == vid)
        return ret;
    visit[i][state] = vid;
    if (state == 0)
    {
        auto temp = solve(i, 1, lamda);
        temp.first += -a[i] + lamda;
        temp.second++;
        ret = temp;
    }
    else
    {
        ret = solve(i + 1, 1, lamda);
        auto temp = solve(i + 1, 0, lamda);
        temp.first += a[i];
        ret = min(ret, temp);
    }
    return ret;
}

pair<ll, int> get(int lamda)
{
    vid++;
    return solve(0, 0, lamda);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("AC.txt", "w", stdout);
#endif
    cin >> n >> k;
    rep(i,0,n)
        cin >> a[i];

    int st = -1e9, en = 1e9;
    while(st < en)
    {
        int mid = st + (en - st)/2;
        pair<ll, int> temp = get(mid);
        int cnt = temp.second;
        if (cnt <= k)
            en = mid;
        else
            st = mid + 1;
    }
    pair<ll, int> temp = get(st);
    ll ans = temp.first;
    int cnt= temp.second;
    debug(st);
    debug(ans);
    debug(cnt);
    cout << fixed << (int)(ans - 1LL * k * st) << '\n';
    return 0;
}