use std::collections::HashSet; use proconio::input; use proconio::marker::Chars; fn main() { input!{ n: usize, m: usize, s: [Chars; n] } let mut ans = vec![]; let mut remain = vec![0; n]; for i in 0..n { remain[i] = i; } for i in 0..m { let mut hands = HashSet::new(); for &j in &remain { hands.insert(s[j][i]); } if hands.len() == 3 { println!("-1"); return; } if hands.len() == 2 { if !hands.contains(&'G') { remain = remain.into_iter().filter(|&h| s[h][i] == 'C').collect(); ans.push('C'); } if !hands.contains(&'C') { remain = remain.into_iter().filter(|&h| s[h][i] == 'P').collect(); ans.push('P'); } if !hands.contains(&'P') { remain = remain.into_iter().filter(|&h| s[h][i] == 'G').collect(); ans.push('G'); } } if hands.len() == 1 { if hands.contains(&'G') { ans.push('P'); break;} if hands.contains(&'C') { ans.push('G'); break;} if hands.contains(&'P') { ans.push('C'); break;} } } while ans.len() < m { ans.push('G'); } println!("{}", ans.iter().fold(String::new(), |mut acc, &c| {acc.push(c); acc})); }