ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?

The first and only line of the input contains a single string s (1 ≤ |s| ≤ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.

If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print  - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.

NoteIn the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1.In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.

use std::io::prelude::*;
use std::io;
use std::str;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [-1i32; 26];
    let mut laschr : Vec<char> = vec![];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for (i, ch) in s.chars().enumerate() {
        laschr.push(ch);

        match ch {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;
            }
        }

        if i > 25 {
            match laschr.remove(0) {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and store the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string
        if count + wildcd >= 26 {

            let mut output = String::new();

            for chr in s.chars().take(i-25) {
                //print 'A' in the question mark spots before the substring
                match chr {
                    '?' => {
                        output.push('A');
                    },
                    c => {
                        output.push(c);
                    }
                }
            }

            for chr in s.chars().skip(i-25) {

                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        output.push(letters.pop().unwrap_or('Z'));
                    },
                    c => {
                        output.push(c);
                    }
                }
            }

            println!("{}", output);
            return;
        }

    }

    println!("-1");
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main(){

    let cs: Vec<char> = get_line().chars().collect();
    let len = cs.len();

    if len < 26 {
        println!("-1");
        return;
    }

    for i in 0..len-25 {
        let mut freq: Vec<usize> = vec![0;26];
        for j in i..i+26 {
            if cs[j] == '?' {
                continue;
            }
            let c = cs[j] as usize - 'A' as usize;
            freq[c] += 1;
        }

        if freq.iter().any(|&x: &usize| x > 1) {
            continue;
        }

        for j in 0..i {
            print!("{}", if cs[j] == '?' { 'A' } else { cs[j] })
        }

        for j in i..i+26 {
            if cs[j] != '?' {
                print!("{}", cs[j]);
            } else {
                for k in 0..26 {
                    if freq[k] == 0 {
                        print!("{}", (k as u8 + 'A' as u8) as char);
                        freq[k] = 1;
                        break;
                    }
                }
            }
        }

        for j in i+26..len {
            print!("{}", if cs[j] == '?' { 'A' } else { cs[j] })
        }
        return;
    }

    println!("-1")
}

#[allow(dead_code)]
fn get_line() -> String{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_string()
}

#[allow(dead_code)]
fn readln<T: Read>() -> T{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

trait Read{
    fn read(s: &str) -> Self;
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl<T: Read> Read for Vec<T>{
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B){
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C){
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

#![allow(unused_imports)]
use std::io::*;
use std::cmp::*;
use std::collections::*;

macro_rules! debug(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

struct Scanner {
   buffer : std::collections::VecDeque<String>
}

impl Scanner {

   fn new() -> Scanner {
      Scanner {
         buffer: std::collections::VecDeque::new()
      }
   }

   fn next<T : std::str::FromStr >(&mut self) -> T {

      if self.buffer.len() == 0 {
         let mut input = String::new();
         std::io::stdin().read_line(&mut input).ok();
         for word in input.split_whitespace() {
            self.buffer.push_back(word.to_string())
         }
      }

      let front = self.buffer.pop_front().unwrap();
      front.parse::<T>().ok().unwrap()
   }
}

fn checked_sub(a : usize, b : usize) -> usize {
   if b > a {
      println!("Checked sub failed!, {}, {}", a, b);
   }
   a - b
}

fn main() {
   let mut s = Scanner::new();
   let buffer : String = s.next();
   let mut input = buffer.into_bytes();

   let mut set : [i32; 30] = [0; 30];
   let mut count = 0;
   let mut left = 0;
   let mut right = 26;
   let b = 'A' as usize;

   if input.len() < 26 {
      println!("-1");
      return;
   }

   for i in left..right {
      let c = input[i] as char;
      let k = input[i] as usize;
      if c == '?' {
         count += 1;
         set[26] += 1;
      } else {

         if set[checked_sub(k, b)] == 0 {
            count += 1;
         }
         set[checked_sub(k, b)] += 1;
      }
   }

   let mut tail = input[left] as usize;
   for i in right..input.len() {
      let c = input[i] as char;
      let k = input[i] as usize;

      if count == 26 {
         break;
      }

      if tail == '?' as usize {
         set[26] -= 1;
         count -= 1;
      } else {
         set[checked_sub(tail, b)] -= 1;
         if set[checked_sub(tail, b)] == 0 {
            count -= 1;
         }
      }

      if c == '?' {
         count += 1;
         set[26] += 1;
      } else {
         if set[checked_sub(k, b)] == 0 {
            count += 1;
         }
         set[checked_sub(k, b)] += 1;
      }

      left += 1;
      right += 1;
      tail = input[left] as usize;
   }

   if count == 26 {

      for i in 0..left {
         let c = input[i] as char;
         if c == '?' {
            input[i] = 'A' as u8;
         }
      }

      for i in left..right {
         let c = input[i] as char;
         if c == '?' {
            for j in 0..27 {
               if set[j] == 0 {
                  let k = j as u8;
                  input[i] = k + b as u8;
                  set[j] = 1;
                  break;
               }
            }
         }
      }

      for i in right..input.len() {
         let c = input[i] as char;
         if c == '?' {
            input[i] = 'A' as u8;
         }
      }

      for i in input.iter() {
         print!("{}", *i as char);
      }
      println!("");
   } else {
      println!("-1");
   }
}

#![allow(unused_imports)]
use std::io::*;
use std::cmp::*;
use std::collections::*;

macro_rules! debug(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

fn main() {
   let mut buffer : String = String::new();
   stdin().read_line(&mut buffer).ok();
   let mut input = buffer.trim().to_string().into_bytes();

   let mut set : [i32; 30] = [0; 30];
   let mut count = 0;
   let mut left = 0;
   let mut right = 26;
   let b = 'A' as usize;

   if input.len() < 26 {
      println!("-1");
      return;
   }

   for i in left..right {
      let c = input[i] as char;
      let k = input[i] as usize;
      if c == '?' {
         count += 1;
         set[26] += 1;
      } else {

         if set[k - b] == 0 {
            count += 1;
         }
         set[k - b] += 1;
      }
   }

   let mut tail = input[left] as usize;
   for i in right..input.len() {
      let c = input[i] as char;
      let k = input[i] as usize;

      if count == 26 {
         break;
      }

      if tail == '?' as usize {
         set[26] -= 1;
         count -= 1;
      } else {
         set[tail - b] -= 1;
         if set[tail - b] == 0 {
            count -= 1;
         }
      }

      if c == '?' {
         count += 1;
         set[26] += 1;
      } else {
         if set[k - b] == 0 {
            count += 1;
         }
         set[k - b] += 1;
      }

      left += 1;
      right += 1;
      tail = input[left] as usize;
   }

   if count == 26 {

      for i in 0..left {
         let c = input[i] as char;
         if c == '?' {
            input[i] = 'A' as u8;
         }
      }

      for i in left..right {
         let c = input[i] as char;
         if c == '?' {
            for j in 0..27 {
               if set[j] == 0 {
                  let k = j as u8;
                  input[i] = k + b as u8;
                  set[j] = 1;
                  break;
               }
            }
         }
      }

      for i in right..input.len() {
         let c = input[i] as char;
         if c == '?' {
            input[i] = 'A' as u8;
         }
      }

      for i in input.iter() {
         print!("{}", *i as char);
      }
      println!("");
   } else {
      println!("-1");
   }
}

use std::io::prelude::*;
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [(s.len()); 26];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for i in 0..(s.len()) {
        match s.chars().skip(i).next().unwrap() {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i;
            }
        }

        if i > 26 {
            match s.chars().skip(i-26).next().unwrap() {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and remember the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if i - laspos[j] < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string.
        if count + wildcd >= 26 {
            for chr in s.chars().skip(i-25).take(26) {
                match chr {
                    '?' => {
                        print!("{}", letters.pop().unwrap_or('?'));
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }
            println!("");
            return;
        }

    }

    println!("-1");
}

use std::io::prelude::*;
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [(s.len()+27); 26];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for i in 0..(s.len()) {
        match s.chars().skip(i).next().unwrap() {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i;
            }
        }

        if i > 26 {
            match s.chars().skip(i-26).next().unwrap() {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and remember the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if i - laspos[j] < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string.
        if count + wildcd >= 26 {
            for chr in s.chars().skip(i-25).take(26) {
                match chr {
                    '?' => {
                        print!("{}", letters.pop().unwrap_or('?'));
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }
            println!("");
            return;
        }

    }

    println!("-1");
}

use std::io::prelude::*;
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [-1i32; 26];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for i in 0..(s.len()) {
        match s.chars().skip(i).next().unwrap() {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;
            }
        }

        if i > 26 {
            match s.chars().skip(i-26).next().unwrap() {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and remember the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string.
        if count + wildcd >= 26 {
            for chr in s.chars().skip(i-25).take(26) {
                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        print!("{}", letters.pop().unwrap_or('?'));
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }
            println!("");
            return;
        }

    }

    println!("-1");
}

use std::io::prelude::*;
use std::io;
use std::str;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [-1i32; 26];
    let mut laschr : Vec<char> = vec![];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for (i, ch) in s.chars().enumerate() {
        laschr.push(ch);

        match ch {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;
            }
        }

        if i > 26 {
            match laschr.remove(0) {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and remember the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string
        if count + wildcd >= 26 {

            let mut output = String::new();

            for chr in s.chars().take(i-25) {
                //print 'A' in the question mark spots before the substring
                match chr {
                    '?' => {
                        output.push('A');
                    },
                    c => {
                        output.push(c);
                    }
                }
            }

            for chr in s.chars().skip(i-25) {

                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        output.push(letters.pop().unwrap_or('Z'));
                    },
                    c => {
                        output.push(c);
                    }
                }
            }

            println!("{}", output);
            return;
        }

    }

    println!("-1");
}

use std::io::prelude::*;
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [-1i32; 26];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for i in 0..(s.len()) {
        match s.chars().skip(i).next().unwrap() {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;
            }
        }

        if i > 26 {
            match s.chars().skip(i-26).next().unwrap() {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and remember the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string.
        if count + wildcd >= 26 {

            for chr in s.chars().take(i-25) {
                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        print!("A");
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }

            for chr in s.chars().skip(i-25).take(26) {
                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        print!("{}", letters.pop().unwrap_or('?'));
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }

            for chr in s.chars().skip(i) {
                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        print!("A");
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }
            println!("");
            return;
        }

    }

    println!("-1");
}

use std::io::prelude::*;
use std::io;
use std::str;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [-1i32; 26];
    let mut laschr : Vec<char> = vec![];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for (i, ch) in s.chars().enumerate() {
        laschr.push(ch);

        match ch {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;
            }
        }

        if i > 26 {
            match laschr.remove(0) {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and remember the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string
        if count + wildcd >= 26 {

            let mut output = String::new();

            for chr in s.chars().take(i-25) {
                //print 'A' in the question mark spots before the substring
                match chr {
                    '?' => {
                        output.push('A');
                    },
                    c => {
                        output.push(c);
                    }
                }
            }

            for chr in s.chars().skip(i-25).take(26) {

                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        output.push(letters.pop().unwrap_or('?'));
                    },
                    c => {
                        output.push(c);
                    }
                }
            }

            for chr in s.chars().skip(i+1) {

                //print 'Z' in the question mark spots after the substring
                match chr {
                    '?' => {
                        output.push('Z');
                    },
                    c => {
                        output.push(c);
                    }
                }
            }
            println!("{}", output);
            return;
        }

    }

    println!("-1");
}

use std::io::prelude::*;
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [-1i32; 26];
    let mut laschr : Vec<char> = vec![];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for (i, ch) in s.chars().enumerate() {
        laschr.push(ch);

        match ch {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;
            }
        }

        if i > 26 {
            match laschr.remove(0) {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and remember the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string.
        if count + wildcd >= 26 {

            for chr in s.chars().take(i-25) {
                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        print!("A");
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }

            for chr in s.chars().skip(i-25).take(26) {

                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        print!("{}", letters.pop().unwrap_or('?'));
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }

            for chr in s.chars().skip(i+1) {

                //print missing letters in the question mark spots
                match chr {
                    '?' => {
                        print!("A");
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }
            println!("");
            return;
        }

    }

    println!("-1");
}

use std::io::prelude::*;
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut s = stdin.lock().lines().next().unwrap().unwrap();

    is_nice_word(&s);
}

fn is_nice_word(s: &String) {

    // list of the last position each letter A-Z was seen
    let mut laspos = [-1i32; 26];
    //how many wildcards '?' there were in the last 26 characters
    let mut wildcd = 0;

    for i in 0..(s.len()) {
        match s.chars().skip(i).next().unwrap() {
            '?' => {
                wildcd += 1;
            },
            chr => {
                laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;
            }
        }

        if i > 26 {
            match s.chars().skip(i-26).next().unwrap() {
                '?' => {
                    wildcd -= 1;
                },
                _ => ()
            }
        }

        // count how many letters occur in the last 26 characters and remember the ones that didn't
        // also keep track of how many wildcards we have seen
        let mut count = 0;
        let mut letters : Vec<char>= vec![];
        for j in 0..26 {
            if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {
                count += 1;
            } else {
                letters.push((('A' as u8) + j as u8) as char);
            }
        }

        //If we have seen enough characters and wildcards, print out the string.
        if count + wildcd >= 26 {
            for chr in s.chars().skip(i-25).take(26) {
                match chr {
                    '?' => {
                        print!("{}", letters.pop().unwrap_or('?'));
                    },
                    c => {
                        print!("{}", c);
                    }
                }
            }
            println!("");
            return;
        }

    }

    println!("-1");
}

#![allow(unused_imports)]
use std::io::*;
use std::cmp::*;
use std::collections::*;

macro_rules! debug(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

struct Scanner {
   buffer : std::collections::VecDeque<String>
}

impl Scanner {

   fn new() -> Scanner {
      Scanner {
         buffer: std::collections::VecDeque::new()
      }
   }

   fn next<T : std::str::FromStr >(&mut self) -> T {

      if self.buffer.len() == 0 {
         let mut input = String::new();
         std::io::stdin().read_line(&mut input).ok();
         for word in input.split_whitespace() {
            self.buffer.push_back(word.to_string())
         }
      }

      let front = self.buffer.pop_front().unwrap();
      front.parse::<T>().ok().unwrap()
   }
}

fn main() {
   let mut s = Scanner::new();
   let input = s.next::<String>();
   let mut set = [0; 27];
   let mut count = 0;
   let mut left = 0;
   let mut right = 26;

   for i in input.chars().take(26) {
      let k = i as usize;
      let b = 'A' as usize;
      if i == '?' {
         count += 1;
         set[26] += 1;
      } else {
         if set[k - b] == 0 {
            count += 1;
         }
         set[k - b] += 1;
      }
   }

   let mut ans : String = input[left..right].to_string();

   let mut tail = input.chars().nth(1).unwrap() as usize;
   for i in input.chars().skip(26) {
      let k = i as usize;
      let b = 'A' as usize;

      if count == 26 {
         ans = input[left..right].to_string();
         break;
      }

      if tail == '?' as usize {
         set[26] -= 1;
         count -= 1;
      } else {
         set[tail - b] -= 1;
         if set[tail - b] == 0 {
            count -= 1;
         }
      }

      if i == '?' {
         count += 1;
         set[26] += 1;
      } else {
         if set[k - b] == 0 {
            count += 1;
         }
         set[k - b] += 1;
      }

      tail = k;
      left += 1;
      right += 1;
   }

   let mut filled : String = String::new();

   for i in ans.chars() {
      let b = 'A' as u8;
      if i == '?' {
         for j in 0..27 {
            if set[j] == 0 {
               let k = j as u8;
               filled.push((k + b) as char);
               set[j] = 1;
               break;
            }
         }
      } else {
         filled.push(i);
      }
   }

   if count == 26 {
      println!("{}", filled);
   } else {
      println!("-1");
   }
}

#![allow(unused_imports)]
use std::io::*;
use std::cmp::*;
use std::collections::*;

macro_rules! debug(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

struct Scanner {
   buffer : std::collections::VecDeque<String>
}

impl Scanner {

   fn new() -> Scanner {
      Scanner {
         buffer: std::collections::VecDeque::new()
      }
   }

   fn next<T : std::str::FromStr >(&mut self) -> T {

      if self.buffer.len() == 0 {
         let mut input = String::new();
         std::io::stdin().read_line(&mut input).ok();
         for word in input.split_whitespace() {
            self.buffer.push_back(word.to_string())
         }
      }

      let front = self.buffer.pop_front().unwrap();
      front.parse::<T>().ok().unwrap()
   }
}

fn main() {
   let mut s = Scanner::new();
   let input = s.next::<String>();
   let mut set = [0; 27];
   let mut count = 0;
   let mut left = 0;
   let mut right = 26;

   for i in input.chars().take(26) {
      let k = i as usize;
      let b = 'A' as usize;
      if i == '?' {
         count += 1;
         set[26] += 1;
      } else {
         if set[k - b] == 0 {
            count += 1;
         }
         set[k - b] += 1;
      }
   }

   let mut tail = input.chars().nth(left).unwrap() as usize;
   for i in input.chars().skip(26) {
      let k = i as usize;
      let b = 'A' as usize;

      if count == 26 {
         break;
      }

      if tail == '?' as usize {
         set[26] -= 1;
         count -= 1;
      } else {
         set[tail - b] -= 1;
         if set[tail - b] == 0 {
            count -= 1;
         }
      }

      if i == '?' {
         count += 1;
         set[26] += 1;
      } else {
         if set[k - b] == 0 {
            count += 1;
         }
         set[k - b] += 1;
      }

      left += 1;
      right += 1;
      tail = input.chars().nth(left).unwrap() as usize;
   }

   let mut filled : String = String::new();

   if count == 26 {
      for i in input.chars().take(left) {
         if i == '?' {
            filled.push('A');
         } else {
            filled.push(i);
         }
      }

      for i in input.chars().skip(left).take(right) {
         let b = 'A' as u8;
         if i == '?' {
            for j in 0..27 {
               if set[j] == 0 {
                  let k = j as u8;
                  filled.push((k + b) as char);
                  set[j] = 1;
                  break;
               }
            }
         } else {
            filled.push(i);
         }
      }

      for i in input.chars().skip(left + right) {
         if i == '?' {
            filled.push('A');
         } else {
            filled.push(i);
         }
      }

      println!("{}", filled);
   } else {
      println!("-1");
   }
}


On a chessboard with a width of $$$n$$$ and a height of $$$n$$$, rows are numbered from bottom to top from $$$1$$$ to $$$n$$$, columns are numbered from left to right from $$$1$$$ to $$$n$$$. Therefore, for each cell of the chessboard, you can assign the coordinates $$$(r,c)$$$, where $$$r$$$ is the number of the row, and $$$c$$$ is the number of the column.The white king has been sitting in a cell with $$$(1,1)$$$ coordinates for a thousand years, while the black king has been sitting in a cell with $$$(n,n)$$$ coordinates. They would have sat like that further, but suddenly a beautiful coin fell on the cell with coordinates $$$(x,y)$$$...Each of the monarchs wanted to get it, so they decided to arrange a race according to slightly changed chess rules:As in chess, the white king makes the first move, the black king makes the second one, the white king makes the third one, and so on. However, in this problem, kings can stand in adjacent cells or even in the same cell at the same time.The player who reaches the coin first will win, that is to say, the player who reaches the cell with the coordinates $$$(x,y)$$$ first will win.Let's recall that the king is such a chess piece that can move one cell in all directions, that is, if the king is in the $$$(a,b)$$$ cell, then in one move he can move from $$$(a,b)$$$ to the cells $$$(a + 1,b)$$$, $$$(a - 1,b)$$$, $$$(a,b + 1)$$$, $$$(a,b - 1)$$$, $$$(a + 1,b - 1)$$$, $$$(a + 1,b + 1)$$$, $$$(a - 1,b - 1)$$$, or $$$(a - 1,b + 1)$$$. Going outside of the field is prohibited.Determine the color of the king, who will reach the cell with the coordinates $$$(x,y)$$$ first, if the white king moves first.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^{18}$$$) — the length of the side of the chess field. The second line contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x,y \le n$$$) — coordinates of the cell, where the coin fell.

In a single line print the answer "White" (without quotes), if the white king will win, or "Black" (without quotes), if the black king will win. You can print each letter in any case (upper or lower).

NoteAn example of the race from the first sample where both the white king and the black king move optimally: The white king moves from the cell $$$(1,1)$$$ into the cell $$$(2,2)$$$. The black king moves form the cell $$$(4,4)$$$ into the cell $$$(3,3)$$$. The white king moves from the cell $$$(2,2)$$$ into the cell $$$(2,3)$$$. This is cell containing the coin, so the white king wins.  An example of the race from the second sample where both the white king and the black king move optimally: The white king moves from the cell $$$(1,1)$$$ into the cell $$$(2,2)$$$. The black king moves form the cell $$$(5,5)$$$ into the cell $$$(4,4)$$$. The white king moves from the cell $$$(2,2)$$$ into the cell $$$(3,3)$$$. The black king moves from the cell $$$(4,4)$$$ into the cell $$$(3,5)$$$. This is the cell, where the coin fell, so the black king wins.  In the third example, the coin fell in the starting cell of the black king, so the black king immediately wins.

fn dist(x:i64,y:i64,x1:i64,y1:i64) -> i64{
    return std::cmp::max((x-x1).abs(), (y-y1).abs());
}

fn read_line() -> Vec<i64>{
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    return input.trim().split(" ").map(|x|{x.parse::<i64>().unwrap()}).collect();
}

fn main(){
    let WHITE = "White";
    let BLACK = "Black";
    let mut line = read_line();
    let n = line[0];
    line = read_line();
    let (x,y) = (line[0],line[1]);
    if dist(1,1,x,y)<=dist(n,n,x,y){
        println!("{}",WHITE);
    }else{
        println!("{}",BLACK);
    }
}

fn main() {
    let mut input = String::new();
    use std::io::{self, prelude::*};
    io::stdin().read_to_string(&mut input).unwrap();

    let mut it = input.split_whitespace();

    let n: u64 = it.next().unwrap().parse().unwrap();
    let x: u64 = it.next().unwrap().parse().unwrap();
    let y: u64 = it.next().unwrap().parse().unwrap();

    let sum = x + y;
    let answer = if sum > n + 1 {
        Answer::Black
    } else {
        Answer::White
    };

    match answer {
        Answer::Black => {
            println!("Black");
        }
        Answer::White => {
            println!("White");
        }
    };
}

enum Answer {
    Black,
    White,
}

fn dist(x: i64, y: i64) -> i64 {
    return std::cmp::min(x, y) + (x - y).abs();
}

fn read_line() -> Vec<i64> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    return buf.trim().split(" ").map(|x| { x.parse::<i64>().unwrap() }).collect();
}

fn main() {
    let l1 = read_line();
    let l2 = read_line();
    let n: i64 = l1[0];
    let x: i64 = l2[0];
    let y: i64 = l2[1];
    let d1 = dist(x, y);
    let d2 = dist(n - x + 1, n - y + 1);
    if d2 < d1 {
        println!("Black");
    } else {
        println!("White");
    }
}


Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.  A row in the airplane Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.

The first line contains two integers n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 100) — the number of rows and the number of groups of soldiers, respectively. The second line contains k integers a1, a2, a3, ..., ak (1 ≤ ai ≤ 10000), where ai denotes the number of soldiers in the i-th group. It is guaranteed that a1 + a2 + ... + ak ≤ 8·n.

If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes). You can choose the case (lower or upper) for each letter arbitrary.

NoteIn the first sample, Daenerys can place the soldiers like in the figure below:  In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats.In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).

use std::io::stdin;
use std::cmp::*;

fn main() {
    let (n, _) = {
        let mut input = String::new();
        stdin().read_line(&mut input).unwrap();
        let mut it = input.split_whitespace().map(|k| k.parse::<usize>().unwrap());
        (it.next().unwrap(), it.next().unwrap())
    };

    let mut a = String::new();
    stdin().read_line(&mut a).unwrap();
    let a = a.split_whitespace().map(|k| k.parse::<usize>().unwrap());
    let (mut a1, mut a2, mut a4) = a.fold((0, 0, 0), |(a1, a2, a4), ai| (a1 + ai % 2, a2 + ai % 4 - ai % 2, a4 + ai - ai % 4));

    let mut s4 = 4 * n;
    let mut s2 = 4 * n;

    let tmp = min(a2, s2);
    a2 -= tmp;
    s2 -= tmp;
    let tmp = min(a2, s4 / 2);
    a2 -= tmp;
    s4 -= tmp;
    let tmp = min(2 * a2, s4);
    a2 -= tmp / 2;
    s4 -= tmp;
    let tmp = min(a4, s4);
    a4 -= tmp;
    s4 -= tmp;
    let tmp = min(a4, s2);
    a4 -= tmp;
    s2 -= tmp;
    let tmp = min(a1, s4 / 2);
    a1 -= tmp;
    let tmp = min(a1, s2 / 2);
    a1 -= tmp;

    if a1 + a2 + a4 > 0 {
        println!("NO");
    } else {
        println!("YES");
    }
}

use std::io::stdin;

fn main() {
    let (n, _) = {
        let mut input = String::new();
        stdin().read_line(&mut input).unwrap();
        let mut it = input.split_whitespace().map(|k| k.parse::<usize>().unwrap());
        (it.next().unwrap(), it.next().unwrap())
    };

    let mut a = String::new();
    stdin().read_line(&mut a).unwrap();
    let a = a.split_whitespace().map(|k| k.parse::<usize>().unwrap());
    let (a1, a2, a4) = a.fold((0, 0, 0), |(a1, a2, a4), ai| (a1 + ai % 2, a2 + ai % 4 / 2, a4 + ai / 4));

    if a2 <= 3 * n && a2 + a1 <= 4 * n && 4 * a4 + 2 * a2 + 2 * a1 <= 8 * n {
        println!("YES");
    } else {
        println!("NO");
    }
}

use std::io::stdin;

fn main() {
    let (n, _) = {
        let mut input = String::new();
        stdin().read_line(&mut input).unwrap();
        let mut it = input.split_whitespace().map(|k| k.parse::<usize>().unwrap());
        (it.next().unwrap(), it.next().unwrap())
    };

    let mut a = String::new();
    stdin().read_line(&mut a).unwrap();
    let a = a.split_whitespace().map(|k| k.parse::<usize>().unwrap());
    let (al, n_al) = a.fold((0, 0), |(al, n_al), ai| (al + ai % 2, n_al + ai / 2));

    if  al + n_al <= n * 4 {
        println!("YES");
    } else {
        println!("NO");
    }
}


String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".You are given a correct string s.You can perform two different operations on this string:   swap any pair of adjacent characters (for example, "101"  "110");  replace "11" with "1" (for example, "110"  "10"). Let val(s) be such a number that s is its binary representation.Correct string a is less than some other correct string b iff val(a) < val(b).Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s. The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.

Print one string — the minimum correct string that you can obtain from the given one.

NoteIn the first example you can obtain the answer by the following sequence of operations: "1001"  "1010"  "1100"  "100".In the second example you can't obtain smaller answer no matter what operations you use.

// Try Codeforces
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }

    let n = get!();
    if n == 1 {
        let s = get();
        println!("{}", s);
        return;
    }
    let s = get().as_bytes();
    let mut zeros = 0;
    for &c in s {
        if c== b'0' {
            zeros += 1;
        }
    }
    print!("1");
    for _ in 0..zeros {
        print!("0");
    }
    println!();

}

use std::io::*;
use std::str::FromStr;

fn main() {
    let stdin = stdin();
    let mut sc = Scanner::new(stdin.lock());
    let n = sc.next::<u32>();
    let s = sc.next::<String>();
    let zeros = s.chars().filter(|&c| c == '0').count() as u32;
    let result = std::iter::repeat("0")
        .take(zeros as usize)
        .collect::<String>();
    if n == zeros {
        println!("{}", result);
    } else {
        println!("1{}", result);
    }
}

pub struct Scanner<B> {
    reader: B,
    buffer: Vec<String>,
}

impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buffer: Vec::new(),
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: ::std::fmt::Debug,
    {
        if let Some(front) = self.buffer.pop() {
            front.parse::<T>().expect(&front)
        } else {
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Line not read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
            self.next()
        }
    }
}

use std::io::*;
use std::str::FromStr;

fn main() {
    let stdin = stdin();
    let mut sc = Scanner::new(stdin.lock());
    let n = sc.next::<u32>();
    let s = sc.next::<String>();
    let zeros = s.chars().filter(|&c| c == '0').count() as u32;
    let result = std::iter::repeat("0")
        .take(zeros as usize)
        .collect::<String>();
    println!("1{}", result);
}

pub struct Scanner<B> {
    reader: B,
    buffer: Vec<String>,
}

impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buffer: Vec::new(),
        }
    }

    pub fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: ::std::fmt::Debug,
    {
        if let Some(front) = self.buffer.pop() {
            front.parse::<T>().expect(&front)
        } else {
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Line not read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
            self.next()
        }
    }
}


Vasya likes to solve equations. Today he wants to solve $$$(x~\mathrm{div}~k) \cdot (x \bmod k) = n$$$, where $$$\mathrm{div}$$$ and $$$\mathrm{mod}$$$ stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, $$$k$$$ and $$$n$$$ are positive integer parameters, and $$$x$$$ is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible $$$x$$$. Can you help him?

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^6$$$, $$$2 \leq k \leq 1000$$$).

Print a single integer $$$x$$$ — the smallest positive integer solution to $$$(x~\mathrm{div}~k) \cdot (x \bmod k) = n$$$. It is guaranteed that this equation has at least one positive integer solution.

NoteThe result of integer division $$$a~\mathrm{div}~b$$$ is equal to the largest integer $$$c$$$ such that $$$b \cdot c \leq a$$$. $$$a$$$ modulo $$$b$$$ (shortened $$$a \bmod b$$$) is the only integer $$$c$$$ such that $$$0 \leq c < b$$$, and $$$a - c$$$ is divisible by $$$b$$$.In the first sample, $$$11~\mathrm{div}~3 = 3$$$ and $$$11 \bmod 3 = 2$$$. Since $$$3 \cdot 2 = 6$$$, then $$$x = 11$$$ is a solution to $$$(x~\mathrm{div}~3) \cdot (x \bmod 3) = 6$$$. One can see that $$$19$$$ is the only other positive integer solution, hence $$$11$$$ is the smallest one.

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let nk: Vec<u32> = s.trim().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    for m in (1..nk[1]).rev() {
        if nk[0] % m == 0 {
            let x = (nk[0] / m) * nk[1] + m;
            println!("{}", x);
            break;
        }
    }
}

#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::{BTreeMap,BTreeSet};
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! ite {
    ($c:expr, $t:expr, $f:expr) => {{
        if $c { $t } else { $f }
    }};
}

// ref: tanakh <https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8>
// diff: using Parser
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut parser = Parser::from_str($s);
        input_inner!{parser, $($r)*}
    };
    (parser = $parser:ident, $($r:tt)*) => {
        input_inner!{$parser, $($r)*}
    };
    (new_stdin_parser = $parser:ident, $($r:tt)*) => {
        let stdin = std::io::stdin();
        let reader = std::io::BufReader::new(stdin.lock());
        let mut $parser = Parser::new(reader);
        input_inner!{$parser, $($r)*}
    };
    ($($r:tt)*) => {
        input!{new_stdin_parser = parser, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($parser:ident) => {};
    ($parser:ident, ) => {};
    ($parser:ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($parser, $t);
        input_inner!{$parser $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($parser:ident, ( $($t:tt),* )) => {
        ( $(read_value!($parser, $t)),* )
    };
    ($parser:ident, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($parser, $t)).collect::<Vec<_>>()
    };
    ($parser:ident, chars) => {
        read_value!($parser, String).chars().collect::<Vec<char>>()
    };
    ($parser:ident, usize1) => {
        read_value!($parser, usize) - 1
    };
    ($parser:ident, $t:ty) => {
        $parser.next::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i64,
        k: i64,
    }
    let mut res = None;
    for right in 1..k {
        if n % right == 0 {
            let left = n / right;
            let x = left * k + right;
            if res.is_none() || res.unwrap() > x {
                res = Some(x);
            }
        }
    }
    println!("{}", res.unwrap());
}

use std::io::BufRead;
use std::io;
use std::str;

// ref: tatsuya6502 <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e>
// ref: wariuni <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e#comment-7040a5ae96305e884eb9>
// diff: using std::io::BufRead::fill_buf()
pub struct Parser<R> {
    reader: R,
    buf: Vec<u8>,
    pos: usize,
}

impl Parser<io::Empty> {
    pub fn from_str(s: &str) -> Parser<io::Empty> {
        Parser {
            reader: io::empty(),
            buf: s.as_bytes().to_vec(),
            pos: 0,
        }
    }
}

impl<R:BufRead> Parser<R> {
    pub fn new(reader: R) -> Parser<R> {
        Parser {
            reader: reader,
            buf: vec![],
            pos: 0,
        }
    }
    pub fn update_buf(&mut self) {
        self.buf.clear();
        self.pos = 0;
        loop {
            let (len,complete) = {
                let buf2 = self.reader.fill_buf().unwrap();
                self.buf.extend_from_slice(buf2);
                let len = buf2.len();
                (len, buf2[len-1] <= 0x20)
            };
            self.reader.consume(len);
            if complete {
                break;
            }
        }
    }
    pub fn next<T:str::FromStr>(&mut self) -> Result<T, T::Err> {
        loop {
            let mut begin = self.pos;
            while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                begin += 1;
            }
            let mut end = begin;
            while end < self.buf.len() && (self.buf[end] > 0x20) {
                end += 1;
            }
            if begin != self.buf.len() {
                self.pos = end;
                return str::from_utf8(&self.buf[begin..end]).unwrap().parse::<T>();
            }
            else {
                self.update_buf();
            }
        }
    }
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!();
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!();
}

use std::io;

macro_rules! readln {
    () => {{
        use std::io;
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

fn main() {
    let (result, divider) = readln!(i32, i32);

    let mut min = std::i32::MAX;
    for right in 1..divider {
        if result % right == 0 {
            let x = right + divider * result / right;
            if x < min {
                min = x;
            }
        }
    }

    println!("{}", min);
}

use std::io;

fn main() {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).expect("failed to read input");
    let mut buffer_iter = buffer.split_whitespace().map(|n| n.parse::<u32>().unwrap());
    let n = buffer_iter.next().unwrap();
    let k = buffer_iter.next().unwrap();

    let md = (1..k).rev().find(|x| n % x == 0).unwrap();
    println!("{}", (n / md) * k + md);
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let nk: Vec<u32> = s.trim().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    let m = nk[0] * nk[1] + 1;
    for x in 1..m {
        let y = x - x % nk[1];
        if (y / nk[1]) * (x % nk[1]) == nk[0] {
            println!("{}", x);
            break;
        }
    }
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let nk: Vec<u32> = s.trim().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    for x in 1..10000001 {
        if (x/nk[1])*(x%nk[1]) == nk[0] {
            println!("{}", x);
            break;
        }
    }
}


There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number n.The presenter has m chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number i gets i chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given n and m how many chips the presenter will get in the end.

The first line contains two integers n and m (1 ≤ n ≤ 50, 1 ≤ m ≤ 104) — the number of walruses and the number of chips correspondingly.

Print the number of chips the presenter ended up with.

NoteIn the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.

struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn _main() {
    let mut scan = Scan::new();
    let n: usize = scan.next();
    let mut m: usize = scan.next();
    let circle = n * (n + 1) / 2;
    m %= circle;
    for i in 1..n {
        if i <= m {
            m -= i;
        } else {
            break;
        }
    }
    println!("{}", m);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you to find two points A = (x1, y1) and C = (x2, y2), such that the following conditions hold:  the coordinates of points: x1, x2, y1, y2 are integers. Besides, the following inequation holds: x1 < x2;  the triangle formed by point A, B and C is rectangular and isosceles ( is right);  all points of the favorite rectangle are located inside or on the border of triangle ABC;  the area of triangle ABC is as small as possible. Help the bear, find the required points. It is not so hard to proof that these points are unique.

The first line contains two integers x, y ( - 109 ≤ x, y ≤ 109, x ≠ 0, y ≠ 0).

Print in the single line four integers x1, y1, x2, y2 — the coordinates of the required points.

use std::io::stdin;
use std::isize;
fn main() {
    let (x,y) = parse_input();
    let abs_x = x.abs();
    let abs_y = y.abs();
    let a =  abs_x+abs_y;
    if abs_x == x && abs_y == y{
        print(0,a ,a,0)
    }else if abs_x != x && abs_y !=y{
        print(-a,0,0,-a)
    }else if abs_x !=x {
        print(-a,0,0,a)
    }else{
        print(0,-a,a,0)
    }
}
fn parse_input()->(isize,isize){
    let mut input = String::new();
    stdin().read_line(&mut input).unwrap();
    let v:Vec<isize> = input.trim().split_whitespace().map(|e| e.parse().unwrap()).collect();
    (v[0],v[1])
}
fn print(a:isize,b:isize,c:isize,d:isize){
    println!("{} {} {} {}",a,b,c,d)
}

struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn _main() {
    let mut scan = Scan::new();
    let x: isize = scan.next();
    let y: isize = scan.next();
    let val = x.abs() + y.abs();
    let first = (0, val * y.signum());
    let second = (val * x.signum(), 0);
    let min = first.min(second);
    let max = first.max(second);
    println!("{} {} {} {}", min.0, min.1, max.0, max.1);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}

use std::io::stdin;
use std::isize;
fn main() {
    let (x,y) = parse_input();
    let abs_x = x.abs();
    let abs_y = y.abs();
    let a =  abs_x+abs_y;
    if abs_x == x && abs_y == y{
        print(0,a ,a,0)
    }else if abs_x != x && abs_y !=y{
        print(-a,0,0,a)
    }else if abs_x !=x {
        print(-a,0,0,a)
    }else{
        print(0,-a,a,0)
    }
}
fn parse_input()->(isize,isize){
    let mut input = String::new();
    stdin().read_line(&mut input).unwrap();
    let v:Vec<isize> = input.trim().split_whitespace().map(|e| e.parse().unwrap()).collect();
    (v[0],v[1])
}
fn print(a:isize,b:isize,c:isize,d:isize){
    println!("{} {} {} {}",a,b,c,d)
}

use std::io::stdin;
fn main() {
    let (x,y) = parse_input();
    let abs_x = x.abs();
    let abs_y = y.abs();
    let a =  abs_x+abs_y;
    if abs_x == x && abs_y == y{
        println!("{} {} {} {}",0,a ,a,0)
    }else if abs_x != x && abs_y !=y{
        println!("{} {} {} {}",-a,0,0,a)
    }else if abs_x !=x {
        println!("{} {} {} {}",-a,0,0,a)
    }else{
        println!("{} {} {} {}",0,-a,a,0)
    }
}
fn parse_input()->(isize,isize){
    let mut input = String::new();
    stdin().read_line(&mut input).unwrap();
    let v:Vec<isize> = input.trim().split_whitespace().map(|e| e.parse().unwrap()).collect();
    (v[0],v[1])
}


Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.

The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.  The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.  It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.

If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.

//! http://codeforces.com/contest/382/problem/A

#[macro_export]
macro_rules! scanln {
  ($($var:ident : $ty:path),+) => {
    $(let $var: $ty;)+
    {
      use std::io;
      let mut __buf = String::new();
      io::stdin().read_line(&mut __buf).unwrap();
      let mut eles = __buf.split_whitespace();
      $($var = Scan::scan(&mut eles);)+
    }
  }
}

pub trait Scan {
  fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str>;
}

macro_rules! impl_scan_single {
  ($ty:ty) => {
    impl Scan for $ty {
      fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
        let next = eles.next().unwrap();
        match next.parse() {
          Ok(res) => res,
          Err(_) => panic!()
        }
      }
    }
  }
}

impl_scan_single!(u8);
impl_scan_single!(u16);
impl_scan_single!(u32);
impl_scan_single!(u64);
impl_scan_single!(usize);
impl_scan_single!(i8);
impl_scan_single!(i16);
impl_scan_single!(i32);
impl_scan_single!(i64);
impl_scan_single!(f32);
impl_scan_single!(f64);
impl_scan_single!(isize);
impl_scan_single!(String);

const __IMPL_SCAN_FOR_VEC: () = {
  use std::str::FromStr;
  impl<T> Scan for Vec<T> where T: FromStr {
    fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
      eles.map(|str| match str.parse() {
        Ok(res) => res,
        Err(_) => panic!()
      }).collect()
    }
  }
};

// -----------------------------------------------------------------------------

fn main() {
  scanln!(scale: String);
  scanln!(weights: String);
  let mut pans = scale.split('|');
  let pan1 = pans.next().unwrap();
  let pan2 = pans.next().unwrap();
  let diff = std::cmp::max(pan1.len(), pan2.len()) - std::cmp::min(pan1.len(), pan2.len());
  let common = weights.len() as i32 - diff as i32;
  if common >= 0 && common % 2 == 0 {
    let (less, more) = weights.as_bytes().split_at((weights.len() - diff) / 2);
    let (front, back) = if pan1.len() > pan2.len() { (less, more) } else { (more, less) };
    for c in front.iter().map(|&b| b as char).chain(pan1.chars()) {
      print!("{}", c);
    }
    print!("|");
    for c in back.iter().map(|&b| b as char).chain(pan2.chars()) {
      print!("{}", c);
    }
    println!("");
  } else {
    println!("Impossible");
  }
}

use std::io;

fn get_line() -> String {
	let mut input = String::new();

	io::stdin().read_line(&mut input)
		.expect("");

	String::from(input.trim())
}

fn main() {
	let s = get_line();
	let t = get_line();

	let mut l = String::new();
	let mut r = String::new();

	let mut k = 0usize;
	for (i, c) in s.chars().enumerate() {
		if c == '|' {
			k = i;
			break;
		}
	}

	for (i, c) in s.chars().enumerate() {
		if i == k {
			break;
		}
		l.push(c);
	}

	for (i, c) in s.chars().enumerate() {
		if i <= k {
			continue;
		}
		r.push(c);
	}

	for c in t.chars() {
		if l.len() < r.len() {
			l.push(c);
		} else {
			r.push(c);
		}
	}

	if l.len() != r.len() {
		println!("Impossible");
	} else {
		println!("{}|{}", l, r);
	}
}

use std::io;

fn get_line() -> String {
	let mut input = String::new();

	io::stdin().read_line(&mut input)
		.expect("");

	String::from(input.trim())
}

fn main() {
	let s = get_line();
	let t = get_line();

	let mut k = 0usize;
	for (i, c) in s.chars().enumerate() {
		if c == '|' {
			k = i;
			break;
		}
	}

	let mut l = String::new();
	for (i, c) in s.chars().enumerate() {
		if i == k {
			break;
		}

		l.push(c);
	}

	let mut r = String::new();
	for (j, d) in s.chars().enumerate() {
		if j <= k {
			continue;
		}

		r.push(d);
	}

	if (t.len() + l.len() + r.len())%2 != 0 {
		println!("Impossible");
		return;
	}

	if l.len() == 0 {
		l.push_str(&t);
	} else if r.len() == 0 {
		r.push_str(&t);
	} else {
		let mut f = if l.len() < r.len() { true } else { false };
    	for c in t.chars() {
			if f {
				l.push(c);
				f = false;
			} else {
				r.push(c);
				f = true;
			}
		}
	}
	println!("{}|{}", l, r);
}

use std::io;

fn get_line() -> String {
	let mut input = String::new();

	io::stdin().read_line(&mut input)
		.expect("");

	String::from(input.trim())
}

fn main() {
	let s = get_line();
	let t = get_line();

	let mut k = 0usize;
	for (i, c) in s.chars().enumerate() {
		if c == '|' {
			k = i;
			break;
		}
	}

	let mut l = String::new();
	for (i, c) in s.chars().enumerate() {
		if i == k {
			break;
		}

		l.push(c);
	}

	let mut r = String::new();
	for (j, d) in s.chars().enumerate() {
		if j <= k {
			continue;
		}

		r.push(d);
	}

	let d = if l.len() < r.len() { r.len()-r.len() } else { l.len()-r.len() };

	if (t.len() + l.len() + r.len())%2 != 0 || d > t.len() {
		println!("Impossible");
		return;
	}

	if l.len() == 0 {
		l.push_str(&t);
	} else if r.len() == 0 {
		r.push_str(&t);
	} else {
		let mut f = if l.len() < r.len() { true } else { false };
    	for c in t.chars() {
			if f {
				l.push(c);
				f = false;
			} else {
				r.push(c);
				f = true;
			}
		}
	}
	println!("{}|{}", l, r);
}

use std::io;

fn get_line() -> String {
	let mut input = String::new();

	io::stdin().read_line(&mut input)
		.expect("");

	String::from(input.trim())
}

fn main() {
	let s = get_line();
	let t = get_line();

	let mut k = 0usize;
	for (i, c) in s.chars().enumerate() {
		if c == '|' {
			k = i;
			break;
		}
	}

	let mut l = String::new();
	for (i, c) in s.chars().enumerate() {
		if i == k {
			break;
		}

		l.push(c);
	}

	let mut r = String::new();
	for (j, d) in s.chars().enumerate() {
		if j <= k {
			continue;
		}

		r.push(d);
	}

	let d = if l.len() < r.len() { r.len()-s.len() } else { l.len()-r.len() };

	if (t.len() + l.len() + r.len())%2 != 0 || d > t.len() {
		println!("Impossible");
		return;
	}

	if l.len() == 0 {
		l.push_str(&t);
	} else if r.len() == 0 {
		r.push_str(&t);
	} else {
		let mut f = if l.len() < r.len() { true } else { false };
    	for c in t.chars() {
			if f {
				l.push(c);
				f = false;
			} else {
				r.push(c);
				f = true;
			}
		}
	}
	println!("{}|{}", l, r);
}

use std::io;

fn get_line() -> String {
	let mut input = String::new();

	io::stdin().read_line(&mut input)
		.expect("");

	String::from(input.trim())
}

fn main() {
	let s = get_line();
	let t = get_line();

	let mut k = 0usize;
	for (i, c) in s.chars().enumerate() {
		if c == '|' {
			k = i;
			break;
		}
	}

	let mut l = String::new();
	for (i, c) in s.chars().enumerate() {
		if i == k {
			break;
		}

		l.push(c);
	}

	let mut r = String::new();
	for (j, d) in s.chars().enumerate() {
		if j <= k {
			continue;
		}

		r.push(d);
	}

	let d = if l.len() < r.len() { r.len()-l.len() } else { l.len()-r.len() };

	if d == 0 {
	 	if t.len()%2 == 0 {
	 		let mut f = true;
	 		for c in t.chars() {
	 			if f {
	 				l.push(c);
	 				f = false;
				} else {
					r.push(c);
					f = true;
				}
			}
			println!("{}|{}", l, r);
	 	} else {
	 		println!("Impossible");
		}
	} else {
		if d != t.len() {
			println!("Impossible");
		} else {
			if l.len() < r.len() {
				for c in t.chars() {
					l.push(c);
				}
			} else {
				for c in t.chars() {
					r.push(c);
				}
			}

			println!("{}|{}", l, r);
		}
	}
}


Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every $$$a$$$ and $$$b$$$ such that $$$1 \leq a \leq b \leq 6$$$, there is exactly one domino with $$$a$$$ dots on one half and $$$b$$$ dots on the other half. The set contains exactly $$$21$$$ dominoes. Here is an exact illustration of his set:  Also, Anadi has an undirected graph without self-loops and multiple edges. He wants to choose some dominoes and place them on the edges of this graph. He can use at most one domino of each type. Each edge can fit at most one domino. It's not necessary to place a domino on each edge of the graph.When placing a domino on an edge, he also chooses its direction. In other words, one half of any placed domino must be directed toward one of the endpoints of the edge and the other half must be directed toward the other endpoint. There's a catch: if there are multiple halves of dominoes directed toward the same vertex, each of these halves must contain the same number of dots.How many dominoes at most can Anadi place on the edges of his graph?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 7$$$, $$$0 \leq m \leq \frac{n\cdot(n-1)}{2}$$$) — the number of vertices and the number of edges in the graph. The next $$$m$$$ lines contain two integers each. Integers in the $$$i$$$-th line are $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a, b \leq n$$$, $$$a \neq b$$$) and denote that there is an edge which connects vertices $$$a_i$$$ and $$$b_i$$$. The graph might be disconnected. It's however guaranteed that the graph doesn't contain any self-loops, and that there is at most one edge between any pair of vertices.

Output one integer which denotes the maximum number of dominoes which Anadi can place on the edges of the graph.

NoteHere is an illustration of Anadi's graph from the first sample test:  And here is one of the ways to place a domino on each of its edges:  Note that each vertex is faced by the halves of dominoes with the same number of dots. For instance, all halves directed toward vertex $$$1$$$ have three dots.

use std::io::Write;

pub struct Scanner {
  buffer: Vec<String>
}

impl Scanner {
  pub fn new() -> Scanner {
    Scanner { buffer: Vec::new() }
  }

  pub fn next<T: std::str::FromStr>(&mut self) -> T {
    loop {
      if let Some(token) = self.buffer.pop() {
          return token.parse().ok().expect("Failed parse");
      }
      let mut input = String::new();
      std::io::stdin().read_line(&mut input).expect("Failed read");
      self.buffer = input.split_whitespace().rev().map(String::from).collect();
    }
  }
}

fn calculate(n: usize, g: &Vec<Vec<usize>>, p: &Vec<usize>) -> i32 {
  let mut found: [[bool; 6]; 6] = [[false; 6]; 6];
  let mut ans: i32 = 0;
  for u in 0..n {
    for &v in g[u].iter() {
      let u = p[u];
      let v = p[v];
      if !found[u][v] {
        found[u][v] = true;
        found[v][u] = true;
        ans += 1;
      }
    }
  }
  return ans;
}

fn gen(d: usize, n: usize, g: &Vec<Vec<usize>>, p: &mut Vec<usize>) -> i32 {
  if d == n {
    return calculate(n, g, p);
  }
  let mut ans: i32 = 0;
  for x in 0..6 {
    p[d] = x;
    ans = std::cmp::max(ans, gen(d + 1, n, g, p));
  }
  return ans;
}

fn main() {
  let stdout = std::io::stdout();
  let mut out = std::io::BufWriter::new(stdout.lock());
  let mut scan = Scanner::new();

  let n: usize = scan.next();
  let m: usize = scan.next();
  let mut g: Vec<Vec<usize>> = vec![vec![]; n];
  for _ in 0..m {
    let u: usize = scan.next();
    let v: usize = scan.next();
    g[u - 1].push(v - 1);
    g[v - 1].push(u - 1);
  }
  let mut p: Vec<usize> = vec![0; n];
  let ans = gen(0, n, &g, &mut p);
  writeln!(out, "{}", ans).unwrap();
}