You are a coach of a group consisting of $$$n$$$ students. The $$$i$$$-th student has programming skill $$$a_i$$$. All students have distinct programming skills. You want to divide them into teams in such a way that:  No two students $$$i$$$ and $$$j$$$ such that $$$|a_i - a_j| = 1$$$ belong to the same team (i.e. skills of each pair of students in the same team have the difference strictly greater than $$$1$$$);  the number of teams is the minimum possible. You have to answer $$$q$$$ independent queries.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int a[n];
    int ans = 1;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (abs(a[j] - a[k]) == 1) {
          ans = 2;
          break;
        }
      }
    }

    printf("%d\n", ans);
  }
  return 0;
}

fn solution() {
    let reader = io::stdin();

    let mut val = String::new();

    io::stdin()
        .read_line(&mut val)
        .expect("Не удалось прочитать строку");

    let val: u32 = val.trim().parse().expect("Пожалуйста, введите число!");

    for _ in 0..val {
        let mut val = String::new();
        io::stdin()
            .read_line(&mut val)
            .expect("Не удалось прочитать строку");

        let mut numbers: Vec<i32> = reader
            .lock()
            .lines()
            .next()
            .unwrap()
            .unwrap()
            .split(' ')
            .map(|s| s.trim())
            .filter(|s| !s.is_empty())
            .map(|s| s.parse().unwrap())
            .collect();

        let length = numbers.len();
        numbers.sort();
        let mut flag = false;
        for i in 0..length - 1 {
            let difference = numbers[i + 1] - numbers[i];
            if difference == 1 {
                println!("2");
                flag = true;
                break;
            }
        }
        if !flag {
            println!("1");
        }
    }
}


Score : <var>200</var> points

Problem Statement

Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer <var>K</var> such that Takahashi will be at the starting position again after he does the following action <var>K</var> times:

Go one meter in the direction he is facing. Then, turn <var>X</var> degrees counter-clockwise.

Constraints

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

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

Input

Input is given from Standard Input in the following format:

<var>X</var>

Output

Print the number of times Takahashi will do the action before he is at the starting position again.

Sample Input 1

90

Sample Output 1

4

Takahashi's path is a square.

Sample Input 2

1

Sample Output 2

360

int solution(void) {
  int x = 0;
  int k = 0;
  int sumx = 0;

  scanf("%d", &x);
  do {
    sumx += x;
    k++;
  } while (sumx % 360);

  printf("%d", k);

  return 0;
}

fn solution() {
    let mut buf = String::new();
    std::io::stdin()
        .read_line(&mut buf)
        .expect("failed to read");
    let x: u32 = buf.trim().parse().unwrap();

    let mut i: u32 = 1;

    loop {
        if (360 * i).is_multiple_of(x) {
            println!("{}", 360 * i / x);
            break;
        } else {
            i += 1;
        }
    }
}


Score : <var>200</var> points

Problem Statement

Given are two strings <var>S</var> and <var>T</var>.

Let us change some of the characters in <var>S</var> so that <var>T</var> will be a substring of <var>S</var>.

At least how many characters do we need to change?

Here, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but not a substring of xxyxx.

Constraints

The lengths of <var>S</var> and <var>T</var> are each at least <var>1</var> and at most <var>1000</var>.

The length of <var>T</var> is at most that of <var>S</var>.

<var>S</var> and <var>T</var> consist of lowercase English letters.

Input

Input is given from Standard Input in the following format:

<var>S</var>
<var>T</var>

Output

Print the minimum number of characters in <var>S</var> that need to be changed.

Sample Input 1

cabacc
abc

Sample Output 1

1

For example, changing the fourth character a in <var>S</var> to c will match the second through fourth characters in <var>S</var> to <var>T</var>.

Since <var>S</var> itself does not have <var>T</var> as its substring, this number of changes - one - is the minimum needed.

Sample Input 2

codeforces
atcoder

Sample Output 2

6

int solution(void) {
  char s[1001] = {'\0'};
  char t[1001] = {'\0'};
  int l_s = 0;
  int l_t = 0;
  int max_match = 0;
  scanf("%s", s);
  scanf("%s", t);
  while (s[l_s] != '\0') {
    l_s++;
  }
  while (t[l_t] != '\0') {
    l_t++;
  }
  for (int i = 0; i < l_s - l_t + 1; i++) {
    int match = 0;
    for (int j = 0; j < l_t; j++) {
      if (s[i + j] == t[j]) {
        match++;
      }
    }
    if (match > max_match) {
      max_match = match;
    }
  }
  printf("%d\n", l_t - max_match);
  return 0;
}

fn solution() -> Result<()> {
    let mut s = String::new();
    let ls = io::stdin().read_line(&mut s)? - 1;
    let mut t = String::new();
    let lt = io::stdin().read_line(&mut t)? - 1;

    let mut m = 1001;
    for i in 0..=(ls - lt) {
        let mut res = 0;
        for (x, y) in t.chars().zip(s[i..i + lt].chars()) {
            if x != y {
                res += 1;
            }
        }
        m = min(m, res);
    }
    println!("{}", m);

    Ok(())
}


Score : <var>300</var> points

Problem Statement

You are given <var>N</var> positive integers <var>a_1, a_2, ..., a_N</var>.

For a non-negative integer <var>m</var>, let <var>f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N)</var>.

Here, <var>X\ mod\ Y</var> denotes the remainder of the division of <var>X</var> by <var>Y</var>.

Find the maximum value of <var>f</var>.

Constraints

All values in input are integers.

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

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

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_N</var>

Output

Print the maximum value of <var>f</var>.

Sample Input 1

3
3 4 6

Sample Output 1

10

<var>f(11) = (11\ mod\ 3) + (11\ mod\ 4) + (11\ mod\ 6) = 10</var> is the maximum value of <var>f</var>.

Sample Input 2

5
7 46 11 20 11

Sample Output 2

90

Sample Input 3

7
994 518 941 851 647 2 581

Sample Output 3

4527

int solution() {
  int N = 0;
  scanf("%d", &N);
  long sum = 0;
  for (int i = 0; i < N; i++) {
    int j = 0;
    scanf("%d", &j);
    sum += j - 1;
  }
  printf("%ld\n", sum);
  return 0;
}

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

    let n: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();

    println!("{}", a.iter().fold(0, |acc, &x| acc + x - 1));
}


Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

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

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

    let mut n = input.trim().parse::<i32>().unwrap();

    while n > 0 {
        let mut word = String::new();
        io::stdin().read_line(&mut word).expect("");
        if word.len() > 12 {
            println!(
                "{}{}{}",
                &word[0..1],
                word.len() - 4,
                &word[word.len() - 3..word.len() - 1]
            );
        } else {
            println!("{}", &word[..word.len() - 1])
        }
        n -= 1;
    }
}


Did you know you can download more RAM? There is a shop with $$$n$$$ different pieces of software that increase your RAM. The $$$i$$$-th RAM increasing software takes $$$a_i$$$ GB of memory to run (temporarily, once the program is done running, you get the RAM back), and gives you an additional $$$b_i$$$ GB of RAM (permanently). Each software can only be used once. Your PC currently has $$$k$$$ GB of RAM.Note that you can't use a RAM-increasing software if it takes more GB of RAM to use than what you currently have.Since RAM is the most important thing in the world, you wonder, what is the maximum possible amount of RAM achievable?

fn solution() {
    let mut input = String::new();
    stdin().read_to_string(&mut input).unwrap();
    let mut input = input.split_ascii_whitespace().flat_map(str::parse);
    let t = input.next().unwrap();
    let mut output = String::new();
    for _ in 0..t {
        let n = input.next().unwrap();
        let mut k = input.next().unwrap();
        let mut ab: Vec<_> = input.by_ref().take(n).map(|ai| (ai, 0)).collect();
        input
            .by_ref()
            .take(n)
            .zip(&mut ab)
            .for_each(|(bi, (_, b))| *b = bi);
        ab.sort_unstable_by_key(|&(a, _)| a);
        for (ai, bi) in ab {
            if ai <= k {
                k += bi;
            }
        }
        writeln!(output, "{}", k).unwrap();
    }
    print!("{}", output);
}


There is a special offer in Vasya's favourite supermarket: if the customer buys $$$a$$$ chocolate bars, he or she may take $$$b$$$ additional bars for free. This special offer can be used any number of times.Vasya currently has $$$s$$$ roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs $$$c$$$ roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!

int solution() {
  int t;
  long long int price;
  long long int offer;
  long long int mon;
  long long int free;
  long long int div;
  long long int ctr = 0;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld%lld%lld", &mon, &offer, &free, &price);
    ctr = 0;
    div = (mon / (offer * price));
    ctr += (div * (free + offer));
    mon = mon % (price * offer);
    ctr += (mon / price);
    mon = 0;
    printf("%lld\n", ctr);
  }
  return 0;
}

fn solution() -> io::Result<()> {
    let mut buf = String::new();
    stdin().read_line(&mut buf)?;
    let times = buf.trim().parse::<u64>().unwrap();

    for _ in 0..times {
        buf.clear();
        stdin().read_line(&mut buf)?;
        let arr = Vec::from_iter(buf.split_whitespace());
        let mut b = arr[0].parse::<u64>().unwrap() / arr[3].parse::<u64>().unwrap();
        let a = b / arr[1].parse::<u64>().unwrap();
        b += a * arr[2].parse::<u64>().unwrap();
        println!("{}", b);
    }

    Ok(())
}


void solution(int *arr, int size) {
  for (int i = 1; i < size; i++) {
    int key = arr[i];
    int low = 0;
    int high = i - 1;
    int index;

    while (low <= high) {
      int mid = low + ((high - low) / 2);

      if (arr[mid] == key) {
        index = mid + 1;
        break;
      }
      if (arr[mid] < key) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }

    if (low > high) {
      index = low;
    }

    int j = i - 1;
    while (j >= index) {
      arr[j + 1] = arr[j];
      j--;
    }

    arr[j + 1] = key;
  }
}

fn solution<T: Ord + Clone>(arr: &mut [T]) {
    let len = arr.len();

    for i in 1..len {
        let key = arr[i].clone();

        let mut low = 0;
        let mut high = i;

        while low < high {
            let mid = low + (high - low) / 2;

            if arr[mid] < key {
                low = mid + 1;
            } else {
                high = mid;
            }
        }

        arr[low..=i].rotate_right(1);
        arr[low] = key;
    }
}


You are given two integers $$$l$$$ and $$$r$$$, where $$$l < r$$$. We will add $$$1$$$ to $$$l$$$ until the result is equal to $$$r$$$. Thus, there will be exactly $$$r-l$$$ additions performed. For each such addition, let's look at the number of digits that will be changed after it.For example:   if $$$l=909$$$, then adding one will result in $$$910$$$ and $$$2$$$ digits will be changed;  if you add one to $$$l=9$$$, the result will be $$$10$$$ and $$$2$$$ digits will also be changed;  if you add one to $$$l=489999$$$, the result will be $$$490000$$$ and $$$5$$$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system.Output the total number of changed digits, if you want to get $$$r$$$ from $$$l$$$, adding $$$1$$$ each time.

fn solution() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut nv: Vec<usize> = Vec::new();
    let t = s.trim().parse().unwrap();
    for _aerfresdf in 0..t {
        s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        let v = s.split_whitespace();
        let mut foo = true;
        let mut l: usize = 0;
        let mut r: usize = 0;
        for i in v {
            if foo {
                l = i.parse().unwrap();
                foo = false;
            } else {
                r = i.parse().unwrap();
            }
        }
        let mut ans: usize = 0;
        while l > 0 || r > 0 {
            ans += r - l;
            r /= 10;
            l /= 10;
        }
        nv.push(ans);
    }
    for i in nv {
        println!("{}", i);
    }
}


Bob is playing with $$$6$$$-sided dice. A net of such standard cube is shown below.He has an unlimited supply of these dice and wants to build a tower by stacking multiple dice on top of each other, while choosing the orientation of each dice. Then he counts the number of visible pips on the faces of the dice.For example, the number of visible pips on the tower below is $$$29$$$ — the number visible on the top is $$$1$$$, from the south $$$5$$$ and $$$3$$$, from the west $$$4$$$ and $$$2$$$, from the north $$$2$$$ and $$$4$$$ and from the east $$$3$$$ and $$$5$$$.The one at the bottom and the two sixes by which the dice are touching are not visible, so they are not counted towards total.Bob also has $$$t$$$ favourite integers $$$x_i$$$, and for every such integer his goal is to build such a tower that the number of visible pips is exactly $$$x_i$$$. For each of Bob's favourite integers determine whether it is possible to build a tower that has exactly that many visible pips.

fn solution() {
    let reader = io::stdin();
    let _lucky_number_count = reader
        .lock()
        .lines()
        .next()
        .unwrap()
        .unwrap()
        .parse::<i32>()
        .unwrap();

    let numbers: Vec<u64> = reader
        .lock()
        .lines()
        .next()
        .unwrap()
        .unwrap()
        .split_whitespace()
        .filter(|s| !s.is_empty())
        .map(|s| s.parse::<u64>().unwrap())
        .collect();

    let result: Vec<String> = numbers
        .iter()
        .map(|x| {
            if x > &14u64 && x % 14 > 0 && x % 14 < 7 {
                "YES".to_string()
            } else {
                "NO".to_string()
            }
        })
        .collect();

    for val in result {
        println!("{}", val);
    }
}


Score : <var>400</var> points

Problem Statement

At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

The player plays <var>N</var> rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)

Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):

<var>R</var> points for winning with Rock;

<var>S</var> points for winning with Scissors;

<var>P</var> points for winning with Paper.

However, in the <var>i</var>-th round, the player cannot use the hand he/she used in the <var>(i-K)</var>-th round. (In the first <var>K</var> rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string <var>T</var>. If the <var>i</var>-th character of <var>T</var> <var>(1 \leq i \leq N)</var> is r, the machine will play Rock in the <var>i</var>-th round. Similarly, p and s stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?

Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

if both players play the same hand, it is a draw.

Constraints

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

<var>1 \leq K \leq N-1</var>

<var>1 \leq R,S,P \leq 10^4</var>

<var>N,K,R,S,</var> and <var>P</var> are all integers.

<var>|T| = N</var>

<var>T</var> consists of r, p, and s.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>K</var>
<var>R</var> <var>S</var> <var>P</var>
<var>T</var>

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn <var>27</var> points.
We cannot earn more points, so the answer is <var>27</var>.

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996

int solution() {
  int N;
  int K;
  int R;
  int S;
  int P;
  char T[100000];
  char *ptr;
  int point;

  scanf("%d %d", &N, &K);
  scanf("%d %d %d", &R, &S, &P);
  scanf("%s", T);

  ptr = T;

  for (int i = 0; i < N; i++) {
    switch (*ptr) {
    case 'r':
      if (i >= K && *(ptr - K) == 'r') {
        T[i] = 'n';
        break;
      }
      point += P;
      break;
    case 's':
      if (i >= K && *(ptr - K) == 's') {
        T[i] = 'n';
        break;
      }
      point += R;
      break;
    case 'p':
      if (i >= K && *(ptr - K) == 'p') {
        T[i] = 'n';
        break;
      }
      point += S;
      break;
    }
    ptr++;
  }

  printf("%d", point);

  return 0;
}

fn solution() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let r: usize = iter.next().unwrap().parse().unwrap();
    let s: usize = iter.next().unwrap().parse().unwrap();
    let p: usize = iter.next().unwrap().parse().unwrap();

    let mut tt = String::new();
    std::io::stdin().read_line(&mut tt).unwrap();
    let t: Vec<char> = tt.chars().collect();

    let mut ans = 0usize;

    for i in 0..k {
        let mut rsp_cont_cnt = 0usize;
        for j in 0..(n / k + 1) {
            let now = i + j * k;
            if now > n - 1 {
                break;
            }

            let rsp = t[now];

            ans += if rsp_cont_cnt % 2 == 1 {
                0
            } else {
                match rsp {
                    'r' => p,
                    's' => r,
                    _ => s,
                }
            };

            let rsp_next = if now + k > n - 1 { '!' } else { t[now + k] };
            if rsp == rsp_next {
                rsp_cont_cnt += 1;
            } else {
                rsp_cont_cnt = 0;
            }
        }
    }

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


This is the easy version of the problem. The difference is that in this version the array can not contain zeros. You can make hacks only if both versions of the problem are solved.You are given an array $$$[a_1, a_2, \ldots a_n]$$$ consisting of integers $$$-1$$$ and $$$1$$$. You have to build a partition of this array into the set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ with the following property:  Denote the alternating sum of all elements of the $$$i$$$-th segment as $$$s_i$$$: $$$s_i$$$ = $$$a_{l_i} - a_{l_i+1} + a_{l_i+2} - a_{l_i+3} + \ldots \pm a_{r_i}$$$. For example, the alternating sum of elements of segment $$$[2, 4]$$$ in array $$$[1, 0, -1, 1, 1]$$$ equals to $$$0 - (-1) + 1 = 2$$$.  The sum of $$$s_i$$$ over all segments of partition should be equal to zero. Note that each $$$s_i$$$ does not have to be equal to zero, this property is about sum of $$$s_i$$$ over all segments of partition.The set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ is called a partition of the array $$$a$$$ of length $$$n$$$ if $$$1 = l_1 \le r_1, l_2 \le r_2, \ldots, l_k \le r_k = n$$$ and $$$r_i + 1 = l_{i+1}$$$ for all $$$i = 1, 2, \ldots k-1$$$. In other words, each element of the array must belong to exactly one segment.You have to build a partition of the given array with properties described above or determine that such partition does not exist.Note that it is not required to minimize the number of segments in the partition.

fn solution() -> std::io::Result<()> {
    let mut buf = String::new();
    let sin = std::io::stdin();
    sin.read_line(&mut buf)?;
    let mut t = buf.trim().parse::<i32>().unwrap();

    let sout = std::io::stdout().lock();
    let mut sout = std::io::BufWriter::new(sout);
    let mut res = Vec::new();
    while t > 0 {
        buf.clear();
        sin.read_line(&mut buf).unwrap();
        let n = buf.trim().parse::<usize>().unwrap();

        buf.clear();
        sin.read_line(&mut buf).unwrap();
        let a = buf
            .trim()
            .split(' ')
            .map(|ch| ch.parse::<i32>().unwrap())
            .collect::<Vec<i32>>();
        let sum = a.iter().sum::<i32>();
        if sum & 1 != 0 {
            writeln!(&mut sout, "-1")?;
        } else {
            let mut cnt = 0;
            for i in (0..n).step_by(2) {
                if a[i] == a[i + 1] {
                    writeln!(&mut res, "{} {}", i + 1, i + 2)?;
                    cnt += 1;
                } else {
                    writeln!(&mut res, "{} {}\n{} {}", i + 1, i + 1, i + 2, i + 2)?;

                    cnt += 2;
                }
            }

            write!(&mut sout, "{cnt}\n{}", std::str::from_utf8(&res).unwrap())?;
            res.clear();
        }

        t -= 1;
    }
    Ok(())
}


Score : <var>100</var> points

Problem Statement

As a New Year's gift, Dolphin received a string <var>s</var> of length <var>19</var>.

The string <var>s</var> has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters].

Dolphin wants to convert the comma-separated string <var>s</var> into a space-separated string.

Write a program to perform the conversion for him.

Constraints

The length of <var>s</var> is <var>19</var>.

The sixth and fourteenth characters in <var>s</var> are ,.

The other characters in <var>s</var> are lowercase English letters.

Input

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

<var>s</var>

Output

Print the string after the conversion.

Sample Input 1

happy,newyear,enjoy

Sample Output 1

happy newyear enjoy

Replace all the commas in happy,newyear,enjoy with spaces to obtain happy newyear enjoy.

Sample Input 2

haiku,atcoder,tasks

Sample Output 2

haiku atcoder tasks

Sample Input 3

abcde,fghihgf,edcba

Sample Output 3

abcde fghihgf edcba

int solution() {
  char *v1 = malloc(5 * sizeof(char));
  char *v2 = malloc(7 * sizeof(char));
  char *v3 = malloc(5 * sizeof(char));
  scanf("%5[^,],%7[^,],%5[^,]", v1, v2, v3);
  printf("%s %s %s\n", v1, v2, v3);
  free(v1);
  free(v2);
  free(v3);
  return 0;
}

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

    println!("{}", s.replace(",", " "));
}


This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.Tokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only of zeros and ones, $$$n$$$ is even.Now Tokitsukaze divides $$$s$$$ into the minimum number of contiguous subsegments, and for each subsegment, all bits in each subsegment are the same. After that, $$$s$$$ is considered good if the lengths of all subsegments are even.For example, if $$$s$$$ is "11001111", it will be divided into "11", "00" and "1111". Their lengths are $$$2$$$, $$$2$$$, $$$4$$$ respectively, which are all even numbers, so "11001111" is good. Another example, if $$$s$$$ is "1110011000", it will be divided into "111", "00", "11" and "000", and their lengths are $$$3$$$, $$$2$$$, $$$2$$$, $$$3$$$. Obviously, "1110011000" is not good.Tokitsukaze wants to make $$$s$$$ good by changing the values of some positions in $$$s$$$. Specifically, she can perform the operation any number of times: change the value of $$$s_i$$$ to '0' or '1'($$$1 \leq i \leq n$$$). Can you tell her the minimum number of operations to make $$$s$$$ good?

int solution() {
  long t;
  scanf("%ld", &t);
  while (t--) {
    long n;
    long ans = 0;
    long con = 1;
    scanf("\n%ld", &n);
    char str[n];
    scanf("%s", str);
    short f = 0;
    for (long a = 1; a < n; a++) {
      if (str[a] == str[a - 1]) {
        con++;
      } else {
        if (con % 2 == 1 && f == 0) {
          f = 1;
        } else if (con % 2 == 1 && f == 1) {
          f = 0;
        }
        con = 1;
        if (f) {
          ans++;
        }
      }
    }
    printf("%ld\n", ans);
  }
  return 0;
}

fn solution() {
    let stdin = std::io::stdin();
    let mut inputs = String::new();
    stdin.lock().read_to_string(&mut inputs).ok();

    let mut scanner = inputs.split_whitespace();

    let case = scanner.next().unwrap().parse::<usize>().unwrap();

    for _ in 0..case {
        let _ = scanner.next();
        let mut line = scanner.next().unwrap().chars();

        let mut elem = line.next().unwrap();
        let mut result = 0;
        let mut cnt = 1;
        for i in line {
            if elem != i {
                if cnt % 2 != 0 {
                    cnt = 2;
                    result += 1;
                } else {
                    cnt = 1;
                }
                elem = i;
            } else {
                cnt += 1;
            }
        }
        println!("{result}");
    }
}


Score : <var>100</var> points

Problem Statement

Snuke lives at position <var>x</var> on a number line.
On this line, there are two stores <var>A</var> and <var>B</var>, respectively at position <var>a</var> and <var>b</var>, that offer food for delivery.

Snuke decided to get food delivery from the closer of stores <var>A</var> and <var>B</var>.
Find out which store is closer to Snuke's residence.

Here, the distance between two points <var>s</var> and <var>t</var> on a number line is represented by <var>|s-t|</var>.

Constraints

<var>1 \leq x \leq 1000</var>

<var>1 \leq a \leq 1000</var>

<var>1 \leq b \leq 1000</var>

<var>x, a</var> and <var>b</var> are pairwise distinct.

The distances between Snuke's residence and stores <var>A</var> and <var>B</var> are different.

Input

Input is given from Standard Input in the following format:

<var>x</var> <var>a</var> <var>b</var>

Output

If store <var>A</var> is closer, print A; if store <var>B</var> is closer, print B.

Sample Input 1

5 2 7

Sample Output 1

B

The distances between Snuke's residence and stores <var>A</var> and <var>B</var> are <var>3</var> and <var>2</var>, respectively.
Since store <var>B</var> is closer, print B.

Sample Input 2

1 999 1000

Sample Output 2

A

int solution(void) {
  int x = 0;
  int a = 0;
  int b = 0;
  int disA = 0;
  int disB = 0;

  scanf("%d %d %d", &x, &a, &b);
  disA = x - a;
  if (disA < 0) {
    disA *= -1;
  }
  disB = x - b;
  if (disB < 0) {
    disB *= -1;
  }
  if (disA < disB) {
    printf("A\n");
  } else {
    printf("B\n");
  }

  return 0;
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v: Vec<i32> = s
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();
    let x = v[0];
    let a = v[1];
    let b = v[2];

    if (a - x).abs() < (b - x).abs() {
        println!("A");
    } else {
        println!("B");
    }
}


According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.

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

    io::stdin().read_line(&mut line).unwrap();
    let mut line_words = line.split_whitespace();
    let n: u8 = line_words.next().unwrap().parse().unwrap();

    let mut last_color = '*';
    let mut res = true;
    for _ in 0..n {
        line.clear();
        io::stdin().read_line(&mut line).unwrap();
        let mut chars = line.trim().chars();
        let c = chars.next().unwrap();
        if last_color == c {
            res = false;
            break;
        }
        for v in chars {
            if v != c {
                res = false;
                break;
            }
        }
        last_color = c;
    }
    if res {
        println!("YES");
    } else {
        println!("NO");
    }
}


Polycarp has spent the entire day preparing problems for you. Now he has to sleep for at least $$$a$$$ minutes to feel refreshed.Polycarp can only wake up by hearing the sound of his alarm. So he has just fallen asleep and his first alarm goes off in $$$b$$$ minutes.Every time Polycarp wakes up, he decides if he wants to sleep for some more time or not. If he's slept for less than $$$a$$$ minutes in total, then he sets his alarm to go off in $$$c$$$ minutes after it is reset and spends $$$d$$$ minutes to fall asleep again. Otherwise, he gets out of his bed and proceeds with the day.If the alarm goes off while Polycarp is falling asleep, then he resets his alarm to go off in another $$$c$$$ minutes and tries to fall asleep for $$$d$$$ minutes again.You just want to find out when will Polycarp get out of his bed or report that it will never happen.Please check out the notes for some explanations of the example.

int solution(void) {
  int t;
  int i;
  scanf("%d", &t);
  long long a[t];
  long long b[t];
  long long c[t];
  long long d[t];
  long long r[t];
  for (i = 0; i < t; ++i) {
    scanf("%lld%lld%lld%lld", &a[i], &b[i], &c[i], &d[i]);
  }
  for (i = 0; i < t; ++i) {
    if (a[i] <= b[i]) {
      r[i] = b[i];
    } else {
      if (c[i] <= d[i]) {
        r[i] = -1;
      } else {
        int diff = c[i] - d[i];
        int cn;
        if ((a[i] - b[i]) % diff == 0) {
          cn = (a[i] - b[i]) / diff;
        } else {
          cn = (a[i] - b[i]) / diff + 1;
        }

        r[i] = b[i] + cn * (d[i] + diff);
      }
    }
  }
  for (i = 0; i < t; ++i) {
    printf("%lld\n", r[i]);
  }
  return 0;
}

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

    let mut output: Vec<i64> = Vec::new();

    for _ in 0..t {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        let mut iter = input.split_whitespace();
        let a = iter.next().unwrap();
        let b = iter.next().unwrap();
        let c = iter.next().unwrap();
        let d = iter.next().unwrap();

        let a: i64 = a.parse().unwrap();
        let b: i64 = b.parse().unwrap();
        let c: i64 = c.parse().unwrap();
        let d: i64 = d.parse().unwrap();

        if a > b && c <= d {
            output.push(-1);
        } else if a <= b {
            output.push(b);
        } else {
            let time_remaining: f64 = (a - b) as f64;
            let sleep_per_alarm: f64 = (c - d) as f64;

            let times_we_need_to_sleep: i64;

            if (b + (((time_remaining / sleep_per_alarm).ceil() as i64) * c)) > a {
                times_we_need_to_sleep = (time_remaining / sleep_per_alarm).ceil() as i64;
            } else {
                times_we_need_to_sleep = ((time_remaining / sleep_per_alarm) + 1.0).ceil() as i64;
            }

            output.push(b + (times_we_need_to_sleep * c));
        }
    }

    for number in output {
        if number < -1 {
            println!("{}", -1);
        } else {
            println!("{}", number);
        }
    }
}


Score : <var>200</var> points

Problem Statement

We have a rectangular parallelepiped of size <var>A×B×C</var>, built with blocks of size <var>1×1×1</var>. Snuke will paint each of the <var>A×B×C</var> blocks either red or blue, so that:

There is at least one red block and at least one blue block.

The union of all red blocks forms a rectangular parallelepiped.

The union of all blue blocks forms a rectangular parallelepiped.

Snuke wants to minimize the difference between the number of red blocks and the number of blue blocks. Find the minimum possible difference.

Constraints

<var>2≤A,B,C≤10^9</var>

Input

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

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

Output

Print the minimum possible difference between the number of red blocks and the number of blue blocks.

Sample Input 1

3 3 3

Sample Output 1

9

For example, Snuke can paint the blocks as shown in the diagram below.
There are <var>9</var> red blocks and <var>18</var> blue blocks, thus the difference is <var>9</var>.

Sample Input 2

2 2 4

Sample Output 2

0

For example, Snuke can paint the blocks as shown in the diagram below.
There are <var>8</var> red blocks and <var>8</var> blue blocks, thus the difference is <var>0</var>.

Sample Input 3

5 3 5

Sample Output 3

15

For example, Snuke can paint the blocks as shown in the diagram below.
There are <var>45</var> red blocks and <var>30</var> blue blocks, thus the difference is <var>9</var>.

int solution(void) {
  long long int red = 0;
  long long int blue = 0;
  long long int high = 0;
  long long int lengh = 0;
  long long int deeper = 0;
  scanf("%lld %lld  %lld", &high, &lengh, &deeper);

  if (high <= lengh) {
    if (lengh <= deeper) {
      red = high * lengh * (deeper / 2 + deeper % 2);
      blue = high * lengh * (deeper / 2);
    } else {
      red = high * (lengh / 2 + lengh % 2) * deeper;
      blue = high * (lengh / 2) * deeper;
    }
  } else if (high <= deeper) {
    if (deeper <= lengh) {
      red = high * (lengh / 2 + lengh % 2) * deeper;
      blue = high * (lengh / 2) * deeper;
    } else {
      red = high * lengh * (deeper / 2 + deeper % 2);
      blue = high * lengh * (deeper / 2);
    }
  } else {
    if (deeper <= high) {
      red = (high / 2 + high % 2) * lengh * deeper;
      blue = (high / 2) * lengh * deeper;
    } else {
      red = high * lengh * (deeper / 2 + deeper % 2);
      blue = high * lengh * (deeper / 2);
    }
  }

  printf("%lld\n", red - blue);

  return 0;
}

fn solution() {
    let (A, B, C): (i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    let ans = if A % 2 == 0 || B % 2 == 0 || C % 2 == 0 {
        0
    } else {
        let mut x = [A, B, C];
        x.sort();
        x[0] * x[1]
    };

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


Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?

int solution()

{
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if ((360 % (180 - a[i])) == 0) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
}

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

    io::stdin().read_line(&mut t).expect("read error");

    let t: usize = t.trim().parse().expect("parse error");

    for _i in 0..t {
        let mut a = String::new();

        io::stdin().read_line(&mut a).expect("read error");

        let a: usize = a.trim().parse().expect("parse error");

        if 360 % (180 - a) == 0 {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}


Madoka's father just reached $$$1$$$ million subscribers on Mathub! So the website decided to send him a personalized award — The Mathhub's Bit Button! The Bit Button is a rectangular table with $$$n$$$ rows and $$$m$$$ columns with $$$0$$$ or $$$1$$$ in each cell. After exploring the table Madoka found out that: A subrectangle $$$A$$$ is contained in a subrectangle $$$B$$$ if there's no cell contained in $$$A$$$ but not contained in $$$B$$$. Two subrectangles intersect if there is a cell contained in both of them. A subrectangle is called black if there's no cell with value $$$0$$$ inside it. A subrectangle is called nice if it's black and it's not contained in another black subrectangle. The table is called elegant if there are no two nice intersecting subrectangles.For example, in the first illustration the red subrectangle is nice, but in the second one it's not, because it's contained in the purple subrectangle.  Help Madoka to determine whether the table is elegant.

fn solution() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    let stdout = io::stdout();
    let stdout_handle = stdout.lock();
    let mut out_buffer = BufWriter::with_capacity(65536, stdout_handle);

    let mut line = String::new();
    stdin.read_line(&mut line).unwrap();
    let test_cases: usize = line.trim().parse().unwrap();

    let mut table: Vec<u8> = Vec::new();
    for _t in 0..test_cases {
        table.clear();
        line.clear();
        stdin.read_line(&mut line).unwrap();
        let mut rows_columns = line.split_ascii_whitespace();
        let row_count: usize = rows_columns.next().unwrap().parse().unwrap();
        let column_count: usize = rows_columns.next().unwrap().parse().unwrap();
        table.reserve(row_count * column_count);

        for _i in 0..row_count {
            line.clear();
            stdin.read_line(&mut line).unwrap();
            table.extend(line.trim().as_bytes().iter().map(|x| x - b'0'));
        }

        let mut is_elegant: bool = true;
        'table_iter: for row in 0..(row_count - 1) {
            for column in 0..(column_count - 1) {
                let i = row * column_count + column;
                if table[i] + table[i + 1] + table[i + column_count] + table[i + column_count + 1]
                    == 3
                {
                    is_elegant = false;
                    break 'table_iter;
                }
            }
        }

        if is_elegant {
            writeln!(&mut out_buffer, "YES").unwrap();
        } else {
            writeln!(&mut out_buffer, "NO").unwrap();
        }
    }

    out_buffer.flush().unwrap();
}


You have $$$n$$$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $$$i$$$-th gift consists of $$$a_i$$$ candies and $$$b_i$$$ oranges.During one move, you can choose some gift $$$1 \le i \le n$$$ and do one of the following operations:  eat exactly one candy from this gift (decrease $$$a_i$$$ by one);  eat exactly one orange from this gift (decrease $$$b_i$$$ by one);  eat exactly one candy and exactly one orange from this gift (decrease both $$$a_i$$$ and $$$b_i$$$ by one). Of course, you can not eat a candy or orange if it's not present in the gift (so neither $$$a_i$$$ nor $$$b_i$$$ can become less than zero).As said above, all gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: $$$a_1 = a_2 = \dots = a_n$$$ and $$$b_1 = b_2 = \dots = b_n$$$ (and $$$a_i$$$ equals $$$b_i$$$ is not necessary).Your task is to find the minimum number of moves required to equalize all the given gifts.You have to answer $$$t$$$ independent test cases.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long int count = 0;
    int n;
    scanf("%d", &n);
    long long int a[n];
    long long int b[n];
    scanf("%lld", &a[0]);
    long long int min_a = a[0];
    for (int i = 1; i < n; i++) {
      scanf("%lld", &a[i]);
      if (min_a > a[i]) {
        min_a = a[i];
      }
    }
    scanf("%lld", &b[0]);
    long long int min_b = b[0];
    for (int i = 1; i < n; i++) {
      scanf("%lld", &b[i]);
      if (min_b > b[i]) {
        min_b = b[i];
      }
    }
    for (int i = 0; i < n; i++) {
      int dif1 = a[i] - min_a;
      int dif2 = b[i] - min_b;
      count = count + ((dif1 >= dif2) ? dif1 : dif2);
    }
    printf("%lld\n", count);
  }
}

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();
            let iter = buf.split_whitespace();
            iter.map(|x| x.parse().unwrap()).collect()
        };

        let b: Vec<i64> = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let iter = buf.split_whitespace();
            iter.map(|x| x.parse().unwrap()).collect()
        };

        let mut ans = 0;
        let min_a = a.iter().min().unwrap();
        let min_b = b.iter().min().unwrap();
        for i in 0..n {
            let x = a[i] - min_a;
            let y = b[i] - min_b;
            ans += cmp::min(x, y) + (x - y).abs();
        }
        println!("{}", ans);
    }
}


Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed k hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very light.Vasya has a train lighting schedule for all n hours of the trip — n numbers from 0 to 100 each (the light level in the first hour, the second hour and so on). During each of those hours he will either read the whole time, or not read at all. He wants to choose k hours to read a book, not necessarily consecutive, so that the minimum level of light among the selected hours were maximum. Vasya is very excited before the upcoming contest, help him choose reading hours.

int solution() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  int n;
  int k;
  scanf("%d %d", &n, &k);
  int a[n];
  int b[n];
  int i = 0;
  int j;
  int t;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (a[i] < a[j]) {
        t = a[i];
        a[i] = a[j];
        a[j] = t;
      }
    }
  }

  printf("%d\n", a[k - 1]);

  int l = a[k - 1];

  int u = 0;
  for (i = 0; i < n; i++) {
    if (b[i] >= l) {
      printf("%d ", i + 1);
      u++;
      if (u == k) {
        break;
      }
    }
  }
}

fn solution() {
    let input = File::open("input.txt").unwrap();
    let mut output = File::create("output.txt").unwrap();

    let mut iter = io::BufReader::new(input).lines();

    let tmp: Vec<usize> = iter
        .next()
        .unwrap()
        .ok()
        .unwrap()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    let n = tmp[0];
    let k = tmp[1];

    let v: Vec<i32> = iter
        .next()
        .unwrap()
        .ok()
        .unwrap()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    let mut t: Vec<(usize, i32)> = v.into_iter().enumerate().collect();
    t.sort_by_key(|tuple| tuple.1);
    t = t.drain((n - k)..).collect();

    writeln!(output, "{}", t[0].1).unwrap();

    t.sort();
    let s: String = t
        .into_iter()
        .map(|(idx, _)| (idx + 1).to_string() + " ")
        .collect();

    writeln!(output, "{}", s.trim()).unwrap();
}


Score : <var>500</var> points

Problem Statement

There are <var>N</var> cards. The <var>i</var>-th card has an integer <var>A_i</var> written on it.
For any two cards, the integers on those cards are different.

Using these cards, Takahashi and Aoki will play the following game:

Aoki chooses an integer <var>x</var>.

Starting from Takahashi, the two players alternately take a card. The card should be chosen in the following manner:

Takahashi should take the card with the largest integer among the remaining card.

Aoki should take the card with the integer closest to <var>x</var> among the remaining card. If there are multiple such cards, he should take the card with the smallest integer among those cards.

The game ends when there is no card remaining.

You are given <var>Q</var> candidates for the value of <var>x</var>: <var>X_1, X_2, ..., X_Q</var>.
For each <var>i</var> (<var>1 \leq i \leq Q</var>), find the sum of the integers written on the cards that Takahashi will take if Aoki chooses <var>x = X_i</var>.

Constraints

<var>2 \leq N \leq 100</var> <var>000</var>

<var>1 \leq Q \leq 100</var> <var>000</var>

<var>1 \leq A_1 < A_2 < ... < A_N \leq 10^9</var>

<var>1 \leq X_i \leq 10^9</var> (<var>1 \leq i \leq Q</var>)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>Q</var>
<var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var>
<var>X_1</var>
<var>X_2</var>
<var>:</var>
<var>X_Q</var>

Output

Print <var>Q</var> lines. The <var>i</var>-th line (<var>1 \leq i \leq Q</var>) should contain the answer for <var>x = X_i</var>.

Sample Input 1

5 5
3 5 7 11 13
1
4
9
10
13

Sample Output 1

31
31
27
23
23

For example, when <var>x = X_3(= 9)</var>, the game proceeds as follows:

Takahashi takes the card with <var>13</var>.

Aoki takes the card with <var>7</var>.

Takahashi takes the card with <var>11</var>.

Aoki takes the card with <var>5</var>.

Takahashi takes the card with <var>3</var>.

Thus, <var>13 + 11 + 3 = 27</var> should be printed on the third line.

Sample Input 2

4 3
10 20 30 40
2
34
34

Sample Output 2

70
60
60

fn solution() {
    input! {
        n: usize,
        q: usize,
        a: [usize; n],
        xs: [usize; q]
    }
    let mut ac: Vec<usize> = vec![0; n + 1];
    for i in 0..n {
        ac[i + 1] = ac[i] + a[i];
    }
    let mut eo: Vec<usize> = vec![0; n];
    eo[0] = a[0];
    eo[1] = a[1];
    for i in 2..n {
        eo[i] = eo[i - 2] + a[i];
    }
    for i in 0..n {
        a[i] *= 3;
    }
    for i in 0..q {
        xs[i] = xs[i] * 3 - 1;
    }
    for i in 0..q {
        if xs[i] + 1 >= a[n - 1] {
            println!("{}", eo[n - 1]);
            continue;
        }
        let mut l = 0;
        let mut r = 3000000000;
        let mut li = 0;
        let mut ri = 0;
        while l + 1 < r {
            let m = (l + r) / 2;
            let lt = if xs[i] < a[0] + m {
                0
            } else {
                let mut l2 = -1;
                let mut r2 = n as i64 - 1;
                while l2 + 1 < r2 {
                    let m2 = (l2 + r2 + 1) / 2;
                    if a[m2 as usize] < xs[i] - m {
                        l2 = m2;
                    } else {
                        r2 = m2;
                    }
                }
                r2 as usize
            };
            let rt = {
                let mut l2 = 0;
                let mut r2 = n;
                while l2 + 1 < r2 {
                    let m2 = (l2 + r2) / 2;
                    if a[m2] <= xs[i] + m {
                        l2 = m2;
                    } else {
                        r2 = m2;
                    }
                }
                l2
            };
            if rt + 1 - lt <= n - 1 - rt {
                l = m;
                li = lt;
                ri = rt;
            } else {
                r = m;
            }
        }
        let mut ans = ac[n] - ac[ri + 1];
        if li > 0 && ri + 1 - li == n - 1 - ri {
            ans += eo[li - 1];
        } else if li > 1 && ri + 2 - li == n - 1 - ri {
            ans += eo[li - 2];
        }
        println!("{}", ans);
    }
}


Score : <var>300</var> points

Problem Statement

You have a pot and <var>N</var> ingredients. Each ingredient has a real number parameter called value, and the value of the <var>i</var>-th ingredient <var>(1 \leq i \leq N)</var> is <var>v_i</var>.

When you put two ingredients in the pot, they will vanish and result in the formation of a new ingredient. The value of the new ingredient will be <var>(x + y) / 2</var> where <var>x</var> and <var>y</var> are the values of the ingredients consumed, and you can put this ingredient again in the pot.

After you compose ingredients in this way <var>N-1</var> times, you will end up with one ingredient. Find the maximum possible value of this ingredient.

Constraints

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

<var>1 \leq v_i \leq 1000</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>v_1</var> <var>v_2</var> <var>\ldots</var> <var>v_N</var>

Output

Print a decimal number (or an integer) representing the maximum possible value of the last ingredient remaining.

Your output will be judged correct when its absolute or relative error from the judge's output is at most <var>10^{-5}</var>.

Sample Input 1

2
3 4

Sample Output 1

3.5

If you start with two ingredients, the only choice is to put both of them in the pot. The value of the ingredient resulting from the ingredients of values <var>3</var> and <var>4</var> is <var>(3 + 4) / 2 = 3.5</var>.

Printing 3.50001, 3.49999, and so on will also be accepted.

Sample Input 2

3
500 300 200

Sample Output 2

375

You start with three ingredients this time, and you can choose what to use in the first composition. There are three possible choices:

Use the ingredients of values <var>500</var> and <var>300</var> to produce an ingredient of value <var>(500 + 300) / 2 = 400</var>. The next composition will use this ingredient and the ingredient of value <var>200</var>, resulting in an ingredient of value <var>(400 + 200) / 2 = 300</var>.

Use the ingredients of values <var>500</var> and <var>200</var> to produce an ingredient of value <var>(500 + 200) / 2 = 350</var>. The next composition will use this ingredient and the ingredient of value <var>300</var>, resulting in an ingredient of value <var>(350 + 300) / 2 = 325</var>.

Use the ingredients of values <var>300</var> and <var>200</var> to produce an ingredient of value <var>(300 + 200) / 2 = 250</var>. The next composition will use this ingredient and the ingredient of value <var>500</var>, resulting in an ingredient of value <var>(250 + 500) / 2 = 375</var>.

Thus, the maximum possible value of the last ingredient remaining is <var>375</var>.

Printing 375.0 and so on will also be accepted.

Sample Input 3

5
138 138 138 138 138

Sample Output 3

138

int solution(void) {
  int n;
  scanf("%d", &n);

  double v[n];

  for (int i = 0; i < n; i++) {
    scanf("%lf", &v[i]);
  }

  for (int j = 0; j < n; j++) {
    double temp1 = 10000;
    double temp2 = 10000;
    int temp1pos = 0;
    int temp2pos = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] < temp1 && v[i] != (double)0) {
        temp2 = temp1;
        temp2pos = temp1pos;
        temp1 = v[i];
        temp1pos = i;
      } else if (v[i] < temp2 && v[i] != (double)0) {
        temp2 = v[i];
        temp2pos = i;
      }
    }
    if (temp2 == 10000) {
      break;
    }
    v[temp1pos] = (temp1 + temp2) / (double)2;
    v[temp2pos] = 0;
  }

  for (int i = 0; i < n; i++) {
    if (v[i] != 0) {
      printf("%lf\n", v[i]);
    }
  }
}

fn solution() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut v: Vec<f64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    v.sort_by(|a, b| a.partial_cmp(b).unwrap());
    println!("{}", v.iter().fold(v[0], |acc, &x| (acc + x) / 2.0));
}


Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars.

int solution() {
  int hx = 0;
  int hy = 0;
  int count = 0;
  int taxi[1002][5];
  double time[1002];
  scanf("%d %d\n%d\n", &hx, &hy, &count);
  for (int i = 0; i < count; i++) {
    scanf("%d %d %d\n", &taxi[i][0], &taxi[i][1], &taxi[i][2]);
  }
  for (int i = 0; i < count; i++) {
    int dx = 0;
    int dy = 0;
    double s = 0;
    if (taxi[i][0] > hx) {
      dx = taxi[i][0] - hx;
    } else {
      dx = hx - taxi[i][0];
    }
    if (taxi[i][1] > hy) {
      dy = taxi[i][1] - hy;
    } else {
      dy = hy - taxi[i][1];
    }
    s = sqrt(pow(dx, 2) + pow(dy, 2));
    time[i] = s / taxi[i][2];
  }
  double min = time[0];
  for (int i = 0; i < count; i++) {
    if (min > time[i]) {
      min = time[i];
    }
  }
  printf("%lf\n", min);
}

fn solution() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let line = lines.next();
    let temp: Vec<f32> = line
        .unwrap()
        .unwrap()
        .split_whitespace()
        .map(|x| x.parse::<f32>().unwrap())
        .collect();
    let x = temp[0];
    let y = temp[1];

    let line = lines.next();
    let taxin: u32 = line.unwrap().unwrap().parse().unwrap();

    let mut ans = std::f32::MAX;
    for _ in 0..taxin {
        let line = lines.next();
        let temp: Vec<f32> = line
            .unwrap()
            .unwrap()
            .split_whitespace()
            .map(|x| x.parse::<f32>().unwrap())
            .collect();

        let xt = temp[0];
        let yt = temp[1];
        let vt = temp[2];

        ans = ans.min(((xt - x).hypot(yt - y)) / vt);
    }
    println!("{:.7}", ans);
}


Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $$$d, m$$$, find the number of arrays $$$a$$$, satisfying the following constraints:  The length of $$$a$$$ is $$$n$$$, $$$n \ge 1$$$  $$$1 \le a_1 < a_2 < \dots < a_n \le d$$$  Define an array $$$b$$$ of length $$$n$$$ as follows: $$$b_1 = a_1$$$, $$$\forall i > 1, b_i = b_{i - 1} \oplus a_i$$$, where $$$\oplus$$$ is the bitwise exclusive-or (xor). After constructing an array $$$b$$$, the constraint $$$b_1 < b_2 < \dots < b_{n - 1} < b_n$$$ should hold. Since the number of possible arrays may be too large, you need to find the answer modulo $$$m$$$.

int solution() {
  int t;
  scanf("%d", &t);
  long long int d;
  long long int m;
  long long int v;
  long long int digit;
  long long int pow[40];
  long long int i;
  pow[0] = 1;
  for (i = 1; i < 40; i++) {
    pow[i] = pow[i - 1] * 2;
  }
  long long int ans;
  for (; t > 0; t--) {
    scanf("%lld %lld", &d, &m);
    v = d;
    digit = 0;
    while (v > 0) {
      digit++;
      v /= 2;
    }
    ans = 1;
    for (i = 1; i < digit; i++) {
      ans = ans * (pow[i - 1] + 1) % m;
    }
    ans = ans * (d - pow[digit - 1] + 2) % m;
    ans = (ans - 1 + m) % m;
    printf("%lld\n", ans);
  }
  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<u64> = lines
            .next()
            .unwrap()
            .unwrap()
            .split(' ')
            .map(|x| x.parse().unwrap())
            .collect();
        let (d, m) = (xs[0], xs[1]);
        let l = (64 - d.leading_zeros()) as usize;
        let mut ns: Vec<u64> = vec![0; l];
        ns[l - 1] = (d - 2_u64.pow(l as u32 - 1) + 1) % m;
        for i in (0..(l - 1)).rev() {
            let p = 2_u64.pow(i as u32);
            ns[i] = (p * (ns[i + 1] + 1) + ns[i + 1]) % m;
        }
        println!("{}", ns[0]);
    }
}


Andryusha is an orderly boy and likes to keep things in their place.Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?

int solution(void) {
  int n = 0;
  int i = 0;
  int sock = 0;
  int size = 0;
  int max = 0;
  int cnt[100001] = {
      0,
  };

  scanf("%d", &n);

  for (i = 0; i < n * 2; i++) {
    scanf("%d", &sock);
    if (cnt[sock]) {
      cnt[sock]--;
      size--;
    } else {
      cnt[sock]++;
      size++;
    }

    if (max < size) {
      max = size;
    }
  }

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

  return 0;
}

fn solution() {
    let stdin = std::io::stdin();
    let mut lines = stdin.lock().lines();
    let ct = str::parse(&lines.next().unwrap().unwrap()).unwrap();

    let mut seen = Vec::new();
    seen.resize(ct, false);
    let mut table = 0;

    let mut max = 0;
    for s in lines
        .next()
        .unwrap()
        .unwrap()
        .split_whitespace()
        .map(|w| str::parse::<usize>(w).unwrap())
    {
        let old: bool = seen[s - 1];
        seen[s - 1] = !old;
        if old {
            table -= 1;
        } else {
            table += 1;
            if table > max {
                max = table;
            }
        }
    }

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


Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own.  Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.

int solution(void) {
  int cnt = 0;
  int i = 0;
  int magnets[100000];
  int groups = 1;

  scanf("%d", &cnt);

  for (i = 0; i < cnt; i++) {
    scanf("%d", &magnets[i]);

    if (i > 0 && magnets[i] != magnets[i - 1]) {
      groups++;
    }
  }

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

  return 0;
}

fn solution() {
    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let mut n: i64 = n.trim().parse().unwrap();

    let mut total = 0;
    let mut last: String = "".to_string();

    while n > 0 {
        let mut x = String::new();
        stdin().read_line(&mut x).unwrap();
        let x = x.trim().to_string();
        if last != x {
            total += 1;
        }

        last = x;
        n -= 1;
    }

    println!("{}", if total > 0 { total } else { 1 });
}


Score : <var>300</var> points

Problem Statement

AtCoDeer the deer and his friend TopCoDeer is playing a game.
The game consists of <var>N</var> turns.
In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition:

(※) After each turn, (the number of times the player has played Paper)<var>≦</var>(the number of times the player has played Rock).

Each player's score is calculated by (the number of turns where the player wins) <var>-</var> (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.

(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)

With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the <var>N</var> turns, before the game starts.
Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.

The gesture that TopCoDeer will play in each turn is given by a string <var>s</var>. If the <var>i</var>-th <var>(1≦i≦N)</var> character in <var>s</var> is g, TopCoDeer will play Rock in the <var>i</var>-th turn. Similarly, if the <var>i</var>-th <var>(1≦i≦N)</var> character of <var>s</var> in p, TopCoDeer will play Paper in the <var>i</var>-th turn.

Constraints

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

<var>N=|s|</var>

Each character in <var>s</var> is g or p.

The gestures represented by <var>s</var> satisfy the condition (※).

Input

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

<var>s</var>

Output

Print the AtCoDeer's maximum possible score.

Sample Input 1

gpg

Sample Output 1

0

Playing the same gesture as the opponent in each turn results in the score of <var>0</var>, which is the maximum possible score.

Sample Input 2

ggppgggpgg

Sample Output 2

2

For example, consider playing gestures in the following order: Rock, Paper, Rock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three victories and suffers one defeat, resulting in the score of <var>2</var>, which is the maximum possible score.

fn solution() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s: Vec<char> = st.trim().chars().collect();
    let p: usize = s.iter().filter(|x| x.to_string() == "p").count();
    let n = s.len();
    println!("{}", n / 2 - p);
}


According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.  However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.Write a program that models the behavior of Ankh-Morpork residents.

fn solution() {
    use std::io;
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<u32>().unwrap();
    buf.clear();
    io::stdin().read_line(&mut buf).unwrap();
    let ns = buf
        .split_whitespace()
        .map(|str| str.trim().parse::<u32>().unwrap());

    let mut seen = vec![false; n as usize + 1];
    let mut waiting_for = n;
    for n in ns {
        seen[n as usize] = true;
        if n == waiting_for {
            for i in (0..n).rev().map(|x| x + 1) {
                if i != n {
                    print!(" ");
                }
                if seen[i as usize] {
                    print!("{}", i);
                } else {
                    waiting_for = i;
                    break;
                }
            }
        }
        println!();
    }
}


Selection of Participants of an Experiment

Dr. Tsukuba has devised a new method of programming training.
In order to evaluate the effectiveness of this method,
he plans to carry out a control experiment.
Having two students as the participants of the experiment,
one of them will be trained under the conventional method
and the other under his new method.
Comparing the final scores of these two,
he will be able to judge the effectiveness of his method.

It is important to select two students having the closest possible scores,
for making the comparison fair.
He has a list of the scores of all students
who can participate in the experiment.
You are asked to write a program which selects two of them
having the smallest difference in their scores.

Input

The input consists of multiple datasets, each in the following format.

n

a1 a2 … an

A dataset consists of two lines.
The number of students n is given in the first line.
n is an integer satisfying 2 ≤ n ≤ 1000.
The second line gives scores of n students.
ai (1 ≤ i ≤ n) is the score of the i-th student, which is a non-negative integer not greater than 1,000,000.

The end of the input is indicated by a line containing a zero.
The sum of n's of all the datasets does not exceed 50,000.

Output

For each dataset, select two students with the smallest difference in their scores,
and output in a line (the absolute value of) the difference.

Sample Input

5
10 10 10 10 10
5
1 5 8 9 11
7
11 34 83 47 59 29 70
0

Output for the Sample Input

0
1
5

int solution(void) {
  int N = 0;
  int ans[60000] = {0};

  int count = 0;
  while (1) {
    int sa = 10000000;
    int a[60000] = {0};
    scanf("%d", &N);
    if (N == 0) {
      break;
    }
    for (int i = 0; i < N; i++) {
      scanf("%d", &a[i]);
    }
    while (1) {
      int sw = 0;
      int temp = 0;
      for (int i = 0; i < N - 1; i++) {
        if (a[i] > a[i + 1]) {
          temp = a[i];
          a[i] = a[i + 1];
          a[i + 1] = temp;
          sw = 1;
        }
      }
      if (sw == 0) {
        break;
      }
    }
    for (int i = 0; i < N - 1; i++) {
      int tempsa = 0;
      tempsa = a[i] - a[i + 1];

      tempsa *= -1;
      if (tempsa < sa) {
        sa = tempsa;
      }
    }

    ans[count] = sa;
    count++;
  }

  for (int i = 0; i < count; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}

fn solution() {
    loop {
        let mut buf1 = String::new();
        io::stdin().read_line(&mut buf1).ok();
        let n: usize = buf1.trim().parse().unwrap();
        if n == 0 {
            return;
        }

        let mut buf2 = String::new();
        io::stdin().read_line(&mut buf2).ok();
        let mut a: Vec<_> = buf2
            .split_whitespace()
            .map(|n| u32::from_str(n).unwrap())
            .collect();

        a.sort();
        let mut ans = 1_000_001;
        for i in 0..a.len() - 1 {
            if a[i + 1] - a[i] < ans {
                ans = a[i + 1] - a[i];
            }
        }
        println!("{}", ans);
    }
}


Score : <var>200</var> points

Problem Statement

A string <var>S</var> of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied:

<var>S</var> is a palindrome.

Let <var>N</var> be the length of <var>S</var>. The string formed by the <var>1</var>-st through <var>((N-1)/2)</var>-th characters of <var>S</var> is a palindrome.

The string consisting of the <var>(N+3)/2</var>-st through <var>N</var>-th characters of <var>S</var> is a palindrome.

Determine whether <var>S</var> is a strong palindrome.

Constraints

<var>S</var> consists of lowercase English letters.

The length of <var>S</var> is an odd number between <var>3</var> and <var>99</var> (inclusive).

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

If <var>S</var> is a strong palindrome, print Yes;
otherwise, print No.

Sample Input 1

akasaka

Sample Output 1

Yes

<var>S</var> is akasaka.

The string formed by the <var>1</var>-st through the <var>3</var>-rd characters is aka.

The string formed by the <var>5</var>-th through the <var>7</var>-th characters is aka.
All of these are palindromes, so <var>S</var> is a strong palindrome.

Sample Input 2

level

Sample Output 2

No

Sample Input 3

atcoder

Sample Output 3

No

fn solution() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.split_whitespace();
    let s = itr.next().unwrap();

    let n = s.len();
    let t = s[0..n / 2].to_string();
    let u = s[n.div_ceil(2)..].to_string();

    let rs = s.chars().rev().collect::<String>();
    let rt = t.chars().rev().collect::<String>();
    let ru = u.chars().rev().collect::<String>();
    if s == rs && t == rt && u == ru {
        println!("Yes");
    } else {
        println!("No")
    }
}


Nezzar's favorite digit among $$$1,\ldots,9$$$ is $$$d$$$. He calls a positive integer lucky if $$$d$$$ occurs at least once in its decimal representation. Given $$$q$$$ integers $$$a_1,a_2,\ldots,a_q$$$, for each $$$1 \le i \le q$$$ Nezzar would like to know if $$$a_i$$$ can be equal to a sum of several (one or more) lucky numbers.

fn solution() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n: Vec<i64> = n.split_whitespace().map(|x| x.parse().unwrap()).collect();

    let n: i64 = n[0];
    for _ in 0..n {
        let mut line_1 = String::new();
        let mut line_2 = String::new();
        io::stdin().read_line(&mut line_1).unwrap();
        io::stdin().read_line(&mut line_2).unwrap();

        let line_1: Vec<i64> = line_1
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect();

        let d = line_1[1];
        let d_s = &format!("{}", d)[..];

        let nums: Vec<i64> = line_2
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect();

        let mut hash_set_yes: HashSet<i64> = HashSet::new();
        let mut hash_set_no: HashSet<i64> = HashSet::new();

        for origin_num in nums {
            let mut num = origin_num;
            loop {
                if hash_set_yes.get(&num).is_some() {
                    println!("{}", "YES");
                    break;
                }

                if hash_set_no.get(&num).is_some() {
                    println!("{}", "NO");
                    break;
                }

                let num_s = format!("{}", num);
                if num_s.contains(d_s) {
                    println!("{}", "YES");
                    hash_set_yes.insert(origin_num);
                    break;
                } else {
                    num -= d;
                    if num < 0 {
                        println!("{}", "NO");
                        hash_set_no.insert(origin_num);
                        break;
                    }
                    if num % 10 == 0 {
                        println!("{}", "YES");
                        hash_set_yes.insert(origin_num);
                        break;
                    }
                }
            }
        }
    }
}


Score : <var>300</var> points

Problem Statement

Snuke has a calculator. It has a display and two buttons.

Initially, the display shows an integer <var>x</var>.
Snuke wants to change this value into another integer <var>y</var>, by pressing the following two buttons some number of times in arbitrary order:

Button A: When pressed, the value on the display is incremented by <var>1</var>.

Button B: When pressed, the sign of the value on the display is reversed.

Find the minimum number of times Snuke needs to press the buttons to achieve his objective.
It can be shown that the objective is always achievable regardless of the values of the integers <var>x</var> and <var>y</var>.

Constraints

<var>x</var> and <var>y</var> are integers.

<var>|x|, |y| ≤ 10^9</var>

<var>x</var> and <var>y</var> are different.

Input

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

<var>x</var> <var>y</var>

Output

Print the minimum number of times Snuke needs to press the buttons to achieve his objective.

Sample Input 1

10 20

Sample Output 1

10

Press button A ten times.

Sample Input 2

10 -10

Sample Output 2

1

Press button B once.

Sample Input 3

-10 -20

Sample Output 3

12

Press the buttons as follows:

Press button B once.

Press button A ten times.

Press button B once.

fn solution() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let v: Vec<i64> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (x, y) = (v[0], v[1]);

    let ans: i64 = if x * y < 0 || x * y == 0 && x > y {
        (x + y).abs() + 1
    } else if x <= y {
        y - x
    } else {
        x - y + 2
    };
    println!("{}", ans);
}


Score : <var>500</var> points

Problem Statement

You are going to hold a competition of one-to-one game called AtCoder Janken. (Janken is the Japanese name for Rock-paper-scissors.)
<var>N</var> players will participate in this competition, and they are given distinct integers from <var>1</var> through <var>N</var>.
The arena has <var>M</var> playing fields for two players. You need to assign each playing field two distinct integers between <var>1</var> and <var>N</var> (inclusive).
You cannot assign the same integer to multiple playing fields.
The competition consists of <var>N</var> rounds, each of which proceeds as follows:

For each player, if there is a playing field that is assigned the player's integer, the player goes to that field and fight the other player who comes there.

Then, each player adds <var>1</var> to its integer. If it becomes <var>N+1</var>, change it to <var>1</var>.

You want to ensure that no player fights the same opponent more than once during the <var>N</var> rounds.
Print an assignment of integers to the playing fields satisfying this condition.
It can be proved that such an assignment always exists under the constraints given.

Constraints

<var>1 \leq M</var>

<var>M \times 2 +1 \leq N \leq 200000</var>

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>M</var>

Output

Print <var>M</var> lines in the format below.
The <var>i</var>-th line should contain the two integers <var>a_i</var> and <var>b_i</var> assigned to the <var>i</var>-th playing field.

<var>a_1</var> <var>b_1</var>
<var>a_2</var> <var>b_2</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>

Sample Input 1

4 1

Sample Output 1

2 3

Let us call the four players A, B, C, and D, and assume that they are initially given the integers <var>1</var>, <var>2</var>, <var>3</var>, and <var>4</var>, respectively.

The <var>1</var>-st round is fought by B and C, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>2</var>, <var>3</var>, <var>4</var>, and <var>1</var>, respectively.

The <var>2</var>-nd round is fought by A and B, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>3</var>, <var>4</var>, <var>1</var>, and <var>2</var>, respectively.

The <var>3</var>-rd round is fought by D and A, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>4</var>, <var>1</var>, <var>2</var>, and <var>3</var>, respectively.

The <var>4</var>-th round is fought by C and D, who has the integers <var>2</var> and <var>3</var>, respectively. After this round, A, B, C, and D have the integers <var>1</var>, <var>2</var>, <var>3</var>, and <var>4</var>, respectively.

No player fights the same opponent more than once during the four rounds, so this solution will be accepted.

Sample Input 2

7 3

Sample Output 2

1 6
2 5
3 4


You are given a set of all integers from $$$l$$$ to $$$r$$$ inclusive, $$$l < r$$$, $$$(r - l + 1) \le 3 \cdot 10^5$$$ and $$$(r - l)$$$ is always odd.You want to split these numbers into exactly $$$\frac{r - l + 1}{2}$$$ pairs in such a way that for each pair $$$(i, j)$$$ the greatest common divisor of $$$i$$$ and $$$j$$$ is equal to $$$1$$$. Each number should appear in exactly one of the pairs.Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.

int solution() {
  long long t = 1;

  while (t--) {
    long long l;
    long long r;
    scanf("%lld%lld", &l, &r);
    printf("YES\n");
    for (long long i = 0; i <= (r - l) / 2; i++) {
      printf("%lld %lld\n", l + (i * 2) + 1, l + (i * 2));
    }
  }
  return 0;
}

fn solution() -> io::Result<()> {
    let mut s = String::new();
    io::stdin().read_to_string(&mut s);
    let range: Vec<i64> = s
        .split_whitespace()
        .filter(|&s| !s.is_empty())
        .map(|s| s.parse::<i64>().unwrap())
        .collect();
    let start = range[0];
    let end = range[1] + 1;
    println!("YES");
    let mut flag = false;
    for x in start..end {
        flag = true;
        if (x - start) % 2 == 1 {
            continue;
        }
        println!("{} {}", x, x + 1);
    }
    if !flag {
        println!("range: {}, {}", start, end);
    }
    Ok(())
}


You are given $$$n$$$ of integers $$$a_1, a_2, \ldots, a_n$$$. Process $$$q$$$ queries of two types: query of the form "0 $$$x_j$$$": add the value $$$x_j$$$ to all even elements of the array $$$a$$$, query of the form "1 $$$x_j$$$": add the value $$$x_j$$$ to all odd elements of the array $$$a$$$.Note that when processing the query, we look specifically at the odd/even value of $$$a_i$$$, not its index.After processing each query, print the sum of the elements of the array $$$a$$$.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

int solution(void) {
  int t;
  scanf("%d", &t);
  while (t--) {
    static int n;
    static int q;
    static int cnt;
    static int type;
    static int x;
    static long long ans;
    cnt = 0;
    ans = 0;
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; ++i) {
      scanf("%d", &x);
      cnt += x & 1;

      ans += x;
    }

    for (int i = 0; i < q; ++i) {
      scanf("%d%d", &type, &x);
      ans += 1LL * x * (type ? cnt : n - cnt);
      if (x & 1) {
        if (type) {
          cnt = 0;
        } else {
          cnt = n;
        }
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}

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_q_str = line_iter.next().unwrap().unwrap();
        let (n_str, q_str) = n_q_str.split_once(' ').unwrap();
        let (_n, q) = (
            n_str.parse::<usize>().unwrap(),
            q_str.parse::<usize>().unwrap(),
        );
        let nums_str = line_iter.next().unwrap().unwrap();
        let nums_iter = nums_str
            .split(' ')
            .map(|num_str| num_str.parse::<u64>().unwrap());

        let mut total: u64 = 0;
        let mut odd_count: u64 = 0;
        let mut even_count: u64 = 0;

        for num in nums_iter {
            total += num;
            if num % 2 == 0 {
                even_count += 1;
            } else {
                odd_count += 1;
            }
        }

        let query_iter = (0..q).map(|_| {
            let query_line_str = line_iter.next().unwrap().unwrap();
            let (type_j_str, x_j_str) = query_line_str.split_once(' ').unwrap();
            (
                type_j_str.parse::<u64>().unwrap(),
                x_j_str.parse::<u64>().unwrap(),
            )
        });

        for query in query_iter {
            if query.0 == 0 {
                total += query.1 * even_count;

                if query.1 % 2 == 1 {
                    odd_count += even_count;
                    even_count = 0;
                }
            } else {
                total += query.1 * odd_count;

                if query.1 % 2 == 1 {
                    even_count += odd_count;
                    odd_count = 0;
                }
            }

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


Karlsson has recently discovered a huge stock of berry jam jars in the basement of the house. More specifically, there were $$$2n$$$ jars of strawberry and blueberry jam.All the $$$2n$$$ jars are arranged in a row. The stairs to the basement are exactly in the middle of that row. So when Karlsson enters the basement, he sees exactly $$$n$$$ jars to his left and $$$n$$$ jars to his right.For example, the basement might look like this:  Being the starightforward man he is, he immediately starts eating the jam. In one minute he chooses to empty either the first non-empty jar to his left or the first non-empty jar to his right.Finally, Karlsson decided that at the end the amount of full strawberry and blueberry jam jars should become the same.For example, this might be the result:  He has eaten $$$1$$$ jar to his left and then $$$5$$$ jars to his right. There remained exactly $$$3$$$ full jars of both strawberry and blueberry jam. Jars are numbered from $$$1$$$ to $$$2n$$$ from left to right, so Karlsson initially stands between jars $$$n$$$ and $$$n+1$$$.What is the minimum number of jars Karlsson is required to empty so that an equal number of full strawberry and blueberry jam jars is left?Your program should answer $$$t$$$ independent test cases.

fn solution() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut entries = buf.split_whitespace();
    let q: usize = entries.next().unwrap().parse().unwrap();
    for _ in 0..q {
        let n: usize = entries.next().unwrap().parse().unwrap();
        let mut sum = 0;
        let mut l: Vec<isize> = Vec::with_capacity(n);
        for _ in 0..n {
            let l_i: isize = entries.next().unwrap().parse().unwrap();
            let l_i = if l_i == 1 { 1 } else { -1 };
            sum += -l_i;
            l.push(l_i);
        }
        let mut l = l.into_iter().rev().collect::<Vec<_>>();
        let mut r: Vec<isize> = Vec::with_capacity(n);
        for _ in 0..n {
            let r_i: isize = entries.next().unwrap().parse().unwrap();
            let r_i = if r_i == 1 { 1 } else { -1 };
            sum += -r_i;
            r.push(r_i);
        }

        for i in 1..n {
            l[i] += l[i - 1];
            r[i] += r[i - 1];
        }

        if sum == 0 {
            println!("0");
            continue;
        }
        let mut l_ind = HashMap::new();
        for i in 0..n {
            l_ind.entry(l[i]).or_insert(i);
        }

        let mut min = if let Some(cost) = l_ind.get(&(-sum)) {
            *cost + 1
        } else {
            usize::max_value()
        };

        for i in 0..n {
            if r[i] == -sum {
                min = min.min(i + 1);
            }
            if let Some(cost) = l_ind.get(&(-(sum + r[i]))) {
                min = min.min(cost + 1 + i + 1)
            }
        }
        if min == usize::max_value() {
            min = 2 * n
        }
        println!("{}", min);
    }
}


Score : <var>100</var> points

Problem Statement

Given are three integers <var>A_1</var>, <var>A_2</var>, and <var>A_3</var>.

If <var>A_1+A_2+A_3</var> is greater than or equal to <var>22</var>, print bust; otherwise, print win.

Constraints

<var>1 \leq A_i \leq 13 \ \ (i=1,2,3)</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>A_1</var> <var>A_2</var> <var>A_3</var>

Output

If <var>A_1+A_2+A_3</var> is greater than or equal to <var>22</var>, print bust; otherwise, print win.

Sample Input 1

5 7 9

Sample Output 1

win

<var>5+7+9=21</var>, so print win.

Sample Input 2

13 7 2

Sample Output 2

bust

<var>13+7+2=22</var>, so print bust.

int solution(void) {
  int a = 0;
  int b = 0;
  int c = 0;
  scanf("%d %d %d", &a, &b, &c);
  if (a + b + c >= 22) {
    printf("bust");
  } else {
    printf("win");
  }
  return 0;
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).expect("read_line error");

    let mut parts = s.split_whitespace().map(|s| s.parse::<i32>());
    if let (Some(Ok(a)), Some(Ok(b)), Some(Ok(c))) = (parts.next(), parts.next(), parts.next()) {
        if a + b + c >= 22 {
            println!("bust")
        } else {
            println!("win")
        }
    }
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below:  $$$[1], [2], [3, 4, 5]$$$;  $$$[1], [2, 3], [4, 5]$$$;  $$$[1], [2, 3, 4], [5]$$$;  $$$[1, 2], [3], [4, 5]$$$;  $$$[1, 2], [3, 4], [5]$$$;  $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    int k;
    scanf("%d %d", &n, &k);
    int a[n];
    int b[n];
    int count = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      if (a[i] % 2 == 1) {
        b[count] = i;
        count++;
      }
    }
    if (count >= k && k % 2 == count % 2) {
      printf("YES\n");
      for (int j = 0; j < k - 1; j++) {
        printf("%d ", b[j] + 1);
      }
      printf("%d\n", n);
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

fn solution() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();

    let stdout = io::stdout();
    let mut out = io::BufWriter::with_capacity(2 * 1024 * 1024, stdout.lock());

    let q = input!(i32);
    for _ in 0..q {
        let (n, k) = input!(usize, usize);
        let a: Vec<_> = input!()
            .split_ascii_whitespace()
            .map(|w| w.parse::<i32>().unwrap())
            .collect();
        let b = a.iter().filter(|&x| x % 2 == 1).count();
        if b < k || (b - k) % 2 != 0 {
            writeln!(out, "NO").unwrap();
        } else {
            writeln!(out, "YES").unwrap();
            for (i, _) in a
                .iter()
                .enumerate()
                .filter(|&(_, x)| x % 2 == 1)
                .take(k - 1)
            {
                write!(out, "{} ", i + 1).unwrap();
            }
            writeln!(out, "{}", n).unwrap();
        }
    }
}


Score : <var>300</var> points

Problem Statement

Given is a positive integer <var>N</var>.
How many tuples <var>(A,B,C)</var> of positive integers satisfy <var>A \times B + C = N</var>?

Constraints

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print the answer.

Sample Input 1

3

Sample Output 1

3

There are <var>3</var> tuples of integers that satisfy <var>A \times B + C = 3</var>: <var>(A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 1)</var>.

Sample Input 2

100

Sample Output 2

473

Sample Input 3

1000000

Sample Output 3

13969985

int solution(void) {

  int n;
  int cnt = 1;
  int ans = 0;
  int flag = 0;

  scanf("%d", &n);

  for (int z = 1; z <= n - 1; z++) {
    flag = 0;
    cnt = 0;
    for (int i = 1; i <= sqrt(z); i++) {
      if (z % i == 0) {
        cnt++;
        if (z == i * i) {
          flag++;
        }
      }
    }
    cnt *= 2;
    if (flag) {
      cnt -= flag;
    }
    ans += cnt;
  }

  printf("%d", ans);

  return 0;
}

fn solution() {
    let mut s = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut s = s.split_whitespace();
    let n: i64 = s.next().unwrap().parse().unwrap();
    let mut d = vec![1; n as usize + 1];
    for i in 2..=n {
        for j in (i..=n).step_by(i as usize) {
            d[j as usize] += 1;
        }
    }
    let mut ans = 0i64;
    for c in 1..n {
        ans += d[(n - c) as usize];
    }
    println!("{}", ans);
}


Let's say you are standing on the $$$XY$$$-plane at point $$$(0, 0)$$$ and you want to reach point $$$(n, n)$$$.You can move only in two directions:   to the right, i. e. horizontally and in the direction that increase your $$$x$$$ coordinate,  or up, i. e. vertically and in the direction that increase your $$$y$$$ coordinate. In other words, your path will have the following structure:   initially, you choose to go to the right or up;  then you go some positive integer distance in the chosen direction (distances can be chosen independently);  after that you change your direction (from right to up, or from up to right) and repeat the process. You don't like to change your direction too much, so you will make no more than $$$n - 1$$$ direction changes.As a result, your path will be a polygonal chain from $$$(0, 0)$$$ to $$$(n, n)$$$, consisting of at most $$$n$$$ line segments where each segment has positive integer length and vertical and horizontal segments alternate.Not all paths are equal. You have $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ where $$$c_i$$$ is the cost of the $$$i$$$-th segment.Using these costs we can define the cost of the path as the sum of lengths of the segments of this path multiplied by their cost, i. e. if the path consists of $$$k$$$ segments ($$$k \le n$$$), then the cost of the path is equal to $$$\sum\limits_{i=1}^{k}{c_i \cdot length_i}$$$ (segments are numbered from $$$1$$$ to $$$k$$$ in the order they are in the path).Find the path of the minimum cost and print its cost.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    int k;
    scanf("%d", &n);
    long cost[n];
    for (int i = 0; i < n; i++) {
      scanf("%ld", &cost[i]);
    }

    long long minSum;
    long long minOdd = cost[0];
    long long minEve = cost[1];
    long long sumOdd = cost[0];
    long long sumEve = 0;
    long long countOdd;
    long long countEve;
    for (k = 2; k <= n; k++) {
      long long x = cost[k - 1];
      countOdd = (k + 1) / 2;
      countEve = k - countOdd;
      if (k & 1) {
        if (minOdd > x) {
          minOdd = x;
        }
        sumOdd += x;
      } else {
        if (minEve > x) {
          minEve = x;
        }
        sumEve += x;
      }

      sumOdd += minOdd * (n - countOdd);
      sumEve += minEve * (n - countEve);

      long long sum = sumOdd + sumEve;
      if (k == 2) {
        minSum = sum;
      }
      if (minSum > sum) {
        minSum = sum;
      }
      sumOdd -= minOdd * (n - countOdd);
      sumEve -= minEve * (n - countEve);
    }
    printf("%lld\n", minSum);
  }
}

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 = scan!(usize);

        let mut c = vec![0; n + 1];

        for i in 1..=n {
            c[i] = scan!(i64);
        }

        let mut odd_mn = 1000_000_000 + 5;
        let mut evn_mn = 1000_000_000 + 5;
        let mut odd_sum = 0;
        let mut evn_sum = 0;

        let mut ans = odd_mn * odd_mn;

        for i in 1..=n {
            if i & 1 == 1 {
                odd_mn = odd_mn.min(c[i]);
                odd_sum += c[i];
            } else {
                evn_mn = evn_mn.min(c[i]);
                evn_sum += c[i];
            }
            let j = i.div_ceil(2) as i64;
            let k = (i / 2) as i64;
            let n = n as i64;
            let ans_odd = (n - j) * odd_mn + odd_sum;
            let ans_evn = (n - k) * evn_mn + evn_sum;

            ans = ans.min(ans_evn + ans_odd);
        }
        print!("{}", ans);
        print!("\n");
    }
}


Mode Value

Your task is to write a program which reads a sequence of integers and prints mode values of the sequence.
The mode value is the element which occurs most frequently.

Input

A sequence of integers <var>ai</var> (1 ≤ <var>ai</var> ≤ 100). The number of integers is less than or equals to 100.

Output

Print the mode values. If there are several mode values, print them in ascending order.

Sample Input

5
6
3
5
8
7
5
3
9
7
3
4

Output for the Sample Input

3
5

For example, 3 and 5 respectively occur three times, 7 occurs two times, and others occur only one. So, the mode values are 3 and 5.

int solution(void) {
  int i = 1;
  int j = 0;
  int data[100];
  int max = 0;
  int count[100];

  for (j = 0; j < 100; j++) {
    data[j] = 0;
    count[j + 1] = 0;
  }

  while (scanf("%d", &data[i]) != EOF) {
    for (j = 1; j <= 100; j++) {
      if (j == data[i]) {
        count[j]++;
      }
    }
    i++;
  }
  max = count[1];
  for (i = 1; i <= 100; i++) {
    if (max < count[i]) {
      max = count[i];
    }
  }
  for (i = 1; i <= 100; i++) {
    if (max == count[i]) {
      printf("%d\n", i);
    }
  }
  return 0;
}

fn solution() {
    let ns = {
        let mut vec = Vec::new();
        let mut s = String::new();
        loop {
            s.clear();
            match std::io::stdin().read_line(&mut s) {
                Ok(0) => break,
                Ok(_) => vec.push(s.trim_end().parse::<i32>().unwrap()),
                Err(e) => println!("{}", e),
            }
        }
        vec
    };

    let mut map_count: BTreeMap<i32, usize> = BTreeMap::new();
    for n in ns {
        *map_count.entry(n).or_insert(0) += 1;
    }

    let max_value = map_count.values().max().unwrap();

    for (key, value) in &map_count {
        if value != max_value {
            continue;
        }
        println!("{}", key);
    }
}


Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.Tickets for group of x people are sold on the attraction, there should be at least one adult in each group (it is possible that the group consists of one adult). The ticket price for such group is c1 + c2·(x - 1)2 (in particular, if the group consists of one person, then the price is c1). All pupils who came to the park and their parents decided to split into groups in such a way that each visitor join exactly one group, and the total price of visiting the most extreme attraction is as low as possible. You are to determine this minimum possible total price. There should be at least one adult in each group.

int solution() {
  long long n;
  long long c1;
  long long c2;
  long long i;
  char s[200010];
  scanf("%lld%lld%lld", &n, &c1, &c2);
  scanf("%s", s);
  long long len = strlen(s);
  long long sum = 1e18;
  long long s1 = 0;
  for (i = 0; i < len; i++) {
    if (s[i] == '1') {
      s1++;
    }
  }
  long long a;
  long long b;
  for (i = 1; i <= s1; i++) {
    long long tmp = i * c1;
    tmp += (n % i) * (n / i) * (n / i) * c2 +
           (i - n % i) * (n / i - 1) * (n / i - 1) * c2;
    if (sum > tmp) {
      sum = tmp;
    }
  }
  printf("%lld\n", sum);
  return 0;
}

fn solution() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let tokens: Vec<&str> = line.split_whitespace().collect();
    let n: i32 = tokens[0].parse().unwrap();
    let c1: i64 = tokens[1].parse().unwrap();
    let c2: i64 = tokens[2].parse().unwrap();

    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut adults = 0;
    for c in s.chars() {
        if (c as u8) == b'1' {
            adults += 1
        }
    }

    let mut res: i64 = 1234567890123456789i64;
    for groups in 1..adults + 1 {
        let sml_var: i64 = ((n as i64) / groups) - 1;
        let sml_cnt: i64 = groups - (n as i64) % groups;
        let big_var: i64 = sml_var + 1;
        let big_cnt: i64 = (n as i64) % groups;
        let cur_res: i64 =
            c1 * groups + c2 * sml_cnt * sml_var * sml_var + c2 * big_cnt * big_var * big_var;
        if cur_res < res {
            res = cur_res;
        }
    }
    println!("{}", res);
}