Polycarp remembered the $$$2020$$$-th year, and he is happy with the arrival of the new $$$2021$$$-th year. To remember such a wonderful moment, Polycarp wants to represent the number $$$n$$$ as the sum of a certain number of $$$2020$$$ and a certain number of $$$2021$$$.For example, if:   $$$n=4041$$$, then the number $$$n$$$ can be represented as the sum $$$2020 + 2021$$$;  $$$n=4042$$$, then the number $$$n$$$ can be represented as the sum $$$2021 + 2021$$$;  $$$n=8081$$$, then the number $$$n$$$ can be represented as the sum $$$2020 + 2020 + 2020 + 2021$$$;  $$$n=8079$$$, then the number $$$n$$$ cannot be represented as the sum of the numbers $$$2020$$$ and $$$2021$$$. Help Polycarp to find out whether the number $$$n$$$ can be represented as the sum of a certain number of numbers $$$2020$$$ and a certain number of numbers $$$2021$$$.

int solution() {
  int n = 0;
  int num = 0;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &num);
    int a = num / 2020;
    int b = num % 2020;
    if (a >= b) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

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

    let mut hash = HashSet::new();
    hash.insert(0u64);

    let mut producables = HashSet::new();
    let mut a = 0;
    while a <= 1_000_000 {
        let mut b = 0;
        while a + b <= 1_000_000 {
            producables.insert(a + b);
            b += 2021;
        }
        a += 2020
    }
    let mut t = String::new();
    let _ = stdin.read_line(&mut t);
    let t: u64 = t.trim().parse().unwrap();
    for _ in 0..t {
        let mut n = String::new();
        let _ = stdin.read_line(&mut n);
        let n: u64 = n.trim().parse().unwrap();
        match producables.contains(&n) {
            true => println!("yes"),
            false => println!("no"),
        }
    }
}


There is a bookshelf which can fit $$$n$$$ books. The $$$i$$$-th position of bookshelf is $$$a_i = 1$$$ if there is a book on this position and $$$a_i = 0$$$ otherwise. It is guaranteed that there is at least one book on the bookshelf.In one move, you can choose some contiguous segment $$$[l; r]$$$ consisting of books (i.e. for each $$$i$$$ from $$$l$$$ to $$$r$$$ the condition $$$a_i = 1$$$ holds) and:  Shift it to the right by $$$1$$$: move the book at index $$$i$$$ to $$$i + 1$$$ for all $$$l \le i \le r$$$. This move can be done only if $$$r+1 \le n$$$ and there is no book at the position $$$r+1$$$.  Shift it to the left by $$$1$$$: move the book at index $$$i$$$ to $$$i-1$$$ for all $$$l \le i \le r$$$. This move can be done only if $$$l-1 \ge 1$$$ and there is no book at the position $$$l-1$$$. Your task is to find the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without any gaps).For example, for $$$a = [0, 0, 1, 0, 1]$$$ there is a gap between books ($$$a_4 = 0$$$ when $$$a_3 = 1$$$ and $$$a_5 = 1$$$), for $$$a = [1, 1, 0]$$$ there are no gaps between books and for $$$a = [0, 0,0]$$$ there are also no gaps between books.You have to answer $$$t$$$ independent test cases.

int solution() {
  int t = 0;
  scanf("%d%*c", &t);
  for (int i = 0; i < t; i++) {
    int n = 0;
    scanf("%d%*c", &n);
    int startCounting = 0;
    int tempSum = 0;
    int res = 0;
    for (int j = 0; j < n; j++) {
      int temp = 0;
      scanf("%d%*c", &temp);
      if (temp == 0) {
        tempSum++;
      }
      if (temp == 1 && startCounting == 0) {
        tempSum = 0;
        startCounting = 1;
      }
      if (temp == 1 && startCounting == 1) {
        res += tempSum;
        tempSum = 0;
      }
    }
    printf("%d\n", res);
  }
  return 0;
}

fn solution() {
    let mut input = "".split_ascii_whitespace();
    let mut read = || loop {
        if let Some(word) = input.next() {
            break word;
        }
        input = {
            let mut input = "".to_owned();
            io::stdin().read_line(&mut input).unwrap();
            if input.is_empty() {
                panic!("reached EOF");
            }
            Box::leak(input.into_boxed_str()).split_ascii_whitespace()
        };
    };

    let t = read!(usize);
    for _ in 0..t {
        let n = read!(usize);
        let mut a: Vec<i64> = vec![0; 0];
        for _ in 0..n {
            a.push(read!(i64));
        }

        let mut r = 0;
        let mut f = false;
        let mut c = 0;
        for i in 0..n {
            if a[i] == 1 {
                if f {
                    r += c;
                }
                c = 0;
                f = true;
            } else {
                c += 1;
            }
        }
        println!("{}", r);
    }
}


Score : <var>200</var> points

Problem Statement

We have <var>N</var> weights indexed <var>1</var> to <var>N</var>. The mass of the weight indexed <var>i</var> is <var>W_i</var>.

We will divide these weights into two groups: the weights with indices not greater than <var>T</var>, and those with indices greater than <var>T</var>, for some integer <var>1 \leq T < N</var>. Let <var>S_1</var> be the sum of the masses of the weights in the former group, and <var>S_2</var> be the sum of the masses of the weights in the latter group.

Consider all possible such divisions and find the minimum possible absolute difference of <var>S_1</var> and <var>S_2</var>.

Constraints

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

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>W_1</var> <var>W_2</var> <var>...</var> <var>W_{N-1}</var> <var>W_N</var>

Output

Print the minimum possible absolute difference of <var>S_1</var> and <var>S_2</var>.

Sample Input 1

3
1 2 3

Sample Output 1

0

If <var>T = 2</var>, <var>S_1 = 1 + 2 = 3</var> and <var>S_2 = 3</var>, with the absolute difference of <var>0</var>.

Sample Input 2

4
1 3 1 1

Sample Output 2

2

If <var>T = 2</var>, <var>S_1 = 1 + 3 = 4</var> and <var>S_2 = 1 + 1 = 2</var>, with the absolute difference of <var>2</var>. We cannot have a smaller absolute difference.

Sample Input 3

8
27 23 76 2 3 5 62 52

Sample Output 3

2

int solution() {
  int n = 0;
  int total = 0;
  int s1 = 0;
  int s2 = 0;
  int s3 = 0;
  int w[100];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &w[i]);
    total = w[i] + total;
  }
  int ans = total;
  for (int i = 0; i < n; i++) {
    s1 = s1 + w[i];
    s2 = total - s1;
    s3 = abs(s2 - s1);
    if (s3 < ans) {
      ans = s3;

    } else {
    }
  }

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

fn solution() {
    let n: usize = {
        let mut n = String::new();
        io::stdin().read_line(&mut n).unwrap();
        n.trim_end().to_owned().trim().parse().unwrap()
    };

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let w: Vec<i32> = buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
    let _sum: i32 = w.iter().sum();
    let mut bb: Vec<i32> = vec![];
    for i in 0..n {
        let (a, b) = w.split_at(i);
        let asum: i32 = a.iter().sum();
        let bsum: i32 = b.iter().sum();
        bb.push(i32::abs(asum - bsum));
    }
    bb.sort();
    println!("{}", bb[0]);
}


You are given two strings $$$s$$$ and $$$t$$$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $$$1$$$. You can't choose a string if it is empty.For example:  by applying a move to the string "where", the result is the string "here",  by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.Write a program that finds the minimum number of moves to make two given strings $$$s$$$ and $$$t$$$ equal.

int solution() {
  char *A = malloc(sizeof(char) * 200005);
  char *B = malloc(sizeof(char) * 200005);
  scanf("%s %s", A, B);
  int length_A = strlen(A);
  int length_B = strlen(B);
  int totalamt = length_A + length_B;
  for (int index_A = length_A - 1, index_B = length_B - 1;
       index_A >= 0 && index_B >= 0;) {
    if (A[index_A] != B[index_B]) {
      break;
    }
    index_A--;
    index_B--;
    totalamt -= 2;
  }
  printf("%i", totalamt);
  free(A);
  free(B);
}

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 i = s.len() - 1;
    let mut j = t.len() - 1;

    use std::cmp::min;

    for _ in 0..min(s.len(), t.len()) {
        if s[i] != t[j] {
            println!("{}", i + j + 2);
            break;
        }
        if i == 0 || j == 0 {
            println!("{}", s.len() + t.len() - min(s.len(), t.len()) * 2);
            break;
        }
        i -= 1;
        j -= 1;
    }
}


You are given a digital clock with $$$n$$$ digits. Each digit shows an integer from $$$0$$$ to $$$9$$$, so the whole clock shows an integer from $$$0$$$ to $$$10^n-1$$$. The clock will show leading zeroes if the number is smaller than $$$10^{n-1}$$$.You want the clock to show $$$0$$$ with as few operations as possible. In an operation, you can do one of the following:   decrease the number on the clock by $$$1$$$, or  swap two digits (you can choose which digits to swap, and they don't have to be adjacent). Your task is to determine the minimum number of operations needed to make the clock show $$$0$$$.

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

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

fn solution() {
    let stdin = stdin();
    let mut string = String::new();
    stdin.read_line(&mut string).unwrap();
    for _ in 0..string.trim().parse::<usize>().unwrap() {
        string.clear();
        stdin.read_line(&mut string).unwrap();
        string.clear();
        stdin.read_line(&mut string).unwrap();
        let vec = string
            .trim()
            .chars()
            .map(|f| f.to_digit(10).unwrap())
            .collect::<Vec<u32>>();
        let mut re = 0;
        for i in 0..vec.len() {
            if vec[i] != 0 {
                re += vec[i];
                if i != vec.len() - 1 {
                    re += 1
                }
            }
        }
        println!("{}", re);
    }
}


The Balance of the World

The world should be finely balanced.  Positive vs. negative,
light vs. shadow, and left vs. right brackets.
Your mission is to write a program that judges whether a string is balanced
with respect to brackets so that we can observe the balance of the
world.

A string that will be given to the program may have two kinds of brackets,
round (“( )”) and square (“[ ]”).
A string is balanced if and only if the following conditions hold.

For every left round bracket (“(”), there is a corresponding
    right round bracket (“)”) in the following part of the string.

For every left square bracket (“[”), there is a corresponding
    right square bracket (“]”) in the following part of the string.

For every right bracket, there is a left bracket corresponding to it.

Correspondences of brackets have to be one to one, that is, a
    single bracket never corresponds to two or more brackets.

For every pair of corresponding left and right brackets,
    the substring between them is balanced.

Input

The input consists of one or more lines, each of which being a dataset.
A dataset is a string that consists of English alphabets,
space characters, and two kinds of brackets, round (“( )”) and square (“[ ]”),
terminated by a period.  You can assume that every line has 100
characters or less.
The line formed by a single period indicates the end of the input,
which is not a dataset.

Output

For each dataset, output “yes” if the
string is balanced, or “no” otherwise, in a line.
There may not be any extra characters in the output.

Sample Input

So when I die (the [first] I will see in (heaven) is a score list).
[ first in ] ( first out ).
Half Moon tonight (At least it is better than no Moon at all].
A rope may form )( a trail in a maze.
Help( I[m being held prisoner in a fortune cookie factory)].
([ (([( [ ] ) ( ) (( ))] )) ]).
 .
.

Output for the Sample Input

yes
yes
no
no
no
yes
yes

int solution(void) {
  char s[128];
  char stack[128];
  while (fgets(s, 128, stdin)) {
    int n = strlen(s) - 1;
    char *p = strchr(s, '\n');
    int i;
    int ok = 1;
    int sp = 0;
    if (p) {
      *p = 0;
    }
    if (*s == '.' && n == 1) {
      break;
    }

    for (i = 0; i < n; ++i) {
      switch (s[i]) {
      case '(':
        stack[sp++] = s[i];
        break;
      case ')':
        if (!sp || stack[--sp] != '(') {
          ok = 0;
        }
        break;
      case '[':
        stack[sp++] = s[i];
        break;
      case ']':
        if (!sp || stack[--sp] != '[') {
          ok = 0;
        }
        break;
      }
    }
    ok = ok && sp == 0;
    puts(ok ? "yes" : "no");
  }
  return 0;
}

fn solution() {
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let chars: Vec<char> = line.unwrap().chars().collect();

        if chars[0] == '.' && chars.len() <= 1 {
            return;
        }

        let mut stack: Vec<char> = Vec::new();

        for char in chars {
            if char == '(' || char == '[' {
                stack.push(char);
            } else if char == ')' {
                if stack.is_empty() || stack.last().unwrap() != &'(' {
                    stack.push(char);
                    break;
                }
                stack.pop();
            } else if char == ']' {
                if stack.is_empty() || stack.last().unwrap() != &'[' {
                    stack.push(char);
                    break;
                }
                stack.pop();
            }
        }

        if !stack.is_empty() {
            println!("no");
        } else {
            println!("yes");
        }
    }
}


Score : <var>400</var> points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is <var>H</var>.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

If the monster's health is <var>1</var>, it drops to <var>0</var>.

If the monster's health, <var>X</var>, is greater than <var>1</var>, that monster disappears. Then, two new monsters appear, each with the health of <var>\lfloor X/2 \rfloor</var>.

(<var>\lfloor r \rfloor</var> denotes the greatest integer not exceeding <var>r</var>.)

Caracal wins when the healths of all existing monsters become <var>0</var> or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

<var>1 \leq H \leq 10^{12}</var>

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>H</var>

Output

Find the minimum number of attacks Caracal needs to make before winning.

Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of <var>1</var>.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775

int solution() {
  unsigned long n = 0;
  unsigned long r = 1;
  scanf("%lu", &n);
  while (n != 0) {
    n >>= 1;
    r <<= 1;
  }

  printf("%lu", r - 1);
}

fn solution() {
    let mut buf = String::new();
    let stdin = std::io::stdin();
    stdin.lock().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let h = iter.next().unwrap().parse::<usize>().unwrap();

    let mut ans = 0_usize;
    for i in (0..41).rev() {
        if (h & 1 << i) != 0_usize {
            for j in 0..i + 1 {
                ans += 1 << j;
            }
            break;
        }
    }

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


You are given two arrays of integers $$$a_1,\ldots,a_n$$$ and $$$b_1,\ldots,b_m$$$.Your task is to find a non-empty array $$$c_1,\ldots,c_k$$$ that is a subsequence of $$$a_1,\ldots,a_n$$$, and also a subsequence of $$$b_1,\ldots,b_m$$$. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it.A sequence $$$a$$$ is a subsequence of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero) elements. For example, $$$[3,1]$$$ is a subsequence of $$$[3,2,1]$$$ and $$$[4,3,1]$$$, but not a subsequence of $$$[1,3,3,7]$$$ and $$$[3,10,4]$$$.

int solution() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    int a;
    int b;
    scanf("%d %d", &a, &b);
    int input1[a];
    int input2[b];
    int ctr1[1005] = {0};
    int ctr2[1005] = {0};
    for (int i = 0; i < a; i++) {
      scanf("%d", &input1[i]);
      ctr1[input1[i]]++;
    }
    for (int i = 0; i < b; i++) {
      scanf("%d", &input2[i]);
      ctr2[input2[i]]++;
    }
    int flag = 1;
    for (int i = 0; i < 1005; i++) {
      if (ctr1[i] > 0 && ctr2[i] > 0) {
        printf("YES\n");
        printf("1 %d\n", i);
        flag = 0;
        break;
      }
    }
    if (flag) {
      printf("NO\n");
    }
  }
  return 0;
}

fn solution() {
    let stdin = std::io::stdin();
    let mut line: String = String::new();
    stdin.read_line(&mut line).unwrap();
    let ntc: i32 = line.trim().parse().unwrap();

    for _ in 0..ntc {
        stdin.read_line(&mut line).unwrap();

        line.clear();
        stdin.read_line(&mut line).unwrap();
        let a: Vec<i32> = line
            .split_whitespace()
            .map(|s| s.parse().expect("parse error"))
            .collect();

        line.clear();
        stdin.read_line(&mut line).unwrap();
        let mut b: Vec<i32> = line
            .split_whitespace()
            .map(|s| s.parse().expect("parse error"))
            .collect();
        b.sort();

        let mut ans: i32 = 0;
        for x in a {
            let mut fr = 0;
            let mut to = b.len() - 1;
            while fr < to {
                let mid = (fr + to) / 2;
                if x > b[mid] {
                    fr = mid + 1;
                } else {
                    to = mid;
                }
            }
            if b[fr] == x {
                ans = x;
                break;
            }
        }

        if ans == 0 {
            println!("NO")
        } else {
            println!("YES\n1 {}", ans);
        }
    }
}


You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number $$$k > 0$$$ written on it, then exactly $$$k$$$ of its neighboring cells have a number greater than $$$0$$$ written on them. Note that if the number in the cell is $$$0$$$, there is no such restriction on neighboring cells.You are allowed to take any number in the grid and increase it by $$$1$$$. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.Two cells are considered to be neighboring if they have a common edge.

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, m) = (xs[0], xs[1]);
        let mut ok = true;
        for i in 0..n {
            let xs: Vec<usize> = lines
                .next()
                .unwrap()
                .unwrap()
                .split(' ')
                .map(|x| x.parse().unwrap())
                .collect();
            if i == 0 || i == n - 1 {
                for j in 0..m {
                    if j == 0 || j == m - 1 {
                        if xs[j] > 2 {
                            ok = false;
                        }
                    } else {
                        if xs[j] > 3 {
                            ok = false;
                        }
                    }
                }
            } else {
                for j in 0..m {
                    if j == 0 || j == m - 1 {
                        if xs[j] > 3 {
                            ok = false;
                        }
                    } else {
                        if xs[j] > 4 {
                            ok = false;
                        }
                    }
                }
            }
        }
        println!("{}", if ok { "YES" } else { "NO" });
        if ok {
            for i in 0..n {
                print!("{}", if i == 0 || i == n - 1 { 2 } else { 3 });
                for _ in 1..(m - 1) {
                    print!(" {}", if i == 0 || i == n - 1 { 3 } else { 4 });
                }
                println!(" {}", if i == 0 || i == n - 1 { 2 } else { 3 });
            }
        }
    }
}


Shohag has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He can perform the following operation any number of times (possibly, zero):  Select any positive integer $$$k$$$ (it can be different in different operations).  Choose any position in the sequence (possibly the beginning or end of the sequence, or in between any two elements) and insert $$$k$$$ into the sequence at this position.  This way, the sequence $$$a$$$ changes, and the next operation is performed on this changed sequence. For example, if $$$a=[3,3,4]$$$ and he selects $$$k = 2$$$, then after the operation he can obtain one of the sequences $$$[\underline{2},3,3,4]$$$, $$$[3,\underline{2},3,4]$$$, $$$[3,3,\underline{2},4]$$$, or $$$[3,3,4,\underline{2}]$$$.Shohag wants this sequence to satisfy the following condition: for each $$$1 \le i \le |a|$$$, $$$a_i \le i$$$. Here, $$$|a|$$$ denotes the size of $$$a$$$.Help him to find the minimum number of operations that he has to perform to achieve this goal. We can show that under the constraints of the problem it's always possible to achieve this goal in a finite number of operations.

fn solution() {
    let mut nn = String::new();
    stdin().read_line(&mut nn).unwrap();
    let mut n: u32 = nn.trim().parse().unwrap();
    while n > 0 {
        let mut _numberofe = String::new();
        stdin().read_line(&mut _numberofe).unwrap();
        let _numberofe: usize = _numberofe.trim().parse().unwrap();
        n -= 1;
        let mut numbers = String::new();
        stdin().read_line(&mut numbers).unwrap();
        let numbers: Vec<i64> = numbers
            .split_whitespace()
            .map(|s| s.trim().parse().unwrap())
            .collect();
        let mut ans: i64 = 0;
        for i in 0.._numberofe {
            ans = Ord::max(ans, numbers[i] - (i + 1) as i64);
        }

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


In an ICPC contest, balloons are distributed as follows:   Whenever a team solves a problem, that team gets a balloon.  The first team to solve a problem gets an additional balloon.  A contest has 26 problems, labelled $$$\textsf{A}$$$, $$$\textsf{B}$$$, $$$\textsf{C}$$$, ..., $$$\textsf{Z}$$$. You are given the order of solved problems in the contest, denoted as a string $$$s$$$, where the $$$i$$$-th character indicates that the problem $$$s_i$$$ has been solved by some team. No team will solve the same problem twice.Determine the total number of balloons that the teams received. Note that some problems may be solved by none of the teams.

int solution(void) {
  int test_cases = 0;
  int problems = 0;
  int index = 0;
  int counting = 0;
  int letter[26] = {0};
  scanf("%d", &test_cases);
  for (int i = 0; i < test_cases; i++) {
    scanf("%d", &problems);
    char ara[problems + 1];
    scanf("%s", ara);
    for (int j = 0; j < problems; j++) {
      index = ara[j] - 'A';
      if (letter[index] == 0) {
        counting = counting + 2;
        letter[index] = 1;
      } else {
        counting++;
      }
    }
    printf("%d\n", counting);
    counting = 0;
    for (int k = 0; k < 26; k++) {
      letter[k] = 0;
    }
  }
  return 0;
}

fn solution() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("input err");
    let t: i32 = input.trim().parse().expect("input is not i32");
    for _ in 0..t {
        input.clear();
        io::stdin().read_line(&mut input).expect("input err");
        let n: usize = input.trim().parse().expect("input is not usize");

        input.clear();
        io::stdin().read_line(&mut input).expect("input err");
        let problem_set: std::collections::HashSet<char> = input.trim().chars().collect();
        println!("{}", problem_set.len() + n);
    }
}


You are a given an array $$$a$$$ of length $$$n$$$. Find a subarray $$$a[l..r]$$$ with length at least $$$k$$$ with the largest median.A median in an array of length $$$n$$$ is an element which occupies position number $$$\lfloor \frac{n + 1}{2} \rfloor$$$ after we sort the elements in non-decreasing order. For example: $$$median([1, 2, 3, 4]) = 2$$$, $$$median([3, 2, 1]) = 2$$$, $$$median([2, 1, 2, 1]) = 1$$$.Subarray $$$a[l..r]$$$ is a contiguous part of the array $$$a$$$, i. e. the array $$$a_l,a_{l+1},\ldots,a_r$$$ for some $$$1 \leq l \leq r \leq n$$$, its length is $$$r - l + 1$$$.

int solution() {
  int n;
  int k;
  int l;
  int r;
  int median;
  int min;
  int max;
  int *a;
  int *b;

  scanf("%d%d", &n, &k);
  a = malloc(n * sizeof(int));
  b = malloc(n * sizeof(int));

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

  l = 1;
  r = n + 1;
  while (l + 1 < r) {
    median = (l + r) >> 1;
    b[0] = (a[0] < median) ? -1 : 1;
    for (int i = 1; i < n; i++) {
      b[i] = b[i - 1] + ((a[i] < median) ? -1 : 1);
    }

    min = 0;
    max = b[k - 1];
    for (int i = k; i < n; i++) {
      min = (min < b[i - k]) ? min : b[i - k];
      max = (max > b[i] - min) ? max : b[i] - min;
    }

    if (max > 0) {
      l = median;
    } else {
      r = median;
    }
  }

  printf("%d", l);
}

fn solution() -> std::io::Result<()> {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf)?;
    let mut itr = buf.split_whitespace();

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

    let (n, k) = scan!(usize, usize);
    let a = scan!([usize; n]);
    let ok = |x: usize| -> bool {
        let mut b = a
            .iter()
            .map(|&y| if y >= x { 1 } else { -1 })
            .collect::<Vec<isize>>();
        for i in 1..n {
            b[i] += b[i - 1];
        }
        let mut prfmin = 0;
        let mut flag = false;
        for i in k - 1..n {
            if b[i] - prfmin > 0 {
                flag = true;

                break;
            }
            prfmin = prfmin.min(b[i - (k - 1)]);
        }
        flag
    };
    let (mut l, mut r) = (1, n);
    while l < r {
        let m = (l + r).div_ceil(2);

        if ok(m) {
            l = m;
        } else {
            r = m - 1;
        }
    }
    print!("{}", l);
    print!("\n");
    Ok(())
}


Score : <var>400</var> points

Problem Statement

Given is a string <var>S</var>. Each character in <var>S</var> is either a digit (0, ..., 9) or ?.

Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of <var>5</var> when divided by <var>13</var>? An integer may begin with <var>0</var>.

Since the answer can be enormous, print the count modulo <var>10^9+7</var>.

Constraints

<var>S</var> is a string consisting of digits (0, ..., 9) and ?.

<var>1 \leq |S| \leq 10^5</var>

Input

Input is given from Standard Input in the following format:

<var>S</var>

Output

Print the number of integers satisfying the condition, modulo <var>10^9+7</var>.

Sample Input 1

??2??5

Sample Output 1

768

For example, <var>482305, 002865,</var> and <var>972665</var> satisfy the condition.

Sample Input 2

?44

Sample Output 2

1

Only <var>044</var> satisfies the condition.

Sample Input 3

7?4

Sample Output 3

0

We may not be able to produce an integer satisfying the condition.

Sample Input 4

?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???

Sample Output 4

153716888

int solution(void) {
  char s[100001];
  scanf("%s", s);

  int s_len = strlen(s);

  long reminder_divided_by_13[13] = {0};

  reminder_divided_by_13[0] = 1;

  const int mod = 1000000007;

  long digit = 1;

  for (int i = s_len - 1; i >= 0; i--) {
    long next_reminder[13] = {0};

    if (s[i] == '?') {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 13; k++) {
          next_reminder[(j * digit + k) % 13] += reminder_divided_by_13[k];
          next_reminder[(j * digit + k) % 13] %= mod;
        }
      }
    } else {
      int j = s[i] - '0';
      for (int k = 0; k < 13; k++) {
        next_reminder[(j * digit + k) % 13] += reminder_divided_by_13[k];
        next_reminder[(j * digit + k) % 13] %= mod;
      }
    }
    digit *= 10;
    digit %= 13;

    for (int j = 0; j < 13; j++) {
      reminder_divided_by_13[j] = next_reminder[j];
    }
  }

  printf("%ld\n", reminder_divided_by_13[5]);
  return 0;
}

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 mut dp = vec![0; 13];
    let n = s.len();
    if s[n - 1] == b'?' {
        for i in 0..10 {
            dp[i] = 1;
        }
    } else {
        let x = (s[n - 1] - b'0') as usize;
        dp[x] = 1;
    }
    let mut p = 10;
    let md = 1_000_000_007;
    for i in 1..s.len() {
        let i = (s.len() - 1) - i;
        let mut tmp = vec![0; 13];
        if s[i] == b'?' {
            for c in 0..10 {
                let x = ((c * p) % 13) as usize;
                for j in 0..13 {
                    tmp[(j + x) % 13] += dp[j];
                    tmp[(j + x) % 13] %= md;
                }
            }
        } else {
            let c = (s[i] - b'0') as i64;
            let x = ((c * p) % 13) as usize;
            for j in 0..13 {
                tmp[(j + x) % 13] = dp[j];
            }
        }
        p = (p * 10) % 13;
        dp = tmp;
    }
    let ans = dp[5];
    println!("{}", ans);
}


Score : <var>200</var> points

Problem Statement

There are <var>N</var> rectangular plate materials made of special metal called AtCoder Alloy.
The dimensions of the <var>i</var>-th material are <var>A_i \times B_i</var> (<var>A_i</var> vertically and <var>B_i</var> horizontally).

Takahashi wants a rectangular plate made of AtCoder Alloy whose dimensions are exactly <var>H \times W</var>.
He is trying to obtain such a plate by choosing one of the <var>N</var> materials and cutting it if necessary.
When cutting a material, the cuts must be parallel to one of the sides of the material.
Also, the materials have fixed directions and cannot be rotated.
For example, a <var>5 \times 3</var> material cannot be used as a <var>3 \times 5</var> plate.

Out of the <var>N</var> materials, how many can produce an <var>H \times W</var> plate if properly cut?

Constraints

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

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

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

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

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

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>H</var> <var>W</var>
<var>A_1</var> <var>B_1</var>
<var>A_2</var> <var>B_2</var>
<var>:</var>
<var>A_N</var> <var>B_N</var>

Output

Print the answer.

Sample Input 1

3 5 2
10 3
5 2
2 5

Sample Output 1

2

Takahashi wants a <var>5 \times 2</var> plate.

The dimensions of the first material are <var>10 \times 3</var>. We can obtain a <var>5 \times 2</var> plate by properly cutting it.

The dimensions of the second material are <var>5 \times 2</var>. We can obtain a <var>5 \times 2</var> plate without cutting it.

The dimensions of the third material are <var>2 \times 5</var>. We cannot obtain a <var>5 \times 2</var> plate, whatever cuts are made. Note that the material cannot be rotated and used as a <var>5 \times 2</var> plate.

Sample Input 2

10 587586158 185430194
894597290 708587790
680395892 306946994
590262034 785368612
922328576 106880540
847058850 326169610
936315062 193149191
702035777 223363392
11672949 146832978
779291680 334178158
615808191 701464268

Sample Output 2

8

int solution(void) {
  int i = 0;
  int n = 0;
  int h = 0;
  int w = 0;

  int a = 0;
  int b = 0;

  int c = 0;

  scanf("%d %d %d", &n, &h, &w);

  for (i = 0; i < n; i++) {
    scanf("%d %d", &a, &b);
    if (a >= h && b >= w) {
      c++;
    }
  }

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

  return 0;
}

fn solution() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    handle.read_line(&mut buf).unwrap();
    let info: Vec<usize> = buf.split_whitespace().map(|a| a.parse().unwrap()).collect();
    let (n, h, w) = (info[0], info[1], info[2]);
    buf.clear();
    let mut count = 0;

    for _i in 0..n {
        handle.read_line(&mut buf).unwrap();
        let board: Vec<usize> = buf.split_whitespace().map(|a| a.parse().unwrap()).collect();
        if board[0] >= h && board[1] >= w {
            count += 1;
        }
        buf.clear();
    }
    println!("{}", count);
}


You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pixels have the same color. In one move, you can choose no more than two pixels of the same color and paint them into some other color (if you choose two pixels, both should be painted into the same color).What is the minimum number of moves you have to make in order to fulfill your goal?

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

  char image[4];

  for (int currentSet = 0; currentSet < numSets; ++currentSet) {
    getchar();

    image[0] = getchar();
    int numDifferentColors = 1;

    image[1] = getchar();
    getchar();
    if (image[1] != image[0]) {
      ++numDifferentColors;
    }

    image[2] = getchar();
    if ((image[2] != image[1]) && (image[2] != image[0])) {
      ++numDifferentColors;
    }

    image[3] = getchar();
    if ((image[3] != image[2]) && (image[3] != image[1]) &&
        (image[3] != image[0])) {
      ++numDifferentColors;
    }

    printf("%d\n", numDifferentColors - 1);
  }

  return 0;
}

fn solution() {
    let stdin = std::io::stdin();
    let mut s = String::new();
    stdin.read_line(&mut s).unwrap();
    let i: u32 = s.trim().parse().unwrap();
    s.clear();
    for _ in 0..i {
        let mut h = HashSet::new();
        for _ in 0..2 {
            stdin.read_line(&mut s).unwrap();
        }
        for c in s.chars() {
            if !c.is_ascii_lowercase() {
                continue;
            }
            h.insert(c);
        }
        println!("{}", h.len() - 1);
        s.clear();
    }
}


Score : <var>200</var> points

Problem Statement

Joisino is working as a receptionist at a theater.

The theater has <var>100000</var> seats, numbered from <var>1</var> to <var>100000</var>.

According to her memo, <var>N</var> groups of audiences have come so far, and the <var>i</var>-th group occupies the consecutive seats from Seat <var>l_i</var> to Seat <var>r_i</var> (inclusive).

How many people are sitting at the theater now?

Constraints

<var>1≤N≤1000</var>

<var>1≤l_i≤r_i≤100000</var>

No seat is occupied by more than one person.

All input values are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>l_1</var> <var>r_1</var>
<var>:</var>
<var>l_N</var> <var>r_N</var>

Output

Print the number of people sitting at the theater.

Sample Input 1

1
24 30

Sample Output 1

7

There are <var>7</var> people, sitting at Seat <var>24,25,26,27,28,29</var> and <var>30</var>.

Sample Input 2

2
6 8
3 3

Sample Output 2

4

int solution() {
  int x = 0;
  int i = 0;
  int total = 0;

  scanf("%d", &x);

  for (i = 0; i < x; i++) {
    int start = 0;
    int end = 0;
    scanf("%d %d", &start, &end);
    total = total + (end - start + 1);
  }

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

  return 0;
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n: i32 = s.trim().parse().ok().unwrap();
    let mut ans: i32 = 0;
    for _i in 0..n {
        let mut t = String::new();
        std::io::stdin().read_line(&mut t).ok();
        let v: Vec<i32> = t
            .split_whitespace()
            .map(|e| e.parse().ok().unwrap())
            .collect();
        ans += v[1] - v[0] + 1;
    }
    println!("{}", ans);
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers.You can remove at most one element from this array. Thus, the final length of the array is $$$n-1$$$ or $$$n$$$.Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.Recall that the contiguous subarray $$$a$$$ with indices from $$$l$$$ to $$$r$$$ is $$$a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$$$. The subarray $$$a[l \dots r]$$$ is called strictly increasing if $$$a_l < a_{l+1} < \dots < a_r$$$.

fn solution() {
    let mut str = String::new();
    let _b1 = stdin().read_line(&mut str).unwrap();
    let n: usize = str.trim().parse().unwrap();
    str.clear();
    let _b1 = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    let mut arr: Vec<i64> = Vec::new();
    loop {
        match iter.next() {
            Some(x) => arr.push(x.parse::<i64>().unwrap()),
            None => break,
        }
    }
    let mut top_vec: Vec<i64> = vec![1; n];
    let mut low_vec: Vec<i64> = vec![1; n];
    for i in 1..n {
        if arr[i] > arr[i - 1] {
            low_vec[i] = low_vec[i - 1] + 1;
        }
    }
    for i in (0..n - 1).rev() {
        if arr[i + 1] > arr[i] {
            top_vec[i] = top_vec[i + 1] + 1;
        }
    }
    let mut answ: i64 = *top_vec.iter().max().unwrap();
    for i in 1..n - 1 {
        if arr[i - 1] < arr[i + 1] {
            answ = max(answ, low_vec[i - 1] + top_vec[i + 1]);
        }
    }
    println!("{}", answ);
}


You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases.

int solution() {

  int tc;
  scanf("%d", &tc);
  while (tc--) {
    long long int n;
    long long int k;
    scanf("%lld %lld", &n, &k);
    if (k * k <= n && n % 2 == 0) {
      if (k % 2 == 0) {
        printf("YES\n");
      } else {
        printf("NO\n");
      }
    } else if (k * k <= n && n % 2 != 0) {
      if (k % 2 != 0) {
        printf("YES\n");
      } else {
        printf("NO\n");
      }
    } else {
      printf("NO\n");
    }
  }

  return 0;
}

fn solution() {
    let mut buf = String::new();
    let t = {
        stdin().read_line(&mut buf).unwrap();
        buf.trim().parse::<i64>().unwrap()
    };
    for _ in 0..t {
        buf.clear();
        stdin().read_line(&mut buf).unwrap();
        let line: Vec<i64> = buf
            .split_whitespace()
            .map(str::parse)
            .map(Result::unwrap)
            .collect();
        let (n, k): (i64, i64) = (line[0], line[1]);
        let mut possible = true;
        if n % 2 != k % 2 {
            possible = false;
        } else {
            let sum_of_odd_nums = (k - 1).pow(2);
            let last_odd = n - sum_of_odd_nums;
            if last_odd <= 2 * k - 3 {
                possible = false;
            }
        }
        if possible {
            println!("YES")
        } else {
            println!("NO")
        }
    }
}


Score : <var>200</var> points

Problem Statement

There are <var>N</var> rabbits, numbered <var>1</var> through <var>N</var>.

The <var>i</var>-th (<var>1≤i≤N</var>) rabbit likes rabbit <var>a_i</var>.
Note that no rabbit can like itself, that is, <var>a_i≠i</var>.

For a pair of rabbits <var>i</var> and <var>j</var> (<var>i＜j</var>), we call the pair (<var>i，j</var>) a friendly pair if the following condition is met.

Rabbit <var>i</var> likes rabbit <var>j</var> and rabbit <var>j</var> likes rabbit <var>i</var>.

Calculate the number of the friendly pairs.

Constraints

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

<var>1≤a_i≤N</var>

<var>a_i≠i</var>

Input

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

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

Output

Print the number of the friendly pairs.

Sample Input 1

4
2 1 4 3

Sample Output 1

2

There are two friendly pairs: <var>(1，2)</var> and <var>(3，4)</var>.

Sample Input 2

3
2 3 1

Sample Output 2

0

There are no friendly pairs.

Sample Input 3

5
5 5 5 5 1

Sample Output 3

1

There is one friendly pair: <var>(1，5)</var>.

int solution(void) {
  int N;
  scanf("%d", &N);
  int a[100000];

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

  int pairs = 0;
  for (int i = 0; i < N; i++) {
    if (a[a[i] - 1] == i + 1) {
      pairs++;
    }
  }
  pairs = pairs / 2;
  printf("%d", pairs);
  return 0;
}

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

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

    let xs: Vec<usize> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();

    let mut res = 0;
    for (i, &x) in xs.iter().enumerate() {
        if xs[x - 1] == i + 1 {
            res += 1;
        }
    }

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


Score : <var>100</var> points

Problem Statement

In this problem, we use the <var>24</var>-hour clock.

Takahashi gets up exactly at the time <var>H_1</var> : <var>M_1</var> and goes to bed exactly at the time <var>H_2</var> : <var>M_2</var>. (See Sample Inputs below for clarity.)
He has decided to study for <var>K</var> consecutive minutes while he is up.
What is the length of the period in which he can start studying?

Constraints

<var>0 \le H_1, H_2 \le 23</var>

<var>0 \le M_1, M_2 \le 59</var>

The time <var>H_1</var> : <var>M_1</var> comes before the time <var>H_2</var> : <var>M_2</var>.

<var>K \ge 1</var>

Takahashi is up for at least <var>K</var> minutes.

All values in input are integers (without leading zeros).

Input

Input is given from Standard Input in the following format:

<var>H_1</var> <var>M_1</var> <var>H_2</var> <var>M_2</var> <var>K</var>

Output

Print the length of the period in which he can start studying, as an integer.

Sample Input 1

10 0 15 0 30

Sample Output 1

270

Takahashi gets up at exactly ten in the morning and goes to bed at exactly three in the afternoon.
It takes <var>30</var> minutes to do the study, so he can start it in the period between ten o'clock and half-past two. The length of this period is <var>270</var> minutes, so we should print <var>270</var>.

Sample Input 2

10 0 12 0 120

Sample Output 2

0

Takahashi gets up at exactly ten in the morning and goes to bed at exactly noon. It takes <var>120</var> minutes to do the study, so he has to start it at exactly ten o'clock. Thus, we should print <var>0</var>.

fn solution() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse().unwrap());
    let h1: usize = itr.next().unwrap();
    let m1: usize = itr.next().unwrap();
    let h2: usize = itr.next().unwrap();
    let m2: usize = itr.next().unwrap();
    let k: usize = itr.next().unwrap();
    let t = (h2 - h1) * 60 + m2 - m1;

    println!("{}", t - k);
}


Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a.Namely, it takes several iterations to calculate value v. At the first iteration, Xenia writes a new sequence a1 or a2, a3 or a4, ..., a2n - 1 or a2n, consisting of 2n - 1 elements. In other words, she writes down the bit-wise OR of adjacent elements of sequence a. At the second iteration, Xenia writes the bitwise exclusive OR of adjacent elements of the sequence obtained after the first iteration. At the third iteration Xenia writes the bitwise OR of the adjacent elements of the sequence obtained after the second iteration. And so on; the operations of bitwise exclusive OR and bitwise OR alternate. In the end, she obtains a sequence consisting of one element, and that element is v.Let's consider an example. Suppose that sequence a = (1, 2, 3, 4). Then let's write down all the transformations (1, 2, 3, 4)  →  (1 or 2 = 3, 3 or 4 = 7)  →  (3 xor 7 = 4). The result is v = 4.You are given Xenia's initial sequence. But to calculate value v for a given sequence would be too easy, so you are given additional m queries. Each query is a pair of integers p, b. Query p, b means that you need to perform the assignment ap = b. After each query, you need to print the new value v for the new sequence a.

fn solution() {
    let mut s = String::new();
    let cin = stdin();
    cin.read_line(&mut s).unwrap();
    let p = s
        .split_whitespace()
        .map(|x| x.parse::<u32>().unwrap())
        .collect::<Vec<_>>();

    let m = p[1];

    s.clear();
    cin.read_line(&mut s).unwrap();
    let a = s
        .split_whitespace()
        .map(|x| x.parse::<u32>())
        .collect::<Result<Vec<_>, _>>()
        .unwrap();

    let mut tree = Vec::new();
    tree.push(a);
    for k in 0.. {
        let mut b = Vec::new();
        for i in 0..tree[k].len() / 2 {
            if k % 2 == 0 {
                b.push(tree[k][2 * i] | tree[k][2 * i + 1]);
            } else {
                b.push(tree[k][2 * i] ^ tree[k][2 * i + 1]);
            }
        }
        tree.push(b);
        if tree[k + 1].len() == 1 {
            break;
        }
    }

    for _ in 0..m {
        s.clear();
        cin.read_line(&mut s).unwrap();
        let mut t = s.split_whitespace();
        let mut p = t.next().unwrap().parse::<usize>().unwrap();
        p -= 1;
        let b = t.next().unwrap().parse::<u32>().unwrap();

        tree[0][p] = b;

        for k in 1..tree.len() {
            if (k - 1) % 2 == 0 {
                tree[k][p / 2] = tree[k - 1][p] | tree[k - 1][p ^ 1];
            } else {
                tree[k][p / 2] = tree[k - 1][p] ^ tree[k - 1][p ^ 1];
            }
            p /= 2;
        }

        println!("{}", tree[tree.len() - 1][0]);
    }
}


Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.Rules of the game are very simple: at first number of rounds n is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!

int solution()

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

    if (m[i] > c[i] && m[i] != c[i]) {
      a++;
    }

    if (m[i] < c[i] && m[i] != c[i]) {
      b++;
    }
  }
  if (a > b) {
    printf("Mishka");
  }

  if (a < b) {
    printf("Chris");
  }

  if (a == b) {
    printf("Friendship is magic!^^");
  }

  return 0;
}

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

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

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

    let mut score: isize = 0;

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

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

        let t = t
            .split_whitespace()
            .map(|x| x.parse::<u128>().expect("parse error"))
            .collect::<Vec<u128>>();

        let m = t[0];

        let c = t[1];

        if m > c {
            score += 1;
        } else if m < c {
            score -= 1;
        }
    }

    if score > 0 {
        println!("Mishka");
    } else if score < 0 {
        println!("Chris");
    } else {
        println!("Friendship is magic!^^");
    }
}


Score : <var>200</var> points

Problem Statement

The postal code in Atcoder Kingdom is <var>A+B+1</var> characters long, its <var>(A+1)</var>-th character is a hyphen -, and the other characters are digits from 0 through 9.

You are given a string <var>S</var>. Determine whether it follows the postal code format in Atcoder Kingdom.

Constraints

<var>1≤A,B≤5</var>

<var>|S|=A+B+1</var>

<var>S</var> consists of - and digits from 0 through 9.

Input

Input is given from Standard Input in the following format:

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

Output

Print Yes if <var>S</var> follows the postal code format in AtCoder Kingdom; print No otherwise.

Sample Input 1

3 4
269-6650

Sample Output 1

Yes

The <var>(A+1)</var>-th character of <var>S</var> is -, and the other characters are digits from 0 through 9, so it follows the format.

Sample Input 2

1 1
---

Sample Output 2

No

<var>S</var> contains unnecessary -s other than the <var>(A+1)</var>-th character, so it does not follow the format.

Sample Input 3

1 2
7444

Sample Output 3

No

fn solution() {
    let mut ab = String::new();
    io::stdin().read_line(&mut ab).expect("error");
    let vec: Vec<_> = ab.split_whitespace().collect();
    let a: usize = vec[0].parse().unwrap();
    let b: usize = vec[1].parse().unwrap();

    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("error");
    let s = s.trim();

    let s_len: usize = s.chars().count();
    if a + b + 1 != s_len || s.chars().nth(a).unwrap() != '-' {
        println!("No");
    } else {
        let s_a: String = s.chars().take(a).collect();
        let s_b: String = s.chars().skip(a + 1).collect();

        let a_is_number = s_a.parse::<u32>().is_ok();
        let b_is_number = s_b.parse::<u32>().is_ok();

        if a_is_number && b_is_number {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Score : <var>200</var> points

Problem Statement

Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes:

Red boxes, each containing <var>R</var> red balls

Green boxes, each containing <var>G</var> green balls

Blue boxes, each containing <var>B</var> blue balls

Snuke wants to get a total of exactly <var>N</var> balls by buying <var>r</var> red boxes, <var>g</var> green boxes and <var>b</var> blue boxes.
How many triples of non-negative integers <var>(r,g,b)</var> achieve this?

Constraints

All values in input are integers.

<var>1 \leq R,G,B,N \leq 3000</var>

Input

Input is given from Standard Input in the following format:

<var>R</var> <var>G</var> <var>B</var> <var>N</var>

Output

Print the answer.

Sample Input 1

1 2 3 4

Sample Output 1

4

Four triples achieve the objective, as follows:

<var>(4,0,0)</var>

<var>(2,1,0)</var>

<var>(1,0,1)</var>

<var>(0,2,0)</var>

Sample Input 2

13 1 4 3000

Sample Output 2

87058

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

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();

    let r: i64 = iter.next().unwrap().parse().unwrap();

    let g: i64 = iter.next().unwrap().parse().unwrap();

    let b: i64 = iter.next().unwrap().parse().unwrap();

    let n: i64 = iter.next().unwrap().parse().unwrap();

    let mut ans: i64 = 0;

    let weight_min: i64 = min(r, min(g, b));
    let loop_min: i64 = (n + 1) / weight_min + 1;

    let weight_max: i64 = max(r, min(g, b));
    let _loop_max: i64 = (n + 1) / weight_max + 1;

    let weight_mid: i64 = r + g + b - weight_min - weight_max;
    let loop_mid: i64 = (n + 1) / weight_mid + 1;

    for i_min in 0..loop_min {
        for i_mid in 0..loop_mid {
            let i_max: i64 = (n - weight_min * i_min - weight_mid * i_mid) / weight_max;
            if i_max < 0 {
                continue;
            }
            let num_ball: i64 = i_min * weight_min + i_mid * weight_mid + i_max * weight_max;
            if num_ball == n {
                ans += 1;
            }
        }
    }

    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    writeln!(out, "{}", ans).unwrap();
}


Score : <var>300</var> points

Problem Statement

You are given an integer sequence of length <var>N</var>, <var>a_1,a_2,...,a_N</var>.

For each <var>1≤i≤N</var>, you have three choices: add <var>1</var> to <var>a_i</var>, subtract <var>1</var> from <var>a_i</var> or do nothing.

After these operations, you select an integer <var>X</var> and count the number of <var>i</var> such that <var>a_i=X</var>.

Maximize this count by making optimal choices.

Constraints

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

<var>0≤a_i<10^5 (1≤i≤N)</var>

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

Input

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

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

Output

Print the maximum possible number of <var>i</var> such that <var>a_i=X</var>.

Sample Input 1

7
3 1 4 1 5 9 2

Sample Output 1

4

For example, turn the sequence into <var>2,2,3,2,6,9,2</var> and select <var>X=2</var> to obtain <var>4</var>, the maximum possible count.

Sample Input 2

10
0 1 2 3 4 5 6 7 8 9

Sample Output 2

3

Sample Input 3

1
99999

Sample Output 3

1

int solution() {
  int n = 0;
  scanf("%d\n", &n);
  int *a = (int *)calloc(100001, sizeof(int));
  int buf = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &buf);
    if (buf > 0) {
      a[buf - 1]++;
      a[buf]++;
      a[buf + 1]++;
    } else {
      a[buf]++;
      a[buf + 1]++;
    }
  }
  int max = 0;
  for (int i = 0; i < 100001; i++) {
    if (a[i] > max) {
      max = a[i];
    }
  }
  printf("%d\n", max);
  free(a);
  return 0;
}

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

    let mut h: HashMap<usize, usize> = HashMap::new();
    let mut p = std::usize::MAX;
    let mut q = 0;
    for i in &a {
        let x = match h.get(i) {
            Some(x) => *x,
            None => 0,
        };
        h.insert(*i, x + 1);
        if *i < p {
            p = *i;
        }
        if *i > q {
            q = *i;
        }
    }

    let mut x = 0;
    if p < std::usize::MAX {
        p += 1;
    }
    q = q.saturating_sub(1);
    for i in std::cmp::min(p, q)..std::cmp::max(p, q) + 1 {
        let mut y = 0;
        y += match h.get(&i) {
            Some(x) => *x,
            None => 0,
        };
        y += match h.get(&(i - 1)) {
            Some(x) => *x,
            None => 0,
        };
        y += match h.get(&(i + 1)) {
            Some(x) => *x,
            None => 0,
        };
        if y > x {
            x = y;
        }
    }

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


A permutation of length $$$n$$$ is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ are permutations, and $$$[1, 1]$$$, $$$[0, 1]$$$, $$$[2, 2, 1, 4]$$$ are not.There was a permutation $$$p[1 \dots n]$$$. It was merged with itself. In other words, let's take two instances of $$$p$$$ and insert elements of the second $$$p$$$ into the first maintaining relative order of elements. The result is a sequence of the length $$$2n$$$.For example, if $$$p=[3, 1, 2]$$$ some possible results are: $$$[3, 1, 2, 3, 1, 2]$$$, $$$[3, 3, 1, 1, 2, 2]$$$, $$$[3, 1, 3, 1, 2, 2]$$$. The following sequences are not possible results of a merging: $$$[1, 3, 2, 1, 2, 3$$$], [$$$3, 1, 2, 3, 2, 1]$$$, $$$[3, 3, 1, 2, 2, 1]$$$.For example, if $$$p=[2, 1]$$$ the possible results are: $$$[2, 2, 1, 1]$$$, $$$[2, 1, 2, 1]$$$. The following sequences are not possible results of a merging: $$$[1, 1, 2, 2$$$], [$$$2, 1, 1, 2]$$$, $$$[1, 2, 2, 1]$$$.Your task is to restore the permutation $$$p$$$ by the given resulting sequence $$$a$$$. It is guaranteed that the answer exists and is unique.You have to answer $$$t$$$ independent test cases.

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

  while (t--) {
    int n = 0;
    int x = 0;

    scanf("%d", &n);

    int arr[51] = {0};

    for (int i = 0; i < n * 2; i++) {
      scanf("%d", &x);

      if (arr[x] == 0) {
        arr[x] += 1;
        printf("%d ", x);
      }
    }

    printf("\n");
  }

  return 0;
}

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

    for _ in 0..t {
        let n: usize = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            buf.trim_end().parse().unwrap()
        };
        let a: Vec<usize> = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let iter = buf.split_whitespace();
            iter.map(|x| x.parse().unwrap()).collect()
        };

        let mut b = vec![false; n + 1];
        let mut ans = Vec::with_capacity(n);
        for i in 0..(n * 2) {
            if !b[a[i]] {
                ans.push(a[i].to_string());
                b[a[i]] = true;
            }
        }
        println!("{}", ans.join(" "));
    }
}


Score : <var>400</var> points

Problem Statement

Let <var>{\rm comb}(n,r)</var> be the number of ways to choose <var>r</var> objects from among <var>n</var> objects, disregarding order.
From <var>n</var> non-negative integers <var>a_1, a_2, ..., a_n</var>, select two numbers <var>a_i > a_j</var> so that <var>{\rm comb}(a_i,a_j)</var> is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.

Constraints

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

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

<var>a_1,a_2,...,a_n</var> are pairwise distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Output

Print <var>a_i</var> and <var>a_j</var> that you selected, with a space in between.

Sample Input 1

5
6 9 4 2 11

Sample Output 1

11 6

<var>\rm{comb}(a_i,a_j)</var> for each possible selection is as follows:

<var>\rm{comb}(4,2)=6</var>

<var>\rm{comb}(6,2)=15</var>

<var>\rm{comb}(6,4)=15</var>

<var>\rm{comb}(9,2)=36</var>

<var>\rm{comb}(9,4)=126</var>

<var>\rm{comb}(9,6)=84</var>

<var>\rm{comb}(11,2)=55</var>

<var>\rm{comb}(11,4)=330</var>

<var>\rm{comb}(11,6)=462</var>

<var>\rm{comb}(11,9)=55</var>

Thus, we should print <var>11</var> and <var>6</var>.

Sample Input 2

2
100 0

Sample Output 2

100 0

int solution(void) {
  int i = 0;
  int j = 0;
  int n;
  scanf("%d", &n);
  int t[100000];
  int max = 0;
  int scn = 0;
  for (; i < n; i++) {
    scanf("%d", &t[i]);
    if (t[i] > max) {
      max = t[i];
    }
  }
  for (; j < n; j++) {
    if (abs(t[j] - (max / 2)) < abs(scn - (max / 2))) {
      scn = t[j];
    }
  }
  printf("%d %d\n", max, scn);
}

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

    a.sort();
    a.reverse();

    let mut ans = a[1];
    let mut val = 1i64 << 60;
    for i in 1..n {
        let tmp = (a[0] / 2 - a[i]).abs();
        if val > tmp {
            val = tmp;
            ans = a[i];
        }
    }
    println!("{} {}", a[0], ans);
}


Score : <var>500</var> points

Problem Statement

For an integer <var>n</var> not less than <var>0</var>, let us define <var>f(n)</var> as follows:

<var>f(n) = 1</var> (if <var>n < 2</var>)

<var>f(n) = n f(n-2)</var> (if <var>n \geq 2</var>)

Given is an integer <var>N</var>. Find the number of trailing zeros in the decimal notation of <var>f(N)</var>.

Constraints

<var>0 \leq N \leq 10^{18}</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print the number of trailing zeros in the decimal notation of <var>f(N)</var>.

Sample Input 1

12

Sample Output 1

1

<var>f(12) = 12 × 10 × 8 × 6 × 4 × 2 = 46080</var>, which has one trailing zero.

Sample Input 2

5

Sample Output 2

0

<var>f(5) = 5 × 3 × 1 = 15</var>, which has no trailing zeros.

Sample Input 3

1000000000000000000

Sample Output 3

124999999999999995

int solution(void) {
  long long int n = 0;
  long long int ans = 0;
  long long int count = 1;
  scanf("%lld", &n);

  if (n % 2 != 0) {
    printf("0\n");
  } else {
    int under = 10;
    while (1) {
      if (under * count > n) {
        break;
      }
      ans += n / (under * count);
      count *= 5;
    }
    printf("%lld\n", ans);
  }
  return 0;
}

fn solution() {
    let n: u64 = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_end().parse().unwrap()
    };
    println!("{}", {
        let mut ans: u64 = 0;
        let mut t: u64 = 10;
        while n >= t {
            ans += n / t;
            t *= 5;
        }
        if n.is_multiple_of(2) {
            ans
        } else {
            0
        }
    });
}


Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).Players take turns, Alice is first. Each player during his or her turn has to move the chip 1, 2 or k cells to the left (so, if the chip is currently in the cell i, the player can move it into cell i - 1, i - 2 or i - k). The chip should not leave the borders of the paper strip: it is impossible, for example, to move it k cells to the left if the current cell has number i < k. The player who can't make a move loses the game.Who wins if both participants play optimally?Alice and Bob would like to play several games, so you should determine the winner in each game.

int solution() {
  int t;
  int n;
  int k;
  scanf("%d", &t);
  while (t > 0) {
    t--;
    scanf("%d %d", &n, &k);
    if (n < k) {
      if (n % 3) {
        printf("Alice\n");
      } else {
        printf("Bob\n");
      }
    } else {
      if (k % 3 == 0) {
        n %= k + 1;
        if (n == k || n % 3) {
          printf("Alice\n");
        } else {
          printf("Bob\n");
        }
      } else {
        if (n % 3) {
          printf("Alice\n");
        } else {
          printf("Bob\n");
        }
      }
    }
  }

  return 0;
}

fn solution() {
    let mut s = String::new();
    stdin()
        .read_line(&mut s)
        .expect("Did not enter a correct string");
    if let Some('\n') = s.chars().next_back() {
        s.pop();
    }
    if let Some('\r') = s.chars().next_back() {
        s.pop();
    }
    let mut i = s.parse::<i32>().unwrap();
    while i > 0 {
        i -= 1;
        s.clear();
        stdin()
            .read_line(&mut s)
            .expect("Did not enter a correct string");
        if let Some('\n') = s.chars().next_back() {
            s.pop();
        }
        if let Some('\r') = s.chars().next_back() {
            s.pop();
        }
        let mut s = s.split(" ");
        let n = s.next().unwrap().parse::<i32>().unwrap();

        let k = s.next().unwrap().parse::<i32>().unwrap();

        if k % 3 != 0 {
            let c = if n % 3 == 0 { "Bob" } else { "Alice" };
            println!("{}", c);
        } else {
            let c = if n % (k + 1) % 3 == 0 && (n + 1) % (k + 1) != 0 {
                "Bob"
            } else {
                "Alice"
            };
            println!("{}", c);
        }
    }
}


Score : <var>100</var> points

Problem Statement

The window of Takahashi's room has a width of <var>A</var>. There are two curtains hung over the window, each of which has a horizontal length of <var>B</var>. (Vertically, the curtains are long enough to cover the whole window.)

We will close the window so as to minimize the total horizontal length of the uncovered part of the window.
Find the total horizontal length of the uncovered parts of the window then.

Constraints

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

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

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the total horizontal length of the uncovered parts of the window.

Sample Input 1

12 4

Sample Output 1

4

We have a window with a horizontal length of <var>12</var>, and two curtains, each of length <var>4</var>, that cover both ends of the window, for example. The uncovered part has a horizontal length of <var>4</var>.

Sample Input 2

20 15

Sample Output 2

0

If the window is completely covered, print <var>0</var>.

Sample Input 3

20 30

Sample Output 3

0

Each curtain may be longer than the window.

int solution(void) {
  int a = 0;
  int b = 0;
  scanf("%d %d", &a, &b);
  if (a - 2 * b > 0) {
    printf("%d", a - (2 * b));
  } else {
    printf("0");
  }
}

fn solution() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    let mut nums = buf.split_whitespace().map(|n| i32::from_str(n).unwrap());
    let (A, B) = (nums.next().unwrap(), nums.next().unwrap());

    let ans = A - 2 * B;
    println!("{}", i32::max(0, ans));
}


Score : <var>200</var> points

Problem Statement

Find the largest square number not exceeding <var>N</var>. Here, a square number is an integer that can be represented as the square of an integer.

Constraints

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

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

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print the largest square number not exceeding <var>N</var>.

Sample Input 1

10

Sample Output 1

9

<var>10</var> is not square, but <var>9 = 3 × 3</var> is. Thus, we print <var>9</var>.

Sample Input 2

81

Sample Output 2

81

Sample Input 3

271828182

Sample Output 3

271821169

int solution(void) {
  int n = 0;
  int a = 0;
  scanf("%d", &n);
  a = sqrt(n);
  n = a * a;
  printf("%d\n", n);
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n: i32 = s.trim().parse().ok().unwrap();

    let mut k = 0;
    let mut ans = 1;
    while k * k <= n {
        ans = k * k;
        k += 1;
    }
    println!("{}", ans);
}


Polycarp is sad — New Year is coming in few days but there is still no snow in his city. To bring himself New Year mood, he decided to decorate his house with some garlands.The local store introduced a new service this year, called "Build your own garland". So you can buy some red, green and blue lamps, provide them and the store workers will solder a single garland of them. The resulting garland will have all the lamps you provided put in a line. Moreover, no pair of lamps of the same color will be adjacent to each other in this garland!For example, if you provide $$$3$$$ red, $$$3$$$ green and $$$3$$$ blue lamps, the resulting garland can look like this: "RGBRBGBGR" ("RGB" being the red, green and blue color, respectively). Note that it's ok to have lamps of the same color on the ends of the garland.However, if you provide, say, $$$1$$$ red, $$$10$$$ green and $$$2$$$ blue lamps then the store workers won't be able to build any garland of them. Any garland consisting of these lamps will have at least one pair of lamps of the same color adjacent to each other. Note that the store workers should use all the lamps you provided.So Polycarp has bought some sets of lamps and now he wants to know if the store workers can build a garland from each of them.

fn solution() {
    outset! { buf }
    input! {
        t: usize,
        rgb: [(usize, usize, usize); t],
    }
    for x in rgb.iter() {
        let mut v = [x.0, x.1, x.2];
        v.sort();
        if v[2] - 1 <= v[0] + v[1] {
            output!(buf, "Yes\n");
        } else {
            output!(buf, "No\n");
        }
    }
}


Score : <var>300</var> points

Problem Statement

There are <var>N</var> squares arranged in a row from left to right. The height of the <var>i</var>-th square from the left is <var>H_i</var>.

For each square, you will perform either of the following operations once:

Decrease the height of the square by <var>1</var>.

Do nothing.

Determine if it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right.

Constraints

All values in input are integers.

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

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

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>H_1</var> <var>H_2</var> <var>...</var> <var>H_N</var>

Output

If it is possible to perform the operations so that the heights of the squares are non-decreasing from left to right, print Yes; otherwise, print No.

Sample Input 1

5
1 2 1 1 3

Sample Output 1

Yes

You can achieve the objective by decreasing the height of only the second square from the left by <var>1</var>.

Sample Input 2

4
1 3 2 1

Sample Output 2

No

Sample Input 3

5
1 2 3 4 5

Sample Output 3

Yes

Sample Input 4

1
1000000000

Sample Output 4

Yes

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

    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let _n: i32 = buf.trim().parse().unwrap();

    buf.clear();
    stdin.read_line(&mut buf).ok();
    let hs: Vec<i32> = buf.split_whitespace().map(|w| w.parse().unwrap()).collect();

    let mut last = std::i32::MAX;
    for &h in hs.iter().rev() {
        if last >= h {
            last = h;
        } else if last == h - 1 {
            last = h - 1;
        } else {
            println!("No");
            std::process::exit(0);
        }
    }
    println!("Yes");
}


Score : <var>500</var> points

Problem Statement

We have <var>N</var> locked treasure boxes, numbered <var>1</var> to <var>N</var>.

A shop sells <var>M</var> keys. The <var>i</var>-th key is sold for <var>a_i</var> yen (the currency of Japan), and it can unlock <var>b_i</var> of the boxes: Box <var>c_{i1}</var>, <var>c_{i2}</var>, <var>...</var>, <var>c_{i{b_i}}</var>. Each key purchased can be used any number of times.

Find the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print <var>-1</var>.

Constraints

All values in input are integers.

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

<var>1 \leq M \leq 10^3</var>

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

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

<var>1 \leq c_{i1} < c_{i2} < ... < c_{i{b_i}} \leq N</var>

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>M</var>
<var>a_1</var> <var>b_1</var>
<var>c_{11}</var> <var>c_{12}</var> <var>...</var> <var>c_{1{b_1}}</var>
<var>:</var>
<var>a_M</var> <var>b_M</var>
<var>c_{M1}</var> <var>c_{M2}</var> <var>...</var> <var>c_{M{b_M}}</var>

Output

Print the minimum cost required to unlock all the treasure boxes.
If it is impossible to unlock all of them, print <var>-1</var>.

Sample Input 1

2 3
10 1
1
15 1
2
30 2
1 2

Sample Output 1

25

We can unlock all the boxes by purchasing the first and second keys, at the cost of <var>25</var> yen, which is the minimum cost required.

Sample Input 2

12 1
100000 1
2

Sample Output 2

-1

We cannot unlock all the boxes.

Sample Input 3

4 6
67786 3
1 3 4
3497 1
2
44908 3
2 3 4
2156 3
2 3 4
26230 1
2
86918 1
3

Sample Output 3

69942

int solution(void) {
  int n;
  int m;
  int i;
  int j;
  int tmp;
  int big = 1000000;
  scanf("%d %d", &n, &m);
  int com = pow(2, n);
  int a[m];
  int b[m];
  int c[m][12];
  int dp[com];
  for (i = 0; i < com; i++) {
    dp[i] = big;
  }

  for (i = 0; i < m; i++) {
    scanf("%d %d", &a[i], &b[i]);
    for (j = 0; j < b[i]; j++) {
      scanf("%d", &c[i][j]);
    }
    tmp = 0;
    for (j = 0; j < b[i]; j++) {
      tmp += pow(2, c[i][j] - 1);
    }
    if (dp[tmp] > a[i]) {
      dp[tmp] = a[i];
    }
    for (j = 0; j < com; j++) {
      if (dp[j] != big && dp[j | tmp] > dp[j] + a[i]) {
        dp[j | tmp] = dp[j] + a[i];
      }
    }
  }
  if (dp[com - 1] == big) {
    printf("-1");
  } else {
    printf("%d", dp[com - 1]);
  }
  return 0;
}

fn solution() {
    let (n, m) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut it = buf.split_whitespace();
        let n: u32 = it.next().unwrap().parse().unwrap();
        let m: usize = it.next().unwrap().parse().unwrap();
        (n, m)
    };
    let mut a: Vec<i32> = Vec::new();
    let mut b: Vec<i32> = Vec::new();
    let mut c: Vec<Vec<i32>> = Vec::new();
    for _ in 0..m {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut it = buf.split_whitespace();
        let _a: i32 = it.next().unwrap().parse().unwrap();
        let _b: i32 = it.next().unwrap().parse().unwrap();
        a.push(_a);
        b.push(_b);

        let mut buf2 = String::new();
        std::io::stdin().read_line(&mut buf2).unwrap();
        let mut it2 = buf2.split_whitespace();
        let _c = (0.._b)
            .map(|_| it2.next().unwrap().parse().unwrap())
            .collect::<Vec<i32>>();
        c.push(_c);
    }

    let mx = 10i32.pow(9);
    let mut dp = vec![vec![mx; 1 << n]; m + 1];
    dp[0][0] = 0;

    for i in 1..m + 1 {
        let key = c.get(i - 1).unwrap();
        let cost = a.get(i - 1).unwrap();
        let mut k = 0;
        for j in key {
            k |= 1 << (j - 1)
        }
        for j in 0..(1 << n) {
            dp[i][j | k] = min(dp[i][j | k], dp[i - 1][j] + cost);
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
        }
    }
    if dp[m][(1 << n) - 1] == mx {
        println!("{}", -1);
    } else {
        println!("{}", dp[m][(1 << n) - 1]);
    }
}


You are given an array $$$a$$$ consisting of $$$n$$$ integer numbers.You have to color this array in $$$k$$$ colors in such a way that:   Each element of the array should be colored in some color;  For each $$$i$$$ from $$$1$$$ to $$$k$$$ there should be at least one element colored in the $$$i$$$-th color in the array;  For each $$$i$$$ from $$$1$$$ to $$$k$$$ all elements colored in the $$$i$$$-th color should be distinct. Obviously, such coloring might be impossible. In this case, print "NO". Otherwise print "YES" and any coloring (i.e. numbers $$$c_1, c_2, \dots c_n$$$, where $$$1 \le c_i \le k$$$ and $$$c_i$$$ is the color of the $$$i$$$-th element of the given array) satisfying the conditions above. If there are multiple answers, you can print any.

int solution() {
  int n;
  int k;
  scanf("%d%d", &n, &k);
  int a[n];
  int cnt = 0;
  int hash[10000] = {0};
  int max = 0;
  int color[10000] = {0};

  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    hash[a[i]]++;
    if (hash[a[i]] > max) {
      max = hash[a[i]];
    }
  }
  int q = 1;
  int temp = 1;

  for (int i = 0; i < 10000; ++i) {
    if (hash[i] != 0) {
      color[i] += temp;
      temp += hash[i];
    }

    q++;
  }
  if (max > k || temp < k) {
    printf("NO\n");
  } else {
    printf("YES\n");
    for (int i = 0; i < n; ++i) {
      if (color[a[i]] % k != 0) {
        printf("%d ", color[a[i]] % k);
      } else {
        printf("%d ", k);
      }
      color[a[i]]++;
    }
  }
}

fn solution() {
    let (_n, k): (usize, usize) = {
        let mut read_buf = String::new();
        io::stdin().read_line(&mut read_buf).unwrap();
        let mut read_buf = read_buf.split_whitespace();
        (
            read_buf.next().unwrap().parse().unwrap(),
            read_buf.next().unwrap().parse().unwrap(),
        )
    };
    let a: Vec<usize> = {
        let mut read_buf = String::new();
        io::stdin().read_line(&mut read_buf).unwrap();
        read_buf
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect()
    };

    let mut ans_flag = true;
    let mut cnt: Vec<usize> = Vec::new();
    let mut max_cnt = 0;
    cnt.resize(5000 + 1, 0);
    for x in &a {
        cnt[*x] += 1;
        if cnt[*x] > max_cnt {
            max_cnt = cnt[*x];
        }
        if max_cnt > k {
            ans_flag = false;
            break;
        }
    }

    if ans_flag {
        println!("YES");

        let mut last_colors = k;
        let mut changed: Vec<bool> = Vec::new();
        changed.resize(5000 + 1, false);
        for x in &a {
            if !changed[*x] && cnt[*x] <= last_colors {
                let c = cnt[*x];
                cnt[*x] = last_colors;
                last_colors -= c;
                changed[*x] = true;
            }
            print!("{} ", cnt[*x]);
            cnt[*x] -= 1;
        }
    } else {
        println!("NO");
    }
}


Score : <var>400</var> points

Problem Statement

There are <var>N</var> people standing on the <var>x</var>-axis.
Let the coordinate of Person <var>i</var> be <var>x_i</var>.
For every <var>i</var>, <var>x_i</var> is an integer between <var>0</var> and <var>10^9</var> (inclusive).
It is possible that more than one person is standing at the same coordinate.

You will given <var>M</var> pieces of information regarding the positions of these people.
The <var>i</var>-th piece of information has the form <var>(L_i, R_i, D_i)</var>.
This means that Person <var>R_i</var> is to the right of Person <var>L_i</var> by <var>D_i</var> units of distance, that is, <var>x_{R_i} - x_{L_i} = D_i</var> holds.

It turns out that some of these <var>M</var> pieces of information may be incorrect.
Determine if there exists a set of values <var>(x_1, x_2, ..., x_N)</var> that is consistent with the given pieces of information.

Constraints

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

<var>0 \leq M \leq 200</var> <var>000</var>

<var>1 \leq L_i, R_i \leq N</var> (<var>1 \leq i \leq M</var>)

<var>0 \leq D_i \leq 10</var> <var>000</var> (<var>1 \leq i \leq M</var>)

<var>L_i \neq R_i</var> (<var>1 \leq i \leq M</var>)

If <var>i \neq j</var>, then <var>(L_i, R_i) \neq (L_j, R_j)</var> and <var>(L_i, R_i) \neq (R_j, L_j)</var>.

<var>D_i</var> are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>M</var>
<var>L_1</var> <var>R_1</var> <var>D_1</var>
<var>L_2</var> <var>R_2</var> <var>D_2</var>
<var>:</var>
<var>L_M</var> <var>R_M</var> <var>D_M</var>

Output

If there exists a set of values <var>(x_1, x_2, ..., x_N)</var> that is consistent with all given pieces of information, print Yes; if it does not exist, print No.

Sample Input 1

3 3
1 2 1
2 3 1
1 3 2

Sample Output 1

Yes

Some possible sets of values <var>(x_1, x_2, x_3)</var> are <var>(0, 1, 2)</var> and <var>(101, 102, 103)</var>.

Sample Input 2

3 3
1 2 1
2 3 1
1 3 5

Sample Output 2

No

If the first two pieces of information are correct, <var>x_3 - x_1 = 2</var> holds, which is contradictory to the last piece of information.

Sample Input 3

4 3
2 1 1
2 3 5
3 4 2

Sample Output 3

Yes

Sample Input 4

10 3
8 7 100
7 9 100
9 8 100

Sample Output 4

No

Sample Input 5

100 0

Sample Output 5

Yes

int solution() {
  int i;
  int u;
  int w;
  int D;
  int N;
  int M;
  scanf("%d %d", &N, &M);
  list **adj = (list **)malloc(sizeof(list *) * (N + 1));
  list *d = (list *)malloc(sizeof(list) * M * 2);
  for (i = 0; i < M; i++) {
    scanf("%d %d %d", &u, &w, &D);
    d[i * 2].v = w;
    d[(i * 2) + 1].v = u;
    d[i * 2].len = D;
    d[(i * 2) + 1].len = -D;
    d[i * 2].next = adj[u];
    d[(i * 2) + 1].next = adj[w];
    adj[u] = &(d[i * 2]);
    adj[w] = &(d[(i * 2) + 1]);
  }

  int flag[100001] = {};
  int q[100001];
  int head;
  int tail;
  long long dist[100001];
  list *p;
  for (i = 1; i <= N; i++) {
    if (flag[i] == 1) {
      continue;
    }
    flag[i] = 1;
    dist[i] = 0;
    q[0] = i;
    for (head = 0, tail = 1; head < tail; head++) {
      u = q[head];
      for (p = adj[u]; p != NULL; p = p->next) {
        w = p->v;
        if (flag[w] == 0) {
          flag[w] = 1;
          dist[w] = dist[u] + p->len;
          q[tail++] = w;
        } else if (dist[w] != dist[u] + p->len) {
          break;
        }
      }
      if (p != NULL) {
        break;
      }
    }
    if (head < tail) {
      break;
    }
  }
  if (i > N) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  fflush(stdout);
  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 m: usize = itr.next().unwrap().parse().unwrap();

    let mut g = vec![Vec::new(); n];
    for _ in 0..m {
        let l = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let r = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let c: i64 = itr.next().unwrap().parse().unwrap();

        g[l].push((r, c));
        g[r].push((l, -c));
    }

    const INF: i64 = 1 << 30;
    let mut d = vec![INF; n];
    let mut q = std::collections::VecDeque::new();

    for i in 0..n {
        if d[i] == INF {
            d[i] = 100000;
        }
        q.clear();
        q.push_back(i);
        while let Some(v) = q.pop_front() {
            for &(nv, c) in g[v].iter() {
                if d[nv] == INF {
                    d[nv] = d[v] + c;
                    q.push_back(nv);
                } else {
                    if d[nv] != d[v] + c {
                        println!("No");
                        return;
                    }
                }
            }
        }
    }

    println!("Yes");
}


int solution() {

  int H;
  int W = 0;
  scanf("%d %d", &H, &W);

  char C[2 * H][W];

  for (int i = 0; i < H; i++) {
    scanf("%s", C[i]);
    printf("%s\n", C[i]);
    printf("%s\n", C[i]);
  }

  return 0;
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<usize> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
    for _ in 0..v[0] {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        println!("{}\n{}", s.trim(), s.trim());
    }
}


Breadth First Search

  Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.

Input

  In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format:

$u$ $k$ $v_1$ $v_2$ ... $v_k$

$u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$.

Constraints

$1 \leq n \leq 100$

Output

  For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs.

Sample Input 1

4
1 2 2 4
2 1 4
3 0
4 1 3

Sample Output 1

1 0
2 1
3 2
4 1

Reference

Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.

fn solution() {
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let n: usize = buf.trim().parse().unwrap();
    let mut g = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        let _ = std::io::stdin().read_line(&mut buf).ok();
        let mut buf = buf.split_whitespace();
        let id: usize = buf.next().unwrap().parse().unwrap();
        let k: usize = buf.next().unwrap().parse().unwrap();
        let mut e = Vec::new();
        for _ in 0..k {
            let p: usize = buf.next().unwrap().parse().unwrap();
            e.push(p);
        }
        g.push((id, e));
    }
    let mut dis: Vec<i64> = vec![-1; n];
    dis[0] = 0;
    for distance in 0..n {
        for i in 0..n {
            if dis[i] == distance as i64 {
                for j in &g[i].1 {
                    if dis[*j - 1] == -1 {
                        dis[*j - 1] = distance as i64 + 1;
                    }
                }
            }
        }
    }

    for (i, d) in dis.iter().enumerate() {
        println!("{} {}", i + 1, d);
    }
}


A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and there is a constraint: the total number of flowers in a large bouquet should be odd. Each of the initial bouquets can be a part of at most one large bouquet. If an initial bouquet becomes a part of a large bouquet, all its flowers are included in the large bouquet.Determine the maximum possible number of large bouquets Vasya can make.

int solution() {
  int count = 0;
  scanf("%d", &count);
  int inp = 0;
  int first = 0;
  int second = 0;
  for (int i = 0; i < count; i++) {
    scanf("%d", &inp);
    if (inp % 2) {
      first++;
    } else {
      second++;
    }
  }
  int answer = 0;
  if (first > second) {
    answer = second + (first - second) / 3;
  } else {
    answer = first;
  }
  printf("%d", answer);
  return 0;
}

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

    let n: u32 = n.trim().parse().expect("Error while parsing!");

    let mut arr = String::new();

    std::io::stdin()
        .read_line(&mut arr)
        .expect("Reading arr error!");
    let tmp = arr.split(" ");
    let vec = tmp.collect::<Vec<&str>>();
    let mut chet = 0;
    let mut nechet = 0;
    for x in vec {
        let y: u32 = x.trim().parse().expect("Error while parsing!");
        if y.is_multiple_of(2) {
            chet += 1;
        } else {
            nechet += 1;
        }
    }
    if nechet * 2 <= n {
        println!("{}", nechet);
    } else {
        println!("{}", chet + ((nechet - chet) / 3));
    }
}


Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has.Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares). All wallets are also produced in form of rectangles (possibly squares).A bill $$$x \times y$$$ fits into some wallet $$$h \times w$$$ if either $$$x \le h$$$ and $$$y \le w$$$ or $$$y \le h$$$ and $$$x \le w$$$. Bills can overlap with each other in a wallet and an infinite amount of bills can fit into a wallet. That implies that all the bills Polycarp currently have fit into a wallet if every single one of them fits into it independently of the others.Now you are asked to perform the queries of two types:  $$$+~x~y$$$ — Polycarp earns a bill of size $$$x \times y$$$;  $$$?~h~w$$$ — Polycarp wants to check if all the bills he has earned to this moment fit into a wallet of size $$$h \times w$$$. It is guaranteed that there is at least one query of type $$$1$$$ before the first query of type $$$2$$$ and that there is at least one query of type $$$2$$$ in the input data.For each query of type $$$2$$$ print "YES" if all the bills he has earned to this moment fit into a wallet of given size. Print "NO" otherwise.

int solution() {

  int n;
  scanf("%d", &n);
  int max_x = -1;
  int max_y = -1;
  while (n--) {
    char c = getchar();
    int a;
    int b;

    scanf("%c %d %d", &c, &a, &b);
    int temp = a < b ? a : b;
    b = a > b ? a : b;
    a = temp;
    if (c == '+') {
      if (a > max_x) {
        max_x = a;
      }
      if (b > max_y) {
        max_y = b;
      }
    } else if (c == '?') {

      if (a >= max_x && b >= max_y) {
        printf("YES\n");
      } else {
        printf("NO\n");
      }
    }
  }
  return 0;
}

fn solution() -> io::Result<()> {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input)?;

    let mut output = String::with_capacity(input.len());

    let mut tokens = input.split_whitespace();

    let _ = tokens.next().unwrap().parse::<usize>().unwrap();

    let mut max_min = 0;
    let mut max_max = 0;

    use std::cmp::{max, min};

    while let Some(kind) = tokens.next() {
        let a = tokens.next().unwrap().parse::<u32>().unwrap();
        let b = tokens.next().unwrap().parse::<u32>().unwrap();

        match kind {
            "+" => {
                max_min = max(max_min, min(a, b));
                max_max = max(max_max, max(a, b));
            }
            "?" => {
                let ans = max_min <= min(a, b) && max_max <= max(a, b);
                output.push_str(if ans { "YES\n" } else { "NO\n" });
            }
            _ => (),
        }
    }

    write!(io::stdout(), "{}", output)
}


Score : <var>100</var> points

Problem Statement

Two students of AtCoder Kindergarten are fighting over candy packs.

There are three candy packs, each of which contains <var>a</var>, <var>b</var>, and <var>c</var> candies, respectively.

Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.

Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

Constraints

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

Input

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

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

Output

If it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.

Sample Input 1

10 30 20

Sample Output 1

Yes

Give the pack with <var>30</var> candies to one student, and give the two packs with <var>10</var> and <var>20</var> candies to the other. Then, each gets <var>30</var> candies.

Sample Input 2

30 30 100

Sample Output 2

No

In this case, the student who gets the pack with <var>100</var> candies always has more candies than the other.

Note that every pack must be given to one of them.

Sample Input 3

56 25 31

Sample Output 3

Yes

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

  if (a + b == c || a + c == b || b + c == a) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

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

    let mut xs: Vec<u64> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();
    xs.sort();

    println!("{}", if xs[0] + xs[1] == xs[2] { "Yes" } else { "No" });
}


void solution(int *numbers, int size) {
  const SHRINK = 1.3 int gap = size;
  while (gap > 1) {
    gap = gap / SHRINK;
    int i = 0;
    while ((i + gap) < size) {
      if (numbers[i] > numbers[i + gap]) {
        int tmp = numbers[i];
        numbers[i] = numbers[i + gap];
        numbers[i + gap] = tmp;
      }
      i++;
    }
  }
}

fn solution<T: Ord>(arr: &mut [T]) {
    let mut gap = arr.len();
    let shrink = 1.3;
    let mut sorted = false;

    while !sorted {
        gap = (gap as f32 / shrink).floor() as usize;
        if gap <= 1 {
            gap = 1;
            sorted = true;
        }
        for i in 0..arr.len() - gap {
            let j = i + gap;
            if arr[i] > arr[j] {
                arr.swap(i, j);
                sorted = false;
            }
        }
    }
}


Score : <var>200</var> points

Problem Statement

Given is a sequence of <var>N</var> integers <var>A_1, \ldots, A_N</var>.

Find the (multiplicative) inverse of the sum of the inverses of these numbers, <var>\frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}</var>.

Constraints

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

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

Input

Input is given from Standard Input in the following format:

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

Output

Print a decimal number (or an integer) representing the value of <var>\frac{1}{\frac{1}{A_1} + \ldots + \frac{1}{A_N}}</var>.

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

Sample Input 1

2
10 30

Sample Output 1

7.5

<var>\frac{1}{\frac{1}{10} + \frac{1}{30}} = \frac{1}{\frac{4}{30}} = \frac{30}{4} = 7.5</var>.

Printing 7.50001, 7.49999, and so on will also be accepted.

Sample Input 2

3
200 200 200

Sample Output 2

66.66666666666667

<var>\frac{1}{\frac{1}{200} + \frac{1}{200} + \frac{1}{200}} = \frac{1}{\frac{3}{200}} = \frac{200}{3} = 66.6666...</var>.

Printing 6.66666e+1 and so on will also be accepted.

Sample Input 3

1
1000

Sample Output 3

1000

<var>\frac{1}{\frac{1}{1000}} = 1000</var>.

Printing +1000.0 and so on will also be accepted.

int solution() {
  int num = 0;
  int i = 0;
  double sum = 0.0;
  double ans = 0.0;
  scanf("%d", &num);
  int yoshio[num];
  for (i = 0; i < num; i++) {
    scanf("%d", &yoshio[i]);
    sum += 1 / (double)yoshio[i];
  }
  ans = 1 / sum;
  printf("%lf\n", ans);
  return 0;
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let vec_str: Vec<String> = s.split_whitespace().map(|x| x.to_string()).collect();
    let _N = vec_str[0].parse::<i32>().unwrap();

    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let vec_str: Vec<String> = s.split_whitespace().map(|x| x.to_string()).collect();
    let a_vec: Vec<f64> = vec_str.iter().map(|x| x.parse::<f64>().unwrap()).collect();

    println!("{:?}", 1.0 / a_vec.iter().fold(0.0, |sum, x| sum + 1.0 / x));
}