Guy-Manuel and Thomas have an array $$$a$$$ of $$$n$$$ integers [$$$a_1, a_2, \dots, a_n$$$]. In one step they can add $$$1$$$ to any element of the array. Formally, in one step they can choose any integer index $$$i$$$ ($$$1 \le i \le n$$$) and do $$$a_i := a_i + 1$$$.If either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and Thomas do not mind to do this operation one more time.What is the minimum number of steps they need to do to make both the sum and the product of all elements in the array different from zero? Formally, find the minimum number of steps to make $$$a_1 + a_2 +$$$ $$$\dots$$$ $$$+ a_n \ne 0$$$ and $$$a_1 \cdot a_2 \cdot$$$ $$$\dots$$$ $$$\cdot a_n \ne 0$$$.

int solution() {
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    int t = 0;
    int n = 0;
    int c = 0;
    scanf("%d", &n);
    int a[n];
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[j]);
      t = t + a[j];
      if (a[j] == 0) {
        c++;
      }
    }
    int s = c;
    if (c + t == 0) {
      s++;
      printf("%d\n", s);
    } else {
      printf("%d\n", s);
    }
  }
}

fn solution() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let t: u32 = line.trim().parse().unwrap();
    for _ in 0..t {
        line = String::new();
        io::stdin().read_line(&mut line).unwrap();
        let _n: u32 = line.trim().parse().unwrap();
        let mut a = Vec::new();
        line = String::new();
        io::stdin().read_line(&mut line).unwrap();
        let pieces = line.split_whitespace();
        for v_str in pieces {
            let v: i32 = v_str.trim().parse().unwrap();
            a.push(v);
        }
        let mut count = a.iter().filter(|&&x| x == 0).count();
        a = a.iter().map(|&x| if x == 0 { 1 } else { x }).collect();
        let sum: i32 = a.iter().sum();
        if sum == 0 {
            a[0] += 1;
            count += 1;
        }

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


$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied:   All scores are integers  $$$0 \leq a_{i} \leq m$$$  The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied.

int solution() {
  int n;
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++) {
    int x1;
    int x2;
    scanf("%d %d\n", &x1, &x2);
    int arr[x1];
    for (int j = 0; j < x1; j++) {
      if (j != (x1 - 1)) {
        scanf("%d ", &arr[j]);
      } else {
        scanf("%d\n", &arr[j]);
      }
    }
    int sum = 0;
    for (int z = 0; z < x1; z++) {
      sum = sum + arr[z];
    }
    if (x1 == 1) {
      printf("%d\n", arr[0]);
    } else {
      if (sum >= x2) {
        printf("%d\n", x2);
      } else {
        printf("%d\n", sum);
      }
    }
  }
  return 0;
}

fn solution() {
    let mut t: String = String::new();
    std::io::stdin().read_line(&mut t).expect("input");
    let counter: Vec<i32> = t
        .split_whitespace()
        .map(|x| x.parse::<i32>().expect("Not an Integer!"))
        .collect();

    let mut test_case = counter[0];
    while test_case > 0 {
        let mut n_m = String::new();
        std::io::stdin().read_line(&mut n_m).expect("input");
        let nums: Vec<i32> = n_m
            .trim()
            .split(' ')
            .flat_map(str::parse::<i32>)
            .collect::<Vec<_>>();

        let mut list_value = String::new();
        std::io::stdin().read_line(&mut list_value).expect("input");
        let mut nums1: Vec<i32> = list_value
            .trim()
            .split(' ')
            .flat_map(str::parse::<i32>)
            .collect::<Vec<_>>();
        nums1.sort();

        let mut max: i32 = 0;

        if nums1[0] != nums[1] {
            max = nums1[0];
            nums1.remove(0);
            let mut total: i32 = 0;
            for num in nums1 {
                total += num;
            }
            while max != nums[1] && total != 0 {
                max += 1;
                total -= 1;
            }
            println!("{}", max);
        } else {
            println!("{}", nums1[0]);
        }

        test_case -= 1;
    }
}


Score : <var>300</var> points

Problem Statement

There are <var>N</var> balls in a two-dimensional plane. The <var>i</var>-th ball is at coordinates <var>(x_i, y_i)</var>.

We will collect all of these balls, by choosing two integers <var>p</var> and <var>q</var> such that <var>p \neq 0</var> or <var>q \neq 0</var> and then repeating the following operation:

Choose a ball remaining in the plane and collect it. Let <var>(a, b)</var> be the coordinates of this ball. If we collected a ball at coordinates <var>(a - p, b - q)</var> in the previous operation, the cost of this operation is <var>0</var>. Otherwise, including when this is the first time to do this operation, the cost of this operation is <var>1</var>.

Find the minimum total cost required to collect all the balls when we optimally choose <var>p</var> and <var>q</var>.

Constraints

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

<var>|x_i|, |y_i| \leq 10^9</var>

If <var>i \neq j</var>, <var>x_i \neq x_j</var> or <var>y_i \neq y_j</var>.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>x_1</var> <var>y_1</var>
<var>:</var>
<var>x_N</var> <var>y_N</var>

Output

Print the minimum total cost required to collect all the balls.

Sample Input 1

2
1 1
2 2

Sample Output 1

1

If we choose <var>p = 1, q = 1</var>, we can collect all the balls at a cost of <var>1</var> by collecting them in the order <var>(1, 1)</var>, <var>(2, 2)</var>.

Sample Input 2

3
1 4
4 6
7 8

Sample Output 2

1

If we choose <var>p = -3, q = -2</var>, we can collect all the balls at a cost of <var>1</var> by collecting them in the order <var>(7, 8)</var>, <var>(4, 6)</var>, <var>(1, 4)</var>.

Sample Input 3

4
1 1
1 2
2 1
2 2

Sample Output 3

2

int solution() {
  int n;
  scanf("%d", &n);
  int x[n];
  int y[n];
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x[i], &y[i]);
  }
  int max = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) {
        int p = x[j] - x[i];
        int q = y[j] - y[i];
        int cnt = 0;
        for (int s = 0; s < n; s++) {
          for (int t = 0; t < n; t++) {
            if ((x[s] + p == x[t]) && (y[s] + q == y[t])) {
              cnt++;
            }
          }
        }
        if (cnt > max) {
          max = cnt;
        }
      }
    }
  }
  printf("%d\n", n - max);
  return 0;
}

fn solution() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            (
                itr.next().unwrap().parse().unwrap(),
                itr.next().unwrap().parse().unwrap(),
            )
        })
        .collect();

    let mut ans = n;
    for i in 0..n {
        for j in 0..n {
            if i == j {
                continue;
            }
            let p = a[j].0 - a[i].0;
            let q = a[j].1 - a[i].1;

            let mut cnt = 0;
            for k in 0..n {
                for l in 0..n {
                    if k == l {
                        continue;
                    }
                    let r = a[l].0 - a[k].0;
                    let s = a[l].1 - a[k].1;
                    if p == r && q == s {
                        cnt += 1;
                    }
                }
            }
            ans = min(ans, n - cnt);
        }
    }
    println!("{}", ans);
}


Score : <var>200</var> points

Problem Statement

Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate <var>A</var>, and he can travel the distance of <var>V</var> per second.
The other child is now at coordinate <var>B</var>, and she can travel the distance of <var>W</var> per second.

He can catch her when his coordinate is the same as hers.
Determine whether he can catch her within <var>T</var> seconds (including exactly <var>T</var> seconds later).
We assume that both children move optimally.

Constraints

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

<var>1 \leq V,W \leq 10^9</var>

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

<var>A \neq B</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>A</var> <var>V</var>
<var>B</var> <var>W</var>
<var>T</var>

Output

If "it" can catch the other child, print YES; otherwise, print NO.

Sample Input 1

1 2
3 1
3

Sample Output 1

YES

Sample Input 2

1 2
3 2
3

Sample Output 2

NO

Sample Input 3

1 2
3 3
3

Sample Output 3

NO

int solution(void) {
  long long int a;
  long long int b;
  long long int v;
  long long int w;
  long long int t;

  scanf("%lld %lld %lld %lld %lld", &a, &v, &b, &w, &t);

  if (a < b) {
    if (a + v * t >= b + w * t) {
      printf("YES");
    } else {
      printf("NO");
    }
  } else {
    if (a + v * t * -1 <= b + w * t * -1 && b < a) {
      printf("YES");
    } else {
      printf("NO");
    }
  }

  return 0;
}

fn solution() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse::<i64>().unwrap());
    let a = itr.next().unwrap();
    let v = itr.next().unwrap();
    is.clear();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse::<i64>().unwrap());
    let b = itr.next().unwrap();
    let w = itr.next().unwrap();
    is.clear();
    stdin().read_line(&mut is).ok();
    let t: i64 = is.trim().parse().unwrap();
    let d = (a - b).abs();

    println!("{}", if v * t >= w * t + d { "YES" } else { "NO" });
}


Score : <var>500</var> points

Problem Statement

Snuke has two boards, each divided into a grid with <var>N</var> rows and <var>N</var> columns.
For both of these boards, the square at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is called Square <var>(i,j)</var>.

There is a lowercase English letter written in each square on the first board. The letter written in Square <var>(i,j)</var> is <var>S_{i,j}</var>. On the second board, nothing is written yet.

Snuke will write letters on the second board, as follows:

First, choose two integers <var>A</var> and <var>B</var> ( <var>0 \leq A, B < N</var> ).

Write one letter in each square on the second board.
Specifically, write the letter written in Square <var>( i+A, j+B )</var> on the first board into Square <var>(i,j)</var> on the second board.
Here, the <var>k</var>-th row is also represented as the <var>(N+k)</var>-th row, and the <var>k</var>-th column is also represented as the <var>(N+k)</var>-th column.

After this operation, the second board is called a good board when, for every <var>i</var> and <var>j</var> ( <var>1 \leq i, j \leq N</var> ), the letter in Square <var>(i,j)</var> and the letter in Square <var>(j,i)</var> are equal.

Find the number of the ways to choose integers <var>A</var> and <var>B</var> ( <var>0 \leq A, B < N</var> ) such that the second board is a good board.

Constraints

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

<var>S_{i,j}</var> ( <var>1 \leq i, j \leq N</var> ) is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>S_{1,1}S_{1,2}..S_{1,N}</var>
<var>S_{2,1}S_{2,2}..S_{2,N}</var>
<var>:</var>
<var>S_{N,1}S_{N,2}..S_{N,N}</var>

Output

Print the number of the ways to choose integers <var>A</var> and <var>B</var> ( <var>0 \leq A, B < N</var> ) such that the second board is a good board.

Sample Input 1

2
ab
ca

Sample Output 1

2

For each pair of <var>A</var> and <var>B</var>, the second board will look as shown below:

The second board is a good board when <var>(A,B) = (0,1)</var> or <var>(A,B) = (1,0)</var>, thus the answer is <var>2</var>.

Sample Input 2

4
aaaa
aaaa
aaaa
aaaa

Sample Output 2

16

Every possible choice of <var>A</var> and <var>B</var> makes the second board good.

Sample Input 3

5
abcde
fghij
klmno
pqrst
uvwxy

Sample Output 3

0

No possible choice of <var>A</var> and <var>B</var> makes the second board good.

int solution() {
  int N;
  scanf("%d", &N);
  char S[N][N];
  for (int i = 0; i < N; i++) {
    scanf(" %s ", S[i]);
  }

  int num = 0;
  for (int k = 0; k < N; k++) {
    int symmetry = 1;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (S[(i + k) % N][j] != S[(j + k) % N][i]) {
          symmetry = 0;
        }
      }
    }

    if (symmetry) {
      num += N;
    }
  }

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

  return 0;
}

fn solution() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let g: Vec<Vec<char>> = (0..n)
        .map(|_| itr.next().unwrap().chars().collect())
        .collect();

    let mut ans = 0;
    for i in 0..n {
        let mut ok = true;
        for j in 0..n {
            for k in 0..n {
                if g[j][(i + k) % n] != g[k][(i + j) % n] {
                    ok = false;
                    break;
                }
            }
            if !ok {
                break;
            }
        }
        if ok {
            ans += n;
        }
    }
    println!("{}", ans);
}


Score : <var>300</var> points

Problem Statement

You are playing the following game with Joisino.

Initially, you have a blank sheet of paper.

Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated <var>N</var> times.

Then, you are asked a question: How many numbers are written on the sheet now?

The numbers announced by Joisino are given as <var>A_1, ... ,A_N</var> in the order she announces them. How many numbers will be written on the sheet at the end of the game?

Constraints

<var>1≤N≤100000</var>

<var>1≤A_i≤1000000000(=10^9)</var>

All input values are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>A_1</var>
<var>:</var>
<var>A_N</var>

Output

Print how many numbers will be written on the sheet at the end of the game.

Sample Input 1

3
6
2
6

Sample Output 1

1

The game proceeds as follows:

<var>6</var> is not written on the sheet, so write <var>6</var>.

<var>2</var> is not written on the sheet, so write <var>2</var>.

<var>6</var> is written on the sheet, so erase <var>6</var>.

Thus, the sheet contains only <var>2</var> in the end. The answer is <var>1</var>.

Sample Input 2

4
2
5
5
2

Sample Output 2

0

It is possible that no number is written on the sheet in the end.

Sample Input 3

6
12
22
16
22
18
12

Sample Output 3

2

int solution() {
  int N;
  scanf("%d", &N);
  int ans = N;
  int A[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    int j = i - 1;
    while (A[i] != A[j] && j >= 0) {
      j--;
    }
    if (j < 0) {
      continue;
    }
    A[j] = 0;
    A[i] = 0;
    ans -= 2;
  }

  printf("%d", ans);

  return 0;
}

fn solution() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    for _ in stdin
        .by_ref()
        .bytes()
        .take_while(|r| r.as_ref().unwrap() != &b'\n')
    {}

    let mut set = HashSet::with_capacity(100_000);
    for a in stdin.lines() {
        let a: u32 = a.unwrap().parse().unwrap();
        if !set.remove(&a) {
            set.insert(a);
        }
    }

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


You are given an array $$$a$$$ consisting of $$$n$$$ integers.In one move, you can choose two indices $$$1 \le i, j \le n$$$ such that $$$i \ne j$$$ and set $$$a_i := a_j$$$. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose $$$i$$$ and $$$j$$$ and replace $$$a_i$$$ with $$$a_j$$$).Your task is to say if it is possible to obtain an array with an odd (not divisible by $$$2$$$) sum of elements.You have to answer $$$t$$$ independent test cases.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    int count = 0;
    int temp = 0;
    scanf("%d", &n);
    int arr[n];
    for (int i = 0; i < n; i++) {
      scanf("%d", &arr[i]);
      count += arr[i];
      if (arr[i] % 2 == 1) {
        temp++;
      }
    }
    if (temp != 0) {
      if (n % 2 == 0 && (arr[0] * n == count || temp == n)) {
        printf("NO\n");
      } else {
        printf("YES\n");
      }
    }

    else {
      printf("NO\n");
    }
  }
}

fn solution() -> Result<(), Box<dyn std::error::Error>> {
    let stdin = io::stdin();
    let mut stdin = stdin.lock().lines();
    let _ = stdin.next();
    for line in stdin
        .map(|e| e.unwrap())
        .collect::<Vec<String>>()
        .chunks(2)
        .map(|a| {
            let (cnt, (odd_sum, odd_numbers)) = (
                a[0].parse::<u32>().unwrap(),
                a[1].split(' ').map(|e| e.parse::<u32>().unwrap()).fold(
                    (false, 0),
                    |(odd_sum, odd_numbers), elem| {
                        (
                            odd_sum ^ (elem.rem_euclid(2) == 1),
                            odd_numbers + elem.rem_euclid(2),
                        )
                    },
                ),
            );
            odd_sum || (cnt > odd_numbers && odd_numbers > 0)
        })
        .map(|res| match res {
            true => "YES",
            false => "NO",
        })
    {
        println!("{}", line);
    }
    Ok(())
}


Sum of 4 Integers

Write a program which reads an integer <var>n</var>  and identifies the number of combinations of <var>a, b, c</var> and <var>d</var> (0 ≤ <var>a, b, c, d</var> ≤ 9) which meet the following equality:

<var>a + b + c + d = n</var>

For example, for <var>n</var> = 35, we have 4 different combinations of (<var>a, b, c, d</var>): (<var>8, 9, 9, 9</var>), (<var>9, 8, 9, 9</var>), (<var>9, 9, 8, 9</var>), and (<var>9, 9, 9, 8</var>).

Input

The input consists of several datasets. Each dataset consists of <var>n</var> (1 ≤ <var>n</var> ≤ 50) in a line. The number of datasets is less than or equal to 50.

Output

Print the number of combination in a line.

Sample Input

35
1

Output for the Sample Input

4
4

int solution() {
  int No1 = 0;
  int No2 = 0;
  int No3 = 0;
  int No4 = 0;
  int Solns = 0;
  int Sum = 0;

  while (scanf("%d", &Sum) != EOF) {
    Solns = 0;
    for (No1 = 0; No1 < 10; No1++) {
      for (No2 = 0; No2 < 10; No2++) {
        for (No3 = 0; No3 < 10; No3++) {
          for (No4 = 0; No4 < 10; No4++) {
            if (No1 + No2 + No3 + No4 == Sum) {
              Solns++;
            }
          }
        }
      }
    }
    printf("%d\n", Solns);
  }
  return 0;
}

fn solution() {
    let mut input;
    loop {
        input = String::new();
        match std::io::stdin().read_line(&mut input) {
            Ok(0) => break,
            Err(_) => break,
            Ok(_) => {}
        };
        let n = input.trim().parse::<u32>().expect("Error parse");
        let mut count = 0;
        for i in 0..10 {
            for j in 0..10 {
                for k in 0..10 {
                    for l in 0..10 {
                        if i + j + k + l == n {
                            count += 1;
                        }
                    }
                }
            }
        }
        println!("{}", count);
    }
}


You have decided to watch the best moments of some movie. There are two buttons on your player:   Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie.  Skip exactly x minutes of the movie (x is some fixed positive integer). If the player is now at the t-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t + x). Initially the movie is turned on in the player on the first minute, and you want to watch exactly n best moments of the movie, the i-th best moment starts at the li-th minute and ends at the ri-th minute (more formally, the i-th best moment consists of minutes: li, li + 1, ..., ri). Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?

int solution() {
  int n = 0;
  int x = 0;
  int i = 0;
  int current = 1;
  int min = 0;
  scanf("%d %d", &n, &x);
  int moments[n][2];
  for (i = 0; i < n; i++) {
    scanf("%d %d", &moments[n][0], &moments[n][1]);
    min += moments[n][1] - (((moments[n][0] - current) / x) * x + current) + 1;
    current = moments[n][1] + 1;
  }
  printf("%d", min);
}

fn solution() {
    let v: Vec<i32> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim()
            .split(" ")
            .map(|s| s.parse::<i32>().unwrap())
            .collect()
    };
    let n = v[0];
    let x = v[1];
    let mut v = vec![];
    for _i in 0..n {
        let tmp: Vec<i32> = {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim()
                .split(" ")
                .map(|s| s.parse::<i32>().unwrap())
                .collect()
        };
        v.push(tmp)
    }

    let (_, total) = v.iter().fold((1, 0), |(prev, total), item| {
        let remain = (item[0] - prev) % x;
        (item[1] + 1, item[1] - item[0] + 1 + remain + total)
    });
    println!("{:?}", total);
}


Score : <var>100</var> points

Problem Statement

Given is an integer <var>x</var> that is greater than or equal to <var>0</var>, and less than or equal to <var>1</var>.
Output <var>1</var> if <var>x</var> is equal to <var>0</var>, or <var>0</var> if <var>x</var> is equal to <var>1</var>.

Constraints

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

<var>x</var> is an integer

Input

Input is given from Standard Input in the following format:

<var>x</var>

Output

Print <var>1</var> if <var>x</var> is equal to <var>0</var>, or <var>0</var> if <var>x</var> is equal to <var>1</var>.

Sample Input 1

1

Sample Output 1

0

Sample Input 2

0

Sample Output 2

1

int solution() {
  int x = 0;
  scanf("%d", &x);
  if (x == 1) {
    printf("0");
  } else {
    printf("1");
  }
}

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

    io::stdin()
        .read_line(&mut no)
        .expect("failed to read line ");

    let no: i32 = no.trim().parse().expect("error!");

    if no == 0 {
        println!("1");
    } else if no == 1 {
        println!("0");
    } else {
        println!("...");
    }
}


Score : <var>200</var> points

Problem Statement

You are given strings <var>s</var> and <var>t</var>, consisting of lowercase English letters.
You will create a string <var>s'</var> by freely rearranging the characters in <var>s</var>.
You will also create a string <var>t'</var> by freely rearranging the characters in <var>t</var>.
Determine whether it is possible to satisfy <var>s' < t'</var> for the lexicographic order.

Notes

For a string <var>a = a_1 a_2 ... a_N</var> of length <var>N</var> and a string <var>b = b_1 b_2 ... b_M</var> of length <var>M</var>, we say <var>a < b</var> for the lexicographic order if either one of the following two conditions holds true:

<var>N < M</var> and <var>a_1 = b_1</var>, <var>a_2 = b_2</var>, ..., <var>a_N = b_N</var>.

There exists <var>i</var> (<var>1 \leq i \leq N, M</var>) such that <var>a_1 = b_1</var>, <var>a_2 = b_2</var>, ..., <var>a_{i - 1} = b_{i - 1}</var> and <var>a_i < b_i</var>. Here, letters are compared using alphabetical order.

For example, xy <var><</var> xya and atcoder <var><</var> atlas.

Constraints

The lengths of <var>s</var> and <var>t</var> are between <var>1</var> and <var>100</var> (inclusive).

<var>s</var> and <var>t</var> consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

<var>s</var>
<var>t</var>

Output

If it is possible to satisfy <var>s' < t'</var>, print Yes; if it is not, print No.

Sample Input 1

yx
axy

Sample Output 1

Yes

We can, for example, rearrange yx into xy and axy into yxa. Then, xy <var><</var> yxa.

Sample Input 2

ratcode
atlas

Sample Output 2

Yes

We can, for example, rearrange ratcode into acdeort and atlas into tslaa. Then, acdeort <var><</var> tslaa.

Sample Input 3

cd
abc

Sample Output 3

No

No matter how we rearrange cd and abc, we cannot achieve our objective.

Sample Input 4

w
ww

Sample Output 4

Yes

Sample Input 5

zzz
zzz

Sample Output 5

No

fn solution() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();

    let s = get().as_bytes();
    let t = get().as_bytes();

    let mut ss = vec![0; 256];
    let mut tt = vec![0; 256];

    for &c in s.iter() {
        ss[c as usize] += 1;
    }
    for &c in t.iter() {
        tt[c as usize] += 1;
    }

    let mut sx = vec![];
    let mut tx = vec![];

    for i in 0..256 {
        for _ in 0..ss[i] {
            sx.push(i);
        }
        for _ in 0..tt[255 - i] {
            tx.push(255 - i);
        }
    }

    for i in 0..std::cmp::min(sx.len(), tx.len()) {
        if sx[i] < tx[i] {
            println!("Yes");
            return;
        } else if sx[i] > tx[i] {
            println!("No");
            return;
        }
    }
    if sx.len() < tx.len() {
        println!("Yes");
    } else {
        println!("No");
    }
}


Score : <var>100</var> points

Problem Statement

You are given three integers, <var>A</var>, <var>B</var> and <var>C</var>.

Among them, two are the same, but the remaining one is different from the rest.

For example, when <var>A=5,B=7,C=5</var>, <var>A</var> and <var>C</var> are the same, but <var>B</var> is different.

Find the one that is different from the rest among the given three integers.

Constraints

<var>-100 \leq A,B,C \leq 100</var>

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

The input satisfies the condition in the statement.

Input

Input is given from Standard Input in the following format:

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

Output

Among <var>A</var>, <var>B</var> and <var>C</var>, print the integer that is different from the rest.

Sample Input 1

5 7 5

Sample Output 1

7

This is the same case as the one in the statement.

Sample Input 2

1 1 7

Sample Output 2

7

In this case, <var>C</var> is the one we seek.

Sample Input 3

-100 100 100

Sample Output 3

-100

int solution() {
  int A = 0;
  int B = 0;
  int C = 0;
  scanf("%d %d %d", &A, &B, &C);
  if (A == B) {
    printf("%d", C);
  } else if (B == C) {
    printf("%d", A);
  } else if (A == C) {
    printf("%d", B);
  }
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let vec: Vec<&str> = s.trim().split(' ').collect();
    if vec[0] == vec[1] {
        println!("{}", vec[2]);
    } else if vec[1] == vec[2] {
        println!("{}", vec[0]);
    } else if vec[0] == vec[2] {
        println!("{}", vec[1]);
    }
}


Score : <var>500</var> points

Problem Statement

We have a two-dimensional grid with <var>H \times W</var> squares. There are <var>M</var> targets to destroy in this grid - the position of the <var>i</var>-th target is <var>\left(h_i, w_i \right)</var>.

Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.

Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.

Constraints

All values in input are integers.

<var>1 \leq H, W \leq 3 \times 10^5</var>

<var>1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right)</var>

<var>1 \leq h_i \leq H</var>

<var>1 \leq w_i \leq W</var>

<var>\left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right)</var>

Input

Input is given from Standard Input in the following format:

<var>H</var> <var>W</var> <var>M</var>
<var>h_1</var> <var>w_1</var>
<var>\vdots</var>
<var>h_M</var> <var>w_M</var>

Output

Print the answer.

Sample Input 1

2 3 3
2 2
1 1
1 3

Sample Output 1

3

We can destroy all the targets by placing the bomb at <var>\left(1, 2\right)</var>.

Sample Input 2

3 3 4
3 3
3 1
1 1
1 2

Sample Output 2

3

Sample Input 3

5 5 10
2 5
4 3
2 3
5 5
2 2
5 4
5 3
5 1
3 5
1 4

Sample Output 3

6

int solution() {
  int H;
  int W;
  int m;
  int hmax = 0;
  int wmax = 0;

  scanf("%d %d %d", &H, &W, &m);

  int hbomb[H + 1];
  int h[m + 1];
  int wbomb[W + 1];
  int w[m + 1];

  for (int i = 1; i <= H; i++) {
    hbomb[i] = 0;
  }

  for (int i = 1; i <= W; i++) {
    wbomb[i] = 0;
  }

  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &h[i], &w[i]);
    hbomb[h[i]] += 1;
    wbomb[w[i]] += 1;
  }

  for (int i = 1; i <= H; i++) {
    if (hmax < hbomb[i]) {
      hmax = hbomb[i];
    }
  }

  for (int i = 1; i <= W; i++) {
    if (wmax < wbomb[i]) {
      wmax = wbomb[i];
    }
  }

  int hbox[H + 1];
  int wbox[W + 1];
  int hcount = 0;
  int wcount = 0;
  int count = 0;

  for (int i = 1; i <= H; i++) {
    if (hbomb[i] == hmax) {
      hbox[i] = 1;
      hcount += 1;
    } else {
      hbox[i] = 0;
    }
  }

  for (int i = 1; i <= W; i++) {
    if (wbomb[i] == wmax) {
      wbox[i] = 1;
      wcount += 1;
    } else {
      wbox[i] = 0;
    }
  }

  for (int i = 1; i <= m; i++) {
    if (hbox[h[i]] == 1 && wbox[w[i]] == 1) {
      count += 1;
    }
  }

  if (count == hcount * wcount) {
    printf("%d", hmax + wmax - 1);
    return 0;
  }
  printf("%d", hmax + wmax);
  return 0;
}

fn solution() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let h = it.next().unwrap().parse::<usize>().unwrap();
    let w = it.next().unwrap().parse::<usize>().unwrap();
    let m = it.next().unwrap().parse::<usize>().unwrap();
    let b = (0..m)
        .map(|_| {
            (
                it.next().unwrap().parse::<usize>().unwrap(),
                it.next().unwrap().parse::<usize>().unwrap(),
            )
        })
        .collect::<Vec<_>>();
    let mut cnt_h = vec![0; h + 1];
    let mut cnt_w = vec![0; w + 1];
    for &p in &b {
        cnt_h[p.0] += 1;
        cnt_w[p.1] += 1;
    }
    let max_h = *cnt_h.iter().max().unwrap();
    let max_w = *cnt_w.iter().max().unwrap();
    let overlap = cnt_h
        .iter()
        .fold(0, |a, &x| a + if x == max_h { 1 } else { 0 })
        * cnt_w
            .iter()
            .fold(0, |a, &x| a + if x == max_w { 1 } else { 0 });
    let cover = b.iter().fold(0, |a, &(x, y)| {
        a + if cnt_h[x] == max_h && cnt_w[y] == max_w {
            1
        } else {
            0
        }
    });
    println!("{}", max_h + max_w - if cover == overlap { 1 } else { 0 });
}


Score : <var>100</var> points

Problem Statement

Rng is going to a festival.

The name of the festival is given to you as a string <var>S</var>, which ends with FESTIVAL, from input. Answer the question: "Rng is going to a festival of what?" Output the answer.

Here, assume that the name of "a festival of <var>s</var>" is a string obtained by appending FESTIVAL to the end of <var>s</var>.
For example, CODEFESTIVAL is a festival of CODE.

Constraints

<var>9 \leq |S| \leq 50</var>

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

<var>S</var> ends with FESTIVAL.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

Print the answer to the question: "Rng is going to a festival of what?"

Sample Input 1

CODEFESTIVAL

Sample Output 1

CODE

This is the same as the example in the statement.

Sample Input 2

CODEFESTIVALFESTIVAL

Sample Output 2

CODEFESTIVAL

This string is obtained by appending FESTIVAL to the end of CODEFESTIVAL, so it is a festival of CODEFESTIVAL.

Sample Input 3

YAKINIKUFESTIVAL

Sample Output 3

YAKINIKU

int solution() {
  char s[99];
  scanf("%s", s);
  int n = strlen(s);
  s[n - 8] = 0;
  puts(s);
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    println!("{}", s.chars().take(s.len() - 9).collect::<String>());
}


Problem Statement

You are given two integers <var>a</var> and <var>b</var> (<var>a≤b</var>). Determine if the product of the integers <var>a</var>, <var>a+1</var>, <var>…</var>, <var>b</var> is positive, negative or zero.

Constraints

<var>a</var> and <var>b</var> are integers.

<var>-10^9≤a≤b≤10^9</var>

Partial Score

In test cases worth <var>100</var> points, <var>-10≤a≤b≤10</var>.

Input

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

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

Output

If the product is positive, print Positive. If it is negative, print Negative. If it is zero, print Zero.

Sample Input 1

1 3

Sample Output 1

Positive

<var>1×2×3=6</var> is positive.

Sample Input 2

-3 -1

Sample Output 2

Negative

<var>(-3)×(-2)×(-1)=-6</var> is negative.

Sample Input 3

-1 1

Sample Output 3

Zero

<var>(-1)×0×1=0</var>.

int solution(void) {

  long long int a;
  long long int b;

  scanf("%lld", &a);
  scanf("%lld", &b);

  if (a <= 0 && b >= 0) {

    printf("Zero\n");
    return 0;
  }
  if (a < 0 && b < 0) {

    if ((b - a) % 2 == 0) {
      printf("Negative\n");
      return 0;
    }
    printf("Positive\n");
    return 0;

  } else if (a > 0 && b > 0) {

    printf("Positive\n");
    return 0;
  }
}

fn solution() {
    let mut stdin = io::stdin();
    let mut lines = String::new();
    let _ = stdin.read_to_string(&mut lines);
    let vec = lines.lines().collect::<Vec<&str>>();
    let vec2 = vec[0].split(' ').collect::<Vec<&str>>();
    let a: i64 = vec2[0].trim().parse().unwrap();
    let b: i64 = vec2[1].trim().parse().unwrap();

    if a * b <= 0 {
        println!("Zero");
    } else if a > 0 {
        println!("Positive");
    } else {
        if (b - a + 1) % 2 == 0 {
            println!("Positive");
        } else {
            println!("Negative");
        }
    }
}


You are given $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$. With a cost of one coin you can perform the following operation:Choose one of these numbers and add or subtract $$$1$$$ from it.In particular, we can apply this operation to the same number several times.We want to make the product of all these numbers equal to $$$1$$$, in other words, we want $$$a_1 \cdot a_2$$$ $$$\dots$$$ $$$\cdot a_n = 1$$$. For example, for $$$n = 3$$$ and numbers $$$[1, -3, 0]$$$ we can make product equal to $$$1$$$ in $$$3$$$ coins: add $$$1$$$ to second element, add $$$1$$$ to second element again, subtract $$$1$$$ from third element, so that array becomes $$$[1, -1, -1]$$$. And $$$1\cdot (-1) \cdot (-1) = 1$$$.What is the minimum cost we will have to pay to do that?

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

  int positive = 0;
  int negative = 0;
  int zero = 0;

  long long int arr[n];
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    long long int number = arr[i];

    if (number > 0) {
      positive++;
    } else if (number < 0) {
      negative++;
    } else {
      zero++;
    }
  }

  unsigned long long int answer = 0;

  for (int i = 0; i < n; i++) {
    long long int number = arr[i];

    if (number > 0) {
      answer += number - 1;
    } else if (number < 0) {
      answer += -number - 1;
    } else {
      answer += 1;
    }
  }

  if (negative % 2 == 0 || zero > 0) {
    ;
  } else {
    (answer += 2);
  }

  printf("%lld\n", answer);

  return 0;
}

fn solution() {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("failed to read input");
    let n = input.trim().parse::<u32>().unwrap();
    let mut neg = 0;
    let mut zeros = 0;
    let mut sum = 0;

    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("failed to read input");
    let mut input_iter = input.split_whitespace();
    for _ in 0..n {
        let num = input_iter.next().unwrap().parse::<i64>().unwrap();
        if num <= -1 {
            sum += -1 - num;
            neg += 1;
        } else if num == 0 {
            zeros += 1;
        } else {
            sum += num - 1;
        }
    }
    sum += zeros;
    if neg % 2 == 1 && zeros == 0 {
        sum += 2;
    }
    println!("{}", sum);
}


Score : <var>100</var> points

Problem Statement

Given are two strings <var>S</var> and <var>T</var> consisting of lowercase English letters. Concatenate <var>T</var> and <var>S</var> in this order, without space in between, and print the resulting string.

Constraints

<var>S</var> and <var>T</var> are strings consisting of lowercase English letters.

The lengths of <var>S</var> and <var>T</var> are between <var>1</var> and <var>100</var> (inclusive).

Input

Input is given from Standard Input in the following format:

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

Output

Print the resulting string.

Sample Input 1

oder atc

Sample Output 1

atcoder

When <var>S = </var> oder and <var>T = </var> atc, concatenating <var>T</var> and <var>S</var> in this order results in atcoder.

Sample Input 2

humu humu

Sample Output 2

humuhumu

int solution(void) {
  char s[101];
  char t[101];
  char buf[203];

  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%s %s", s, t);
  printf("%s%s\n", t, s);

  return 0;
}

fn solution() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let s = iter.next().unwrap().to_owned();
    let t = iter.next().unwrap().to_owned();
    println!("{}", t + &s);
}


Score : <var>500</var> points

Problem Statement

There are <var>N</var> towns on a line running east-west.
The towns are numbered <var>1</var> through <var>N</var>, in order from west to east.
Each point on the line has a one-dimensional coordinate, and a point that is farther east has a greater coordinate value.
The coordinate of town <var>i</var> is <var>X_i</var>.

You are now at town <var>1</var>, and you want to visit all the other towns.
You have two ways to travel:

Walk on the line.
Your fatigue level increases by <var>A</var> each time you travel a distance of <var>1</var>, regardless of direction.

Teleport to any location of your choice.
Your fatigue level increases by <var>B</var>, regardless of the distance covered.

Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways.

Constraints

All input values are integers.

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

<var>1≤X_i≤10^9</var>

For all <var>i(1≤i≤N-1)</var>, <var>X_i<X_{i+1}</var>.

<var>1≤A≤10^9</var>

<var>1≤B≤10^9</var>

Input

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

<var>N</var> <var>A</var> <var>B</var>
<var>X_1</var> <var>X_2</var> <var>...</var> <var>X_N</var>

Output

Print the minimum possible total increase of your fatigue level when you visit all the towns.

Sample Input 1

4 2 5
1 2 5 7

Sample Output 1

11

From town <var>1</var>, walk a distance of <var>1</var> to town <var>2</var>, then teleport to town <var>3</var>, then walk a distance of <var>2</var> to town <var>4</var>.
The total increase of your fatigue level in this case is <var>2×1+5+2×2=11</var>, which is the minimum possible value.

Sample Input 2

7 1 100
40 43 45 105 108 115 124

Sample Output 2

84

From town <var>1</var>, walk all the way to town <var>7</var>.
The total increase of your fatigue level in this case is <var>84</var>, which is the minimum possible value.

Sample Input 3

7 1 2
24 35 40 68 72 99 103

Sample Output 3

12

Visit all the towns in any order by teleporting six times.
The total increase of your fatigue level in this case is <var>12</var>, which is the minimum possible value.

int solution(void) {

  long n;
  long a;
  long b;
  scanf("%ld %ld %ld", &n, &a, &b);
  long x[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &x[i]);
  }
  long min = 0;
  for (long i = 1; i < n; i++) {
    if ((x[i] - x[i - 1]) * a <= b) {
      min += (x[i] - x[i - 1]) * a;
    } else {
      min += b;
    }
  }
  printf("%ld\n", min);

  return 0;
}

fn solution() {
    input! {
        n: usize, a: usize, b: usize,
        x: [usize; n],
    }
    let mut tired = 0;
    for i in 1..n {
        if (x[i] - x[i - 1]) * a <= b {
            tired += (x[i] - x[i - 1]) * a
        } else {
            tired += b;
        }
    }
    println!("{}", tired);
}


Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $$$k$$$ have the same sum. A subarray of an array is any sequence of consecutive elements.Phoenix currently has an array $$$a$$$ of length $$$n$$$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $$$1$$$ and $$$n$$$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    int k;
    scanf("%d %d", &n, &k);
    int A[n];
    int uniq[100] = {0};
    int len = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &A[i]);
      if (uniq[A[i] - 1] == 0) {
        len++;
        uniq[A[i] - 1] = 1;
      }
    }
    if (k < len) {
      printf("-1\n");
      continue;
    }
    for (int i = 0; len < k; i++) {
      if (uniq[i] == 0) {
        uniq[i] = 1;
        len++;
      }
    }
    printf("%d\n", len * n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 100; j++) {
        if (uniq[j]) {
          printf("%d ", j + 1);
        }
      }
    }
    printf("\n");
  }
}

fn solution() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
    for _ in 0..t {
        let xs: Vec<usize> = lines
            .next()
            .unwrap()
            .unwrap()
            .split(' ')
            .map(|x| x.parse().unwrap())
            .collect();
        let (n, k) = (xs[0], xs[1]);
        let ys: Vec<usize> = lines
            .next()
            .unwrap()
            .unwrap()
            .split(' ')
            .map(|x| x.parse().unwrap())
            .collect();
        let mut s: HashSet<usize> = ys.iter().cloned().collect();
        if s.len() > k {
            println!("-1");
            continue;
        }
        let mut zs: Vec<usize> = Vec::new();
        let mut i: usize = 0;
        while i < n {
            if zs.len() < k {
                if k - zs.len() <= s.len() && !s.contains(&ys[i]) {
                    let z = s.iter().cloned().next().unwrap();
                    zs.push(z);
                    s.remove(&z);
                } else {
                    zs.push(ys[i]);
                    s.remove(&ys[i]);
                    i += 1;
                }
            } else {
                if zs[zs.len() - k] == ys[i] {
                    zs.push(ys[i]);
                    i += 1;
                } else {
                    zs.push(zs[zs.len() - k]);
                }
            }
        }
        println!("{}", zs.len());
        for z in zs {
            print!("{} ", z);
        }
        println!();
    }
}


Let $$$s$$$ be a string of lowercase Latin letters. Its price is the sum of the indices of letters (an integer between 1 and 26) that are included in it. For example, the price of the string abca is $$$1+2+3+1=7$$$.The string $$$w$$$ and the integer $$$p$$$ are given. Remove the minimal number of letters from $$$w$$$ so that its price becomes less than or equal to $$$p$$$ and print the resulting string. Note that the resulting string may be empty. You can delete arbitrary letters, they do not have to go in a row. If the price of a given string $$$w$$$ is less than or equal to $$$p$$$, then nothing needs to be deleted and $$$w$$$ must be output.Note that when you delete a letter from $$$w$$$, the order of the remaining letters is preserved. For example, if you delete the letter e from the string test, you get tst.

fn solution() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    let t: usize = scan.next();
    for _ in 0..t {
        let s: String = scan.next();
        let v: Vec<char> = s.chars().collect();
        let p: i32 = scan.next();
        let mut vv = Vec::new();
        let n = v.len();
        let mut w = 0;
        for i in 0..n {
            vv.push((v[i], i));
            w += v[i] as i32 - 'a' as i32 + 1;
        }
        vv.sort();
        vv.reverse();
        let mut used = Vec::new();
        used.resize(n, false);
        if w > p {
            for i in 0..n {
                w -= vv[i].0 as i32 - 'a' as i32 + 1;
                used[vv[i].1] = true;
                if w <= p {
                    break;
                }
            }
        }
        for i in 0..n {
            if !used[i] {
                write!(out, "{}", v[i]);
            }
        }
        writeln!(out);
    }
}


Score : <var>100</var> points

Problem Statement

Three people, A, B and C, are trying to communicate using transceivers.
They are standing along a number line, and the coordinates of A, B and C are <var>a</var>, <var>b</var> and <var>c</var> (in meters), respectively.
Two people can directly communicate when the distance between them is at most <var>d</var> meters.
Determine if A and C can communicate, either directly or indirectly.
Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.

Constraints

<var>1</var> <var>≤</var> <var>a,b,c</var> <var>≤</var> <var>100</var>

<var>1</var> <var>≤</var> <var>d</var> <var>≤</var> <var>100</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>a</var> <var>b</var> <var>c</var> <var>d</var>

Output

If A and C can communicate, print Yes; if they cannot, print No.

Sample Input 1

4 7 9 3

Sample Output 1

Yes

A and B can directly communicate, and also B and C can directly communicate, so we should print Yes.

Sample Input 2

100 10 1 2

Sample Output 2

No

They cannot communicate in this case.

Sample Input 3

10 10 10 1

Sample Output 3

Yes

There can be multiple people at the same position.

Sample Input 4

1 100 2 10

Sample Output 4

Yes

int solution(void) {

  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  int dca = 0;
  int dba = 0;
  int dcb = 0;

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

  if (c - a >= 0) {
    dca = c - a;
  } else {
    dca = a - c;
  }
  if (b - a >= 0) {
    dba = b - a;
  } else {
    dba = a - b;
  }
  if (c - b >= 0) {
    dcb = c - b;
  } else {
    dcb = b - c;
  }

  if (dca <= d) {
    printf("Yes\n");
    return 0;
  }
  if (dba <= d && dcb <= d) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

fn solution() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let s = s.split_whitespace();
    let mut i: Vec<isize> = Vec::new();
    for z in s {
        i.push(z.parse().unwrap());
    }

    let a = i[0];
    let b = i[1];
    let c = i[2];
    let d = i[3];

    let mut ans = false;
    if (c - a).abs() <= d {
        ans = true;
    }
    if (a - b).abs() <= d && (b - c).abs() <= d {
        ans = true;
    }

    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


Score : <var>100</var> points

Problem Statement

AtCoder Inc. holds a contest every Saturday.

There are two types of contests called ABC and ARC, and just one of them is held at a time.

The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.

Given a string <var>S</var> representing the type of the contest held last week, print the string representing the type of the contest held this week.

Constraints

<var>S</var> is ABC or ARC.

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

Print the string representing the type of the contest held this week.

Sample Input 1

ABC

Sample Output 1

ARC

They held an ABC last week, so they will hold an ARC this week.

fn solution() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    if s.trim() == "ABC" {
        println!("ARC");
    } else {
        println!("ABC")
    }
}


Score : <var>100</var> points

Problem Statement

Takahashi likes the sound when he buys a drink from a vending machine.

That sound can be heard by spending <var>A</var> yen (the currency of Japan) each time.

Takahashi has <var>B</var> yen. He will hear the sound as many times as he can with that money, but at most <var>C</var> times, as he would be satisfied at that time.

How many times will he hear the sound?

Constraints

All values in input are integers.

<var>1 \leq A, B, C \leq 100</var>

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of times Takahashi will hear his favorite sound.

Sample Input 1

2 11 4

Sample Output 1

4

Since he has not less than <var>8</var> yen, he will hear the sound four times and be satisfied.

Sample Input 2

3 9 5

Sample Output 2

3

He may not be able to be satisfied.

Sample Input 3

100 1 10

Sample Output 3

0

int solution() {

  int a = 0;
  int b = 0;
  int c = 0;
  int son = 0;

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

  while (b >= a) {
    b = b - a;
    son++;
    if (son == c) {
      break;
    }
  }
  printf("%d\n", son);
  return 0;
}

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

    let mut iter = buf.split_whitespace();

    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    let c: usize = iter.next().unwrap().parse().unwrap();

    println!("{}", min(b / a, c));
}


Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.

fn solution() -> io::Result<()> {
    let mut input = String::new();

    io::stdin().read_line(&mut input)?;

    let n = input.trim().parse().unwrap();
    for _ in 0..n {
        input.clear();
        io::stdin().read_line(&mut input)?;
        let a: Vec<i32> = input
            .trim()
            .split(" ")
            .map(|x| x.parse().unwrap())
            .collect();

        input.clear();
        io::stdin().read_line(&mut input)?;
        let b: Vec<i32> = input
            .trim()
            .split(" ")
            .map(|x| x.parse().unwrap())
            .collect();

        if (a[0] == b[0]) && (a[0] == a[1] + b[1])
            || (a[0] == b[1]) && (a[0] == a[1] + b[0])
            || (a[1] == b[0]) && (a[1] == a[0] + b[1])
            || (a[1] == b[1]) && (a[1] == a[0] + b[0])
        {
            println!("YES");
        } else {
            println!("NO");
        }
    }
    Ok(())
}


When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs ai minutes to read the i-th book.Valera decided to choose an arbitrary book with number i and read the books one by one, starting from this book. In other words, he will first read book number i, then book number i + 1, then book number i + 2 and so on. He continues the process until he either runs out of the free time or finishes reading the n-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read.

int solution() {
  long n;
  long t;
  scanf("%ld %ld", &n, &t);
  long a[n];
  long i = 0;
  long j = 0;
  long books = 0;
  long mints = 0;
  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
    mints += a[i];
    if (mints <= t) {
      books++;
    } else if (mints > t) {
      mints -= a[j];
      j++;
    }
  }
  printf("%ld", books);
  return 0;
}

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

    let line: Vec<usize> = iterator
        .next()
        .unwrap()
        .unwrap()
        .split(" ")
        .map(|x| x.parse().expect("Not an integer!"))
        .collect();

    let books: Vec<usize> = iterator
        .next()
        .unwrap()
        .unwrap()
        .split(" ")
        .map(|x| x.parse().expect("Not an integer!"))
        .collect();

    let mut s = 0;
    let mut x = 0;
    let mut ans = 0;
    for i in 0..line[0] {
        s += books[i];
        while s > line[1] {
            s -= books[x];
            x += 1;
        }
        if i - x + 1 > ans {
            ans = i - x + 1;
        }
    }
    println!("{}", ans);
}


Score : <var>300</var> points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string <var>S</var> consisting of lowercase English letters.

He also found a string <var>S'</var>, which turns out to be the string <var>S</var> with some of its letters (possibly all or none) replaced with ?.

One more thing he found is a sheet of paper with the following facts written on it:

Condition 1: The string <var>S</var> contains a string <var>T</var> as a contiguous substring.

Condition 2: <var>S</var> is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string <var>S</var>.

If such a string does not exist, print UNRESTORABLE.

Constraints

<var>1 \leq |S'|, |T| \leq 50</var>

<var>S'</var> consists of lowercase English letters and ?.

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the string <var>S</var>.

If such a string does not exist, print UNRESTORABLE instead.

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are <var>26</var> strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say <var>S = </var>atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string <var>S</var> does not exist.

int solution(void) {

  char s[51];
  char t[51];
  scanf("%s %s", s, t);
  int s_length = strlen(s);
  int t_length = strlen(t);
  int flag;
  for (int i = s_length - 1; i >= t_length - 1; i--) {
    flag = 1;
    for (int j = 0; j < t_length; j++) {
      if (s[i - j] != t[t_length - 1 - j] && s[i - j] != '?') {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      for (int j = 0; j < s_length; j++) {
        if (j >= i - t_length + 1 && j <= i) {
          s[j] = t[j - (i - t_length + 1)];
        } else {
          if (s[j] == '?') {
            s[j] = 'a';
          }
        }
      }
      printf("%s\n", s);
      return 0;
    }
  }
  printf("UNRESTORABLE\n");

  return 0;
}

fn solution() {
    let mut s = String::new();
    let mut t = String::new();
    std::io::stdin().read_line(&mut s).ok();
    std::io::stdin().read_line(&mut t).ok();
    let a = s.trim_end().as_bytes();
    let b = t.trim_end().as_bytes();
    for i in (0..a.len()).rev() {
        if i + b.len() > a.len() {
            continue;
        }
        let mut valid = true;
        for j in 0..b.len() {
            if a[i + j] != b'?' && a[i + j] != b[j] {
                valid = false;
                break;
            }
        }
        if valid {
            for j in 0..i {
                print!("{}", if a[j] == b'?' { "a" } else { &s[j..j + 1] })
            }
            print!("{}", t.trim_end());
            for j in i + b.len()..a.len() {
                print!("{}", if a[j] == b'?' { "a" } else { &s[j..j + 1] })
            }
            println!();
            return;
        }
    }
    println!("UNRESTORABLE");
}


Let's denote a $$$k$$$-step ladder as the following structure: exactly $$$k + 2$$$ wooden planks, of which  two planks of length at least $$$k+1$$$ — the base of the ladder;  $$$k$$$ planks of length at least $$$1$$$ — the steps of the ladder; Note that neither the base planks, nor the steps planks are required to be equal.For example, ladders $$$1$$$ and $$$3$$$ are correct $$$2$$$-step ladders and ladder $$$2$$$ is a correct $$$1$$$-step ladder. On the first picture the lengths of planks are $$$[3, 3]$$$ for the base and $$$[1]$$$ for the step. On the second picture lengths are $$$[3, 3]$$$ for the base and $$$[2]$$$ for the step. On the third picture lengths are $$$[3, 4]$$$ for the base and $$$[2, 3]$$$ for the steps.   You have $$$n$$$ planks. The length of the $$$i$$$-th planks is $$$a_i$$$. You don't have a saw, so you can't cut the planks you have. Though you have a hammer and nails, so you can assemble the improvised "ladder" from the planks.The question is: what is the maximum number $$$k$$$ such that you can choose some subset of the given planks and assemble a $$$k$$$-step ladder using them?

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

  while (T-- > 0) {
    long first = 0;
    long second = 0;
    int n = 0;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
      long a = 0;
      scanf("%ld", &a);
      if (a > first) {
        second = first;
        first = a;
      } else if (a > second) {
        second = a;
      }
    }

    long k = second - 1 < n - 2 ? second - 1 : n - 2;

    printf("%ld\n", k);
  }
}

fn solution() {
    let mut s: String = String::new();
    let t: i32 = {
        io::stdin().read_line(&mut s).ok();
        s.trim().parse().unwrap()
    };
    s.clear();
    for _t in 0..t {
        let n: i32 = {
            io::stdin().read_line(&mut s).ok();
            s.trim().parse().unwrap()
        };
        s.clear();
        let a: Vec<i32> = {
            io::stdin().read_line(&mut s).ok();
            s.split_whitespace().map(|s| s.parse().unwrap()).collect()
        };
        s.clear();
        let (mut max1, mut max2) = (cmp::max(a[0], a[1]), cmp::min(a[0], a[1]));
        for &el in &a[2..] {
            if el > max1 {
                max2 = max1;
                max1 = el;
            } else if el > max2 {
                max2 = el;
            }
        }

        println!("{}", cmp::min(max2 - 1, n - 2));
    }
}


There are $$$n$$$ piles of stones, where the $$$i$$$-th pile has $$$a_i$$$ stones. Two people play a game, where they take alternating turns removing stones.In a move, a player may remove a positive number of stones from the first non-empty pile (the pile with the minimal index, that has at least one stone). The first player who cannot make a move (because all piles are empty) loses the game. If both players play optimally, determine the winner of the game.

int solution() {
  int t;
  scanf("%d", &t);
  for (int k = 0; k < t; ++k) {
    int n;
    scanf("%d", &n);
    int a[n];
    int check1 = 0;
    int not1 = 0;
    int flag = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
      if (a[i] == 1) {
        ++check1;
        if (flag == 0) {
          ++not1;
        }
      } else {
        flag = 1;
      }
    }
    if (check1 == n && n % 2 == 0) {
      printf("Second\n");
    } else if (check1 == n && n % 2 == 1) {
      printf("First\n");
    } else {
      if (not1 % 2 == 0) {
        printf("First\n");
      } else {
        printf("Second\n");
      }
    }
  }
  return 0;
}

fn solution() {
    let stdin = io::stdin();
    let mut input = stdin.lock();
    let mut line = String::new();
    input.read_line(&mut line).unwrap();
    let mut count: i16 = line.trim().parse().unwrap();
    while count > 0 {
        input.read_line(&mut line).unwrap();
        line.clear();
        let mut first_wins = false;
        input.read_line(&mut line).unwrap();
        for heap in line.split_whitespace() {
            first_wins = !first_wins;
            if heap != "1" {
                break;
            }
        }
        if first_wins {
            println!("First");
        } else {
            println!("Second");
        }
        count -= 1;
    }
}


There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in turn consists of two contests.A result of the elimination stage is the total score in two contests, but, unfortunately, the jury lost the final standings and has only standings for the first and for the second contest separately. In each contest, the participants are ranked by their point score in non-increasing order. When two participants have a tie (earned the same score), they are ranked by their passport number (in accordance with local regulations, all passport numbers are distinct). In the first contest, the participant on the 100-th place scored $$$a$$$ points. Also, the jury checked all participants from the 1-st to the 100-th place (inclusive) in the first contest and found out that all of them have at least $$$b$$$ points in the second contest.Similarly, for the second contest, the participant on the 100-th place has $$$c$$$ points. And the jury checked that all the participants from the 1-st to the 100-th place (inclusive) have at least $$$d$$$ points in the first contest.After two contests, all participants are ranked by their total score in two contests in non-increasing order. When participants have the same total score, tie-breaking with passport numbers is used. The cutoff score to qualify to the final stage is the total score of the participant on the 100-th place.Given integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$, please help the jury determine the smallest possible value of the cutoff score.

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

  while (t--) {
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    printf("%d\n", (a + b) > (c + d) ? (a + b) : (c + d));
  }

  return 0;
}

fn solution() {
    let mut reader = BufReader::new(stdin());
    let mut get_line = || {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        buf
    };
    let mut writer = BufWriter::new(stdout());

    let t: usize = get_line().trim().parse().unwrap();
    for _ in 0..t {
        let a: Vec<i32> = get_line()
            .split_whitespace()
            .map(|a| a.parse().unwrap())
            .collect();
        writeln!(writer, "{}", std::cmp::max(a[0] + a[1], a[2] + a[3])).unwrap();
    }
}


Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?Note: uppercase and lowercase letters are considered different.

fn solution() {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).expect("wrong format");

    let mut counter: [i32; 256] = [0; 256];

    for c in buffer.as_bytes() {
        let i: usize = (*c).into();
        counter[i] += 1;
    }

    let mut max = 1000000;
    for c in "Blbsr".as_bytes() {
        let i: usize = (*c).into();
        max = cmp::min(max, counter[i]);
    }

    for c in "au".as_bytes() {
        let i: usize = (*c).into();
        max = cmp::min(max, counter[i] / 2);
    }
    println!("{}", max);
}


Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!

int solution() {
  long long n;
  scanf("%lli", &n);
  long long x[n];
  long long z = 1;
  long long temp = 1;
  for (int i = 0; i < n; i++) {
    scanf("%lli", &x[i]);
    if (i == 0) {
      continue;
    }
    if (i > 0 && x[i] >= x[i - 1] && i != n - 1) {
      z++;
    } else if (i > 0 && x[i] < x[i - 1]) {
      if (z > temp) {
        temp = z;
        z = 1;
      } else {
        z = 1;
      }
    } else if (i > 0 && x[i] >= x[i - 1] && i == n - 1) {
      z++;
      if (z > temp) {
        temp = z;
        z = 1;
      } else {
        z = 1;
      }
    }
  }

  printf("%lli", temp);
}

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

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

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

    let n: Vec<i32> = input
        .trim()
        .split_ascii_whitespace()
        .map(|num| num.parse::<i32>().expect("Parsing error"))
        .collect();

    let mut best = 0;
    let mut ant = 0;
    let mut count = 0;

    for i in n {
        if i >= ant {
            count += 1;
            if count > best {
                best = count;
            }
        } else {
            count = 1;
            if count > best {
                best = count;
            }
        }
        ant = i;
    }

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


Score: <var>100</var> points

Problem Statement

Takahashi the Jumbo will practice golf.

His objective is to get a carry distance that is a multiple of <var>K</var>, while he can only make a carry distance of between <var>A</var> and <var>B</var> (inclusive).

If he can achieve the objective, print OK; if he cannot, print NG.

Constraints

All values in input are integers.

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

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

Input

Input is given from Standard Input in the following format:

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

Output

If he can achieve the objective, print OK; if he cannot, print NG.

Sample Input 1

7
500 600

Sample Output 1

OK

Among the multiples of <var>7</var>, for example, <var>567</var> lies between <var>500</var> and <var>600</var>.

Sample Input 2

4
5 7

Sample Output 2

NG

No multiple of <var>4</var> lies between <var>5</var> and <var>7</var>.

Sample Input 3

1
11 11

Sample Output 3

OK

int solution() {
  int k = 0;
  int a = 0;
  int b = 0;
  int i = 0;

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

  i = 1;
  while (k <= a) {
    if (a <= k * i) {
      break;
    }
    i++;
  }

  if (k * i <= b) {
    printf("OK\n");
  } else {
    printf("NG\n");
  }
  return 0;
}

fn solution() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    buf.pop();
    let K = i64::from_str(&buf).unwrap();
    buf.clear();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| i64::from_str(n).unwrap());
    let (A, B) = (it.next().unwrap(), it.next().unwrap());
    for i in A..(B + 1) {
        if i % K == 0 {
            println!("OK");
            return;
        }
    }
    println!("NG");
}


Ehab loves number theory, but for some reason he hates the number $$$x$$$. Given an array $$$a$$$, find the length of its longest subarray such that the sum of its elements isn't divisible by $$$x$$$, or determine that such subarray doesn't exist.An array $$$a$$$ is a subarray of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

int solution() {
  int t;
  int size;
  int x;
  scanf("%d", &t);

  for (int i = 0; i < t; i++) {

    scanf("%d %d", &size, &x);
    int arr[size];
    int flag = 0;
    int sum = 0;
    for (int j = 0; j < size; j++) {
      scanf("%d", &arr[j]);
      if ((arr[j] % x) != 0) {
        flag = 1;
      }
      sum = sum + arr[j];
    }

    if (flag == 0) {
      printf("-1\n");
    } else if (flag == 1 && (sum % x) != 0) {
      printf("%d\n", size);
    } else {
      for (int k = 0; k < size; k++) {
        if (((arr[k] % x) != 0) || ((arr[size - k - 1] % x) != 0)) {
          printf("%d\n", size - k - 1);
          break;
        }
      }
    }
  }
}

fn solution() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
    for _ in 0..t {
        let xs: Vec<usize> = lines
            .next()
            .unwrap()
            .unwrap()
            .split(' ')
            .map(|x| x.parse().unwrap())
            .collect();
        let (n, x) = (xs[0], xs[1] as u64);
        let ys: Vec<u64> = lines
            .next()
            .unwrap()
            .unwrap()
            .split(' ')
            .map(|x| x.parse().unwrap())
            .collect();
        let ok = ys.iter().any(|y| y % x != 0);
        if !ok {
            println!("-1");
            continue;
        }
        let sum: u64 = ys.iter().sum();
        if !sum.is_multiple_of(x) {
            println!("{}", n);
            continue;
        }
        let mut m: u64 = sum % x;
        let mut left: usize = 0;
        while m == 0 && left < n {
            m = (m + (x - ys[left] % x)) % x;
            left += 1;
        }
        m = sum % x;
        let mut right: usize = 0;
        while m == 0 && right < n {
            m = (m + (x - ys[n - right - 1] % x)) % x;
            right += 1;
        }
        println!("{}", n - min(left, right));
    }
}


During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows:   The cell with coordinates $$$(x, y)$$$ is at the intersection of $$$x$$$-th row and $$$y$$$-th column. Upper left cell $$$(1,1)$$$ contains an integer $$$1$$$.The developers of the SUM function don't sleep either. Because of the boredom, they teamed up with the developers of the RAND function, so they added the ability to calculate the sum on an arbitrary path from one cell to another, moving down or right. Formally, from the cell $$$(x,y)$$$ in one step you can move to the cell $$$(x+1, y)$$$ or $$$(x, y+1)$$$. After another Dinwows update, Levian started to study "Celex-2021" (because he wants to be an accountant!). After filling in the table with the GAZ-GIZ function, he asked you to calculate the quantity of possible different amounts on the path from a given cell $$$(x_1, y_1)$$$ to another given cell $$$(x_2, y_2$$$), if you can only move one cell down or right.Formally, consider all the paths from the cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$ such that each next cell in the path is located either to the down or to the right of the previous one. Calculate the number of different sums of elements for all such paths.

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

  while (t--) {
    int x1;
    int y1;
    int x2;
    int y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    int x = x2 - x1;
    long long y = y2 - y1;
    long long ans = x * y;

    printf("%lld \n", ++ans);
  }
}

fn solution() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.split_whitespace();
    let t: usize = itr.next().unwrap().parse().unwrap();
    let mut out = Vec::new();
    for _ in 0..t {
        let a: u64 = itr.next().unwrap().parse().unwrap();
        let b: u64 = itr.next().unwrap().parse().unwrap();
        let c: u64 = itr.next().unwrap().parse().unwrap();
        let d: u64 = itr.next().unwrap().parse().unwrap();
        writeln!(out, "{}", (c - a) * (d - b) + 1).ok();
    }
    stdout().write_all(&out).unwrap();
}


Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = $$$2$$$, b = $$$3$$$ changes the value of a to $$$5$$$ (the value of b does not change).In a prototype program Leo has two integer variables a and b, initialized with some positive values. He can perform any number of operations "a += b" or "b += a". Leo wants to test handling large integers, so he wants to make the value of either a or b strictly greater than a given value $$$n$$$. What is the smallest number of operations he has to perform?

fn solution() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let s: u32 = s.trim().parse().expect("");
    for _ in 0..s {
        let mut st = String::new();
        io::stdin().read_line(&mut st).expect("");
        let st: Vec<&str> = st.split(" ").collect();
        let mut a: u32 = st[0].trim().parse().expect("");
        let mut b: u32 = st[1].trim().parse().expect("");
        let n: u32 = st[2].trim().parse().expect("");
        let mut cnt = 0;
        while (a <= n) && (b <= n) {
            if a > b {
                b += a;
            } else {
                a += b;
            }
            cnt += 1;
        }
        println!("{}", cnt);
    }
}


After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points.At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs C roubles and decreases hunger by N points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.

int solution() {
  int a;
  int b;
  double c;
  double d;
  double e;
  double f;
  double g;
  double h;
  scanf("%d%d%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f);
  if (a < 20) {
    h = (20 - a) * 60 + (0 - b);
  } else {
    h = 0;
  }
  h = c + h * d;
  h = h / f;
  if (h != (int)h) {
    h = ((int)h + 1);
  }
  h = e * h;
  h = h - h * 20 / 100;
  g = c;
  g = g / f;
  if (g != (int)g) {
    g = (int)g + 1;
  }
  g = e * g;
  if (g <= h) {
    printf("%.4lf", g);
  } else {
    printf("%.4f", h);
  }
  return 0;
}

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

    let mut it = input.split_whitespace();

    let hh: f64 = it.next().unwrap().parse().unwrap();
    let mm: f64 = it.next().unwrap().parse().unwrap();
    let h: f64 = it.next().unwrap().parse().unwrap();
    let d: f64 = it.next().unwrap().parse().unwrap();
    let c: f64 = it.next().unwrap().parse().unwrap();
    let n: f64 = it.next().unwrap().parse().unwrap();

    if hh >= 20.0 {
        let c = c * 0.8;
        let cnt = (h / n).ceil();
        let ans = cnt * c;
        println!("{}", ans);
        return;
    }

    let a1 = {
        let cnt = (h / n).ceil();
        cnt * c
    };
    let a2 = {
        let tio = 60.0 * (20.0 - hh) - mm;
        let c = 0.8 * c;
        let cnt = ((h + tio * d) / n).ceil();
        c * cnt
    };
    let ans = if a1 < a2 { a1 } else { a2 };
    println!("{}", ans);
}


Score : <var>300</var> points

Problem Statement

You are given an integer sequence of length <var>n</var>, <var>a_1, ..., a_n</var>.
Let us consider performing the following <var>n</var> operations on an empty sequence <var>b</var>.

The <var>i</var>-th operation is as follows:

Append <var>a_i</var> to the end of <var>b</var>.

Reverse the order of the elements in <var>b</var>.

Find the sequence <var>b</var> obtained after these <var>n</var> operations.

Constraints

<var>1 \leq n \leq 2\times 10^5</var>

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

<var>n</var> and <var>a_i</var> are integers.

Input

Input is given from Standard Input in the following format:

<var>n</var>
<var>a_1</var> <var>a_2</var> <var>...</var> <var>a_n</var>

Output

Print <var>n</var> integers in a line with spaces in between.
The <var>i</var>-th integer should be <var>b_i</var>.

Sample Input 1

4
1 2 3 4

Sample Output 1

4 2 1 3

After step 1 of the first operation, <var>b</var> becomes: <var>1</var>.

After step 2 of the first operation, <var>b</var> becomes: <var>1</var>.

After step 1 of the second operation, <var>b</var> becomes: <var>1, 2</var>.

After step 2 of the second operation, <var>b</var> becomes: <var>2, 1</var>.

After step 1 of the third operation, <var>b</var> becomes: <var>2, 1, 3</var>.

After step 2 of the third operation, <var>b</var> becomes: <var>3, 1, 2</var>.

After step 1 of the fourth operation, <var>b</var> becomes: <var>3, 1, 2, 4</var>.

After step 2 of the fourth operation, <var>b</var> becomes: <var>4, 2, 1, 3</var>.

Thus, the answer is 4 2 1 3.

Sample Input 2

3
1 2 3

Sample Output 2

3 1 2

As shown above in Sample Output 1, <var>b</var> becomes <var>3, 1, 2</var> after step 2 of the third operation. Thus, the answer is 3 1 2.

Sample Input 3

1
1000000000

Sample Output 3

1000000000

Sample Input 4

6
0 6 7 6 7 0

Sample Output 4

0 6 6 0 7 7

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

    let ans = (0..n)
        .map(|i| {
            if i < n.div_ceil(2) {
                a[n - 2 * i - 1]
            } else {
                a[2 * (i - n.div_ceil(2)) + n % 2]
            }
        })
        .map(|x| x.to_string())
        .collect::<Vec<_>>()
        .join(" ");

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


Vlad, like everyone else, loves to sleep very much.Every day Vlad has to do $$$n$$$ things, each at a certain time. For each of these things, he has an alarm clock set, the $$$i$$$-th of them is triggered on $$$h_i$$$ hours $$$m_i$$$ minutes every day ($$$0 \le h_i < 24, 0 \le m_i < 60$$$). Vlad uses the $$$24$$$-hour time format, so after $$$h=12, m=59$$$ comes $$$h=13, m=0$$$ and after $$$h=23, m=59$$$ comes $$$h=0, m=0$$$.This time Vlad went to bed at $$$H$$$ hours $$$M$$$ minutes ($$$0 \le H < 24, 0 \le M < 60$$$) and asks you to answer: how much he will be able to sleep until the next alarm clock.If any alarm clock rings at the time when he went to bed, then he will sleep for a period of time of length $$$0$$$.

fn solution() {
    let mut tln = String::new();
    std::io::stdin().read_line(&mut tln).unwrap();
    let tcn = tln.trim_end().parse::<i32>().unwrap();

    for _k in 0..tcn {
        let mut sln = String::new();

        std::io::stdin().read_line(&mut sln).unwrap();
        let sln = sln
            .split_ascii_whitespace()
            .map(|x| x.trim_end().parse::<i32>().unwrap())
            .collect::<Vec<i32>>();
        let (n, t_hour, t_minute) = (sln[0], sln[1], sln[2]);

        let mut alarm_vec = Vec::new();

        for _i in 0..n {
            let mut cln = String::new();
            std::io::stdin().read_line(&mut cln).unwrap();

            let ca = cln
                .split_ascii_whitespace()
                .map(|x| x.trim_end().parse::<i32>().unwrap())
                .collect::<Vec<i32>>();

            alarm_vec.push(ca[0] * 60 + ca[1]);
        }

        alarm_vec.sort_unstable();
        if !alarm_vec.is_empty() {
            alarm_vec.push(alarm_vec[0] + 1440);
        }
        match alarm_vec.binary_search(&(t_hour * 60 + t_minute)) {
            Ok(_idx) => {
                println!("0 0");
            }
            Err(idx) => {
                let intv = alarm_vec[idx] - (t_hour * 60 + t_minute);
                println!("{} {}", intv / 60, intv % 60);
            }
        }
    }
}


電子レンジ (Microwave)

問題

JOI 君は食事の準備のため，A ℃の肉を電子レンジで B ℃まで温めようとしている．
肉は温度が 0 ℃未満のとき凍っている．
また，温度が 0 ℃より高いとき凍っていない．
温度がちょうど 0 ℃のときの肉の状態は，凍っている場合と，凍っていない場合の両方があり得る．

JOI 君は，肉の加熱にかかる時間は以下のようになると仮定して，肉を温めるのにかかる時間を見積もることにした．

肉が凍っていて，その温度が 0 ℃より小さいとき： C 秒で 1 ℃温まる．

肉が凍っていて，その温度がちょうど 0 ℃のとき： D 秒で肉が解凍され，凍っていない状態になる．

肉が凍っていないとき： E 秒で 1 ℃温まる．

この見積もりにおいて，肉を B ℃にするのに何秒かかるかを求めよ．

入力

入力は 5 行からなり，1 行に 1 個ずつ整数が書かれている．

1 行目には，もともとの肉の温度 A が書かれている．

2 行目には，目的の温度 B が書かれている．

3 行目には，凍った肉を 1 ℃温めるのにかかる時間 C が書かれている．

4 行目には，凍った肉を解凍するのにかかる時間 D が書かれている．

5 行目には，凍っていない肉を 1 ℃温めるのにかかる時間 E が書かれている．

もともとの温度 A は -100 以上 100 以下，目的の温度 B は 1 以上 100 以下であり，A ≠ 0 および A < B を満たす．

温めるのにかかる時間 C, D, E はすべて 1 以上 100 以下である．

出力

肉を B ℃にするのにかかる秒数を 1 行で出力せよ．

入出力例

入力例 1

-10
20
5
10
3

出力例 1

120

入力例 2

35
92
31
50
11

出力例 2

627

入出力例 1 では，もともとの肉は -10 ℃で凍っている．かかる時間は以下のようになる．

-10 ℃から 0 ℃まで温めるのに 5 × 10 = 50 秒．

0 ℃の肉を解凍するのに 10 秒．

0 ℃から 20 ℃まで温めるのに 3 × 20 = 60 秒．

したがって，かかる時間の合計は 120 秒である．

入出力例 2 では，もともとの肉は凍っていない．したがって，肉を 35 ℃から 92 ℃まで温めるのにかかる時間は 627 秒である．

情報オリンピック日本委員会作 『第 16 回日本情報オリンピック JOI 2016/2017 予選競技課題』

int solution(void) {
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  int e = 0;
  int t = 0;
  scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
  if (a < 0) {
    t = -a * c + d + e * b;
  } else {
    t = (b - a) * e;
  }
  printf("%d\n", t);
  return 0;
}

fn solution() {
    let input = {
        let mut buf = vec![];
        stdin().read_to_end(&mut buf);
        unsafe { String::from_utf8_unchecked(buf) }
    };
    let mut lines = input.split('\n').map(|s| s.parse::<i32>().unwrap());

    let a = lines.next().unwrap();
    let b = lines.next().unwrap();
    let c = lines.next().unwrap();
    let d = lines.next().unwrap();
    let e = lines.next().unwrap();

    let sec = if a <= 0 {
        -a * c + d + b * e
    } else {
        (b - a) * e
    };

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


Score: <var>100</var> points

Problem Statement

In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.

For example, May <var>3</var>, <var>2018</var> is written as <var>2018</var>-<var>5</var>-<var>3</var>, or <var>5</var>-<var>3</var> without the year.

In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, <var>5</var>-<var>5</var> is Takahashi.

How many days from <var>2018</var>-<var>1</var>-<var>1</var> through <var>2018</var>-<var>a</var>-<var>b</var> are Takahashi?

Constraints

<var>a</var> is an integer between <var>1</var> and <var>12</var> (inclusive).

<var>b</var> is an integer between <var>1</var> and <var>31</var> (inclusive).

<var>2018</var>-<var>a</var>-<var>b</var> is a valid date in Gregorian calendar.

Input

Input is given from Standard Input in the following format:

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

Output

Print the number of days from <var>2018</var>-<var>1</var>-<var>1</var> through <var>2018</var>-<var>a</var>-<var>b</var> that are Takahashi.

Sample Input 1

5 5

Sample Output 1

5

There are five days that are Takahashi: <var>1</var>-<var>1</var>, <var>2</var>-<var>2</var>, <var>3</var>-<var>3</var>, <var>4</var>-<var>4</var> and <var>5</var>-<var>5</var>.

Sample Input 2

2 1

Sample Output 2

1

There is only one day that is Takahashi: <var>1</var>-<var>1</var>.

Sample Input 3

11 30

Sample Output 3

11

There are eleven days that are Takahashi: <var>1</var>-<var>1</var>, <var>2</var>-<var>2</var>, <var>3</var>-<var>3</var>, <var>4</var>-<var>4</var>, <var>5</var>-<var>5</var>, <var>6</var>-<var>6</var>, <var>7</var>-<var>7</var>, <var>8</var>-<var>8</var>, <var>9</var>-<var>9</var>, <var>10</var>-<var>10</var> and <var>11</var>-<var>11</var>.

int solution() {
  int a = 0;
  int b = 0;
  scanf("%d %d", &a, &b);
  if (a <= b) {
    printf("%d", a);
  } else {
    printf("%d", a - 1);
  }
}

fn solution() {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let v: Vec<u64> = s.trim().split(" ").map(|n| n.parse().unwrap()).collect();
    if v[0] > v[1] {
        println!("{}", v[0] - 1);
    } else {
        println!("{}", v[0]);
    }
}


You are given two arrays $$$a$$$ and $$$b$$$ of positive integers, with length $$$n$$$ and $$$m$$$ respectively. Let $$$c$$$ be an $$$n \times m$$$ matrix, where $$$c_{i,j} = a_i \cdot b_j$$$. You need to find a subrectangle of the matrix $$$c$$$ such that the sum of its elements is at most $$$x$$$, and its area (the total number of elements) is the largest possible.Formally, you need to find the largest number $$$s$$$ such that it is possible to choose integers $$$x_1, x_2, y_1, y_2$$$ subject to $$$1 \leq x_1 \leq x_2 \leq n$$$, $$$1 \leq y_1 \leq y_2 \leq m$$$, $$$(x_2 - x_1 + 1) \times (y_2 - y_1 + 1) = s$$$, and $$$$$$\sum_{i=x_1}^{x_2}{\sum_{j=y_1}^{y_2}{c_{i,j}}} \leq x.$$$$$$

int solution() {
  int n;
  int m;
  int a[2010];
  int b[2010];
  int x;

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

  a[0] = b[0] = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = a[i - 1] + a[i];
  }
  for (int i = 1; i <= m; i++) {
    b[i] = b[i - 1] + b[i];
  }

  long long sa[2005];
  long long sb[2005];
  memset(sa, 0x7f, sizeof(sa));
  memset(sb, 0x7f, sizeof(sb));

  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int sum = a[j] - a[i - 1];
      int len = j - i + 1;
      if (sa[len] > sum) {
        sa[len] = sum;
      }
    }
  }

  for (int i = 1; i <= m; i++) {
    for (int j = i; j <= m; j++) {
      int sum = b[j] - b[i - 1];
      int len = j - i + 1;
      if (sb[len] > sum) {
        sb[len] = sum;
      }
    }
  }

  int answer = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (sa[i] * sb[j] <= (long long)(x) && answer < i * j) {
        answer = i * j;
      }
    }
  }

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

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

    let arr: Vec<_> = buffer
        .split_whitespace()
        .map(|x| x.parse::<u64>().unwrap())
        .collect();
    let n = arr[0];
    let m = arr[1];

    let a = arr.iter().skip(2).take(n as usize).collect::<Vec<_>>();
    let b = arr
        .iter()
        .skip(2 + n as usize)
        .take(m as usize)
        .collect::<Vec<_>>();
    let x = *arr.get(2 + n as usize + m as usize).unwrap();

    use std::cmp;

    use std::collections::HashMap;
    let mut ma = HashMap::new();
    let mut mb = HashMap::new();

    for i in 0..a.len() {
        let mut accm = 0;
        for j in i..a.len() {
            accm += a[j];
            if accm <= x {
                let num_squares = j - i + 1;
                if let std::collections::hash_map::Entry::Vacant(e) = ma.entry(num_squares) {
                    e.insert(accm);
                } else {
                    let v = *ma.get_mut(&num_squares).unwrap();
                    *(ma.get_mut(&num_squares).unwrap()) = cmp::min(v, accm);
                }
            }
        }
    }
    for i in 0..b.len() {
        let mut accm = 0;
        for j in i..b.len() {
            accm += b[j];
            if accm <= x {
                let num_squares = j - i + 1;
                if let std::collections::hash_map::Entry::Vacant(e) = mb.entry(num_squares) {
                    e.insert(accm);
                } else {
                    let v = *mb.get_mut(&num_squares).unwrap();
                    *(mb.get_mut(&num_squares).unwrap()) = cmp::min(v, accm);
                }
            }
        }
    }

    let va: Vec<_> = ma.drain().collect();
    let vb: Vec<_> = mb.drain().collect();
    let mut max_area = 0;
    for (k1, v1) in va.iter() {
        for (k2, v2) in vb.iter() {
            if *v1 * v2 <= x {
                max_area = cmp::max(max_area, k1 * k2);
            }
        }
    }

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


Today we will be playing a red and white colouring game (no, this is not the Russian Civil War; these are just the colours of the Canadian flag).You are given an $$$n \times m$$$ grid of "R", "W", and "." characters. "R" is red, "W" is white and "." is blank. The neighbours of a cell are those that share an edge with it (those that only share a corner do not count).Your job is to colour the blank cells red or white so that every red cell only has white neighbours (and no red ones) and every white cell only has red neighbours (and no white ones). You are not allowed to recolour already coloured cells.

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

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

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

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

    'cases: for _case_index in 1..=t {
        let s = lines.next().unwrap();
        let mut it = s.split_whitespace().map(|s| s.parse::<usize>().unwrap());

        let n = it.next().unwrap();
        let m = it.next().unwrap();

        let mut grid = Vec::with_capacity(n * m);

        for _ in 0..n {
            for c in lines.next().unwrap().chars() {
                grid.push(match c {
                    'R' => 0,
                    'W' => 1,
                    _ => 2,
                })
            }
        }

        let mut r_even = None;

        for i in 0..n {
            for j in 0..m {
                let even = (i + j) % 2 == 0;
                let c = grid[i * m + j];
                if c == 2 {
                    continue;
                }

                if let Some(r) = r_even {
                    let o = if r && even || !r && !even { 0 } else { 1 };

                    if c != o {
                        writeln!(&mut output, "NO").unwrap();
                        continue 'cases;
                    }
                } else {
                    r_even = Some(c == 0 && even || c == 1 && !even);
                }
            }
        }

        writeln!(&mut output, "YES").unwrap();

        let r_even = r_even.unwrap_or(true);

        for i in 0..n {
            for j in 0..m {
                let even = (i + j) % 2 == 0;
                let c = match (even, r_even) {
                    (true, true) | (false, false) => 'R',
                    _ => 'W',
                };
                write!(&mut output, "{}", c).unwrap();
            }
            writeln!(&mut output).unwrap();
        }
    }
}


You are given a string $$$a$$$, consisting of $$$n$$$ characters, $$$n$$$ is even. For each $$$i$$$ from $$$1$$$ to $$$n$$$ $$$a_i$$$ is one of 'A', 'B' or 'C'.A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.You want to find a string $$$b$$$ that consists of $$$n$$$ characters such that:   $$$b$$$ is a regular bracket sequence;  if for some $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$) $$$a_i=a_j$$$, then $$$b_i=b_j$$$. In other words, you want to replace all occurrences of 'A' with the same type of bracket, then all occurrences of 'B' with the same type of bracket and all occurrences of 'C' with the same type of bracket.Your task is to determine if such a string $$$b$$$ exists.

fn solution() {
    let mut input = String::new();
    stdin().read_to_string(&mut input).unwrap();

    let mut it = input.split_whitespace();

    let _t = it.next();

    for a in it {
        let a = a.as_bytes();
        let s = a.first().unwrap();
        let e = a.last().unwrap();

        let ans = if e == s {
            false
        } else {
            let mut ans = false;

            for &opening in &[true, false] {
                let mut d = 0;
                for c in a {
                    if c == s || (c != e && opening) {
                        d += 1;
                    } else {
                        if d == 0 {
                            d = 1;
                            break;
                        }
                        d -= 1;
                    }
                }

                if d == 0 {
                    ans = true;
                    break;
                }
            }
            ans
        };

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


You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.

int solution() {
  int n;
  int m;
  scanf("%d %d", &n, &m);
  char l1[m][15];
  char l2[m][15];
  for (int i = 0; i < m; i++) {
    scanf("%s %s", l1[i], l2[i]);
  }
  char s[15];
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    for (int j = 0; j < m; j++) {
      if (strcmp(s, l1[j]) == 0) {
        if (strlen(s) <= strlen(l2[j])) {
          printf("%s ", s);
        } else {
          printf("%s ", l2[j]);
        }
      }
    }
  }
}

fn solution() {
    let mut fl = String::new();
    io::stdin().read_line(&mut fl).expect("error reading line");
    let fl: Vec<&str> = fl.as_str().split(' ').collect();
    let n: i32 = fl[0].trim().parse().expect("en");
    let m: i32 = fl[1].trim().parse().expect("en");
    let mut v1 = Vec::new();
    let mut v2 = Vec::new();
    let mut sl = String::new();
    for _i in 0..m {
        sl = "".to_string();
        io::stdin().read_line(&mut sl).expect("error reading line");
        let sl: Vec<String> = sl.as_str().split(' ').map(|s| s.to_string()).collect();
        v1.push(sl[0].clone());
        v2.push(sl[1].clone());
    }
    let mut fl = String::new();
    io::stdin().read_line(&mut fl).expect("error reading line");
    let fl: Vec<&str> = fl.as_str().split(' ').collect();
    for i in 0..n {
        let i = i as usize;
        for j in 0..m {
            let j = j as usize;
            if fl[i].trim() == v1[j].trim() || fl[i].trim() == v2[j].trim() {
                if v1[j].trim().len() <= v2[j].trim().len() {
                    print!("{} ", v1[j].trim());
                } else {
                    print!("{} ", v2[j].trim());
                }
                break;
            }
        }
    }
}