You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.

You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.

For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.

Input

The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.

The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.

Output

The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.

Examples

Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std; int main()
{
int n,a,b;
scanf("%d %d:%d",&n,&a,&b);
while(b>=)
{
b%=;
}
if(n==)
{
while(a>=)
{
a%=;
}
}
else if(n==)
{
while(a>)
{
a-=;
}
if(a==)
a++;
}
printf("%02d:%02d\n",a,b);
}

浙南联合训练赛 D - Broken Clock的更多相关文章

  1. 浙南联合训练赛 H - The number of positions

    Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say ...

  2. 浙南联合训练赛 B-Laptops

    One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the m ...

  3. 2014 多校联合训练赛6 Fighting the Landlords

    本场比赛的三个水题之一,题意是两个玩家每人都持有一手牌,问第一个玩家是否有一种出牌方法使得在第一回和对方无牌可出.直接模拟即可,注意一次出完的情况,一开始没主意,wa了一发. #include< ...

  4. 2013暑假江西联合训练赛 -- by jxust_acm 解题报告

    第6题是利用周期性求解, 第7题是 (总的序列长度-最长的满足要求的序列长度) 第8题是 设定起点,可以找到最早出现的不满足条件,然后后面都是不满足的,利用队列求解这个过程 大神给的简单,精炼的题解. ...

  5. hdu 5381 The sum of gcd 2015多校联合训练赛#8莫队算法

    The sum of gcd Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  6. 2015多校联合训练赛 Training Contest 4 1008

    构造题: 比赛的时候只想到:前面一样的数,后面 是类似1,2,3,4,5,6....t这 既是:t+1,t+1...,1,2,3,...t t+1的数目 可能 很多, 题解时YY出一个N 然后对N   ...

  7. hdu 5358 First One 2015多校联合训练赛#6 枚举

    First One Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  8. hdu 5361 2015多校联合训练赛#6 最短路

    In Touch Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total ...

  9. HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)

    pid=5358">HDU 5358 题意: 求∑​i=1​n​​∑​j=i​n​​(⌊log​2​​S(i,j)⌋+1)∗(i+j). 思路: S(i,j) < 10^10 & ...

随机推荐

  1. hdu 1969 Pie(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others)    Me ...

  2. CTSC/APIO2018 帝都一周游

    day0 报道 上午早早就起来了,两点才到酒店,然后去简单试了试机子. 不得不说今年八十中的伙食变得瓜皮了啊,去年还是大叠的5元卷,今年变成了单张的*餐卷.不知道食堂吝啬什么,面条米饭都只有一点点,还 ...

  3. python3中处理url异常

    import urllib.request import urllib.error url = 'http://c.telunyun.com/Chart/getJsonData?market=1' d ...

  4. static class 和 non static class 的区别

    static class non static class 1.用static修饰的是内部类,此时这个 内部类变为静态内部类:对测试有用: 2.内部静态类不需要有指向外部类的引用: 3.静态类只能访问 ...

  5. 安全测试===appscan扫描工具介绍

    IBM AppScan该产品是一个领先的 Web 应用安全测试工具,曾以 Watchfire AppScan 的名称享誉业界.Rational AppScan 可自动化 Web 应用的安全漏洞评估工作 ...

  6. Open WATCOM指南 - 哦这样的孤单 你冷若冰霜

    https://my.oschina.net/GIIoOS/blog/126701 WATCOM的历史可以追溯到1965年 加拿大的学生Waterloo的团队开发了叫WATFOR的Fortran编译器 ...

  7. sicily 1016. 排队接水--课程作业

                                                                                    1016. 排队接水 Time Limi ...

  8. C++中STL容器的比较

    基本参考 https://blog.csdn.net/qq_14898543/article/details/51381642 容器特性: vector:典型的序列容器,C++标准严格要求次容器的实现 ...

  9. HDU 6115 Factory LCA,暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6115 题意:中文题面 分析:直接维护LCA,然后暴力枚举集合维护答案即可. #include < ...

  10. C C++ 常被人问的问题分析

    正文  -  开始了, 直接扯淡 以下都是自己面试中遇到的常见的问题.如有不妥的地方就当见笑了. 哈哈 1. 谈谈你们服务器的架构吧. 分析: 假如这是第一个问题, 你可以走了. 可能各方面原因他不想 ...