Slava and tanks (Codeforces 877C)
Tags: Others, constructive algorithms

Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.Formally, map is a checkered field of size 1 × n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell n can only move to the cell n - 1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.Help Slava to destroy all tanks using as few bombs as possible.

Input: The first line contains a single integer n (2 ≤ n ≤ 100 000) — the size of the map.

Output: In the first line print m — the minimum number of bombs Slava needs to destroy all tanks.In the second line print m integers k1, k2, ..., km. The number ki means that the i-th bomb should be dropped at the cell ki.If there are multiple answers, you can print any of them.


Sample Inputs:
2

3

Sample Outputs:
3
2 1 2

4
2 1 3 2

Solution (Python):
from math import *
tt = int(input())
print(tt + tt // 2)
a1 = list(range(2, tt + 1, 2))
a2 = list(range(1, tt + 1, 2))
a1 = ' '.join([str(i) for i in a1])
a2 = ' '.join([str(i) for i in a2])
if tt % 2 == 1:
    print(a1, end=' ')
    print(a2, end=' ')
    print(a1)
else:
    print(a2, end=' ')
    print(a1, end=' ')
    print(a2)

Solution (Python):
n = int(input())
if n == 2:
    print(3)
    print(2, 1, 2)
else:
    shoots = [i for i in range(2, n + 1, 2)] + [i for i in range(1, n + 1, 2)] + [i for i in range(2, n + 1, 2)]
    print(len(shoots))
    print(' '.join(map(str, shoots)))

Solution (Python):
n = int(input())
k = list(range(2, n + 1, 2)) + list(range(1, n + 1, 2)) + list(range(2, n + 1, 2))
print(len(k))
print(' '.join(map(str, k)))