#include<iostream>
#include<iomanip>
using namespace std;

class Timeconverter
{
    private:
    string time12;
    public:
    Timeconverter(string t)
    {
        time12=t;
    }
    void convert()
    {
        if(time12.length() !=10)
        {
            cout<<"Invalid input";
            return;
        }
        int hh=stoi(time12.substr(0,2));
        int mm=stoi(time12.substr(3,2));
        int ss=stoi(time12.substr(6,2));
        string period =time12.substr(8,2);
        
        if(time12[2] != ':'||time12[5] !=':'||(period != "AM"&& period != "PM")||hh<1||hh>12||mm<0||mm>59||ss<0||ss>59)
        {
            cout<<"Invalid input";
            return;
        }
    }
}