# EZPZ - Editorial

**URL:** <https://discuss.codechef.com/t/ezpz-editorial/24633>\
**Category:** editorial\
**Created:** [April 23, 2019, 8:40pm UTC](https://discuss.codechef.com/t/ezpz-editorial/24633 "2019-04-23T20:40:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luvk1412](https://discuss.codechef.com/user_avatar/discuss.codechef.com/luvk1412/32/6500_2.png) [@luvk1412](https://discuss.codechef.com/u/luvk1412)\
**Post date:** [April 23, 2019, 8:40pm UTC](https://discuss.codechef.com/t/ezpz-editorial/24633/1 "2019-04-23T20:40:43Z")

</div>

[Contest](https://www.codechef.com/GHC22019/problems/EZPZ)  
[Practice](https://www.codechef.com/problems/EZPZ)

**Difficulty:** &nbsp;Cakewalk

**Pre-requisite Knowledge:** &nbsp;Loops

**Time Complexity:&nbsp;&nbsp;** (O(N)) for each test case.

**Problem:**

You are given an integer N denoting the number of vertices of a regular polygon. Also, you are given two integers A and B denoting vertex numbers. You need to find the smallest vertex X for which the sum of the minimum distance of X from A and minimum distance of X from B is minimum.

**Quick Explanation:**

Run a loop from 1 to N and for each vertex (not A or B) calculate the sum of minimum distance of that vertex from A and B, and update the answer accordingly.

**Detailed Explanation:**

The minimum distance between two vertices P and Q on a regular polygon can be given as min(abs(Q-P), abs(N-Q+P)).

Run a loop from 1 to N and for each vertex (not A or B) calculate the sum of minimum distance of that vertex from A and B, and update the answer accordingly.

**Solution Links:**

**[Author's Solution](https://pastebin.com/64rFqUZ5)**
