Codeforces/1851/index.html
Matej Focko 9c74f2847d
1851(rs): solve contest
* “A. Escalator Conversations”
* “B. Parity Sort”
* “C. Tiles Comeback”

Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-07-31 18:06:51 +02:00

1279 lines
95 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="X-Csrf-Token" content="09149a92b18def2ae04853d8d4e84c66"/>
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=0.01"/>
<script type="text/javascript" src="//codeforces.org/s/0/js/jquery-1.8.3.js"></script>
<script type="application/javascript">
window.locale = "en";
window.standaloneContest = false;
function adjustViewport() {
var screenWidthPx = Math.min($(window).width(), window.screen.width);
var siteWidthPx = 1100; // min width of site
var ratio = Math.min(screenWidthPx / siteWidthPx, 1.0);
var viewport = "width=device-width, initial-scale=" + ratio;
$('#viewport').attr('content', viewport);
var style = $('<style>html * { max-height: 1000000px; }</style>');
$('html > head').append(style);
}
if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
adjustViewport();
}
/* Protection against trailing dot in domain. */
let hostLength = window.location.host.length;
if (hostLength > 1 && window.location.host[hostLength - 1] === '.') {
window.location = window.location.protocol + "//" + window.location.host.substring(0, hostLength - 1);
}
</script>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
<meta http-equiv="profileName" content="f1">
<meta name="google-site-verification" content="OTd2dN5x4nS4OPknPI9JFg36fKxjqY0i1PSfFPv_J90"/>
<meta property="fb:admins" content="100001352546622" />
<meta property="og:image" content="//codeforces.org/s/0/images/codeforces-sponsored-by-ton.png" />
<link rel="image_src" href="//codeforces.org/s/0/images/codeforces-sponsored-by-ton.png" />
<meta property="og:title" content="Problems - Codeforces"/>
<meta property="og:description" content=""/>
<meta property="og:site_name" content="Codeforces"/>
<meta name="utc_offset" content="+03:00"/>
<meta name="verify-reformal" content="f56f99fd7e087fb6ccb48ef2" />
<title>Problems - Codeforces</title>
<meta name="description" content="Codeforces. Programming competitions and contests, programming community" />
<meta name="keywords" content="programming algorithm contest competition informatics olympiads c++ java graphs vkcup" />
<meta name="robots" content="index, follow" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/font-awesome.min.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/line-awesome.min.css" type="text/css" charset="utf-8" />
<link href='//fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Cuprum&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
<link rel="apple-touch-icon" sizes="57x57" href="//codeforces.org/s/0/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="//codeforces.org/s/0/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="//codeforces.org/s/0/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="//codeforces.org/s/0/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="//codeforces.org/s/0/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="//codeforces.org/s/0/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="//codeforces.org/s/0/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="//codeforces.org/s/0/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="//codeforces.org/s/0/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="//codeforces.org/s/0/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="//codeforces.org/s/0/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="//codeforces.org/s/0/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="//codeforces.org/s/0/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="//codeforces.org/s/0/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!--CombineResourcesFilter-->
<link rel="stylesheet" href="//codeforces.org/s/48188/css/prettify.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/clear.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/ttypography.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/problem-statement.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/second-level-menu.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/roundbox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/datatable.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/table-form.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/topic.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/jquery.jgrowl.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/facebox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/jquery.wysiwyg.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/jquery.autocomplete.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/codeforces.datepick.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/colorbox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/jquery.drafts.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/community.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/css/sidebar-menu.css" type="text/css" charset="utf-8" />
<!-- MathJax -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$$$','$$$']], displayMath: [['$$$$$$','$$$$$$']]}
});
MathJax.Hub.Register.StartupHook("End", function () {
Codeforces.runMathJaxListeners();
});
</script>
<script type="text/javascript" async
src="https://cdn-mathjax.codeforces.com/MathJax.js?config=TeX-AMS_HTML-full"
>
</script>
<!-- /MathJax -->
<script type="text/javascript" src="//codeforces.org/s/48188/js/prettify/prettify.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/moment-with-locales.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/pushstream.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.easing.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.lavalamp.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.jgrowl.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.swipe.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.hotkeys.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/facebox.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/controls/wysiwyg.colorpicker.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/controls/wysiwyg.table.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/controls/wysiwyg.image.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/controls/wysiwyg.link.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.datepick.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.ie6blocker.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.colorbox-min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.ba-bbq.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/jquery.drafts.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/clipboard.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/autosize.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/sjcl.js"></script>
<script type="text/javascript" src="/scripts/5716dbde6e61c3ccfa4e6ed058200e5f/en/codeforces-options.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/codeforces.js?v=20160131"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/EventCatcher.js?v=20160131"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/preparedVerdictFormats-en.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/js/confetti.min.js"></script>
<!--/CombineResourcesFilter-->
<link rel="stylesheet" href="//codeforces.org/s/48188/markitup/skins/markitup/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/48188/markitup/sets/markdown/style.css" type="text/css" charset="utf-8" />
<script type="text/javascript" src="//codeforces.org/s/48188/markitup/jquery.markitup.js"></script>
<script type="text/javascript" src="//codeforces.org/s/48188/markitup/sets/markdown/set.js"></script>
<!--[if IE]>
<style>
#sidebar {
padding-left: 1em;
margin: 1em 1em 1em 0;
}
</style>
<![endif]-->
</head>
<body class=" "><span style='display:none;' class='csrf-token' data-csrf='09149a92b18def2ae04853d8d4e84c66'>&nbsp;</span>
<!-- .notificationTextCleaner used in Codeforces.showAnnouncements() -->
<div class="notificationTextCleaner" style="font-size: 0"></div>
<div class="button-up" style="display: none; opacity: 0.7; width: 50px; height:100%; position: fixed; left: 0; top: 0; cursor: pointer; text-align: center; line-height: 35px; color: #d3dbe4; font-weight: bold; font-size: 3.0rem;"><i class="icon-circle-arrow-up"></i></div>
<div class="verdictPrototypeDiv" style="display: none;"></div>
<!-- Codeforces JavaScripts. -->
<script type="text/javascript">
String.prototype.hashCode = function() {
var hash = 0, i, chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
var queryMobile = Codeforces.queryString.mobile;
if (queryMobile === "true" || queryMobile === "false") {
Codeforces.putToStorage("useMobile", queryMobile === "true");
} else {
var useMobile = Codeforces.getFromStorage("useMobile");
if (useMobile === true || useMobile === false) {
if (useMobile != false) {
Codeforces.redirect(Codeforces.updateUrlParameter(document.location.href, "mobile", useMobile));
}
}
}
</script>
<script type="text/javascript">
if (window.parent.frames.length > 0) {
window.stop();
}
</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));
$.ajaxPrefilter(function(options, originalOptions, xhr) {
var csrf = Codeforces.getCsrfToken();
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();
}
$.ajaxSetup({ scriptCharset: "utf-8" ,contentType: "application/x-www-form-urlencoded; charset=UTF-8", headers: {
'X-Csrf-Token': Codeforces.getCsrfToken()
}});
window.updateTypography();
Codeforces.signForms();
setTimeout(function() {
$(".second-level-menu-list").lavaLamp({
fx: "backout",
speed: 700
});
}, 100);
Codeforces.countdown();
$("a[rel='photobox']").colorbox();
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() {
var title = $(this).attr("data-title");
if (title) {
Codeforces.alert(title);
} else {
Codeforces.alert($(this).attr("title"));
}
}).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("/data/contests");
Codeforces.setupSpoilers();
Codeforces.setupTutorials("/data/problemTutorial");
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-743380-5']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = (document.location.protocol == 'https:' ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<div id="body">
<div style="width: 950px; margin: 0 auto;" class="compact-problemset">
<div id="header" style="position: relative; margin: 0;">
<div style="float:left;">
<a href="/"><img height="65" style="height: 65px;" src="//codeforces.org/s/25487/images/codeforces-sponsored-by-ton.png" alt="Codeforces"/></a>
</div>
<div class="lang">
<div style="text-align: right;">
<a href="?locale=en"><img src="//codeforces.org/s/25487/images/flags/24/gb.png" title="In English" alt="In English"/></a>
<a href="?locale=ru"><img src="//codeforces.org/s/25487/images/flags/24/ru.png" title="По-русски" alt="По-русски"/></a>
</div>
</div>
<br style="clear: both;"/>
</div>
<br style="clear: both;"/>
<div style="text-align: center; font-size: 1.8rem; margin-bottom: 0.5em;"
class="caption">Codeforces Round 888 (Div. 3)</div>
<div style="border-top: 1px solid #ccc; height: 1em;"></div>
<div class="problem-frames">
<div
style="margin-bottom: 2em;"
>
<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);
const nodeToText = function (node, pre) {
let result = [];
if (node.tagName === "SCRIPT" || node.tagName === "math"
|| (node.classList && node.classList.contains("input-output-copier")))
return [];
if (node.tagName === "NOBR") {
result.push(OPENING_SPACE);
}
if (node.nodeType === Node.TEXT_NODE) {
let s = node.textContent;
if (!pre) {
s = s.replace(/\s+/g, " ");
}
if (s.length > 0) {
result.push(s);
}
}
if (pre && node.tagName === "BR") {
result.push("\n");
}
node.childNodes.forEach(function (child) {
result.push(nodeToText(child, node.tagName === "PRE").join(""));
});
if (node.tagName === "DIV"
|| node.tagName === "P"
|| node.tagName === "PRE"
|| node.tagName === "UL"
|| node.tagName === "LI"
) {
result.push("\n");
}
if (node.tagName === "NOBR") {
result.push(CLOSING_SPACE);
}
return result;
}
const isSpecial = function (c) {
return c === ',' || c === '.' || c === ';' || c === ')' || c === ' ';
}
const convertStatementToText = function(statmentNode) {
const text = nodeToText(statmentNode, false).join("").replace(/ +/g, " ").replace(/\n\n+/g, "\n\n");
let result = [];
for (let i = 0; i < text.length; i++) {
const c = text.charAt(i);
if (c === OPENING_SPACE) {
if (!((i > 0 && text.charAt(i - 1) === '(') || (result.length > 0 && result[result.length - 1] === ' '))) {
result.push('+');
}
} else if (c === CLOSING_SPACE) {
if (!(i + 1 < text.length && isSpecial(text.charAt(i + 1)))) {
result.push('-');
}
} else {
result.push(c);
}
}
return result.join("").split("\n").map(value => value.trim()).join("\n");
};
</script>
<div class="diff-popup">
</div>
<div class="problemindexholder" problemindex="A" data-uuid="ps_c4e5fcb71b8d8c6aa52d2419a4feb16b248c3b93">
<div style="display: none; margin:1em 0;text-align: center; position: relative;" class="alert alert-info diff-notifier">
<div>The problem statement has recently been changed. <a class="view-changes" href="#">View the changes.</a></div>
<span class="diff-notifier-close" style="position: absolute; top: 0.2em; right: 0.3em; cursor: pointer; font-size: 1.4em;">&times;</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">A. Escalator Conversations</div><div class="time-limit"><div class="property-title">time limit per test</div>2 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>One day, Vlad became curious about who he can have a conversation with on the escalator in the subway. There are a total of $$$n$$$ passengers. The escalator has a total of $$$m$$$ steps, all steps indexed from $$$1$$$ to $$$m$$$ and $$$i$$$-th step has height $$$i \cdot k$$$.</p><p>Vlad's height is $$$H$$$ centimeters. Two people with heights $$$a$$$ and $$$b$$$ can have a conversation on the escalator if they are standing on <span class="tex-font-style-bf">different</span> steps and the height difference between them is equal to the height difference between the steps.</p><p>For example, if two people have heights $$$170$$$ and $$$180$$$ centimeters, and $$$m = 10, k = 5$$$, then they can stand on steps numbered $$$7$$$ and $$$5$$$, where the height difference between the steps is equal to the height difference between the two people: $$$k \cdot 2 = 5 \cdot 2 = 10 = 180 - 170$$$. There are other possible ways.</p><p>Given an array $$$h$$$ of size $$$n$$$, where $$$h_i$$$ represents the height of the $$$i$$$-th person. Vlad is interested in how many people he can have a conversation with on the escalator <span class="tex-font-style-bf">individually</span>.</p><p>For example, if $$$n = 5, m = 3, k = 3, H = 11$$$, and $$$h = [5, 4, 14, 18, 2]$$$, Vlad can have a conversation with the person with height $$$5$$$ (Vlad will stand on step $$$1$$$, and the other person will stand on step $$$3$$$) and with the person with height $$$14$$$ (for example, Vlad can stand on step $$$3$$$, and the other person will stand on step $$$2$$$). Vlad cannot have a conversation with the person with height $$$2$$$ because even if they stand on the extreme steps of the escalator, the height difference between them will be $$$6$$$, while their height difference is $$$9$$$. Vlad cannot have a conversation with the rest of the people on the escalator, so the answer for this example is $$$2$$$.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.</p><p>Then the descriptions of the test cases follow.</p><p>The first line of each test case contains integers: $$$n, m, k, H$$$ ($$$1 \le n,m \le 50$$$, $$$1 \le k,H \le 10^6$$$). Here, $$$n$$$ is the number of people, $$$m$$$ is the number of steps, $$$k$$$ is the height difference between neighboring steps, and $$$H$$$ is Vlad's height.</p><p>The second line contains $$$n$$$ integers: $$$h_1, h_2, \ldots, h_n$$$ ($$$1 \le h_i \le 10^6$$$). Here, $$$h_i$$$ represents the height of the $$$i$$$-th person.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each test case, output a single integer — the number of people Vlad can have a conversation with on the escalator <span class="tex-font-style-bf">individually</span>.</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">7</div><div class="test-example-line test-example-line-odd test-example-line-1">5 3 3 11</div><div class="test-example-line test-example-line-odd test-example-line-1">5 4 14 18 2</div><div class="test-example-line test-example-line-even test-example-line-2">2 9 5 6</div><div class="test-example-line test-example-line-even test-example-line-2">11 9</div><div class="test-example-line test-example-line-odd test-example-line-3">10 50 3 11</div><div class="test-example-line test-example-line-odd test-example-line-3">43 44 74 98 62 60 99 4 11 73</div><div class="test-example-line test-example-line-even test-example-line-4">4 8 8 49</div><div class="test-example-line test-example-line-even test-example-line-4">68 58 82 73</div><div class="test-example-line test-example-line-odd test-example-line-5">7 1 4 66</div><div class="test-example-line test-example-line-odd test-example-line-5">18 66 39 83 48 99 79</div><div class="test-example-line test-example-line-even test-example-line-6">9 1 1 13</div><div class="test-example-line test-example-line-even test-example-line-6">26 23 84 6 60 87 40 41 25</div><div class="test-example-line test-example-line-odd test-example-line-7">6 13 3 28</div><div class="test-example-line test-example-line-odd test-example-line-7">30 70 85 13 1 55</div></pre></div><div class="output"><div class="title">Output</div><pre>
2
1
4
1
0
0
3
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>The first example is explained in the problem statement.</p><p>In the second example, Vlad can have a conversation with the person with height $$$11$$$.</p><p>In the third example, Vlad can have a conversation with people with heights: $$$44, 74, 98, 62$$$. Therefore, the answer is $$$4$$$.</p><p>In the fourth example, Vlad can have a conversation with the person with height $$$73$$$.</p></div></div><p> </p></div>
</div>
<script>
$(function () {
Codeforces.addMathJaxListener(function () {
let $problem = $("div[problemindex=A]");
let uuid = $problem.attr("data-uuid");
let statementText = convertStatementToText($problem.find(".ttypography").get(0));
let previousStatementText = Codeforces.getFromStorage(uuid);
if (previousStatementText) {
if (previousStatementText !== statementText) {
$problem.find(".diff-notifier").show();
$problem.find(".diff-notifier-close").click(function() {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
$problem.find(".diff-notifier").hide();
});
$problem.find("a.view-changes").click(function() {
$.post("/data/diff", {action: "getDiff", a: previousStatementText, b: statementText}, function (result) {
if (result["success"] === "true") {
Codeforces.facebox(".diff-popup", "//codeforces.org/s/25487");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
window.changedTests = new Set();
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}
const inputFileDiv = $("div.input-file");
const inputFile = inputFileDiv.text();
const outputFileDiv = $("div.output-file");
const outputFile = outputFileDiv.text();
if (!endsWith(inputFile, "standard input")
&& !endsWith(inputFile, "standard input")) {
inputFileDiv.attr("style", "font-weight: bold");
}
if (!endsWith(outputFile, "standard output")
&& !endsWith(outputFile, "standard output")) {
outputFileDiv.attr("style", "font-weight: bold");
}
const titleDiv = $("div.header div.title");
String.prototype.replaceAll = function (search, replace) {
return this.split(search).join(replace);
};
$(".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);
const clipboard = new Clipboard('#' + cpyId, {
text: function (trigger) {
const pre = document.querySelector('#' + preId);
const lines = pre.querySelectorAll(".test-example-line");
return Codeforces.filterClipboardText(pre.innerText, lines.length);
}
});
const isInput = $(this).parent().hasClass("input");
clipboard.on('success', function (e) {
if (isInput) {
Codeforces.showMessage("The example input has been copied into the clipboard");
} else {
Codeforces.showMessage("The example output has been copied into the clipboard");
}
e.clearSelection();
});
});
$(".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
style="margin-bottom: 2em;"
>
<div class="problemindexholder" problemindex="B" data-uuid="ps_b2c3631f47db804384969c7f8ebb1667921e033a">
<div style="display: none; margin:1em 0;text-align: center; position: relative;" class="alert alert-info diff-notifier">
<div>The problem statement has recently been changed. <a class="view-changes" href="#">View the changes.</a></div>
<span class="diff-notifier-close" style="position: absolute; top: 0.2em; right: 0.3em; cursor: pointer; font-size: 1.4em;">&times;</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">B. Parity Sort</div><div class="time-limit"><div class="property-title">time limit per test</div>2 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>You have an array of integers $$$a$$$ of length $$$n$$$. You can apply the following operation to the given array: </p><ul> <li> Swap two elements $$$a_i$$$ and $$$a_j$$$ such that $$$i \neq j$$$, $$$a_i$$$ and $$$a_j$$$ are either <span class="tex-font-style-bf">both</span> even or <span class="tex-font-style-bf">both</span> odd. </li></ul><p> Determine whether it is possible to sort the array in non-decreasing order by performing the operation any number of times (possibly zero).</p><p>For example, let $$$a$$$ = [$$$7, 10, 1, 3, 2$$$]. Then we can perform $$$3$$$ operations to sort the array: </p><ol> <li> Swap $$$a_3 = 1$$$ and $$$a_1 = 7$$$, since $$$1$$$ and $$$7$$$ are odd. We get $$$a$$$ = [$$$1, 10, 7, 3, 2$$$]; </li><li> Swap $$$a_2 = 10$$$ and $$$a_5 = 2$$$, since $$$10$$$ and $$$2$$$ are even. We get $$$a$$$ = [$$$1, 2, 7, 3, 10$$$]; </li><li> Swap $$$a_4 = 3$$$ and $$$a_3 = 7$$$, since $$$3$$$ and $$$7$$$ are odd. We get $$$a$$$ = [$$$1, 2, 3, 7, 10$$$]. </li></ol></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.</p><p>The description of the test cases follows.</p><p>The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of array $$$a$$$.</p><p>The second line of each test case contains exactly $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of array $$$a$$$.</p><p>It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each test case, output on a separate line: </p><ul> <li> <span class="tex-font-style-tt">YES</span> if the array can be sorted by applying the operation to it some number of times; </li><li> <span class="tex-font-style-tt">NO</span> otherwise. </li></ul><p>You can output <span class="tex-font-style-tt">YES</span> and <span class="tex-font-style-tt">NO</span> in any case (for example, strings <span class="tex-font-style-tt">yEs</span>, <span class="tex-font-style-tt">yes</span>, <span class="tex-font-style-tt">Yes</span> and <span class="tex-font-style-tt">YES</span> will be recognized as positive response).</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">6</div><div class="test-example-line test-example-line-odd test-example-line-1">5</div><div class="test-example-line test-example-line-odd test-example-line-1">7 10 1 3 2</div><div class="test-example-line test-example-line-even test-example-line-2">4</div><div class="test-example-line test-example-line-even test-example-line-2">11 9 3 5</div><div class="test-example-line test-example-line-odd test-example-line-3">5</div><div class="test-example-line test-example-line-odd test-example-line-3">11 3 15 3 2</div><div class="test-example-line test-example-line-even test-example-line-4">6</div><div class="test-example-line test-example-line-even test-example-line-4">10 7 8 1 2 3</div><div class="test-example-line test-example-line-odd test-example-line-5">1</div><div class="test-example-line test-example-line-odd test-example-line-5">10</div><div class="test-example-line test-example-line-even test-example-line-6">5</div><div class="test-example-line test-example-line-even test-example-line-6">6 6 4 1 6</div></pre></div><div class="output"><div class="title">Output</div><pre>
YES
YES
NO
NO
YES
NO</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>The first test case is explained in the problem statement.</p></div></div><p> </p></div>
</div>
<script>
$(function () {
Codeforces.addMathJaxListener(function () {
let $problem = $("div[problemindex=B]");
let uuid = $problem.attr("data-uuid");
let statementText = convertStatementToText($problem.find(".ttypography").get(0));
let previousStatementText = Codeforces.getFromStorage(uuid);
if (previousStatementText) {
if (previousStatementText !== statementText) {
$problem.find(".diff-notifier").show();
$problem.find(".diff-notifier-close").click(function() {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
$problem.find(".diff-notifier").hide();
});
$problem.find("a.view-changes").click(function() {
$.post("/data/diff", {action: "getDiff", a: previousStatementText, b: statementText}, function (result) {
if (result["success"] === "true") {
Codeforces.facebox(".diff-popup", "//codeforces.org/s/25487");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}
const inputFileDiv = $("div.input-file");
const inputFile = inputFileDiv.text();
const outputFileDiv = $("div.output-file");
const outputFile = outputFileDiv.text();
if (!endsWith(inputFile, "standard input")
&& !endsWith(inputFile, "standard input")) {
inputFileDiv.attr("style", "font-weight: bold");
}
if (!endsWith(outputFile, "standard output")
&& !endsWith(outputFile, "standard output")) {
outputFileDiv.attr("style", "font-weight: bold");
}
const titleDiv = $("div.header div.title");
});
</script>
</div>
<div
style="margin-bottom: 2em;"
>
<div class="problemindexholder" problemindex="C" data-uuid="ps_495b3d640fce348ea2002939d1be871b49f1a62e">
<div style="display: none; margin:1em 0;text-align: center; position: relative;" class="alert alert-info diff-notifier">
<div>The problem statement has recently been changed. <a class="view-changes" href="#">View the changes.</a></div>
<span class="diff-notifier-close" style="position: absolute; top: 0.2em; right: 0.3em; cursor: pointer; font-size: 1.4em;">&times;</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">C. Tiles Comeback</div><div class="time-limit"><div class="property-title">time limit per test</div>2 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>Vlad remembered that he had a series of $$$n$$$ tiles and a number $$$k$$$. The tiles were numbered from left to right, and the $$$i$$$-th tile had colour $$$c_i$$$.</p><p>If you stand on the <span class="tex-font-style-bf">first</span> tile and start jumping any number of tiles <span class="tex-font-style-bf">right</span>, you can get a path of length $$$p$$$. The length of the path is the number of tiles you stood on.</p><p>Vlad wants to see if it is possible to get a path of length $$$p$$$ such that: </p><ul> <li> it ends at tile with index $$$n$$$; </li><li> $$$p$$$ is divisible by $$$k$$$ </li><li> the path is divided into blocks of length exactly $$$k$$$ each; </li><li> tiles in each block have the same colour, the colors in adjacent blocks are not necessarily different. </li></ul><p>For example, let $$$n = 14$$$, $$$k = 3$$$.</p><p>The colours of the tiles are contained in the array $$$c$$$ = [$$$\color{red}{1}, \color{violet}{2}, \color{red}{1}, \color{red}{1}, \color{violet}{2}, \color{violet}{2}, \color{green}{3}, \color{green}{3}, \color{red}{1}, \color{green}{3}, \color{blue}{4}, \color{blue}{4}, \color{violet}{2}, \color{blue}{4}$$$]. Then we can construct a path of length $$$6$$$ consisting of $$$2$$$ blocks:</p><p>$$$\color{red}{c_1} \rightarrow \color{red}{c_3} \rightarrow \color{red}{c_4} \rightarrow \color{blue}{c_{11}} \rightarrow \color{blue}{c_{12}} \rightarrow \color{blue}{c_{14}}$$$</p><p>All tiles from the $$$1$$$-st block will have colour $$$\color{red}{\textbf{1}}$$$, from the $$$2$$$-nd block will have colour $$$\color{blue}{\textbf{4}}$$$.</p><p>It is also possible to construct a path of length $$$9$$$ in this example, in which all tiles from the $$$1$$$-st block will have colour $$$\color{red}{\textbf{1}}$$$, from the $$$2$$$-nd block will have colour $$$\color{green}{\textbf{3}}$$$, and from the $$$3$$$-rd block will have colour $$$\color{blue}{\textbf{4}}$$$.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.</p><p>The description of the test cases follows.</p><p>The first line of each test case ontains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$)—the number of tiles in the series and the length of the block.</p><p>The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, c_3, \dots, c_n$$$ ($$$1 \le c_i \le n$$$) — the colours of the tiles.</p><p>It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each test case, output on a separate line: </p><ul> <li> <span class="tex-font-style-tt">YES</span> if you can get a path that satisfies these conditions; </li><li> <span class="tex-font-style-tt">NO</span> otherwise. </li></ul><p>You can output <span class="tex-font-style-tt">YES</span> and <span class="tex-font-style-tt">NO</span> in any case (for example, strings <span class="tex-font-style-tt">yEs</span>, <span class="tex-font-style-tt">yes</span>, <span class="tex-font-style-tt">Yes</span> and <span class="tex-font-style-tt">YES</span> will be recognized as positive response).</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">10</div><div class="test-example-line test-example-line-odd test-example-line-1">4 2</div><div class="test-example-line test-example-line-odd test-example-line-1">1 1 1 1</div><div class="test-example-line test-example-line-even test-example-line-2">14 3</div><div class="test-example-line test-example-line-even test-example-line-2">1 2 1 1 7 5 3 3 1 3 4 4 2 4</div><div class="test-example-line test-example-line-odd test-example-line-3">3 3</div><div class="test-example-line test-example-line-odd test-example-line-3">3 1 3</div><div class="test-example-line test-example-line-even test-example-line-4">10 4</div><div class="test-example-line test-example-line-even test-example-line-4">1 2 1 2 1 2 1 2 1 2</div><div class="test-example-line test-example-line-odd test-example-line-5">6 2</div><div class="test-example-line test-example-line-odd test-example-line-5">1 3 4 1 6 6</div><div class="test-example-line test-example-line-even test-example-line-6">2 2</div><div class="test-example-line test-example-line-even test-example-line-6">1 1</div><div class="test-example-line test-example-line-odd test-example-line-7">4 2</div><div class="test-example-line test-example-line-odd test-example-line-7">2 1 1 1</div><div class="test-example-line test-example-line-even test-example-line-8">2 1</div><div class="test-example-line test-example-line-even test-example-line-8">1 2</div><div class="test-example-line test-example-line-odd test-example-line-9">3 2</div><div class="test-example-line test-example-line-odd test-example-line-9">2 2 2</div><div class="test-example-line test-example-line-even test-example-line-10">4 1</div><div class="test-example-line test-example-line-even test-example-line-10">1 1 2 2</div></pre></div><div class="output"><div class="title">Output</div><pre>
YES
YES
NO
NO
YES
YES
NO
YES
YES
YES
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first test case, you can jump from the first tile to the last tile;</p><p>The second test case is explained in the problem statement.</p></div></div><p> </p></div>
</div>
<script>
$(function () {
Codeforces.addMathJaxListener(function () {
let $problem = $("div[problemindex=C]");
let uuid = $problem.attr("data-uuid");
let statementText = convertStatementToText($problem.find(".ttypography").get(0));
let previousStatementText = Codeforces.getFromStorage(uuid);
if (previousStatementText) {
if (previousStatementText !== statementText) {
$problem.find(".diff-notifier").show();
$problem.find(".diff-notifier-close").click(function() {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
$problem.find(".diff-notifier").hide();
});
$problem.find("a.view-changes").click(function() {
$.post("/data/diff", {action: "getDiff", a: previousStatementText, b: statementText}, function (result) {
if (result["success"] === "true") {
Codeforces.facebox(".diff-popup", "//codeforces.org/s/25487");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}
const inputFileDiv = $("div.input-file");
const inputFile = inputFileDiv.text();
const outputFileDiv = $("div.output-file");
const outputFile = outputFileDiv.text();
if (!endsWith(inputFile, "standard input")
&& !endsWith(inputFile, "standard input")) {
inputFileDiv.attr("style", "font-weight: bold");
}
if (!endsWith(outputFile, "standard output")
&& !endsWith(outputFile, "standard output")) {
outputFileDiv.attr("style", "font-weight: bold");
}
const titleDiv = $("div.header div.title");
});
</script>
</div>
<div
style="margin-bottom: 2em;"
>
<div class="problemindexholder" problemindex="D" data-uuid="ps_5168013f2d3ae84a9e051a7050956d58ec357160">
<div style="display: none; margin:1em 0;text-align: center; position: relative;" class="alert alert-info diff-notifier">
<div>The problem statement has recently been changed. <a class="view-changes" href="#">View the changes.</a></div>
<span class="diff-notifier-close" style="position: absolute; top: 0.2em; right: 0.3em; cursor: pointer; font-size: 1.4em;">&times;</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">D. Prefix Permutation Sums</div><div class="time-limit"><div class="property-title">time limit per test</div>3 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>Your friends have an array of $$$n$$$ elements, calculated its array of prefix sums and passed it to you, accidentally losing one element during the transfer. Your task is to find out if the given array can matches <span class="tex-font-style-bf">permutation</span>.</p><p>A permutation of $$$n$$$ elements is an array of $$$n$$$ numbers from $$$1$$$ to $$$n$$$ such that each number occurs exactly <span class="tex-font-style-bf">one</span> times in it.</p><p>The array of prefix sums of the array $$$a$$$ — is such an array $$$b$$$ that $$$b_i = \sum_{j=1}^i a_j, 1 \le i \le n$$$.</p><p>For example, the original permutation was $$$[1, 5, 2, 4, 3]$$$. Its array of prefix sums — $$$[1, 6, 8, 12, 15]$$$. Having lost one element, you can get, for example, arrays $$$[6, 8, 12, 15]$$$ or $$$[1, 6, 8, 15]$$$.</p><p>It can also be shown that the array $$$[1, 2, 100]$$$ does not correspond to any permutation.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains a positive number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.</p><p>The first line of the description of each test case contains a positive number $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the size of the initial array.</p><p>The second line of the description of each test case contains $$$n - 1$$$ positive number $$$a_i$$$ ($$$1 \le a_i \le 10^{18}$$$), $$$a_{i-1} &lt; a_i$$$ — elements of the array of prefix sums.</p><p>It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each test case, output &quot;<span class="tex-font-style-tt">YES</span>&quot; if such a permutation exists, and &quot;<span class="tex-font-style-tt">NO</span>&quot; otherwise.</p><p>You can output &quot;<span class="tex-font-style-tt">YES</span>&quot; and &quot;<span class="tex-font-style-tt">NO</span>&quot; in any case (for example, the strings &quot;<span class="tex-font-style-tt">yEs</span>&quot;, &quot;<span class="tex-font-style-tt">yes</span>&quot; and &quot;<span class="tex-font-style-tt">Yes</span>&quot; will be recognized as a positive response).</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">12</div><div class="test-example-line test-example-line-odd test-example-line-1">5</div><div class="test-example-line test-example-line-odd test-example-line-1">6 8 12 15</div><div class="test-example-line test-example-line-even test-example-line-2">5</div><div class="test-example-line test-example-line-even test-example-line-2">1 6 8 15</div><div class="test-example-line test-example-line-odd test-example-line-3">4</div><div class="test-example-line test-example-line-odd test-example-line-3">1 2 100</div><div class="test-example-line test-example-line-even test-example-line-4">4</div><div class="test-example-line test-example-line-even test-example-line-4">1 3 6</div><div class="test-example-line test-example-line-odd test-example-line-5">2</div><div class="test-example-line test-example-line-odd test-example-line-5">2</div><div class="test-example-line test-example-line-even test-example-line-6">3</div><div class="test-example-line test-example-line-even test-example-line-6">1 2</div><div class="test-example-line test-example-line-odd test-example-line-7">4</div><div class="test-example-line test-example-line-odd test-example-line-7">3 7 10</div><div class="test-example-line test-example-line-even test-example-line-8">5</div><div class="test-example-line test-example-line-even test-example-line-8">5 44 46 50</div><div class="test-example-line test-example-line-odd test-example-line-9">4</div><div class="test-example-line test-example-line-odd test-example-line-9">1 9 10</div><div class="test-example-line test-example-line-even test-example-line-10">5</div><div class="test-example-line test-example-line-even test-example-line-10">13 21 36 42</div><div class="test-example-line test-example-line-odd test-example-line-11">5</div><div class="test-example-line test-example-line-odd test-example-line-11">1 2 3 1000000000000000000</div><div class="test-example-line test-example-line-even test-example-line-12">9</div><div class="test-example-line test-example-line-even test-example-line-12">9 11 12 20 25 28 30 33</div></pre></div><div class="output"><div class="title">Output</div><pre>
YES
YES
NO
YES
YES
NO
YES
NO
NO
NO
NO
NO
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the fourth example, for example, the permutation $$$[1, 2, 3, 4]$$$ is suitable. In the fifth example, for example, the permutation $$$[1, 2]$$$ is suitable. In the seventh example, for example, the permutation $$$[1, 2, 4, 3]$$$ is suitable.</p></div></div><p> </p></div>
</div>
<script>
$(function () {
Codeforces.addMathJaxListener(function () {
let $problem = $("div[problemindex=D]");
let uuid = $problem.attr("data-uuid");
let statementText = convertStatementToText($problem.find(".ttypography").get(0));
let previousStatementText = Codeforces.getFromStorage(uuid);
if (previousStatementText) {
if (previousStatementText !== statementText) {
$problem.find(".diff-notifier").show();
$problem.find(".diff-notifier-close").click(function() {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
$problem.find(".diff-notifier").hide();
});
$problem.find("a.view-changes").click(function() {
$.post("/data/diff", {action: "getDiff", a: previousStatementText, b: statementText}, function (result) {
if (result["success"] === "true") {
Codeforces.facebox(".diff-popup", "//codeforces.org/s/25487");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}
const inputFileDiv = $("div.input-file");
const inputFile = inputFileDiv.text();
const outputFileDiv = $("div.output-file");
const outputFile = outputFileDiv.text();
if (!endsWith(inputFile, "standard input")
&& !endsWith(inputFile, "standard input")) {
inputFileDiv.attr("style", "font-weight: bold");
}
if (!endsWith(outputFile, "standard output")
&& !endsWith(outputFile, "standard output")) {
outputFileDiv.attr("style", "font-weight: bold");
}
const titleDiv = $("div.header div.title");
});
</script>
</div>
<div
style="margin-bottom: 2em;"
>
<div class="problemindexholder" problemindex="E" data-uuid="ps_47b2a1bac7a32a7e8eb94423b23e1ba70bcdfbca">
<div style="display: none; margin:1em 0;text-align: center; position: relative;" class="alert alert-info diff-notifier">
<div>The problem statement has recently been changed. <a class="view-changes" href="#">View the changes.</a></div>
<span class="diff-notifier-close" style="position: absolute; top: 0.2em; right: 0.3em; cursor: pointer; font-size: 1.4em;">&times;</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">E. Nastya and Potions</div><div class="time-limit"><div class="property-title">time limit per test</div>3 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>Alchemist Nastya loves mixing potions. There are a total of $$$n$$$ types of potions, and one potion of type $$$i$$$ can be bought for $$$c_i$$$ coins.</p><p>Any kind of potions can be obtained in no more than one way, by mixing from several others. The potions used in the mixing process will be <span class="tex-font-style-bf">consumed</span>. Moreover, no potion can be obtained from itself through one or more mixing processes.</p><p>As an experienced alchemist, Nastya has an <span class="tex-font-style-bf">unlimited</span> supply of $$$k$$$ types of potions $$$p_1, p_2, \dots, p_k$$$, but she doesn't know which one she wants to obtain next. To decide, she asks you to find, for each $$$1 \le i \le n$$$, the minimum number of coins she needs to spend to obtain a potion of type $$$i$$$ next.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of each test contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.</p><p>Each test case is described as follows:</p><p>The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k &lt; n \le 2 \cdot 10^5$$$) — the total number of potion types and the number of potion types Nastya already has.</p><p>The second line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 10^9$$$) — the costs of buying the potions.</p><p>The third line contains $$$k$$$ distinct integers $$$p_1, p_2, \dots, p_k$$$ ($$$1 \le p_i \le n$$$) — the indices of potions Nastya already has an <span class="tex-font-style-bf">unlimited</span> supply of.</p><p>This is followed by $$$n$$$ lines describing ways to obtain potions by mixing.</p><p>Each line starts with the integer $$$m_i$$$ ($$$0 \le m_i &lt; n$$$) — the number of potions required to mix a potion of the type $$$i$$$ ($$$1 \le i \le n$$$).</p><p>Then line contains $$$m_i$$$ distinct integers $$$e_1, e_2, \dots, e_{m_i}$$$ ($$$1 \le e_j \le n$$$, $$$e_j \ne i$$$) — the indices of potions needed to mix a potion of the type $$$i$$$. If this list is empty, then a potion of the type $$$i$$$ can only be bought.</p><p>It is guaranteed that no potion can be obtained from itself through one or more mixing processes.</p><p>It is guaranteed that the sum of all $$$n$$$ values across all test cases does not exceed $$$2 \cdot 10^5$$$. Similarly, it is guaranteed that the sum of all $$$m_i$$$ values across all test cases does not exceed $$$2 \cdot 10^5$$$.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each test case, output $$$n$$$ integers — the minimum number of coins Nastya needs to spend to obtain a potion of each type.</p></div><div class="sample-tests"><div class="section-title">Examples</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">4</div><div class="test-example-line test-example-line-odd test-example-line-1">5 1</div><div class="test-example-line test-example-line-odd test-example-line-1">30 8 3 5 10</div><div class="test-example-line test-example-line-odd test-example-line-1">3</div><div class="test-example-line test-example-line-odd test-example-line-1">3 2 4 5</div><div class="test-example-line test-example-line-odd test-example-line-1">0 </div><div class="test-example-line test-example-line-odd test-example-line-1">0 </div><div class="test-example-line test-example-line-odd test-example-line-1">2 3 5</div><div class="test-example-line test-example-line-odd test-example-line-1">0 </div><div class="test-example-line test-example-line-even test-example-line-2">3 2</div><div class="test-example-line test-example-line-even test-example-line-2">5 143 3</div><div class="test-example-line test-example-line-even test-example-line-2">1 3</div><div class="test-example-line test-example-line-even test-example-line-2">1 2</div><div class="test-example-line test-example-line-even test-example-line-2">0 </div><div class="test-example-line test-example-line-even test-example-line-2">2 1 2</div><div class="test-example-line test-example-line-odd test-example-line-3">5 1</div><div class="test-example-line test-example-line-odd test-example-line-3">5 4 1 3 4</div><div class="test-example-line test-example-line-odd test-example-line-3">2</div><div class="test-example-line test-example-line-odd test-example-line-3">2 4 5</div><div class="test-example-line test-example-line-odd test-example-line-3">3 3 5 4</div><div class="test-example-line test-example-line-odd test-example-line-3">2 1 4</div><div class="test-example-line test-example-line-odd test-example-line-3">1 5</div><div class="test-example-line test-example-line-odd test-example-line-3">0 </div><div class="test-example-line test-example-line-even test-example-line-4">4 2</div><div class="test-example-line test-example-line-even test-example-line-4">1 1 5 4</div><div class="test-example-line test-example-line-even test-example-line-4">2 4</div><div class="test-example-line test-example-line-even test-example-line-4">3 2 4 3</div><div class="test-example-line test-example-line-even test-example-line-4">0 </div><div class="test-example-line test-example-line-even test-example-line-4">2 2 4</div><div class="test-example-line test-example-line-even test-example-line-4">1 2</div></pre></div><div class="output"><div class="title">Output</div><pre>
23 8 0 5 10
0 143 0
5 0 1 3 4
0 0 0 0
</pre></div><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">3</div><div class="test-example-line test-example-line-odd test-example-line-1">6 3</div><div class="test-example-line test-example-line-odd test-example-line-1">5 5 4 5 2 2</div><div class="test-example-line test-example-line-odd test-example-line-1">3 4 5</div><div class="test-example-line test-example-line-odd test-example-line-1">2 2 5</div><div class="test-example-line test-example-line-odd test-example-line-1">1 5</div><div class="test-example-line test-example-line-odd test-example-line-1">3 4 1 6</div><div class="test-example-line test-example-line-odd test-example-line-1">4 2 6 1 5</div><div class="test-example-line test-example-line-odd test-example-line-1">0 </div><div class="test-example-line test-example-line-odd test-example-line-1">0 </div><div class="test-example-line test-example-line-even test-example-line-2">6 2</div><div class="test-example-line test-example-line-even test-example-line-2">1 4 4 1 5 2</div><div class="test-example-line test-example-line-even test-example-line-2">3 6</div><div class="test-example-line test-example-line-even test-example-line-2">4 6 3 4 5</div><div class="test-example-line test-example-line-even test-example-line-2">4 6 5 3 4</div><div class="test-example-line test-example-line-even test-example-line-2">0 </div><div class="test-example-line test-example-line-even test-example-line-2">1 5</div><div class="test-example-line test-example-line-even test-example-line-2">1 6</div><div class="test-example-line test-example-line-even test-example-line-2">0 </div><div class="test-example-line test-example-line-odd test-example-line-3">2 1</div><div class="test-example-line test-example-line-odd test-example-line-3">4 3</div><div class="test-example-line test-example-line-odd test-example-line-3">1</div><div class="test-example-line test-example-line-odd test-example-line-3">0 </div><div class="test-example-line test-example-line-odd test-example-line-3">1 1</div></pre></div><div class="output"><div class="title">Output</div><pre>
0 0 0 0 0 2
0 0 0 0 0 0
0 0
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first test case of the first sample, it is optimal:</p><ul> <li> Get a potion of the first type by buying and mixing $$$2$$$, $$$3$$$ and $$$4$$$; </li><li> a potion of the second type can only be obtained by purchasing it; </li><li> Nastya already has an unlimited number of potions of the third type; </li><li> a potion of the fourth type is more profitable to buy than to buy and mix other potions; </li><li> a potion of the fifth type can only be obtained by purchasing it. </li></ul></div></div><p> </p></div>
</div>
<script>
$(function () {
Codeforces.addMathJaxListener(function () {
let $problem = $("div[problemindex=E]");
let uuid = $problem.attr("data-uuid");
let statementText = convertStatementToText($problem.find(".ttypography").get(0));
let previousStatementText = Codeforces.getFromStorage(uuid);
if (previousStatementText) {
if (previousStatementText !== statementText) {
$problem.find(".diff-notifier").show();
$problem.find(".diff-notifier-close").click(function() {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
$problem.find(".diff-notifier").hide();
});
$problem.find("a.view-changes").click(function() {
$.post("/data/diff", {action: "getDiff", a: previousStatementText, b: statementText}, function (result) {
if (result["success"] === "true") {
Codeforces.facebox(".diff-popup", "//codeforces.org/s/25487");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}
const inputFileDiv = $("div.input-file");
const inputFile = inputFileDiv.text();
const outputFileDiv = $("div.output-file");
const outputFile = outputFileDiv.text();
if (!endsWith(inputFile, "standard input")
&& !endsWith(inputFile, "standard input")) {
inputFileDiv.attr("style", "font-weight: bold");
}
if (!endsWith(outputFile, "standard output")
&& !endsWith(outputFile, "standard output")) {
outputFileDiv.attr("style", "font-weight: bold");
}
const titleDiv = $("div.header div.title");
});
</script>
</div>
<div
style="margin-bottom: 2em;"
>
<div class="problemindexholder" problemindex="F" data-uuid="ps_d886294be63d9fea6073546320120773a0511dbd">
<div style="display: none; margin:1em 0;text-align: center; position: relative;" class="alert alert-info diff-notifier">
<div>The problem statement has recently been changed. <a class="view-changes" href="#">View the changes.</a></div>
<span class="diff-notifier-close" style="position: absolute; top: 0.2em; right: 0.3em; cursor: pointer; font-size: 1.4em;">&times;</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">F. Lisa and the Martians</div><div class="time-limit"><div class="property-title">time limit per test</div>3 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>512 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>Lisa was kidnapped by martians! It okay, because she has watched a lot of TV shows about aliens, so she knows what awaits her. Let's call integer <span class="tex-font-style-it">martian</span> if it is <span class="tex-font-style-bf">a non-negative integer</span> and <span class="tex-font-style-bf">strictly less than</span> $$$2^k$$$, for example, when $$$k = 12$$$, the numbers $$$51$$$, $$$1960$$$, $$$0$$$ are <span class="tex-font-style-it">martian</span>, and the numbers $$$\pi$$$, $$$-1$$$, $$$\frac{21}{8}$$$, $$$4096$$$ are not.</p><p>The aliens will give Lisa $$$n$$$ <span class="tex-font-style-it">martian</span> numbers $$$a_1, a_2, \ldots, a_n$$$. Then they will ask her to name any <span class="tex-font-style-it">martian</span> number $$$x$$$. After that, Lisa will select a pair of numbers $$$a_i, a_j$$$ ($$$i \neq j$$$) in the given sequence and count $$$(a_i \oplus x) \&amp; (a_j \oplus x)$$$. The operation $$$\oplus$$$ means <a href="http://tiny.cc/xor_wiki">Bitwise exclusive OR</a>, the operation $$$\&amp;$$$ means <a href="http://tiny.cc/and_wiki ">Bitwise And</a>. For example, $$$(5 \oplus 17) \&amp; (23 \oplus 17) = (00101_2 \oplus 10001_2) \&amp; (10111_2 \oplus 10001_2) = 10100_2 \&amp; 00110_2 = 00100_2 = 4$$$.</p><p>Lisa is sure that the higher the calculated value, the higher her chances of returning home. Help the girl choose such $$$i, j, x$$$ that maximize the calculated value.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of testcases.</p><p>Each testcase is described by two lines.</p><p>The first line contains integers $$$n, k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le k \le 30$$$) — the length of the sequence of <span class="tex-font-style-it">martian</span> numbers and the value of $$$k$$$.</p><p>The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i &lt; 2^k$$$) — a sequence of <span class="tex-font-style-it">martian</span> numbers.</p><p>It is guaranteed that the sum of $$$n$$$ over all testcases <span class="tex-font-style-bf">does not exceed</span> $$$2 \cdot 10^5$$$.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each testcase, print three integers $$$i, j, x$$$ ($$$1 \le i, j \le n$$$, $$$i \neq j$$$, $$$0 \le x &lt; 2^k$$$). The value of $$$(a_i \oplus x) \&amp; (a_j \oplus x)$$$ should be the maximum possible.</p><p>If there are several solutions, you can print any one.</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">10</div><div class="test-example-line test-example-line-odd test-example-line-1">5 4</div><div class="test-example-line test-example-line-odd test-example-line-1">3 9 1 4 13</div><div class="test-example-line test-example-line-even test-example-line-2">3 1</div><div class="test-example-line test-example-line-even test-example-line-2">1 0 1</div><div class="test-example-line test-example-line-odd test-example-line-3">6 12</div><div class="test-example-line test-example-line-odd test-example-line-3">144 1580 1024 100 9 13</div><div class="test-example-line test-example-line-even test-example-line-4">4 3</div><div class="test-example-line test-example-line-even test-example-line-4">7 3 0 4</div><div class="test-example-line test-example-line-odd test-example-line-5">3 2</div><div class="test-example-line test-example-line-odd test-example-line-5">0 0 1</div><div class="test-example-line test-example-line-even test-example-line-6">2 4</div><div class="test-example-line test-example-line-even test-example-line-6">12 2</div><div class="test-example-line test-example-line-odd test-example-line-7">9 4</div><div class="test-example-line test-example-line-odd test-example-line-7">6 14 9 4 4 4 5 10 2</div><div class="test-example-line test-example-line-even test-example-line-8">2 1</div><div class="test-example-line test-example-line-even test-example-line-8">1 0</div><div class="test-example-line test-example-line-odd test-example-line-9">2 4</div><div class="test-example-line test-example-line-odd test-example-line-9">11 4</div><div class="test-example-line test-example-line-even test-example-line-10">9 4</div><div class="test-example-line test-example-line-even test-example-line-10">2 11 10 1 6 9 11 0 5</div></pre></div><div class="output"><div class="title">Output</div><pre>
1 3 14
1 3 0
5 6 4082
2 3 7
1 2 3
1 2 15
4 5 11
1 2 0
1 2 0
2 7 4
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>First testcase: $$$(3 \oplus 14) \&amp; (1 \oplus 14) = (0011_2 \oplus 1110_2) \&amp; (0001_2 \oplus 1110_2) = 1101_2 = 1101_2 \&amp; 1111_2 = 1101_2 = 13$$$.</p><p>Second testcase: $$$(1 \oplus 0) \&amp; (1 \oplus 0) = 1$$$.</p><p>Third testcase: $$$(9 \oplus 4082) \&amp; (13 \oplus 4082) = 4091$$$.</p><p>Fourth testcase: $$$(3 \oplus 7) \&amp; (0 \oplus 7) = 4$$$.</p></div></div><p> </p></div>
</div>
<script>
$(function () {
Codeforces.addMathJaxListener(function () {
let $problem = $("div[problemindex=F]");
let uuid = $problem.attr("data-uuid");
let statementText = convertStatementToText($problem.find(".ttypography").get(0));
let previousStatementText = Codeforces.getFromStorage(uuid);
if (previousStatementText) {
if (previousStatementText !== statementText) {
$problem.find(".diff-notifier").show();
$problem.find(".diff-notifier-close").click(function() {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
$problem.find(".diff-notifier").hide();
});
$problem.find("a.view-changes").click(function() {
$.post("/data/diff", {action: "getDiff", a: previousStatementText, b: statementText}, function (result) {
if (result["success"] === "true") {
Codeforces.facebox(".diff-popup", "//codeforces.org/s/25487");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}
const inputFileDiv = $("div.input-file");
const inputFile = inputFileDiv.text();
const outputFileDiv = $("div.output-file");
const outputFile = outputFileDiv.text();
if (!endsWith(inputFile, "standard input")
&& !endsWith(inputFile, "standard input")) {
inputFileDiv.attr("style", "font-weight: bold");
}
if (!endsWith(outputFile, "standard output")
&& !endsWith(outputFile, "standard output")) {
outputFileDiv.attr("style", "font-weight: bold");
}
const titleDiv = $("div.header div.title");
});
</script>
</div>
<div
style="margin-bottom: 1em;"
>
<div class="problemindexholder" problemindex="G" data-uuid="ps_06031b66a54d0a6fbf482f4b0d77472a9ff8283c">
<div style="display: none; margin:1em 0;text-align: center; position: relative;" class="alert alert-info diff-notifier">
<div>The problem statement has recently been changed. <a class="view-changes" href="#">View the changes.</a></div>
<span class="diff-notifier-close" style="position: absolute; top: 0.2em; right: 0.3em; cursor: pointer; font-size: 1.4em;">&times;</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">G. Vlad and the Mountains</div><div class="time-limit"><div class="property-title">time limit per test</div>5 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file"><div class="property-title">input</div>standard input</div><div class="output-file"><div class="property-title">output</div>standard output</div></div><div><p>Vlad decided to go on a trip to the mountains. He plans to move between $$$n$$$ mountains, some of which are connected by roads. The $$$i$$$-th mountain has a height of $$$h_i$$$.</p><p>If there is a road between mountains $$$i$$$ and $$$j$$$, Vlad can move from mountain $$$i$$$ to mountain $$$j$$$ by spending $$$h_j - h_i$$$ units of energy. If his energy drops below zero during the transition, he will not be able to move from mountain $$$i$$$ to mountain $$$j$$$. Note that $$$h_j - h_i$$$ can be negative and then the energy will be restored.</p><p>Vlad wants to consider different route options, so he asks you to answer the following queries: is it possible to construct some route starting at mountain $$$a$$$ and ending at mountain $$$b$$$, given that he initially has $$$e$$$ units of energy?</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.</p><p>The descriptions of the test cases follow.</p><p>The first line of each test case contains two numbers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le \min(\frac{n\cdot(n - 1)}{2}, 2 \cdot 10^5)$$$) — the number of mountains and the number of roads between them, respectively.</p><p>The second line contains $$$n$$$ integers $$$h_1, h_2, h_3, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$) — the heights of the mountains.</p><p>The next $$$m$$$ lines contain two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) — the numbers of the mountains connected by a road. It is guaranteed that no road appears twice.</p><p>The next line contains an integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries.</p><p>The following $$$q$$$ lines contain three numbers $$$a$$$, $$$b$$$, and $$$e$$$ ($$$1 \le a, b \le n$$$, $$$0 \le e \le 10^9$$$) — the initial and final mountains of the route, and the amount of energy, respectively.</p><p>It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. The same guarantee applies to $$$m$$$ and $$$q$$$.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each query, output &quot;<span class="tex-font-style-tt">YES</span>&quot; if Vlad can construct a route from mountain $$$a$$$ to mountain $$$b$$$, and &quot;<span class="tex-font-style-tt">NO</span>&quot; otherwise.</p><p>You can output the answer in any case (for example, the strings &quot;<span class="tex-font-style-tt">yEs</span>&quot;, &quot;<span class="tex-font-style-tt">yes</span>&quot;, &quot;<span class="tex-font-style-tt">Yes</span>&quot;, and &quot;<span class="tex-font-style-tt">YES</span>&quot; will be recognized as a positive answer).</p><p>In the examples below, the answers for different test cases are separated by an empty line, which you do not need to output.</p></div><div class="sample-tests"><div class="section-title">Examples</div><div class="sample-test"><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">2</div><div class="test-example-line test-example-line-odd test-example-line-1">7 7</div><div class="test-example-line test-example-line-odd test-example-line-1">1 5 3 4 2 4 1</div><div class="test-example-line test-example-line-odd test-example-line-1">1 4</div><div class="test-example-line test-example-line-odd test-example-line-1">4 3</div><div class="test-example-line test-example-line-odd test-example-line-1">3 6</div><div class="test-example-line test-example-line-odd test-example-line-1">3 2</div><div class="test-example-line test-example-line-odd test-example-line-1">2 5</div><div class="test-example-line test-example-line-odd test-example-line-1">5 6</div><div class="test-example-line test-example-line-odd test-example-line-1">5 7</div><div class="test-example-line test-example-line-odd test-example-line-1">5</div><div class="test-example-line test-example-line-odd test-example-line-1">1 1 3</div><div class="test-example-line test-example-line-odd test-example-line-1">6 2 0</div><div class="test-example-line test-example-line-odd test-example-line-1">4 7 0</div><div class="test-example-line test-example-line-odd test-example-line-1">1 7 4</div><div class="test-example-line test-example-line-odd test-example-line-1">1 7 2</div><div class="test-example-line test-example-line-even test-example-line-2">6 5</div><div class="test-example-line test-example-line-even test-example-line-2">4 7 6 2 5 1</div><div class="test-example-line test-example-line-even test-example-line-2">1 3</div><div class="test-example-line test-example-line-even test-example-line-2">5 3</div><div class="test-example-line test-example-line-even test-example-line-2">1 5</div><div class="test-example-line test-example-line-even test-example-line-2">2 4</div><div class="test-example-line test-example-line-even test-example-line-2">6 2</div><div class="test-example-line test-example-line-even test-example-line-2">5</div><div class="test-example-line test-example-line-even test-example-line-2">1 5 1</div><div class="test-example-line test-example-line-even test-example-line-2">1 3 1</div><div class="test-example-line test-example-line-even test-example-line-2">1 2 1000</div><div class="test-example-line test-example-line-even test-example-line-2">6 2 6</div><div class="test-example-line test-example-line-even test-example-line-2">6 2 5</div></pre></div><div class="output"><div class="title">Output</div><pre>
YES
NO
YES
YES
NO
YES
NO
NO
YES
NO
</pre></div><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">2</div><div class="test-example-line test-example-line-odd test-example-line-1">3 2</div><div class="test-example-line test-example-line-odd test-example-line-1">1 3 9</div><div class="test-example-line test-example-line-odd test-example-line-1">1 2</div><div class="test-example-line test-example-line-odd test-example-line-1">2 3</div><div class="test-example-line test-example-line-odd test-example-line-1">5</div><div class="test-example-line test-example-line-odd test-example-line-1">1 1 1</div><div class="test-example-line test-example-line-odd test-example-line-1">3 2 2</div><div class="test-example-line test-example-line-odd test-example-line-1">1 1 2</div><div class="test-example-line test-example-line-odd test-example-line-1">3 3 0</div><div class="test-example-line test-example-line-odd test-example-line-1">1 2 1</div><div class="test-example-line test-example-line-even test-example-line-2">3 3</div><div class="test-example-line test-example-line-even test-example-line-2">1 4 1</div><div class="test-example-line test-example-line-even test-example-line-2">1 2</div><div class="test-example-line test-example-line-even test-example-line-2">2 3</div><div class="test-example-line test-example-line-even test-example-line-2">1 3</div><div class="test-example-line test-example-line-even test-example-line-2">5</div><div class="test-example-line test-example-line-even test-example-line-2">3 3 9</div><div class="test-example-line test-example-line-even test-example-line-2">1 3 6</div><div class="test-example-line test-example-line-even test-example-line-2">1 1 2</div><div class="test-example-line test-example-line-even test-example-line-2">3 3 6</div><div class="test-example-line test-example-line-even test-example-line-2">3 3 4</div></pre></div><div class="output"><div class="title">Output</div><pre>
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
</pre></div><div class="input"><div class="title">Input</div><pre><div class="test-example-line test-example-line-even test-example-line-0">1</div><div class="test-example-line test-example-line-odd test-example-line-1">6 10</div><div class="test-example-line test-example-line-odd test-example-line-1">7 9 2 10 8 6</div><div class="test-example-line test-example-line-odd test-example-line-1">4 2</div><div class="test-example-line test-example-line-odd test-example-line-1">6 1</div><div class="test-example-line test-example-line-odd test-example-line-1">4 5</div><div class="test-example-line test-example-line-odd test-example-line-1">3 5</div><div class="test-example-line test-example-line-odd test-example-line-1">6 4</div><div class="test-example-line test-example-line-odd test-example-line-1">1 3</div><div class="test-example-line test-example-line-odd test-example-line-1">2 6</div><div class="test-example-line test-example-line-odd test-example-line-1">6 5</div><div class="test-example-line test-example-line-odd test-example-line-1">1 2</div><div class="test-example-line test-example-line-odd test-example-line-1">3 6</div><div class="test-example-line test-example-line-odd test-example-line-1">5</div><div class="test-example-line test-example-line-odd test-example-line-1">4 4 8</div><div class="test-example-line test-example-line-odd test-example-line-1">3 3 1</div><div class="test-example-line test-example-line-odd test-example-line-1">5 5 9</div><div class="test-example-line test-example-line-odd test-example-line-1">2 1 7</div><div class="test-example-line test-example-line-odd test-example-line-1">6 6 10</div></pre></div><div class="output"><div class="title">Output</div><pre>
YES
YES
YES
YES
YES
</pre></div></div></div></div><p> </p></div>
</div>
<script>
$(function () {
Codeforces.addMathJaxListener(function () {
let $problem = $("div[problemindex=G]");
let uuid = $problem.attr("data-uuid");
let statementText = convertStatementToText($problem.find(".ttypography").get(0));
let previousStatementText = Codeforces.getFromStorage(uuid);
if (previousStatementText) {
if (previousStatementText !== statementText) {
$problem.find(".diff-notifier").show();
$problem.find(".diff-notifier-close").click(function() {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
$problem.find(".diff-notifier").hide();
});
$problem.find("a.view-changes").click(function() {
$.post("/data/diff", {action: "getDiff", a: previousStatementText, b: statementText}, function (result) {
if (result["success"] === "true") {
Codeforces.facebox(".diff-popup", "//codeforces.org/s/25487");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script>
<script type="text/javascript">
$(document).ready(function () {
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}
const inputFileDiv = $("div.input-file");
const inputFile = inputFileDiv.text();
const outputFileDiv = $("div.output-file");
const outputFile = outputFileDiv.text();
if (!endsWith(inputFile, "standard input")
&& !endsWith(inputFile, "standard input")) {
inputFileDiv.attr("style", "font-weight: bold");
}
if (!endsWith(outputFile, "standard output")
&& !endsWith(outputFile, "standard output")) {
outputFileDiv.attr("style", "font-weight: bold");
}
const titleDiv = $("div.header div.title");
});
</script>
</div>
</div>
<div id="footer">
<div><a href="https://codeforces.com/">Codeforces</a> (c) Copyright 2010-2023 Mike Mirzayanov</div>
<div>The only programming contests Web 2.0 platform</div>
</div>
</div>
</div>
<script type="application/javascript">
if ('serviceWorker' in navigator && 'fetch' in window && 'caches' in window) {
navigator.serviceWorker.register('/service-worker-25487.js')
.then(function (registration) {
console.log('Service worker registered: ', registration);
})
.catch(function (error) {
console.log('Registration failed: ', error);
});
}
</script>
<script>(function(){var js = "window['__CF$cv$params']={r:'7ec534130eb5b35f'};_cpo=document.createElement('script');_cpo.nonce='',_cpo.src='/cdn-cgi/challenge-platform/scripts/invisible.js',document.getElementsByTagName('head')[0].appendChild(_cpo);";var _0xh = document.createElement('iframe');_0xh.height = 1;_0xh.width = 1;_0xh.style.position = 'absolute';_0xh.style.top = 0;_0xh.style.left = 0;_0xh.style.border = 'none';_0xh.style.visibility = 'hidden';document.body.appendChild(_0xh);function handler() {var _0xi = _0xh.contentDocument || _0xh.contentWindow.document;if (_0xi) {var _0xj = _0xi.createElement('script');_0xj.innerHTML = js;_0xi.getElementsByTagName('head')[0].appendChild(_0xj);}}if (document.readyState !== 'loading') {handler();} else if (window.addEventListener) {document.addEventListener('DOMContentLoaded', handler);} else {var prev = document.onreadystatechange || function () {};document.onreadystatechange = function (e) {prev(e);if (document.readyState !== 'loading') {document.onreadystatechange = prev;handler();}};}})();</script></body>
</html>