EditorialRepeatedly swapping adjacent inverted elements always sorts the sequence, so the answer is always YES. Reading the input takes O(N)O(N)O(N); simulating bubble sort takes O(N2)O(N^2)O(N2).