PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000237. Bật và tắt máy va chạm (Colliders)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bật và tắt máy va chạm (Colliders)

Colliders

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn colliders numbered 11 through nn. Initially, all of them are switched off. The currently active colliders are safe exactly when the numbers assigned to every two distinct active colliders are coprime (their greatest common divisor is 11).

Process mm requests in order:

  • + i: try to activate collider ii. If it is already on, leave it unchanged. If a different active collider has a non-coprime number, reject the activation without changing the state. Otherwise activate it.
  • - i: try to deactivate collider ii. If already off, nothing changes; otherwise switch it off.

Report the result of every request. If several active colliders conflict with an activation, reporting any one of their indices is accepted.

Input

  • The first line contains integers n,mn,m, the number of colliders and requests.
  • Each of the following mm lines contains + or -, a space, and integer ii (1≤i≤n1\le i\le n).

Output

Print exactly mm lines, one per request:

  • Success: the requested state change succeeded.
  • Already on: the collider was already active.
  • Already off: the collider was already inactive.
  • Conflict with j: the activation failed because active collider jj has gcd⁡(i,j)>1\gcd(i,j)>1; any valid conflicting index is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤501\le n\le 50; 1≤m≤1001\le m\le 100; every request is + i or - i, 1≤i≤n1\le i\le n.

  • Subtask 2 (30 points): 1≤n≤50001\le n\le 5000; 1≤m≤50001\le m\le 5000; every request is + i or - i, 1≤i≤n1\le i\le n.

  • Subtask 3 (50 points): 1≤n≤1051\le n\le 10^5; 1≤m≤1051\le m\le 10^5; every request is + i or - i, 1≤i≤n1\le i\le n.

Examples

Input

10 10
+ 6
+ 10
+ 5
- 10
- 5
- 6
+ 10
+ 3
+ 6
+ 3

Output

Success
Conflict with 6
Success
Already off
Success
Success
Success
Success
Conflict with 10
Already on

Explanation

All colliders start off. Request 1 activates 66. Request 2 cannot activate 1010 because gcd⁡(10,6)=2\gcd(10,6)=2. Request 3 activates 55 as gcd⁡(5,6)=1\gcd(5,6)=1. Request 4 attempts to deactivate the still-inactive 1010, so it reports Already off. Requests 5 and 6 switch 55 and 66 off. Requests 7 and 8 successfully activate 1010 and 33, which are coprime. Request 9 tries to activate 66, but it conflicts with both 1010 (gcd 22) and 33 (gcd 33); the sample chooses Conflict with 10, while Conflict with 3 is also valid. Request 10 reports Already on because 33 remains active.