Problem - B - Codeforces
Problem - B - Codeforces
Problem - B - Codeforces
01//EN">
<!-- saved from
url=(0092)https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/
contest/580643/problem/B -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)
) {
adjustViewport();
}
<!--[if IE]>
<style>
#sidebar {
padding-left: 1em;
margin: 1em 1em 1em 0;
}
</style>
<![endif]-->
Codeforces.redirect(Codeforces.updateUrlParameter(document.location.href, "mobile",
useMobile));
}
}
}
</script>
<script type="text/javascript">
$(document).ready(function () {
(function () {
jQuery.expr[':'].containsCI = function(elem, index, match) {
return !match || !match.length || match.length < 4 || !match[3] || (
elem.textContent || elem.innerText || jQuery(elem).text() || ''
).toLowerCase().indexOf(match[3].toLowerCase()) >= 0;
}
}(jQuery));
if (csrf) {
var data = originalOptions.data;
if (originalOptions.data !== undefined) {
if (Object.prototype.toString.call(originalOptions.data) ===
'[object String]') {
data = $.deparam(originalOptions.data);
}
} else {
data = {};
}
options.data = $.param($.extend(data, { csrf_token: csrf }));
}
});
window.getCodeforcesServerTime = function(callback) {
$.post("/data/time", {}, callback, "json");
}
window.updateTypography = function () {
$("div.ttypography code").addClass("tt");
$("div.ttypography pre>code").addClass("prettyprint").removeClass("tt");
$("div.ttypography table").addClass("bordertable");
prettyPrint();
}
window.updateTypography();
Codeforces.signForms();
setTimeout(function() {
$(".second-level-menu-list").lavaLamp({
fx: "backout",
speed: 700
});
}, 100);
Codeforces.countdown();
$("a[rel='photobox']").colorbox();
var count = 0;
function getDelay() {
var delay = 0;
var last = Codeforces.getFromStorage("LastOnlineTimeUpdaterMillis", 0);
if (last && last != null) {
var period = count < 20 ? 360 * 1000 : 600 * 1000;
delay = period - (new Date().getTime() - last);
if (delay < 0)
delay = 0;
}
return delay;
}
window.setInterval(function () {
if (getDelay() <= 0 && count < 120) {
++count;
Codeforces.ping("/data/update-online");
}
}, 5000);
function showAnnouncements(json) {
//info("j=" + JSON.stringify(json));
if (json.t != "a") {
return;
}
setTimeout(function() {
Codeforces.showAnnouncements(json.d, "en");
}, Math.random() * 500);
}
function showEventCatcherUserMessage(json) {
if (json.t == "s") {
var points = json.d[5];
var passedTestCount = json.d[7];
var judgedTestCount = json.d[8];
var verdict = preparedVerdictFormats[json.d[12]];
var verdictPrototypeDiv = $(".verdictPrototypeDiv");
verdictPrototypeDiv.html(verdict);
if (judgedTestCount != null && judgedTestCount != undefined) {
verdictPrototypeDiv.find(".verdict-format-
judged").text(judgedTestCount);
}
if (passedTestCount != null && passedTestCount != undefined) {
verdictPrototypeDiv.find(".verdict-format-
passed").text(passedTestCount);
}
if (points != null && points != undefined) {
verdictPrototypeDiv.find(".verdict-format-points").text(points);
}
Codeforces.showMessage(verdictPrototypeDiv.text());
}
}
$(".clickable-title").each(function() {
var title = $(this).attr("data-title");
if (title) {
var tmp = document.createElement("DIV");
tmp.innerHTML = title;
$(this).attr("title", tmp.textContent || tmp.innerText || "");
}
});
$(".clickable-title").click(function() {
const title = $(this).attr("data-title");
const clazz = $(this).attr("data-clazz");
const props = {};
if (typeof (clazz) !== 'undefined') {
props['clazz'] = clazz;
}
if (title) {
Codeforces.alert(title, null, null, props);
} else {
Codeforces.alert($(this).attr("title"), null, null, props);
}
}).css("position", "relative").css("bottom", "3px");
Codeforces.showDelayedMessage();
Codeforces.reformatTimes();
//Codeforces.initializePubSub();
if (window.codeforcesOptions.subscribeServerUrl) {
window.eventCatcher = new EventCatcher(
window.codeforcesOptions.subscribeServerUrl,
[
Codeforces.getGlobalChannel(),
Codeforces.getUserChannel(),
Codeforces.getUserShowMessageChannel(),
Codeforces.getContestChannel(),
Codeforces.getParticipantChannel(),
Codeforces.getTalkChannel()
]
);
if (Codeforces.getParticipantChannel()) {
window.eventCatcher.subscribe(Codeforces.getParticipantChannel(),
function(json) {
showAnnouncements(json);
});
}
if (Codeforces.getContestChannel()) {
window.eventCatcher.subscribe(Codeforces.getContestChannel(),
function(json) {
showAnnouncements(json);
});
}
if (Codeforces.getGlobalChannel()) {
window.eventCatcher.subscribe(Codeforces.getGlobalChannel(),
function(json) {
showAnnouncements(json);
});
}
if (Codeforces.getUserChannel()) {
window.eventCatcher.subscribe(Codeforces.getUserChannel(),
function(json) {
showAnnouncements(json);
});
}
if (Codeforces.getUserShowMessageChannel()) {
window.eventCatcher.subscribe(Codeforces.getUserShowMessageChannel(),
function(json) {
showEventCatcherUserMessage(json);
});
}
}
Codeforces.setupContestTimes("/group/jf2P3wolKK/data/contests");
Codeforces.setupSpoilers();
Codeforces.setupTutorials("/data/problemTutorial");
});
</script>
<div id="body">
<script type="application/javascript">
window.setTimeout(function () {
var url = location.href;
var hashCode32 = Math.abs(url.hashCode()).toString();
var hashCode = "p" + hashCode32 + Math.abs((hashCode32 +
url).hashCode());
var pvs = Codeforces.getFromStorage("pvs" + hashCode);
if (!pvs) {
$.post("/data/apv", {
ftaa: window._ftaa,
bfaa: window._bfaa,
url: url
}, function (json) {
if (json["success"] === "true") {
Codeforces.putToStorage("pvs" + hashCode, true);
}
}, "json");
}
}, 5000);
</script>
<div>
Bùi Hoàng Minh 2007
|
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/5d48d0d9311d0ff557d0ed30aa
927f41/logout">Logout</a>
</div>
</div>
<br style="clear: both;">
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("input.search").focus(function () {
if ($(this).attr("data-isPlaceholder") === "true") {
$(this).val("");
$(this).removeAttr("data-isPlaceholder");
}
});
});
</script>
<br style="height: 3em; clear: both;">
</style>
<div class="top-links">
</div>
</div>
<ul style=" " data-page-url="/data/group/manage" data-extra-key-0="action"
data-extra-value-0="setGroupContestsSidebarFrameCollapsed" data-extra-key-
1="groupCode" data-extra-value-1="jf2P3wolKK">
<li class="active">
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
580643">
HSG_Fall_24: Đề 9 </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
578173">
HSG Fall 24: Euler tour on tree </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
575644">
HSG Fall 24: Segment tree </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
568517">
HSG Fall 24: Contest 2 </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
566866">
HSG Fall 24: Tree - Đồ thị cây </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
563867">
HSG Fall 24: Hashing </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
560118">
HSG Fall 24: Đường đi ngắn nhất - Dijkstra </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
559364">
HSG Fall 24: Bai kiem tra 1 </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
559277">
HSG Fall 24: Bonus DFS, BFS </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
554314">
HSG_Fall24: Graph - đồ thị </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
552262">
HSG Fall 24: Quy hoach dong </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
550481">
HSG Fall 24: Binary search - Tim kiem nhi phan 2 </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
550480">
HSG Fall 24: Binary search - Tim kiem nhi phan 1 </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
548489">
HSG Fall 24: two pointers - hai con tro </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
548487">
HSG Fall 24: Bitwise, bitmask, cac thao tac voi bit </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
547142">
HSG_Fall24: Prefix sum - Tong cong don </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
547119">
HSG_Fall24: Sorting - Sap xep </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
545648">
HSG Fall 24: Số nguyên tố, sàng nguyên tố </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
544145">
HSG Fall 24: Đệ quy, quay lui </a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
544097">
HSG Fall 24: STL - Vector, pair, set, map, priorty queue, stack, deque...
</a>
</li>
<li>
<a
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
544090">
HSG Fall 24: Test </a>
</li>
</ul>
</div>
<style>
.submit-form.output-only select[name='programTypeId'],
.submitForm.output-only select[name='programTypeId'],
.submit-form.output-only .programSourceTr {
display: none !important;
}
.submit-form.output-only .programTypeNotice,
.submitForm.output-only .programTypeNotice {
display: none !important;
}
.outputOnlyProgramTypeIdNotice {
display: none;
font-size: 1.1rem !important;
}
.submit-form.output-only .outputOnlyProgramTypeIdNotice,
.submitForm.output-only .outputOnlyProgramTypeIdNotice {
display: block !important;
}
</style>
<style type="text/css">
.submitForm .field {
font-size: 1.1rem;
width: 3em !important;
padding-right: 1em;
}
<tr>
<td class="field">Choose file:</td>
<td>
<input name="sourceFile" type="file" value="">
</td>
</tr>
<tr>
<td colspan="2">
<div style="text-align: center;">
<script type="text/javascript">
$(function() {
window._ftaa = "1mzow920b2wsbg4awi";
})
</script>
<script type="text/javascript">
$(function() {
window._bfaa = "4b1c73301711758aff71dee46fc03e72";
});
</script>
<script>
$(function () {
function adjustNotice(programTypeId) {
var $programTypeNotice = $(".programTypeNotice");
$programTypeNotice.text("");
if (programTypeId === 7) {
$programTypeNotice.text("Almost always, if you send a solution
on PyPy, it works much faster");
}
if (programTypeId === 31) {
$programTypeNotice.text("Almost always, if you send a solution
on PyPy, it works much faster");
}
}
adjustNotice(54);
const $submittedProblemIndex = $
("select[name='submittedProblemIndex']");
function adjustSubmittedProblemIndex() {
const index = $submittedProblemIndex.val();
const outputOnlyIndices = [];
const outputOnly = outputOnlyIndices.indexOf(index) >= 0;
if (outputOnly) {
$submittedProblemIndex.closest(".submit-
form").addClass("output-only");
} else {
$submittedProblemIndex.closest(".submit-
form").removeClass("output-only");
}
}
$submittedProblemIndex.change(function () {
adjustSubmittedProblemIndex();
});
adjustSubmittedProblemIndex();
$("select[name='programTypeId']").change(function () {
adjustNotice(parseInt($(this).val()));
});
$(".submit-form, .submitForm").submitOnce(function () {
var form = $(this);
var $ftaa = form.find("input[name='ftaa']");
var $bfaa = form.find("input[name='bfaa']");
return true;
});
});
</script>
<style>
#facebox .content:has(.diff-popup) {
width: 90vw;
max-width: 120rem !important;
}
.testCaseMarker {
position: absolute;
font-weight: bold;
font-size: 1rem;
}
.diff-popup {
width: 90vw;
max-width: 120rem !important;
display: none;
overflow: auto;
}
.input-output-copier {
font-size: 1.2rem;
float: right;
color: #888 !important;
cursor: pointer;
border: 1px solid rgb(185, 185, 185);
padding: 3px;
margin: 1px;
line-height: 1.1rem;
text-transform: none;
}
.input-output-copier:hover {
background-color: #def;
}
.test-explanation textarea {
width: 100%;
height: 1.5em;
}
.pending-submission-message {
color: darkorange !important;
}
</style>
<script>
const OPENING_SPACE = String.fromCharCode(1001);
const CLOSING_SPACE = String.fromCharCode(1002);
node.childNodes.forEach(function (child) {
result.push(nodeToText(child, node.tagName === "PRE").join(""));
});
return result;
}
$(".sample-test .title").each(function () {
const preId = ("id" + Math.random()).replaceAll(".", "0");
const cpyId = ("id" + Math.random()).replaceAll(".", "0");
$(this).parent().find("pre").attr("id", preId);
const $copy = $("<div title='Copy' data-clipboard-target='#" + preId +
"' id='" + cpyId + "' class='input-output-copier'>Copy</div>");
$(this).append($copy);
$(".test-form-item input").change(function () {
addPendingSubmissionMessage($($(this).closest("form")), "You changed
the answer, do not forget to submit it if you want to save the changes");
const index = $
(this).closest(".problemindexholder").attr("problemindex");
let test = "";
$(this).closest("form input").each(function () {
const test_ = $(this).attr("name");
if (test_ && test_.substring(0, 4) === "test") {
test = test_;
}
});
if (index.length > 0 && test.length > 0) {
const indexTest = index + "::" + test;
window.changedTests.add(indexTest);
}
});
$(window).on('beforeunload', function () {
if (window.changedTests.size > 0) {
return 'Dialog text here';
}
});
autosize($('.test-explanation textarea'));
$(".test-example-line").hover(function() {
$(this).attr("class").split(" ").forEach((clazz) => {
if (clazz.substr(0, "test-example-line-".length) === "test-example-
line-") {
let end = clazz.substr("test-example-line-".length);
if (end !== "even" && end !== "odd" && end !== "0") {
let top = 1E20;
let left = 1E20;
let problem = $(this).closest(".problemindexholder");
$(this).closest(".input").find("." +
clazz).css("background-color", "#FFFDE7").each(function() {
top = Math.min(top, $(this).offset().top);
left = Math.min(left, $(this).offset().left);
});
let testCaseMarker = problem.find(".testCaseMarker_" +
end);
if (testCaseMarker.length === 0) {
const html = "<div class=\"testCaseMarker
testCaseMarker_" + end + " notice\"></div>";
problem.append($(html));
testCaseMarker = problem.find(".testCaseMarker_" +
end);
}
if (testCaseMarker) {
testCaseMarker.show()
.offset({top, left: left - 20})
.text(end);
}
}
}
});
}, function() {
$(this).attr("class").split(" ").forEach((clazz) => {
if (clazz.substr(0, "test-example-line-".length) === "test-example-
line-") {
let end = clazz.substr("test-example-line-".length);
if (end !== "even" && end !== "odd" && end !== "0") {
$("." + clazz).css("background-color", "");
$
(this).closest(".problemindexholder").find(".testCaseMarker_" + end).hide();
}
}
});
});
});
</script>
</div>
</div>
<br style="clear: both;">
<div id="footer">
<div>Codeforces (c) Copyright 2010-2025 Mike Mirzayanov</div>
<div>The only programming contests Web 2.0 platform</div>
<div>Server time: Jan/13/2025 21:13:24<sup title="timezone
offset" style="font-size:8px;">UTC+7</sup> (i1).</div>
<div>Desktop version, switch to <a rel="nofollow"
class="switchToMobile"
href="https://yugihackerhsgfall24.contest.codeforces.com/group/jf2P3wolKK/contest/
580643/problem/B?mobile=true">mobile version</a>.</div>
<div class="smaller"><a
href="https://yugihackerhsgfall24.contest.codeforces.com/privacy">Privacy
Policy</a></div>
Codeforces.redirect(Codeforces.updateUrlParameter(document.location.href, "mobile",
"true"));
return false;
});
$(".switchToDesktop").click(function() {
Codeforces.redirect(Codeforces.updateUrlParameter(document.location.href, "mobile",
"false"));
return false;
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
if ($(window).width() < 1600) {
$('.button-up').css('width', '30px').css('line-height',
'30px').css('font-size', '20px');
}
$('.button-up').click(function () {
$('body,html').animate({
scrollTop: 0
}, 500);
return false;
});
$('.button-up').hover(function () {
$(this).animate({
'opacity':'1'
}).css({'background-color':'#e7ebf0','color':'#6a86a4'});
}, function () {
$(this).animate({
'opacity':'0.7'
}).css({'background':'none','color':'#d3dbe4'});;
});
}
Codeforces.focusOnError();
});
</script>
<div class="userListsFacebox" style="display:none;">
<div style="padding: 0.5em; width: 600px; max-height: 200px; overflow-y:
auto">
<div class="datatable" style="background-color: #E1E1E1; padding-bottom: 3px;">
<div class="lt"> </div>
<div class="rt"> </div>
<div class="lb"> </div>
<div class="rb"> </div>
<div style="position:absolute;right:0.25em;top:0.35em;">
<span style="padding:0;position:relative;bottom:2px;"
class="rowCount"></span>
if (window.updateDatatableFilter == undefined) {
window.updateDatatableFilter = function(i) {
var parent = $(i).parent().parent().parent().parent();
$("tr.no-items", parent).remove();
$("tr", parent).hide().removeClass('visible');
var text = $(i).val();
if (text) {
$("tr" + ":containsIgnoreCase('" + text + "')",
parent).show().addClass('visible');
} else {
parent.find(".rowCount").text("");
$("tr", parent).show().addClass('visible');
}
$(".datatable .closed").click(function () {
var parent = $(this).parent();
$(this).hide();
$(".filter", parent).fadeIn(function () {
$("input", parent).val("").focus().css("border", "1px
solid #aaa");
});
});
$(".datatable .opened").click(function () {
var parent = $(this).parent().parent();
$(".filter", parent).fadeOut(function () {
$(".closed", parent).show();
$("input", parent).val("").each(function () {
window.updateDatatableFilter(this);
});
});
});
$(".datatable table").each(function () {
var found = false;
$("tr", this).each(function () {
if (!found && $(this).find("th").size() == 0) {
found = true;
}
});
if (!found) {
$("<tr class='no-items visible'><td style=\"text-
align:left;\"colspan=\"32\">No items<\/td><\/tr>").appendTo(this);
}
});
$(".datatable table.tablesorter").each(function () {
$(this).bind("sortEnd", function () {
$(".datatable").each(function () {
$(this).find("th, td")
.removeClass("top").removeClass("bottom")
.removeClass("left").removeClass("right")
.removeClass("dark");
$(this).find("tr:first th").addClass("top");
$(this).find("tr:last td").addClass("bottom");
$(this).find("tr:odd td").addClass("dark");
$(this).find("tr td:first-child, tr th:first-
child").addClass("left");
$(this).find("tr td:last-child, tr th:last-
child").addClass("right");
});
});
});
}
});
</script>
</div>
</div>
<script type="application/javascript">
$(function() {
$(".userListMarker").click(function() {
$.post("/data/lists", {action: "findTouched"}, function(json) {
Codeforces.facebox(".userListsFacebox");
var tbody = $("#facebox tbody");
tbody.empty();
for (var i in json) {
tbody.append(
$("<tr></tr>").append(
$("<td></td>").attr("data-readKey",
json[i].readKey).text(json[i].name)
)
);
}
Codeforces.updateDatatables();
tbody.find("td").css("cursor", "pointer").click(function() {
document.location =
Codeforces.updateUrlParameter(document.location.href, "list", $(this).attr("data-
readKey"));
});
}, "json");
});
});
</script>
</div>