Score : <var>100</var> points

Problem Statement

Three poles stand evenly spaced along a line. Their heights are <var>a</var>, <var>b</var> and <var>c</var> meters, from left to right.
We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, <var>b-a = c-b</var>.

Determine whether the arrangement of the poles is beautiful.

Constraints

<var>1 \leq a,b,c \leq 100</var>

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

Input

Input is given from Standard Input in the following format:

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

Output

Print YES if the arrangement of the poles is beautiful; print NO otherwise.

Sample Input 1

2 4 6

Sample Output 1

YES

Since <var>4-2 = 6-4</var>, this arrangement of poles is beautiful.

Sample Input 2

2 5 6

Sample Output 2

NO

Since <var>5-2 \neq 6-5</var>, this arrangement of poles is not beautiful.

Sample Input 3

3 2 1

Sample Output 3

YES

Since <var>1-2 = 2-3</var>, this arrangement of poles is beautiful.

fn solution() {
    let stdin = io::stdin();
    let mut s = String::new();
    stdin.read_line(&mut s).ok();
    s.pop();
    let mut abc: Vec<i32> = Vec::new();
    let it = s.split_whitespace();
    for arg in it {
        abc.push(i32::from_str(arg).expect("e"));
    }
    let a = abc[0];
    let b = abc[1];
    let c = abc[2];
    if b - a == c - b {
        println!("YES");
    } else {
        println!("NO");
    }
}


You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally?

int solution() {
  int n;
  int x;
  int y;
  scanf("%d%d%d", &n, &x, &y);
  int d[n];
  int good = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &d[i]);
    if (d[i] <= x) {
      good++;
    }
  }
  if (x > y) {
    printf("%d", n);
  } else {
    printf("%d", (good + 1) / 2);
  }
}

fn solution() {
    let (n, a, b): (usize, u32, u32) = {
        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(),
            read_buf.next().unwrap().parse().unwrap(),
        )
    };
    let cnt = {
        let mut res = 0;
        let mut read_buf = String::new();
        io::stdin().read_line(&mut read_buf).unwrap();
        for i in read_buf.split_whitespace() {
            let i: u32 = i.parse().unwrap();
            if i <= a {
                res += 1;
            }
        }
        res
    };

    if a > b {
        println!("{}", n);
    } else {
        println!("{}", (cnt + 1) / 2);
    }
}


Toggling Cases

  Write a program which converts uppercase/lowercase letters to lowercase/uppercase for a given string.

Input

  A string is given in a line.

Output

  Print the converted string in a line. Note that you do not need to convert any characters other than alphabetical letters.

Constraints

The length of the input string < 1200

Sample Input

fAIR, LATER, OCCASIONALLY CLOUDY.

Sample Output

Fair, later, occasionally cloudy.

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    for c in s.trim().chars() {
        let n = c as u8;
        print!(
            "{}",
            if (65..=90).contains(&n) {
                (n + 32) as char
            } else if (97..=122).contains(&n) {
                (n - 32) as char
            } else {
                c
            }
        );
    }
    println!();
}


Score : <var>200</var> points

Problem Statement

It is November <var>18</var> now in Japan. By the way, <var>11</var> and <var>18</var> are adjacent Lucas numbers.

You are given an integer <var>N</var>. Find the <var>N</var>-th Lucas number.

Here, the <var>i</var>-th Lucas number <var>L_i</var> is defined as follows:

<var>L_0=2</var>

<var>L_1=1</var>

<var>L_i=L_{i-1}+L_{i-2} (i≥2)</var>

Constraints

<var>1≤N≤86</var>

It is guaranteed that the answer is less than <var>10^{18}</var>.

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

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print the <var>N</var>-th Lucas number.

Sample Input 1

5

Sample Output 1

11

<var>L_0=2</var>

<var>L_1=1</var>

<var>L_2=L_0+L_1=3</var>

<var>L_3=L_1+L_2=4</var>

<var>L_4=L_2+L_3=7</var>

<var>L_5=L_3+L_4=11</var>

Thus, the <var>5</var>-th Lucas number is <var>11</var>.

Sample Input 2

86

Sample Output 2

939587134549734843

int solution(void) {
  int n;
  unsigned long long a = -1;
  unsigned long long b = 2;
  scanf("%d", &n);
  while (n-- > 0) {
    b = a + b;
    a = b - a;
  }
  printf("%llu\n", b);
  return 0;
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().ok().unwrap();
    let mut v: Vec<i64> = Vec::new();

    v.push(2);
    v.push(1);
    for i in 2..(n + 1) {
        let x = v[i - 1] + v[i - 2];
        v.push(x);
    }
    println!("{}", v[n]);
}


You are given an integer $$$n$$$. You have to change the minimum number of digits in it in such a way that the resulting number does not have any leading zeroes and is divisible by $$$7$$$.If there are multiple ways to do it, print any of them. If the given number is already divisible by $$$7$$$, leave it unchanged.

fn solution() {
    let mut buf = String::new();
    let handle = io::stdin();
    let _ = handle.read_line(&mut buf);
    let ntc: usize = buf.trim().parse().unwrap();
    for _ in 1..=ntc {
        buf.clear();
        let _ = handle.read_line(&mut buf);
        let num: usize = buf.trim().parse().unwrap();
        let m10 = num % 10;
        let m7 = num % 7;
        if m10 >= m7 {
            println!("{}", num - m7)
        } else {
            println!("{}", num + 7 - m7);
        }
    }
}


Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every ticket exactly in two, but he didn’t think it was enough and Leonid also threw part of the pieces away. Having seen this, Vasya got terrified but still tried to restore the collection. He chose several piece pairs and glued each pair together so that each pair formed a lucky ticket. The rest of the pieces Vasya threw away reluctantly. Thus, after the gluing of the 2t pieces he ended up with t tickets, each of which was lucky.When Leonid tore the tickets in two pieces, one piece contained the first several letters of his number and the second piece contained the rest.Vasya can glue every pair of pieces in any way he likes, but it is important that he gets a lucky ticket in the end. For example, pieces 123 and 99 can be glued in two ways: 12399 and 99123.What maximum number of tickets could Vasya get after that?

int solution() {
  int n;
  int a;
  static int cnt[3];

  scanf("%d", &n);
  while (n-- > 0) {
    scanf("%d", &a);
    cnt[a % 3]++;
  }
  printf("%d\n", (cnt[0] / 2) + (cnt[1] < cnt[2] ? cnt[1] : cnt[2]));
  return 0;
}

fn solution() -> io::Result<()> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf)?;
    buf.clear();
    io::stdin().read_line(&mut buf)?;
    let a: Vec<usize> = buf
        .split_ascii_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    let mut rem = [0; 3];
    for i in a {
        rem[i % 3] += 1;
    }

    let ans = rem[0] / 2 + cmp::min(rem[1], rem[2]);
    println!("{}", ans);

    Ok(())
}


The elections in which three candidates participated have recently ended. The first candidate received $$$a$$$ votes, the second one received $$$b$$$ votes, the third one received $$$c$$$ votes. For each candidate, solve the following problem: how many votes should be added to this candidate so that he wins the election (i.e. the number of votes for this candidate was strictly greater than the number of votes for any other candidate)?Please note that for each candidate it is necessary to solve this problem independently, i.e. the added votes for any candidate do not affect the calculations when getting the answer for the other two candidates.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long a[3];
    long long max = 0;
    long long c = 0;
    for (int i = 0; i < 3; i++) {
      scanf("%lld", &a[i]);
      if (max < a[i]) {
        max = a[i];
      }
    }
    for (int i = 0; i < 3; i++) {
      if (max == a[i]) {
        c += 1;
      }
    }
    for (int i = 0; i < 3; i++) {
      if (max == 0 && a[i] == 0) {
        printf("1 ");
      } else if (a[i] < max) {
        printf("%lld ", (max - a[i]) + 1);
      } else if (a[i] == max && c == 1) {
        printf("%lld ", max - a[i]);
      } else if (a[i] == max && c > 1) {
        printf("%lld ", max - a[i] + 1);
      }
    }
    printf("\n");
  }
}

fn solution() {
    let (i, o) = (io::stdin(), io::stdout());
    let mut o = bw::new(o.lock());
    for l in i.lock().lines().skip(1) {
        let v = l
            .unwrap()
            .split(' ')
            .map(|w| w.parse::<u64>().unwrap())
            .collect::<Vec<_>>();
        let (m, c) = v[1..].iter().fold((v[0], 0), |(m, c), &x| {
            if x > m {
                (x, 0)
            } else if x == m {
                (m, 1)
            } else {
                (m, c)
            }
        });
        for &x in v.iter() {
            write!(o, "{} ", if x == m { c } else { m - x + 1 }).ok();
        }
        writeln!(o).ok();
    }
}


Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.Katya had no problems with completing this task. Will you do the same?

int solution() {
  long long n = 0;
  scanf("%lli", &n);

  long long a = -1;
  long long b = -1;

  if (n > 2) {
    if (n % 2 == 0) {
      long long m = n / 2;
      a = m * m - 1;
      b = m * m + 1;
    } else {
      long long k = (n - 1) / 2;
      long long m = 1 + k;
      b = 2 * k * m;
      a = m * m + k * k;
    }
  }

  if (a != -1) {
    printf("%lli %lli\n", a, b);
  } else {
    printf("-1\n");
  }

  return 0;
}

fn solution() {
    let stdin = std::io::stdin();
    let mut s = String::new();
    let _lines = stdin.lock().read_line(&mut s).unwrap();
    let a = s.trim().parse::<u64>().unwrap();
    if a <= 2 {
        println!("-1");
        return;
    }
    if (a & 0x01u64) != 0 {
        println!("{} {}", ((a * a) - 1) / 2, (a * a).div_ceil(2));
    } else {
        println!("{} {}", ((a / 2) * (a / 2)) - 1, ((a / 2) * (a / 2)) + 1);
    }
}


A sequence $$$a = [a_1, a_2, \ldots, a_l]$$$ of length $$$l$$$ has an ascent if there exists a pair of indices $$$(i, j)$$$ such that $$$1 \le i < j \le l$$$ and $$$a_i < a_j$$$. For example, the sequence $$$[0, 2, 0, 2, 0]$$$ has an ascent because of the pair $$$(1, 4)$$$, but the sequence $$$[4, 3, 3, 3, 1]$$$ doesn't have an ascent.Let's call a concatenation of sequences $$$p$$$ and $$$q$$$ the sequence that is obtained by writing down sequences $$$p$$$ and $$$q$$$ one right after another without changing the order. For example, the concatenation of the $$$[0, 2, 0, 2, 0]$$$ and $$$[4, 3, 3, 3, 1]$$$ is the sequence $$$[0, 2, 0, 2, 0, 4, 3, 3, 3, 1]$$$. The concatenation of sequences $$$p$$$ and $$$q$$$ is denoted as $$$p+q$$$.Gyeonggeun thinks that sequences with ascents bring luck. Therefore, he wants to make many such sequences for the new year. Gyeonggeun has $$$n$$$ sequences $$$s_1, s_2, \ldots, s_n$$$ which may have different lengths. Gyeonggeun will consider all $$$n^2$$$ pairs of sequences $$$s_x$$$ and $$$s_y$$$ ($$$1 \le x, y \le n$$$), and will check if its concatenation $$$s_x + s_y$$$ has an ascent. Note that he may select the same sequence twice, and the order of selection matters.Please count the number of pairs ($$$x, y$$$) of sequences $$$s_1, s_2, \ldots, s_n$$$ whose concatenation $$$s_x + s_y$$$ contains an ascent.

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

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

    let n = arr[0];

    let mut ix = 1;

    let mut s = vec![];
    for _i in 0..n {
        let m = arr[ix];
        ix += 1;
        s.push(arr[ix..ix + m as usize].to_vec());
        ix += m as usize;
    }

    let mut info = vec![];
    for arr in s.iter() {
        let _ma = *arr.iter().max().unwrap();
        let _mi = *arr.iter().min().unwrap();

        let is_non_increasing = arr[..].windows(2).all(|w| w[0] >= w[1]);
        if is_non_increasing {
            info.push((arr[0], *arr.iter().rev().next().unwrap()));
        }
    }

    let mut ans = n * n;

    info.sort();

    let mut idx = 0;
    for i in info.iter() {
        let last = i.1;

        let mut l = 0;
        let mut r = info.len();
        while l < r {
            let m = (l + r) / 2;

            let v = info[m].0;
            if v > last {
                r = m;
            } else {
                l = m + 1;
            }
        }

        ans -= l as i64;
        idx += 1;
    }
    println!("{}", ans);
}


Vasya has recently got a job as a cashier at a local store. His day at work is $$$L$$$ minutes long. Vasya has already memorized $$$n$$$ regular customers, the $$$i$$$-th of which comes after $$$t_{i}$$$ minutes after the beginning of the day, and his service consumes $$$l_{i}$$$ minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer. Vasya is a bit lazy, so he likes taking smoke breaks for $$$a$$$ minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?

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

  int time_between = 0;
  int sessions = 0;
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      time_between = t[i] - 0;
    } else {
      time_between = t[i] - (t[i - 1] + l[i - 1]);
    }
    sessions += time_between / a;
  }
  if (n > 0) {
    time_between = L - (t[n - 1] + l[n - 1]);
  } else {
    time_between = L;
  }
  sessions += time_between / a;
  printf("%d\n", sessions);
  return 0;
}

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

    let arr: Vec<_> = buffer
        .split_whitespace()
        .map(|x| x.parse::<u32>().unwrap())
        .collect();
    let n = arr[0] as usize;
    let l = arr[1];
    let a = arr[2];
    let mut prev = 0;
    let mut ans = 0;
    for i in 0..n {
        let ti = arr[3 + i * 2];
        let li = arr[4 + i * 2];
        let d = ti - prev;
        ans += d / a;
        prev = ti + li;
    }
    ans += (l - prev) / a;
    println!("{}", ans);
}


You are given an array $$$a$$$ consisting of $$$n$$$ positive integers, and an array $$$b$$$, with length $$$n$$$. Initially $$$b_i=0$$$ for each $$$1 \leq i \leq n$$$.In one move you can choose an integer $$$i$$$ ($$$1 \leq i \leq n$$$), and add $$$a_i$$$ to $$$b_i$$$ or subtract $$$a_i$$$ from $$$b_i$$$. What is the minimum number of moves needed to make $$$b$$$ increasing (that is, every element is strictly greater than every element before it)?

int solution(void) {
  int n;
  scanf("%d", &n);
  long long int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
  }
  long long int zeropos;
  long long int minmov = LLONG_MAX;
  for (zeropos = 0; zeropos < n; zeropos++) {
    long long int movcount = 0;
    long long b[n];
    b[zeropos] = 0;
    for (int i = zeropos + 1; i < n; i++) {
      long long int mintimes = 1 + (b[i - 1] / a[i]);
      b[i] = a[i] * (mintimes);
      movcount += mintimes;
    }
    for (int i = zeropos - 1; i >= 0; i--) {
      long long int mintimes = 1 + ((-b[i + 1]) / a[i]);
      b[i] = (-a[i]) * (mintimes);
      movcount += mintimes;
    }
    if (movcount < minmov) {
      minmov = movcount;
    }
  }
  printf("%lld\n", minmov);
  return 0;
}

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

    let mut ans = -1;
    for i in 0..n {
        let mut tmp = 0;

        let mut lst = 0i64;
        for j in (0..i).rev() {
            tmp += lst / arr[j] + 1;
            lst = (lst / arr[j] + 1) * arr[j];
        }
        lst = 0;
        for j in i + 1..n {
            tmp += lst / arr[j] + 1;
            lst = (lst / arr[j] + 1) * arr[j];
        }

        if tmp < ans || ans == -1 {
            ans = tmp;
        }
    }
    println!("{}", ans);
}


Score : <var>700</var> points

Problem Statement

You are given an integer <var>N</var>.
Build an undirected graph with <var>N</var> vertices with indices <var>1</var> to <var>N</var> that satisfies the following two conditions:

The graph is simple and connected.

There exists an integer <var>S</var> such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is <var>S</var>.

It can be proved that at least one such graph exists under the constraints of this problem.

Constraints

All values in input are integers.

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

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

In the first line, print the number of edges, <var>M</var>, in the graph you made. In the <var>i</var>-th of the following <var>M</var> lines, print two integers <var>a_i</var> and <var>b_i</var>, representing the endpoints of the <var>i</var>-th edge.

The output will be judged correct if the graph satisfies the conditions.

Sample Input 1

3

Sample Output 1

2
1 3
2 3

For every vertex, the sum of the indices of the vertices adjacent to that vertex is <var>3</var>.

fn solution() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let ng = if n % 2 == 0 { n + 1 } else { n };
    let mut res = Vec::new();
    for i in 1..n {
        for j in i + 1..n + 1 {
            if i + j == ng {
                continue;
            }
            res.push((i, j));
        }
    }
    println!("{}", res.len());
    for &p in &res {
        println!("{} {}", p.0, p.1);
    }
}


Let's call a positive integer composite if it has at least one divisor other than $$$1$$$ and itself. For example:  the following numbers are composite: $$$1024$$$, $$$4$$$, $$$6$$$, $$$9$$$;  the following numbers are not composite: $$$13$$$, $$$1$$$, $$$2$$$, $$$3$$$, $$$37$$$. You are given a positive integer $$$n$$$. Find two composite integers $$$a,b$$$ such that $$$a-b=n$$$.It can be proven that solution always exists.

int solution() {
  int n = 0;
  scanf("%d", &n);
  if (n % 2 == 0) {
    printf("%d %d", n + 4, 4);
  } else {
    printf("%d %d", n + 9, 9);
  }
  return 0;
}

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

    let n: i32 = s.trim().parse().expect("");

    println!("{} {}", 9 * n, 8 * n);
}


Score : <var>100</var> points

Problem Statement

You are given an integer <var>N</var> that has exactly four digits in base ten.
How many times does 2 occur in the base-ten representation of <var>N</var>?

Constraints

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

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print the answer.

Sample Input 1

1222

Sample Output 1

3

2 occurs three times in 1222. By the way, this contest is held on December <var>22</var> (JST).

Sample Input 2

3456

Sample Output 2

0

Sample Input 3

9592

Sample Output 3

1

int solution(void) {
  int n = 0;
  int ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= 4; i++) {
    if (n % 10 == 2) {
      ans += 1;
    }
    n /= 10;
  }
  printf("%d", ans);
  return 0;
}

fn solution() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    handle.read_line(&mut buf).unwrap();
    let mut count = 0;
    for c in buf.chars() {
        if c == '2' {
            count += 1;
        }
    }
    println!("{}", count);
}


void solution(int *arr, int n) {
  int writes = 0;

  for (int cycle_start = 0; cycle_start <= n - 2; cycle_start++) {
    int item = arr[cycle_start];
    int pos = cycle_start;

    for (int i = cycle_start + 1; i < n; i++) {
      if (arr[i] < item) {
        pos++;
      }
    }

    if (pos == cycle_start) {
      continue;
    }

    while (item == arr[pos]) {
      pos += 1;
    }

    if (pos != cycle_start) {
      int temp;

      temp = item;
      item = arr[pos];
      arr[pos] = temp;

      writes++;
    }

    while (pos != cycle_start) {
      pos = cycle_start;

      for (int i = cycle_start + 1; i < n; i++) {
        if (arr[i] < item) {
          pos += 1;
        }
      }

      while (item == arr[pos]) {
        pos += 1;
      }

      if (item != arr[pos]) {
        int temp;

        temp = item;
        item = arr[pos];
        arr[pos] = temp;

        writes++;
      }
    }
  }
}

fn solution(arr: &mut [i32]) {
    for cycle_start in 0..arr.len() {
        let mut item = arr[cycle_start];
        let mut pos = cycle_start;
        for i in arr.iter().skip(cycle_start + 1) {
            if *i < item {
                pos += 1;
            }
        }
        if pos == cycle_start {
            continue;
        }
        while item == arr[pos] {
            pos += 1;
        }
        std::mem::swap(&mut arr[pos], &mut item);
        while pos != cycle_start {
            pos = cycle_start;
            for i in arr.iter().skip(cycle_start + 1) {
                if *i < item {
                    pos += 1;
                }
            }
            while item == arr[pos] {
                pos += 1;
            }
            std::mem::swap(&mut arr[pos], &mut item);
        }
    }
}


Score : <var>200</var> points

Problem Statement

There are <var>N</var> gems. The value of the <var>i</var>-th gem is <var>V_i</var>.

You will choose some of these gems, possibly all or none, and get them.

However, you need to pay a cost of <var>C_i</var> to get the <var>i</var>-th gem.

Let <var>X</var> be the sum of the values of the gems obtained, and <var>Y</var> be the sum of the costs paid.

Find the maximum possible value of <var>X-Y</var>.

Constraints

All values in input are integers.

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

<var>1 \leq C_i, V_i \leq 50</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>V_1</var> <var>V_2</var> <var>...</var> <var>V_N</var>
<var>C_1</var> <var>C_2</var> <var>...</var> <var>C_N</var>

Output

Print the maximum possible value of <var>X-Y</var>.

Sample Input 1

3
10 2 5
6 3 4

Sample Output 1

5

If we choose the first and third gems, <var>X = 10 + 5 = 15</var> and <var>Y = 6 + 4 = 10</var>.
We have <var>X-Y = 5</var> here, which is the maximum possible value.

Sample Input 2

4
13 21 6 19
11 30 6 15

Sample Output 2

6

Sample Input 3

1
1
50

Sample Output 3

0

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

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let vs = buf
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect::<Vec<_>>();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let cs = buf
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect::<Vec<_>>();

    let mut ans: i32 = 0;
    for i in 0..n {
        let vc = vs[i] - cs[i];
        if vc > 0 {
            ans += vc;
        }
    }

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


You are playing another computer game, and now you have to slay $$$n$$$ monsters. These monsters are standing in a circle, numbered clockwise from $$$1$$$ to $$$n$$$. Initially, the $$$i$$$-th monster has $$$a_i$$$ health.You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the health of the targeted monster by $$$1$$$ (deals $$$1$$$ damage to it). Furthermore, when the health of some monster $$$i$$$ becomes $$$0$$$ or less than $$$0$$$, it dies and explodes, dealing $$$b_i$$$ damage to the next monster (monster $$$i + 1$$$, if $$$i < n$$$, or monster $$$1$$$, if $$$i = n$$$). If the next monster is already dead, then nothing happens. If the explosion kills the next monster, it explodes too, damaging the monster after it and possibly triggering another explosion, and so on.You have to calculate the minimum number of bullets you have to fire to kill all $$$n$$$ monsters in the circle.

int solution() {
  int t;
  scanf("%d", &t);
  long long int res[t];
  for (int i = 0; i < t; i++) {
    int n;
    scanf("%d", &n);
    long long int health[n];
    long long int damage[n];
    long long int bullets = 0;
    for (int j = 0; j < n; j++) {
      scanf("%lld %lld", &health[j], &damage[j]);
    }

    for (int j = 1; j < n; j++) {
      if (damage[j - 1] < health[j]) {
        bullets += health[j] - damage[j - 1];
        health[j] = damage[j - 1];
      }
    }
    if (damage[n - 1] < health[0]) {
      bullets += health[0] - damage[n - 1];
      health[0] = damage[n - 1];
    }

    long long int small = health[0];
    for (int j = 1; j < n; j++) {
      if (health[j] < small) {
        small = health[j];
      }
    }
    bullets += small;

    res[i] = bullets;
  }

  for (int i = 0; i < t; i++) {
    printf("%lld\n", res[i]);
  }

  return 0;
}

fn solution() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
    let mut s = String::new();
    for _ in 0..t {
        let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
        let mut ls: Vec<u64> = vec![0; n];
        let mut bs: Vec<u64> = vec![0; n];
        let mut cs: Vec<u64> = vec![0; n];
        let mut total: u64 = 0;
        for i in 0..n {
            let xs: Vec<u64> = lines
                .next()
                .unwrap()
                .unwrap()
                .split(' ')
                .map(|x| x.parse().unwrap())
                .collect();
            ls[i] = xs[0];
            bs[i] = xs[1];
            if i > 0 {
                cs[i] = ls[i].saturating_sub(bs[i - 1]);
                total += cs[i];
            }
        }
        cs[0] = ls[0].saturating_sub(bs[n - 1]);
        total += cs[0];
        let mut ans: u64 = u64::max_value();
        for i in 0..n {
            ans = min(ans, total - cs[i] + ls[i]);
        }
        s.push_str(format!("{}\n", ans).as_str());
    }
    print!("{}", s);
}


You are given a grid, consisting of $$$2$$$ rows and $$$n$$$ columns. Each cell of this grid should be colored either black or white.Two cells are considered neighbours if they have a common border and share the same color. Two cells $$$A$$$ and $$$B$$$ belong to the same component if they are neighbours, or if there is a neighbour of $$$A$$$ that belongs to the same component with $$$B$$$.Let's call some bicoloring beautiful if it has exactly $$$k$$$ components.Count the number of beautiful bicolorings. The number can be big enough, so print the answer modulo $$$998244353$$$.

int solution(int argc, char **argv) {
  int n;
  int k;
  scanf("%d %d", &n, &k);

  int64_t **same = (int64_t **)calloc(n, sizeof(int64_t *));
  int64_t **opposite = (int64_t **)calloc(n, sizeof(int64_t *));

  for (int i = 0; i < n; i++) {
    same[i] = (int64_t *)calloc(k, sizeof(int64_t));
    opposite[i] = (int64_t *)calloc(k, sizeof(int64_t));
  }

  same[0][0] = 2;

  opposite[0][0] = 0;
  opposite[0][1] = 2;

  for (int i = 1; i < n; i++) {

    for (int j = 0; j < k; j++) {
      same[i][j] += same[i - 1][j] + 2 * opposite[i - 1][j];
      opposite[i][j] += opposite[i - 1][j];
    }

    for (int j = 1; j < k; j++) {
      same[i][j] += same[i - 1][j - 1];
      opposite[i][j] += 2 * same[i - 1][j - 1];
    }

    for (int j = 2; j < k; j++) {
      opposite[i][j] += opposite[i - 1][j - 2];
    }

    for (int j = 0; j < k; j++) {
      same[i][j] = same[i][j] % 998244353;
      opposite[i][j] = opposite[i][j] % 998244353;
    }
  }
  int total = (same[n - 1][k - 1] + opposite[n - 1][k - 1]) % 998244353;
  printf("%d\n", total);
  return (EXIT_SUCCESS);
}

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

    handle.read_to_string(&mut buffer).expect("stdin");

    let arr: Vec<_> = buffer.split_whitespace().collect();

    let n = arr[0].parse::<u32>().unwrap();
    let k = arr[1].parse::<u32>().unwrap();

    let mut dp: [[[u32; 4]; 2001]; 2] = [[[0; 4]; 2001]; 2];
    dp[1][1][3] = 1;
    dp[1][1][0] = 1;
    dp[1][2][1] = 1;
    dp[1][2][2] = 1;
    let mo: u32 = 998244353;

    for i in 2..=n {
        let x: usize = (i % 2) as usize;
        let y: usize = ((i + 1) % 2) as usize;
        for j in 1..=k {
            dp[x][j as usize][0] = 0;
            dp[x][j as usize][1] = 0;
            dp[x][j as usize][2] = 0;
            dp[x][j as usize][3] = 0;
        }
        for j in 1..=k {
            dp[x][j as usize][3] = (dp[x][j as usize][3]
                + dp[y][j as usize][2]
                + dp[y][j as usize][1]
                + dp[y][j as usize][3])
                % mo;
            if j >= 1 {
                dp[x][j as usize][3] = (dp[x][j as usize][3] + dp[y][(j - 1) as usize][0]) % mo;
            }
            dp[x][j as usize][0] = (dp[x][j as usize][0]
                + dp[y][j as usize][2]
                + dp[y][j as usize][1]
                + dp[y][j as usize][0])
                % mo;
            if j >= 1 {
                dp[x][j as usize][0] = (dp[x][j as usize][0] + dp[y][(j - 1) as usize][3]) % mo;
            }
            dp[x][j as usize][2] = (dp[x][j as usize][2] + dp[y][j as usize][2]) % mo;
            if j >= 2 {
                dp[x][j as usize][2] = (dp[x][j as usize][2] + dp[y][(j - 2) as usize][1]) % mo;
            }
            if j >= 1 {
                dp[x][j as usize][2] = (dp[x][j as usize][2]
                    + dp[y][(j - 1) as usize][0]
                    + dp[y][(j - 1) as usize][3])
                    % mo;
            }
            dp[x][j as usize][1] = (dp[x][j as usize][1] + dp[y][j as usize][1]) % mo;
            if j >= 2 {
                dp[x][j as usize][1] = (dp[x][j as usize][1] + dp[y][(j - 2) as usize][2]) % mo;
            }
            if j >= 1 {
                dp[x][j as usize][1] = (dp[x][j as usize][1]
                    + dp[y][(j - 1) as usize][0]
                    + dp[y][(j - 1) as usize][3])
                    % mo;
            }
        }
    }
    let mut ans: u32 = 0;
    for i in 0..4 {
        let x = (n % 2) as usize;
        ans = (ans + dp[x][k as usize][i]) % mo;
    }
    println!("{}", ans);
}


Score : <var>400</var> points

Problem Statement

You are given integers <var>N</var> and <var>M</var>.

Consider a sequence <var>a</var> of length <var>N</var> consisting of positive integers such that <var>a_1 + a_2 + ... + a_N</var> = <var>M</var>. Find the maximum possible value of the greatest common divisor of <var>a_1, a_2, ..., a_N</var>.

Constraints

All values in input are integers.

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

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the maximum possible value of the greatest common divisor of a sequence <var>a_1, a_2, ..., a_N</var> that satisfies the condition.

Sample Input 1

3 14

Sample Output 1

2

Consider the sequence <var>(a_1, a_2, a_3) = (2, 4, 8)</var>. Their greatest common divisor is <var>2</var>, and this is the maximum value.

Sample Input 2

10 123

Sample Output 2

3

Sample Input 3

100000 1000000000

Sample Output 3

10000

int solution() {
  int n;
  int m;
  scanf("%d%d", &n, &m);
  if (n == 1) {
    printf("%d", m);
    return 0;
  }
  for (int i = m / 2; i; i--) {
    if (!(m % i) && m / i >= n) {
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}

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

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

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();

    let mut ans = 1;
    let mut gcd = 1;

    while gcd * gcd <= m {
        if m.is_multiple_of(gcd) {
            if n <= m / gcd {
                ans = std::cmp::max(gcd, ans);
            }
            let gcd2 = m / gcd;
            if n <= m / gcd2 {
                ans = std::cmp::max(gcd2, ans);
            }
        }
        gcd += 1;
    }

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


Capitalize

Write a program which replace all the lower-case letters of a given text with the corresponding captital letters.

Input

A text including lower-case letters, periods, and space is given in a line. The number of characters in the text is less than or equal to 200.

Output

Print the converted text.

Sample Input

this is a pen.

Output for the Sample Input

THIS IS A PEN.

fn solution() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let chars: Vec<char> = buf
        .trim()
        .chars()
        .map(|c| c.to_uppercase().next().unwrap())
        .collect();
    println!("{}", chars.iter().collect::<String>());
}


Score : <var>100</var> points

Problem Statement

Decades have passed since the beginning of AtCoder Beginner Contest.

The contests are labeled as ABC001, ABC002, <var>...</var> from the first round, but after the <var>999</var>-th round ABC999, a problem occurred: how the future rounds should be labeled?

In the end, the labels for the rounds from the <var>1000</var>-th to the <var>1998</var>-th are decided: ABD001, ABD002, <var>...</var>, ABD999.

You are given an integer <var>N</var> between <var>1</var> and <var>1998</var> (inclusive). Print the first three characters of the label of the <var>N</var>-th round of AtCoder Beginner Contest.

Constraints

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

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

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print the first three characters of the label of the <var>N</var>-th round of AtCoder Beginner Contest.

Sample Input 1

999

Sample Output 1

ABC

The <var>999</var>-th round of AtCoder Beginner Contest is labeled as ABC999.

Sample Input 2

1000

Sample Output 2

ABD

The <var>1000</var>-th round of AtCoder Beginner Contest is labeled as ABD001.

Sample Input 3

1481

Sample Output 3

ABD

The <var>1481</var>-th round of AtCoder Beginner Contest is labeled as ABD482.

int solution() {
  int N = 0;

  scanf("%d", &N);
  printf((N < 1000) ? "ABC" : "ABD");
}

fn solution() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).expect("Failed to read line");
    let n: u32 = n.trim().parse().expect("Failed to parse");
    if n >= 1000 {
        println!("ABD");
    } else {
        println!("ABC");
    }
}


Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!Your task is to write a program which calculates two things:  The maximum beauty difference of flowers that Pashmak can give to Parmida.  The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.

int solution() {
  long long num;
  long long i = 0;
  scanf("%lld", &num);
  long long arr[num];
  long long max = 0;
  long long min = 1000000000;
  for (i = 0; i < num; ++i) {
    scanf("%lld", &arr[i]);
    if (arr[i] > max) {
      max = arr[i];
    }
    if (arr[i] < min) {
      min = arr[i];
    }
  }
  long long countmax = 0;
  long long countmin = 0;
  for (i = 0; i < num; ++i) {
    if (arr[i] == max) {
      countmax += 1;
    }
    if (arr[i] == min) {
      countmin += 1;
    }
  }
  long long diff = max - min;
  long long ways = countmax * countmin;
  if (max == min) {
    ways = (countmax * (countmax - 1)) / 2;
  }
  printf("%lld %lld", diff, ways);
  return 0;
}

fn solution() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n: u32 = buf.trim().parse().unwrap();
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut s = buf.split_whitespace();
    let mut b = Vec::new();
    for _ in 0..n {
        let t: u32 = s.next().unwrap().trim().parse().unwrap();
        b.push(t);
    }
    let max = *b.iter().max().unwrap();
    let min = *b.iter().min().unwrap();
    if max != min {
        let cnt1 = b.iter().filter(|x| **x == min).count() as u64;
        let cnt2 = b.iter().filter(|x| **x == max).count() as u64;
        println!("{} {}", max - min, cnt1 * cnt2);
    } else {
        let cnt = b.iter().filter(|x| **x == min).count() as u64;
        println!("0 {}", cnt * (cnt - 1) / 2);
    }
}


Score : <var>200</var> points

Problem Statement

You are given two integers <var>K</var> and <var>S</var>.

Three variable <var>X, Y</var> and <var>Z</var> takes integer values satisfying <var>0≤X,Y,Z≤K</var>.

How many different assignments of values to <var>X, Y</var> and <var>Z</var> are there such that <var>X + Y + Z = S</var>?

Constraints

<var>2≤K≤2500</var>

<var>0≤S≤3K</var>

<var>K</var> and <var>S</var> are integers.

Input

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

<var>K</var> <var>S</var>

Output

Print the number of the triples of <var>X, Y</var> and <var>Z</var> that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of <var>X, Y</var> and <var>Z</var> that satisfy the condition:

<var>X = 0, Y = 0, Z = 2</var>

<var>X = 0, Y = 2, Z = 0</var>

<var>X = 2, Y = 0, Z = 0</var>

<var>X = 0, Y = 1, Z = 1</var>

<var>X = 1, Y = 0, Z = 1</var>

<var>X = 1, Y = 1, Z = 0</var>

Sample Input 2

5 15

Sample Output 2

1

The maximum value of <var>X + Y + Z</var> is <var>15</var>, achieved by one triple of <var>X, Y</var> and <var>Z</var>.

int solution() {
  int *k = malloc(sizeof(int));
  int *s = malloc(sizeof(int));
  int resp = 0;
  scanf("%d%d", k, s);
  for (int x = 0; x <= *k; ++x) {
    for (int y = 0; y <= *k; ++y) {
      int z = (*s) - x - y;
      if (*k >= z && z >= 0) {
        ++resp;
      }
    }
  }
  printf("%d\n", resp);
  free(k);
  free(s);
}

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

    let k = input[0] + 1;
    let s = input[1];
    let mut count = 0;

    for x in 0..k {
        for y in 0..k {
            let t = x + y;
            if t > s {
                break;
            }
            if (s - t) < k {
                count += 1;
            }
        }
    }

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


Score : <var>500</var> points

Problem Statement

A robot is put at the origin in a two-dimensional plane.
Initially, the robot is facing in the positive <var>x</var>-axis direction.

This robot will be given an instruction sequence <var>s</var>.
<var>s</var> consists of the following two kinds of letters, and will be executed in order from front to back.

F : Move in the current direction by distance <var>1</var>.

T : Turn <var>90</var> degrees, either clockwise or counterclockwise.

The objective of the robot is to be at coordinates <var>(x, y)</var> after all the instructions are executed.
Determine whether this objective is achievable.

Constraints

<var>s</var> consists of F and T.

<var>1 \leq |s| \leq 8</var> <var>000</var>

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

<var>|x|, |y| \leq |s|</var>

Input

Input is given from Standard Input in the following format:

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

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

FTFFTFFF
4 2

Sample Output 1

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T.

Sample Input 2

FTFFTFFF
-2 -2

Sample Output 2

Yes

The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T.

Sample Input 3

FF
1 0

Sample Output 3

No

Sample Input 4

TF
1 0

Sample Output 4

No

Sample Input 5

FFTTFF
0 0

Sample Output 5

Yes

The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T.

Sample Input 6

TTTT
1 0

Sample Output 6

No

fn solution() {
    let mut s = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut s = s.split_whitespace();
    let op = s
        .next()
        .unwrap()
        .split("T")
        .map(|a| a.len())
        .collect::<Vec<_>>();
    let x: i32 = s.next().unwrap().parse().unwrap();
    let y: i32 = s.next().unwrap().parse().unwrap();
    let mut xs = std::collections::BTreeSet::new();
    let mut ys = std::collections::BTreeSet::new();
    xs.insert(op[0] as i32);
    ys.insert(0);
    if op.len() > 1 {
        for (i, f) in op[1..].iter().enumerate() {
            let f = *f as i32;
            if f == 0 {
                continue;
            }
            if i & 1 == 0 {
                ys = ys
                    .into_iter()
                    .flat_map(|a| vec![a + f, a - f])
                    .collect::<std::collections::BTreeSet<_>>();
            } else {
                xs = xs
                    .into_iter()
                    .flat_map(|a| vec![a + f, a - f])
                    .collect::<std::collections::BTreeSet<_>>();
            }
        }
    }
    if xs.contains(&x) && ys.contains(&y) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Madoka decided to participate in an underground sports programming competition. And there was exactly one task in it:A square table of size $$$n \times n$$$, where $$$n$$$ is a multiple of $$$k$$$, is called good if only the characters '.' and 'X' are written in it, as well as in any subtable of size $$$1 \times k$$$ or $$$k \times 1$$$, there is at least one character 'X'. In other words, among any $$$k$$$ consecutive vertical or horizontal cells, there must be at least one containing the character 'X'.Output any good table that has the minimum possible number of characters 'X', and also the symbol 'X' is written in the cell $$$(r, c)$$$. Rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, columns are numbered from $$$1$$$ to $$$n$$$ from left to right.

int solution() {

  int t;
  scanf("%d", &t);

  int n[t];
  int k[t];
  int r[t];
  int c[t];

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

  for (i = 0; i < t; i++) {
    r[i]--;
    c[i]--;
    int row = 0;
    int col = 0;

    for (int row = 0; row < n[i]; row++) {
      for (int col = 0; col < n[i]; col++) {
        if ((row - r[i] - (col - c[i])) % k[i] == 0) {
          printf("X");
        } else {
          printf(".");
        }
      }
      printf("\n");
    }
  }

  return 0;
}

fn solution() {
    let std_in = stdin();
    let mut input = Scanner::new(std_in.lock());

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

    let t: usize = input.token();
    for _ in 0..t {
        let (n, k, r, c): (usize, usize, usize, usize) =
            (input.token(), input.token(), input.token(), input.token());
        let (r, c) = (r - 1, c - 1);

        for i in 0..n {
            for j in 0..n {
                write!(
                    output,
                    "{}",
                    if (i + j) % k == (r + c) % k { 'X' } else { '.' }
                )
                .unwrap();
            }
            writeln!(output).unwrap();
        }
    }
}


Score : <var>100</var> points

Problem Statement

You are given a positive integer <var>N</var>.
Find the minimum positive integer divisible by both <var>2</var> and <var>N</var>.

Constraints

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Print the minimum positive integer divisible by both <var>2</var> and <var>N</var>.

Sample Input 1

3

Sample Output 1

6

<var>6</var> is divisible by both <var>2</var> and <var>3</var>.
Also, there is no positive integer less than <var>6</var> that is divisible by both <var>2</var> and <var>3</var>.
Thus, the answer is <var>6</var>.

Sample Input 2

10

Sample Output 2

10

Sample Input 3

999999999

Sample Output 3

1999999998

int solution(void) {
  int N = 0;
  scanf("%d", &N);
  if (N % 2 == 0) {
    printf("%d\n", N);
    return 0;
  }
  printf("%d\n", 2 * N);
  return 0;

  return 0;
}

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

    println!("{}", if n % 2 == 0 { n } else { n * 2 });
}


You like the card board game "Set". Each card contains $$$k$$$ features, each of which is equal to a value from the set $$$\{0, 1, 2\}$$$. The deck contains all possible variants of cards, that is, there are $$$3^k$$$ different cards in total.A feature for three cards is called good if it is the same for these cards or pairwise distinct. Three cards are called a set if all $$$k$$$ features are good for them.For example, the cards $$$(0, 0, 0)$$$, $$$(0, 2, 1)$$$, and $$$(0, 1, 2)$$$ form a set, but the cards $$$(0, 2, 2)$$$, $$$(2, 1, 2)$$$, and $$$(1, 2, 0)$$$ do not, as, for example, the last feature is not good.A group of five cards is called a meta-set, if there is strictly more than one set among them. How many meta-sets there are among given $$$n$$$ distinct cards?

int solution() {
  int x;
  int y;
  int z;
  int w;
  int i;
  int j;
  int k;
  int a;
  int b;
  int n;
  int m;
  int t;
  int arr[1000][20];
  long long c;
  long long cnt[1000];
  long long d;
  long long nn[1000];

  do {
    scanf("%d %d", &n, &k);
    memset(cnt, 0, sizeof(cnt));

    for (x = 0; x < n; x++) {
      d = 0;
      for (y = 0; y < k; y++) {
        scanf("%d", &arr[x][y]);
        d = 3 * d + arr[x][y];
      }

      nn[x] = d;
    }

    for (x = 0; x < n; x++) {
      for (y = x + 1; y < n; y++) {
        d = 0;
        for (z = 0; z < k; z++) {
          if (arr[x][z] == arr[y][z]) {
            d = 3 * d + arr[x][z];
          } else {
            for (w = 0; w < 3; w++) {
              if (arr[x][z] != w && arr[y][z] != w) {
                d = 3 * d + w;
              }
            }
          }
        }

        for (z = 0; z < n; z++) {
          if (nn[z] == d) {
            cnt[z]++;
          }
        }
      }
    }

    for (x = 0; x < n; x++) {
      c += cnt[x] * (cnt[x] - 1) / 2;
    }

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

  } while (0);
}

fn solution() {
    input! {
        n: usize,
        k: usize,
        c: [[i8; k]; n],
    }
    let mut map = BTreeMap::new();
    for i in 0..n {
        map.insert(&c[i], 0i64);
    }
    for i in 0..n {
        for j in 0..i {
            let mut good = vec![0; k];
            for k in 0..k {
                good[k] = if c[i][k] == c[j][k] {
                    c[i][k]
                } else {
                    3 - c[i][k] - c[j][k]
                };
            }
            if let Some(count) = map.get_mut(&good) {
                *count += 1;
            }
        }
    }
    let mut ans = 0;
    for count in map.into_values() {
        ans += count * (count - 1) / 2;
    }
    println!("{}", ans);
}


You are given an array of positive integers $$$a_1, a_2, \ldots, a_n$$$.Make the product of all the numbers in the array (that is, $$$a_1 \cdot a_2 \cdot \ldots \cdot a_n$$$) divisible by $$$2^n$$$.You can perform the following operation as many times as you like:  select an arbitrary index $$$i$$$ ($$$1 \leq i \leq n$$$) and replace the value $$$a_i$$$ with $$$a_i=a_i \cdot i$$$. You cannot apply the operation repeatedly to a single index. In other words, all selected values of $$$i$$$ must be different.Find the smallest number of operations you need to perform to make the product of all the elements in the array divisible by $$$2^n$$$. Note that such a set of operations does not always exist.

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

  while (t--) {
    int n;
    int max = 0;
    int a;
    int ava;
    scanf("%d", &n);

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

      while (a != 0) {
        if (a % 2 == 0) {
          max++;
          a /= 2;
        }

        else {
          break;
        }
      }
    }

    if (max >= n) {
      printf("0\n");
      continue;
    }

    a = 2, ava = max;

    while (1) {
      if (n / a == 0) {
        break;
      }

      max += n / a;
      a *= 2;
    }

    if (max < n) {
      printf("-1\n");
      continue;
    }

    int l = 0;
    int ans = 0;
    int count = 1;
    a = n / 2;

    while (a != 0) {
      l++;
      a /= 2;
    }

    a = 1;

    for (int i = 0; i < l; i++) {
      a *= 2;
    }

    while (1) {
      while (count--) {
        ava += l;
        ans++;

        if (ava >= n) {
          goto end;
        }
      }

      l -= 1;
      a /= 2;
      count = n / a - ans;
    }

  end:
    printf("%d\n", ans);
  }

  return 0;
}

fn solution() {
    let stdin = std::io::stdin();
    let stdin_lock = stdin.lock();
    let mut line_iter = stdin_lock.lines();
    let t = line_iter
        .next()
        .unwrap()
        .unwrap()
        .as_str()
        .parse::<usize>()
        .unwrap();
    for _ in 0..t {
        let n = line_iter.next().unwrap().unwrap().parse::<usize>().unwrap();
        let nums_str = line_iter.next().unwrap().unwrap();
        let nums_iter = nums_str
            .split(' ')
            .map(|num_str| num_str.parse::<u64>().unwrap());

        let mut init_pows_2: usize = 0;
        for num in nums_iter {
            let mut quotient = num;
            while quotient % 2 == 0 {
                init_pows_2 += 1;
                quotient /= 2;
            }
        }

        if init_pows_2 >= n {
            println!("0");
            continue;
        }

        let mut rem_pows_2: usize = n - init_pows_2;
        let mut ops_required = 0;

        let mut counts_by_pow: Vec<usize> = Vec::with_capacity(40);

        let mut quotient = n;
        while quotient > 0 {
            counts_by_pow.push(quotient);
            quotient /= 2;
        }

        let mut already_used_pows = 0;
        let pow_count = counts_by_pow.len() - 1;
        for pow_of_2 in (1..=pow_count).rev() {
            if rem_pows_2 <= 0 {
                break;
            }

            let count_with_pow_of_2 = counts_by_pow[pow_of_2] - already_used_pows;
            already_used_pows += count_with_pow_of_2;
            for _ in 0..count_with_pow_of_2 {
                ops_required += 1;
                if rem_pows_2 <= pow_of_2 {
                    rem_pows_2 = 0;
                    break;
                } else {
                    rem_pows_2 -= pow_of_2;
                }
            }
        }

        if rem_pows_2 > 0 {
            println!("-1");
        } else {
            println!("{}", ops_required);
        }
    }
}


You are given the array $$$a$$$ consisting of $$$n$$$ positive (greater than zero) integers.In one move, you can choose two indices $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that the absolute difference between $$$a_i$$$ and $$$a_j$$$ is no more than one ($$$|a_i - a_j| \le 1$$$) and remove the smallest of these two elements. If two elements are equal, you can remove any of them (but exactly one).Your task is to find if it is possible to obtain the array consisting of only one element using several (possibly, zero) such moves or not.You have to answer $$$t$$$ independent test cases.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int a[n];
    int min = 100;
    int max = 0;
    int ct[101];
    memset(ct, 0, 101 * sizeof(int));
    for (int i = 0; i < n; ++i) {
      int aa;
      scanf("%d", &aa);
      a[i] = aa;
      ct[aa] = 1;
      if (min > aa) {
        min = aa;
      }
      if (max < aa) {
        max = aa;
      }
    }
    int flag = 1;
    for (int i = min + 1; i < max; ++i) {
      if (ct[i] == 0) {
        printf("NO\n");
        flag = 0;
        break;
      }
    }
    if (flag) {
      printf("YES\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()
    };

    'outer: 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 mut 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()
        };

        a.sort();

        for i in 0..(n - 1) {
            if a[i + 1] - a[i] > 1 {
                println!("NO");
                continue 'outer;
            }
        }
        println!("YES");
    }
}


For an array $$$[b_1, b_2, \ldots, b_m]$$$ define its number of inversions as the number of pairs $$$(i, j)$$$ of integers such that $$$1 \le i < j \le m$$$ and $$$b_i>b_j$$$. Let's call array $$$b$$$ odd if its number of inversions is odd. For example, array $$$[4, 2, 7]$$$ is odd, as its number of inversions is $$$1$$$, while array $$$[2, 1, 4, 3]$$$ isn't, as its number of inversions is $$$2$$$.You are given a permutation $$$[p_1, p_2, \ldots, p_n]$$$ of integers from $$$1$$$ to $$$n$$$ (each of them appears exactly once in the permutation). You want to split it into several consecutive subarrays (maybe just one), so that the number of the odd subarrays among them is as large as possible. What largest number of these subarrays may be odd?

int solution(void) {
  int testcase = 0;
  scanf("%i", &testcase);
  for (int i = 0; i < testcase; i++) {
    int n = 0;
    scanf("%i", &n);
    int p[n];
    for (int i = 0; i < n; i++) {
      scanf("%i", &p[i]);
    }

    int count = 0;
    int i = 0;
    while (i < n) {
      if (p[i] > p[i + 1]) {
        count++;
        i++;
      }
      i++;
    }

    printf("%i\n", count);
  }
}

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

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

    let t: i32 = inputt.trim().parse().expect("not a nubmer");

    for _ in 0..t as usize {
        let mut _inputn = String::new();

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

        let n: i32 = _inputn.trim().parse().expect("not a number");

        let mut _inputa = String::new();

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

        let a: Vec<i32> = _inputa
            .split_whitespace()
            .map(|x| x.parse().expect("not a number "))
            .collect();

        let mut cnt = a[0];
        let mut ans = 0;

        for _i in 0..a.len() {
            cnt = cmp::max(a[_i], cnt);

            if a[_i] < cnt {
                ans += 1;
                if _i + 1 != n as usize {
                    cnt = a[_i + 1];
                }
            }
        }
        println!("{}", ans);
    }
}


Score : <var>100</var> points

Problem Statement

Snuke is buying a bicycle.
The bicycle of his choice does not come with a bell, so he has to buy one separately.

He has very high awareness of safety, and decides to buy two bells, one for each hand.

The store sells three kinds of bells for the price of <var>a</var>, <var>b</var> and <var>c</var> yen (the currency of Japan), respectively.
Find the minimum total price of two different bells.

Constraints

<var>1 \leq a,b,c \leq 10000</var>

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

Input

Input is given from Standard Input in the following format:

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

Output

Print the minimum total price of two different bells.

Sample Input 1

700 600 780

Sample Output 1

1300

Buying a <var>700</var>-yen bell and a <var>600</var>-yen bell costs <var>1300</var> yen.

Buying a <var>700</var>-yen bell and a <var>780</var>-yen bell costs <var>1480</var> yen.

Buying a <var>600</var>-yen bell and a <var>780</var>-yen bell costs <var>1380</var> yen.

The minimum among these is <var>1300</var> yen.

Sample Input 2

10000 10000 10000

Sample Output 2

20000

Buying any two bells costs <var>20000</var> yen.

int solution() {
  int price[3];
  scanf("%d %d %d", &price[0], &price[1], &price[2]);
  if (price[0] >= price[1] && price[0] >= price[2]) {
    printf("%d\n", price[1] + price[2]);
  } else if (price[1] >= price[0] && price[1] >= price[2]) {
    printf("%d\n", price[0] + price[2]);
  } else {
    printf("%d\n", price[0] + price[1]);
  }
  return 0;
}

fn solution() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    let v: Vec<u16> = line
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();
    let a = v[0];
    let b = v[1];
    let c = v[2];
    println!("{}", cmp::min(cmp::min(a + b, b + c), a + c));
}


Score : <var>300</var> points

Problem Statement

Compute <var>A \times B</var>, truncate its fractional part, and print the result as an integer.

Constraints

<var>0 \leq A \leq 10^{15}</var>

<var>0 \leq B < 10</var>

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

<var>B</var> is a number with two digits after the decimal point.

Input

Input is given from Standard Input in the following format:

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

Output

Print the answer as an integer.

Sample Input 1

198 1.10

Sample Output 1

217

We have <var>198 \times 1.10 = 217.8</var>. After truncating the fractional part, we have the answer: <var>217</var>.

Sample Input 2

1 0.01

Sample Output 2

0

Sample Input 3

1000000000000000 9.99

Sample Output 3

9990000000000000

int solution(void) {

  long double A = 0.0;
  long double B = 0.0;
  scanf("%Lf %Lf", &A, &B);
  B = A * B;
  B = floorl(B);
  printf("%0.0Lf\n", B);

  return 0;
}

fn solution() {
    let (A, B) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut splitted = s.split_whitespace();
        (
            splitted.next().unwrap().to_string(),
            splitted.next().unwrap().to_string(),
        )
    };

    let mut aup = 0;
    let mut amake = "".to_string();
    for c in A.chars() {
        if aup > 0 {
            aup *= 10;
        }
        if c == '.' {
            aup = 1;
            continue;
        }
        amake.push(c);
    }
    if aup == 0 {
        aup = 1;
    }

    let mut bup = 0;
    let mut bmake = "".to_string();
    for c in B.chars() {
        if bup > 0 {
            bup *= 10;
        }
        if c == '.' {
            bup = 1;
            continue;
        }
        bmake.push(c);
    }
    if bup == 0 {
        bup = 1;
    }

    println!(
        "{}",
        amake.parse::<i128>().unwrap() * bmake.parse::<i128>().unwrap() / (aup * bup)
    );
}


Score : <var>600</var> points

Problem Statement

Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.

She thinks that a set <var>S = \{a_{1}, a_{2}, ..., a_{N}\}</var> of distinct positive integers is called special if for all <var>1 \leq i \leq N</var>, the gcd (greatest common divisor) of <var>a_{i}</var> and the sum of the remaining elements of <var>S</var> is not <var>1</var>.

Nagase wants to find a special set of size <var>N</var>. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size <var>N</var> such that the gcd of all elements are <var>1</var> and the elements of the set does not exceed <var>30000</var>.

Constraints

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

Input

Input is given from Standard Input in the following format:

<var>N</var>

Output

Output <var>N</var> space-separated integers, denoting the elements of the set <var>S</var>. <var>S</var> must satisfy the following conditions :

The elements must be distinct positive integers not exceeding <var>30000</var>.

The gcd of all elements of <var>S</var> is <var>1</var>, i.e. there does not exist an integer <var>d > 1</var> that divides all elements of <var>S</var>.

<var>S</var> is a special set.

If there are multiple solutions, you may output any of them. The elements of <var>S</var> may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.

Sample Input 1

3

Sample Output 1

2 5 63

<var>\{2, 5, 63\}</var> is special because <var>gcd(2, 5 + 63) = 2, gcd(5, 2 + 63) = 5, gcd(63, 2 + 5) = 7</var>. Also, <var>gcd(2, 5, 63) = 1</var>. Thus, this set satisfies all the criteria.

Note that <var>\{2, 4, 6\}</var> is not a valid solution because <var>gcd(2, 4, 6) = 2 > 1</var>.

Sample Input 2

4

Sample Output 2

2 5 20 63

<var>\{2, 5, 20, 63\}</var> is special because <var>gcd(2, 5 + 20 + 63) = 2, gcd(5, 2 + 20 + 63) = 5, gcd(20, 2 + 5 + 63) = 10, gcd(63, 2 + 5 + 20) = 9</var>. Also, <var>gcd(2, 5, 20, 63) = 1</var>. Thus, this set satisfies all the criteria.

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

    let m = std::cmp::min(5000, 2 * ((N - 2) / 2));
    let res = if N == 3 {
        vec![2, 3, 25]
    } else {
        (0..m)
            .map(|i| 6 * i + 3)
            .chain((1..(N - m + 1)).map(|i| {
                if m + i == N && i % 3 == 1 {
                    2 * (i + 2)
                } else {
                    2 * i
                }
            }))
            .collect::<Vec<_>>()
    };
    let ans = res
        .iter()
        .map(|&x| x.to_string())
        .collect::<Vec<_>>()
        .join(" ");

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


Consider a conveyor belt represented using a grid consisting of $$$n$$$ rows and $$$m$$$ columns. The cell in the $$$i$$$-th row from the top and the $$$j$$$-th column from the left is labelled $$$(i,j)$$$. Every cell, except $$$(n,m)$$$, has a direction R (Right) or D (Down) assigned to it. If the cell $$$(i,j)$$$ is assigned direction R, any luggage kept on that will move to the cell $$$(i,j+1)$$$. Similarly, if the cell $$$(i,j)$$$ is assigned direction D, any luggage kept on that will move to the cell $$$(i+1,j)$$$. If at any moment, the luggage moves out of the grid, it is considered to be lost. There is a counter at the cell $$$(n,m)$$$ from where all luggage is picked. A conveyor belt is called functional if and only if any luggage reaches the counter regardless of which cell it is placed in initially. More formally, for every cell $$$(i,j)$$$, any luggage placed in this cell should eventually end up in the cell $$$(n,m)$$$. This may not hold initially; you are, however, allowed to change the directions of some cells to make the conveyor belt functional. Please determine the minimum amount of cells you have to change.Please note that it is always possible to make any conveyor belt functional by changing the directions of some set of cells.

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, m): (usize, usize) = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let mut iter = buf.split_whitespace();
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
            )
        };

        let mut a = Vec::with_capacity(n);
        for _ in 0..n {
            let s: Vec<char> = {
                let mut buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
                buf.trim_end().chars().collect()
            };
            a.push(s);
        }

        let mut ans = 0;
        for i in 0..(n - 1) {
            if a[i][m - 1] == 'R' {
                ans += 1;
            }
        }
        for i in 0..(m - 1) {
            if a[n - 1][i] == 'D' {
                ans += 1;
            }
        }
        println!("{}", ans);
    }
}


Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $$$1$$$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $$$3$$$ steps, and the second contains $$$4$$$ steps, she will pronounce the numbers $$$1, 2, 3, 1, 2, 3, 4$$$.You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.

fn solution() {
    let stdin = io::stdin();
    let mut in_lines = stdin.lock().lines();
    let _l: u32 = in_lines.next().unwrap().unwrap().parse().unwrap();
    let elems: Vec<u32> = in_lines
        .next()
        .unwrap()
        .unwrap()
        .split(' ')
        .map(|s| s.parse::<u32>().unwrap())
        .fold(Vec::new(), |mut acc, el| {
            if el == 1 {
                acc.push(1);
            } else {
                let last = acc.last_mut().unwrap();
                *last += 1;
            }
            acc
        });
    println!("{}", elems.len());
    for i in elems {
        print!("{} ", i);
    }
}


While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other.A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself.

int solution() {
  const unsigned int n = 1 + 1e5;
  char Str1[n];
  char Str2[n];
  scanf("%s%s", Str1, Str2);
  unsigned int i = 0;
  unsigned int s1 = 0;
  unsigned int s2 = 0;
  while (Str1[s1] != '\0') {
    s1++;
  }
  while (Str2[s2] != '\0') {
    s2++;
  }
  while (Str1[i] == Str2[i] && Str1[i] != '\0' && Str2[i] != '\0') {
    i++;
  }
  if (Str1[i] == '\0' && Str2[i] == '\0') {
    printf("-1");
  } else {
    printf("%u", s1 > s2 ? s1 : s2);
  }
  return 0;
}

fn solution() {
    use std::io;
    let mut str1 = String::new();
    let mut str2 = String::new();
    io::stdin().read_line(&mut str1).unwrap();
    io::stdin().read_line(&mut str2).unwrap();
    let bytes1 = str1.trim().as_bytes();
    let bytes2 = str2.trim().as_bytes();
    if bytes1 == bytes2 {
        println!("-1");
    } else {
        println!("{}", std::cmp::max(bytes1.len(), bytes2.len()));
    }
}


Score : <var>500</var> points

Problem Statement

Given is a string <var>S</var> of length <var>N</var>.

Find the maximum length of a non-empty string that occurs twice or more in <var>S</var> as contiguous substrings without overlapping.

More formally, find the maximum positive integer <var>len</var> such that there exist integers <var>l_1</var> and <var>l_2</var> ( <var>1 \leq l_1, l_2 \leq N - len + 1</var> ) that satisfy the following:

<var>l_1 + len \leq l_2</var>

<var>S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)</var>

If there is no such integer <var>len</var>, print <var>0</var>.

Constraints

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

<var>|S| = N</var>

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

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>S</var>

Output

Print the maximum length of a non-empty string that occurs twice or more in <var>S</var> as contiguous substrings without overlapping. If there is no such non-empty string, print <var>0</var> instead.

Sample Input 1

5
ababa

Sample Output 1

2

The strings satisfying the conditions are: a, b, ab, and ba. The maximum length among them is <var>2</var>, which is the answer.
Note that aba occurs twice in <var>S</var> as contiguous substrings, but there is no pair of integers <var>l_1</var> and <var>l_2</var> mentioned in the statement such that <var>l_1 + len \leq l_2</var>.

Sample Input 2

2
xy

Sample Output 2

0

No non-empty string satisfies the conditions.

Sample Input 3

13
strangeorange

Sample Output 3

5

fn solution() {
    let mut stdin = io::stdin();
    let mut lines_str = String::new();
    let _ = stdin.read_to_string(&mut lines_str);
    let lines_vec = lines_str.lines().collect::<Vec<&str>>();
    let n: usize = lines_vec[0].trim().parse().unwrap();
    let s_vec = lines_vec[1].trim().chars().collect::<Vec<char>>();

    let mut max_len = 0;
    let mut len: Vec<Vec<usize>> = Vec::new();
    for i in 0..n {
        len.push(vec![0; i]);
        for j in 0..i {
            if s_vec[i] != s_vec[j] {
                continue;
            }
            if j == 0 {
                len[i][j] = 1;
                if max_len < len[i][j] {
                    max_len = len[i][j];
                }
            } else {
                len[i][j] = len[i - 1][j - 1] + 1;
                if len[i][j] > i - j {
                    len[i][j] = i - j;
                }
                if max_len < len[i][j] {
                    max_len = len[i][j];
                }
            }
        }
    }

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


Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...The string $$$s$$$ he found is a binary string of length $$$n$$$ (i. e. string consists only of 0-s and 1-s).In one move he can choose two consecutive characters $$$s_i$$$ and $$$s_{i+1}$$$, and if $$$s_i$$$ is 1 and $$$s_{i + 1}$$$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $$$s$$$ as clean as possible. He thinks for two different strings $$$x$$$ and $$$y$$$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.Now you should answer $$$t$$$ test cases: for the $$$i$$$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.Small reminder: if we have two strings $$$x$$$ and $$$y$$$ of the same length then $$$x$$$ is lexicographically smaller than $$$y$$$ if there is a position $$$i$$$ such that $$$x_1 = y_1$$$, $$$x_2 = y_2$$$,..., $$$x_{i - 1} = y_{i - 1}$$$ and $$$x_i < y_i$$$.

int solution() {
  int N;
  scanf("%d", &N);
  char *out[N];
  for (int k = 0; k < N; k++) {
    int n;
    scanf("%d", &n);
    out[k] = (char *)malloc((n + 1) * sizeof(char));
    scanf("%s", out[k]);
    int i;
    for (i = 0; i < n - 1 && out[k][i] <= out[k][i + 1]; i++) {
      ;
    }
    if (i != n - 1) {
      i = 0;
      int zeroCount = 1;
      int oneCount = 0;
      for (int j = 0; j < n && out[k][j] == '0'; j++) {
        zeroCount++;
      }
      for (int j = 0; n - 1 - j >= 0 && out[k][n - 1 - j] == '1'; j++) {
        oneCount++;
      }

      for (int j = 0; j < zeroCount; j++) {
        out[k][i++] = '0';
      }
      for (int j = 0; j < oneCount; j++) {
        out[k][i++] = '1';
      }
      out[k][i] = '\0';
    }
  }
  for (int k = 0; k < N; k++) {
    printf("%s\n", out[k]);
    free(out[k]);
  }
}

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 n: usize = lines.next().unwrap().unwrap().parse().unwrap();
        let cs: Vec<char> = lines.next().unwrap().unwrap().chars().collect();
        let mut state: u8 = 0;
        let mut rear_zeros: usize = 0;
        let mut rear_ones: usize = 0;
        for i in 0..n {
            let k = n - i - 1;
            if cs[k] == '0' {
                rear_zeros += 1;
                if state == 0 {
                    state = 1;
                }
            } else {
                if state != 0 {
                    break;
                }
                rear_ones += 1;
            }
        }
        state = 0;
        let mut front_zeros: usize = 0;
        let mut front_ones: usize = 0;
        for i in 0..(n - rear_zeros - rear_ones) {
            if cs[i] == '0' {
                front_zeros += 1;
                if state == 0 {
                    state = 1;
                }
            } else if state != 0 {
                break;
            } else {
                front_ones += 1;
            }
        }
        let mut ans: Vec<u8> = Vec::new();
        if front_ones == 0 {
            for _ in 0..front_zeros {
                ans.push(0_u8 + b'0');
            }
        }
        if front_ones != 0 || front_zeros != 0 {
            if rear_zeros != 0 {
                ans.push(0_u8 + b'0');
            }
        } else {
            for _ in 0..rear_zeros {
                ans.push(0_u8 + b'0');
            }
        }
        for _ in 0..rear_ones {
            ans.push(1_u8 + b'0');
        }
        println!("{}", String::from_utf8(ans).unwrap());
    }
}


It was the third month of remote learning, Nastya got sick of staying at dormitory, so she decided to return to her hometown. In order to make her trip more entertaining, one of Nastya's friend presented her an integer array $$$a$$$. Several hours after starting her journey home Nastya remembered about the present. To entertain herself she decided to check, are there four different indices $$$x, y, z, w$$$ such that $$$a_x + a_y = a_z + a_w$$$.Her train has already arrived the destination, but she still hasn't found the answer. Can you help her unravel the mystery?

int solution() {
  static int i;
  static int j;
  static int number[5000100];
  static int sum;
  static int n;
  static int store[5000100] = {0};
  static int pos1[5000100];
  static int pos2[5000100];
  static int flag = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &number[i]);
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      sum = number[i] + number[j];
      store[sum]++;
      if (store[sum] > 1) {
        if (i != pos1[sum] && i != pos2[sum] && j != pos1[sum] &&
            j != pos2[sum]) {
          printf("YES\n");
          printf("%d %d %d %d\n", i + 1, j + 1, pos1[sum] + 1, pos2[sum] + 1);
          return 0;
        }
      }

      pos1[sum] = i, pos2[sum] = j;
    }
  }
  if (flag == 0) {
    printf("NO\n");
  }
  return 0;
}

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

    let mut valoresdosnumeros = String::new();
    io::stdin().read_line(&mut valoresdosnumeros).unwrap();

    let vectornumb = valoresdosnumeros
        .split_whitespace()
        .map(|x| x.parse::<u32>().unwrap())
        .collect::<Vec<u32>>();

    let mut map: HashMap<u32, [usize; 2]> = HashMap::new();

    let _dimxy = 0;
    for x in 0..vectornumb.len() {
        for y in 0..x {
            let dimxy = vectornumb[x] + vectornumb[y];
            if let std::collections::hash_map::Entry::Vacant(e) = map.entry(dimxy) {
                e.insert([x, y]);
            } else {
                let pair = map.get(&dimxy).unwrap();
                if pair[0] != x && pair[0] != y && pair[1] != x && pair[1] != y {
                    println!("YES\n{} {} {} {}", x + 1, y + 1, 1 + pair[0], 1 + pair[1]);
                    std::process::exit(0);
                }
            }
        }
    }

    println!("NO");
}


Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open.

int solution() {
  int size = 0;
  scanf("%d", &size);
  int l_door = 0;
  int r_door = 0;
  int arr[size];
  for (int i = 0; i < size; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] == 0) {
      l_door++;
    } else {
      r_door++;
    }
  }
  for (int i = 0; i < size; i++) {
    if (arr[i] == 0) {
      l_door--;
    } else {
      r_door--;
    }
    if (l_door == 0 || r_door == 0) {
      printf("%d\n", i + 1);
      break;
    }
  }
  return 0;
}

fn solution() {
    let mut input = String::new();
    std::io::stdin()
        .read_line(&mut input)
        .expect("input: read line failed");
    let amount = input
        .trim()
        .parse::<usize>()
        .expect("amount: parse to usize failed");
    input.clear();
    std::io::stdin()
        .read_line(&mut input)
        .expect("input: read line failed");
    let mut vec = input
        .split_whitespace()
        .map(|item| item.parse::<usize>().expect("item: parse to usize failed"))
        .collect::<Vec<usize>>();
    vec.reverse();

    let mut zero_index = usize::default();
    let mut one_index = usize::default();

    for index in 0..amount {
        if vec[index] == 0 {
            zero_index = index;
            break;
        }
    }

    for index in 0..amount {
        if vec[index] == 1 {
            one_index = index;
            break;
        }
    }

    println!(
        "{}",
        amount
            - if zero_index > one_index {
                zero_index
            } else {
                one_index
            }
    );
}


You are walking through a parkway near your house. The parkway has $$$n+1$$$ benches in a row numbered from $$$1$$$ to $$$n+1$$$ from left to right. The distance between the bench $$$i$$$ and $$$i+1$$$ is $$$a_i$$$ meters.Initially, you have $$$m$$$ units of energy. To walk $$$1$$$ meter of distance, you spend $$$1$$$ unit of your energy. You can't walk if you have no energy. Also, you can restore your energy by sitting on benches (and this is the only way to restore the energy). When you are sitting, you can restore any integer amount of energy you want (if you sit longer, you restore more energy). Note that the amount of your energy can exceed $$$m$$$.Your task is to find the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk).You have to answer $$$t$$$ independent test cases.

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

    int e = m - c;
    if (e < 0) {
      printf("%d\n", -1 * e);
    } else {
      if (e >= 0) {
        printf("%d\n", 0);
      }
    }
  }

  return 0;
}

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

    io::stdin().read_line(&mut t).unwrap();
    let t = t.trim().parse::<i32>().unwrap();

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

        io::stdin().read_line(&mut line).unwrap();
        io::stdin().read_line(&mut benches).unwrap();

        let m = line.split(' ').collect::<Vec<&str>>()[1]
            .trim()
            .parse::<i32>()
            .unwrap();
        let benches = benches.split(' ');

        let mut sum = 0;
        for bench in benches {
            sum += bench.trim().parse::<i32>().unwrap();
        }

        println!("{}", std::cmp::max(0, sum - m));
    }
}


There are $$$n$$$ candies in a row, they are numbered from left to right from $$$1$$$ to $$$n$$$. The size of the $$$i$$$-th candy is $$$a_i$$$.Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob — from right to left. The game ends if all the candies are eaten.The process consists of moves. During a move, the player eats one or more sweets from her/his side (Alice eats from the left, Bob — from the right).Alice makes the first move. During the first move, she will eat $$$1$$$ candy (its size is $$$a_1$$$). Then, each successive move the players alternate — that is, Bob makes the second move, then Alice, then again Bob and so on.On each move, a player counts the total size of candies eaten during the current move. Once this number becomes strictly greater than the total size of candies eaten by the other player on their previous move, the current player stops eating and the move ends. In other words, on a move, a player eats the smallest possible number of candies such that the sum of the sizes of candies eaten on this move is strictly greater than the sum of the sizes of candies that the other player ate on the previous move. If there are not enough candies to make a move this way, then the player eats up all the remaining candies and the game ends.For example, if $$$n=11$$$ and $$$a=[3,1,4,1,5,9,2,6,5,3,5]$$$, then:  move 1: Alice eats one candy of size $$$3$$$ and the sequence of candies becomes $$$[1,4,1,5,9,2,6,5,3,5]$$$.  move 2: Alice ate $$$3$$$ on the previous move, which means Bob must eat $$$4$$$ or more. Bob eats one candy of size $$$5$$$ and the sequence of candies becomes $$$[1,4,1,5,9,2,6,5,3]$$$.  move 3: Bob ate $$$5$$$ on the previous move, which means Alice must eat $$$6$$$ or more. Alice eats three candies with the total size of $$$1+4+1=6$$$ and the sequence of candies becomes $$$[5,9,2,6,5,3]$$$.  move 4: Alice ate $$$6$$$ on the previous move, which means Bob must eat $$$7$$$ or more. Bob eats two candies with the total size of $$$3+5=8$$$ and the sequence of candies becomes $$$[5,9,2,6]$$$.  move 5: Bob ate $$$8$$$ on the previous move, which means Alice must eat $$$9$$$ or more. Alice eats two candies with the total size of $$$5+9=14$$$ and the sequence of candies becomes $$$[2,6]$$$.  move 6 (the last): Alice ate $$$14$$$ on the previous move, which means Bob must eat $$$15$$$ or more. It is impossible, so Bob eats the two remaining candies and the game ends. Print the number of moves in the game and two numbers:  $$$a$$$ — the total size of all sweets eaten by Alice during the game;  $$$b$$$ — the total size of all sweets eaten by Bob during the game.

int solution() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int a[1000] = {0};
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    int l = 0;
    int r = n - 1;
    int suml = 0;
    int sumr = 0;
    int cnt = 0;
    int ansl = 0;
    int ansr = 0;
    while (l <= r) {
      if (cnt % 2 == 0) {
        int nsuml = 0;
        while (l <= r && nsuml <= sumr) {
          nsuml += a[l++];
        }
        ansl += nsuml;
        suml = nsuml;
      } else {
        int nsumr = 0;
        while (l <= r && nsumr <= suml) {
          nsumr += a[r--];
        }
        ansr += nsumr;
        sumr = nsumr;
      }
      ++cnt;
    }
    printf("%d %d %d\n", cnt, ansl, ansr);
  }
  return 0;
}

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

    io::stdin().read_line(&mut input)?;
    let n = input.trim().parse().unwrap();
    for _ in 0..n {
        input.clear();
        io::stdin().read_line(&mut input)?;

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

        let (mut a, mut b, mut count, mut prev) = (0, 0, 0, 0);
        let mut current = true;
        while !candies.is_empty() {
            count += 1;
            let mut now = 0;
            if current {
                while (now <= prev) && !candies.is_empty() {
                    now += candies[0];
                    candies.remove(0);
                }
                a += now;
                prev = now;
            } else {
                while (now <= prev) && !candies.is_empty() {
                    now += candies.pop().unwrap();
                }
                b += now;
                prev = now;
            }

            current = !current;
        }

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

    Ok(())
}


Score : <var>200</var> points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate <var>X</var>, and that of Empire B is located at coordinate <var>Y</var>.

One day, Empire A becomes inclined to put the cities at coordinates <var>x_1, x_2, ..., x_N</var> under its control, and Empire B becomes inclined to put the cities at coordinates <var>y_1, y_2, ..., y_M</var> under its control.

If there exists an integer <var>Z</var> that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

<var>X < Z \leq Y</var>

<var>x_1, x_2, ..., x_N < Z</var>

<var>y_1, y_2, ..., y_M \geq Z</var>

Determine if war will break out.

Constraints

All values in input are integers.

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

<var>-100 \leq X < Y \leq 100</var>

<var>-100 \leq x_i, y_i \leq 100</var>

<var>x_1, x_2, ..., x_N \neq X</var>

<var>x_i</var> are all different.

<var>y_1, y_2, ..., y_M \neq Y</var>

<var>y_i</var> are all different.

Input

Input is given from Standard Input in the following format:

<var>N</var> <var>M</var> <var>X</var> <var>Y</var>
<var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var>
<var>y_1</var> <var>y_2</var> <var>...</var> <var>y_M</var>

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice <var>Z = 16</var> satisfies all of the three conditions as follows, thus they will come to an agreement.

<var>X = 10 < 16 \leq 20 = Y</var>

<var>8, 15, 13 < 16</var>

<var>16, 22 \geq 16</var>

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War

int solution(void) {
  int N = 0;
  int M = 0;
  int X = 0;
  int Y = 0;
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &X);
  scanf("%d", &Y);
  int x[100];
  int y[100];
  int i = 0;
  for (i = 0; i < N; ++i) {
    scanf("%d", &x[i]);
  }
  for (i = 0; i < M; ++i) {
    scanf("%d", &y[i]);
  }

  int x_max = X;
  int y_min = Y;
  for (i = 0; i < N; ++i) {
    if (x_max < x[i]) {
      x_max = x[i];
    }
  }
  for (i = 0; i < M; ++i) {
    if (y_min > y[i]) {
      y_min = y[i];
    }
  }
  if (x_max < y_min) {
    printf("No War");
  } else {
    printf("War");
  }
  return 0;
}

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

    let mut v: Vec<Vec<i32>> = Vec::new();

    for _ in 0..3 {
        let mut s = String::new();
        let _ = reader.read_line(&mut s);
        let tmp = s.split_whitespace().map(|x| x.parse().unwrap()).collect();
        v.push(tmp);
    }

    let mut ans = false;

    let x_max = v[1].iter().max().unwrap();
    let y_min = v[2].iter().min().unwrap();

    let x = v[0][2];
    let y = v[0][3];

    for z in x_max + 1..y_min + 1 {
        if x < z && z <= y {
            ans = true;
            break;
        }
    }

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


Score : <var>100</var> points

Problem Statement

Alice and Bob are playing One Card Poker.

One Card Poker is a two-player game using playing cards.

Each card in this game shows an integer between 1 and 13, inclusive.

The strength of a card is determined by the number written on it, as follows:

Weak 2 <var><</var> 3 <var><</var> 4 <var><</var> 5 <var><</var> 6 <var><</var> 7 <var><</var> 8 <var><</var> 9 <var><</var> 10 <var><</var> 11 <var><</var> 12 <var><</var> 13 <var><</var> 1 Strong

One Card Poker is played as follows:

Each player picks one card from the deck. The chosen card becomes the player's hand.

The players reveal their hands to each other. The player with the stronger card wins the game.

If their cards are equally strong, the game is drawn.

You are watching Alice and Bob playing the game, and can see their hands.

The number written on Alice's card is <var>A</var>, and the number written on Bob's card is <var>B</var>.

Write a program to determine the outcome of the game.

Constraints

<var>1≦A≦13</var>

<var>1≦B≦13</var>

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

Input

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

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

Output

Print Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.

Sample Input 1

8 6

Sample Output 1

Alice

8 is written on Alice's card, and 6 is written on Bob's card.
Alice has the stronger card, and thus the output should be Alice.

Sample Input 2

1 1

Sample Output 2

Draw

Since their cards have the same number, the game will be drawn.

Sample Input 3

13 1

Sample Output 3

Bob

int solution(void) {
  int a = 0;
  int b = 0;
  scanf("%d", &a);
  scanf("%d", &b);
  if (a == 1) {
    a = 14;
  }
  if (b == 1) {
    b = 14;
  }
  if (a < b) {
    printf("Bob");
  } else if (a > b) {
    printf("Alice");
  } else {
    printf("Draw");
  }
  return 0;
}

fn solution() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v: Vec<i32> = s
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();
    let a = v[0];
    let b = v[1];
    if a == b {
        println!("Draw");
    } else if a == 1 {
        println!("Alice");
    } else if b == 1 {
        println!("Bob");
    } else if a > b {
        println!("Alice");
    } else {
        println!("Bob");
    }
}


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>.

You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square.

Find the maximum number of times you can move.

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

Print the maximum number of times you can move.

Sample Input 1

5
10 4 8 7 3

Sample Output 1

2

By landing on the third square from the left, you can move to the right twice.

Sample Input 2

7
4 4 5 6 6 5 5

Sample Output 2

3

By landing on the fourth square from the left, you can move to the right three times.

Sample Input 3

4
1 2 3 4

Sample Output 3

0

int solution() {
  int n;

  scanf("%d", &n);

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

    if (i != 0 && H[i - 1] >= H[i]) {
      count++;
    } else {
      if (max < count) {
        max = count;
      }
      count = 0;
    }
  }
  if (max < count) {
    max = count;
  }
  printf("%d", max);
}

fn solution() {
    let mut buft = String::new();
    io::stdin().read_line(&mut buft).unwrap();
    let n: usize = buft.trim().parse().unwrap();
    buft.clear();
    io::stdin().read_line(&mut buft).unwrap();
    let hs: Vec<i32> = buft
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    let mut i: usize = 1;
    let mut ans: usize = 0;
    while i < n {
        let mut j = i;
        while hs[j] <= hs[j - 1] {
            j += 1;
            if j >= n {
                break;
            }
        }
        ans = max(ans, j - i);
        i = j + 1;
    }
    println!("{}", ans);
}


Score : <var>200</var> points

Problem Statement

Given are a positive integer <var>N</var> and a string <var>S</var> of length <var>N</var> consisting of lowercase English letters.

Determine whether the string is a concatenation of two copies of some string.
That is, determine whether there is a string <var>T</var> such that <var>S = T + T</var>.

Constraints

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

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

<var>|S| = N</var>

Input

Input is given from Standard Input in the following format:

<var>N</var>
<var>S</var>

Output

If <var>S</var> is a concatenation of two copies of some string, print Yes; otherwise, print No.

Sample Input 1

6
abcabc

Sample Output 1

Yes

Let <var>T = </var> abc, and <var>S = T + T</var>.

Sample Input 2

6
abcadc

Sample Output 2

No

Sample Input 3

1
z

Sample Output 3

No

int solution() {
  char S[101] = {0};
  int N = 0;
  scanf("%d", &N);
  scanf("%s", S);
  if (N % 2 != 0) {
    printf("No\n");
  } else {
    int ret = 0;
    ret = strncmp(&S[0], &S[(N / 2)], N / 2);
    if (ret != 0) {
      printf("No\n");
    } else {
      printf("Yes\n");
    }
  }
  return 0;
}

fn solution() {
    let stdin = io::stdin();
    let mut vec = Vec::new();
    for line in stdin.lock().lines() {
        vec.push(line.unwrap())
    }

    let n: usize = vec[0].parse().unwrap();
    let s = &vec[1];

    if !n.is_multiple_of(2) {
        println!("No");
        return;
    }

    let m = n / 2;

    let former = &s[..m];
    let latter = &s[m..];

    if former == latter {
        println!("Yes");
    } else {
        println!("No");
    }
}


Circle

Write a program which calculates the area and circumference of a circle for given radius <var>r</var>.

Input

A real number <var>r</var> is given.

Output

Print the area and circumference of the circle in a line. Put a single space between them. The output should not contain an absolute error greater than 10-5.

Constraints

 0 < <var>r</var> < 10000

Sample Input 1

2

Sample Output 1

12.566371 12.566371

Sample Input 2

3

Sample Output 2

28.274334 18.849556

fn solution() {
    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let r: f64 = vec[0].parse().unwrap_or(0.0);
    println!(
        "{} {}",
        r * r * std::f64::consts::PI,
        r * 2_f64 * std::f64::consts::PI
    );
}


Recently Vova found $$$n$$$ candy wrappers. He remembers that he bought $$$x$$$ candies during the first day, $$$2x$$$ candies during the second day, $$$4x$$$ candies during the third day, $$$\dots$$$, $$$2^{k-1} x$$$ candies during the $$$k$$$-th day. But there is an issue: Vova remembers neither $$$x$$$ nor $$$k$$$ but he is sure that $$$x$$$ and $$$k$$$ are positive integers and $$$k > 1$$$.Vova will be satisfied if you tell him any positive integer $$$x$$$ so there is an integer $$$k>1$$$ that $$$x + 2x + 4x + \dots + 2^{k-1} x = n$$$. It is guaranteed that at least one solution exists. Note that $$$k > 1$$$.You have to answer $$$t$$$ independent test cases.

int solution() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    int s = 1;
    int p = 1;
    while (n > 0) {
      p = p * 2;
      s = s + p;

      if (n % s == 0) {
        printf("%d\n", n / s);

        break;
      }
    }
  }
  return 0;
}

fn solution() {
    let mut stdin = BufReader::new(io::stdin());
    let mut stdout = BufWriter::new(io::stdout());

    let mut buffer = String::new();
    stdin.read_line(&mut buffer).unwrap();
    let t = buffer.trim().parse().unwrap();
    for _ in 0..t {
        let mut buffer = String::new();
        stdin.read_line(&mut buffer).unwrap();
        let n: u32 = buffer.trim().parse().unwrap();

        let mut base: u32 = 4;
        while !n.is_multiple_of(base - 1) {
            base *= 2;
        }
        writeln!(stdout, "{}", n / (base - 1)).unwrap();
    }
}