Codeforces/231/index.html
Matej Focko a29844dd09
231(A,java): solve “Team”
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-07-10 09:56:59 +02:00

1035 lines
69 KiB
HTML
Raw Permalink 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="f654ee5b8bdf2239b0f7991aa2a7a469"/>
<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/19903/css/font-awesome.min.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/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/19903/css/prettify.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/clear.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/ttypography.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/problem-statement.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/second-level-menu.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/roundbox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/datatable.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/table-form.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/topic.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/jquery.jgrowl.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/facebox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/jquery.wysiwyg.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/jquery.autocomplete.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/codeforces.datepick.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/colorbox.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/jquery.drafts.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/css/community.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/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/19903/js/prettify/prettify.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/moment-with-locales.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/pushstream.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.easing.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.lavalamp.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.jgrowl.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.swipe.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.hotkeys.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/facebox.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/controls/wysiwyg.colorpicker.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/controls/wysiwyg.table.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/controls/wysiwyg.image.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/controls/wysiwyg.link.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.datepick.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.ie6blocker.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.colorbox-min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.ba-bbq.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/jquery.drafts.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/clipboard.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/autosize.min.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/sjcl.js"></script>
<script type="text/javascript" src="/scripts/3dccf1f9f8cb4969b151d97264ecfd48/en/codeforces-options.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/codeforces.js?v=20160131"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/EventCatcher.js?v=20160131"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/preparedVerdictFormats-en.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/js/confetti.min.js"></script>
<!--/CombineResourcesFilter-->
<link rel="stylesheet" href="//codeforces.org/s/19903/markitup/skins/markitup/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="//codeforces.org/s/19903/markitup/sets/markdown/style.css" type="text/css" charset="utf-8" />
<script type="text/javascript" src="//codeforces.org/s/19903/markitup/jquery.markitup.js"></script>
<script type="text/javascript" src="//codeforces.org/s/19903/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='f654ee5b8bdf2239b0f7991aa2a7a469'>&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/34323/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/34323/images/flags/24/gb.png" title="In English" alt="In English"/></a>
<a href="?locale=ru"><img src="//codeforces.org/s/34323/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 143 (Div. 2)</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_7f5ad304fa5c104a7c803718ee5600dc8b248af0">
<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. Team</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 three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.</p><p>This contest offers <span class="tex-span"><i>n</i></span> problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first input line contains a single integer <span class="tex-span"><i>n</i></span> (<span class="tex-span">1<i>n</i>1000</span>) — the number of problems in the contest. Then <span class="tex-span"><i>n</i></span> lines contain three integers each, each integer is either <span class="tex-span">0</span> or <span class="tex-span">1</span>. If the first number in the line equals <span class="tex-span">1</span>, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print a single integer — the number of problems the friends will implement on the contest.</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>3<br />1 1 0<br />1 1 1<br />1 0 0<br /></pre></div><div class="output"><div class="title">Output</div><pre>2<br /></pre></div><div class="input"><div class="title">Input</div><pre>2<br />1 0 0<br />0 1 1<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 sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. </p><p>In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.</p></div></div></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/34323");
$("#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_d7ade6cfd153f6b34f4f6e02f161a4659fba8d05">
<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. Magic, Wizardry and Wonders</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>Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into some other ones.</p><p>This morning he has <span class="tex-span"><i>n</i></span> cards with integers lined up in front of him. Each integer is not less than 1, but not greater than <span class="tex-span"><i>l</i></span>. When Vasya waves his magic wand, two rightmost cards vanish from the line and a new card magically appears in their place. It contains the difference between the left and the right numbers on the two vanished cards. Vasya was very interested to know what would happen next, and so he waved with his magic wand on and on, until the table had a single card left.</p><p>Suppose that Vasya originally had the following cards: 4, 1, 1, 3 (listed from left to right). Then after the first wave the line would be: 4, 1, -2, and after the second one: 4, 3, and after the third one the table would have a single card with number 1.</p><p>Please note that in spite of the fact that initially all the numbers on the cards were not less than 1 and not greater than <span class="tex-span"><i>l</i></span>, the numbers on the appearing cards can be anything, no restrictions are imposed on them.</p><p>It is now evening. Vasya is very tired and wants to return everything back, but does not remember which cards he had in the morning. He only remembers that there were <span class="tex-span"><i>n</i></span> cards, they contained integers from 1 to <span class="tex-span"><i>l</i></span>, and after all magical actions he was left with a single card containing number <span class="tex-span"><i>d</i></span>.</p><p>Help Vasya to recover the initial set of cards with numbers.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The single line contains three space-separated integers: <span class="tex-span"><i>n</i></span> (<span class="tex-span">2<i>n</i>100</span>) — the initial number of cards on the table, <span class="tex-span"><i>d</i></span> (<span class="tex-span">|<i>d</i>|10<sup class="upper-index">4</sup></span>) — the number on the card that was left on the table after all the magical actions, and <span class="tex-span"><i>l</i></span> (<span class="tex-span">1<i>l</i>100</span>) — the limits for the initial integers.</p></div><div class="output-specification"><div class="section-title">Output</div><p>If Vasya is mistaken, that is, if there doesn't exist a set that meets the requirements given in the statement, then print a single number -1, otherwise print the sought set containing <span class="tex-span"><i>n</i></span> integers from <span class="tex-span">1</span> to <span class="tex-span"><i>l</i></span>. Separate the integers by spaces. Print the integers in the order, in which they were written on the cards from left to right. If there are several suitable sets of numbers, you can print any of them.</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>3 3 2<br /></pre></div><div class="output"><div class="title">Output</div><pre>2 1 2 </pre></div><div class="input"><div class="title">Input</div><pre>5 -4 3<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>5 -4 4<br /></pre></div><div class="output"><div class="title">Output</div><pre>2 4 1 4 1 </pre></div></div></div></div></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/34323");
$("#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_18ee2517b8dd4c4e8df79868005351e1a98de2f6">
<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. To Add or Not to Add</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>A piece of paper contains an array of <span class="tex-span"><i>n</i></span> integers <span class="tex-span"><i>a</i><sub class="lower-index">1</sub>,<i>a</i><sub class="lower-index">2</sub>,...,<i>a</i><sub class="lower-index"><i>n</i></sub></span>. Your task is to find a number that occurs the maximum number of times in this array.</p><p>However, before looking for such number, you are allowed to perform not more than <span class="tex-span"><i>k</i></span> following operations — choose an arbitrary element from the array and add <span class="tex-span">1</span> to it. In other words, you are allowed to increase some array element by <span class="tex-span">1</span> no more than <span class="tex-span"><i>k</i></span> times (you are allowed to increase the same element of the array multiple times).</p><p>Your task is to find the maximum number of occurrences of some number in the array after performing no more than <span class="tex-span"><i>k</i></span> allowed operations. If there are several such numbers, your task is to find the minimum one.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains two integers <span class="tex-span"><i>n</i></span> and <span class="tex-span"><i>k</i></span> (<span class="tex-span">1<i>n</i>10<sup class="upper-index">5</sup></span>; <span class="tex-span">0<i>k</i>10<sup class="upper-index">9</sup></span>) — the number of elements in the array and the number of operations you are allowed to perform, correspondingly.</p><p>The third line contains a sequence of <span class="tex-span"><i>n</i></span> integers <span class="tex-span"><i>a</i><sub class="lower-index">1</sub>,<i>a</i><sub class="lower-index">2</sub>,...,<i>a</i><sub class="lower-index"><i>n</i></sub></span> <span class="tex-span">(|<i>a</i><sub class="lower-index"><i>i</i></sub>|10<sup class="upper-index">9</sup>)</span> — the initial array. The numbers in the lines are separated by single spaces.</p></div><div class="output-specification"><div class="section-title">Output</div><p>In a single line print two numbers — the maximum number of occurrences of some number in the array after at most <span class="tex-span"><i>k</i></span> allowed operations are performed, and the minimum number that reaches the given maximum. Separate the printed numbers by whitespaces.</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 3<br />6 3 4 0 2<br /></pre></div><div class="output"><div class="title">Output</div><pre>3 4<br /></pre></div><div class="input"><div class="title">Input</div><pre>3 4<br />5 5 5<br /></pre></div><div class="output"><div class="title">Output</div><pre>3 5<br /></pre></div><div class="input"><div class="title">Input</div><pre>5 3<br />3 1 2 2 1<br /></pre></div><div class="output"><div class="title">Output</div><pre>4 2<br /></pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first sample your task is to increase the second element of the array once and increase the fifth element of the array twice. Thus, we get sequence <span class="tex-span">6,4,4,0,4</span>, where number <span class="tex-span">4</span> occurs <span class="tex-span">3</span> times.</p><p>In the second sample you don't need to perform a single operation or increase each element by one. If we do nothing, we get array <span class="tex-span">5,5,5</span>, if we increase each by one, we get <span class="tex-span">6,6,6</span>. In both cases the maximum number of occurrences equals <span class="tex-span">3</span>. So we should do nothing, as number <span class="tex-span">5</span> is less than number <span class="tex-span">6</span>.</p><p>In the third sample we should increase the second array element once and the fifth element once. Thus, we get sequence <span class="tex-span">3,2,2,2,2</span>, where number <span class="tex-span">2</span> occurs <span class="tex-span">4</span> times.</p></div></div></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/34323");
$("#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_cb466b3401ff99fcd4f2dc975a3d624fd601fe2d">
<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. Magic Box</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 Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point <span class="tex-span">(0,0,0)</span>, and the opposite one is at point <span class="tex-span">(<i>x</i><sub class="lower-index">1</sub>,<i>y</i><sub class="lower-index">1</sub>,<i>z</i><sub class="lower-index">1</sub>)</span>. The six faces of the box contain some numbers <span class="tex-span"><i>a</i><sub class="lower-index">1</sub>,<i>a</i><sub class="lower-index">2</sub>,...,<i>a</i><sub class="lower-index">6</sub></span>, exactly one number right in the center of each face.</p><center> <img class="tex-graphics" src="https://espresso.codeforces.com/00ffc13ae21b26aca27ffa402f18891e92c99713.png" style="max-width: 100.0%;max-height: 100.0%;" /> </center><p>The numbers are located on the box like that: </p><ul> <li> number <span class="tex-span"><i>a</i><sub class="lower-index">1</sub></span> is written on the face that lies on the ZOX plane; </li><li> <span class="tex-span"><i>a</i><sub class="lower-index">2</sub></span> is written on the face, parallel to the plane from the previous point; </li><li> <span class="tex-span"><i>a</i><sub class="lower-index">3</sub></span> is written on the face that lies on the XOY plane; </li><li> <span class="tex-span"><i>a</i><sub class="lower-index">4</sub></span> is written on the face, parallel to the plane from the previous point; </li><li> <span class="tex-span"><i>a</i><sub class="lower-index">5</sub></span> is written on the face that lies on the YOZ plane; </li><li> <span class="tex-span"><i>a</i><sub class="lower-index">6</sub></span> is written on the face, parallel to the plane from the previous point. </li></ul><p>At the moment Vasya is looking at the box from point <span class="tex-span">(<i>x</i>,<i>y</i>,<i>z</i>)</span>. Find the sum of numbers that Vasya sees. Note that all faces of the box are not transparent and Vasya can't see the numbers through the box. The picture contains transparent faces just to make it easier to perceive. You can consider that if Vasya is looking from point, lying on the plane of some face, than he can not see the number that is written on this face. It is enough to see the center of a face to see the corresponding number for Vasya. Also note that Vasya always reads correctly the <span class="tex-span"><i>a</i><sub class="lower-index"><i>i</i></sub></span> numbers that he sees, independently of their rotation, angle and other factors (that is, for example, if Vasya sees some <span class="tex-span"><i>a</i><sub class="lower-index"><i>i</i></sub>=6</span>, then he can't mistake this number for <span class="tex-span">9</span> and so on). </p></div><div class="input-specification"><div class="section-title">Input</div><p>The fist input line contains three space-separated integers <span class="tex-span"><i>x</i></span>, <span class="tex-span"><i>y</i></span> and <span class="tex-span"><i>z</i></span> (<span class="tex-span">|<i>x</i>|,|<i>y</i>|,|<i>z</i>|10<sup class="upper-index">6</sup></span>) — the coordinates of Vasya's position in space. The second line contains three space-separated integers <span class="tex-span"><i>x</i><sub class="lower-index">1</sub></span>, <span class="tex-span"><i>y</i><sub class="lower-index">1</sub></span>, <span class="tex-span"><i>z</i><sub class="lower-index">1</sub></span> (<span class="tex-span">1<i>x</i><sub class="lower-index">1</sub>,<i>y</i><sub class="lower-index">1</sub>,<i>z</i><sub class="lower-index">1</sub>10<sup class="upper-index">6</sup></span>) — the coordinates of the box's vertex that is opposite to the vertex at point <span class="tex-span">(0,0,0)</span>. The third line contains six space-separated integers <span class="tex-span"><i>a</i><sub class="lower-index">1</sub>,<i>a</i><sub class="lower-index">2</sub>,...,<i>a</i><sub class="lower-index">6</sub></span> (<span class="tex-span">1<i>a</i><sub class="lower-index"><i>i</i></sub>10<sup class="upper-index">6</sup></span>) — the numbers that are written on the box faces. </p><p>It is guaranteed that point <span class="tex-span">(<i>x</i>,<i>y</i>,<i>z</i>)</span> is located strictly outside the box.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print a single integer — the sum of all numbers on the box faces that Vasya sees.</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>2 2 2<br />1 1 1<br />1 2 3 4 5 6<br /></pre></div><div class="output"><div class="title">Output</div><pre>12<br /></pre></div><div class="input"><div class="title">Input</div><pre>0 0 10<br />3 2 3<br />1 2 3 4 5 6<br /></pre></div><div class="output"><div class="title">Output</div><pre>4<br /></pre></div></div></div><div class="note"><div class="section-title">Note</div><p>The first sample corresponds to perspective, depicted on the picture. Vasya sees numbers <span class="tex-span"><i>a</i><sub class="lower-index">2</sub></span> (on the top face that is the darkest), <span class="tex-span"><i>a</i><sub class="lower-index">6</sub></span> (on the right face that is the lightest) and <span class="tex-span"><i>a</i><sub class="lower-index">4</sub></span> (on the left visible face).</p><p>In the second sample Vasya can only see number <span class="tex-span"><i>a</i><sub class="lower-index">4</sub></span>.</p></div></div></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/34323");
$("#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="E" data-uuid="ps_cd118b3a0b558f2a53eb77fd31df7f0147672054">
<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. Cactus</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>A connected undirected graph is called a <span class="tex-font-style-underline">vertex cactus</span>, if each vertex of this graph belongs to at most one simple cycle.</p><p>A <span class="tex-font-style-it">simple cycle</span> in a undirected graph is a sequence of distinct vertices <span class="tex-span"><i>v</i><sub class="lower-index">1</sub>,<i>v</i><sub class="lower-index">2</sub>,...,<i>v</i><sub class="lower-index"><i>t</i></sub></span> <span class="tex-span">(<i>t</i>&gt;2)</span>, such that for any <span class="tex-span"><i>i</i></span> <span class="tex-span">(1<i>i</i>&lt;<i>t</i>)</span> exists an edge between vertices <span class="tex-span"><i>v</i><sub class="lower-index"><i>i</i></sub></span> and <span class="tex-span"><i>v</i><sub class="lower-index"><i>i</i>+1</sub></span>, and also exists an edge between vertices <span class="tex-span"><i>v</i><sub class="lower-index">1</sub></span> and <span class="tex-span"><i>v</i><sub class="lower-index"><i>t</i></sub></span>.</p><p>A <span class="tex-font-style-it">simple path</span> in a undirected graph is a sequence of not necessarily distinct vertices <span class="tex-span"><i>v</i><sub class="lower-index">1</sub>,<i>v</i><sub class="lower-index">2</sub>,...,<i>v</i><sub class="lower-index"><i>t</i></sub></span> <span class="tex-span">(<i>t</i>&gt;0)</span>, such that for any <span class="tex-span"><i>i</i></span> <span class="tex-span">(1<i>i</i>&lt;<i>t</i>)</span> exists an edge between vertices <span class="tex-span"><i>v</i><sub class="lower-index"><i>i</i></sub></span> and <span class="tex-span"><i>v</i><sub class="lower-index"><i>i</i>+1</sub></span> and furthermore each <span class="tex-font-style-bf">edge occurs no more than once</span>. We'll say that a simple path <span class="tex-span"><i>v</i><sub class="lower-index">1</sub>,<i>v</i><sub class="lower-index">2</sub>,...,<i>v</i><sub class="lower-index"><i>t</i></sub></span> starts at vertex <span class="tex-span"><i>v</i><sub class="lower-index">1</sub></span> and ends at vertex <span class="tex-span"><i>v</i><sub class="lower-index"><i>t</i></sub></span>.</p><p>You've got a graph consisting of <span class="tex-span"><i>n</i></span> vertices and <span class="tex-span"><i>m</i></span> edges, that is a vertex cactus. Also, you've got a list of <span class="tex-span"><i>k</i></span> pairs of interesting vertices <span class="tex-span"><i>x</i><sub class="lower-index"><i>i</i></sub>,<i>y</i><sub class="lower-index"><i>i</i></sub></span>, for which you want to know the following information — the number of distinct simple paths that start at vertex <span class="tex-span"><i>x</i><sub class="lower-index"><i>i</i></sub></span> and end at vertex <span class="tex-span"><i>y</i><sub class="lower-index"><i>i</i></sub></span>. We will consider two simple paths distinct if the sets of edges of the paths are distinct.</p><p>For each pair of interesting vertices count the number of distinct simple paths between them. As this number can be rather large, you should calculate it modulo <span class="tex-span">1000000007</span> (<span class="tex-span">10<sup class="upper-index">9</sup>+7</span>). </p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains two space-separated integers <span class="tex-span"><i>n</i>,<i>m</i></span> <span class="tex-span">(2<i>n</i>10<sup class="upper-index">5</sup>; 1<i>m</i>10<sup class="upper-index">5</sup>)</span> — the number of vertices and edges in the graph, correspondingly. Next <span class="tex-span"><i>m</i></span> lines contain the description of the edges: the <span class="tex-span"><i>i</i></span>-th line contains two space-separated integers <span class="tex-span"><i>a</i><sub class="lower-index"><i>i</i></sub>,<i>b</i><sub class="lower-index"><i>i</i></sub></span> <span class="tex-span">(1<i>a</i><sub class="lower-index"><i>i</i></sub>,<i>b</i><sub class="lower-index"><i>i</i></sub> ≤ <i>n</i>)</span> — the indexes of the vertices connected by the <span class="tex-span"><i>i</i></span>-th edge.</p><p>The next line contains a single integer <span class="tex-span"><i>k</i></span> <span class="tex-span">(1<i>k</i>10<sup class="upper-index">5</sup>)</span> — the number of pairs of interesting vertices. Next <span class="tex-span"><i>k</i></span> lines contain the list of pairs of interesting vertices: the <span class="tex-span"><i>i</i></span>-th line contains two space-separated numbers <span class="tex-span"><i>x</i><sub class="lower-index"><i>i</i></sub></span>, <span class="tex-span"><i>y</i><sub class="lower-index"><i>i</i></sub></span> <span class="tex-span">(1<i>x</i><sub class="lower-index"><i>i</i></sub>,<i>y</i><sub class="lower-index"><i>i</i></sub> ≤ <i>n</i>; <i>x</i><sub class="lower-index"><i>i</i></sub> ≠ <i>y</i><sub class="lower-index"><i>i</i></sub>)</span> — the indexes of interesting vertices in the <span class="tex-span"><i>i</i></span>-th pair.</p><p>It is guaranteed that the given graph is a vertex cactus. It is guaranteed that the graph contains no loops or multiple edges. Consider the graph vertices are numbered from 1 to <span class="tex-span"><i>n</i></span>.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print <span class="tex-span"><i>k</i></span> lines: in the <span class="tex-span"><i>i</i></span>-th line print a single integer — the number of distinct simple ways, starting at <span class="tex-span"><i>x</i><sub class="lower-index"><i>i</i></sub></span> and ending at <span class="tex-span"><i>y</i><sub class="lower-index"><i>i</i></sub></span>, modulo <span class="tex-span">1000000007</span> (<span class="tex-span">10<sup class="upper-index">9</sup>+7</span>).</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>10 11<br />1 2<br />2 3<br />3 4<br />1 4<br />3 5<br />5 6<br />8 6<br />8 7<br />7 6<br />7 9<br />9 10<br />6<br />1 2<br />3 5<br />6 9<br />9 2<br />9 3<br />9 10<br /></pre></div><div class="output"><div class="title">Output</div><pre>2<br />2<br />2<br />4<br />4<br />1<br /></pre></div></div></div></div></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/34323");
$("#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-34323.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:'7e42d64fc91eb386',m:'iMS4VjMGu7Gwq54f4B.VwbOvHwDHNkJ_vPDKR3DGdRk-1688929513-0-AbN8/5RbLR764KRIsh6GjISgHwkHNosfBQRgqW9Q8R7a'};_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>