// Arup Guha
// 3/12/2024
// Solution for COP 3503 Exam 2 Question 8

import java.util.*;

public class e2dfs {

	// Put your test here.
	public static void main(String[] args) {
		dfswrapper(100, 78, 83, 98);
	}
	
	public static void dfswrapper(int n, int a, int b, int s) {
		boolean[] used = new boolean[n];
		dfs(n,a,b,s,used);
		
		// I added this to see where we can get to.
		for (int i=0; i<n; i++)
			if (used[i])
				System.out.print(i+" ");
		System.out.println();
	}

	// Marks all reachable floors in a building of n floors starting 
	// at the floor cur with an elevator that can go up a floors or
	// go down b floors.
	public static void dfs(int n, int a, int b, int cur, boolean[] used) {

		// Mark it.
		used[cur] = true;

		// Go up if it's inbounds and not previously visited.
		if (cur+a < n && !used[cur+a]) dfs(n, a, b, cur+a, used);

		// Go down if it's inbounds and not previously visited.
		if (cur-b >=0 && !used[cur-b]) dfs(n, a, b, cur-b, used);
	}

}