Problem:
Score : 100 points

Problem Statement

You are given a positive integer N.
Find the minimum positive integer divisible by both 2 and N.

Constraints

1 \leq N \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum positive integer divisible by both 2 and N.

Sample Input 1

3

Sample Output 1

6

6 is divisible by both 2 and 3.
Also, there is no positive integer less than 6 that is divisible by both 2 and 3.
Thus, the answer is 6.

Sample Input 2

10

Sample Output 2

10

Sample Input 3

999999999

Sample Output 3

1999999998

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
 
using namespace std;
 
int abss(vector<int> v, int b){
  int sum = 0;
  for(int i = 0; i < v.size(); i++){
    sum += abs(v.at(i) - (b + i + 1));
  }
  return sum;
}
 
int main(){
  int max = 30;
  int min = -30;
  int mid;
  int n;
  int t;
  int a, b, c;
  
  vector<int> v;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> t; v.push_back(t);
  }
  while(min <= max){
    mid = (min + max) / 2;
    a = abss(v, mid);
    b = abss(v, max);
    c = abss(v, min);
    if (a == b || a == c) {
      cout << a << endl;
      return 0;
    }
    else if(a > b) {
      min = mid + 1;
    }else if(a > c){
      max = mid - 1;
    }else{
      min += 1;
      max -= 1;
    }
  }
    
}