Problem:
Score : 100 points

Problem Statement

You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.

Constraints

The length of S is 2 or 3.

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

If the length of S is 2, print S as is; if the length is 3, print S after reversing it.

Sample Input 1

abc

Sample Output 1

cba

As the length of S is 3, we print it after reversing it.

Sample Input 2

ac

Sample Output 2

ac

As the length of S is 2, we print it as is.

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)

using namespace std;

typedef long long unsigned int ll;

void println(string const str)
{
    printf("%s\n", str.c_str());
}

void print(string const str)
{
    printf("%s", str.c_str());
}

int judge_align(int front, int back, int value)
{
    int diff_f = abs(front - value);
    int diff_b = abs(back - value);
    if (diff_f > diff_b)
    {
        return -1;
    }
    else
    {
        return 1;
    }
}

int align(int count, vector<int> v)
{
    int start = 0;
    int end = count - 1;
    // init push
    deque<int> result(v.back());
    end--;
    count--;

    while (true)
    {
        if (judge_align(result.front(), result.back(), v[start]) < 0)
        {
            result.push_front(v[start]);
        }
        else
        {
            result.push_back(v[start]);
        }
        start++;
        count--;
        if (count == 0)
        {
            int sum = 0;
            REP(i, result.size() - 1)
            {
                sum += abs(result[i + 1] - result[i]);
                printf("%d ", result[i]);
            }
            printf("%d\n", result[result.size() - 1]);
            return sum;
        }

        if (judge_align(result.front(), result.back(), v[end]) < 0)
        {
            result.push_front(v[end]);
        }
        else
        {
            result.push_back(v[end]);
        }
        end--;
        count--;
        if (count == 0)
        {
            int sum = 0;
            REP(i, result.size() - 1)
            {
                sum += abs(result[i + 1] - result[i]);
                printf("%d ", result[i]);
            }
            printf("%d\n", result[result.size() - 1]);
            return sum;
        }
    }

    int sum = 0;
    REP(i, result.size() - 1)
    {
        sum += abs(result[i + 1] - result[i]);
    }
    return sum;
}

int main()
{
    int count;
    cin >> count;
    // printf("count = %d\n", count);
    vector<int> v(count);
    vector<bool> flag(count, true);
    REP(i, count)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    int start = 0;
    int end = count - 1;
    // init push
    deque<int> result(0, 0);
    result.push_back(v.back());
    // printf("deque-size = %ld\n", result.size());
    end--;
    count--;

    while (true)
    {
        if (judge_align(result.front(), result.back(), v[start]) < 0)
        {
            result.push_front(v[start]);
        }
        else
        {
            result.push_back(v[start]);
        }
        start++;
        count--;
        if (count == 0)
        {
            int sum = 0;
            REP(i, result.size() - 1)
            {
                sum += abs(result[i + 1] - result[i]);
                // printf("%d ", result[i]);
            }
            // printf("%d\n", result[result.size() - 1]);
            printf("%d\n", sum);
            return 0;
        }

        if (judge_align(result.front(), result.back(), v[end]) < 0)
        {
            result.push_front(v[end]);
        }
        else
        {
            result.push_back(v[end]);
        }
        end--;
        count--;
        if (count == 0)
        {
            int sum = 0;
            REP(i, result.size() - 1)
            {
                sum += abs(result[i + 1] - result[i]);
                // printf("%d ", result[i]);
            }
            printf("%d\n", sum);
            return 0;
        }
    }

    return 0;
}