cp.nvim/tests/fixtures/codeforces_1550_problems.html

1095 lines
No EOL
223 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

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

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html lang="en"><head><script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script><script type="text/javascript" async="" src="https://www.googletagmanager.com/gtag/js?id=G-K230KVN22K&amp;cx=c&amp;gtm=4e5a11"></script><script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-743380-5"></script><script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-743380-5');
</script><meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta name="X-Csrf-Token" content="9ef48a30482a4cff4d2010893754d22a"><meta id="viewport" name="viewport" content="width=device-width, initial-scale=0.01"><meta name="robots" content="noai"><meta name="robots" content="noimageai"><script type="text/javascript" src="//codeforces.org/s/15523/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="l2"><meta name="google-site-verification" content="OTd2dN5x4nS4OPknPI9JFg36fKxjqY0i1PSfFPv_J90"><meta property="fb:admins" content="100001352546622"><meta property="og:image" content="//codeforces.org/s/15523/images/codeforces-sponsored-by-ton.png"><link rel="image_src" href="//codeforces.org/s/15523/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/15523/css/font-awesome.min.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/line-awesome.min.css" type="text/css" charset="utf-8"><link href="//fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700&amp;subset=latin,cyrillic" rel="stylesheet" type="text/css"><link href="//fonts.googleapis.com/css?family=Cuprum&amp;subset=latin,cyrillic" rel="stylesheet" type="text/css"><link rel="apple-touch-icon" sizes="57x57" href="//codeforces.org/s/15523/apple-icon-57x57.png"><link rel="apple-touch-icon" sizes="60x60" href="//codeforces.org/s/15523/apple-icon-60x60.png"><link rel="apple-touch-icon" sizes="72x72" href="//codeforces.org/s/15523/apple-icon-72x72.png"><link rel="apple-touch-icon" sizes="76x76" href="//codeforces.org/s/15523/apple-icon-76x76.png"><link rel="apple-touch-icon" sizes="114x114" href="//codeforces.org/s/15523/apple-icon-114x114.png"><link rel="apple-touch-icon" sizes="120x120" href="//codeforces.org/s/15523/apple-icon-120x120.png"><link rel="apple-touch-icon" sizes="144x144" href="//codeforces.org/s/15523/apple-icon-144x144.png"><link rel="apple-touch-icon" sizes="152x152" href="//codeforces.org/s/15523/apple-icon-152x152.png"><link rel="apple-touch-icon" sizes="180x180" href="//codeforces.org/s/15523/apple-icon-180x180.png"><link rel="icon" type="image/png" sizes="192x192" href="//codeforces.org/s/15523/android-icon-192x192.png"><link rel="icon" type="image/png" sizes="32x32" href="//codeforces.org/s/15523/favicon-32x32.png"><link rel="icon" type="image/png" sizes="96x96" href="//codeforces.org/s/15523/favicon-96x96.png"><link rel="icon" type="image/png" sizes="16x16" href="//codeforces.org/s/15523/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="msapplication-TileColor" content="#ffffff"><meta name="msapplication-TileImage" content="//codeforces.org/s/15523/ms-icon-144x144.png"><meta name="theme-color" content="#ffffff"><link rel="stylesheet" href="//codeforces.org/s/15523/css/prettify.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/clear.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/style.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/ttypography.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/problem-statement.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/second-level-menu.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/roundbox.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/datatable.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/table-form.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/topic.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/jquery.jgrowl.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/facebox.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/jquery.wysiwyg.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/jquery.autocomplete.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/codeforces.datepick.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/colorbox.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/jquery.drafts.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/community.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/css/sidebar-menu.css" type="text/css" charset="utf-8"><script type="text/x-mathjax-config;executed=true">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$$$','$$$']], displayMath: [['$$$$$$','$$$$$$']]}
});
MathJax.Hub.Register.StartupHook("End", function () {
Codeforces.runMathJaxListeners();
});
</script><script type="text/javascript" async="" src="https://codeforces.com/mathjax.codeforces.org/MathJax.js?config=TeX-AMS_HTML-full">
</script><script type="text/javascript" src="//codeforces.org/s/15523/js/prettify/prettify.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/moment-with-locales.min.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/pushstream.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.easing.min.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.lavalamp.min.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.jgrowl.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.swipe.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.hotkeys.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/facebox.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.wysiwyg.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/controls/wysiwyg.colorpicker.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/controls/wysiwyg.table.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/controls/wysiwyg.image.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/controls/wysiwyg.link.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.autocomplete.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.datepick.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.ie6blocker.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.colorbox-min.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.ba-bbq.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/jquery.drafts.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/clipboard.min.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/autosize.min.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/sjcl.js"></script><script type="text/javascript" src="/scripts/b166015692c73aeac2b663c7ab9ff3d7/en/codeforces-options.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/codeforces.js?v=20160131"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/EventCatcher.js?v=20160131"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/preparedVerdictFormats-en.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/confetti.min.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/js/purify.min.js"></script><link rel="stylesheet" href="//codeforces.org/s/15523/markitup/skins/markitup/style.css" type="text/css" charset="utf-8"><link rel="stylesheet" href="//codeforces.org/s/15523/markitup/sets/markdown/style.css" type="text/css" charset="utf-8"><script type="text/javascript" src="//codeforces.org/s/15523/markitup/jquery.markitup.js"></script><script type="text/javascript" src="//codeforces.org/s/15523/markitup/sets/markdown/set.js"></script><style type="text/css">.MathJax_Hover_Frame {border-radius: .25em; -webkit-border-radius: .25em; -moz-border-radius: .25em; -khtml-border-radius: .25em; box-shadow: 0px 0px 15px #83A; -webkit-box-shadow: 0px 0px 15px #83A; -moz-box-shadow: 0px 0px 15px #83A; -khtml-box-shadow: 0px 0px 15px #83A; border: 1px solid #A6D ! important; display: inline-block; position: absolute}
.MathJax_Menu_Button .MathJax_Hover_Arrow {position: absolute; cursor: pointer; display: inline-block; border: 2px solid #AAA; border-radius: 4px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -khtml-border-radius: 4px; font-family: 'Courier New',Courier; font-size: 9px; color: #F0F0F0}
.MathJax_Menu_Button .MathJax_Hover_Arrow span {display: block; background-color: #AAA; border: 1px solid; border-radius: 3px; line-height: 0; padding: 4px}
.MathJax_Hover_Arrow:hover {color: white!important; border: 2px solid #CCC!important}
.MathJax_Hover_Arrow:hover span {background-color: #CCC!important}
</style><style type="text/css">#MathJax_About {position: fixed; left: 50%; width: auto; text-align: center; border: 3px outset; padding: 1em 2em; background-color: #DDDDDD; color: black; cursor: default; font-family: message-box; font-size: 120%; font-style: normal; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 15px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -khtml-border-radius: 15px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_About.MathJax_MousePost {outline: none}
.MathJax_Menu {position: absolute; background-color: white; color: black; width: auto; padding: 5px 0px; border: 1px solid #CCCCCC; margin: 0; cursor: default; font: menu; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; z-index: 201; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; -khtml-border-radius: 5px; box-shadow: 0px 10px 20px #808080; -webkit-box-shadow: 0px 10px 20px #808080; -moz-box-shadow: 0px 10px 20px #808080; -khtml-box-shadow: 0px 10px 20px #808080; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
.MathJax_MenuItem {padding: 1px 2em; background: transparent}
.MathJax_MenuArrow {position: absolute; right: .5em; padding-top: .25em; color: #666666; font-size: .75em}
.MathJax_MenuActive .MathJax_MenuArrow {color: white}
.MathJax_MenuArrow.RTL {left: .5em; right: auto}
.MathJax_MenuCheck {position: absolute; left: .7em}
.MathJax_MenuCheck.RTL {right: .7em; left: auto}
.MathJax_MenuRadioCheck {position: absolute; left: .7em}
.MathJax_MenuRadioCheck.RTL {right: .7em; left: auto}
.MathJax_MenuLabel {padding: 1px 2em 3px 1.33em; font-style: italic}
.MathJax_MenuRule {border-top: 1px solid #DDDDDD; margin: 4px 3px}
.MathJax_MenuDisabled {color: GrayText}
.MathJax_MenuActive {background-color: #606872; color: white}
.MathJax_MenuDisabled:focus, .MathJax_MenuLabel:focus {background-color: #E8E8E8}
.MathJax_ContextMenu:focus {outline: none}
.MathJax_ContextMenu .MathJax_MenuItem:focus {outline: none}
#MathJax_AboutClose {top: .2em; right: .2em}
.MathJax_Menu .MathJax_MenuClose {top: -10px; left: -10px}
.MathJax_MenuClose {position: absolute; cursor: pointer; display: inline-block; border: 2px solid #AAA; border-radius: 18px; -webkit-border-radius: 18px; -moz-border-radius: 18px; -khtml-border-radius: 18px; font-family: 'Courier New',Courier; font-size: 24px; color: #F0F0F0}
.MathJax_MenuClose span {display: block; background-color: #AAA; border: 1.5px solid; border-radius: 18px; -webkit-border-radius: 18px; -moz-border-radius: 18px; -khtml-border-radius: 18px; line-height: 0; padding: 8px 0 6px}
.MathJax_MenuClose:hover {color: white!important; border: 2px solid #CCC!important}
.MathJax_MenuClose:hover span {background-color: #CCC!important}
.MathJax_MenuClose:hover:focus {outline: none}
</style><style type="text/css">.MathJax_Preview .MJXf-math {color: inherit!important}
</style><style type="text/css">.MJX_Assistive_MathML {position: absolute!important; top: 0; left: 0; clip: rect(1px, 1px, 1px, 1px); padding: 1px 0 0 0!important; border: 0!important; height: 1px!important; width: 1px!important; overflow: hidden!important; display: block!important; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none}
.MJX_Assistive_MathML.MJX_Assistive_MathML_Block {width: 100%!important}
</style><style type="text/css">#MathJax_Zoom {position: absolute; background-color: #F0F0F0; overflow: auto; display: block; z-index: 301; padding: .5em; border: 1px solid black; margin: 0; font-weight: normal; font-style: normal; text-align: left; text-indent: 0; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; -webkit-box-sizing: content-box; -moz-box-sizing: content-box; box-sizing: content-box; box-shadow: 5px 5px 15px #AAAAAA; -webkit-box-shadow: 5px 5px 15px #AAAAAA; -moz-box-shadow: 5px 5px 15px #AAAAAA; -khtml-box-shadow: 5px 5px 15px #AAAAAA; filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')}
#MathJax_ZoomOverlay {position: absolute; left: 0; top: 0; z-index: 300; display: inline-block; width: 100%; height: 100%; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
#MathJax_ZoomFrame {position: relative; display: inline-block; height: 0; width: 0}
#MathJax_ZoomEventTrap {position: absolute; left: 0; top: 0; z-index: 302; display: inline-block; border: 0; padding: 0; margin: 0; background-color: white; opacity: 0; filter: alpha(opacity=0)}
</style><style type="text/css">.MathJax_Preview {color: #888; display: contents}
#MathJax_Message {position: fixed; left: 1px; bottom: 2px; background-color: #E6E6E6; border: 1px solid #959595; margin: 0px; padding: 2px 8px; z-index: 102; color: black; font-size: 80%; width: auto; white-space: nowrap}
#MathJax_MSIE_Frame {position: absolute; top: 0; left: 0; width: 0px; z-index: 101; border: 0px; margin: 0px; padding: 0px}
.MathJax_Error {color: #CC0000; font-style: italic}
</style><script type="text/javascript" src="https://codeforces.com/mathjax.codeforces.org/jax/output/HTML-CSS/fonts/TeX/fontdata.js?V=2.7.9"></script><style type="text/css">.MJXp-script {font-size: .8em}
.MJXp-right {-webkit-transform-origin: right; -moz-transform-origin: right; -ms-transform-origin: right; -o-transform-origin: right; transform-origin: right}
.MJXp-bold {font-weight: bold}
.MJXp-italic {font-style: italic}
.MJXp-scr {font-family: MathJax_Script,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-frak {font-family: MathJax_Fraktur,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-sf {font-family: MathJax_SansSerif,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-cal {font-family: MathJax_Caligraphic,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-mono {font-family: MathJax_Typewriter,'Times New Roman',Times,STIXGeneral,serif}
.MJXp-largeop {font-size: 150%}
.MJXp-largeop.MJXp-int {vertical-align: -.2em}
.MJXp-math {display: inline-block; line-height: 1.2; text-indent: 0; font-family: 'Times New Roman',Times,STIXGeneral,serif; white-space: nowrap; border-collapse: collapse}
.MJXp-display {display: block; text-align: center; margin: 1em 0}
.MJXp-math span {display: inline-block}
.MJXp-box {display: block!important; text-align: center}
.MJXp-box:after {content: " "}
.MJXp-rule {display: block!important; margin-top: .1em}
.MJXp-char {display: block!important}
.MJXp-mo {margin: 0 .15em}
.MJXp-mfrac {margin: 0 .125em; vertical-align: .25em}
.MJXp-denom {display: inline-table!important; width: 100%}
.MJXp-denom > * {display: table-row!important}
.MJXp-surd {vertical-align: top}
.MJXp-surd > * {display: block!important}
.MJXp-script-box > * {display: table!important; height: 50%}
.MJXp-script-box > * > * {display: table-cell!important; vertical-align: top}
.MJXp-script-box > *:last-child > * {vertical-align: bottom}
.MJXp-script-box > * > * > * {display: block!important}
.MJXp-mphantom {visibility: hidden}
.MJXp-munderover, .MJXp-munder {display: inline-table!important}
.MJXp-over {display: inline-block!important; text-align: center}
.MJXp-over > * {display: block!important}
.MJXp-munderover > *, .MJXp-munder > * {display: table-row!important}
.MJXp-mtable {vertical-align: .25em; margin: 0 .125em}
.MJXp-mtable > * {display: inline-table!important; vertical-align: middle}
.MJXp-mtr {display: table-row!important}
.MJXp-mtd {display: table-cell!important; text-align: center; padding: .5em 0 0 .5em}
.MJXp-mtr > .MJXp-mtd:first-child {padding-left: 0}
.MJXp-mtr:first-child > .MJXp-mtd {padding-top: 0}
.MJXp-mlabeledtr {display: table-row!important}
.MJXp-mlabeledtr > .MJXp-mtd:first-child {padding-left: 0}
.MJXp-mlabeledtr:first-child > .MJXp-mtd {padding-top: 0}
.MJXp-merror {background-color: #FFFF88; color: #CC0000; border: 1px solid #CC0000; padding: 1px 3px; font-style: normal; font-size: 90%}
.MJXp-scale0 {-webkit-transform: scaleX(.0); -moz-transform: scaleX(.0); -ms-transform: scaleX(.0); -o-transform: scaleX(.0); transform: scaleX(.0)}
.MJXp-scale1 {-webkit-transform: scaleX(.1); -moz-transform: scaleX(.1); -ms-transform: scaleX(.1); -o-transform: scaleX(.1); transform: scaleX(.1)}
.MJXp-scale2 {-webkit-transform: scaleX(.2); -moz-transform: scaleX(.2); -ms-transform: scaleX(.2); -o-transform: scaleX(.2); transform: scaleX(.2)}
.MJXp-scale3 {-webkit-transform: scaleX(.3); -moz-transform: scaleX(.3); -ms-transform: scaleX(.3); -o-transform: scaleX(.3); transform: scaleX(.3)}
.MJXp-scale4 {-webkit-transform: scaleX(.4); -moz-transform: scaleX(.4); -ms-transform: scaleX(.4); -o-transform: scaleX(.4); transform: scaleX(.4)}
.MJXp-scale5 {-webkit-transform: scaleX(.5); -moz-transform: scaleX(.5); -ms-transform: scaleX(.5); -o-transform: scaleX(.5); transform: scaleX(.5)}
.MJXp-scale6 {-webkit-transform: scaleX(.6); -moz-transform: scaleX(.6); -ms-transform: scaleX(.6); -o-transform: scaleX(.6); transform: scaleX(.6)}
.MJXp-scale7 {-webkit-transform: scaleX(.7); -moz-transform: scaleX(.7); -ms-transform: scaleX(.7); -o-transform: scaleX(.7); transform: scaleX(.7)}
.MJXp-scale8 {-webkit-transform: scaleX(.8); -moz-transform: scaleX(.8); -ms-transform: scaleX(.8); -o-transform: scaleX(.8); transform: scaleX(.8)}
.MJXp-scale9 {-webkit-transform: scaleX(.9); -moz-transform: scaleX(.9); -ms-transform: scaleX(.9); -o-transform: scaleX(.9); transform: scaleX(.9)}
.MathJax_PHTML .noError {vertical-align: ; font-size: 90%; text-align: left; color: black; padding: 1px 3px; border: 1px solid}
</style></head><body class=" "><div id="MathJax_Message" style="">Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js</div><span style="display:none;" class="csrf-token" data-csrf="9ef48a30482a4cff4d2010893754d22a"> </span><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><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()
}, beforeSend: function(jqXHR, settings) {
const url = new URL(settings.url, window.location.href);
const urlHref = url.href;
url.searchParams.set('rv', Math.random().toString(36).substr(2, 9)); // Generate a random value
settings.url = url.href;
}});
window.updateTypography();
Codeforces.signForms();
Codeforces.applyDatatableJs("Hold Ctrl+Alt and click to hide column. Also, you can drag&drop columns to reorder them.");
setTimeout(function() {
$(".second-level-menu-list").lavaLamp({
fx: "backout",
speed: 700
});
}, 100);
Codeforces.countdown();
$("a[rel='photobox']").colorbox();
function showAnnouncements(json) {
if (json.t === "a") {
setTimeout(function() {
Codeforces.showAnnouncements(json.d, "en");
}, Math.random() * 500);
}
}
function showEventCatcherUserMessage(json) {
if (json.t === "s") {
var points = json.d[5];
var passedTestCount = json.d[7];
var judgedTestCount = json.d[8];
var verdict = preparedVerdictFormats[json.d[12]];
var verdictPrototypeDiv = $(".verdictPrototypeDiv");
verdictPrototypeDiv.html(verdict);
if (judgedTestCount != null && judgedTestCount != undefined) {
verdictPrototypeDiv.find(".verdict-format-judged").text(judgedTestCount);
}
if (passedTestCount != null && passedTestCount != undefined) {
verdictPrototypeDiv.find(".verdict-format-passed").text(passedTestCount);
}
if (points != null && points != undefined) {
verdictPrototypeDiv.find(".verdict-format-points").text(points);
}
Codeforces.showMessage(verdictPrototypeDiv.text());
}
}
$(".clickable-title").each(function() {
var title = $(this).attr("data-title");
if (title) {
var tmp = document.createElement("DIV");
tmp.innerHTML = title;
$(this).attr("title", tmp.textContent || tmp.innerText || "");
}
});
$(".clickable-title").click(function() {
const title = $(this).attr("data-title");
const clazz = $(this).attr("data-clazz");
const props = {};
if (typeof (clazz) !== 'undefined') {
props['clazz'] = clazz;
}
if (title) {
Codeforces.alert(title, null, null, props);
} else {
Codeforces.alert($(this).attr("title"), null, null, props);
}
}).css("position", "relative").css("bottom", "3px");
Codeforces.showDelayedMessage();
Codeforces.reformatTimes();
//Codeforces.initializePubSub();
if (window.codeforcesOptions.subscribeServerUrl) {
window.eventCatcher = new EventCatcher(
window.codeforcesOptions.subscribeServerUrl,
[
Codeforces.getGlobalChannel(),
Codeforces.getUserChannel(),
Codeforces.getUserShowMessageChannel(),
Codeforces.getContestChannel(),
Codeforces.getParticipantChannel(),
Codeforces.getTalkChannel()
]
);
if (Codeforces.getParticipantChannel()) {
window.eventCatcher.subscribe(Codeforces.getParticipantChannel(), function(json) {
showAnnouncements(json);
});
}
if (Codeforces.getContestChannel()) {
window.eventCatcher.subscribe(Codeforces.getContestChannel(), function(json) {
showAnnouncements(json);
});
}
if (Codeforces.getGlobalChannel()) {
window.eventCatcher.subscribe(Codeforces.getGlobalChannel(), function(json) {
showAnnouncements(json);
});
}
if (Codeforces.getUserChannel()) {
window.eventCatcher.subscribe(Codeforces.getUserChannel(), function(json) {
showAnnouncements(json);
});
}
if (Codeforces.getUserShowMessageChannel()) {
window.eventCatcher.subscribe(Codeforces.getUserShowMessageChannel(), function(json) {
showEventCatcherUserMessage(json);
});
}
}
Codeforces.setupContestTimes("/data/contests");
Codeforces.setupSpoilers();
Codeforces.setupTutorials("/data/problemTutorial");
});
</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;">
<div style="padding:0.5em 0 0 2px;color:#00a651;">
<a href="/harbourspace"><img style="position:relative; bottom:6px;" src="//assets.codeforces.com/images/hsu.png"></a>
</div>
</div>
<div class="lang">
<div style="text-align: right;">
<a href="?locale=en"><img src="//codeforces.org/s/15523/images/flags/24/gb.png" title="In English" alt="In English"></a>
<a href="?locale=ru"><img src="//codeforces.org/s/15523/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">Educational Codeforces Round 111 (Rated for 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_cdca4b584b10da43dcb13b587596b603b8370a1a">
<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;">×</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">A. Find The Array</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 input-standard"><div class="property-title">input</div>standard input</div><div class="output-file output-standard"><div class="property-title">output</div>standard output</div></div><div><p>Let's call an array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-2">a</span></span></span><script type="math/tex" id="MathJax-Element-1">a</script> consisting of <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-3"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-4">n</span></span></span><script type="math/tex" id="MathJax-Element-2">n</script> positive (greater than <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-5"><span class="MJXp-mn" id="MJXp-Span-6">0</span></span></span><script type="math/tex" id="MathJax-Element-3">0</script>) integers <span class="tex-font-style-it">beautiful</span> if the following condition is held for every <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-7"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-8">i</span></span></span><script type="math/tex" id="MathJax-Element-4">i</script> from <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-9"><span class="MJXp-mn" id="MJXp-Span-10">1</span></span></span><script type="math/tex" id="MathJax-Element-5">1</script> to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-11"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-12">n</span></span></span><script type="math/tex" id="MathJax-Element-6">n</script>: either <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-13"><span class="MJXp-msubsup" id="MJXp-Span-14"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-15" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-16" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-17" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-18">1</span></span></span><script type="math/tex" id="MathJax-Element-7">a_i = 1</script>, or at least one of the numbers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-19"><span class="MJXp-msubsup" id="MJXp-Span-20"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-21" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-22" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-23" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-24">1</span></span></span><script type="math/tex" id="MathJax-Element-8">a_i - 1</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-25"><span class="MJXp-msubsup" id="MJXp-Span-26"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-27" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-28" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-29" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-30">2</span></span></span><script type="math/tex" id="MathJax-Element-9">a_i - 2</script> exists in the array as well.</p><p>For example: </p><ul><li> the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-31"><span class="MJXp-mo" id="MJXp-Span-32" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-33">5</span><span class="MJXp-mo" id="MJXp-Span-34" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-35">3</span><span class="MJXp-mo" id="MJXp-Span-36" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-37">1</span><span class="MJXp-mo" id="MJXp-Span-38" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-10">[5, 3, 1]</script> is beautiful: for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-39"><span class="MJXp-msubsup" id="MJXp-Span-40"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-41" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-42" style="vertical-align: -0.4em;">1</span></span></span></span><script type="math/tex" id="MathJax-Element-11">a_1</script>, the number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-43"><span class="MJXp-msubsup" id="MJXp-Span-44"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-45" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-46" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-47" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-48">2</span><span class="MJXp-mo" id="MJXp-Span-49" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-50">3</span></span></span><script type="math/tex" id="MathJax-Element-12">a_1 - 2 = 3</script> exists in the array; for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-51"><span class="MJXp-msubsup" id="MJXp-Span-52"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-53" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-54" style="vertical-align: -0.4em;">2</span></span></span></span><script type="math/tex" id="MathJax-Element-13">a_2</script>, the number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-55"><span class="MJXp-msubsup" id="MJXp-Span-56"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-57" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-58" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-59" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-60">2</span><span class="MJXp-mo" id="MJXp-Span-61" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-62">1</span></span></span><script type="math/tex" id="MathJax-Element-14">a_2 - 2 = 1</script> exists in the array; for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-63"><span class="MJXp-msubsup" id="MJXp-Span-64"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-65" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-66" style="vertical-align: -0.4em;">3</span></span></span></span><script type="math/tex" id="MathJax-Element-15">a_3</script>, the condition <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-67"><span class="MJXp-msubsup" id="MJXp-Span-68"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-69" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-70" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-71" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-72">1</span></span></span><script type="math/tex" id="MathJax-Element-16">a_3 = 1</script> holds; </li><li> the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-73"><span class="MJXp-mo" id="MJXp-Span-74" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-75">1</span><span class="MJXp-mo" id="MJXp-Span-76" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-77">2</span><span class="MJXp-mo" id="MJXp-Span-78" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-79">2</span><span class="MJXp-mo" id="MJXp-Span-80" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-81">2</span><span class="MJXp-mo" id="MJXp-Span-82" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-83">2</span><span class="MJXp-mo" id="MJXp-Span-84" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-17">[1, 2, 2, 2, 2]</script> is beautiful: for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-85"><span class="MJXp-msubsup" id="MJXp-Span-86"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-87" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-88" style="vertical-align: -0.4em;">1</span></span></span></span><script type="math/tex" id="MathJax-Element-18">a_1</script>, the condition <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-89"><span class="MJXp-msubsup" id="MJXp-Span-90"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-91" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-92" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-93" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-94">1</span></span></span><script type="math/tex" id="MathJax-Element-19">a_1 = 1</script> holds; for every other number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-95"><span class="MJXp-msubsup" id="MJXp-Span-96"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-97" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-98" style="vertical-align: -0.4em;">i</span></span></span></span><script type="math/tex" id="MathJax-Element-20">a_i</script>, the number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-99"><span class="MJXp-msubsup" id="MJXp-Span-100"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-101" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-102" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-103" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-104">1</span><span class="MJXp-mo" id="MJXp-Span-105" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-106">1</span></span></span><script type="math/tex" id="MathJax-Element-21">a_i - 1 = 1</script> exists in the array; </li><li> the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-107"><span class="MJXp-mo" id="MJXp-Span-108" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-109">1</span><span class="MJXp-mo" id="MJXp-Span-110" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-111">4</span><span class="MJXp-mo" id="MJXp-Span-112" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-22">[1, 4]</script> is not beautiful: for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-113"><span class="MJXp-msubsup" id="MJXp-Span-114"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-115" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-116" style="vertical-align: -0.4em;">2</span></span></span></span><script type="math/tex" id="MathJax-Element-23">a_2</script>, neither <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-117"><span class="MJXp-msubsup" id="MJXp-Span-118"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-119" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-120" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-121" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-122">2</span><span class="MJXp-mo" id="MJXp-Span-123" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-124">2</span></span></span><script type="math/tex" id="MathJax-Element-24">a_2 - 2 = 2</script> nor <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-125"><span class="MJXp-msubsup" id="MJXp-Span-126"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-127" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-128" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-129" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-130">1</span><span class="MJXp-mo" id="MJXp-Span-131" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-132">3</span></span></span><script type="math/tex" id="MathJax-Element-25">a_2 - 1 = 3</script> exists in the array, and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-133"><span class="MJXp-msubsup" id="MJXp-Span-134"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-135" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-136" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-137" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-138">1</span></span></span><script type="math/tex" id="MathJax-Element-26">a_2 \ne 1</script>; </li><li> the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-139"><span class="MJXp-mo" id="MJXp-Span-140" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-141">2</span><span class="MJXp-mo" id="MJXp-Span-142" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-27">[2]</script> is not beautiful: for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-143"><span class="MJXp-msubsup" id="MJXp-Span-144"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-145" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-146" style="vertical-align: -0.4em;">1</span></span></span></span><script type="math/tex" id="MathJax-Element-28">a_1</script>, neither <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-147"><span class="MJXp-msubsup" id="MJXp-Span-148"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-149" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-150" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-151" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-152">1</span><span class="MJXp-mo" id="MJXp-Span-153" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-154">1</span></span></span><script type="math/tex" id="MathJax-Element-29">a_1 - 1 = 1</script> nor <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-155"><span class="MJXp-msubsup" id="MJXp-Span-156"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-157" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-158" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-159" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-160">2</span><span class="MJXp-mo" id="MJXp-Span-161" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-162">0</span></span></span><script type="math/tex" id="MathJax-Element-30">a_1 - 2 = 0</script> exists in the array, and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-163"><span class="MJXp-msubsup" id="MJXp-Span-164"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-165" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-166" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-167" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-168">1</span></span></span><script type="math/tex" id="MathJax-Element-31">a_1 \ne 1</script>; </li><li> the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-169"><span class="MJXp-mo" id="MJXp-Span-170" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-171">2</span><span class="MJXp-mo" id="MJXp-Span-172" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-173">1</span><span class="MJXp-mo" id="MJXp-Span-174" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-175">3</span><span class="MJXp-mo" id="MJXp-Span-176" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-32">[2, 1, 3]</script> is beautiful: for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-177"><span class="MJXp-msubsup" id="MJXp-Span-178"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-179" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-180" style="vertical-align: -0.4em;">1</span></span></span></span><script type="math/tex" id="MathJax-Element-33">a_1</script>, the number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-181"><span class="MJXp-msubsup" id="MJXp-Span-182"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-183" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-184" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-185" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-186">1</span><span class="MJXp-mo" id="MJXp-Span-187" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-188">1</span></span></span><script type="math/tex" id="MathJax-Element-34">a_1 - 1 = 1</script> exists in the array; for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-189"><span class="MJXp-msubsup" id="MJXp-Span-190"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-191" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-192" style="vertical-align: -0.4em;">2</span></span></span></span><script type="math/tex" id="MathJax-Element-35">a_2</script>, the condition <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-193"><span class="MJXp-msubsup" id="MJXp-Span-194"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-195" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-196" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-197" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-198">1</span></span></span><script type="math/tex" id="MathJax-Element-36">a_2 = 1</script> holds; for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-199"><span class="MJXp-msubsup" id="MJXp-Span-200"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-201" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-202" style="vertical-align: -0.4em;">3</span></span></span></span><script type="math/tex" id="MathJax-Element-37">a_3</script>, the number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-203"><span class="MJXp-msubsup" id="MJXp-Span-204"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-205" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-206" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-207" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-208">2</span><span class="MJXp-mo" id="MJXp-Span-209" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-210">1</span></span></span><script type="math/tex" id="MathJax-Element-38">a_3 - 2 = 1</script> exists in the array. </li></ul><p>You are given a positive integer <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-211"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-212">s</span></span></span><script type="math/tex" id="MathJax-Element-39">s</script>. Find the minimum possible size of a beautiful array with the sum of elements equal to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-213"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-214">s</span></span></span><script type="math/tex" id="MathJax-Element-40">s</script>.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains one integer <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-215"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-216">t</span></span></span><script type="math/tex" id="MathJax-Element-41">t</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-217"><span class="MJXp-mn" id="MJXp-Span-218">1</span><span class="MJXp-mo" id="MJXp-Span-219" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-220">t</span><span class="MJXp-mo" id="MJXp-Span-221" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-222">5000</span></span></span><script type="math/tex" id="MathJax-Element-42">1 \le t \le 5000</script>) — the number of test cases.</p><p>Then <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-223"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-224">t</span></span></span><script type="math/tex" id="MathJax-Element-43">t</script> lines follow, the <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-225"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-226">i</span></span></span><script type="math/tex" id="MathJax-Element-44">i</script>-th line contains one integer <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-227"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-228">s</span></span></span><script type="math/tex" id="MathJax-Element-45">s</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-229"><span class="MJXp-mn" id="MJXp-Span-230">1</span><span class="MJXp-mo" id="MJXp-Span-231" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-232">s</span><span class="MJXp-mo" id="MJXp-Span-233" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-234">5000</span></span></span><script type="math/tex" id="MathJax-Element-46">1 \le s \le 5000</script>) for the <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-235"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-236">i</span></span></span><script type="math/tex" id="MathJax-Element-47">i</script>-th test case.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-237"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-238">t</span></span></span><script type="math/tex" id="MathJax-Element-48">t</script> integers, the <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-239"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-240">i</span></span></span><script type="math/tex" id="MathJax-Element-49">i</script>-th integer should be the answer for the <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-241"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-242">i</span></span></span><script type="math/tex" id="MathJax-Element-50">i</script>-th testcase: the minimum possible size of a beautiful array with the sum of elements equal to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-243"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-244">s</span></span></span><script type="math/tex" id="MathJax-Element-51">s</script>.</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id0011335133290051413" id="id007175500850450626" class="input-output-copier">Copy</div></div><pre id="id0011335133290051413">4
1
8
7
42
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id005021691657849819" id="id004270717779247326" class="input-output-copier">Copy</div></div><pre id="id005021691657849819">1
3
3
7
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>Consider the example test:</p><ol><li> in the first test case, the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-245"><span class="MJXp-mo" id="MJXp-Span-246" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-247">1</span><span class="MJXp-mo" id="MJXp-Span-248" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-52">[1]</script> meets all conditions; </li><li> in the second test case, the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-249"><span class="MJXp-mo" id="MJXp-Span-250" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-251">3</span><span class="MJXp-mo" id="MJXp-Span-252" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-253">4</span><span class="MJXp-mo" id="MJXp-Span-254" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-255">1</span><span class="MJXp-mo" id="MJXp-Span-256" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-53">[3, 4, 1]</script> meets all conditions; </li><li> in the third test case, the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-257"><span class="MJXp-mo" id="MJXp-Span-258" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-259">1</span><span class="MJXp-mo" id="MJXp-Span-260" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-261">2</span><span class="MJXp-mo" id="MJXp-Span-262" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-263">4</span><span class="MJXp-mo" id="MJXp-Span-264" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-54">[1, 2, 4]</script> meets all conditions; </li><li> in the fourth test case, the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-265"><span class="MJXp-mo" id="MJXp-Span-266" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-267">1</span><span class="MJXp-mo" id="MJXp-Span-268" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-269">4</span><span class="MJXp-mo" id="MJXp-Span-270" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-271">6</span><span class="MJXp-mo" id="MJXp-Span-272" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-273">8</span><span class="MJXp-mo" id="MJXp-Span-274" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-275">10</span><span class="MJXp-mo" id="MJXp-Span-276" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-277">2</span><span class="MJXp-mo" id="MJXp-Span-278" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-279">11</span><span class="MJXp-mo" id="MJXp-Span-280" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-55">[1, 4, 6, 8, 10, 2, 11]</script> meets all conditions. </li></ol></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/15523");
$("#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();
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'));
function showTestCaseMarker($input, tp, clazz, end) {
let top = 1E20;
let left = 1E20;
let problem = $input.closest(".problemindexholder");
$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_" + tp + "_" + end);
if (testCaseMarker.length === 0) {
const html = "<div class=\"testCaseMarker testCaseMarker_" + tp + "_" + end + " notice\"></div>";
problem.append($(html));
testCaseMarker = problem.find(".testCaseMarker_" + tp + "_" + end);
}
if (testCaseMarker) {
testCaseMarker.show()
.offset({top, left: left - 20})
.text(end);
}
}
$(".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") {
showTestCaseMarker($(this).closest(".sample-test").find(".input"), "input", clazz, end);
showTestCaseMarker($(this).closest(".sample-test").find(".output"), "output", clazz, 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_input_" + end).hide();
$(this).closest(".problemindexholder").find(".testCaseMarker_output_" + end).hide();
}
}
});
});
});
</script></div>
<div style="margin-bottom: 2em;">
<div class="problemindexholder" problemindex="B" data-uuid="ps_acba7964483d80b77a40beaf2204266bb81feabd">
<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;">×</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">B. Maximum Cost Deletion</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 input-standard"><div class="property-title">input</div>standard input</div><div class="output-file output-standard"><div class="property-title">output</div>standard output</div></div><div><p>You are given a string <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-281"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-282">s</span></span></span><script type="math/tex" id="MathJax-Element-56">s</script> of length <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-283"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-284">n</span></span></span><script type="math/tex" id="MathJax-Element-57">n</script> consisting only of the characters <span class="tex-font-style-tt">0</span> and <span class="tex-font-style-tt">1</span>.</p><p>You perform the following operation until the string becomes empty: choose some <span class="tex-font-style-bf">consecutive</span> substring of <span class="tex-font-style-bf">equal</span> characters, erase it from the string and glue the remaining two parts together (any of them can be empty) in the same order. For example, if you erase the substring <span class="tex-font-style-tt">111</span> from the string <span class="tex-font-style-tt">1<span class="tex-font-style-bf">111</span>10</span>, you will get the string <span class="tex-font-style-tt">110</span>. When you delete a substring of length <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-285"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-286">l</span></span></span><script type="math/tex" id="MathJax-Element-58">l</script>, you get <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-287"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-288">a</span><span class="MJXp-mo" id="MJXp-Span-289" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-290">l</span><span class="MJXp-mo" id="MJXp-Span-291" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-292">b</span></span></span><script type="math/tex" id="MathJax-Element-59">a \cdot l + b</script> points.</p><p>Your task is to calculate the maximum number of points that you can score in total, if you have to make the given string empty.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains a single integer <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-293"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-294">t</span></span></span><script type="math/tex" id="MathJax-Element-60">t</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-295"><span class="MJXp-mn" id="MJXp-Span-296">1</span><span class="MJXp-mo" id="MJXp-Span-297" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-298">t</span><span class="MJXp-mo" id="MJXp-Span-299" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-300">2000</span></span></span><script type="math/tex" id="MathJax-Element-61">1 \le t \le 2000</script>) — the number of testcases.</p><p>The first line of each testcase contains three integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-301"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-302">n</span></span></span><script type="math/tex" id="MathJax-Element-62">n</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-303"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-304">a</span></span></span><script type="math/tex" id="MathJax-Element-63">a</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-305"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-306">b</span></span></span><script type="math/tex" id="MathJax-Element-64">b</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-307"><span class="MJXp-mn" id="MJXp-Span-308">1</span><span class="MJXp-mo" id="MJXp-Span-309" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-310">n</span><span class="MJXp-mo" id="MJXp-Span-311" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-312">100</span><span class="MJXp-mo" id="MJXp-Span-313" style="margin-left: 0em; margin-right: 0.222em;">;</span><span class="MJXp-mo" id="MJXp-Span-314" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-315">100</span><span class="MJXp-mo" id="MJXp-Span-316" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-317">a</span><span class="MJXp-mo" id="MJXp-Span-318" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-319">b</span><span class="MJXp-mo" id="MJXp-Span-320" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-321">100</span></span></span><script type="math/tex" id="MathJax-Element-65">1 \le n \le 100; -100 \le a, b \le 100</script>) — the length of the string <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-322"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-323">s</span></span></span><script type="math/tex" id="MathJax-Element-66">s</script> and the parameters <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-324"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-325">a</span></span></span><script type="math/tex" id="MathJax-Element-67">a</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-326"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-327">b</span></span></span><script type="math/tex" id="MathJax-Element-68">b</script>.</p><p>The second line contains the string <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-328"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-329">s</span></span></span><script type="math/tex" id="MathJax-Element-69">s</script>. The string <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-330"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-331">s</span></span></span><script type="math/tex" id="MathJax-Element-70">s</script> consists only of the characters <span class="tex-font-style-tt">0</span> and <span class="tex-font-style-tt">1</span>.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each testcase, print a single integer — the maximum number of points that you can score.</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id007675683682124629" id="id0006505631406218215" class="input-output-copier">Copy</div></div><pre id="id007675683682124629">3
3 2 0
000
5 -2 5
11001
6 1 -4
100111
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id001322358127831661" id="id00996265197942917" class="input-output-copier">Copy</div></div><pre id="id001322358127831661">6
15
-2
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first example, it is enough to delete the entire string, then we will get <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-332"><span class="MJXp-mn" id="MJXp-Span-333">2</span><span class="MJXp-mo" id="MJXp-Span-334" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-335">3</span><span class="MJXp-mo" id="MJXp-Span-336" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-337">0</span><span class="MJXp-mo" id="MJXp-Span-338" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-339">6</span></span></span><script type="math/tex" id="MathJax-Element-71">2 \cdot 3 + 0 = 6</script> points.</p><p>In the second example, if we delete characters one by one, then for each deleted character we will get <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-340"><span class="MJXp-mo" id="MJXp-Span-341" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-342" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-343">2</span><span class="MJXp-mo" id="MJXp-Span-344" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-345" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-346">1</span><span class="MJXp-mo" id="MJXp-Span-347" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-348">5</span><span class="MJXp-mo" id="MJXp-Span-349" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-350">3</span></span></span><script type="math/tex" id="MathJax-Element-72">(-2) \cdot 1 + 5 = 3</script> points, i.e. <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-351"><span class="MJXp-mn" id="MJXp-Span-352">15</span></span></span><script type="math/tex" id="MathJax-Element-73">15</script> points in total.</p><p>In the third example, we can delete the substring <span class="tex-font-style-tt">00</span> from the string <span class="tex-font-style-tt">1<span class="tex-font-style-bf">00</span>111</span>, we get <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-353"><span class="MJXp-mn" id="MJXp-Span-354">1</span><span class="MJXp-mo" id="MJXp-Span-355" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-356">2</span><span class="MJXp-mo" id="MJXp-Span-357" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mo" id="MJXp-Span-358" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-359" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-360">4</span><span class="MJXp-mo" id="MJXp-Span-361" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-362" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mo" id="MJXp-Span-363" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-364">2</span></span></span><script type="math/tex" id="MathJax-Element-74">1 \cdot 2 + (-4) = -2</script> points, and the string will be equal to <span class="tex-font-style-tt">1111</span>, removing it entirely we get <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-365"><span class="MJXp-mn" id="MJXp-Span-366">1</span><span class="MJXp-mo" id="MJXp-Span-367" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-368">4</span><span class="MJXp-mo" id="MJXp-Span-369" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mo" id="MJXp-Span-370" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-371" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-372">4</span><span class="MJXp-mo" id="MJXp-Span-373" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-374" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-375">0</span></span></span><script type="math/tex" id="MathJax-Element-75">1 \cdot 4 + (-4) = 0</script> points. In total, we got <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-376"><span class="MJXp-mo" id="MJXp-Span-377" style="margin-left: 0em; margin-right: 0.111em;"></span><span class="MJXp-mn" id="MJXp-Span-378">2</span></span></span><script type="math/tex" id="MathJax-Element-76">-2</script> points for <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-379"><span class="MJXp-mn" id="MJXp-Span-380">2</span></span></span><script type="math/tex" id="MathJax-Element-77">2</script> operations.</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/15523");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script><script type="text/javascript">
$(document).ready(function () {
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_b3e37fec06e987daeb69fa1795897de33dc060d7">
<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;">×</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">C. Manhattan Subarrays</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 input-standard"><div class="property-title">input</div>standard input</div><div class="output-file output-standard"><div class="property-title">output</div>standard output</div></div><div><p>Suppose you have two points <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-381"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-382">p</span><span class="MJXp-mo" id="MJXp-Span-383" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mo" id="MJXp-Span-384" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-385"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-386" style="margin-right: 0.05em;">x</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-387" style="vertical-align: -0.4em;">p</span></span><span class="MJXp-mo" id="MJXp-Span-388" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-389"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-390" style="margin-right: 0.05em;">y</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-391" style="vertical-align: -0.4em;">p</span></span><span class="MJXp-mo" id="MJXp-Span-392" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-78">p = (x_p, y_p)</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-393"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-394">q</span><span class="MJXp-mo" id="MJXp-Span-395" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mo" id="MJXp-Span-396" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-397"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-398" style="margin-right: 0.05em;">x</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-399" style="vertical-align: -0.4em;">q</span></span><span class="MJXp-mo" id="MJXp-Span-400" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-401"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-402" style="margin-right: 0.05em;">y</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-403" style="vertical-align: -0.4em;">q</span></span><span class="MJXp-mo" id="MJXp-Span-404" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-79">q = (x_q, y_q)</script>. Let's denote the Manhattan distance between them as <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-405"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-406">d</span><span class="MJXp-mo" id="MJXp-Span-407" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-408">p</span><span class="MJXp-mo" id="MJXp-Span-409" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-410">q</span><span class="MJXp-mo" id="MJXp-Span-411" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-412" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mrow" id="MJXp-Span-413"><span class="MJXp-mo" id="MJXp-Span-414" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-msubsup" id="MJXp-Span-415"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-416" style="margin-right: 0.05em;">x</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-417" style="vertical-align: -0.4em;">p</span></span><span class="MJXp-mo" id="MJXp-Span-418" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-msubsup" id="MJXp-Span-419"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-420" style="margin-right: 0.05em;">x</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-421" style="vertical-align: -0.4em;">q</span></span><span class="MJXp-mrow" id="MJXp-Span-422"><span class="MJXp-mo" id="MJXp-Span-423" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-424" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mrow" id="MJXp-Span-425"><span class="MJXp-mo" id="MJXp-Span-426" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-msubsup" id="MJXp-Span-427"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-428" style="margin-right: 0.05em;">y</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-429" style="vertical-align: -0.4em;">p</span></span><span class="MJXp-mo" id="MJXp-Span-430" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-msubsup" id="MJXp-Span-431"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-432" style="margin-right: 0.05em;">y</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-433" style="vertical-align: -0.4em;">q</span></span><span class="MJXp-mrow" id="MJXp-Span-434"><span class="MJXp-mo" id="MJXp-Span-435" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span></span></span><script type="math/tex" id="MathJax-Element-80">d(p, q) = |x_p - x_q| + |y_p - y_q|</script>.</p><p>Let's say that three points <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-436"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-437">p</span></span></span><script type="math/tex" id="MathJax-Element-81">p</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-438"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-439">q</span></span></span><script type="math/tex" id="MathJax-Element-82">q</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-440"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-441">r</span></span></span><script type="math/tex" id="MathJax-Element-83">r</script> form a <span class="tex-font-style-it">bad</span> triple if <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-442"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-443">d</span><span class="MJXp-mo" id="MJXp-Span-444" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-445">p</span><span class="MJXp-mo" id="MJXp-Span-446" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-447">r</span><span class="MJXp-mo" id="MJXp-Span-448" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-449" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-450">d</span><span class="MJXp-mo" id="MJXp-Span-451" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-452">p</span><span class="MJXp-mo" id="MJXp-Span-453" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-454">q</span><span class="MJXp-mo" id="MJXp-Span-455" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-456" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-457">d</span><span class="MJXp-mo" id="MJXp-Span-458" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-459">q</span><span class="MJXp-mo" id="MJXp-Span-460" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-461">r</span><span class="MJXp-mo" id="MJXp-Span-462" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-84">d(p, r) = d(p, q) + d(q, r)</script>.</p><p>Let's say that an array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-463"><span class="MJXp-msubsup" id="MJXp-Span-464"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-465" style="margin-right: 0.05em;">b</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-466" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-467" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-468"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-469" style="margin-right: 0.05em;">b</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-470" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-471" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-472" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-473" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-474"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-475" style="margin-right: 0.05em;">b</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-476" style="vertical-align: -0.4em;">m</span></span></span></span><script type="math/tex" id="MathJax-Element-85">b_1, b_2, \dots, b_m</script> is <span class="tex-font-style-it">good</span> if it is impossible to choose three <span class="tex-font-style-bf">distinct</span> indices <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-477"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-478">i</span></span></span><script type="math/tex" id="MathJax-Element-86">i</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-479"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-480">j</span></span></span><script type="math/tex" id="MathJax-Element-87">j</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-481"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-482">k</span></span></span><script type="math/tex" id="MathJax-Element-88">k</script> such that the points <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-483"><span class="MJXp-mo" id="MJXp-Span-484" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-485"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-486" style="margin-right: 0.05em;">b</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-487" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-488" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-489">i</span><span class="MJXp-mo" id="MJXp-Span-490" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-89">(b_i, i)</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-491"><span class="MJXp-mo" id="MJXp-Span-492" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-493"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-494" style="margin-right: 0.05em;">b</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-495" style="vertical-align: -0.4em;">j</span></span><span class="MJXp-mo" id="MJXp-Span-496" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-497">j</span><span class="MJXp-mo" id="MJXp-Span-498" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-90">(b_j, j)</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-499"><span class="MJXp-mo" id="MJXp-Span-500" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-501"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-502" style="margin-right: 0.05em;">b</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-503" style="vertical-align: -0.4em;">k</span></span><span class="MJXp-mo" id="MJXp-Span-504" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-505">k</span><span class="MJXp-mo" id="MJXp-Span-506" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-91">(b_k, k)</script> form a bad triple.</p><p>You are given an array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-507"><span class="MJXp-msubsup" id="MJXp-Span-508"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-509" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-510" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-511" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-512"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-513" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-514" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-515" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-516" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-517" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-518"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-519" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-520" style="vertical-align: -0.4em;">n</span></span></span></span><script type="math/tex" id="MathJax-Element-92">a_1, a_2, \dots, a_n</script>. Calculate the number of <span class="tex-font-style-it">good</span> subarrays of <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-521"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-522">a</span></span></span><script type="math/tex" id="MathJax-Element-93">a</script>. A subarray of the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-523"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-524">a</span></span></span><script type="math/tex" id="MathJax-Element-94">a</script> is the array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-525"><span class="MJXp-msubsup" id="MJXp-Span-526"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-527" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-528" style="vertical-align: -0.4em;">l</span></span><span class="MJXp-mo" id="MJXp-Span-529" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-530"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-531" style="margin-right: 0.05em;">a</span><span class="MJXp-mrow MJXp-script" id="MJXp-Span-532" style="vertical-align: -0.4em;"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-533">l</span><span class="MJXp-mo" id="MJXp-Span-534">+</span><span class="MJXp-mn" id="MJXp-Span-535">1</span></span></span><span class="MJXp-mo" id="MJXp-Span-536" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-537" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-538" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-539"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-540" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-541" style="vertical-align: -0.4em;">r</span></span></span></span><script type="math/tex" id="MathJax-Element-95">a_l, a_{l + 1}, \dots, a_r</script> for some <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-542"><span class="MJXp-mn" id="MJXp-Span-543">1</span><span class="MJXp-mo" id="MJXp-Span-544" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-545">l</span><span class="MJXp-mo" id="MJXp-Span-546" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-547">r</span><span class="MJXp-mo" id="MJXp-Span-548" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-549">n</span></span></span><script type="math/tex" id="MathJax-Element-96">1 \le l \le r \le n</script>.</p><p>Note that, according to the definition, subarrays of length <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-550"><span class="MJXp-mn" id="MJXp-Span-551">1</span></span></span><script type="math/tex" id="MathJax-Element-97">1</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-552"><span class="MJXp-mn" id="MJXp-Span-553">2</span></span></span><script type="math/tex" id="MathJax-Element-98">2</script> are <span class="tex-font-style-it">good</span>.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains one integer <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-554"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-555">t</span></span></span><script type="math/tex" id="MathJax-Element-99">t</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-556"><span class="MJXp-mn" id="MJXp-Span-557">1</span><span class="MJXp-mo" id="MJXp-Span-558" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-559">t</span><span class="MJXp-mo" id="MJXp-Span-560" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-561">5000</span></span></span><script type="math/tex" id="MathJax-Element-100">1 \le t \le 5000</script>) — the number of test cases.</p><p>The first line of each test case contains one integer <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-562"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-563">n</span></span></span><script type="math/tex" id="MathJax-Element-101">n</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-564"><span class="MJXp-mn" id="MJXp-Span-565">1</span><span class="MJXp-mo" id="MJXp-Span-566" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-567">n</span><span class="MJXp-mo" id="MJXp-Span-568" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-569">2</span><span class="MJXp-mo" id="MJXp-Span-570" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-msubsup" id="MJXp-Span-571"><span class="MJXp-mn" id="MJXp-Span-572" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-573" style="vertical-align: 0.5em;">5</span></span></span></span><script type="math/tex" id="MathJax-Element-102">1 \le n \le 2 \cdot 10^5</script>) — the length of array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-574"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-575">a</span></span></span><script type="math/tex" id="MathJax-Element-103">a</script>.</p><p>The second line of each test case contains <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-576"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-577">n</span></span></span><script type="math/tex" id="MathJax-Element-104">n</script> integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-578"><span class="MJXp-msubsup" id="MJXp-Span-579"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-580" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-581" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-582" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-583"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-584" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-585" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-586" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-587" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-588" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-589"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-590" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-591" style="vertical-align: -0.4em;">n</span></span></span></span><script type="math/tex" id="MathJax-Element-105">a_1, a_2, \dots, a_n</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-592"><span class="MJXp-mn" id="MJXp-Span-593">1</span><span class="MJXp-mo" id="MJXp-Span-594" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-msubsup" id="MJXp-Span-595"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-596" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-597" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-598" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-msubsup" id="MJXp-Span-599"><span class="MJXp-mn" id="MJXp-Span-600" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-601" style="vertical-align: 0.5em;">9</span></span></span></span><script type="math/tex" id="MathJax-Element-106">1 \le a_i \le 10^9</script>).</p><p>It's guaranteed that the sum of <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-602"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-603">n</span></span></span><script type="math/tex" id="MathJax-Element-107">n</script> doesn't exceed <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-604"><span class="MJXp-mn" id="MJXp-Span-605">2</span><span class="MJXp-mo" id="MJXp-Span-606" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-msubsup" id="MJXp-Span-607"><span class="MJXp-mn" id="MJXp-Span-608" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-609" style="vertical-align: 0.5em;">5</span></span></span></span><script type="math/tex" id="MathJax-Element-108">2 \cdot 10^5</script>.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each test case, print the number of <span class="tex-font-style-it">good</span> subarrays of array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-610"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-611">a</span></span></span><script type="math/tex" id="MathJax-Element-109">a</script>.</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id0045100789178148193" id="id0034855463835277845" class="input-output-copier">Copy</div></div><pre id="id0045100789178148193">3
4
2 4 1 3
5
6 9 1 9 6
2
13 37
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id008205050640892653" id="id00646096671878121" class="input-output-copier">Copy</div></div><pre id="id008205050640892653">10
12
3
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first test case, it can be proven that any subarray of <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-612"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-613">a</span></span></span><script type="math/tex" id="MathJax-Element-110">a</script> is <span class="tex-font-style-it">good</span>. For example, subarray <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-614"><span class="MJXp-mo" id="MJXp-Span-615" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-msubsup" id="MJXp-Span-616"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-617" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-618" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-619" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-620"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-621" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-622" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-623" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-624"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-625" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-626" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-627" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-111">[a_2, a_3, a_4]</script> is good since it contains only three elements and: </p><ul><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-628"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-629">d</span><span class="MJXp-mo" id="MJXp-Span-630" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-631" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-632"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-633" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-634" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-635" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-636">2</span><span class="MJXp-mo" id="MJXp-Span-637" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-638" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-639" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-640"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-641" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-642" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-643" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-644">4</span><span class="MJXp-mo" id="MJXp-Span-645" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-646" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-647" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mrow" id="MJXp-Span-648"><span class="MJXp-mo" id="MJXp-Span-649" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mn" id="MJXp-Span-650">4</span><span class="MJXp-mo" id="MJXp-Span-651" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-652">3</span><span class="MJXp-mrow" id="MJXp-Span-653"><span class="MJXp-mo" id="MJXp-Span-654" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-655" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mrow" id="MJXp-Span-656"><span class="MJXp-mo" id="MJXp-Span-657" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mn" id="MJXp-Span-658">2</span><span class="MJXp-mo" id="MJXp-Span-659" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-660">4</span><span class="MJXp-mrow" id="MJXp-Span-661"><span class="MJXp-mo" id="MJXp-Span-662" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-663" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-664">3</span></span></span><script type="math/tex" id="MathJax-Element-112">d((a_2, 2), (a_4, 4)) = |4 - 3| + |2 - 4| = 3</script><span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-665"><span class="MJXp-mo" id="MJXp-Span-666" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span></span></span><script type="math/tex" id="MathJax-Element-113"><</script><span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-667"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-668">d</span><span class="MJXp-mo" id="MJXp-Span-669" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-670" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-671"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-672" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-673" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-674" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-675">2</span><span class="MJXp-mo" id="MJXp-Span-676" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-677" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-678" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-679"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-680" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-681" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-682" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-683">3</span><span class="MJXp-mo" id="MJXp-Span-684" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-685" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-686" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-687">d</span><span class="MJXp-mo" id="MJXp-Span-688" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-689" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-690"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-691" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-692" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-693" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-694">3</span><span class="MJXp-mo" id="MJXp-Span-695" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-696" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-697" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-698"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-699" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-700" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-701" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-702">4</span><span class="MJXp-mo" id="MJXp-Span-703" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-704" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-705" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-706">3</span><span class="MJXp-mo" id="MJXp-Span-707" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-708">1</span><span class="MJXp-mo" id="MJXp-Span-709" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-710">2</span><span class="MJXp-mo" id="MJXp-Span-711" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-712">1</span><span class="MJXp-mo" id="MJXp-Span-713" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-714">7</span></span></span><script type="math/tex" id="MathJax-Element-114">d((a_2, 2), (a_3, 3)) + d((a_3, 3), (a_4, 4)) = 3 + 1 + 2 + 1 = 7</script>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-715"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-716">d</span><span class="MJXp-mo" id="MJXp-Span-717" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-718" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-719"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-720" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-721" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-722" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-723">2</span><span class="MJXp-mo" id="MJXp-Span-724" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-725" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-726" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-727"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-728" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-729" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-730" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-731">3</span><span class="MJXp-mo" id="MJXp-Span-732" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-733" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-115">d((a_2, 2), (a_3, 3))</script><span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-734"><span class="MJXp-mo" id="MJXp-Span-735" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span></span></span><script type="math/tex" id="MathJax-Element-116"><</script><span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-736"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-737">d</span><span class="MJXp-mo" id="MJXp-Span-738" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-739" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-740"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-741" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-742" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-743" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-744">2</span><span class="MJXp-mo" id="MJXp-Span-745" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-746" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-747" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-748"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-749" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-750" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-751" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-752">4</span><span class="MJXp-mo" id="MJXp-Span-753" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-754" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-755" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-756">d</span><span class="MJXp-mo" id="MJXp-Span-757" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-758" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-759"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-760" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-761" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-762" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-763">4</span><span class="MJXp-mo" id="MJXp-Span-764" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-765" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-766" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-767"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-768" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-769" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-770" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-771">3</span><span class="MJXp-mo" id="MJXp-Span-772" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-773" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-117">d((a_2, 2), (a_4, 4)) + d((a_4, 4), (a_3, 3))</script>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-774"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-775">d</span><span class="MJXp-mo" id="MJXp-Span-776" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-777" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-778"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-779" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-780" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-781" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-782">3</span><span class="MJXp-mo" id="MJXp-Span-783" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-784" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-785" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-786"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-787" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-788" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-789" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-790">4</span><span class="MJXp-mo" id="MJXp-Span-791" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-792" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-118">d((a_3, 3), (a_4, 4))</script><span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-793"><span class="MJXp-mo" id="MJXp-Span-794" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span></span></span><script type="math/tex" id="MathJax-Element-119"><</script><span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-795"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-796">d</span><span class="MJXp-mo" id="MJXp-Span-797" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-798" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-799"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-800" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-801" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-802" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-803">3</span><span class="MJXp-mo" id="MJXp-Span-804" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-805" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-806" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-807"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-808" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-809" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-810" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-811">2</span><span class="MJXp-mo" id="MJXp-Span-812" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-813" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-814" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-815">d</span><span class="MJXp-mo" id="MJXp-Span-816" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-817" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-818"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-819" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-820" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-821" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-822">2</span><span class="MJXp-mo" id="MJXp-Span-823" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-824" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-825" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-826"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-827" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-828" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-829" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-830">4</span><span class="MJXp-mo" id="MJXp-Span-831" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-832" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-120">d((a_3, 3), (a_2, 2)) + d((a_2, 2), (a_4, 4))</script>; </li></ul><p>In the second test case, for example, subarray <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-833"><span class="MJXp-mo" id="MJXp-Span-834" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-msubsup" id="MJXp-Span-835"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-836" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-837" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-838" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-839"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-840" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-841" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-842" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-843"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-844" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-845" style="vertical-align: -0.4em;">3</span></span><span class="MJXp-mo" id="MJXp-Span-846" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-847"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-848" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-849" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-850" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-121">[a_1, a_2, a_3, a_4]</script> is <span class="tex-font-style-bf">not</span> good, since it contains a <span class="tex-font-style-it">bad</span> triple <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-851"><span class="MJXp-mo" id="MJXp-Span-852" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-853"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-854" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-855" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-856" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-857">1</span><span class="MJXp-mo" id="MJXp-Span-858" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-122">(a_1, 1)</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-859"><span class="MJXp-mo" id="MJXp-Span-860" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-861"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-862" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-863" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-864" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-865">2</span><span class="MJXp-mo" id="MJXp-Span-866" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-123">(a_2, 2)</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-867"><span class="MJXp-mo" id="MJXp-Span-868" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-869"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-870" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-871" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-872" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-873">4</span><span class="MJXp-mo" id="MJXp-Span-874" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-124">(a_4, 4)</script>: </p><ul><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-875"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-876">d</span><span class="MJXp-mo" id="MJXp-Span-877" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-878" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-879"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-880" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-881" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-882" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-883">1</span><span class="MJXp-mo" id="MJXp-Span-884" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-885" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-886" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-887"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-888" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-889" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-890" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-891">4</span><span class="MJXp-mo" id="MJXp-Span-892" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-893" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-894" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mrow" id="MJXp-Span-895"><span class="MJXp-mo" id="MJXp-Span-896" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mn" id="MJXp-Span-897">6</span><span class="MJXp-mo" id="MJXp-Span-898" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-899">9</span><span class="MJXp-mrow" id="MJXp-Span-900"><span class="MJXp-mo" id="MJXp-Span-901" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-902" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mrow" id="MJXp-Span-903"><span class="MJXp-mo" id="MJXp-Span-904" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mn" id="MJXp-Span-905">1</span><span class="MJXp-mo" id="MJXp-Span-906" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-907">4</span><span class="MJXp-mrow" id="MJXp-Span-908"><span class="MJXp-mo" id="MJXp-Span-909" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-910" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-911">6</span></span></span><script type="math/tex" id="MathJax-Element-125">d((a_1, 1), (a_4, 4)) = |6 - 9| + |1 - 4| = 6</script>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-912"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-913">d</span><span class="MJXp-mo" id="MJXp-Span-914" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-915" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-916"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-917" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-918" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-919" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-920">1</span><span class="MJXp-mo" id="MJXp-Span-921" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-922" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-923" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-924"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-925" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-926" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-927" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-928">2</span><span class="MJXp-mo" id="MJXp-Span-929" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-930" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-931" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mrow" id="MJXp-Span-932"><span class="MJXp-mo" id="MJXp-Span-933" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mn" id="MJXp-Span-934">6</span><span class="MJXp-mo" id="MJXp-Span-935" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-936">9</span><span class="MJXp-mrow" id="MJXp-Span-937"><span class="MJXp-mo" id="MJXp-Span-938" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-939" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mrow" id="MJXp-Span-940"><span class="MJXp-mo" id="MJXp-Span-941" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mn" id="MJXp-Span-942">1</span><span class="MJXp-mo" id="MJXp-Span-943" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-944">2</span><span class="MJXp-mrow" id="MJXp-Span-945"><span class="MJXp-mo" id="MJXp-Span-946" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-947" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-948">4</span></span></span><script type="math/tex" id="MathJax-Element-126">d((a_1, 1), (a_2, 2)) = |6 - 9| + |1 - 2| = 4</script>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-949"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-950">d</span><span class="MJXp-mo" id="MJXp-Span-951" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-952" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-953"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-954" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-955" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-956" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-957">2</span><span class="MJXp-mo" id="MJXp-Span-958" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-959" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-960" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-961"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-962" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-963" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-964" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-965">4</span><span class="MJXp-mo" id="MJXp-Span-966" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-967" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-968" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mrow" id="MJXp-Span-969"><span class="MJXp-mo" id="MJXp-Span-970" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mn" id="MJXp-Span-971">9</span><span class="MJXp-mo" id="MJXp-Span-972" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-973">9</span><span class="MJXp-mrow" id="MJXp-Span-974"><span class="MJXp-mo" id="MJXp-Span-975" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-976" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mrow" id="MJXp-Span-977"><span class="MJXp-mo" id="MJXp-Span-978" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mn" id="MJXp-Span-979">2</span><span class="MJXp-mo" id="MJXp-Span-980" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-981">4</span><span class="MJXp-mrow" id="MJXp-Span-982"><span class="MJXp-mo" id="MJXp-Span-983" style="margin-left: 0.167em; margin-right: 0.167em;">|</span></span><span class="MJXp-mo" id="MJXp-Span-984" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-985">2</span></span></span><script type="math/tex" id="MathJax-Element-127">d((a_2, 2), (a_4, 4)) = |9 - 9| + |2 - 4| = 2</script>; </li></ul><p>So, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-986"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-987">d</span><span class="MJXp-mo" id="MJXp-Span-988" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-989" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-990"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-991" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-992" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-993" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-994">1</span><span class="MJXp-mo" id="MJXp-Span-995" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-996" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-997" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-998"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-999" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1000" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-1001" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1002">4</span><span class="MJXp-mo" id="MJXp-Span-1003" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-1004" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-1005" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1006">d</span><span class="MJXp-mo" id="MJXp-Span-1007" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-1008" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-1009"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1010" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1011" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-1012" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1013">1</span><span class="MJXp-mo" id="MJXp-Span-1014" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-1015" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-1016" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-1017"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1018" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1019" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1020" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1021">2</span><span class="MJXp-mo" id="MJXp-Span-1022" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-1023" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-1024" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1025">d</span><span class="MJXp-mo" id="MJXp-Span-1026" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mo" id="MJXp-Span-1027" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-1028"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1029" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1030" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1031" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1032">2</span><span class="MJXp-mo" id="MJXp-Span-1033" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-1034" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-1035" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-msubsup" id="MJXp-Span-1036"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1037" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1038" style="vertical-align: -0.4em;">4</span></span><span class="MJXp-mo" id="MJXp-Span-1039" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1040">4</span><span class="MJXp-mo" id="MJXp-Span-1041" style="margin-left: 0em; margin-right: 0em;">)</span><span class="MJXp-mo" id="MJXp-Span-1042" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-128">d((a_1, 1), (a_4, 4)) = d((a_1, 1), (a_2, 2)) + d((a_2, 2), (a_4, 4))</script>.</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/15523");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script><script type="text/javascript">
$(document).ready(function () {
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_515ea55cc6ec3152039a89e81dba7559d15ff9d5">
<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;">×</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">D. Excellent Arrays</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 input-standard"><div class="property-title">input</div>standard input</div><div class="output-file output-standard"><div class="property-title">output</div>standard output</div></div><div><p>Let's call an integer array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1043"><span class="MJXp-msubsup" id="MJXp-Span-1044"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1045" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1046" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-1047" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-1048"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1049" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1050" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1051" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-1052" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-1053" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-1054"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1055" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1056" style="vertical-align: -0.4em;">n</span></span></span></span><script type="math/tex" id="MathJax-Element-129">a_1, a_2, \dots, a_n</script><span class="tex-font-style-it">good</span> if <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1057"><span class="MJXp-msubsup" id="MJXp-Span-1058"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1059" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1060" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-1061" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1062">i</span></span></span><script type="math/tex" id="MathJax-Element-130">a_i \neq i</script> for each <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1063"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1064">i</span></span></span><script type="math/tex" id="MathJax-Element-131">i</script>.</p><p>Let <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1065"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1066">F</span><span class="MJXp-mo" id="MJXp-Span-1067" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1068">a</span><span class="MJXp-mo" id="MJXp-Span-1069" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-132">F(a)</script> be the number of pairs <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1070"><span class="MJXp-mo" id="MJXp-Span-1071" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1072">i</span><span class="MJXp-mo" id="MJXp-Span-1073" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1074">j</span><span class="MJXp-mo" id="MJXp-Span-1075" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-133">(i, j)</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1076"><span class="MJXp-mn" id="MJXp-Span-1077">1</span><span class="MJXp-mo" id="MJXp-Span-1078" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1079">i</span><span class="MJXp-mo" id="MJXp-Span-1080" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1081">j</span><span class="MJXp-mo" id="MJXp-Span-1082" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1083">n</span></span></span><script type="math/tex" id="MathJax-Element-134">1 \le i < j \le n</script>) such that <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1084"><span class="MJXp-msubsup" id="MJXp-Span-1085"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1086" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1087" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-1088" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-msubsup" id="MJXp-Span-1089"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1090" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1091" style="vertical-align: -0.4em;">j</span></span><span class="MJXp-mo" id="MJXp-Span-1092" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1093">i</span><span class="MJXp-mo" id="MJXp-Span-1094" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1095">j</span></span></span><script type="math/tex" id="MathJax-Element-135">a_i + a_j = i + j</script>.</p><p>Let's say that an array <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1096"><span class="MJXp-msubsup" id="MJXp-Span-1097"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1098" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1099" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-1100" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-1101"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1102" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1103" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1104" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-1105" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-1106" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-1107"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1108" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1109" style="vertical-align: -0.4em;">n</span></span></span></span><script type="math/tex" id="MathJax-Element-136">a_1, a_2, \dots, a_n</script> is <span class="tex-font-style-it">excellent</span> if: </p><ul><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1110"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1111">a</span></span></span><script type="math/tex" id="MathJax-Element-137">a</script> is <span class="tex-font-style-it">good</span>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1112"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1113">l</span><span class="MJXp-mo" id="MJXp-Span-1114" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1115"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1116" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1117" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-1118" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1119">r</span></span></span><script type="math/tex" id="MathJax-Element-138">l \le a_i \le r</script> for each <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1120"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1121">i</span></span></span><script type="math/tex" id="MathJax-Element-139">i</script>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1122"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1123">F</span><span class="MJXp-mo" id="MJXp-Span-1124" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1125">a</span><span class="MJXp-mo" id="MJXp-Span-1126" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-140">F(a)</script> is the maximum possible among all <span class="tex-font-style-it">good</span> arrays of size <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1127"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1128">n</span></span></span><script type="math/tex" id="MathJax-Element-141">n</script>. </li></ul><p>Given <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1129"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1130">n</span></span></span><script type="math/tex" id="MathJax-Element-142">n</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1131"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1132">l</span></span></span><script type="math/tex" id="MathJax-Element-143">l</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1133"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1134">r</span></span></span><script type="math/tex" id="MathJax-Element-144">r</script>, calculate the number of <span class="tex-font-style-it">excellent</span> arrays modulo <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1135"><span class="MJXp-msubsup" id="MJXp-Span-1136"><span class="MJXp-mn" id="MJXp-Span-1137" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1138" style="vertical-align: 0.5em;">9</span></span><span class="MJXp-mo" id="MJXp-Span-1139" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-1140">7</span></span></span><script type="math/tex" id="MathJax-Element-145">10^9 + 7</script>.</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains a single integer <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1141"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1142">t</span></span></span><script type="math/tex" id="MathJax-Element-146">t</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1143"><span class="MJXp-mn" id="MJXp-Span-1144">1</span><span class="MJXp-mo" id="MJXp-Span-1145" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1146">t</span><span class="MJXp-mo" id="MJXp-Span-1147" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-1148">1000</span></span></span><script type="math/tex" id="MathJax-Element-147">1 \le t \le 1000</script>) — the number of test cases. </p><p>The first and only line of each test case contains three integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1149"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1150">n</span></span></span><script type="math/tex" id="MathJax-Element-148">n</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1151"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1152">l</span></span></span><script type="math/tex" id="MathJax-Element-149">l</script>, and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1153"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1154">r</span></span></span><script type="math/tex" id="MathJax-Element-150">r</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1155"><span class="MJXp-mn" id="MJXp-Span-1156">2</span><span class="MJXp-mo" id="MJXp-Span-1157" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1158">n</span><span class="MJXp-mo" id="MJXp-Span-1159" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-1160">2</span><span class="MJXp-mo" id="MJXp-Span-1161" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1162"><span class="MJXp-mn" id="MJXp-Span-1163" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1164" style="vertical-align: 0.5em;">5</span></span></span></span><script type="math/tex" id="MathJax-Element-151">2 \le n \le 2 \cdot 10^5</script>; <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1165"><span class="MJXp-mo" id="MJXp-Span-1166" style="margin-left: 0em; margin-right: 0.111em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1167"><span class="MJXp-mn" id="MJXp-Span-1168" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1169" style="vertical-align: 0.5em;">9</span></span><span class="MJXp-mo" id="MJXp-Span-1170" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1171">l</span><span class="MJXp-mo" id="MJXp-Span-1172" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-1173">1</span></span></span><script type="math/tex" id="MathJax-Element-152">-10^9 \le l \le 1</script>; <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1174"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1175">n</span><span class="MJXp-mo" id="MJXp-Span-1176" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1177">r</span><span class="MJXp-mo" id="MJXp-Span-1178" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1179"><span class="MJXp-mn" id="MJXp-Span-1180" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1181" style="vertical-align: 0.5em;">9</span></span></span></span><script type="math/tex" id="MathJax-Element-153">n \le r \le 10^9</script>).</p><p>It's guaranteed that the sum of <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1182"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1183">n</span></span></span><script type="math/tex" id="MathJax-Element-154">n</script> doesn't exceed <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1184"><span class="MJXp-mn" id="MJXp-Span-1185">2</span><span class="MJXp-mo" id="MJXp-Span-1186" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1187"><span class="MJXp-mn" id="MJXp-Span-1188" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1189" style="vertical-align: 0.5em;">5</span></span></span></span><script type="math/tex" id="MathJax-Element-155">2 \cdot 10^5</script>.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each test case, print the number of excellent arrays modulo <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1190"><span class="MJXp-msubsup" id="MJXp-Span-1191"><span class="MJXp-mn" id="MJXp-Span-1192" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1193" style="vertical-align: 0.5em;">9</span></span><span class="MJXp-mo" id="MJXp-Span-1194" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-1195">7</span></span></span><script type="math/tex" id="MathJax-Element-156">10^9 + 7</script>.</p></div><div class="sample-tests"><div class="section-title">Example</div><div class="sample-test"><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id0023043713167808821" id="id004407875898011011" class="input-output-copier">Copy</div></div><pre id="id0023043713167808821">4
3 0 3
4 -3 5
42 -33 55
69 -42 146
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id004542568812571498" id="id008244354808710753" class="input-output-copier">Copy</div></div><pre id="id004542568812571498">4
10
143922563
698570404
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first test case, it can be proven that the maximum <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1196"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1197">F</span><span class="MJXp-mo" id="MJXp-Span-1198" style="margin-left: 0em; margin-right: 0em;">(</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1199">a</span><span class="MJXp-mo" id="MJXp-Span-1200" style="margin-left: 0em; margin-right: 0em;">)</span></span></span><script type="math/tex" id="MathJax-Element-157">F(a)</script> among all <span class="tex-font-style-it">good</span> arrays <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1201"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1202">a</span></span></span><script type="math/tex" id="MathJax-Element-158">a</script> is equal to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1203"><span class="MJXp-mn" id="MJXp-Span-1204">2</span></span></span><script type="math/tex" id="MathJax-Element-159">2</script>. The excellent arrays are: </p><ol><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1205"><span class="MJXp-mo" id="MJXp-Span-1206" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-1207">2</span><span class="MJXp-mo" id="MJXp-Span-1208" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1209">1</span><span class="MJXp-mo" id="MJXp-Span-1210" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1211">2</span><span class="MJXp-mo" id="MJXp-Span-1212" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-160">[2, 1, 2]</script>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1213"><span class="MJXp-mo" id="MJXp-Span-1214" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-1215">0</span><span class="MJXp-mo" id="MJXp-Span-1216" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1217">3</span><span class="MJXp-mo" id="MJXp-Span-1218" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1219">2</span><span class="MJXp-mo" id="MJXp-Span-1220" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-161">[0, 3, 2]</script>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1221"><span class="MJXp-mo" id="MJXp-Span-1222" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-1223">2</span><span class="MJXp-mo" id="MJXp-Span-1224" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1225">3</span><span class="MJXp-mo" id="MJXp-Span-1226" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1227">2</span><span class="MJXp-mo" id="MJXp-Span-1228" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-162">[2, 3, 2]</script>; </li><li> <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1229"><span class="MJXp-mo" id="MJXp-Span-1230" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-1231">3</span><span class="MJXp-mo" id="MJXp-Span-1232" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1233">0</span><span class="MJXp-mo" id="MJXp-Span-1234" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mn" id="MJXp-Span-1235">1</span><span class="MJXp-mo" id="MJXp-Span-1236" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-163">[3, 0, 1]</script>. </li></ol></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/15523");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script><script type="text/javascript">
$(document).ready(function () {
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_dd28f1f2ac52ae740b63aee0f0cf48df0cf99ac3">
<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;">×</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">E. Stringforces</div><div class="time-limit"><div class="property-title">time limit per test</div>3 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file input-standard"><div class="property-title">input</div>standard input</div><div class="output-file output-standard"><div class="property-title">output</div>standard output</div></div><div><p>You are given a string <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1237"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1238">s</span></span></span><script type="math/tex" id="MathJax-Element-164">s</script> of length <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1239"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1240">n</span></span></span><script type="math/tex" id="MathJax-Element-165">n</script>. Each character is either one of the first <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1241"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1242">k</span></span></span><script type="math/tex" id="MathJax-Element-166">k</script> lowercase Latin letters or a question mark.</p><p>You are asked to replace every question mark with one of the first <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1243"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1244">k</span></span></span><script type="math/tex" id="MathJax-Element-167">k</script> lowercase Latin letters in such a way that the following value is maximized.</p><p>Let <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1245"><span class="MJXp-msubsup" id="MJXp-Span-1246"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1247" style="margin-right: 0.05em;">f</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1248" style="vertical-align: -0.4em;">i</span></span></span></span><script type="math/tex" id="MathJax-Element-168">f_i</script> be the maximum length substring of string <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1249"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1250">s</span></span></span><script type="math/tex" id="MathJax-Element-169">s</script>, which consists entirely of the <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1251"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1252">i</span></span></span><script type="math/tex" id="MathJax-Element-170">i</script>-th Latin letter. A substring of a string is a contiguous subsequence of that string. If the <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1253"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1254">i</span></span></span><script type="math/tex" id="MathJax-Element-171">i</script>-th letter doesn't appear in a string, then <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1255"><span class="MJXp-msubsup" id="MJXp-Span-1256"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1257" style="margin-right: 0.05em;">f</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1258" style="vertical-align: -0.4em;">i</span></span></span></span><script type="math/tex" id="MathJax-Element-172">f_i</script> is equal to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1259"><span class="MJXp-mn" id="MJXp-Span-1260">0</span></span></span><script type="math/tex" id="MathJax-Element-173">0</script>.</p><p>The value of a string <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1261"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1262">s</span></span></span><script type="math/tex" id="MathJax-Element-174">s</script> is the minimum value among <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1263"><span class="MJXp-msubsup" id="MJXp-Span-1264"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1265" style="margin-right: 0.05em;">f</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1266" style="vertical-align: -0.4em;">i</span></span></span></span><script type="math/tex" id="MathJax-Element-175">f_i</script> for all <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1267"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1268">i</span></span></span><script type="math/tex" id="MathJax-Element-176">i</script> from <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1269"><span class="MJXp-mn" id="MJXp-Span-1270">1</span></span></span><script type="math/tex" id="MathJax-Element-177">1</script> to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1271"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1272">k</span></span></span><script type="math/tex" id="MathJax-Element-178">k</script>.</p><p>What is the maximum value the string can have?</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains two integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1273"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1274">n</span></span></span><script type="math/tex" id="MathJax-Element-179">n</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1275"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1276">k</span></span></span><script type="math/tex" id="MathJax-Element-180">k</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1277"><span class="MJXp-mn" id="MJXp-Span-1278">1</span><span class="MJXp-mo" id="MJXp-Span-1279" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1280">n</span><span class="MJXp-mo" id="MJXp-Span-1281" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-1282">2</span><span class="MJXp-mo" id="MJXp-Span-1283" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1284"><span class="MJXp-mn" id="MJXp-Span-1285" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1286" style="vertical-align: 0.5em;">5</span></span></span></span><script type="math/tex" id="MathJax-Element-181">1 \le n \le 2 \cdot 10^5</script>; <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1287"><span class="MJXp-mn" id="MJXp-Span-1288">1</span><span class="MJXp-mo" id="MJXp-Span-1289" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1290">k</span><span class="MJXp-mo" id="MJXp-Span-1291" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-1292">17</span></span></span><script type="math/tex" id="MathJax-Element-182">1 \le k \le 17</script>) — the length of the string and the number of first Latin letters used.</p><p>The second line contains a string <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1293"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1294">s</span></span></span><script type="math/tex" id="MathJax-Element-183">s</script>, consisting of <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1295"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1296">n</span></span></span><script type="math/tex" id="MathJax-Element-184">n</script> characters. Each character is either one of the first <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1297"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1298">k</span></span></span><script type="math/tex" id="MathJax-Element-185">k</script> lowercase Latin letters or a question mark.</p></div><div class="output-specification"><div class="section-title">Output</div><p>Print a single integer — the maximum value of the string after every question mark is replaced with one of the first <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1299"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1300">k</span></span></span><script type="math/tex" id="MathJax-Element-186">k</script> lowercase Latin letters.</p></div><div class="sample-tests"><div class="section-title">Examples</div><div class="sample-test"><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id0010278017840988773" id="id0036697665286741366" class="input-output-copier">Copy</div></div><pre id="id0010278017840988773">10 2
a??ab????b
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id0012852910736247602" id="id0023007378841179338" class="input-output-copier">Copy</div></div><pre id="id0012852910736247602">4
</pre></div><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id008360522336769922" id="id006567512747417346" class="input-output-copier">Copy</div></div><pre id="id008360522336769922">9 4
?????????
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id003666838310571824" id="id007490701155756769" class="input-output-copier">Copy</div></div><pre id="id003666838310571824">2
</pre></div><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id004808096454233227" id="id0029136739482146945" class="input-output-copier">Copy</div></div><pre id="id004808096454233227">2 3
??
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id0020261251752636744" id="id008323933857992657" class="input-output-copier">Copy</div></div><pre id="id0020261251752636744">0
</pre></div><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id006719335306102051" id="id007729559272990804" class="input-output-copier">Copy</div></div><pre id="id006719335306102051">15 3
??b?babbc??b?aa
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id0011681461962729234" id="id005737182969104904" class="input-output-copier">Copy</div></div><pre id="id0011681461962729234">3
</pre></div><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id0049861046124584174" id="id00027302885836351765" class="input-output-copier">Copy</div></div><pre id="id0049861046124584174">4 4
cabd
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id007620779631950757" id="id00005901348145114671" class="input-output-copier">Copy</div></div><pre id="id007620779631950757">1
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>In the first example the question marks can be replaced in the following way: "<span class="tex-font-style-tt">a<span class="tex-font-style-underline">aa</span>ab<span class="tex-font-style-underline">abbb</span>b</span>". <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1301"><span class="MJXp-msubsup" id="MJXp-Span-1302"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1303" style="margin-right: 0.05em;">f</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1304" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-1305" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-1306">4</span></span></span><script type="math/tex" id="MathJax-Element-187">f_1 = 4</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1307"><span class="MJXp-msubsup" id="MJXp-Span-1308"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1309" style="margin-right: 0.05em;">f</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1310" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1311" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-1312">4</span></span></span><script type="math/tex" id="MathJax-Element-188">f_2 = 4</script>, thus the answer is <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1313"><span class="MJXp-mn" id="MJXp-Span-1314">4</span></span></span><script type="math/tex" id="MathJax-Element-189">4</script>. Replacing it like this is also possible: "<span class="tex-font-style-tt">a<span class="tex-font-style-underline">aa</span>ab<span class="tex-font-style-underline">bbbb</span>b</span>". That way <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1315"><span class="MJXp-msubsup" id="MJXp-Span-1316"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1317" style="margin-right: 0.05em;">f</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1318" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-1319" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-1320">4</span></span></span><script type="math/tex" id="MathJax-Element-190">f_1 = 4</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1321"><span class="MJXp-msubsup" id="MJXp-Span-1322"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1323" style="margin-right: 0.05em;">f</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1324" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1325" style="margin-left: 0.333em; margin-right: 0.333em;">=</span><span class="MJXp-mn" id="MJXp-Span-1326">6</span></span></span><script type="math/tex" id="MathJax-Element-191">f_2 = 6</script>, however, the minimum of them is still <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1327"><span class="MJXp-mn" id="MJXp-Span-1328">4</span></span></span><script type="math/tex" id="MathJax-Element-192">4</script>.</p><p>In the second example one of the possible strings is "<span class="tex-font-style-tt"><span class="tex-font-style-underline">aabbccdda</span></span>".</p><p>In the third example at least one letter won't appear in the string, thus, the minimum of values <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1329"><span class="MJXp-msubsup" id="MJXp-Span-1330"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1331" style="margin-right: 0.05em;">f</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1332" style="vertical-align: -0.4em;">i</span></span></span></span><script type="math/tex" id="MathJax-Element-193">f_i</script> is always <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1333"><span class="MJXp-mn" id="MJXp-Span-1334">0</span></span></span><script type="math/tex" id="MathJax-Element-194">0</script>.</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/15523");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script><script type="text/javascript">
$(document).ready(function () {
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_0f51dc10ae570758a4dd7be335e4001d92c15179">
<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;">×</span>
</div>
<div class="ttypography"><div class="problem-statement"><div class="header"><div class="title">F. Jumping Around</div><div class="time-limit"><div class="property-title">time limit per test</div>5 seconds</div><div class="memory-limit"><div class="property-title">memory limit per test</div>256 megabytes</div><div class="input-file input-standard"><div class="property-title">input</div>standard input</div><div class="output-file output-standard"><div class="property-title">output</div>standard output</div></div><div><p>There is an infinite pond that can be represented with a number line. There are <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1335"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1336">n</span></span></span><script type="math/tex" id="MathJax-Element-195">n</script> rocks in the pond, numbered from <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1337"><span class="MJXp-mn" id="MJXp-Span-1338">1</span></span></span><script type="math/tex" id="MathJax-Element-196">1</script> to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1339"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1340">n</span></span></span><script type="math/tex" id="MathJax-Element-197">n</script>. The <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1341"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1342">i</span></span></span><script type="math/tex" id="MathJax-Element-198">i</script>-th rock is located at an integer coordinate <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1343"><span class="MJXp-msubsup" id="MJXp-Span-1344"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1345" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1346" style="vertical-align: -0.4em;">i</span></span></span></span><script type="math/tex" id="MathJax-Element-199">a_i</script>. The coordinates of the rocks are pairwise distinct. The rocks are numbered in the increasing order of the coordinate, so <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1347"><span class="MJXp-msubsup" id="MJXp-Span-1348"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1349" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1350" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-1351" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span><span class="MJXp-msubsup" id="MJXp-Span-1352"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1353" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1354" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1355" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span><span class="MJXp-mo" id="MJXp-Span-1356" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-1357" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span><span class="MJXp-msubsup" id="MJXp-Span-1358"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1359" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1360" style="vertical-align: -0.4em;">n</span></span></span></span><script type="math/tex" id="MathJax-Element-200">a_1 < a_2 < \dots < a_n</script>.</p><p>A robot frog sits on the rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1361"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1362">s</span></span></span><script type="math/tex" id="MathJax-Element-201">s</script>. The frog is programmable. It has a base jumping distance parameter <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1363"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1364">d</span></span></span><script type="math/tex" id="MathJax-Element-202">d</script>. There also is a setting for the jumping distance range. If the jumping distance range is set to some integer <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1365"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1366">k</span></span></span><script type="math/tex" id="MathJax-Element-203">k</script>, then the frog can jump from some rock to any rock at a distance from <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1367"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1368">d</span><span class="MJXp-mo" id="MJXp-Span-1369" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1370">k</span></span></span><script type="math/tex" id="MathJax-Element-204">d - k</script> to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1371"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1372">d</span><span class="MJXp-mo" id="MJXp-Span-1373" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1374">k</span></span></span><script type="math/tex" id="MathJax-Element-205">d + k</script> inclusive in any direction. The distance between two rocks is an absolute difference between their coordinates.</p><p>You are assigned a task to implement a feature for the frog. Given two integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1375"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1376">i</span></span></span><script type="math/tex" id="MathJax-Element-206">i</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1377"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1378">k</span></span></span><script type="math/tex" id="MathJax-Element-207">k</script> determine if the frog can reach a rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1379"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1380">i</span></span></span><script type="math/tex" id="MathJax-Element-208">i</script> from a rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1381"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1382">s</span></span></span><script type="math/tex" id="MathJax-Element-209">s</script> performing a sequence of jumps with the jumping distance range set to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1383"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1384">k</span></span></span><script type="math/tex" id="MathJax-Element-210">k</script>. The sequence can be arbitrarily long or empty.</p><p>You will be given <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1385"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1386">q</span></span></span><script type="math/tex" id="MathJax-Element-211">q</script> testcases for that feature, the <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1387"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1388">j</span></span></span><script type="math/tex" id="MathJax-Element-212">j</script>-th testcase consists of two integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1389"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1390">i</span></span></span><script type="math/tex" id="MathJax-Element-213">i</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1391"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1392">k</span></span></span><script type="math/tex" id="MathJax-Element-214">k</script>. Print "<span class="tex-font-style-tt">Yes</span>" if the <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1393"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1394">i</span></span></span><script type="math/tex" id="MathJax-Element-215">i</script>-th rock is reachable and "<span class="tex-font-style-tt">No</span>" otherwise.</p><p>You can output "<span class="tex-font-style-tt">YES</span>" and "<span class="tex-font-style-tt">NO</span>" in any case (for example, strings "<span class="tex-font-style-tt">yEs</span>", "<span class="tex-font-style-tt">yes</span>", "<span class="tex-font-style-tt">Yes</span>" and '<span class="tex-font-style-tt">YES</span>"' will be recognized as a positive answer).</p></div><div class="input-specification"><div class="section-title">Input</div><p>The first line contains four integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1395"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1396">n</span></span></span><script type="math/tex" id="MathJax-Element-216">n</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1397"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1398">q</span></span></span><script type="math/tex" id="MathJax-Element-217">q</script>, <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1399"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1400">s</span></span></span><script type="math/tex" id="MathJax-Element-218">s</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1401"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1402">d</span></span></span><script type="math/tex" id="MathJax-Element-219">d</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1403"><span class="MJXp-mn" id="MJXp-Span-1404">1</span><span class="MJXp-mo" id="MJXp-Span-1405" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1406">n</span><span class="MJXp-mo" id="MJXp-Span-1407" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1408">q</span><span class="MJXp-mo" id="MJXp-Span-1409" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mn" id="MJXp-Span-1410">2</span><span class="MJXp-mo" id="MJXp-Span-1411" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1412"><span class="MJXp-mn" id="MJXp-Span-1413" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1414" style="vertical-align: 0.5em;">5</span></span></span></span><script type="math/tex" id="MathJax-Element-220">1 \le n, q \le 2 \cdot 10^5</script>; <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1415"><span class="MJXp-mn" id="MJXp-Span-1416">1</span><span class="MJXp-mo" id="MJXp-Span-1417" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1418">s</span><span class="MJXp-mo" id="MJXp-Span-1419" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1420">n</span></span></span><script type="math/tex" id="MathJax-Element-221">1 \le s \le n</script>; <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1421"><span class="MJXp-mn" id="MJXp-Span-1422">1</span><span class="MJXp-mo" id="MJXp-Span-1423" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1424">d</span><span class="MJXp-mo" id="MJXp-Span-1425" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1426"><span class="MJXp-mn" id="MJXp-Span-1427" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1428" style="vertical-align: 0.5em;">6</span></span></span></span><script type="math/tex" id="MathJax-Element-222">1 \le d \le 10^6</script>) — the number of rocks, the number of testcases, the starting rock and the base jumping distance parameter.</p><p>The second line contains <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1429"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1430">n</span></span></span><script type="math/tex" id="MathJax-Element-223">n</script> integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1431"><span class="MJXp-msubsup" id="MJXp-Span-1432"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1433" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1434" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-1435" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-1436"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1437" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1438" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1439" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-mo" id="MJXp-Span-1440" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-1441" style="margin-left: 0em; margin-right: 0.222em;">,</span><span class="MJXp-msubsup" id="MJXp-Span-1442"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1443" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1444" style="vertical-align: -0.4em;">n</span></span></span></span><script type="math/tex" id="MathJax-Element-224">a_1, a_2, \dots, a_n</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1445"><span class="MJXp-mn" id="MJXp-Span-1446">1</span><span class="MJXp-mo" id="MJXp-Span-1447" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1448"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1449" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1450" style="vertical-align: -0.4em;">i</span></span><span class="MJXp-mo" id="MJXp-Span-1451" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1452"><span class="MJXp-mn" id="MJXp-Span-1453" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1454" style="vertical-align: 0.5em;">6</span></span></span></span><script type="math/tex" id="MathJax-Element-225">1 \le a_i \le 10^6</script>) — the coordinates of the rocks. The coordinates of the rocks are pairwise distinct. The rocks are numbered in the increasing order of distance from the land, so <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1455"><span class="MJXp-msubsup" id="MJXp-Span-1456"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1457" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1458" style="vertical-align: -0.4em;">1</span></span><span class="MJXp-mo" id="MJXp-Span-1459" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span><span class="MJXp-msubsup" id="MJXp-Span-1460"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1461" style="margin-right: 0.05em;">a</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1462" style="vertical-align: -0.4em;">2</span></span><span class="MJXp-mo" id="MJXp-Span-1463" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span><span class="MJXp-mo" id="MJXp-Span-1464" style="margin-left: 0em; margin-right: 0em;"></span><span class="MJXp-mo" id="MJXp-Span-1465" style="margin-left: 0.333em; margin-right: 0.333em;">&lt;</span><span class="MJXp-msubsup" id="MJXp-Span-1466"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1467" style="margin-right: 0.05em;">a</span><span class="MJXp-mi MJXp-italic MJXp-script" id="MJXp-Span-1468" style="vertical-align: -0.4em;">n</span></span></span></span><script type="math/tex" id="MathJax-Element-226">a_1 < a_2 < \dots < a_n</script>.</p><p>Each of the next <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1469"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1470">q</span></span></span><script type="math/tex" id="MathJax-Element-227">q</script> lines contains two integers <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1471"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1472">i</span></span></span><script type="math/tex" id="MathJax-Element-228">i</script> and <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1473"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1474">k</span></span></span><script type="math/tex" id="MathJax-Element-229">k</script> (<span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1475"><span class="MJXp-mn" id="MJXp-Span-1476">1</span><span class="MJXp-mo" id="MJXp-Span-1477" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1478">i</span><span class="MJXp-mo" id="MJXp-Span-1479" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1480">n</span></span></span><script type="math/tex" id="MathJax-Element-230">1 \le i \le n</script>; <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1481"><span class="MJXp-mn" id="MJXp-Span-1482">1</span><span class="MJXp-mo" id="MJXp-Span-1483" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1484">k</span><span class="MJXp-mo" id="MJXp-Span-1485" style="margin-left: 0.333em; margin-right: 0.333em;"></span><span class="MJXp-msubsup" id="MJXp-Span-1486"><span class="MJXp-mn" id="MJXp-Span-1487" style="margin-right: 0.05em;">10</span><span class="MJXp-mn MJXp-script" id="MJXp-Span-1488" style="vertical-align: 0.5em;">6</span></span></span></span><script type="math/tex" id="MathJax-Element-231">1 \le k \le 10^6</script>) — the parameters to the testcase.</p></div><div class="output-specification"><div class="section-title">Output</div><p>For each of the testcases print an answer. If there is a sequence of jumps from a rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1489"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1490">s</span></span></span><script type="math/tex" id="MathJax-Element-232">s</script> to a rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1491"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1492">i</span></span></span><script type="math/tex" id="MathJax-Element-233">i</script> with the jumping distance range set to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1493"><span class="MJXp-mi MJXp-italic" id="MJXp-Span-1494">k</span></span></span><script type="math/tex" id="MathJax-Element-234">k</script>, then print "<span class="tex-font-style-tt">Yes</span>". Otherwise, print "<span class="tex-font-style-tt">No</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 title="Copy" data-clipboard-target="#id009457268175320975" id="id0009232387181386903" class="input-output-copier">Copy</div></div><pre id="id009457268175320975">7 4 4 5
1 5 10 13 20 22 28
4 1
7 2
7 3
3 2
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id006703894185413486" id="id009325666133454178" class="input-output-copier">Copy</div></div><pre id="id006703894185413486">Yes
No
Yes
Yes
</pre></div><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id003030451618641431" id="id0012268541365229912" class="input-output-copier">Copy</div></div><pre id="id003030451618641431">10 8 6 11
1 2 4 7 8 9 11 13 19 20
2 13
5 8
8 1
6 15
1 15
2 7
7 6
8 9
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id00007163596982270759" id="id0004696282416006514" class="input-output-copier">Copy</div></div><pre id="id00007163596982270759">Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
</pre></div><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id004021868626461702" id="id006245115827740666" class="input-output-copier">Copy</div></div><pre id="id004021868626461702">6 9 6 6
1 2 4 9 18 19
2 17
1 18
5 4
2 11
5 17
6 8
4 3
3 3
6 6
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id0028814164650272367" id="id003382640439163931" class="input-output-copier">Copy</div></div><pre id="id0028814164650272367">Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
</pre></div><div class="input"><div class="title">Input<div title="Copy" data-clipboard-target="#id0036202103055617885" id="id007376883974196634" class="input-output-copier">Copy</div></div><pre id="id0036202103055617885">4 1 1 10
1 8 10 19
2 1
</pre></div><div class="output"><div class="title">Output<div title="Copy" data-clipboard-target="#id008954713496747658" id="id0012921296784619696" class="input-output-copier">Copy</div></div><pre id="id008954713496747658">Yes
</pre></div></div></div><div class="note"><div class="section-title">Note</div><p>Explanation of the first example:</p><p>In the first testcase the destination rock is the same as the starting rock, thus no jumps are required to reach it.</p><p>In the second testcase the frog can jump any distance in the range <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1495"><span class="MJXp-mo" id="MJXp-Span-1496" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-1497">5</span><span class="MJXp-mo" id="MJXp-Span-1498" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-1499">2</span><span class="MJXp-mo" id="MJXp-Span-1500" style="margin-left: 0em; margin-right: 0.222em;">;</span><span class="MJXp-mn" id="MJXp-Span-1501">5</span><span class="MJXp-mo" id="MJXp-Span-1502" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-1503">2</span><span class="MJXp-mo" id="MJXp-Span-1504" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-235">[5 - 2; 5 + 2]</script>. Thus, it can reach rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1505"><span class="MJXp-mn" id="MJXp-Span-1506">5</span></span></span><script type="math/tex" id="MathJax-Element-236">5</script> (by jumping <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1507"><span class="MJXp-mn" id="MJXp-Span-1508">7</span></span></span><script type="math/tex" id="MathJax-Element-237">7</script> to the right) and rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1509"><span class="MJXp-mn" id="MJXp-Span-1510">3</span></span></span><script type="math/tex" id="MathJax-Element-238">3</script> (by jumping <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1511"><span class="MJXp-mn" id="MJXp-Span-1512">3</span></span></span><script type="math/tex" id="MathJax-Element-239">3</script> to the left). From rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1513"><span class="MJXp-mn" id="MJXp-Span-1514">3</span></span></span><script type="math/tex" id="MathJax-Element-240">3</script> it can reach rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1515"><span class="MJXp-mn" id="MJXp-Span-1516">2</span></span></span><script type="math/tex" id="MathJax-Element-241">2</script> (by jumping <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1517"><span class="MJXp-mn" id="MJXp-Span-1518">5</span></span></span><script type="math/tex" id="MathJax-Element-242">5</script> to the left). From rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1519"><span class="MJXp-mn" id="MJXp-Span-1520">2</span></span></span><script type="math/tex" id="MathJax-Element-243">2</script> it can reach rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1521"><span class="MJXp-mn" id="MJXp-Span-1522">1</span></span></span><script type="math/tex" id="MathJax-Element-244">1</script> (by jumping <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1523"><span class="MJXp-mn" id="MJXp-Span-1524">4</span></span></span><script type="math/tex" id="MathJax-Element-245">4</script> to the left). However, there is no way to reach rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1525"><span class="MJXp-mn" id="MJXp-Span-1526">7</span></span></span><script type="math/tex" id="MathJax-Element-246">7</script>.</p><p>In the third testcase the frog can jump any distance in the range <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1527"><span class="MJXp-mo" id="MJXp-Span-1528" style="margin-left: 0em; margin-right: 0em;">[</span><span class="MJXp-mn" id="MJXp-Span-1529">5</span><span class="MJXp-mo" id="MJXp-Span-1530" style="margin-left: 0.267em; margin-right: 0.267em;"></span><span class="MJXp-mn" id="MJXp-Span-1531">3</span><span class="MJXp-mo" id="MJXp-Span-1532" style="margin-left: 0em; margin-right: 0.222em;">;</span><span class="MJXp-mn" id="MJXp-Span-1533">5</span><span class="MJXp-mo" id="MJXp-Span-1534" style="margin-left: 0.267em; margin-right: 0.267em;">+</span><span class="MJXp-mn" id="MJXp-Span-1535">3</span><span class="MJXp-mo" id="MJXp-Span-1536" style="margin-left: 0em; margin-right: 0em;">]</span></span></span><script type="math/tex" id="MathJax-Element-247">[5 - 3; 5 + 3]</script>. Thus, it can reach rock number <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1537"><span class="MJXp-mn" id="MJXp-Span-1538">7</span></span></span><script type="math/tex" id="MathJax-Element-248">7</script> by jumping to rock <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1539"><span class="MJXp-mn" id="MJXp-Span-1540">5</span></span></span><script type="math/tex" id="MathJax-Element-249">5</script> first and to <span class="MathJax_Preview" style="color: inherit;"><span class="MJXp-math" id="MJXp-Span-1541"><span class="MJXp-mn" id="MJXp-Span-1542">7</span></span></span><script type="math/tex" id="MathJax-Element-250">7</script> afterwards.</p><p>The fourth testcase is shown in the explanation for the second testcase.</p></div></div><p> </p></div>
</div>
<script>
$(function () {
Codeforces.addMathJaxListener(function () {
let $problem = $("div[problemindex=F]");
let uuid = $problem.attr("data-uuid");
let statementText = convertStatementToText($problem.find(".ttypography").get(0));
let previousStatementText = Codeforces.getFromStorage(uuid);
if (previousStatementText) {
if (previousStatementText !== statementText) {
$problem.find(".diff-notifier").show();
$problem.find(".diff-notifier-close").click(function() {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
$problem.find(".diff-notifier").hide();
});
$problem.find("a.view-changes").click(function() {
$.post("/data/diff", {action: "getDiff", a: previousStatementText, b: statementText}, function (result) {
if (result["success"] === "true") {
Codeforces.facebox(".diff-popup", "//codeforces.org/s/15523");
$("#facebox .diff-popup").html(result["diff"]);
}
}, "json");
});
}
} else {
Codeforces.putToStorageTtl(uuid, statementText, 6 * 60 * 60);
}
});
});
</script><script type="text/javascript">
$(document).ready(function () {
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-2025 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-15523.js')
.then(function (registration) {
console.log('Service worker registered: ', registration);
})
.catch(function (error) {
console.log('Registration failed: ', error);
});
}
</script><script>(function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'98a1d6da1e7a43f2',t:'MTc1OTcxODkwMA=='};var a=document.createElement('script');a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script><iframe height="1" width="1" style="position: absolute; top: 0px; left: 0px; border: medium; visibility: hidden;"></iframe><script defer src="https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon='{"version":"2024.11.0","token":"316c29dfa3804effb5a91c52a59b5bd0","server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}' crossorigin="anonymous"></script><div id="datepick-div" style="display: none;"></div><div id="cboxOverlay" style="display: none;"></div><div id="colorbox" class="" style="display: none; padding-bottom: 42px; padding-right: 42px;"><div id="cboxWrapper"><div><div id="cboxTopLeft" style="float: left;"></div><div id="cboxTopCenter" style="float: left;"></div><div id="cboxTopRight" style="float: left;"></div></div><div style="clear: left;"><div id="cboxMiddleLeft" style="float: left;"></div><div id="cboxContent" style="float: left;"><div id="cboxLoadedContent" style="width: 0px; height: 0px; overflow: hidden; float: left;"></div><div id="cboxLoadingOverlay" style="float: left;"></div><div id="cboxLoadingGraphic" style="float: left;"></div><div id="cboxTitle" style="float: left;"></div><div id="cboxCurrent" style="float: left;"></div><div id="cboxNext" style="float: left;"></div><div id="cboxPrevious" style="float: left;"></div><div id="cboxSlideshow" style="float: left;"></div><div id="cboxClose" style="float: left;"></div></div><div id="cboxMiddleRight" style="float: left;"></div></div><div style="clear: left;"><div id="cboxBottomLeft" style="float: left;"></div><div id="cboxBottomCenter" style="float: left;"></div><div id="cboxBottomRight" style="float: left;"></div></div></div><div style="position: absolute; width: 9999px; visibility: hidden; display: none;"></div></div><div style="position: absolute; width: 0px; height: 0px; overflow: hidden; padding: 0px; border: 0px; margin: 0px;"><div id="MathJax_Font_Test" style="position: absolute; visibility: hidden; top: 0px; left: 0px; width: auto; min-width: 0px; max-width: none; padding: 0px; border: 0px; margin: 0px; white-space: nowrap; text-align: left; text-indent: 0px; text-transform: none; line-height: normal; letter-spacing: normal; word-spacing: normal; font-size: 40px; font-weight: normal; font-style: normal; font-size-adjust: none; font-family: STIXSizeOneSym, Arial;"></div></div></body></html>