Codeforces/977/index.html
Matej Focko d98a05a245
977(A,cpp): solve “Wrong Subtraction”
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-07-10 14:23:27 +02:00

1113 lines
65 KiB
HTML

<!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="a0ea42f7a32d84225c8c095f356aa6e7"/>
<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/62837/css/font-awesome.min.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/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/62837/css/prettify.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/clear.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/ttypography.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/problem-statement.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/second-level-menu.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/roundbox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/datatable.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/table-form.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/topic.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/jquery.jgrowl.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/facebox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/jquery.wysiwyg.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/jquery.autocomplete.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/codeforces.datepick.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/colorbox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/jquery.drafts.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/css/community.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/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/62837/js/prettify/prettify.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/moment-with-locales.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/pushstream.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.easing.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.lavalamp.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.jgrowl.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.swipe.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.hotkeys.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/facebox.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/controls/wysiwyg.colorpicker.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/controls/wysiwyg.table.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/controls/wysiwyg.image.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/controls/wysiwyg.link.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.datepick.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.ie6blocker.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.colorbox-min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.ba-bbq.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/jquery.drafts.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/clipboard.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/autosize.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/sjcl.js"></script>
<script type="text/javascript" src="/scripts/7524722dd28773e2987937a750cd80cd/en/codeforces-options.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/codeforces.js?v=20160131"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/EventCatcher.js?v=20160131"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/preparedVerdictFormats-en.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/js/confetti.min.js"></script>
<!--/CombineResourcesFilter-->
<link rel="stylesheet" href="//codeforces.org/s/62837/markitup/skins/markitup/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/62837/markitup/sets/markdown/style.css" type="text/css" charset="utf-8" />
<script type="text/javascript" src="//codeforces.org/s/62837/markitup/jquery.markitup.js"></script>
<script type="text/javascript" src="//codeforces.org/s/62837/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='a0ea42f7a32d84225c8c095f356aa6e7'>&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/14919/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/14919/images/flags/24/gb.png" title="In English" alt="In English"/></a>
<a href="?locale=ru"><img src="//codeforces.org/s/14919/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 479 (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_69cce5d6a8c570a2802b85e86e1851dcb9397ab5">
<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. Wrong Subtraction</div><div class="time-limit"><div class="property-title">time limit per test</div>1 second</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>Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:</p><ul> <li> if the last digit of the number is non-zero, she decreases the number by one; </li><li> if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). </li></ul><p>You are given an integer number $$$n$$$. Tanya will subtract one from it $$$k$$$ times. Your task is to print the result after all $$$k$$$ subtractions.</p><p>It is guaranteed that the result will be positive integer number.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of the input contains two integer numbers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le k \le 50$$$) — the number from which Tanya will subtract and the number of subtractions correspondingly.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print one integer number — the result of the decreasing $$$n$$$ by one $$$k$$$ times.</p><p>It is guaranteed that the result will be positive integer number. </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>512 4<br /></pre></div><div class="output"><div class="title">Output</div><pre>50<br /></pre></div><div class="input"><div class="title">Input</div><pre>1000000000 9<br /></pre></div><div class="output"><div class="title">Output</div><pre>1<br /></pre></div></div></div><div class="note"><div class="section-title">Note</div><p>The first example corresponds to the following sequence: $$$512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$$$.</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/14919");
$("#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_c5e66a94d66a801d187e452c63d9b280e61e4a60">
<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. Two-gram</div><div class="time-limit"><div class="property-title">time limit per test</div>1 second</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>Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, &quot;<span class="tex-font-style-tt">AZ</span>&quot;, &quot;<span class="tex-font-style-tt">AA</span>&quot;, &quot;<span class="tex-font-style-tt">ZA</span>&quot; — three distinct two-grams.</p><p>You are given a string $$$s$$$ consisting of $$$n$$$ capital Latin letters. Your task is to find <span class="tex-font-style-bf">any</span> two-gram contained in the given string <span class="tex-font-style-bf">as a substring</span> (i.e. two consecutive characters of the string) maximal number of times. For example, for string $$$s$$$ = &quot;<span class="tex-font-style-tt">BBAABBBA</span>&quot; the answer is two-gram &quot;<span class="tex-font-style-tt">BB</span>&quot;, which contained in $$$s$$$ three times. In other words, find any most frequent two-gram.</p><p>Note that occurrences of the two-gram can overlap with each other.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of the input contains integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ capital Latin letters.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print the only line containing exactly two capital Latin letters — <span class="tex-font-style-bf">any</span> two-gram contained in the given string $$$s$$$ <span class="tex-font-style-bf">as a substring</span> (i.e. two consecutive characters of the string) maximal number of times.</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>7<br />ABACABA<br /></pre></div><div class="output"><div class="title">Output</div><pre>AB<br /></pre></div><div class="input"><div class="title">Input</div><pre>5<br />ZZZAA<br /></pre></div><div class="output"><div class="title">Output</div><pre>ZZ<br /></pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first example &quot;<span class="tex-font-style-tt">BA</span>&quot; is also valid answer.</p><p>In the second example the only two-gram &quot;<span class="tex-font-style-tt">ZZ</span>&quot; can be printed because it contained in the string &quot;<span class="tex-font-style-tt">ZZZAA</span>&quot; two times.</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/14919");
$("#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_ebee70f6c834ee8d0a48a93e704dee4546debd7c">
<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. Less or Equal</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 are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print <span class="tex-font-style-bf">any integer</span> number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.</p><p>Note that the sequence can contain equal elements.</p><p>If there is no such $$$x$$$, print &quot;<span class="tex-font-style-tt">-1</span>&quot; (without quotes).</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print <span class="tex-font-style-bf">any integer</span> number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$.</p><p>If there is no such $$$x$$$, print &quot;<span class="tex-font-style-tt">-1</span>&quot; (without quotes).</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>7 4<br />3 7 5 1 10 3 20<br /></pre></div><div class="output"><div class="title">Output</div><pre>6</pre></div><div class="input"><div class="title">Input</div><pre>7 2<br />3 7 5 1 10 3 20<br /></pre></div><div class="output"><div class="title">Output</div><pre>-1<br /></pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.</p><p>In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this number because $$$3$$$ elements of the given sequence will be also less than or equal to this number.</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/14919");
$("#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_08ad1612f9209b5ac43faa23848479b9a4e4efa8">
<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. Divide by three, multiply by two</div><div class="time-limit"><div class="property-title">time limit per test</div>1 second</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>Polycarp likes to play with numbers. He takes some integer number $$$x$$$, writes it down on the board, and then performs with it $$$n - 1$$$ operations of the two kinds: </p><ul> <li> divide the number $$$x$$$ by $$$3$$$ ($$$x$$$ must be divisible by $$$3$$$); </li><li> multiply the number $$$x$$$ by $$$2$$$. </li></ul><p>After each operation, Polycarp writes down the result on the board and replaces $$$x$$$ by the result. So there will be $$$n$$$ numbers on the board after all.</p><p>You are given a sequence of length $$$n$$$ — the numbers that Polycarp wrote down. This sequence is given in arbitrary order, i.e. the order of the sequence can mismatch the order of the numbers written on the board.</p><p>Your problem is to rearrange (reorder) elements of this sequence in such a way that it can match possible Polycarp's game in the order of the numbers written on the board. I.e. each next number will be exactly two times of the previous number or exactly one third of previous number.</p><p>It is guaranteed that the answer exists.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of the input contatins an integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the number of the elements in the sequence. The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 3 \cdot 10^{18}$$$) — rearranged (reordered) sequence that Polycarp can wrote down on the board.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print $$$n$$$ integer numbers — rearranged (reordered) input sequence that can be the sequence that Polycarp could write down on the board.</p><p>It is guaranteed that the answer exists.</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>6<br />4 8 6 3 12 9<br /></pre></div><div class="output"><div class="title">Output</div><pre>9 3 6 12 4 8 <br /></pre></div><div class="input"><div class="title">Input</div><pre>4<br />42 28 84 126<br /></pre></div><div class="output"><div class="title">Output</div><pre>126 42 84 28 <br /></pre></div><div class="input"><div class="title">Input</div><pre>2<br />1000000000000000000 3000000000000000000<br /></pre></div><div class="output"><div class="title">Output</div><pre>3000000000000000000 1000000000000000000 <br /></pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first example the given sequence can be rearranged in the following way: $$$[9, 3, 6, 12, 4, 8]$$$. It can match possible Polycarp's game which started with $$$x = 9$$$.</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/14919");
$("#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_b2b3e9680d67a2b42d5a0aeff90f689936bdd1e3">
<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. Cyclic Components</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 are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Your task is to find the number of connected components which are cycles.</p><p>Here are some definitions of graph theory.</p><p>An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices. All edges are bidirectional (i.e. if a vertex $$$a$$$ is connected with a vertex $$$b$$$, a vertex $$$b$$$ is also connected with a vertex $$$a$$$). An edge can't connect vertex with itself, there is at most one edge between a pair of vertices.</p><p>Two vertices $$$u$$$ and $$$v$$$ belong to the same connected component if and only if there is at least one path along edges connecting $$$u$$$ and $$$v$$$.</p><p>A connected component is a cycle if and only if its vertices can be reordered in such a way that:</p><ul> <li> the first vertex is connected with the second vertex by an edge, </li><li> the second vertex is connected with the third vertex by an edge, </li><li> ... </li><li> the last vertex is connected with the first vertex by an edge, </li><li> all the described edges of a cycle are distinct. </li></ul><p>A cycle doesn't contain any other edges except described above. By definition any cycle contains three or more vertices.</p><center> <img class="tex-graphics" src="https://espresso.codeforces.com/69828f4d3554b0093ff12f1466d664d757de7a79.png" style="max-width: 100.0%;max-height: 100.0%;" /> <span class="tex-font-size-small">There are $$$6$$$ connected components, $$$2$$$ of them are cycles: $$$[7, 10, 16]$$$ and $$$[5, 11, 9, 15]$$$.</span> </center></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains two integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) — number of vertices and edges.</p><p>The following $$$m$$$ lines contains edges: edge $$$i$$$ is given as a pair of vertices $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$). There is no multiple edges in the given graph, i.e. for each pair ($$$v_i, u_i$$$) there no other pairs ($$$v_i, u_i$$$) and ($$$u_i, v_i$$$) in the list of edges.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print one integer — the number of connected components which are also cycles.</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>5 4<br />1 2<br />3 4<br />5 4<br />3 5<br /></pre></div><div class="output"><div class="title">Output</div><pre>1<br /></pre></div><div class="input"><div class="title">Input</div><pre>17 15<br />1 8<br />1 12<br />5 11<br />11 9<br />9 15<br />15 5<br />4 13<br />3 13<br />4 3<br />10 16<br />7 10<br />16 7<br />14 3<br />14 4<br />17 6<br /></pre></div><div class="output"><div class="title">Output</div><pre>2<br /></pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first example only component $$$[3, 4, 5]$$$ is also a cycle.</p><p>The illustration above corresponds to the second example.</p></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/14919");
$("#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="F" data-uuid="ps_652247df3269eda9c2c0ac36c3a1f5947f391b0a">
<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. Consecutive Subsequence</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 are given an integer array of length $$$n$$$.</p><p>You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $$$[x, x + 1, \dots, x + k - 1]$$$ for some value $$$x$$$ and length $$$k$$$.</p><p>Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array $$$[5, 3, 1, 2, 4]$$$ the following arrays are subsequences: $$$[3]$$$, $$$[5, 3, 1, 2, 4]$$$, $$$[5, 1, 4]$$$, but the array $$$[1, 3]$$$ is not.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line of the input containing integer number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array. The second line of the input containing $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.</p></div><div class="output-specification"><div class="section-title">Output</div><p>On the first line print $$$k$$$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.</p><p>On the second line print the sequence of the indices of the <span class="tex-font-style-bf">any</span> maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.</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>7<br />3 3 4 7 5 6 8<br /></pre></div><div class="output"><div class="title">Output</div><pre>4<br />2 3 5 6 <br /></pre></div><div class="input"><div class="title">Input</div><pre>6<br />1 3 5 2 4 6<br /></pre></div><div class="output"><div class="title">Output</div><pre>2<br />1 4 <br /></pre></div><div class="input"><div class="title">Input</div><pre>4<br />10 9 8 7<br /></pre></div><div class="output"><div class="title">Output</div><pre>1<br />1 <br /></pre></div><div class="input"><div class="title">Input</div><pre>9<br />6 7 8 3 4 5 9 10 11<br /></pre></div><div class="output"><div class="title">Output</div><pre>6<br />1 2 3 7 8 9 <br /></pre></div></div></div><div class="note"><div class="section-title">Note</div><p>All valid answers for the first example (as sequences of indices): </p><ul> <li> $$$[1, 3, 5, 6]$$$ </li><li> $$$[2, 3, 5, 6]$$$ </li></ul><p>All valid answers for the second example: </p><ul> <li> $$$[1, 4]$$$ </li><li> $$$[2, 5]$$$ </li><li> $$$[3, 6]$$$ </li></ul><p>All valid answers for the third example: </p><ul> <li> $$$[1]$$$ </li><li> $$$[2]$$$ </li><li> $$$[3]$$$ </li><li> $$$[4]$$$ </li></ul><p>All valid answers for the fourth example: </p><ul> <li> $$$[1, 2, 3, 7, 8, 9]$$$ </li></ul></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/14919");
$("#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-14919.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:'7e47f3c65be24137',m:'0v8oegTdFo9v1ZpqQa7JeodVXG8r65GAiLqCPlfYT_E-1688983149-0-AS9tLuk4OHVwd/PpNDiqeVokALTOzFhOT1WdqyQOsuCF'};_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.nonce = '';_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>