let [ y, m, d ] = '172800 2 29'.split(' ');
y = parseInt(y);
m = parseInt(m);
d = parseInt(d);

let isRunYear = (y) => {
    if (y >= 3200) {
        return (y % 3200 === 0 && y % 172800 === 0) ? true : false;
    }
    if (y % 100 === 0) {
        return y % 400 === 0 ? true : false;
    }
    return (y % 4 === 0 && y % 10 !== 0) ? true : false;
}

let stringify = (v) => {
    return v > 9 ? String(v) : '0' + v;
}

let getDays = (m) => {
    let bigMon = [1, 3, 5, 7, 8, 10, 12];
    return bigMon.some(x => x === m) ? 31 : 30;
}

let printYMD = (y, m, d) => {
    console.log(y + '-' + stringify(m) + '-' + stringify(d));
}

function getYMD(year, month, day) {
    let days, isRun;
    if (month !== 2) {
        days = getDays(month);
    } else {
        isRun = isRunYear(year);
        days = isRun ? 29 : 28;
    }
    if (day > days) {
        printYMD(year, month + 1, day - days);
    } else {
        printYMD(year, month, day);
    }
}

getYMD(y, m, d);