Pack and Unpack
Python
Medium
2 views
Problem Description
One line has n and then n integers. Store them into variables: first, middle (all), last. Output first, count of middle elements, last.
Input Format
One line: n a1 a2 ... an.
Output Format
One line: first midCount last.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
n=int(p[0])
arr=list(map(int,p[1:1+n]))
first=arr[0]
last=arr[-1]
midCount=max(0,n-2)
sys.stdout.write(f"{first} {midCount} {last}")
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!