UVA838 Worm World

Description

[problemUrl]: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=10&page=show_problem&problem=779 [PDF](https://uva.onlinejudge.org/external/8/p838.pdf) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA838/6001fbbcec4d97e723bc5f2f5aa065f05f356c05.png)

Input Format

![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA838/98d9c1233e7fef2ee1a1c6ebf3b5e5fea979d844.png)

Output Format

![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA838/764b5dd8244645885dab54bf2df590346cef5316.png)