Problem - 1985C - Codeforces (2024)

Enter | Register


  • Home
  • Top
  • Catalog
  • Contests
  • Gym
  • Problemset
  • Groups
  • Rating
  • Edu
  • API
  • Calendar
  • Help


Codeforces Round 952 (Div. 4)
Finished

→ Virtual participation

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

→ Problem tags

greedy

No tag edit access

→ Contest materials

  • Announcement (en)Problem - 1985C - Codeforces (4)
  • Tutorial (en)Problem - 1985C - Codeforces (5)
  • Problems
  • Submit
  • Status
  • Standings
  • Custom test

C. Good Prefixes

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Alex thinks some array is good if there exists some element that can be represented as the sum of all other elements (the sum of all other elements is $$$0$$$ if there are no other elements). For example, the array $$$[1,6,3,2]$$$ is good since $$$1+3+2=6$$$. Furthermore, the array $$$[0]$$$ is also good. However, the arrays $$$[1,2,3,4]$$$ and $$$[1]$$$ are not good.

Alex has an array $$$a_1,a_2,\ldots,a_n$$$. Help him count the number of good non-empty prefixes of the array $$$a$$$. In other words, count the number of integers $$$i$$$ ($$$1 \le i \le n$$$) such that the length $$$i$$$ prefix (i.e. $$$a_1,a_2,\ldots,a_i$$$) is good.

Input

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array.

The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the array.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, output a single integer — the number of good non-empty prefixes of the array $$$a$$$.

Example

Input

7

1

1

1

4

1 1 2 0

5

0 1 2 1 4

7

1 1 0 3 5 2 12

7

1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 294967296

10

0 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 589934592

Output

1033412

Note

In the fourth test case, the array has five prefixes:

  • prefix $$$[0]$$$ is a good array, as mentioned in the statement;
  • prefix $$$[0, 1]$$$ is not a good array, since $$$0 \ne 1$$$;
  • prefix $$$[0, 1, 2]$$$ is not a good array, since $$$0 \ne 1 + 2$$$, $$$1 \ne 0 + 2$$$ and $$$2 \ne 0 + 1$$$;
  • prefix $$$[0, 1, 2, 1]$$$ is a good array, since $$$2 = 0 + 1 + 1$$$;
  • prefix $$$[0, 1, 2, 1, 4]$$$ is a good array, since $$$4 = 0 + 1 + 2 + 1$$$.

As you can see, three of them are good, so the answer is $$$3$$$.

"); $(this).append($copy); const clipboard = new Clipboard('#' + cpyId, { text: function (trigger) { const pre = document.querySelector('#' + preId); const lines = pre.querySelectorAll(".test-example-line"); return Codeforces.filterClipboardText(pre.innerText, lines.length); } }); const isInput = $(this).parent().hasClass("input"); clipboard.on('success', function (e) { if (isInput) { Codeforces.showMessage("The example input has been copied into the clipboard"); } else { Codeforces.showMessage("The example output has been copied into the clipboard"); } e.clearSelection(); }); }); $(".test-form-item input").change(function () { addPendingSubmissionMessage($($(this).closest("form")), "You changed the answer, do not forget to submit it if you want to save the changes"); const index = $(this).closest(".problemindexholder").attr("problemindex"); let test = ""; $(this).closest("form input").each(function () { const test_ = $(this).attr("name"); if (test_ && test_.substring(0, 4) === "test") { test = test_; } }); if (index.length > 0 && test.length > 0) { const indexTest = index + "::" + test; window.changedTests.add(indexTest); } }); $(window).on('beforeunload', function () { if (window.changedTests.size > 0) { return 'Dialog text here'; } }); autosize($('.test-explanation textarea')); $(".test-example-line").hover(function() { $(this).attr("class").split(" ").forEach((clazz) => { if (clazz.substr(0, "test-example-line-".length) === "test-example-line-") { let end = clazz.substr("test-example-line-".length); if (end !== "even" && end !== "odd" && end !== "0") { let top = 1E20; let left = 1E20; let problem = $(this).closest(".problemindexholder"); $(this).closest(".input").find("." + clazz).css("background-color", "#FFFDE7").each(function() { top = Math.min(top, $(this).offset().top); left = Math.min(left, $(this).offset().left); }); let testCaseMarker = problem.find(".testCaseMarker_" + end); if (testCaseMarker.length === 0) { const html = "

"; problem.append($(html)); testCaseMarker = problem.find(".testCaseMarker_" + end); } if (testCaseMarker) { testCaseMarker.show() .offset({top, left: left - 20}) .text(end); } } } }); }, function() { $(this).attr("class").split(" ").forEach((clazz) => { if (clazz.substr(0, "test-example-line-".length) === "test-example-line-") { let end = clazz.substr("test-example-line-".length); if (end !== "even" && end !== "odd" && end !== "0") { $("." + clazz).css("background-color", ""); $(this).closest(".problemindexholder").find(".testCaseMarker_" + end).hide(); } } }); }); });

Problem - 1985C - Codeforces (2024)

References

Top Articles
Get 'Verified' with UM-Dearborn's Community Read
14 Vegetables That Thrive Grown in Poor Soils
Lowe's Garden Fence Roll
Dragon Age Inquisition War Table Operations and Missions Guide
Cappacuolo Pronunciation
Zabor Funeral Home Inc
Sportsman Warehouse Cda
Craigslist - Pets for Sale or Adoption in Zeeland, MI
Chuckwagon racing 101: why it's OK to ask what a wheeler is | CBC News
Skip The Games Norfolk Virginia
What Is A Good Estimate For 380 Of 60
Clarksburg Wv Craigslist Personals
Tracking Your Shipments with Maher Terminal
Walmart Double Point Days 2022
Procore Championship 2024 - PGA TOUR Golf Leaderboard | ESPN
Letter F Logos - 178+ Best Letter F Logo Ideas. Free Letter F Logo Maker. | 99designs
Daily Voice Tarrytown
Roster Resource Orioles
Nick Pulos Height, Age, Net Worth, Girlfriend, Stunt Actor
Cta Bus Tracker 77
Gentle Dental Northpointe
Red8 Data Entry Job
A Cup of Cozy – Podcast
Jcp Meevo Com
BJ 이름 찾는다 꼭 도와줘라 | 짤방 | 일베저장소
Temu Seat Covers
Anesthesia Simstat Answers
Mississippi Craigslist
Greyson Alexander Thorn
How Much Is An Alignment At Costco
Tamil Play.com
Texas Baseball Officially Releases 2023 Schedule
Metro 72 Hour Extension 2022
How Much Is Mink V3
Retire Early Wsbtv.com Free Book
Shih Tzu dogs for sale in Ireland
Trivago Myrtle Beach Hotels
D-Day: Learn about the D-Day Invasion
Gvod 6014
11301 Lakeline Blvd Parkline Plaza Ctr Ste 150
Below Five Store Near Me
Nina Flowers
Inducement Small Bribe
Myrtle Beach Craigs List
Craigslist Antique
Oklahoma City Farm & Garden Craigslist
The Cutest Photos of Enrique Iglesias and Anna Kournikova with Their Three Kids
News & Events | Pi Recordings
Sleep Outfitters Springhurst
Aaca Not Mine
Koniec veľkorysých plánov. Prestížna LEAF Academy mení adresu, masívny kampus nepostaví
Cataz.net Android Movies Apk
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 5942

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.