Score : <var>200</var> points

Problem Statement

Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string <var>s</var> (that is, a consecutive part of <var>s</var>).

Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of <var>s</var> that starts with A and ends with Z.

Constraints

<var>1 ≦ |s| ≦ 200{,}000</var>

<var>s</var> consists of uppercase English letters.

There exists a substring of <var>s</var> that starts with A and ends with Z.

Input

The input is given from Standard Input in the following format:

<var>s</var>

Output

Print the answer.

Sample Input 1

QWERTYASDFZXCV

Sample Output 1

5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Sample Input 2

ZABCZ

Sample Output 2

4

Sample Input 3

HASFJGHOGAKZZFEGA

Sample Output 3

12

int solution(void) {
  char s[300000];
  int strat_a = 0;
  int strat_z = 0;
  bool flag = true;

  fgets(s, sizeof(s), stdin);
  for (int i = 0; s[i] != '\n'; i++) {
    if (s[i] == 'A' && flag == true) {
      strat_a = i;
      flag = false;
    }
    if (s[i] == 'Z' && flag == false) {
      strat_z = i;
    }
  }
  printf("%d\n", strat_z - strat_a + 1);
  return 0;
}

fn solution() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();

    let mut f = false;
    let mut now = 0;
    let mut res = 0;
    for c in s.trim().chars() {
        if !f && c == 'A' {
            f = true;
        }

        if f {
            now += 1;
        }

        if f && c == 'Z' {
            res = now;
        }
    }

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


Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s: Vec<char> = s.chars().collect();
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).unwrap();
    let n: usize = t.trim().parse().unwrap();
    let mut count = vec![0];
    let mut c = s[0];
    let mut sum = 0;
    for i in 1..s.len() {
        sum += if c == s[i] { 1 } else { 0 };
        count.push(sum);
        c = s[i];
    }

    for _i in 0..n {
        t = String::new();
        std::io::stdin().read_line(&mut t).unwrap();
        let mut ints = t.split_whitespace().map(|x| x.parse::<usize>().unwrap());
        let a = ints.next().unwrap();
        let b = ints.next().unwrap();
        println!("{}", count[b - 1] - count[a - 1]);
    }
}


You are given two integers $$$a$$$ and $$$b$$$. Print $$$a+b$$$.

int solution() {
  int n;
  scanf("%d", &n);
  int numbers[n][2];
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &numbers[i][0], &numbers[i][1]);
  }
  for (int i = 0; i < n; i++) {
    printf("%d\n", numbers[i][0] + numbers[i][1]);
  }
  return 0;
}

fn solution() {
    let mut cases = String::new();
    io::stdin()
        .read_line(&mut cases)
        .expect("Unable to read number of cases");
    let cases: u32 = cases
        .trim()
        .parse()
        .expect("Unable to parse number of cases");

    for _ in 0..cases {
        let mut val = String::new();
        io::stdin()
            .read_line(&mut val)
            .expect("Unable to read values");

        let tuple: Vec<i32> = val
            .split_whitespace()
            .map(|x| x.parse().expect("Unable to parse values"))
            .collect();

        assert_eq!(tuple.len(), 2, "Did not get exactly 2 numbers");

        println!("{}", tuple[0] + tuple[1]);
    }
}


Score : <var>300</var> points

Problem Statement

Takahashi is a teacher responsible for a class of <var>N</var> students.

The students are given distinct student numbers from <var>1</var> to <var>N</var>.

Today, all the students entered the classroom at different times.

According to Takahashi's record, there were <var>A_i</var> students in the classroom when student number <var>i</var> entered the classroom (including student number <var>i</var>).

From these records, reconstruct the order in which the students entered the classroom.

Constraints

<var> 1 \le N \le 10^5 </var>

<var> 1 \le A_i \le N </var>

<var> A_i \neq A_j </var> <var>(i \neq j)</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A_1</var> <var>A_2</var> <var>\ldots</var> <var>A_N</var>

Output

Print the student numbers of the students in the order the students entered the classroom.

Sample Input 1

3
2 3 1

Sample Output 1

3 1 2

First, student number <var>3</var> entered the classroom.

Then, student number <var>1</var> entered the classroom.

Finally, student number <var>2</var> entered the classroom.

Sample Input 2

5
1 2 3 4 5

Sample Output 2

1 2 3 4 5

Sample Input 3

8
8 2 7 3 4 5 6 1

Sample Output 3

8 2 4 5 6 7 3 1

int solution() {
  int N;
  int i;
  scanf("%d", &N);
  int(*A) = (int(*))malloc(100010 * sizeof(int));
  int(*B) = (int(*))malloc(100010 * sizeof(int));

  for (i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    B[A[i]] = i;
  }
  for (i = 1; i <= N; i++) {
    printf("%d ", B[i]);
  }
  free(A);
  free(B);
  return 0;
}

fn solution() {
    let _n: i64 = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let mut a: Vec<(i64, i64)> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let ret = line.split_whitespace().map(|a| a.parse().unwrap());
        ret.zip(0i64..).collect()
    };
    a.sort();
    println!(
        "{}",
        a.iter()
            .map(|&(_a, i)| (i + 1).to_string())
            .collect::<Vec<String>>()
            .join(" ")
    )
}


One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.

int solution() {
  long n;
  long t;
  int m = 0;
  int c = 0;
  scanf("%ld", &n);
  int a[n];
  int b[n];
  long long h;
  long long s = 0;
  for (long i = 0; i < n; i++) {
    scanf("%d %d", &a[i], &b[i]);
    s = s + a[i];
    if (b[i] > m) {
      m = b[i];
      t = i;
    }
  }
  for (long i = 0; i < n; i++) {
    if (i != t && b[i] > c) {
      c = b[i];
    }
  }
  for (long i = 0; i < n; i++) {
    if (i == t) {
      h = (s - a[i]) * c;
      printf("%lld ", h);
    } else {
      h = (s - a[i]) * m;
      printf("%lld ", h);
    }
  }
  return 0;
}

fn solution() {
    let mut n = String::new();

    io::stdin().read_line(&mut n).expect("Failed to read line!");

    let n = n.trim().parse::<u32>().expect("Type a number, please!");

    let mut w: [u8; 200000] = [0; 200000];

    let mut h: [u16; 2] = [0; 2];

    let mut full_w: u32 = 0;

    let mut biggest_height_id: u32 = 0;

    for i in 0..n {
        let mut line = String::new();
        io::stdin()
            .read_line(&mut line)
            .expect("Failed to read line!");

        let mut iter = line.split_whitespace();

        w[i as usize] = iter
            .next()
            .unwrap()
            .trim()
            .parse::<u8>()
            .expect("Type a number, please!");

        full_w += w[i as usize] as u32;

        let height = iter
            .next()
            .unwrap()
            .trim()
            .parse::<u16>()
            .expect("Type a number, please!");

        if height > h[0] {
            if h[1] < h[0] {
                h[1] = h[0]
            }
            h[0] = height;
            biggest_height_id = i;
        } else if height > h[1] {
            h[1] = height;
        }
    }

    for i in 0..n {
        let height = if biggest_height_id == i { h[1] } else { h[0] };
        print!("{} ", (full_w - w[i as usize] as u32) * height as u32);
    }
}


Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?

int solution() {
  int calories[4];
  char str[100001];
  int i = 0;
  int count = 0;
  scanf("%d %d %d %d", &calories[0], &calories[1], &calories[2], &calories[3]);
  scanf("%s", str);
  if (calories[0] == '0' && calories[1] == '0' && calories[2] == '0' &&
      calories[3] == '0') {
    printf("0");
    return 0;
  }
  while (str[i] != '\0') {
    count += calories[str[i] - 49];
    i++;
  }
  printf("%d", count);
  return 0;
}

fn solution() {
    let mut input: String = String::new();
    std::io::stdin()
        .read_line(&mut input)
        .expect("INPUT::read line failed");
    let mut input = input.trim().split(' ');

    let one: i32 = input.next().unwrap().parse::<i32>().unwrap();
    let two: i32 = input.next().unwrap().parse::<i32>().unwrap();
    let three: i32 = input.next().unwrap().parse::<i32>().unwrap();
    let four: i32 = input.next().unwrap().parse::<i32>().unwrap();

    let mut input: String = String::new();
    std::io::stdin()
        .read_line(&mut input)
        .expect("INPUT::read line failed");

    let mut vec = vec![];
    vec = input.trim().chars().collect::<Vec<char>>();

    let _bound: usize = vec.len();
    let mut sum: i32 = i32::default();
    for i in &vec {
        match i {
            '1' => sum += one,
            '2' => sum += two,
            '3' => sum += three,
            '4' => sum += four,
            _ => println!("ERROR::number not exist"),
        }
    }

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


The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream.

int solution() {
  int h_rank = 0;
  int i = 0;
  int now = 0;
  int after = 0;
  int left = 0;
  scanf("%d", &h_rank);

  int time_arr[h_rank - 1];

  for (i = 0; i < h_rank - 1; i++) {
    scanf("%d", &time_arr[i]);
  }

  scanf("%d %d", &now, &after);

  for (i = now - 1; i < after - 1; i++) {
    left += time_arr[i];
  }

  printf("%d", left);
  return 0;
}

fn solution() {
    let mut buf = String::new();
    let mut n: usize = 0;
    let reader = io::stdin();
    reader.read_line(&mut buf);
    n = buf.trim().parse().expect(" ");
    let mut v = vec![0; n - 1];

    let mut buf2 = String::new();
    reader.read_line(&mut buf2);
    let it = buf2.trim().split(" ");
    let mut ct = 0;
    for sub in it {
        v[ct] = sub.trim().parse().expect(" ");
        ct += 1;
    }

    let mut buf3 = String::new();
    reader.read_line(&mut buf3);
    let wv = buf3.trim().split(" ").collect::<Vec<&str>>();
    let a: i32 = wv[0].parse().expect(" ");
    let b: i32 = wv[1].parse().expect(" ");
    let mut ans: u32 = 0;
    for i in (a - 1)..=(b - 2) {
        ans += v[i as usize];
    }
    println!("{}", ans);
}


You are given a permutation $$$a$$$ of size $$$n$$$ and you should perform $$$n$$$ operations on it. In the $$$i$$$-th operation, you can choose a non-empty suffix of $$$a$$$ and increase all of its elements by $$$i$$$. How can we perform the operations to minimize the number of inversions in the final array?Note that you can perform operations on the same suffix any number of times you want.A permutation of size $$$n$$$ is an array of size $$$n$$$ such that each integer from $$$1$$$ to $$$n$$$ occurs exactly once in this array. A suffix is several consecutive elements of an array that include the last element of the array. An inversion in an array $$$a$$$ is a pair of indices $$$(i, j)$$$ such that $$$i > j$$$ and $$$a_{i} < a_{j}$$$.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int a;
    int n;
    scanf("%d", &n);
    int perm[n];
    for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      perm[n - a] = i + 1;
    }
    for (int i = 0; i < n; i++) {
      printf("%d ", perm[i]);
    }
    printf("\n");
  }
}

fn solution() {
    let stdin = std::io::stdin();
    let stdin_lock = stdin.lock();

    let mut line_iter = stdin_lock.lines();
    let t = line_iter
        .next()
        .unwrap()
        .unwrap()
        .as_str()
        .parse::<usize>()
        .unwrap();
    for _ in 0..t {
        let n = line_iter.next().unwrap().unwrap().parse::<usize>().unwrap();
        let a_line = line_iter.next().unwrap().unwrap();
        let a_iter = a_line
            .split(' ')
            .map(|a_str| a_str.parse::<usize>().unwrap());

        let mut ops = vec![0_usize; n];

        for (index, a_i) in a_iter.enumerate() {
            let i = n - a_i;
            ops[i] = index + 1;
        }

        print!("{}", ops[0]);
        for index in ops[1..].iter() {
            print!(" {}", index);
        }
        println!();
    }
}


Petya organized a strange birthday party. He invited $$$n$$$ friends and assigned an integer $$$k_i$$$ to the $$$i$$$-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are $$$m$$$ unique presents available, the $$$j$$$-th present costs $$$c_j$$$ dollars ($$$1 \le c_1 \le c_2 \le \ldots \le c_m$$$). It's not allowed to buy a single present more than once.For the $$$i$$$-th friend Petya can either buy them a present $$$j \le k_i$$$, which costs $$$c_j$$$ dollars, or just give them $$$c_{k_i}$$$ dollars directly.Help Petya determine the minimum total cost of hosting his party.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    int m;
    long long sum = 0;
    scanf("%d%d", &n, &m);
    long long k[n];
    long long c[m + 1];
    long long f[m + 1];
    for (long long i = 0; i <= m; i++) {
      f[i] = 0;
    }
    for (long long i = 0; i < n; i++) {
      scanf("%lld", &k[i]);
      f[k[i]]++;
    }
    for (long long i = 1; i <= m; i++) {
      scanf("%lld", &c[i]);
    }
    for (long long k = n, i = 1; i <= m && k > 0; i++) {
      if (k % (f[i] + 1) != 0 && k / (f[i] + 1) == 0) {
        sum = sum + (k)*c[i];
      } else {
        sum = sum + (f[i] + 1) * c[i];
      }
      k = k - (f[i] + 1);
    }
    printf("%lld\n", sum);
  }
}

fn solution() {
    use std::io::{self, Write};

    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut sc = cf_scanner::Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    let t: usize = sc.next();
    for _ in 0..t {
        let n: usize = sc.next();
        let m: usize = sc.next();
        let idx: Vec<usize> = (0..n).map(|_| sc.next()).collect();
        let look_up: Vec<usize> = (0..m).map(|_| sc.next()).collect();
        let mut vals: Vec<usize> = vec![];
        idx.iter().for_each(|&x| vals.push(look_up[x - 1]));
        look_up.iter().for_each(|&x| vals.push(x));
        vals.sort();
        writeln!(out, "{}", vals[0..n].iter().fold(0, |x, y| x + *y as i64)).unwrap();
    }
}


Score : <var>100</var> points

Problem Statement

We have weather records at AtCoder Town for some consecutive three days. A string of length <var>3</var>, <var>S</var>, represents the records - if the <var>i</var>-th character is S, it means it was sunny on the <var>i</var>-th day; if that character is R, it means it was rainy on that day.

Find the maximum number of consecutive rainy days in this period.

Constraints

<var>|S| = 3</var>

Each character of <var>S</var> is S or R.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

Print the maximum number of consecutive rainy days in the period.

Sample Input 1

RRS

Sample Output 1

2

We had rain on the <var>1</var>-st and <var>2</var>-nd days in the period. Here, the maximum number of consecutive rainy days is <var>2</var>, so we should print <var>2</var>.

Sample Input 2

SSS

Sample Output 2

0

It was sunny throughout the period. We had no rainy days, so we should print <var>0</var>.

Sample Input 3

RSR

Sample Output 3

1

We had rain on the <var>1</var>-st and <var>3</var>-rd days - two "streaks" of one rainy day, so we should print <var>1</var>.

fn solution() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let s = buf.trim();
    if s == "RRR" {
        println!("3");
    } else if s == "RRS" || s == "SRR" {
        println!("2");
    } else if s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR" {
        println!("1");
    } else {
        println!("0");
    }
}


Doremy is asked to test $$$n$$$ contests. Contest $$$i$$$ can only be tested on day $$$i$$$. The difficulty of contest $$$i$$$ is $$$a_i$$$. Initially, Doremy's IQ is $$$q$$$. On day $$$i$$$ Doremy will choose whether to test contest $$$i$$$ or not. She can only test a contest if her current IQ is strictly greater than $$$0$$$.If Doremy chooses to test contest $$$i$$$ on day $$$i$$$, the following happens:   if $$$a_i>q$$$, Doremy will feel she is not wise enough, so $$$q$$$ decreases by $$$1$$$;  otherwise, nothing changes.  If she chooses not to test a contest, nothing changes.Doremy wants to test as many contests as possible. Please give Doremy a solution.

int solution() {
  int k;
  scanf("%d", &k);
  while (k--) {
    int n;
    int m;

    scanf("%d %d", &n, &m);
    int array[n];
    int curr = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &array[i]);
    }

    for (long long int i = n - 1; i >= 0; i--) {
      if (array[i] <= curr) {
        array[i] = 1;
      } else if (curr < array[i] && curr < m) {
        array[i] = 1;
        curr++;
      } else if (curr >= m) {
        array[i] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      printf("%d", array[i]);
    }
    printf("\n");
  }

  return 0;
}

fn solution() {
    let stdout = std::io::stdout();
    let mut writer = std::io::BufWriter::new(stdout.lock());

    input! {
        name = reader,
        tests: usize
    }
    for _ in 0..tests {
        input! {
            use reader,
            n: usize,
            q: u32,
            a: [u32; n]
        }
        let mut bytes = vec![b'0'; n];
        let mut nowq = 0;
        for (i, &ai) in a.iter().enumerate().rev() {
            if nowq >= ai {
                bytes[i] = b'1';
            } else if nowq < q {
                bytes[i] = b'1';
                nowq += 1;
            }
        }
        let bytes = String::from_utf8(bytes).unwrap();
        println!("{}", bytes);
    }
}


Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.Each customer is characterized by three values: $$$t_i$$$ — the time (in minutes) when the $$$i$$$-th customer visits the restaurant, $$$l_i$$$ — the lower bound of their preferred temperature range, and $$$h_i$$$ — the upper bound of their preferred temperature range.A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the $$$i$$$-th customer is satisfied if and only if the temperature is between $$$l_i$$$ and $$$h_i$$$ (inclusive) in the $$$t_i$$$-th minute.Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.

int solution() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int a;
    int t0;
    scanf("%d %d", &a, &t0);
    int s = 0;
    int min = t0;
    int max = t0;
    int k = 0;
    while (a--) {
      int s1;
      int mi;
      int ma;
      scanf("%d %d %d", &s1, &mi, &ma);
      min = min - (s1 - s);
      max = max + (s1 - s);
      if (min >= mi && max <= ma) {
        min = min;
        max = max;
      } else if (min <= mi && max >= ma) {
        min = mi;
        max = ma;
      } else if (min <= mi && max >= mi && max <= ma) {
        min = mi;
        max = max;
      } else if (min >= mi && min <= ma && max >= ma) {
        min = min;
        max = ma;
      } else {
        k++;
      }
      s = s1;
    }
    if (k == 0) {
      printf("YEs\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

fn solution() {
    let mut buffer = String::new();
    {
        let stdin = io::stdin();
        let mut handle = stdin.lock();
        handle.read_to_string(&mut buffer).unwrap();
    }

    let arr = buffer
        .split_whitespace()
        .map(|x| x.parse::<i64>().expect("convert to number"))
        .collect::<Vec<_>>();

    let mut it = arr.iter();

    let q = *it.next().unwrap();

    for _i in 0..q {
        let n = *it.next().unwrap();
        let m = *it.next().unwrap();

        let mut arr = vec![];
        for _ in 0..n {
            let t = *it.next().unwrap();
            let l = *it.next().unwrap();
            let h = *it.next().unwrap();
            arr.push((t, l, h));
        }

        let mut time = 0i64;
        let mut range = (m, m);

        let mut possible = true;

        for &(t, l, h) in arr.iter() {
            let t_diff = t - time;

            let r_l = range.0 - t_diff;
            let r_h = range.1 + t_diff;

            let clamp_l = cmp::max(r_l, l);
            let clamp_h = cmp::min(r_h, h);

            if clamp_l > clamp_h {
                possible = false;
                break;
            }

            range = (clamp_l, clamp_h);
            time = t;
        }

        if possible {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}


Kawashiro Nitori is a girl who loves competitive programming.One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.Given a string $$$s$$$ and a parameter $$$k$$$, you need to check if there exist $$$k+1$$$ non-empty strings $$$a_1,a_2...,a_{k+1}$$$, such that $$$$$$s=a_1+a_2+\ldots +a_k+a_{k+1}+R(a_k)+R(a_{k-1})+\ldots+R(a_{1}).$$$$$$ Here $$$+$$$ represents concatenation. We define $$$R(x)$$$ as a reversed string $$$x$$$. For example $$$R(abcd) = dcba$$$. Note that in the formula above the part $$$R(a_{k+1})$$$ is intentionally skipped.

fn solution() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut itr = buf.split_whitespace();

    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());

    let t: usize = scan!(usize);
    for _ in 1..=t {
        let (n, k) = scan!(usize, usize);
        let s = scan!(bytes);

        if k < n.div_ceil(2) {
            let mut flag = true;
            for i in 0..k {
                if s[i] != s[n - 1 - i] {
                    flag = false;
                    break;
                }
            }
            if flag {
                print!("YES");
            } else {
                print!("NO");
            }
        } else {
            print!("NO");
        }
        print!("\n");
    }
}


You are given an array $$$a_1, a_2, \dots , a_n$$$ consisting of integers from $$$0$$$ to $$$9$$$. A subarray $$$a_l, a_{l+1}, a_{l+2}, \dots , a_{r-1}, a_r$$$ is good if the sum of elements of this subarray is equal to the length of this subarray ($$$\sum\limits_{i=l}^{r} a_i = r - l + 1$$$).For example, if $$$a = [1, 2, 0]$$$, then there are $$$3$$$ good subarrays: $$$a_{1 \dots 1} = [1], a_{2 \dots 3} = [2, 0]$$$ and $$$a_{1 \dots 3} = [1, 2, 0]$$$.Calculate the number of good subarrays of the array $$$a$$$.

int solution() {
  int tests;
  scanf("%d", &tests);
  for (int i = 0; i < tests; ++i) {
    int32_t n;
    scanf("%" SCNd32, &n);
    char *s = (char *)malloc(n + 1);
    int32_t *sum_cnt = (int32_t *)calloc(n * 9, sizeof(int32_t));
    int32_t *negative_sum_cnt = (int32_t *)calloc(n * 9, sizeof(int32_t));
    sum_cnt[0] = 1;
    scanf("%s", s);
    int32_t sum = 0;
    int64_t total = 0;
    for (int32_t i = 0; i < n; ++i) {
      sum += (s[i] - '0' - 1);
      if (sum < 0) {
        total += negative_sum_cnt[-sum];
        ++negative_sum_cnt[-sum];
      } else {
        total += sum_cnt[sum];
        ++sum_cnt[sum];
      }
    }
    printf("%" SCNd64 "\n", total);
    free(s);
    free(sum_cnt);
    free(negative_sum_cnt);
  }
  return 0;
}

fn solution() {
    let t: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    for _ in 0..t {
        let n: usize = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            buf.trim_end().parse().unwrap()
        };

        let a: Vec<i64> = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            buf.trim_end()
                .chars()
                .map(|c| c.to_digit(10).unwrap() as i64)
                .collect()
        };

        let mut csa = vec![0; n + 1];
        for i in 0..n {
            csa[i + 1] = csa[i] + a[i];
        }

        let mut map = HashMap::new();
        for i in 0..=n {
            *map.entry(csa[i] - i as i64).or_insert(0i64) += 1;
        }

        let mut ans = 0;
        for x in map.values() {
            ans += x * (x - 1) / 2;
        }
        println!("{}", ans);
    }
}


Johnny has recently found an ancient, broken computer. The machine has only one register, which allows one to put in there one variable. Then in one operation, you can shift its bits left or right by at most three positions. The right shift is forbidden if it cuts off some ones. So, in fact, in one operation, you can multiply or divide your number by $$$2$$$, $$$4$$$ or $$$8$$$, and division is only allowed if the number is divisible by the chosen divisor. Formally, if the register contains a positive integer $$$x$$$, in one operation it can be replaced by one of the following:   $$$x \cdot 2$$$  $$$x \cdot 4$$$  $$$x \cdot 8$$$  $$$x / 2$$$, if $$$x$$$ is divisible by $$$2$$$  $$$x / 4$$$, if $$$x$$$ is divisible by $$$4$$$  $$$x / 8$$$, if $$$x$$$ is divisible by $$$8$$$ For example, if $$$x = 6$$$, in one operation it can be replaced by $$$12$$$, $$$24$$$, $$$48$$$ or $$$3$$$. Value $$$6$$$ isn't divisible by $$$4$$$ or $$$8$$$, so there're only four variants of replacement.Now Johnny wonders how many operations he needs to perform if he puts $$$a$$$ in the register and wants to get $$$b$$$ at the end.

int solution(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    unsigned long long int a;
    unsigned long long int b;
    scanf("%llu %llu", &a, &b);
    int count = 0;
    while (8 * a <= b) {
      a *= 8, count++;
    }
    while (4 * a <= b) {
      a *= 4, count++;
    }
    while (2 * a <= b) {
      a *= 2, count++;
    }
    if (a == b) {
      printf("%d\n", count);
      continue;
    }
    while ((!(a % 8)) && (a / 8 >= b)) {
      a /= 8, count++;
    }
    while ((!(a % 4)) && (a / 4 >= b)) {
      a /= 4, count++;
    }
    while ((!(a % 2)) && (a / 2 >= b)) {
      a /= 2, count++;
    }
    if (a == b) {
      printf("%d\n", count);
    } else {
      printf("-1\n");
    }
  }
  return 0;
}

fn solution() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.split_whitespace();
    let t: usize = itr.next().unwrap().parse().unwrap();
    let mut out = Vec::new();
    for _ in 0..t {
        let mut a: u64 = itr.next().unwrap().parse().unwrap();
        let mut b: u64 = itr.next().unwrap().parse().unwrap();
        if a > b {
            std::mem::swap(&mut a, &mut b);
        }
        if !b.is_multiple_of(a) {
            writeln!(out, "-1").ok();
        } else {
            let rem = b / a;
            if rem & (rem - 1) == 0 {
                let cnt = rem.trailing_zeros();
                writeln!(out, "{}", cnt / 3 + cnt % 3 / 2 + cnt % 3 % 2).ok();
            } else {
                writeln!(out, "-1").ok();
            }
        }
    }
    stdout().write_all(&out).unwrap();
}


Berland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.So imagine Monocarp got recommended $$$n$$$ songs, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th song had its predicted rating equal to $$$p_i$$$, where $$$1 \le p_i \le n$$$ and every integer from $$$1$$$ to $$$n$$$ appears exactly once. In other words, $$$p$$$ is a permutation.After listening to each of them, Monocarp pressed either a like or a dislike button. Let his vote sequence be represented with a string $$$s$$$, such that $$$s_i=0$$$ means that he disliked the $$$i$$$-th song, and $$$s_i=1$$$ means that he liked it.Now the service has to re-evaluate the song ratings in such a way that:  the new ratings $$$q_1, q_2, \dots, q_n$$$ still form a permutation ($$$1 \le q_i \le n$$$; each integer from $$$1$$$ to $$$n$$$ appears exactly once);  every song that Monocarp liked should have a greater rating than every song that Monocarp disliked (formally, for all $$$i, j$$$ such that $$$s_i=1$$$ and $$$s_j=0$$$, $$$q_i>q_j$$$ should hold). Among all valid permutations $$$q$$$ find the one that has the smallest value of $$$\sum\limits_{i=1}^n |p_i-q_i|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$.Print the permutation $$$q_1, q_2, \dots, q_n$$$. If there are multiple answers, you can print any of them.

fn solution() {
    let (i, o) = (io::stdin(), io::stdout());
    let mut o = bw::new(o.lock());
    let mut i = i.lock().lines().skip(1);
    while let Some(_) = i.next() {
        let p = i
            .next()
            .unwrap()
            .unwrap()
            .split(' ')
            .map(|w| w.parse::<u32>().unwrap())
            .collect::<Vec<_>>();
        let s = i.next().unwrap().unwrap().chars().collect::<Vec<_>>();
        let (mut x, mut y): (Vec<((usize, u32), &char)>, Vec<((usize, u32), &char)>) = p
            .into_iter()
            .enumerate()
            .zip(&s)
            .partition(|&t| *t.1 == '0');
        x.sort_unstable_by_key(|k| k.0 .1);
        y.sort_unstable_by_key(|k| k.0 .1);

        let mut x = (1..=s.len()).zip(x.iter().chain(&y)).collect::<Vec<_>>();
        x.sort_unstable_by_key(|k| k.1 .0 .0);

        for (_z, ((_a, _n), _q)) in &x {
            write!(o, "{} ", _z).ok();
        }
        writeln!(o).ok();
    }
}


Score : <var>200</var> points

Problem Statement

Today is August <var>24</var>, one of the five Product Days in a year.

A date <var>m</var>-<var>d</var> (<var>m</var> is the month, <var>d</var> is the date) is called a Product Day when <var>d</var> is a two-digit number, and all of the following conditions are satisfied (here <var>d_{10}</var> is the tens digit of the day and <var>d_1</var> is the ones digit of the day):

<var>d_1 \geq 2</var>

<var>d_{10} \geq 2</var>

<var>d_1 \times d_{10} = m</var>

Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of <var>M</var> month from Month <var>1</var> to Month <var>M</var>, and each month consists of <var>D</var> days from Day <var>1</var> to Day <var>D</var>.

In Takahashi Calendar, how many Product Days does a year have?

Constraints

All values in input are integers.

<var>1 \leq M \leq 100</var>

<var>1 \leq D \leq 99</var>

Input

Input is given from Standard Input in the following format:

<var>M</var> <var>D</var>

Output

Print the number of Product Days in a year in Takahashi Calender.

Sample Input 1

15 40

Sample Output 1

10

There are <var>10</var> Product Days in a year, as follows (<var>m</var>-<var>d</var> denotes Month <var>m</var>, Day <var>d</var>):

<var>4</var>-<var>22</var>

<var>6</var>-<var>23</var>

<var>6</var>-<var>32</var>

<var>8</var>-<var>24</var>

<var>9</var>-<var>33</var>

<var>10</var>-<var>25</var>

<var>12</var>-<var>26</var>

<var>12</var>-<var>34</var>

<var>14</var>-<var>27</var>

<var>15</var>-<var>35</var>

Sample Input 2

12 31

Sample Output 2

5

Sample Input 3

1 1

Sample Output 3

0

fn solution() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.split_whitespace();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let d: usize = itr.next().unwrap().parse().unwrap();
    let mut ans = 0;
    for i in 1..m + 1 {
        for j in 1..d + 1 {
            let d1 = j / 10;
            let d2 = j % 10;
            if d1 >= 2 && d2 >= 2 && i == d1 * d2 {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Let $$$LCM(x, y)$$$ be the minimum positive integer that is divisible by both $$$x$$$ and $$$y$$$. For example, $$$LCM(13, 37) = 481$$$, $$$LCM(9, 6) = 18$$$.You are given two integers $$$l$$$ and $$$r$$$. Find two integers $$$x$$$ and $$$y$$$ such that $$$l \le x < y \le r$$$ and $$$l \le LCM(x, y) \le r$$$.

int solution(void) {
  int linenum;

  scanf("%d", &linenum);

  int l[linenum];
  int r[linenum];

  for (int i = 0; i < linenum; i++) {
    getchar();
    scanf("%d %d", &l[i], &r[i]);
  }

  for (int i = 0; i < linenum; i++) {
    if (l[i] * 2 > r[i]) {
      printf("-1 -1");
    } else {
      printf("%d %d", l[i], 2 * l[i]);
    }
    printf("\n");
  }
}

fn solution() {
    let stdin = std::io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).unwrap();
    let ntc: i32 = line.trim().parse().unwrap();
    for _ in 0..ntc {
        line.clear();
        stdin.read_line(&mut line).unwrap();
        let a: Vec<i32> = line
            .split_whitespace()
            .map(|x| x.parse().expect("parse error"))
            .collect();
        if a[0] * 2 <= a[1] {
            println!("{} {}", a[0], a[0] * 2);
        } else {
            println!("-1 -1");
        }
    }
}


Score : <var>100</var> points

Problem Statement

Find the number of ways to choose a pair of an even number and an odd number from the positive integers between <var>1</var> and <var>K</var> (inclusive). The order does not matter.

Constraints

<var>2\leq K\leq 100</var>

<var>K</var> is an integer.

Input

Input is given from Standard Input in the following format:

<var>K</var>

Output

Print the number of ways to choose a pair of an even number and an odd number from the positive integers between <var>1</var> and <var>K</var> (inclusive).

Sample Input 1

3

Sample Output 1

2

Two pairs can be chosen: <var>(2,1)</var> and <var>(2,3)</var>.

Sample Input 2

6

Sample Output 2

9

Sample Input 3

11

Sample Output 3

30

Sample Input 4

50

Sample Output 4

625

int solution(void) {
  int K = 0;
  scanf("%d", &K);
  printf("%d", K / 2 * (K - K / 2));
  return 0;
}

fn solution() {
    let reader = io::stdin();
    let mut reader = BufReader::new(reader.lock());

    let mut s = String::new();

    let _ = reader.read_line(&mut s);

    let k: u32 = s.trim().parse().unwrap();

    let tmp = k / 2;

    println!(
        "{}",
        if k.is_multiple_of(2) {
            tmp * tmp
        } else {
            tmp * (tmp + 1)
        }
    );
}


void solution(int *numbers, int size) {
  int pos = 0;
  while (pos < size) {
    if (numbers[pos] >= numbers[pos - 1]) {
      pos++;
    } else {
      int tmp = numbers[pos - 1];
      numbers[pos - 1] = numbers[pos];
      numbers[pos] = tmp;
      pos--;

      if (pos == 0) {
        pos = 1;
      }
    }
  }
}

fn solution<T>(arr: &[T]) -> Vec<T>
where
    T: cmp::PartialEq + cmp::PartialOrd + Clone,
{
    let mut arr = arr.to_vec();
    let mut i: usize = 1;
    let mut j: usize = 2;

    while i < arr.len() {
        if arr[i - 1] < arr[i] {
            i = j;
            j = i + 1;
        } else {
            arr.swap(i - 1, i);
            i -= 1;
            if i == 0 {
                i = j;
                j += 1;
            }
        }
    }
    arr
}


Score : <var>100</var> points

Problem Statement

There are a total of <var>A + B</var> cats and dogs.
Among them, <var>A</var> are known to be cats, but the remaining <var>B</var> are not known to be either cats or dogs.

Determine if it is possible that there are exactly <var>X</var> cats among these <var>A + B</var> animals.

Constraints

<var>1 \leq A \leq 100</var>

<var>1 \leq B \leq 100</var>

<var>1 \leq X \leq 200</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>B</var> <var>X</var>

Output

If it is possible that there are exactly <var>X</var> cats, print YES; if it is impossible, print NO.

Sample Input 1

3 5 4

Sample Output 1

YES

If there are one cat and four dogs among the <var>B = 5</var> animals, there are <var>X = 4</var> cats in total.

Sample Input 2

2 2 6

Sample Output 2

NO

Even if all of the <var>B = 2</var> animals are cats, there are less than <var>X = 6</var> cats in total.

Sample Input 3

5 3 2

Sample Output 3

NO

Even if all of the <var>B = 3</var> animals are dogs, there are more than <var>X = 2</var> cats in total.

int solution() {
  int a = 0;
  int b = 0;
  int c = 0;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  if (a + b >= c) {
    if (a <= c) {
      printf("YES");
    } else {
      printf("NO");
    }
  } else {
    printf("NO");
  }
  return 0;
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let input: Vec<i32> = s
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    let mut state = 0;
    let lefta = input[2] - input[0];
    if lefta >= 0 && lefta <= input[1] {
        state = 1
    }

    let ans = ["NO", "YES"];
    println!("{}", ans[state]);
}


Score : <var>300</var> points

Problem Statement

Snuke has a fair <var>N</var>-sided die that shows the integers from <var>1</var> to <var>N</var> with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between <var>1</var> and <var>K-1</var> (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes <var>0</var> if the coin lands tails up.

The game ends when the score becomes <var>0</var> or becomes <var>K</var> or above. Snuke wins if the score is <var>K</var> or above, and loses if the score is <var>0</var>.

You are given <var>N</var> and <var>K</var>. Find the probability that Snuke wins the game.

Constraints

<var>1 ≤ N ≤ 10^5</var>

<var>1 ≤ K ≤ 10^5</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>K</var>

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most <var>10^{-9}</var>.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows <var>1</var>, Snuke needs to get four consecutive heads from four coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}</var>.

If the die shows <var>2</var>, Snuke needs to get three consecutive heads from three coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}</var>.

If the die shows <var>3</var>, Snuke needs to get two consecutive heads from two coin flips to obtain a score of <var>10</var> or above. The probability of this happening is <var>\frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}</var>.

Thus, the probability that Snuke wins is <var>\frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333</var>.

Sample Input 2

100000 5

Sample Output 2

0.999973749998

int solution(void) {
  double N = 0;
  int K = 0;
  int count = 1;
  double answer = 0;
  double temp = 1.0;
  int temp2 = 0;
  scanf("%lf %d", &N, &K);
  double kaku[100000] = {0};
  for (int i = 1; i <= N; i++) {
    temp2 = i;
    while (1) {
      if (temp2 >= K) {
        for (int j = 1; j < count; j++) {
          temp *= 0.5;
        }
        answer = 1.0 / N;
        kaku[i] = answer * temp;
        break;
      }
      temp2 *= 2;
      count++;
    }
    count = 1;
    temp = 1;
  }
  answer = 0;
  for (int i = 1; i <= N; i++) {
    answer += kaku[i];
  }
  printf("%.12lf\n", answer);
  return 0;
}

fn solution() {
    let text = {
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    };

    let mut iter = text.split_whitespace();
    let num: u64 = iter.next().unwrap().parse().unwrap();
    let goal: u64 = iter.next().unwrap().parse().unwrap();

    let mut p_s: f64 = 0.0;

    for current_score in 1..(num + 1) {
        let mut current_score = current_score;
        let mut p: f64 = 1.0;

        while current_score < goal {
            p /= 2.0;
            current_score *= 2;
        }

        p_s += p;
    }

    println!("{}", p_s / (num as f64));
}


A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading zeroes.

int solution() {
  int tickets = 0;
  scanf("%d\n", &tickets);
  char t[6];
  int sum_f = 0;
  int sum_l = 0;
  while (tickets != 0) {
    for (int i = 0; i < 3; i++) {
      scanf("%c", &t[i]);
      sum_f = sum_f + (t[i] - 48);
    }
    for (int i = 3; i < 6; i++) {
      scanf("%c\n", &t[i]);
      sum_l = sum_l + (t[i] - 48);
    }
    if (sum_f == sum_l) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    for (int i = 0; i < 6; i++) {
      t[i] = 0;
    }
    sum_f = 0;
    sum_l = 0;
    tickets--;
  }
  return 0;
}

fn solution() {
    let mut input_t = String::new();
    std::io::stdin()
        .read_line(&mut input_t)
        .expect("Can't read line");
    let t: i32 = input_t.trim().parse().expect("Can't parse input to i32");

    println!();

    for _ in 0..t {
        let mut input_line = String::new();
        std::io::stdin()
            .read_line(&mut input_line)
            .expect("Can't read line");

        let mut char_line = input_line.chars();

        let mut x = 0;
        let mut y = 0;

        for _ in 0..3 {
            x += char_line
                .next()
                .expect("something")
                .to_digit(10)
                .expect("Can't parse input to number");
        }

        for _ in 0..3 {
            y += char_line
                .next()
                .expect("something")
                .to_digit(10)
                .expect("can't parse");
        }

        if x == y {
            println!("YES")
        } else {
            println!("NO")
        }
    }
}


Score : <var>700</var> points

Problem Statement

<var>N</var> hotels are located on a straight line. The coordinate of the <var>i</var>-th hotel <var>(1 \leq i \leq N)</var> is <var>x_i</var>.

Tak the traveler has the following two personal principles:

He never travels a distance of more than <var>L</var> in a single day.

He never sleeps in the open. That is, he must stay at a hotel at the end of a day.

You are given <var>Q</var> queries. The <var>j</var>-th <var>(1 \leq j \leq Q)</var> query is described by two distinct integers <var>a_j</var> and <var>b_j</var>.
For each query, find the minimum number of days that Tak needs to travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel following his principles.
It is guaranteed that he can always travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel, in any given input.

Constraints

<var>2 \leq N \leq 10^5</var>

<var>1 \leq L \leq 10^9</var>

<var>1 \leq Q \leq 10^5</var>

<var>1 \leq x_i < x_2 < ... < x_N \leq 10^9</var>

<var>x_{i+1} - x_i \leq L</var>

<var>1 \leq a_j,b_j \leq N</var>

<var>a_j \neq b_j</var>

<var>N,\,L,\,Q,\,x_i,\,a_j,\,b_j</var> are integers.

Partial Score

<var>200</var> points will be awarded for passing the test set satisfying <var>N \leq 10^3</var> and <var>Q \leq 10^3</var>.

Input

The input is given from Standard Input in the following format:

<var>N</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
<var>L</var>
<var>Q</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
:
<var>a_Q</var> <var>b_Q</var>

Output

Print <var>Q</var> lines.
The <var>j</var>-th line <var>(1 \leq j \leq Q)</var> should contain the minimum number of days that Tak needs to travel from the <var>a_j</var>-th hotel to the <var>b_j</var>-th hotel.

Sample Input 1

9
1 3 6 13 15 18 19 29 31
10
4
1 8
7 3
6 7
8 5

Sample Output 1

4
2
1
2

For the <var>1</var>-st query, he can travel from the <var>1</var>-st hotel to the <var>8</var>-th hotel in <var>4</var> days, as follows:

Day <var>1</var>: Travel from the <var>1</var>-st hotel to the <var>2</var>-nd hotel. The distance traveled is <var>2</var>.

Day <var>2</var>: Travel from the <var>2</var>-nd hotel to the <var>4</var>-th hotel. The distance traveled is <var>10</var>.

Day <var>3</var>: Travel from the <var>4</var>-th hotel to the <var>7</var>-th hotel. The distance traveled is <var>6</var>.

Day <var>4</var>: Travel from the <var>7</var>-th hotel to the <var>8</var>-th hotel. The distance traveled is <var>10</var>.

int solution() {
  long N;
  long L;
  long Q;
  long x[100001];
  long i;
  long j;
  long k;
  long a;
  long b;
  long tmp;
  long move[100001];
  long move100[100001];
  long right;
  long ans[100001] = {0};

  scanf("%ld", &N);
  for (i = 1; i <= N; i++) {
    scanf("%ld", &x[i]);
  }
  scanf("%ld", &L);

  right = 2;
  for (i = 1; i <= N; i++) {
    for (j = right; j <= N; j++) {
      if (x[j] - x[i] > L) {
        j--;
        break;
      }
    }
    if (j > N) {
      j = N;
    }
    move[i] = j;
    right = j;
  }

  for (i = 1; i <= N; i++) {
    k = i;
    for (j = 0; j < 100; j++) {
      if (k >= N) {
        break;
      }
      k = move[k];
    }
    if (j >= 100) {
      move100[i] = k;
    } else {
      move100[i] = -1;
    }
  }

  scanf("%ld", &Q);
  for (i = 1; i <= Q; i++) {
    scanf("%ld %ld", &a, &b);
    if (a > b) {
      tmp = a;
      a = b;
      b = tmp;
    }
    if (L == 1) {
      ans[i] = b - a;
      continue;
    }

    j = a;
    while (move100[j] != -1 && move100[j] < b) {
      j = move100[j];
      ans[i] += 100;
    }

    for (; j < b;) {
      j = move[j];
      ans[i]++;
    }
  }

  for (i = 1; i <= Q; i++) {
    printf("%ld\n", ans[i]);
  }

  return 0;
}

fn solution() {
    input! {
        n: usize,
        v: [usize; n],
        l: usize,
        q: usize,
        qs: [(usize1, usize1); q]
    }
    let mut p = 1;
    while 1 << p < n - 1 {
        p += 1;
    }
    p += 1;
    let mut tab = vec![vec![0; p]; n];
    for i in 0..p {
        tab[n - 1][i] = n - 1;
    }
    let mut il = 0;
    let mut ir = 0;
    let mut d = 0;
    while il < n - 1 {
        if ir == n - 1 || d + v[ir + 1] - v[ir] > l {
            tab[il][0] = ir;
            d -= v[il + 1] - v[il];
            il += 1;
        } else {
            d += v[ir + 1] - v[ir];
            ir += 1;
        }
    }
    for i in (0..n - 1).rev() {
        for j in 1..p {
            tab[i][j] = tab[tab[i][j - 1]][j - 1];
        }
    }
    for &(a, b) in &qs {
        let a1 = min(a, b);
        let b1 = max(a, b);
        let mut day = 0;
        let mut x = a1;
        while x < b1 {
            if tab[x][0] >= b1 {
                day += 1;
                break;
            }
            for i in 0..p {
                if tab[x][i] >= b1 {
                    day += 1 << (i - 1);
                    x = tab[x][i - 1];
                    break;
                }
            }
        }
        println!("{}", day);
    }
}


Score : <var>200</var> points

Problem Statement

You are given two positive integers <var>A</var> and <var>B</var>. Compare the magnitudes of these numbers.

Constraints

<var>1 ≤ A, B ≤ 10^{100}</var>

Neither <var>A</var> nor <var>B</var> begins with a 0.

Input

Input is given from Standard Input in the following format:

<var>A</var>
<var>B</var>

Output

Print GREATER if <var>A>B</var>, LESS if <var>A<B</var> and EQUAL if <var>A=B</var>.

Sample Input 1

36
24

Sample Output 1

GREATER

Since <var>36>24</var>, print GREATER.

Sample Input 2

850
3777

Sample Output 2

LESS

Sample Input 3

9720246
22516266

Sample Output 3

LESS

Sample Input 4

123456789012345678901234567890
234567890123456789012345678901

Sample Output 4

LESS

int solution() {
  int len1 = 0;
  int len2 = 0;
  char s1[101];
  char s2[101];

  scanf("%s %s", s1, s2);

  while (s1[len1]) {
    len1++;
  }
  while (s2[len2]) {
    len2++;
  }
  if (len1 > len2 || (len1 == len2 && strcmp(s1, s2) > 0)) {
    printf("GREATER\n");
  } else if (strcmp(s1, s2) == 0) {
    printf("EQUAL\n");
  } else {
    printf("LESS\n");
  }

  return 0;
}

fn solution() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let a = buf.trim().chars().collect::<Vec<char>>();
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let b = buf.trim().chars().collect::<Vec<char>>();
    if a.len() > b.len() {
        println!("GREATER");
    } else if a.len() < b.len() {
        println!("LESS");
    } else {
        for i in 0..a.len() {
            if a[i] > b[i] {
                println!("GREATER");
                break;
            } else if a[i] < b[i] {
                println!("LESS");
                break;
            } else {
                if i == 0 {
                    println!("EQUAL");
                }
            }
        }
    }
}


Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of $$$n$$$ distinct integers. An array $$$b = [b_1, b_2, \ldots, b_k]$$$ is called nice if for any two distinct elements $$$b_i, b_j$$$ of $$$b$$$, $$$|b_i-b_j|$$$ appears in $$$b$$$ at least once. In addition, all elements in $$$b$$$ must be distinct. Can you add several (maybe, $$$0$$$) integers to $$$a$$$ to create a nice array $$$b$$$ of size at most $$$300$$$? If $$$a$$$ is already nice, you don't have to add any elements.For example, array $$$[3, 6, 9]$$$ is nice, as $$$|6-3|=|9-6| = 3$$$, which appears in the array, and $$$|9-3| = 6$$$, which appears in the array, while array $$$[4, 2, 0, 6, 9]$$$ is not nice, as $$$|9-4| = 5$$$ is not present in the array.For integers $$$x$$$ and $$$y$$$, $$$|x-y| = x-y$$$ if $$$x > y$$$ and $$$|x-y| = y-x$$$ otherwise.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int arr[n];
    int f = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &arr[i]);
      if (arr[i] < 0) {
        f = 1;
      }
    }
    if (f) {
      printf("NO\n");
    } else {
      printf("YES\n");
      printf("101\n");
      for (int i = 0; i <= 100; i++) {
        printf("%d ", i);
      }
    }
    printf("\n");
  }
  return 0;
}

fn solution() {
    let std_in = stdin();
    let in_lock = std_in.lock();
    let input = BufReader::new(in_lock);

    let std_out = stdout();
    let out_lock = std_out.lock();
    let mut output = BufWriter::new(out_lock);

    let mut lines = input.lines().map(|r| r.unwrap());

    let s = lines.next().unwrap();
    let mut it = s.split_whitespace().map(|s| s.parse::<usize>().unwrap());
    let t = it.next().unwrap();

    for _ in 0..t {
        let s = lines.next().unwrap();
        let mut it = s.split_whitespace().map(|s| s.parse::<i64>().unwrap());

        let n = it.next().unwrap() as usize;

        let s = lines.next().unwrap();
        let it = s.split_whitespace().map(|s| s.parse::<i64>().unwrap());

        let mut a = Vec::with_capacity(n);
        a.extend(it);

        if a.iter().any(|&i| i < 0) {
            writeln!(&mut output, "NO").unwrap();
        } else {
            writeln!(&mut output, "YES").unwrap();
            writeln!(&mut output, "101").unwrap();
            for i in 0..=100 {
                write!(&mut output, "{} ", i).unwrap();
            }
            writeln!(&mut output).unwrap();
        }
    }
}


Ashish and Vivek play a game on a matrix consisting of $$$n$$$ rows and $$$m$$$ columns, where they take turns claiming cells. Unclaimed cells are represented by $$$0$$$, while claimed cells are represented by $$$1$$$. The initial state of the matrix is given. There can be some claimed cells in the initial state.In each turn, a player must claim a cell. A cell may be claimed if it is unclaimed and does not share a row or column with any other already claimed cells. When a player is unable to make a move, he loses and the game ends.If Ashish and Vivek take turns to move and Ashish goes first, determine the winner of the game if both of them are playing optimally.Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves.

fn solution() {
    let cases = {
        let mut input = String::new();
        io::stdin()
            .read_line(&mut input)
            .expect("failed to read input");

        input.trim().parse::<u8>().expect("invalid input")
    };

    for _ in 0..cases {
        let (n, m) = {
            let mut input = String::new();
            io::stdin()
                .read_line(&mut input)
                .expect("failed to read input");

            let mut input_iter = input
                .split_whitespace()
                .map(|x| x.parse::<usize>().expect("invalid input"));
            (input_iter.next().unwrap(), input_iter.next().unwrap())
        };

        let mut rows = vec![false; n];
        let mut cols = vec![false; m];
        for row in rows.iter_mut() {
            let mut input = String::new();
            io::stdin()
                .read_line(&mut input)
                .expect("failed to read input");

            for (col, val) in cols.iter_mut().zip(input.split_whitespace()) {
                if val != "0" {
                    *col = true;
                    *row = true;
                }
            }
        }

        let val = cmp::min(
            rows.iter().filter(|&&x| !x).count(),
            cols.iter().filter(|&&x| !x).count(),
        );

        if val % 2 == 0 {
            println!("Vivek");
        } else {
            println!("Ashish");
        }
    }
}


Score : <var>400</var> points

Problem Statement

Fennec and Snuke are playing a board game.

On the board, there are <var>N</var> cells numbered <var>1</var> through <var>N</var>, and <var>N-1</var> roads, each connecting two cells. Cell <var>a_i</var> is adjacent to Cell <var>b_i</var> through the <var>i</var>-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.

Initially, Cell <var>1</var> is painted black, and Cell <var>N</var> is painted white. The other cells are not yet colored.
Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell.
More specifically, each player performs the following action in her/his turn:

Fennec: selects an uncolored cell that is adjacent to a black cell, and paints it black.

Snuke: selects an uncolored cell that is adjacent to a white cell, and paints it white.

A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.

Constraints

<var>2 \leq N \leq 10^5</var>

<var>1 \leq a_i, b_i \leq N</var>

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>a_1</var> <var>b_1</var>
<var>:</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>

Output

If Fennec wins, print Fennec; if Snuke wins, print Snuke.

Sample Input 1

7
3 6
1 2
3 1
7 4
5 7
1 4

Sample Output 1

Fennec

For example, if Fennec first paints Cell <var>2</var> black, she will win regardless of Snuke's moves.

Sample Input 2

4
1 4
4 2
2 3

Sample Output 2

Snuke

int solution(void) {
  int n;
  scanf("%d", &n);
  int m = 0;
  int head[n * 2];
  int next[n * 2];
  int to[n * 2];
  int a;
  int b;
  int post[n];
  int count;
  bool visited[n];

  for (int i = 0; i < n; i++) {
    head[i] = -1;
  }
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    next[m] = head[a];
    head[a] = m;
    to[m] = b;
    m++;
    next[m] = head[b];
    head[b] = m;
    to[m] = a;
    m++;
  }

  for (int i = 0; i < n; i++) {
    visited[i] = false;
  }
  int costf[n];
  costf[0] = 0;
  visited[0] = true;
  count = 0;
  post[0] = 0;
  for (int i = 0; i < count + 1; i++) {
    for (int e = head[post[i]]; e != -1; e = next[e]) {
      if (visited[to[e]] == false) {
        visited[to[e]] = true;
        costf[to[e]] = costf[post[i]] + 1;
        count++;
        post[count] = to[e];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    visited[i] = false;
  }
  int costs[n];
  costs[n - 1] = 0;
  visited[n - 1] = true;
  count = 0;
  post[0] = n - 1;
  for (int i = i = 0; i < count + 1; i++) {
    for (int e = head[post[i]]; e != -1; e = next[e]) {
      if (visited[to[e]] == false) {
        visited[to[e]] = true;
        costs[to[e]] = costs[post[i]] + 1;
        count++;
        post[count] = to[e];
      }
    }
  }

  int Fennec = 0;
  int Snuke = 0;
  for (int i = 0; i < n; i++) {
    if (costf[i] <= costs[i]) {
      Fennec++;
    } else {
      Snuke++;
    }
  }

  if (Fennec > Snuke) {
    printf("Fennec\n");
  } else {
    printf("Snuke\n");
  }

  return 0;
}

fn solution() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin
        .read_line(&mut buf)
        .expect("ERROR Can't read array size");
    let n: usize = buf.trim().parse().unwrap();
    let mut graph: Vec<Vec<usize>> = Vec::with_capacity(n);
    for _ in 0..n {
        graph.push(Vec::new());
    }
    for _ in 0..n - 1 {
        let mut buf = String::new();
        stdin
            .read_line(&mut buf)
            .expect("ERROR Can't read array size");
        let v: Vec<usize> = buf.split_whitespace().map(|n| n.parse().unwrap()).collect();
        let a = v[0] - 1;
        let b = v[1] - 1;
        graph.get_mut(a).unwrap().push(b);
        graph.get_mut(b).unwrap().push(a);
    }
    let mut used: Vec<bool> = Vec::new();
    used.resize(n, false);
    let mut sa = 0;
    let mut sb = 0;

    let mut aque = VecDeque::new();
    let mut bque = VecDeque::new();
    aque.push_back(0);
    bque.push_back(n - 1);

    while !aque.is_empty() || !bque.is_empty() {
        let mut aque_new = VecDeque::new();
        while !aque.is_empty() {
            let tar = aque.pop_front().unwrap();
            if !used[tar] {
                used[tar] = true;
                sa += 1;
                for val in graph[tar].iter() {
                    aque_new.push_back(*val);
                }
            }
        }
        aque.append(&mut aque_new);
        let mut bque_new = VecDeque::new();
        while !bque.is_empty() {
            let tar = bque.pop_front().unwrap();
            if !used[tar] {
                sb += 1;
                used[tar] = true;
                for val in graph[tar].iter() {
                    bque_new.push_back(*val);
                }
            }
        }
        bque.append(&mut bque_new);
    }
    if sa > sb {
        println!("Fennec");
    } else {
        println!("Snuke");
    }
}


Score : <var>200</var> points

Problem Statement

You have written <var>N</var> problems to hold programming contests.
The <var>i</var>-th problem will have a score of <var>P_i</var> points if used in a contest.

With these problems, you would like to hold as many contests as possible under the following condition:

A contest has three problems. The first problem has a score not greater than <var>A</var> points, the second has a score between <var>A + 1</var> and <var>B</var> points (inclusive), and the third has a score not less than <var>B + 1</var> points.

The same problem should not be used in multiple contests.
At most how many contests can be held?

Constraints

<var>3 \leq N \leq 100</var>

<var>1 \leq P_i \leq 20</var> (<var>1 \leq i \leq N</var>)

<var>1 \leq A < B < 20</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A</var> <var>B</var>
<var>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var>

Output

Print the answer.

Sample Input 1

7
5 15
1 10 16 2 7 20 12

Sample Output 1

2

Two contests can be held by putting the first, second, third problems and the fourth, fifth, sixth problems together.

Sample Input 2

8
3 8
5 5 5 10 10 10 15 20

Sample Output 2

0

No contest can be held, because there is no problem with a score of <var>A = 3</var> or less.

Sample Input 3

3
5 6
5 6 10

Sample Output 3

1

int solution(void) {
  int n;
  int a;
  int b;
  int p[101];
  int cnt1 = 0;
  int cnt2 = 0;
  int cnt3 = 0;
  int ans = 0;
  ;

  scanf("%d%d%d", &n, &a, &b);

  for (int cnt = 1; cnt <= n; cnt++) {
    scanf("%d", &p[cnt]);
    if (p[cnt] <= a) {
      cnt1++;
    } else if (p[cnt] < b || p[cnt] <= b) {
      cnt2++;
    } else if (p[cnt] > b) {
      cnt3++;
    }
  }
  ans = cnt1;
  if (ans > cnt2) {
    ans = cnt2;
  }
  if (ans > cnt3) {
    ans = cnt3;
  }

  printf("%d\n", ans);

  return 0;
}

fn solution() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    let _n: usize = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().parse().unwrap();
        buf.clear();
        tmp
    };
    let info: Vec<usize> = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.split_whitespace().map(|a| a.parse().unwrap()).collect();
        buf.clear();
        tmp
    };
    let mut ps: Vec<usize> = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.split_whitespace().map(|a| a.parse().unwrap()).collect();
        buf.clear();
        tmp
    };
    ps.sort();
    let one = ps.iter().filter(|a| a <= &&info[0]).count();
    let two = ps
        .iter()
        .filter(|a| &&info[0] < a && a <= &&info[1])
        .count();
    let three = ps.iter().filter(|a| &&info[1] < a).count();
    println!("{}", min(min(one, two), three));
}


Score : <var>100</var> points

Problem Statement

A Hitachi string is a concatenation of one or more copies of the string hi.

For example, hi and hihi are Hitachi strings, while ha and hii are not.

Given a string <var>S</var>, determine whether <var>S</var> is a Hitachi string.

Constraints

The length of <var>S</var> is between <var>1</var> and <var>10</var> (inclusive).

<var>S</var> is a string consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

If <var>S</var> is a Hitachi string, print Yes; otherwise, print No.

Sample Input 1

hihi

Sample Output 1

Yes

hihi is the concatenation of two copies of hi, so it is a Hitachi string.

Sample Input 2

hi

Sample Output 2

Yes

Sample Input 3

ha

Sample Output 3

No

fn solution() {
    let mut target_str = String::new();
    io::stdin().read_line(&mut target_str).unwrap();
    let target_str = target_str.trim();

    let mut count: usize = 0;

    loop {
        match target_str.chars().nth(count) {
            Some('h') => match target_str.chars().nth(count + 1) {
                Some('i') => {
                    count += 2;
                }
                _ => {
                    println!("No");
                    break;
                }
            },
            None => {
                println!("Yes");
                break;
            }
            _ => {
                println!("No");
                break;
            }
        };
    }
}


Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse. For example, strings "pop", "noon", "x", and "kkkkkk" are palindromes, while strings "moon", "tv", and "abab" are not. An empty string is also a palindrome.Gildong loves this concept so much, so he wants to play with it. He has $$$n$$$ distinct strings of equal length $$$m$$$. He wants to discard some of the strings (possibly none or all) and reorder the remaining strings so that the concatenation becomes a palindrome. He also wants the palindrome to be as long as possible. Please help him find one.

fn solution() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let mut pieces = line.split_whitespace();
    let n: u32 = pieces.next().unwrap().parse().unwrap();
    let _m: u32 = pieces.next().unwrap().parse().unwrap();
    let mut strings = Vec::new();
    for _ in 0..n {
        let mut string = String::new();
        io::stdin().read_line(&mut string).unwrap();
        string = string.trim().to_string();
        strings.push(string);
    }

    let mut pairs = Vec::new();
    let mut palindrome_string: Option<String> = None;

    while !strings.is_empty() {
        let string = strings.pop().unwrap();
        let string_rev: String = string.chars().rev().collect();
        match strings.iter().position(|s| *s == string_rev) {
            Some(partner_idx) => {
                pairs.push((string, string_rev));
                strings.remove(partner_idx);
            }
            None => {
                if string == string_rev {
                    palindrome_string = Some(string);
                }
            }
        }
    }

    let mut palindrome = String::new();
    for pair_first in pairs.iter().map(|(first, _)| first) {
        palindrome.push_str(pair_first);
    }
    if palindrome_string.is_some() {
        palindrome.push_str(&palindrome_string.unwrap());
    }
    for pair_second in pairs.iter().rev().map(|(_, second)| second) {
        palindrome.push_str(pair_second);
    }

    println!("{}", palindrome.len());
    println!("{}", palindrome);
}


A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.You are given a string $$$s$$$ of length $$$n$$$, consisting of digits.In one operation you can delete any character from string $$$s$$$. For example, it is possible to obtain strings 112, 111 or 121 from string 1121.You need to determine whether there is such a sequence of operations (possibly empty), after which the string $$$s$$$ becomes a telephone number.

int solution() {
  int t;
  scanf("%d", &t);
  int a[t];
  char s[t][101];
  for (int i = 0; i < t; i++) {
    scanf("%d", &a[i]);
    getchar();
    scanf("%s", s[i]);
  }
  int flag = 1;
  for (int i = 0; i < t; i++) {
    flag = 1;
    for (int j = 0; j < a[i] - 10; j++) {
      if (s[i][j] == '8') {
        printf("YES\n");
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      printf("NO\n");
    }
  }
}

fn solution() {
    use std::io::{self, Read};

    let mut b = String::new();
    io::stdin().read_to_string(&mut b).unwrap();
    let a = b.split_whitespace().skip(1).collect::<Vec<_>>();

    for j in a.as_slice().chunks(2) {
        let i = j[1];

        match i.find('8') {
            Some(idx) => {
                let l = i.len() - idx;
                if l >= 11 {
                    println!("YES");
                } else {
                    println!("NO");
                }
            }
            _ => {
                println!("NO");
            }
        }
    }
}


There are $$$n$$$ points on the plane, $$$(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$$$.You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.

fn solution() {
    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    handle.read_to_string(&mut buffer).unwrap();

    let arr: Vec<_> = buffer
        .split_whitespace()
        .map(|x| x.parse::<u32>().unwrap())
        .collect();
    let n = arr[0] as usize;
    let mut bmin = 0;
    for i in 0..n {
        let x0 = arr[1 + i * 2];
        let y0 = arr[1 + i * 2 + 1];
        let b = y0 + x0;
        bmin = cmp::max(bmin, b);
    }

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


Score : <var>500</var> points

Problem Statement

There are <var>N</var> Snuke Cats numbered <var>1, 2, \ldots, N</var>, where <var>N</var> is even.

Each Snuke Cat wears a red scarf, on which his favorite non-negative integer is written.

Recently, they learned the operation called xor (exclusive OR).

What is xor?

For <var>n</var> non-negative integers <var>x_1, x_2, \ldots, x_n</var>, their xor, <var>x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n</var> is defined as follows:

 When <var>x_1~\textrm{xor}~x_2~\textrm{xor}~\ldots~\textrm{xor}~x_n</var> is written in base two, the digit in the <var>2^k</var>'s place (<var>k \geq 0</var>) is <var>1</var> if the number of integers among <var>x_1, x_2, \ldots, x_n</var> whose binary representations have <var>1</var> in the <var>2^k</var>'s place is odd, and <var>0</var> if that count is even.

For example, <var>3~\textrm{xor}~5 = 6</var>.

They wanted to use this operation quickly, so each of them calculated the xor of the integers written on their scarfs except his scarf.

We know that the xor calculated by Snuke Cat <var>i</var>, that is, the xor of the integers written on the scarfs except the scarf of Snuke Cat <var>i</var> is <var>a_i</var>.
Using this information, restore the integer written on the scarf of each Snuke Cat.

Constraints

All values in input are integers.

<var>2 \leq N \leq 200000</var>

<var>N</var> is even.

<var>0 \leq a_i \leq 10^9</var>

There exists a combination of integers on the scarfs that is consistent with the given information.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>a_1</var> <var>a_2</var> <var>\ldots</var> <var>a_N</var>

Output

Print a line containing <var>N</var> integers separated with space.

The <var>i</var>-th of the integers from the left should represent the integer written on the scarf of Snuke Cat <var>i</var>.

If there are multiple possible solutions, you may print any of them.

Sample Input 1

4
20 11 9 24

Sample Output 1

26 5 7 22

<var>5~\textrm{xor}~7~\textrm{xor}~22 = 20</var>

<var>26~\textrm{xor}~7~\textrm{xor}~22 = 11</var>

<var>26~\textrm{xor}~5~\textrm{xor}~22 = 9</var>

<var>26~\textrm{xor}~5~\textrm{xor}~7 = 24</var>

Thus, this output is consistent with the given information.

fn solution() {
    let _n = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace()
            .next()
            .unwrap()
            .parse::<i64>()
            .unwrap()
    };
    let a: Vec<i64> = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace()
            .filter_map(|x| x.parse().ok())
            .collect()
    };

    let all_xor = a.iter().fold(0_i64, |l, r| l ^ *r);
    for x in a {
        println!("{}", all_xor ^ x);
    }
}


Score : <var>400</var> points

Problem Statement

Given is a tree <var>G</var> with <var>N</var> vertices.
The vertices are numbered <var>1</var> through <var>N</var>, and the <var>i</var>-th edge connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.

Consider painting the edges in <var>G</var> with some number of colors.
We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.

Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.

Constraints

<var> 2 \le N \le 10^5</var>

<var> 1 \le a_i \lt b_i \le N</var>

All values in input are integers.

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>\vdots</var>
<var>a_{N-1}</var> <var>b_{N-1}</var>

Output

Print <var>N</var> lines.

The first line should contain <var>K</var>, the number of colors used.

The <var>(i+1)</var>-th line <var>(1 \le i \le N-1)</var> should contain <var>c_i</var>, the integer representing the color of the <var>i</var>-th edge, where <var>1 \le c_i \le K</var> must hold.

If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.

Sample Input 1

3
1 2
2 3

Sample Output 1

2
1
2

Sample Input 2

8
1 2
2 3
2 4
2 5
4 7
5 6
6 8

Sample Output 2

4
1
2
3
4
1
1
2

Sample Input 3

6
1 2
1 3
1 4
1 5
1 6

Sample Output 3

5
1
2
3
4
5

fn solution() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let (a, b): (Vec<usize>, Vec<usize>) = {
        let (mut a, mut b) = (vec![], vec![]);
        for _ in 0..(N - 1) {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            a.push(iter.next().unwrap().parse().unwrap());
            b.push(iter.next().unwrap().parse().unwrap());
        }
        (a, b)
    };

    let G = {
        let mut G = vec![std::collections::HashSet::new(); N + 1];
        for i in 0..(N - 1) {
            G[a[i]].insert((b[i], i));
            G[b[i]].insert((a[i], i));
        }
        G
    };

    let mut q = std::collections::VecDeque::new();
    q.push_back(1);
    let mut prev = vec![0; N + 1];
    let mut res = vec![0; N - 1];
    let mut K = 0;

    while !q.is_empty() {
        let i = q.pop_front().unwrap();

        let mut z = 1;
        for &(j, k) in &G[i] {
            if prev[j] == 0 && j != 1 {
                if z == prev[i] {
                    z += 1;
                }

                res[k] = z;
                prev[j] = z;
                z += 1;
                q.push_back(j);
            }
        }

        K = std::cmp::max(z - 1, K);
    }

    println!("{}", K);

    println!(
        "{}",
        res.iter()
            .map(|&r| r.to_string())
            .collect::<Vec<_>>()
            .join("\n")
    );
}


Score : <var>200</var> points

Problem Statement

Alice, Bob and Charlie are playing Card Game for Three, as below:

At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.

The players take turns. Alice goes first.

If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)

If the current player's deck is empty, the game ends and the current player wins the game.

You are given the initial decks of the players.
More specifically, you are given three strings <var>S_A</var>, <var>S_B</var> and <var>S_C</var>. The <var>i</var>-th <var>(1≦i≦|S_A|)</var> letter in <var>S_A</var> is the letter on the <var>i</var>-th card in Alice's initial deck. <var>S_B</var> and <var>S_C</var> describes Bob's and Charlie's initial decks in the same way.

Determine the winner of the game.

Constraints

<var>1≦|S_A|≦100</var>

<var>1≦|S_B|≦100</var>

<var>1≦|S_C|≦100</var>

Each letter in <var>S_A</var>, <var>S_B</var>, <var>S_C</var> is a, b or c.

Input

The input is given from Standard Input in the following format:

<var>S_A</var>
<var>S_B</var>
<var>S_C</var>

Output

If Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.

Sample Input 1

aca
accc
ca

Sample Output 1

A

The game will progress as below:

Alice discards the top card in her deck, a. Alice takes the next turn.

Alice discards the top card in her deck, c. Charlie takes the next turn.

Charlie discards the top card in his deck, c. Charlie takes the next turn.

Charlie discards the top card in his deck, a. Alice takes the next turn.

Alice discards the top card in her deck, a. Alice takes the next turn.

Alice's deck is empty. The game ends and Alice wins the game.

Sample Input 2

abcb
aacb
bccc

Sample Output 2

C

int solution() {
  int a = 0;
  int b = 0;
  int c = 0;
  char ary_a[128];
  char ary_b[128];
  char ary_c[128];
  char turn = 'a';

  fgets(ary_a, sizeof(ary_a), stdin);
  fgets(ary_b, sizeof(ary_b), stdin);
  fgets(ary_c, sizeof(ary_c), stdin);

  while (1) {

    if (turn == 'a') {
      turn = ary_a[a];
      if (isspace(ary_a[a]) != 0) {
        puts("A");
        return 0;
      }
      a++;
    } else if (turn == 'b') {
      turn = ary_b[b];
      if (isspace(ary_b[b]) != 0) {
        puts("B");
        return 0;
      }
      b++;
    } else {
      turn = ary_c[c];
      if (isspace(ary_c[c]) != 0) {
        puts("C");
        return 0;
      }
      c++;
    }
  }

  return 0;
}

fn solution() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let a = String::from(s.trim());
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let b = String::from(s.trim());
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let c = String::from(s.trim());
    let mut s = [a, b, c];

    let mut next = 0;
    while !s[next].is_empty() {
        next = match s[next].remove(0) {
            'a' => 0,
            'b' => 1,
            _ => 2,
        };
    }

    println!(
        "{}",
        match next {
            0 => 'A',
            1 => 'B',
            _ => 'C',
        },
    );
}


Score : <var>400</var> points

Problem Statement

Snuke has one biscuit and zero Japanese yen (the currency) in his pocket.
He will perform the following operations exactly <var>K</var> times in total, in the order he likes:

Hit his pocket, which magically increases the number of biscuits by one.

Exchange <var>A</var> biscuits to <var>1</var> yen.

Exchange <var>1</var> yen to <var>B</var> biscuits.

Find the maximum possible number of biscuits in Snuke's pocket after <var>K</var> operations.

Constraints

<var>1 \leq K,A,B \leq 10^9</var>

<var>K,A</var> and <var>B</var> are integers.

Input

Input is given from Standard Input in the following format:

<var>K</var> <var>A</var> <var>B</var>

Output

Print the maximum possible number of biscuits in Snuke's pocket after <var>K</var> operations.

Sample Input 1

4 2 6

Sample Output 1

7

The number of biscuits in Snuke's pocket after <var>K</var> operations is maximized as follows:

Hit his pocket. Now he has <var>2</var> biscuits and <var>0</var> yen.

Exchange <var>2</var> biscuits to <var>1</var> yen. his pocket. Now he has <var>0</var> biscuits and <var>1</var> yen.

Hit his pocket. Now he has <var>1</var> biscuits and <var>1</var> yen.

Exchange <var>1</var> yen to <var>6</var> biscuits. his pocket. Now he has <var>7</var> biscuits and <var>0</var> yen.

Sample Input 2

7 3 4

Sample Output 2

8

Sample Input 3

314159265 35897932 384626433

Sample Output 3

48518828981938099

int solution(void) {
  long K = 0;
  long A = 0;
  long B = 0;
  scanf("%ld %ld %ld", &K, &A, &B);
  if (K <= A) {
    printf("%ld\n", K + 1);
  } else {
    if (B - A <= 2) {
      printf("%ld\n", K + 1);
    } else {
      long count = 0;
      long hit = 0;
      count = A;
      hit = A - 1;
      K -= hit;
      if (K % 2 == 0) {
        count += (K / 2) * (B - A);
      } else {
        count += (K / 2) * (B - A);
        count++;
      }
      printf("%ld\n", count);
    }
  }
  return 0;
}

fn solution() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let vs: Vec<u64> = s
        .split_whitespace()
        .map(|token| token.parse().ok().unwrap())
        .collect();
    let k = vs[0];
    let a = vs[1];
    let b = vs[2];

    if b <= a + 2 {
        println!("{}", k + 1);
        return;
    }

    let mut n: u64 = 1;
    let mut yen: u64 = 0;

    for i in (0..k).rev() {
        if i <= yen {
            if yen > 0 {
                n += b;
                yen -= 1;
            } else {
                n += 1;
            }
        } else if n >= a {
            n -= a;
            yen += 1;
        } else if yen > 0 {
            n += b;
            yen -= 1;
        } else {
            n += 1;
        }
    }
    println!("{}", n);
}


You are given $$$n$$$ words of equal length $$$m$$$, consisting of lowercase Latin alphabet letters. The $$$i$$$-th word is denoted $$$s_i$$$.In one move you can choose any position in any single word and change the letter at that position to the previous or next letter in alphabetical order. For example:  you can change 'e' to 'd' or to 'f';  'a' can only be changed to 'b';  'z' can only be changed to 'y'. The difference between two words is the minimum number of moves required to make them equal. For example, the difference between "best" and "cost" is $$$1 + 10 + 0 + 0 = 11$$$.Find the minimum difference of $$$s_i$$$ and $$$s_j$$$ such that $$$(i < j)$$$. In other words, find the minimum difference over all possible pairs of the $$$n$$$ words.

int solution() {
  int test_cases = 0;
  scanf("%d", &test_cases);

  while (test_cases--) {
    int num_strings = 0;
    scanf("%d", &num_strings);
    int string_len = 0;
    scanf("%d", &string_len);
    char array[num_strings][string_len];
    for (int i = 0; i < num_strings; i++) {
      scanf("%s", array[i]);
    }

    int answer = INT_MAX;
    for (int i = 0; i < num_strings; i++) {
      for (int j = i + 1; j < num_strings; j++) {
        int score = 0;
        for (int k = 0; k < string_len; k++) {
          if (array[i][k] == array[j][k]) {
            continue;
          }
          score = score + abs(array[i][k] - array[j][k]);
        }
        if (answer > score) {
          answer = score;
        }
      }
    }
    printf("%d\n", answer);
  }
}

fn solution() {
    let mut input = String::new();
    stdin().read_to_string(&mut input).ok();
    let mut output = String::new();
    let mut input = input.split_ascii_whitespace();
    let t = input.next().unwrap().parse::<usize>().unwrap();
    for _ in 0..t {
        let n = input.next().unwrap().parse::<usize>().unwrap();
        let m = input.next().unwrap().parse::<usize>().unwrap();
        let s: Vec<_> = input.by_ref().map(str::as_bytes).take(n).collect();
        let mut min = u32::MAX;
        for i in 1..n {
            for j in 0..i {
                let mut sum = 0u32;
                for k in 0..m {
                    let a = s[i][k];
                    let b = s[j][k];
                    if a > b {
                        sum += (a - b) as u32;
                    } else {
                        sum += (b - a) as u32;
                    }
                }
                min = min.min(sum);
            }
        }
        writeln!(output, "{min}").ok();
    }
    print!("{output}");
}


Alice and Bob are playing a game with strings. There will be $$$t$$$ rounds in the game. In each round, there will be a string $$$s$$$ consisting of lowercase English letters. Alice moves first and both the players take alternate turns. Alice is allowed to remove any substring of even length (possibly empty) and Bob is allowed to remove any substring of odd length from $$$s$$$.More formally, if there was a string $$$s = s_1s_2 \ldots s_k$$$ the player can choose a substring $$$s_ls_{l+1} \ldots s_{r-1}s_r$$$ with length of corresponding parity and remove it. After that the string will become $$$s = s_1 \ldots s_{l-1}s_{r+1} \ldots s_k$$$.After the string becomes empty, the round ends and each player calculates his/her score for this round. The score of a player is the sum of values of all characters removed by him/her. The value of $$$\texttt{a}$$$ is $$$1$$$, the value of $$$\texttt{b}$$$ is $$$2$$$, the value of $$$\texttt{c}$$$ is $$$3$$$, $$$\ldots$$$, and the value of $$$\texttt{z}$$$ is $$$26$$$. The player with higher score wins the round. For each round, determine the winner and the difference between winner's and loser's scores. Assume that both players play optimally to maximize their score. It can be proved that a draw is impossible.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char str[200001];
    scanf("%s", str);
    int l = strlen(str);
    if (l == 1) {
      printf("Bob %d\n", (str[0] - 96));
      continue;
    }
    int sum = 0;
    for (int i = 0; i < l; i++) {
      sum += (str[i] - 96);
    }
    if (!(l & 1)) {
      printf("Alice %d\n", sum);
      continue;
    }
    if (str[0] >= str[l - 1]) {
      printf("Alice %d\n", (sum - (2 * (str[l - 1] - 96))));
    } else {
      printf("Alice %d\n", (sum - (2 * (str[0] - 96))));
    }
  }
}

fn solution() {
    let alphabet = "abcdefghijklmnopqrstuvwxyz";

    let mut t = String::new();
    stdin().read_line(&mut t);
    let t = t.trim().parse::<usize>().unwrap();

    for _ in 0..t {
        let mut buf = String::new();
        stdin().read_line(&mut buf);

        buf = buf.trim().to_string();
        if buf.len() < 2 {
            println!("Bob {}", alphabet.find(&buf).unwrap() + 1);
            continue;
        }

        let mut alicesum = 0;
        let mut first = 0;
        let mut last = 0;
        let mut j = 0;
        for i in buf.chars() {
            if j == 0 {
                first = alphabet.find(i).unwrap() + 1;
            }
            if j == buf.len() - 1 {
                last = alphabet.find(i).unwrap() + 1;
            }

            alicesum += alphabet.find(i).unwrap() + 1;
            j += 1;
        }

        if buf.len().is_multiple_of(2) {
            println!("Alice {}", alicesum);
        } else {
            if first > last {
                println!("Alice {}", alicesum - last * 2)
            } else {
                println!("Alice {}", alicesum - first * 2)
            }
        }
    }
}


Score : <var>400</var> points

Problem Statement

In some other world, today is Christmas.

Mr. Takaha decides to make a multi-dimensional burger in his party. A level-<var>L</var> burger (<var>L</var> is an integer greater than or equal to <var>0</var>) is the following thing:

A level-<var>0</var> burger is a patty.

A level-<var>L</var> burger <var>(L \geq 1)</var> is a bun, a level-<var>(L-1)</var> burger, a patty, another level-<var>(L-1)</var> burger and another bun, stacked vertically in this order from the bottom.

For example, a level-<var>1</var> burger and a level-<var>2</var> burger look like BPPPB and BBPPPBPBPPPBB (rotated <var>90</var> degrees), where B and P stands for a bun and a patty.

The burger Mr. Takaha will make is a level-<var>N</var> burger. Lunlun the Dachshund will eat <var>X</var> layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?

Constraints

<var>1 \leq N \leq 50</var>

<var>1 \leq X \leq (</var> the total number of layers in a level-<var>N</var> burger <var>)</var>

<var>N</var> and <var>X</var> are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>X</var>

Output

Print the number of patties in the bottom-most <var>X</var> layers from the bottom of a level-<var>N</var> burger.

Sample Input 1

2 7

Sample Output 1

4

There are <var>4</var> patties in the bottom-most <var>7</var> layers of a level-<var>2</var> burger (BBPPPBPBPPPBB).

Sample Input 2

1 1

Sample Output 2

0

The bottom-most layer of a level-<var>1</var> burger is a bun.

Sample Input 3

50 4321098765432109

Sample Output 3

2160549382716056

A level-<var>50</var> burger is rather thick, to the extent that the number of its layers does not fit into a <var>32</var>-bit integer.

int solution(void) {

  long N;
  long X;
  long sou[51];
  long patty[51];
  long ans = 0;
  scanf("%ld %ld", &N, &X);
  sou[0] = 1;
  patty[0] = 1;
  for (int i = 1; i <= N; i++) {
    sou[i] = sou[i - 1] * 2 + 3;
    patty[i] = patty[i - 1] * 2 + 1;
  }

  int flag = 0;
  int i = 0;
  for (i = N; i >= 0 && flag == 0; i--) {

    if (X == 1) {
      flag = 1;
      if (i == 0) {
        ans += 1;
      } else {
        ans += 0;
      }
    } else if (1 < X && X < sou[i] / 2 + 1) {
      X -= 1;
    } else if (X == sou[i] / 2 + 1) {
      ans += patty[i - 1] + 1;
      flag = 1;
    } else if (sou[i] / 2 + 1 < X && X < sou[i]) {
      X -= sou[i] / 2 + 1;
      ans += patty[i - 1] + 1;
    } else if (X == sou[i]) {
      flag = 1;
      ans += patty[i];
    }
  }
  printf("%ld\n", ans);
}

fn solution() {
    input! {
        n: usize,
        x: usize
    }

    let mut v: Vec<(usize, usize)> = vec![(1, 1)];
    for i in 0..n {
        let (iall, ipat) = v[i];
        let all = 3 + 2 * iall;
        let pat = 1 + 2 * ipat;
        v.push((all, pat));
    }
    let mut sum = 0;
    let mut queue: Vec<(usize, usize)> = vec![(n, x)];
    while let Some((level, eat)) = queue.pop() {
        if level == 0 && eat == 1 {
            sum += 1;
            continue;
        }
        if eat <= level {
            continue;
        }
        let (all, pat) = v[level];
        if eat == all {
            sum += pat;
            continue;
        }
        let mid = all / 2;
        match eat.cmp(&(mid + 1)) {
            std::cmp::Ordering::Less => {
                queue.push((level - 1, eat - 1));
            }
            std::cmp::Ordering::Equal => {
                let (_, pat) = v[level - 1];
                sum += pat + 1;
            }
            std::cmp::Ordering::Greater => {
                let (_, pat) = v[level - 1];
                sum += pat + 1;
                queue.push((level - 1, eat - mid - 1));
            }
        }
    }
    println!("{}", sum);
}


You might have remembered Theatre square from the problem 1A. Now it's finally getting repaved.The square still has a rectangular shape of $$$n \times m$$$ meters. However, the picture is about to get more complicated now. Let $$$a_{i,j}$$$ be the $$$j$$$-th square in the $$$i$$$-th row of the pavement.You are given the picture of the squares:  if $$$a_{i,j} = $$$ "*", then the $$$j$$$-th square in the $$$i$$$-th row should be black;  if $$$a_{i,j} = $$$ ".", then the $$$j$$$-th square in the $$$i$$$-th row should be white. The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:  $$$1 \times 1$$$ tiles — each tile costs $$$x$$$ burles and covers exactly $$$1$$$ square;  $$$1 \times 2$$$ tiles — each tile costs $$$y$$$ burles and covers exactly $$$2$$$ adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into $$$1 \times 1$$$ tiles. You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.What is the smallest total price of the tiles needed to cover all the white squares?

int solution() {
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    int n;
    int m;
    int x;
    int y;
    char *a = NULL;
    long long cost = 0;
    scanf("%d%d%d%d", &n, &m, &x, &y);
    a = (char *)calloc(m + 4, sizeof(char));
    for (int j = 0; j < n; j++) {
      scanf("%s", a);
      for (int k = 0; k < m; k++) {
        if (k < m - 1 && a[k] == '.' && a[k + 1] == '.') {
          int min = (2 * x) < y ? (2 * x) : y;
          cost += min;
          k++;
        } else if (k <= m - 1 && a[k] == '.') {
          cost += x;
        }
      }
    }
    printf("%lld\n", cost);
    free(a);
  }
  return 0;
}

fn solution() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
    for _ in 0..t {
        let xs: Vec<usize> = lines
            .next()
            .unwrap()
            .unwrap()
            .split(' ')
            .map(|x| x.parse().unwrap())
            .collect();
        let (n, x, y) = (xs[0], xs[2], xs[3]);
        let mut css: Vec<Vec<usize>> = Vec::new();
        for _ in 0..n {
            let mut s: Vec<char> = lines.next().unwrap().unwrap().chars().collect();
            s.push('*');
            let mut cs: Vec<usize> = Vec::new();
            let mut count: usize = 0;
            for c in s {
                if c == '.' {
                    count += 1;
                } else if count > 0 {
                    cs.push(count);
                    count = 0;
                }
            }
            css.push(cs);
        }
        let mut ans: usize = 0;
        for cs in css {
            for c in cs {
                if x * 2 < y {
                    ans += x * c;
                } else {
                    ans += y * (c / 2) + x * (c % 2);
                }
            }
        }
        println!("{}", ans);
    }
}


You have $$$n$$$ rectangular wooden blocks, which are numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th block is $$$1$$$ unit high and $$$\lceil \frac{i}{2} \rceil$$$ units long.Here, $$$\lceil \frac{x}{2} \rceil$$$ denotes the result of division of $$$x$$$ by $$$2$$$, rounded up. For example, $$$\lceil \frac{4}{2} \rceil = 2$$$ and $$$\lceil \frac{5}{2} \rceil = \lceil 2.5 \rceil = 3$$$.For example, if $$$n=5$$$, then the blocks have the following sizes: $$$1 \times 1$$$, $$$1 \times 1$$$, $$$1 \times 2$$$, $$$1 \times 2$$$, $$$1 \times 3$$$.  The available blocks for $$$n=5$$$ Find the maximum possible side length of a square you can create using these blocks, without rotating any of them. Note that you don't have to use all of the blocks.  One of the ways to create $$$3 \times 3$$$ square using blocks $$$1$$$ through $$$5$$$

int solution() {
  long long t = 0;
  long long n = 0;

  scanf("%lld", &t);

  while (t--) {
    scanf("%lld", &n);
    printf("%lld \n", (long long)(n + 1) / 2);
  }

  return 0;
}

fn solution() {
    let mut buf = BufWriter::new(io::stdout().lock());
    std::io::stdin()
        .lines()
        .skip(1)
        .flatten()
        .flat_map(|s| s.parse::<i32>())
        .for_each(|n| {
            writeln!(buf, "{}", n.wrapping_add(1).wrapping_shr(1)).unwrap_or_default();
        });
}


You are given an array $$$a$$$ of $$$n$$$ positive integers. Determine if, by rearranging the elements, you can make the array strictly increasing. In other words, determine if it is possible to rearrange the elements such that $$$a_1 < a_2 < \dots < a_n$$$ holds.

int solution() {
  int ccount = 0;
  int num2 = 0;

  scanf("%d", &ccount);
  for (int i = 0; i < ccount; ++i) {

    scanf("%d", &num2);
    int arr[num2];
    for (int j = 0; j < num2; ++j) {
      scanf("%d", &arr[j]);
    }

    for (int i = 0; i < num2 - 1; i++) {
      for (int j = 0; j < num2 - 1 - i; j++) {
        int temp = 0;
        if (arr[j] > arr[j + 1]) {
          temp = arr[j];
          arr[j] = arr[j + 1];
          arr[j + 1] = temp;
        }
      }
    }
    int index_temp = 0;
    for (index_temp = 0; index_temp < num2 - 1; ++index_temp) {
      if (arr[index_temp] == arr[index_temp + 1]) {
        printf("NO\n");
        break;
      }
    }
    if (index_temp == num2 - 1) {
      printf("YES\n");
    }
  }
}

fn solution() {
    std::io::stdin()
        .lines()
        .skip(2)
        .step_by(2)
        .flatten()
        .for_each(|a| {
            let mut hs = std::collections::HashSet::with_capacity(100_000);
            if a.split_ascii_whitespace()
                .try_fold((), |_a, s| hs.insert(s).then_some(()))
                == Some(())
            {
                println!("YES");
            } else {
                println!("NO");
            };
        });
}