#!/usr/bin/env python3

import re
import sys


def get_meminfo():
    meminfo = {}
    for line in open("/proc/meminfo").readlines():
        match = re.match(r"(.*):\s+(.*)", line)
        if match:
            key = match.group(1)
            value = match.group(2)
            meminfo[key] = value

    return meminfo


def main(args):
    meminfo = get_meminfo()
    amount, units = meminfo["MemTotal"].split()

    amount = float(amount)
    next_units = {'kB': 'MB',
                  'MB': 'GB'}

    while amount > 1024:
        amount = amount / 1024
        units = next_units[units]

    print("%.1f %s" % (amount, units))
    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))
