UVA12140 Magic Rings

Description

[problemUrl]: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=243&page=show_problem&problem=3292 [PDF](https://uva.onlinejudge.org/external/121/p12140.pdf) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA12140/3c73a8029dd191875299a281d69af23a8fb2ec5c.png)

Input Format

![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA12140/4ee2a0185114827856ef8b1ba1a5f92445569b6b.png)

Output Format

![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA12140/4513ce67fcb3ff3f8931daab57d1db5390e37d20.png)