Problem:
Score : 100 points

Problem Statement

We have A apples and P pieces of apple.

We can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.

Find the maximum number of apple pies we can make with what we have now.

Constraints

All values in input are integers.

0 \leq A, P \leq 100

Input

Input is given from Standard Input in the following format:

A P

Output

Print the maximum number of apple pies we can make with what we have.

Sample Input 1

1 3

Sample Output 1

3

We can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.

Sample Input 2

0 1

Sample Output 2

0

We cannot make an apple pie in this case, unfortunately.

Sample Input 3

32 21

Sample Output 3

58

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<i64>();
    }
    let ans = solve(&seq);
    println!("{}", ans);
}

fn solve(seq: &Vec<i64>) -> i64 {
    let n = seq.len();
    let mut ret = 0;
    let mut visit = vec![false; n];
    for skip in 1..n {
        let mut sum = 0;
        let mut max_k = 0;
        for k in 1..n {
            let a = n - 1 - skip * k;
            if a < skip {
                break;
            }
            let mut l = skip * k;
            if skip * k >= n - 1 {
                break;
            }
            let mut r = n - 1 - skip * k;
            if visit[l] || visit[r] || l == r {
                break;
            }
            visit[l] = true;
            visit[r] = true;
            sum += seq[l] + seq[r];
            ret = std::cmp::max(ret, sum);
            max_k = k;
        }
        for k in 1..(max_k + 1) {
            let mut l = skip * k;
            let mut r = n - 1 - skip * k;
            visit[l] = false;
            visit[r] = false;
        }
    }
    return ret;
}