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.



Sample input:
abc


Sample output:
cba

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]

A.sort()

ans = A[len(A) - 1] - A[0]
small = 0
large = len(A) - 1
while (True):

    if large - small == 1:
        break
    elif large - small == 2:
        ans += max(A[large] - A[large - 1], A[small + 1] - A[small])
        break
    ans += A[large - 1] - A[small] + A[large] - A[small + 1]
    small += 1
    large -= 1

print(ans)

Submission status: Runtime Error

Solution code:
S = input()

if len(s) == 2:
    print(s)
else:
    print(s[::-1])

Submission status: Runtime Error

Solution code:
s=input()
if len(s)==2:
  print(s)
else:
  print(s.reverse())

Submission status: Runtime Error

Solution code:
S=input()
if len(S)==2:
    print(S)
else:
    S.reverse()
    print(S)

Submission status: Runtime Error

Solution code:
s=input()
if len(s)==2;print(s)
else:print(s[::-1])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def cookie(p1,p2):
	if p1 % 2 == 1:
		p1 -= 1
	p1 /= 2
	p2 += p1
	return p1,p2

a,b,k = map(int, input().split())
for i in range(k):
	if i % 2 == 0:
		a,b = cookie(a,b)
	else:
		b,a = cookie(b,a)
print("{} {}".format(int(a),int(b)))

Submission status: Runtime Error

Solution code:
from itertools import accumulate


class CoeffTable:
    def __init__(self, n):
        self.n = n
        if n == 2:
            (self.p2, self.p1, self.m1, self.m2) = (0, 1, 1, 0)
        if n % 2 == 0:
            self.p1 = self.m1 = 1
            self.p2 = self.m2 = (n - 1) // 2
        else:
            self.p1 = 0
            self.m1 = 2
            self.p2 = (n - 1) // 2
            self.m2 = (n - 2) // 2
    def reverse(self):
        (self.p2, self.p1, self.m1, self.m2) = (
            self.m2,
            self.m1,
            self.p1,
            self.p2,
        )

    def cumsum(self):
        return list(accumulate([self.p2, self.p1, self.m1, self.m2]))



def main(n, seq):
    seq = sorted(seq, reverse=True)
    coeff = CoeffTable(n)
    cm = coeff.cumsum()
    ans1 = (
        2 * sum(seq[0 : cm[0]])
        + 1 * sum(seq[cm[0] : cm[1]])
        - 1 * sum(seq[cm[1] : cm[2]])
        - 2 * sum(seq[cm[2] : cm[3]])
    )
    coeff.reverse()
    rcm = coeff.cumsum()
    ans2 = (
        2 * sum(seq[0 : rcm[0]])
        + 1 * sum(seq[rcm[0] : rcm[1]])
        - 1 * sum(seq[rcm[1] : rcm[2]])
        - 2 * sum(seq[rcm[2] : rcm[3]])
    )
    ans = max(ans1, ans2)
    print(ans)
    return


if __name__ == "__main__":
    n = int(input())
    sample = []
    for _ in range(n):
        sample.append(int(input()))
    main(n, sample)

Submission status: Runtime Error

Solution code:
n = int(input())

def isTriangular(n):
    i = 1
    while( (i*(i+1))//2 <= n) :
        if (i*(i+1))//2 == n:
            return True
        i+=1
    return False


def solve(n):
    if not isTriangular(n):
        print("No")
        return
    i = 1
    jump = 2
    ans = [[1],[1]]
    while ans[-1][-1] != n:
        next_ind = list(range(ans[-1][-1]+1, ans[-1][-1]+jump+1))
        for i in range(len(next_ind)):
            ans[i].append(next_ind[i])
        ans.append(next_ind)
        i+=jump
        jump += 1
    print("Yes")
    print(len(ans))
    for x in ans:
        p_str = ""
        p_str += str(len(x))
        for b in x:
            p_str += " " 
            p_str += str(b)
        print(p_str)
solve(n)

Submission status: Runtime Error

Solution code:
args = str(input())
args = args.split(" ")
a = int(args[0])
b = int(args[1])
k = int(args[2])

turn = 0
for i in range(k):
    if (turn==0):
        if (a>0):
            if (a % 2 == 1):
                a = a - 1
        if (a>0):
            g = a/2
            a = a - g
            b = b + g
        turn=1
    elif (turn==1):
        if (b>0):
            if (b % 2 == 1):
                b = b -1
        if (b>0):
            g = b/2
            b = b - g
            a = a + g
        turn=0

print(int(a),int(b))

Submission status: Runtime Error

Solution code:
lis=list(map(int,input().split()))
if len(lis)==2:
     print(str(lis[1])+str(lis[0]))
else:
    for i in range(len(lis)):
           print(lis[i],end="")

Submission status: Runtime Error

Solution code:
A,B,K=map(int,input().split())
count=1
while count!=K:
         if  A%2!=0:
                 A-=1
         A,B=A/2,A/2+B
         count+=1
         A,B=B,A
if count%2==0:
           print(int(A),int(B))
else:
            print(int(B),int(A))

Submission status: Runtime Error

Solution code:
n = int(input())

print(100-100//n)

Submission status: Runtime Error

Solution code:
a=input()
b=list(a)
if int(a)>=100:
       print(a)
else:
      print(b[1]+b[0])

Submission status: Runtime Error

Solution code:
A = input()
if len(A) == 2:
  print(A)
else:
  return reversed(A)

Submission status: Runtime Error

Solution code:
a = input()
if len(a) == 2:
  print(a)
else:
  print(a.reverse())

Submission status: Runtime Error

Solution code:
N = input()
if len(N) == 3:
    print(::-1)
else:
    print(N)

Submission status: Runtime Error

Solution code:
a,b,k=map(int,input().split())
for i in range(1,k+1):
    if (i % 2) == 1:
        if (a % 2) == 1:
            a -= 1
            a /= 2
            b += a
        else:
            a /= 2
            b += a
    else:
        if (b % 2) == 1:
            b -= 1
            b /= 2
            a += b
        else:
            b /= 2
            a += b
print(str(int(a))+" "+str(int(b)))

Submission status: Runtime Error

Solution code:
c = input()
if len(c) == 2:
  print(c)
else:
  c[0], c[2] = c[2], c[0]
  print(c)

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
listx = [int(input()) for i in range(n)]
listx.sort()
listx = deque(listx)
listy = deque([])
ans=0

x=listx.popleft()
listy.appendleft(x)
x=listx.pop()
listy.append(x)
ans+=int(listy[1])-int(listy[0])

while len(listx)>=1:
    abs1=abs(listx[0]-listy[-1])
    abs2=abs(listx[-1]-listy[0])

    if abs1 < abs2:
        x=listx.pop()
        listy.appendleft(x)
        ans+=abs2

    else:
        x=listx.popleft()
        listy.append(x)
        ans+=abs1
        
    if listy[0] > listy[-1]:
        listy.reverse()

print(ans)

Submission status: Runtime Error

Solution code:


a=[]
N = int(input())
for i in range(N):
    a.append(int(input()))
a=sorted(a)

if(len(a)==2):
    print(abs(a[0]-a[1]))
elif(len(a)==3):
    print(max(a[2] - a[1] + a[2] - a[0], a[1]-a[0] + a[2]-a[0]))
else:
    #----------------------------------------------------------------------
    def append2big(id1, id2):
        global bBeg
        global bEnd
        global s
        if (a[id1] - bBeg + a[id2] - bEnd < a[id2] - bBeg + a[id1] - bEnd):
            id1, id2 = id2, id1
        s+=a[id1] - bBeg + a[id2] - bEnd
        bBeg = a[id1]
        bEnd = a[id2]
    def append2small(id1, id2):
        global bBeg
        global bEnd
        global s
        if (bBeg - a[id1] + bEnd - a[id2] < bBeg - a[id2] + bEnd - a[id1]):
            id1, id2 = id2, id1
        s+=bBeg - a[id1] + bEnd - a[id2]
        bBeg = a[id1]
        bEnd = a[id2]
    def append1small(id):
        global bBeg
        global bEnd
        global s
        if (bBeg - a[id] > bEnd - a[id]):
            s+=bBeg-a[id]
            bBeg = a[id]
        else:
            s+=bEnd-a[id]
            bEnd = a[id]
    def append1big(id):
        global bBeg
        global bEnd
        global s
        if (a[id] - bBeg > a[id] - bEnd):
            s+=a[id]-bBeg
            bBeg = a[id]
        else:
            s+=a[id]-bEnd
            bEnd = a[id]
    # ----------------------------------------------------------------------
    s = a[N-2]-a[0] + a[N-1] - a[0]
    bBeg = a[N-2]
    bEnd = a[N-1]
    l = 0
    r = N-2
    cur = 0
    while(l<r-1):
        if(cur==0):
            if(l+2<r):
                append2small(l+1, l+2)
                l+=2
            elif(l+1<r):
                append1small(l+1)
                l+=1
            cur = 1-cur
        else:
            if(r-2>l):
                append2big(r-1, r-2)
                r-=2
            elif(r-1>l):
                append1big(r-1)
                r-=1
            cur = 1- cur
    r1 = s
    #-----case 2------
    s = a[N - 1] - a[0] + a[N - 1] - a[1]
    bBeg = a[0]
    bEnd = a[1]
    l = 1
    r = N - 1
    cur = 1
    while (l < r - 1):
        if (cur == 0):
            if (l + 2 < r):
                append2small(l + 1, l + 2)
                l += 2
            elif (l + 1 < r):
                append1small(l + 1)
                l += 1
            cur = 1 - cur
        else:
            if (r - 2 > l):
                append2big(r - 1, r - 2)
                r -= 2
            elif (r - 1 > l):
                append1big(r - 1)
                r -= 1
            cur = 1 - cur
    r2 = s

    print(max(r1, r2))

Submission status: Runtime Error

Solution code:
a=[]
a1,a2,c = input().split()
a.append(int(a1))
a.append(int(a2))
c = int(c)
cur = 0
for i in range(c):
    a[1-cur]+=a[cur]//2
    a[cur]//=2
    cur=1-cur
print(a[0], a[1])

Submission status: Runtime Error

Solution code:
s = input()
l = len(s)

if l==2: print(s)
else: s.reverse(); print(s)

Submission status: Runtime Error

Solution code:
from collections import deque

def main(sorted_list):
    if len(sorted_list) == 2:
        print(sorted_list.pop()- sorted_list.popleft())
        return
    if len(sorted_list) == 3:
        print(max(sorted_list[1]+sorted_list[2]-sorted_list[0]*2, -sorted_list[1]-sorted_list[0]+sorted_list[2]*2))
        return
    max_num = sorted_list.pop()
    left = sorted_list.popleft()
    right = sorted_list.popleft()
    ans = 2*max_num - left - right
    status = 'max'

    while sorted_list:
        if status == 'max':
            num = sorted_list.pop()
            status = 'min'
            if left < right:
                ans += num - left
                left = num
            else:
                ans += num - right
                right = num
        else:
            num = sorted_list.popleft()
            status = 'max'
            if left < right:
                ans += right - num
                right = num
            else:
                ans += left - num
                left = num
    print(ans)


if __name__ == '__main__':
    n = int(input())
    sample = []
    for _ in range(n):
        sample.append(int(input()))
    sorted_list = deque(sorted(sample))
    main(sorted_list)

Submission status: Runtime Error

Solution code:
import itertools
n=int(input())
x=[int(input()) for i in range(n)]
listX = list(itertools.permutations(x, n))

listY = []
for j in range(len(listX)):
  y = 0
  for i in range(n-1):
    y = y + abs(listX[j][i]-listX[j][i+1])
  listY.append(y)

print(max(listY))

Submission status: Runtime Error

Solution code:
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(S):
    x = S
    if len(S) == 2:
        return S
    elif len(S) == 3 :
        return x[2] + x[1] + x[0]

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    return int(line)

def main():
    n = readQuestion()
    answer = solve(n)
    print(answer)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = input()

listed_S = list[S]
if len(listed_S)==2:
    print(S)
elif len(listed_S)==3:
    print(S[::-1])

Submission status: Runtime Error

Solution code:
s = input()
if len(s) == 2:
  print s
else :
  print s[::-1]

Submission status: Runtime Error

Solution code:
a,b,k = (int(x) for x in input().split())

cnt = 0

while cnt < k:
    if a % 2 !=0:
        a -= 1
    a = a/2
    b += a
    cnt += 1

    if b % 2 !=0:
        b -= 1
    b = b/2
    a += b
    cnt += 1

a = int(a)
b = int(b)
print(a,b,k)

Submission status: Runtime Error

Solution code:
S = input()
if len(S) ==2:
    print(S)
else:
　print(S[::-1])

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted([int(input()) for i in range(N)])

if N % 2 == 0:
    print(2 * (sum(A[N // 2:]) - sum(A[:N // 2])) - (A[N // 2] - A[N // -1]))
else:
    print(2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2])) - min(A[N // 2] - A[N // 2 - 1], A[N // 2 + 1] - A[N // 2]))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
ans=0
if N % 2 == 0:
    ans = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) + A[N // 2] - A[N // 2 - 1]
else:
    x = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) - A[N // 2] - A[N // 2 - 1]
    y = 2 * (sum(A[N // 2 + 2:]) - sum(A[:N // 2])) + A[N // 2] + A[N // 2 + 1]
    ans = max(x, y)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import pandas as pd

N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
ans=0
if N % 2 == 0:
    ans = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) + A[N // 2] - A[N // 2 - 1]
else:
    x = 2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2 - 1])) - A[N // 2] - A[N // 2 - 1]
    y = 2 * (sum(A[N // 2 + 2:]) - sum(A[:N // 2])) + A[N // 2] + A[N // 2 + 1]
    ans = max(x, y)
print(ans)

Submission status: Runtime Error

Solution code:
import sys

def main(input):
    return input if len(input) == 2 else input[::-1]

if __name__ == "__main__":
    print main(sys.stdin.readline().strip())

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys


def main(input):
    return input if len(input) == 2 else ''.join(reversed(input))

if __name__ == "__main__":
    print main(sys.stdin.readline().strip())

Submission status: Runtime Error

Solution code:
a, b, k = map(int, raw_input().split())

stop = 0

for i in range(k):
    if i % 2 == 0:
        a /= 2
        b += a
        if b == a * 2:
            stop = i + 1
            break
    if i % 2 == 1:
        b /= 2
        a += b
        if a == b * 2:
            print i
            stop = i + 1

if stop == 0 or (k - stop) % 2 == 0:
    print a, b
else:
    print b, a

Submission status: Runtime Error

Solution code:
A,B,K = map(int,input().split())
i = 1
c = 1
while i <= K:
    if c % 2 == 1:
        if A % 2 == 0:
            A_ = A // 2
            A = A_
            B = B + A_
        else:
            A -= 1
            A_ = A // 2
            A = A_
            B = B + A_

        i += 1
        c += 1
    else:
        if B % 2 == 0:
            B_ = B //2
            A = A + B_
            B = B_
        else:
            B -= 1
            B_ = B //2
            A = A + B_
            B = B_

        i += 1
        c += 1
print(A,B)

Submission status: Runtime Error

Solution code:
s=input()
if len(s)%2:
  s.reverse()
print(s)

Submission status: Runtime Error

Solution code:
n = input()
print n if len(n)==2 else n[::-1]

Submission status: Runtime Error

Solution code:
input_str = str(input()).split()
a, b, k = int(input_str[0]), int(input_str[1]), int(input_str[2])

self = a
partner = b

for i in range(k):
    if self % 2 == 1:
        self += -1

    partner += int(self / 2)
    self = int(self / 2)

    self, partner = partner, self
    i -= 1

if i % 2 == 1:
    a = partner
    b = self
else:
    b = partner
    a = self

print(a, b)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
q=int(math.sqrt(N*2))
if N*2!=q*q+q:print("No");exit()
S=[list(range(1,q+1))]
S+=[[j]for j in S[0]]
last=q
for i in range(1,q):
	r=list(range(last+1,last+1+q-i))
	S[i]+=r
	for j in range(q-i):S[i+j+1]+=[r[j]]
	last=r[-1]
print("Yes")
print(len(S))
for s in S:print(len(s)," ".join(map(str,s)))

Submission status: Runtime Error

Solution code:
S = input()
if len(S) == 2:
	print(type(S)
elese:
	S = S[::-1]
	print(type(S)

Submission status: Runtime Error

Solution code:
S = input()
if len(S) == 2:
	print(S)
elese:
	S = S[::-1]
	print(S)

Submission status: Runtime Error

Solution code:
= input()
if len(S) == 2:
	print(S)
elese:
	S = S[::-1]
	print(S)

Submission status: Runtime Error

Solution code:
a, b, c= (int(i) for i in input().split())
for i in range(c):
 if(i%2==0):
  a=a//2
  b=b+a
 else:
  b=b//2
  a=a+b
print(a,b)

Submission status: Runtime Error

Solution code:
a, b, c= (int(i) for i in input().split())
for i in range(c):
 if(i%2==0):
  a=a//2
  b=b+a//2
 else:
  b=b//2
  a=a+b//2
print(a,b)

Submission status: Runtime Error

Solution code:
a, b, c = (int(i) for i in input().split()) 
for i in range(c):
 if(i%2==0):
  a=a//2
  b=b+a//2
 else:
  b=b//2
  a=a+b//2
print(a,b)

Submission status: Runtime Error

Solution code:
!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
a=[]
for i in range(0,n):
  a.append(int(input()))
a.sort()

b = [a[0]]
l = a[0]
r = a[0]
a=a[1:]
res=0

while len(a)>0:
  al = a.pop()
  lx = abs(l-al)
  rx = abs(r-al)

  if lx > rx:
    res = res + lx
    l = al
    if len(a)>0:
      ta = a.pop()
      res = res + abs(r-ta)
      r=ta
  else:
    res = res + rx
    r = al
    if len(a)>0:
      ta = a.pop()
      res = res + abs(l-ta)
      l = ta
  #
  if len(a)>0:
    af = a[0]
    a = a[1:]
    ln = abs(l-af)
    rn = abs(r-af)
    if ln > rn:
      res = res + ln
      l = af
      if len(a)>0:
        ta=a[0]
        res=res+abs(r-ta)
        r=ta
        a=a[1:]
    else:
      res = res + rn
      r = af
      if len(a)>0:
        ta=a[0]
        res=res+abs(l-ta)
        l=ta
        a=a[1:]


print(res)

Submission status: Runtime Error

Solution code:
N=(input())
if len(N)==3:
...     N = N[::-1]
...     print(N)
... elif len(N)==2:
...     print(N)

Submission status: Runtime Error

Solution code:
    a=input()
    if len(a)==2:
        print(a)
    else:
        print(a[::-1])

Submission status: Runtime Error

Solution code:
n = int(input())

a = [0] * n

for i in range(0, n):
  a[i] = int(input())

a.sort()

c = 0

if len(a) == 2:
  print(abs(a[0] - a[1]))

if len(a) == 3:
  diff = abs(a[0] - a[1]) + abs(a[1] - a[2])
  diff = max(abs(a[0] - a[2]) + abs(a[1] - a[2]), diff)
  diff = max(abs(a[0] - a[2]) + abs(a[0] - a[1]), diff)
  print(diff)

mini = 0
maxi = len(a) - 1

if len(a) > 3:
  (l, r) = (a[maxi], a[maxi - 1])
  maxi -= 2
  diff = abs(a[0] - l) + abs(a[0] - r)
  mini += 1
  for i in range(0, n - 3):
    if i % 2 == 0:
      if c < 2:
        diff += abs(a[mini] - l)
        l = a[mini]
        mini += 1
      else:
        diff += abs(a[maxi] - l)
        l = a[maxi]
        maxi -= 1
    else:
      if c < 2:
        diff += abs(a[mini] - r)
        r = a[mini]
        mini += 1
      else:
        diff += abs(a[maxi] - r)
        r = a[maxi]
        maxi -= 1
    if c < 3:
      c += 1
    else:
      c = 0
  
  maxi = len(a) - 1
  mini = 0
  (l, r) = (a[mini], a[mini + 1])
  mini += 2
  diff2 = abs(a[-1] - l) + abs(a[-1] - r)
  maxi -= 1
  for i in range(0, n - 3):
    if i % 2 == 0:
      if c > 1:
        diff2 += abs(a[mini] - l)
        l = a[mini]
        mini += 1
      else:
        diff2 += abs(a[maxi] - l)
        l = a[maxi]
        maxi -= 1
    else:
      if c > 1:
        diff2 += abs(a[mini] - r)
        r = a[mini]
        mini += 1
      else:
        diff2 += abs(a[maxi] - r)
        r = a[maxi]
        maxi -= 1
    if c < 3:
      c += 1
    else:
      c = 0

  print(max(diff, diff2))

Submission status: Runtime Error

Solution code:
#coding:utf-8
import copy
N = int(input())
A_list = []
for i in range(N):
    A_list.append(int(input()) )

def calculate_x(list):
    len_list = len(list)
    sum = 0
    for i in range(len_list-1):
        sum = sum + abs(list[i]-list[i+1])
    return sum

A_list = sorted(A_list)

if N % 2 ==0: #even
    answer_list = []
    A_min_list = A_list[:int(N/2)-1]
    A_max_list = A_list[-int(N/2)+1:]
    for max, min in zip(A_max_list, A_min_list):
        answer_list.append(max)
        answer_list.append(min)
    answer_list.append(A_list[int(N/2)]) #min of max_list
    answer_list.insert(0,A_list[int(N/2)-1]) #max of min_list
    tmp = calculate_x(answer_list)
    print(tmp)

else: #odd
    answer_list = []
    A_min_list = A_list[:int((N-1)/2)-1] #0,1
    A_max_list = A_list[-int((N-1)/2)+1:] #5,6
    x1 = A_list[int((N-1)/2)-1] #2
    x2 = A_list[int((N-1)/2)]#3
    x3 = A_list[int((N-1)/2)+1]#4
    for max, min in zip(A_max_list, A_min_list):
        answer_list.append(max)
        answer_list.append(min)

    answer_list2 = copy.deepcopy(answer_list)
    max = 0
    answer_list2.append(x1)
    answer_list2.insert(0,x2)
    answer_list2.insert(0,x3)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x1)
    answer_list2.insert(0,x3)
    answer_list2.insert(0,x2)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x2)
    answer_list2.insert(0,x1)
    answer_list2.insert(0,x3)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x2)
    answer_list2.insert(0,x3)
    answer_list2.insert(0,x1)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x3)
    answer_list2.insert(0,x1)
    answer_list2.insert(0,x2)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp

    answer_list2 = copy.deepcopy(answer_list)
    answer_list2.append(x3)
    answer_list2.insert(0,x2)
    answer_list2.insert(0,x1)
    tmp = calculate_x(answer_list2)
    if tmp > max:
        max = tmp



    answer_list3 = []
    A_min_list = A_list[:int((N-1)/2)-1] #0,1
    A_max_list = A_list[-int((N-1)/2)+1:] #5,6
    x1 = A_list[int((N-1)/2)-1] #2
    x2 = A_list[int((N-1)/2)]#3
    x3 = A_list[int((N-1)/2)+1]#4
    for max, min in zip(A_max_list, A_min_list):
        answer_list3.append(min)
        answer_list3.append(max)

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x1)
    answer_list4.insert(0,x2)
    answer_list4.insert(0,x3)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x1)
    answer_list4.insert(0,x3)
    answer_list4.insert(0,x2)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x2)
    answer_list4.insert(0,x1)
    answer_list4.insert(0,x3)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x2)
    answer_list4.insert(0,x3)
    answer_list4.insert(0,x1)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x3)
    answer_list4.insert(0,x1)
    answer_list4.insert(0,x2)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp

    answer_list4 = copy.deepcopy(answer_list3)
    answer_list4.append(x3)
    answer_list4.insert(0,x2)
    answer_list4.insert(0,x1)
    tmp = calculate_x(answer_list4)
    if tmp > max:
        max = tmp
    print(max)

Submission status: Runtime Error

Solution code:
N = int(input())
l=[int(input()) for i in range(N)]
l.sort()
res = 0
k = 0
o = 0
if N%2 == 0:
    a = l[:int(N/2)]
    a.reverse()
    b = l[int(N/2):]
    b.reverse()
    for i in range(N-1):
        res += b[k] - a[o]
        if i%2 == 0:
            o += 1
        if i%2 == 1:
            k += 1
else:
    a = l[:int(N/2)]
    b = l[int(N/2)+1:]
    b.reverse()
    for i in range(N-2):
        res += b[k] - a[o]
        if i%2 == 0:
            k += 1
        if i%2 == 1:
            o += 1
    res += max(abs(a[-1] - l[int(N/2)]), abs(b[-1] - l[int(N/2)]))
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()

if n%2 != 0:
        m = int(n/2)
        x = 0
        y = 0
        z = max(a[2*m]-a[m], a[m]-a[0])
        for i in range(m):
                x += int(a[2*m-i] - a[i])
        for i in range(m-1):
                y += int(a[2*m-1-i] - a[i])
        print(x+y+z)
elif n%2 == 0:
        m = int(n/2)
        x = 0
        y = 0
        for i in range(m-1):
                x += int(a[2*m-1-i] - a[i])
        for i in range(m-2):
                y += int(a[2*m-2-i] - a[i])
        print(x+y+a[m]-a[m-2]+a[2*m-1]-a[m-1])

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
flag=0
ans=0
anslist=[]
se=0
for i in range(N):
    A.append(int(input()))
A.sort()
if N%2==0:
    anslist.append(A[-1])
    del A[-1]
else:
    anslist.append(A[0])
    del A[0]
    se=1
try:
    if se==0:
        while True:
            if flag==0:
                for i in range(2):
                    anslist.append(A[0])
                    anslist.reverse()
                    del A[0]
                flag=1
            else:
                for i in range(2):
                    anslist.append(A[-1])
                    anslist.reverse()
                    del A[-1]
                flag=0
    else:
        while True:
            if flag!=0:
                for i in range(2):
                    anslist.append(A[0])
                    anslist.reverse()
                    del A[0]
                flag=1
            else:
                for i in range(2):
                    anslist.append(A[-1])
                    anslist.reverse()
                    del A[-1]
                flag=0
 
 
except Exception as e:
    #print (anslist)
    flag=0
    while N-1>flag:
        ans=abs(anslist[flag]-anslist[flag+1])+ans
        flag=flag+1
    
    print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import deque
n=int(input())
a=[]
for i in range(0,n):
  a.append(int(input()))
a.sort()

d = [a[0]]
a=a[1:]
b = deque(d)

f=True
while len(a)>0:
  la=len(a)-1
  lb=len(b)-1
  ln = abs(b[0]-a[0])
  lx = abs(b[0]-a[la])
  rn = abs(b[lb]-a[0])
  rx = abs(b[lb]-a[la])

  x = max(ln, max(lx, max(rn, rx)))
  
  if x == ln:
    b.insert(0,a[0])
    a=a[1:]
  elif x == lx:
    b.insert(0,a.pop())
  elif x == rn:
    b.append(a[0])
    a=a[1:]
  else:
    b.append(a.pop())
#print(b)

res=0
for i in range(0,len(b)-1):
  res=res+abs(b[i]-b[i+1])
print(res)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
a=[]
for i in range(0,n):
  a.append(int(input()))
a.sort()

b = [a[0]]
a=a[1:]

f=True
while len(a)>0:
  la=len(a)-1
  lb=len(b)-1
  ln = abs(b[0]-a[0])
  lx = abs(b[0]-a[la])
  rn = abs(b[lb]-a[0])
  rx = abs(b[lb]-a[la])

  x = max(ln, max(lx, max(rn, rx)))
  
  if x == ln:
    b.insert(0,a[0])
    a=a[1:]
  elif x == lx:
    b.insert(0,a.pop())
  elif x == rn:
    b.append(a[0])
    a=a[1:]
  else:
    b.append(a.pop())

res=0
for i in range(0,len(b)-1):
  res=res+abs(b[i]-b[i+1])
print(res)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import deque
n=int(input())
a=[]
for i in range(0,n):
  a.append(int(input()))
a.sort()

d = [a[0]]
a=a[1:]
b = deque(d)

f=True
while len(a)>0:
  la=len(a)-1
  lb=len(b)-1
  ln = abs(b[0]-a[0])
  lx = abs(b[0]-a[la])
  rn = abs(b[lb]-a[0])
  rx = abs(b[lb]-a[la])

  x = max(ln, max(lx, max(rn, rx)))

  if x == ln:
    b.insert(0,a[0])
    a=a[1:]
  elif x == lx:
    b.insert(0,a.pop())
  elif x == rn:
    b.append(a[0])
    a=a[1:]
  else:
    b.append(a.pop())
#print(b)

res=0
for i in range(0,len(b)-1):
  res=res+abs(b[i]-b[i+1])
print(res)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import deque
n=int(input())
a=[]
for i in range(0,n):
  a.append(int(input()))
a.sort()

d = [a[0]]
a=a[1:]
b = deque(d)

f=True
while len(a)>0:
  la=len(a)-1
  lb=len(b)-1
  ln = abs(b[0]-a[0])
  lx = abs(b[0]-a[la])
  rn = abs(b[lb]-a[0])
  rx = abs(b[lb]-a[la])

  x = max(ln, max(lx, max(rn, rx)))

  if x == ln:
    b.insert(0,a[0])
    a=a[1:]
  elif x == lx:
    b.insert(0,a.pop())
  elif x == rn:
    b.append(a[0])
    a=a[1:]
  else:
    b.append(a.pop())

res=0
for i in range(0,len(b)-1):
  res=res+abs(b[i]-b[i+1])
print(res)

Submission status: Runtime Error

Solution code:
N = input()
A = [int(input()) for i in range(N)]

res = []
begin = 0
end = len(A) - 1
res =[]
res.append(A[begin])
res.append(A[end])
begin += 1
end -= 1

Submission status: Runtime Error

Solution code:
str=input()
x=len(str)
if x=2:
  print(str)
else:
  print(str[::-1])

Submission status: Runtime Error

Solution code:
from collections import deque
N = input()
A = [int(input()) for i in range(N)]

res = []
begin = 0
end = len(A) - 1
res = deque()
res.append(A[begin])
res.append(A[end])
begin += 1
end -= 1

Submission status: Runtime Error

Solution code:
# -*- coding-UTF-8 -*-
A, B, K = map(int, input().split())

i = 0
while True:
    i += 1
    if A%2:
         A -= 1
    A /= 2
    B += A
    if i == K:
        break
    i += 1
    if B%2:
        B -= 1
    B /= 2
    A += B
    if i == K:
        break
print(A,B)

Submission status: Runtime Error

Solution code:
A,B,K = input().split()
A=int(A)
B=int(B)
K=int(K)

if K==1:
    if A % 2 ==1:
        A =A-1
    A =A/2
    B=B+A

if K==2:
    if A % 2 ==1:
        A =A-1
    A =A/2
    B=B+A
    if B % 2==1:
        B=B-1
    B=B/2
    A=A+B

if K>=3:
    for i in range(1,K,2):
        if A % 2 ==1:
            A =A-1
        A =A/2
        B=B+A
        if B % 2==1:
            B=B-1
        B=B/2
        A=A+B

    if K%2==1:
        if A % 2 ==1:
            A =A-1
        A =A/2
        B=B+A


print (int(A),int(B))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
A.sort()
me=1
usr=N-2
lenme=A[0]
lenusr=A[N-1]
ans=A[N-1]-A[0]

for i in range(N-2):
    if max([abs(A[me]-lenme),abs(A[me]-lenusr)])>=max([abs(A[usr]-lenme),abs(A[usr]-lenusr)]):
        if abs(A[me]-lenme)>=abs(A[me]-lenusr):
            ans+=abs(A[me]-lenme)
            lenme=A[me]
        else:
            ans+=abs(A[me]-lenusr)
            lenusr=A[me]
        me+=1
    else:
        if abs(A[usr]-lenme)>=abs(A[usr]-lenusr):
            ans+=abs(A[usr]-lenme)
            lenme=A[usr]
        else:
            ans+=abs(A[usr]-lenusr)
            lenusr=A[usr]
        usr-=1
print(ans)

Submission status: Runtime Error

Solution code:
N=input()
N=int(N)
L=[]

def diff(L):
    total=0
    for i in range(len(L)-1):
        total+=abs(L[i+1]-L[i])
    return total
for i in range(N):
    A=input()
    L.append(int(A))
L.sort()
if len(L)>3:
    length=len(L)
    SL=L[:int(length/2)]
    LL=L[int(length/2):]
    result=[]
    result.append(SL[-1])
    SL.pop(-1)
    last=LL[0]
    LL.pop(0)
    while True:
        try:
            result.append(LL[-1])
            LL.pop(-1)
            result.append(SL[0])
            SL.pop(0)
        except:
            break

    result.append(last)
    print(diff(result))    
elif len(L)==3:
    all=[diff([L[0],L[1],L[2]]),diff([L[0],L[2],L[1]]),diff([L[1],L[0],L[2]]),diff([L[1],L[2],L[0]]),diff([L[2],L[0],L[1]]),diff([L[2],L[1],L[0]])]
    print(max(all))
elif len(L)==2:
    print(abs(L[0]-L[1]))