output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s743185150
Wrong Answer
p03227
Input is given from Standard Input in the following format: S
0
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s905631602
Accepted
p03227
Input is given from Standard Input in the following format: S
#!/usr/bin/env python3 import sys from typing import ( Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union, ) # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import Fraction # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10) def main(): mod = 1000000007 # 10^9+7 inf = float("inf") # sys.float_info.max = 1.79e+308 # inf = 2 ** 63 - 1 # (for fast JIT compile in PyPy) 9.22e+18 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def isp(): return input().split() def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x) - 1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x) - 1, input().split())) def li(): return list(input()) s = input() n = len(s) print(s) if n == 2 else print(s[::-1]) if __name__ == "__main__": main()
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s936783774
Accepted
p03227
Input is given from Standard Input in the following format: S
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import ( accumulate, permutations, combinations, product, groupby, combinations_with_replacement, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 S = input() print(S if len(S) == 2 else S[::-1])
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s503853092
Runtime Error
p03227
Input is given from Standard Input in the following format: S
# coding:utf-8 import copy N = int(input()) A_list = [] for i in range(N): A_list.append(int(input())) def calculate_x(list): len_list = len(list) sum = 0 for i in range(len_list - 1): sum = sum + abs(list[i] - list[i + 1]) return sum A_list = sorted(A_list) if N % 2 == 0: # even answer_list = [] A_min_list = A_list[: int(N / 2) - 1] A_max_list = A_list[-int(N / 2) + 1 :] for max, min in zip(A_max_list, A_min_list): answer_list.append(max) answer_list.append(min) answer_list.append(A_list[int(N / 2)]) # min of max_list answer_list.insert(0, A_list[int(N / 2) - 1]) # max of min_list tmp = calculate_x(answer_list) print(tmp) else: # odd answer_list = [] A_min_list = A_list[: int((N - 1) / 2) - 1] # 0,1 A_max_list = A_list[-int((N - 1) / 2) + 1 :] # 5,6 x1 = A_list[int((N - 1) / 2) - 1] # 2 x2 = A_list[int((N - 1) / 2)] # 3 x3 = A_list[int((N - 1) / 2) + 1] # 4 for max, min in zip(A_max_list, A_min_list): answer_list.append(max) answer_list.append(min) answer_list2 = copy.deepcopy(answer_list) max = 0 answer_list2.append(x1) answer_list2.insert(0, x2) answer_list2.insert(0, x3) tmp = calculate_x(answer_list2) if tmp > max: max = tmp answer_list2 = copy.deepcopy(answer_list) answer_list2.append(x1) answer_list2.insert(0, x3) answer_list2.insert(0, x2) tmp = calculate_x(answer_list2) if tmp > max: max = tmp answer_list2 = copy.deepcopy(answer_list) answer_list2.append(x2) answer_list2.insert(0, x1) answer_list2.insert(0, x3) tmp = calculate_x(answer_list2) if tmp > max: max = tmp answer_list2 = copy.deepcopy(answer_list) answer_list2.append(x2) answer_list2.insert(0, x3) answer_list2.insert(0, x1) tmp = calculate_x(answer_list2) if tmp > max: max = tmp answer_list2 = copy.deepcopy(answer_list) answer_list2.append(x3) answer_list2.insert(0, x1) answer_list2.insert(0, x2) tmp = calculate_x(answer_list2) if tmp > max: max = tmp answer_list2 = copy.deepcopy(answer_list) answer_list2.append(x3) answer_list2.insert(0, x2) answer_list2.insert(0, x1) tmp = calculate_x(answer_list2) if tmp > max: max = tmp answer_list3 = [] A_min_list = A_list[: int((N - 1) / 2) - 1] # 0,1 A_max_list = A_list[-int((N - 1) / 2) + 1 :] # 5,6 x1 = A_list[int((N - 1) / 2) - 1] # 2 x2 = A_list[int((N - 1) / 2)] # 3 x3 = A_list[int((N - 1) / 2) + 1] # 4 for max, min in zip(A_max_list, A_min_list): answer_list3.append(min) answer_list3.append(max) answer_list4 = copy.deepcopy(answer_list3) answer_list4.append(x1) answer_list4.insert(0, x2) answer_list4.insert(0, x3) tmp = calculate_x(answer_list4) if tmp > max: max = tmp answer_list4 = copy.deepcopy(answer_list3) answer_list4.append(x1) answer_list4.insert(0, x3) answer_list4.insert(0, x2) tmp = calculate_x(answer_list4) if tmp > max: max = tmp answer_list4 = copy.deepcopy(answer_list3) answer_list4.append(x2) answer_list4.insert(0, x1) answer_list4.insert(0, x3) tmp = calculate_x(answer_list4) if tmp > max: max = tmp answer_list4 = copy.deepcopy(answer_list3) answer_list4.append(x2) answer_list4.insert(0, x3) answer_list4.insert(0, x1) tmp = calculate_x(answer_list4) if tmp > max: max = tmp answer_list4 = copy.deepcopy(answer_list3) answer_list4.append(x3) answer_list4.insert(0, x1) answer_list4.insert(0, x2) tmp = calculate_x(answer_list4) if tmp > max: max = tmp answer_list4 = copy.deepcopy(answer_list3) answer_list4.append(x3) answer_list4.insert(0, x2) answer_list4.insert(0, x1) tmp = calculate_x(answer_list4) if tmp > max: max = tmp print(max)
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s535876403
Runtime Error
p03227
Input is given from Standard Input in the following format: S
a, b, k = map(int, input().split()) for i in range(1, k + 1): if (i % 2) == 1: if (a % 2) == 1: a -= 1 a /= 2 b += a else: a /= 2 b += a else: if (b % 2) == 1: b -= 1 b /= 2 a += b else: b /= 2 a += b print(str(int(a)) + " " + str(int(b)))
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s032391719
Runtime Error
p03227
Input is given from Standard Input in the following format: S
N = int(input()) k = 1 n = 0 while n < N: n += k k += 1 if n != N: print("No") exit() print("Yes") print(k) ans = [[] for _ in range(k)] v = 1 for i in range(k - 1): for j in range(i + 1, k): ans[i].append(v) ans[j].append(v) v += 1 for row in ans: print(len(row), *row)
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s029388517
Runtime Error
p03227
Input is given from Standard Input in the following format: S
args = str(input()) args = args.split(" ") a = int(args[0]) b = int(args[1]) k = int(args[2]) turn = 0 for i in range(k): if turn == 0: if a > 0: if a % 2 == 1: a = a - 1 if a > 0: g = a / 2 a = a - g b = b + g turn = 1 elif turn == 1: if b > 0: if b % 2 == 1: b = b - 1 if b > 0: g = b / 2 b = b - g a = a + g turn = 0 print(int(a), int(b))
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s912955033
Runtime Error
p03227
Input is given from Standard Input in the following format: S
a=input() if len(a)==2: print(a) else: print(a[::-1])
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s376892767
Runtime Error
p03227
Input is given from Standard Input in the following format: S
n = input() if len(n) == 2: print(n) else if len(n) == 3: print(n[::-1])
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s547709719
Runtime Error
p03227
Input is given from Standard Input in the following format: S
s = input() if len(s) <= 2: print(s) else : for i in reversed(s) print(i)
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s416523544
Runtime Error
p03227
Input is given from Standard Input in the following format: S
S = input() if len(S) == 2: print(type(S) elese: S = S[::-1] print(type(S)
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s489530977
Runtime Error
p03227
Input is given from Standard Input in the following format: S
N=(input()) if len(N)==3: ... N = N[::-1] ... print(N) ... elif len(N)==2: ... print(N)
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s450515311
Accepted
p03227
Input is given from Standard Input in the following format: S
print((input() * 5)[2::5])
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s576703698
Runtime Error
p03227
Input is given from Standard Input in the following format: S
s = input() print(s if len(s)==2 else s[::-1]
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s206475836
Accepted
p03227
Input is given from Standard Input in the following format: S
answer = input().strip() if len(answer) == 2: print(answer) else: print(answer[2] + answer[1] + answer[0])
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s167684159
Runtime Error
p03227
Input is given from Standard Input in the following format: S
A, B, K = map(int, input().split()) for i in range(K): if i % 2 == 0: B = B + A/2 A = A/2 else: A = A + B/2 B = B/2 print ('{} {}'.format(A,B))
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s866979626
Runtime Error
p03227
Input is given from Standard Input in the following format: S
S = input() if len(S) == 2: print (S) else: new_str_list = list(reversed(S)) #print(new_str_list) print (new_str_list.join(''))
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s247146285
Runtime Error
p03227
Input is given from Standard Input in the following format: S
a = [] a1, a2, c = input().split() a.append(int(a1)) a.append(int(a2)) c = int(c) cur = 0 for i in range(c): a[1 - cur] += a[cur] // 2 a[cur] //= 2 cur = 1 - cur print(a[0], a[1])
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s953664355
Runtime Error
p03227
Input is given from Standard Input in the following format: S
A, B, K = map(int, input().split()) for k in range(K): if A % 2 != 0 and A < 1: A -= 1 B += round(A/2) A -= round(A/2) if B % 2 != 0 and if B < 1: B -= 1 A += round(B/2) B -= round(B/2) print(A, B)
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s757156554
Runtime Error
p03227
Input is given from Standard Input in the following format: S
= input() if len(S) == 2: print(S) elese: S = S[::-1] print(S)
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s705780232
Runtime Error
p03227
Input is given from Standard Input in the following format: S
n = int(input()) a = [0] * n for i in range(0, n): a[i] = int(input()) a.sort() c = 0 if len(a) == 2: print(abs(a[0] - a[1])) if len(a) == 3: diff = abs(a[0] - a[1]) + abs(a[1] - a[2]) diff = max(abs(a[0] - a[2]) + abs(a[1] - a[2]), diff) diff = max(abs(a[0] - a[2]) + abs(a[0] - a[1]), diff) print(diff) mini = 0 maxi = len(a) - 1 if len(a) > 3: (l, r) = (a[maxi], a[maxi - 1]) maxi -= 2 diff = abs(a[0] - l) + abs(a[0] - r) mini += 1 for i in range(0, n - 3): if i % 2 == 0: if c < 2: diff += abs(a[mini] - l) l = a[mini] mini += 1 else: diff += abs(a[maxi] - l) l = a[maxi] maxi -= 1 else: if c < 2: diff += abs(a[mini] - r) r = a[mini] mini += 1 else: diff += abs(a[maxi] - r) r = a[maxi] maxi -= 1 if c < 3: c += 1 else: c = 0 maxi = len(a) - 1 mini = 0 (l, r) = (a[mini], a[mini + 1]) mini += 2 diff2 = abs(a[-1] - l) + abs(a[-1] - r) maxi -= 1 for i in range(0, n - 3): if i % 2 == 0: if c > 1: diff2 += abs(a[mini] - l) l = a[mini] mini += 1 else: diff2 += abs(a[maxi] - l) l = a[maxi] maxi -= 1 else: if c > 1: diff2 += abs(a[mini] - r) r = a[mini] mini += 1 else: diff2 += abs(a[maxi] - r) r = a[maxi] maxi -= 1 if c < 3: c += 1 else: c = 0 print(max(diff, diff2))
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s307607770
Runtime Error
p03227
Input is given from Standard Input in the following format: S
a = [] N = int(input()) for i in range(N): a.append(int(input())) a = sorted(a) if len(a) == 2: print(abs(a[0] - a[1])) elif len(a) == 3: print(max(a[2] - a[1] + a[2] - a[0], a[1] - a[0] + a[2] - a[0])) else: # ---------------------------------------------------------------------- def append2big(id1, id2): global bBeg global bEnd global s if a[id1] - bBeg + a[id2] - bEnd < a[id2] - bBeg + a[id1] - bEnd: id1, id2 = id2, id1 s += a[id1] - bBeg + a[id2] - bEnd bBeg = a[id1] bEnd = a[id2] def append2small(id1, id2): global bBeg global bEnd global s if bBeg - a[id1] + bEnd - a[id2] < bBeg - a[id2] + bEnd - a[id1]: id1, id2 = id2, id1 s += bBeg - a[id1] + bEnd - a[id2] bBeg = a[id1] bEnd = a[id2] def append1small(id): global bBeg global bEnd global s if bBeg - a[id] > bEnd - a[id]: s += bBeg - a[id] bBeg = a[id] else: s += bEnd - a[id] bEnd = a[id] def append1big(id): global bBeg global bEnd global s if a[id] - bBeg > a[id] - bEnd: s += a[id] - bBeg bBeg = a[id] else: s += a[id] - bEnd bEnd = a[id] # ---------------------------------------------------------------------- s = a[N - 2] - a[0] + a[N - 1] - a[0] bBeg = a[N - 2] bEnd = a[N - 1] l = 0 r = N - 2 cur = 0 while l < r - 1: if cur == 0: if l + 2 < r: append2small(l + 1, l + 2) l += 2 elif l + 1 < r: append1small(l + 1) l += 1 cur = 1 - cur else: if r - 2 > l: append2big(r - 1, r - 2) r -= 2 elif r - 1 > l: append1big(r - 1) r -= 1 cur = 1 - cur r1 = s # -----case 2------ s = a[N - 1] - a[0] + a[N - 1] - a[1] bBeg = a[0] bEnd = a[1] l = 1 r = N - 1 cur = 1 while l < r - 1: if cur == 0: if l + 2 < r: append2small(l + 1, l + 2) l += 2 elif l + 1 < r: append1small(l + 1) l += 1 cur = 1 - cur else: if r - 2 > l: append2big(r - 1, r - 2) r -= 2 elif r - 1 > l: append1big(r - 1) r -= 1 cur = 1 - cur r2 = s print(max(r1, r2))
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s032523959
Runtime Error
p03227
Input is given from Standard Input in the following format: S
N = input() N = int(N) L = [] def diff(L): total = 0 for i in range(len(L) - 1): total += abs(L[i + 1] - L[i]) return total for i in range(N): A = input() L.append(int(A)) L.sort() if len(L) > 3: length = len(L) SL = L[: int(length / 2)] LL = L[int(length / 2) :] result = [] result.append(SL[-1]) SL.pop(-1) last = LL[0] LL.pop(0) while True: try: result.append(LL[-1]) LL.pop(-1) result.append(SL[0]) SL.pop(0) except: break result.append(last) print(diff(result)) elif len(L) == 3: all = [ diff([L[0], L[1], L[2]]), diff([L[0], L[2], L[1]]), diff([L[1], L[0], L[2]]), diff([L[1], L[2], L[0]]), diff([L[2], L[0], L[1]]), diff([L[2], L[1], L[0]]), ] print(max(all)) elif len(L) == 2: print(abs(L[0] - L[1]))
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s177591050
Runtime Error
p03227
Input is given from Standard Input in the following format: S
S = input() if len(S) == 2:
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s668407992
Runtime Error
p03227
Input is given from Standard Input in the following format: S
str=input() x=len(str) if x=2: print(str) else: print(str[::-1])
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
If the length of S is 2, print S as is; if the length is 3, print S after reversing it. * * *
s667337845
Runtime Error
p03227
Input is given from Standard Input in the following format: S
N = input() if len(N) == 3: print(::-1) else: print(N)
Statement You are given a string S of length 2 or 3 consisting of lowercase English letters. If the length of the string is 2, print it as is; if the length is 3, print the string after reversing it.
[{"input": "abc", "output": "cba\n \n\nAs the length of S is 3, we print it after reversing it.\n\n* * *"}, {"input": "ac", "output": "ac\n \n\nAs the length of S is 2, we print it as is."}]
Print 2 lines. * In the first line, print the number of elements of a best representation of w. * In the second line, print the number of the best representations of w, modulo 1000000007. * * *
s112276125
Wrong Answer
p04018
The input is given from Standard Input in the following format: w
import sys readline = sys.stdin.readline class Rollinhash: def __init__(self, S): N = len(S) self.mod = 10**9 + 9 self.base = 2009 self.has = [0] * (N + 1) self.power = [1] * (N + 1) for i in range(N): s = S[i] self.has[i + 1] = (self.has[i] * self.base + s) % self.mod self.power[i + 1] = self.power[i] * self.base % self.mod def rh(self, i, j): return (self.has[j] - self.has[i] * self.power[j - i]) % self.mod MOD = 10**9 + 7 S = list(map(ord, readline().strip())) N = len(S) if len(set(S)) == 1: print(N) print(1) else: Rs = Rollinhash(S) tabler = [True] * (N + 1) for d in range(2, 1 + N // 2): r = Rs.rh(0, d) for i in range(1, N // d): if r != Rs.rh(i * d, (i + 1) * d): break tabler[(i + 1) * d] = False tablel = [True] * (N + 1) for d in range(2, 1 + N // 2): r = Rs.rh(N - d, N) for i in range(1, N // d): if r != Rs.rh(N - (i + 1) * d, N - i * d): break tablel[N - (i + 1) * d] = False if tabler[N]: print(1) print(1) else: print(2) ans = 0 for i in range(N + 1): if tabler[i] and tablel[i]: ans += 1 print(ans)
Statement Let x be a string of length at least 1. We will call x a _good_ string, if for any string y and any integer k (k \geq 2), the string obtained by concatenating k copies of y is different from x. For example, `a`, `bbc` and `cdcdc` are good strings, while `aa`, `bbbb` and `cdcdcd` are not. Let w be a string of length at least 1. For a sequence F=(\,f_1,\,f_2,\,...,\,f_m) consisting of m elements, we will call F a _good representation_ of w, if the following conditions are both satisfied: * For any i \, (1 \leq i \leq m), f_i is a good string. * The string obtained by concatenating f_1,\,f_2,\,...,\,f_m in this order, is w. For example, when w=`aabb`, there are five good representations of w: * (`aabb`) * (`a`,`abb`) * (`aab`,`b`) * (`a`,`ab`,`b`) * (`a`,`a`,`b`,`b`) Among the good representations of w, the ones with the smallest number of elements are called the _best representations_ of w. For example, there are only one best representation of w=`aabb`: (`aabb`). You are given a string w. Find the following: * the number of elements of a best representation of w * the number of the best representations of w, modulo 1000000007 \, (=10^9+7) (It is guaranteed that a good representation of w always exists.)
[{"input": "aab", "output": "1\n 1\n \n\n* * *"}, {"input": "bcbc", "output": "2\n 3\n \n\n * In this case, there are 3 best representations of 2 elements:\n * (`b`,`cbc`)\n * (`bc`,`bc`)\n * (`bcb`,`c`)\n\n* * *"}, {"input": "ddd", "output": "3\n 1"}]
Print the number of different sequences that can result after M operations, modulo 998244353. * * *
s093123163
Wrong Answer
p02965
Input is given from Standard Input in the following format: N M
mod = 998244353 def cmb(n, r): if r > n - r: r = n - r if r < 2: return n**r numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2, r + 1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p - 1, r, p): numerator[k - offset] //= pivot denominator[k] //= pivot result = 1 for k in range(r): if numerator[k] > 1: result = (result * numerator[k]) % mod return result n, m = map(int, input().split()) print((cmb(3 * m + n - 1, n - 1) - n * cmb(m + n - 2, n - 1)) % mod)
Statement We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation **exactly** M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353.
[{"input": "2 2", "output": "3\n \n\nAfter two operations, there are three possible outcomes:\n\n * x=(2,4)\n * x=(3,3)\n * x=(4,2)\n\nFor example, x=(3,3) can result after the following sequence of operations:\n\n * First, choose i=0,j=1, changing x from (0,0) to (2,1).\n * Second, choose i=1,j=0, changing x from (2,1) to (3,3).\n\n* * *"}, {"input": "3 2", "output": "19\n \n\n* * *"}, {"input": "10 10", "output": "211428932\n \n\n* * *"}, {"input": "100000 50000", "output": "3463133"}]
Print the number of different sequences that can result after M operations, modulo 998244353. * * *
s962393757
Accepted
p02965
Input is given from Standard Input in the following format: N M
class Combination: """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う""" def __init__(self, n, MOD): self.fact = [1] for i in range(1, n + 1): self.fact.append(self.fact[-1] * i % MOD) self.inv_fact = [0] * (n + 1) self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD) for i in reversed(range(n)): self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD self.MOD = MOD def inverse(self, k): """kの逆元を求める O(1)""" return (self.inv_fact[k] * self.fact[k - 1]) % self.MOD def factorial(self, k): """k!を求める O(1)""" return self.fact[k] def inverse_factorial(self, k): """k!の逆元を求める O(1)""" return self.inv_fact[k] def permutation(self, k, r): """kPrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r]) % self.MOD def combination(self, k, r): """kCrを求める O(1)""" if k < r: return 0 return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD n, m = map(int, input().split()) MOD = 998244353 comb = Combination(10**7, MOD) ans = 0 for odd_cnt in range(m + 1): if odd_cnt > n: continue if (3 * m - odd_cnt) % 2 == 1: continue ptn = 1 box = n odd_ball = odd_cnt ptn *= comb.combination(box, odd_ball) even_pair_ball = (3 * m - odd_cnt) // 2 ptn *= comb.combination(even_pair_ball + box - 1, even_pair_ball) ans += ptn ptn %= MOD for i in range(1, m + 1): ball = m - i box = n - 1 ans -= comb.combination(ball + box - 1, ball) * n ans %= MOD print(ans)
Statement We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation **exactly** M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353.
[{"input": "2 2", "output": "3\n \n\nAfter two operations, there are three possible outcomes:\n\n * x=(2,4)\n * x=(3,3)\n * x=(4,2)\n\nFor example, x=(3,3) can result after the following sequence of operations:\n\n * First, choose i=0,j=1, changing x from (0,0) to (2,1).\n * Second, choose i=1,j=0, changing x from (2,1) to (3,3).\n\n* * *"}, {"input": "3 2", "output": "19\n \n\n* * *"}, {"input": "10 10", "output": "211428932\n \n\n* * *"}, {"input": "100000 50000", "output": "3463133"}]
Print the number of different sequences that can result after M operations, modulo 998244353. * * *
s118603498
Wrong Answer
p02965
Input is given from Standard Input in the following format: N M
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10**18 MOD = 998244353 N, M = list(map(int, sys.stdin.readline().split())) def get_factorials(max, mod=None): """ 階乗 0!, 1!, 2!, ..., max! :param int max: :param int mod: :return: """ ret = [1] n = 1 if mod: for i in range(1, max + 1): n *= i n %= mod ret.append(n) else: for i in range(1, max + 1): n *= i ret.append(n) return ret factorials = get_factorials(M * 3 + N - 1, MOD) # invs = mod_invs(M * 3 + N - 1, MOD) # fi = [0, invs[1]] # a = invs[1] # for i in invs[2:]: # a = a * i % MOD # fi.append(a) # # print(invs) def mod_inv(a, mod): """ a の逆元 :param int a: :param int mod: :return: """ return pow(a, mod - 2, mod) def ncr(n, r, mod=None): """ scipy.misc.comb または scipy.special.comb と同じ 組み合わせの数 nCr :param int n: :param int r: :param int mod: 3 以上の素数であること :rtype: int """ if n < r: return 0 return ( factorials[n] * mod_inv(factorials[r], mod) * mod_inv(factorials[n - r], mod) % mod ) # 合計が M*3 となる数列の数 c1 = ncr(M * 3 + N - 1, N - 1, MOD) # max が M*2 より大きい数列の数を引く c2 = 0 for m in range(M * 2 + 1, M * 3 + 1): s = M * 3 - m c2 += ncr(s + N - 2, N - 2, MOD) * N c2 %= MOD print((c1 - c2) % MOD)
Statement We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation **exactly** M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of different sequences that can result after M operations. Since it can be enormous, compute the count modulo 998244353.
[{"input": "2 2", "output": "3\n \n\nAfter two operations, there are three possible outcomes:\n\n * x=(2,4)\n * x=(3,3)\n * x=(4,2)\n\nFor example, x=(3,3) can result after the following sequence of operations:\n\n * First, choose i=0,j=1, changing x from (0,0) to (2,1).\n * Second, choose i=1,j=0, changing x from (2,1) to (3,3).\n\n* * *"}, {"input": "3 2", "output": "19\n \n\n* * *"}, {"input": "10 10", "output": "211428932\n \n\n* * *"}, {"input": "100000 50000", "output": "3463133"}]
For each front operation, print an integer in a line.
s141532986
Accepted
p02436
The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $t$ where the first digits 0, 1 and 2 represent enqueue, front and dequeue operations respectively.
from collections import deque def enqueue(t, x): global Qlist Qlist[t].appendleft(x) def front(t): global Qlist if Qlist[t] != deque(): print(Qlist[t][-1]) def dequeue(t): global Qlist if Qlist[t] != deque(): Qlist[t].pop() n, q = map(int, input().split()) Qlist = [] for i in range(n): Q = deque() Qlist.append(Q) for j in range(q): queryi = list(map(int, input().split())) if queryi[0] == 0: enqueue(queryi[1], queryi[2]) elif queryi[0] == 1: front(queryi[1]) else: dequeue(queryi[1])
Queue Queue is a container of elements that are inserted and deleted according to FIFO (First In First Out). For $n$ queues $Q_i$ ($i = 0, 1, ..., n-1$), perform a sequence of the following operations. * enqueue($t$, $x$): Insert an integer $x$ to $Q_t$. * front($t$): Report the value which should be deleted next from $Q_t$. If $Q_t$ is empty, do nothing. * dequeue($t$): Delete an element from $Q_t$. If $Q_t$ is empty, do nothing. In the initial state, all queues are empty.
[{"input": "3 9\n 0 0 1\n 0 0 2\n 0 0 3\n 0 2 4\n 0 2 5\n 1 0\n 1 2\n 2 0\n 1 0", "output": "1\n 4\n 2"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s016259178
Runtime Error
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
m = int(input()) a = input().split() tmp = sum( int(n[0]) * int(n[1]) for n in set([(a[i], w) for w in a[i + 1 :]] for i in range(m)) ) print(tmp % 1000000007)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s663344831
Wrong Answer
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
a = input() b = input() ind = [] for i in range(len(a) - len(b)): if a[i] == b[0]: ind.append(i) ans = len(b) for i in range(len(ind)): count = 0 for j in range(len(b)): if a[ind[i] + j] != b[j]: count += 1 ans = min(ans, count) print(ans)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s550877353
Accepted
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
c=s=0 for a in[*open(0)][1].split():a=int(a);c+=s*a;s+=a print(c%(10**9+7))
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s584575173
Accepted
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N = I() A = LI() s = sum(A) mod = 10**9+7 s %= mod a = s**2-sum(A[i]**2 for i in range(N)) a %= mod a *= pow(2,mod-2,mod) a %= mod print(a)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s008223024
Wrong Answer
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
def fastSumPair(A): L = len(A) M = 1000000007 # (a + b + c)**2 = a**2 + b**2 + c**2 + 2*(a*b + b*c + c*a) # derive from this equation # first array A_1_sum = 0 for i in range(0, L): A_1_sum = A_1_sum + A[i] A_1_sum = A_1_sum**2 # second array A_2_sum = 0 for i in range(0, L): A_2_sum = A_2_sum + A[i] ** 2 return int((A_1_sum - A_2_sum) / 2) % M N = int(input()) A = list(map(int, input().rstrip().split())) print(fastSumPair(A))
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s367970252
Accepted
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
n=int(input()) a=[int(x) for x in input().split()] m=10**9+7 s=0 for c in range(n): s=(s+a[c])%m s=pow(s,2,m) for c in range(n): s=(s-pow(a[c],2,m))%m if s%2==0: print(s//2) else: print((s+m)//2)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s216544287
Accepted
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
n=int(input()) a=list(map(int,input().strip().split()))[:n] s=0; b=[] b.append(a[0]) for i in range(1,n): b.append(a[i]+b[i-1]) for i in range(0,n): s+=a[i]*(b[n-1]-b[i]) s=s%1000000007 print(s)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s796926079
Wrong Answer
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) MOD = 10**9 + 7 class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): return ( ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other) ) def __sub__(self, other): return ( ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other) ) def __mul__(self, other): return ( ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other) ) def __truediv__(self, other): return ( ModInt(self.x * pow(other.x, MOD - 2, MOD)) if isinstance(other, ModInt) else ModInt(self.x * pow(other, MOD - 2, MOD)) ) def __pow__(self, other): return ( ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, MOD)) ) __radd__ = __add__ def __rsub__(self, other): return ( ModInt(other.x - self.x) if isinstance(other, ModInt) else ModInt(other - self.x) ) __rmul__ = __mul__ def __rtruediv__(self, other): return ( ModInt(other.x * pow(self.x, MOD - 2, MOD)) if isinstance(other, ModInt) else ModInt(other * pow(self.x, MOD - 2, MOD)) ) def __rpow__(self, other): return ( ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(other, self.x, MOD)) ) N = int(input()) A = list(map(int, input().split())) A = [ModInt(a) for a in A] A_d = [a * a for a in A] res = sum(A) ** 2 - sum(A_d) res = int(str(res)) res //= 2 print(res)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s386982374
Runtime Error
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
test = int(input()) for t in range(test): lst = map(int, input().split()) lst2 = list(lst) sum = 0 for i in range(len(lst2)): for j in range(i + 1, len(lst2)): sum = sum + lst2[i] * lst2[j] print(sum)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s751975721
Runtime Error
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
S = input() T = input() print(S) print(T) num = [] for i in range(len(T)): _T = T[i:] for j in range(len(T) - i): _T_ = _T if j == 0 else _T[:-j] base = S[i:-j] if j != 0 else S[i:] if _T_ in base: num.append(len(T) - len(_T_)) print(num) print(min(num))
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s497535648
Wrong Answer
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
n = int(input('')) adl = input('') a = list(map(int,adl.split(' '))) number = 0 mod0 = 1000000000 mod1 = 7 amari = 0 for i in range(n): aa = 0 for e in range(n-i-1): j = i+e+1 if i != j: aa = aa + a[j] number = number + (a[i] * aa) amari0 = number % mod0 amari1 = number % mod1 amari = amari0 + amari1 print(amari)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s451136600
Wrong Answer
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
#Worst Solution input() l = list(map(int,input().split())) r = 0 s = l for i in range(len(l)): for j in range(i+1,len(s)): r+=l[i]*l[j] print(r)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s285890553
Wrong Answer
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
N = int(input()) A = list(map(int, input().split())) M = 0 X = (10**9) + 7 Y = 0 for k in range(0, N): M = M + A[k] Y = A[k] * A[k] + Y k = k + 1 M = M % X newM = (M * M) % X newY = Y % X if newM - newY < 0: Answer = (newM - newY + X) // 2 else: Answer = (newM - newY) // 2 print(Answer)
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s140239629
Wrong Answer
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
# Date [ 2020-08-29 21:10:46 ] # Problem [ c.py ] # Author Koki_tkg import sys # import math # import bisect # import numpy as np # from decimal import Decimal # from numba import njit, i8, u1, b1 #JIT compiler # from itertools import combinations, product # from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10**9 + 7 INF = 10**9 PI = 3.14159265358979323846 def read_str(): return sys.stdin.readline().strip() def read_int(): return int(sys.stdin.readline().strip()) def read_ints(): return map(int, sys.stdin.readline().strip().split()) def read_ints2(x): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split()) def read_str_list(): return list(sys.stdin.readline().strip().split()) def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) def GCD(a: int, b: int) -> int: return b if a % b == 0 else GCD(b, a % b) def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b) def Main(): n = read_int() a = read_int_list() ans = 0 total = sum(a) for i in range(n): ans += (a[i] * (total - a[i])) / 2 ans %= MOD print(int(ans % MOD)) if __name__ == "__main__": Main()
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} A_i A_j, modulo (10^9+7). * * *
s695191878
Accepted
p02572
Input is given from Standard Input in the following format: N A_1 \ldots A_N
N = int(input()) A_list = list(map(int, input().split())) # myans_list = [ [0 for n in range(N)] for nn in range(N) ] # myans = 0 # for n in range(N): # for nn in range(N): # myans_list[n][nn] = A_list[n] * A_list[nn] # for n in myans_list: # print(n) mysum = sum(A_list) myans = 0 for n in range(N - 1): mysum -= A_list[n] myans += mysum * A_list[n] print(myans % (1000000007))
Statement Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7).
[{"input": "3\n 1 2 3", "output": "11\n \n\nWe have 1 \\times 2 + 1 \\times 3 + 2 \\times 3 = 11.\n\n* * *"}, {"input": "4\n 141421356 17320508 22360679 244949", "output": "437235829"}]
Print the maximum value that can be displayed as your grade. * * *
s457976870
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
n = int(input()) x = 0 mn = 101 for i in range(n): s = int(input()) x += s if x % 10 != 0 if s < mn: mn = s if x % 10 != 0: print(x) else: x -= mn if x % 10 == 0: print(0) else: if x < 0: print(0) exit() print(x)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s686475206
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
a=int(input()) b=[int(input()) for i in range(a)] b.sort() c=sum(b) d=0 if c%10!=0: print(c) else: for i in range(a): if b[i]%!=0: d=c-b[i] print(d) break if d==c: print(0)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s090061088
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
a=int(input()) b=[int(input()) for i in range(a)] b.sort() c=sum(b) if c%10!==0: print(c) else: while c%10==0: for k in range(a): c=c-b[k] print(c)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s135246795
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
n = int(input()) s = [int(input()) for i range(n)] summ = sum(s) ans = [0]*summ for i in range(n): ans[i] -= a[i] ans.sort(reverse = True) for i in ans: if i % 10 != 0: print(i) break
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s879334517
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
n, a, b = map(int, input().split()) c = a - b h = [] maxValue = 0 minValue = 1000000000 for i in range(n): temp = int(input()) h.append(temp) maxValue = max(maxValue, temp) minValue = min(minValue, temp) for i in range(int(minValue / a), int(maxValue / b) + 1): cnt = 0 for m in range(n): if h[m] - i * b > 0: cnt += (h[m] - i * b) / c if cnt <= i: print(i) exit()
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s083046773
Accepted
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
def read_input(): n = int(input()) slist = [] for i in range(n): slist.append(int(input())) return n, slist # return matrix initialized by zero # shape = (n, m) def make_2d_matrix(n, m): result = [] for i in range(n): result.append([0] * m) return result def submit(): n, slist = read_input() total = sum(slist) dp = make_2d_matrix(len(slist) + 1, total + 1) # dp[0][0] = 1 , dp[0][not 0] = 0 # dp[i][j]はi番目のsまででjになる/ならない # dp[i][j] = # 1 if dp[i - 1][j] == 1 # 1 if dp[i - 1][j - xj] == 1 dp[0][0] = 1 for i in range(1, len(slist) + 1): for j in range(total + 1): if dp[i - 1][j] == 1: dp[i][j] = 1 else: if j - slist[i - 1] >= 0: if dp[i - 1][j - slist[i - 1]] == 1: dp[i][j] = 1 maxscore = 0 for s in range(total + 1): if dp[len(slist)][s] == 1: if s % 10: if maxscore < s: maxscore = s print(maxscore) if __name__ == "__main__": submit()
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s550376567
Wrong Answer
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = SR() return l mod = 1000000007 # A n = I() s = IR(n) dp = [[0 for i in range(10001)] for j in range(n)] dp[0][s[0]] = 1 for i in range(n): dp[0][0] = 1 for i in range(1, n): for j in range(10001)[::-1]: if s[i] + j <= 10000: dp[i][s[i] + j] = dp[i - 1][j] else: dp[i][j] = dp[i - 1][j] for i in range(10001)[::-1]: if dp[n - 1][i] == 1 and i % 10 != 0: break print(i) # B # C # D # E # F # G # H # I # J # K # L # M # N # O # P # Q # R # S # T
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s285129437
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math import bisect from collections import deque from fractions import gcd from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def inputI(): return int(input().strip()) def inputS(): return input().strip() def inputIL(): return list(map(int, input().split())) def inputSL(): return list(map(str, input().split())) def inputILs(n): return list(int(input()) for _ in range(n)) def inputSLs(n): return list(input().strip() for _ in range(n)) def inputILL(n): return [list(map(int, input().split())) for _ in range(n)] def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def Yes(): print("Yes") def No(): print("No") #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count ############# # Main Code # ############# N = input() L = inputILs(N) L.sort() R = [l % 10 for l in L] x = 0 for l in L: if l % 10 == 0: continue else: x = l break if x == 0: print(x) else: print(sum(L) - x)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s881332933
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
mport sys n = int(input()) nums = [] for _ in range(n): nums.append(int(input())) s = sum(nums) if s % 10 != 0: print(s) else: nums.sort() for num in nums: t = s - num if t % 10 != 0: print(t) break else: print(0)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s514549405
Accepted
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
# coding: utf-8 # Your code here! # coding: utf-8 from fractions import gcd from functools import reduce import sys sys.setrecursionlimit(200000000) from inspect import currentframe # my functions here! # 標準エラー出力 def printargs2err(*args): names = {id(v): k for k, v in currentframe().f_back.f_locals.items()} print( ", ".join(names.get(id(arg), "???") + " : " + repr(arg) for arg in args), file=sys.stderr, ) def debug(x): print(x, file=sys.stderr) def printglobals(): for symbol, value in globals().items(): print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr) def printlocals(): for symbol, value in locals().items(): print('symbol="%s"、value=%s' % (symbol, value), file=sys.stderr) # 入力(後でいじる) def pin(type=int): return map(type, input().split()) # どっかで最悪計算量の入力データを用意する関数を作ろう? def worstdata(): a = 0 return a # solution: def vacation(N, act): lastact = [] dp = [0, max(act[0])] * (N + 1) # [i]日目のActivity で得られる最大幸福量 return 0 # input (N,) = pin() S = sorted([int(input()) for i in range(N)]) Smod = [val % 10 for val in S] debug(S) debug(Smod) ans = sum(S) if sum(Smod) == 0: # directly includes all element is 10*(something) ans = 0 # corner case elif sum(Smod) % 10 == 0: for i in range(N): if Smod[i] != 0: ans -= S[i] break print(ans) # output # print(solution(H,N)) # print(["No","Yes"][cond])
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s454851032
Accepted
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
import sys import math import collections import itertools import array import inspect # Set max recursion limit sys.setrecursionlimit(1000000) # Debug output def chkprint(*args): names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()} print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args)) # Binary converter def to_bin(x): return bin(x)[2:] def li_input(): return [int(_) for _ in input().split()] def gcd(n, m): if n % m == 0: return m else: return gcd(m, n % m) def gcd_list(L): v = L[0] for i in range(1, len(L)): v = gcd(v, L[i]) return v def lcm(n, m): return (n * m) // gcd(n, m) def lcm_list(L): v = L[0] for i in range(1, len(L)): v = lcm(v, L[i]) return v # Width First Search (+ Distance) def wfs_d(D, N, K): """ D: 隣接行列(距離付き) N: ノード数 K: 始点ノード """ dfk = [-1] * (N + 1) dfk[K] = 0 cps = [(K, 0)] r = [False] * (N + 1) r[K] = True while len(cps) != 0: n_cps = [] for cp, cd in cps: for i, dfcp in enumerate(D[cp]): if dfcp != -1 and not r[i]: dfk[i] = cd + dfcp n_cps.append((i, cd + dfcp)) r[i] = True cps = n_cps[:] return dfk # Depth First Search (+Distance) def dfs_d(v, pre, dist): """ v: 現在のノード pre: 1つ前のノード dist: 現在の距離 以下は別途用意する D: 隣接リスト(行列ではない) D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト """ global D global D_dfs_d D_dfs_d[v] = dist for next_v, d in D[v]: if next_v != pre: dfs_d(next_v, v, dist + d) return def sigma(N): ans = 0 for i in range(1, N + 1): ans += i return ans class Combination: def __init__(self, n, mod): g1 = [1, 1] g2 = [1, 1] inverse = [0, 1] for i in range(2, n + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) self.MOD = mod self.N = n self.g1 = g1 self.g2 = g2 self.inverse = inverse def __call__(self, n, r): if r < 0 or r > n: return 0 r = min(r, n - r) return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD # -------------------------------------------- dp = None def main(): N = int(input()) S = [int(input()) for _ in range(N)] total = sum(S) if total % 10 != 0: print(total) else: min10x = 999 for s in S: if s % 10 != 0 and s < min10x: min10x = s if min10x == 999: print(0) else: print(total - min10x) main()
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s597416832
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
``` n = int(input()) s = [] for i in range(n): tmp = int(input()) s.append(tmp) sorted(s) max_s = sum(s) if max_s % 10 != 0: print(max_s) else: for j in range(n): if s[j] % 10 != 0: print(max_s - s[j]) break elif j == n-1: assert "a" print(0)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s266404702
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
#C Bugged import numpy as np a = int(input()) k = [] k10 = [] s = 0 for j in range(a): i = int(input()) if i % 10 == 0: k10.append(i) s += i else: k.append(i) k.sort() c = np.array(k) l = c.sum() if l%10==0 and len(k) !=0: l = l - c[0] s = s + l elif:len(k) == 0 s = 0 else: s = s + l print(s)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s856799621
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
n = int(input()) l = [int(input()) for i in range(n)] total = sum(l) i = 0 while total % 10 == 0: if i = n: break total = total - l[i] i += 1 print(total)
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Print the maximum value that can be displayed as your grade. * * *
s542646477
Runtime Error
p03699
Input is given from Standard Input in the following format: N s_1 s_2 : s_N
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] s = new int[n]; int sum = 0; for (int i = 0; i<n; i++) { s[i] = sc.nextInt(); sum += s[i]; } Arrays.sort(s); if (sum%10 != 0) {System.out.println(sum);} else { for (int i=0; i<n;i++) { if (s[i]%10!=0) { System.out.println(sum-s[i]); return; } } } System.out.println(0); } }
Statement You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
[{"input": "3\n 5\n 10\n 15", "output": "25\n \n\nYour grade will be 25 if the 10-point and 15-point questions are answered\ncorrectly and the 5-point question is not, and this grade will be displayed\ncorrectly. Your grade will become 30 if the 5-point question is also answered\ncorrectly, but this grade will be incorrectly displayed as 0.\n\n* * *"}, {"input": "3\n 10\n 10\n 15", "output": "35\n \n\nYour grade will be 35 if all the questions are answered correctly, and this\ngrade will be displayed correctly.\n\n* * *"}, {"input": "3\n 10\n 20\n 30", "output": "0\n \n\nRegardless of whether each question is answered correctly or not, your grade\nwill be a multiple of 10 and displayed as 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s709528385
Wrong Answer
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import sys import math import copy import heapq from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = float("inf") MOD = 10**9 + 7 divide = lambda x: pow(x, MOD - 2, MOD) def nck(n, k, kaijyo): return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD def npk(n, k, kaijyo): if k == 0 or k == n: return n % MOD return (kaijyo[n] * divide(kaijyo[n - k])) % MOD def fact_and_inv(SIZE): inv = [0] * SIZE # inv[j] = j^{-1} mod MOD fac = [0] * SIZE # fac[j] = j! mod MOD finv = [0] * SIZE # finv[j] = (j!)^{-1} mod MOD inv[1] = 1 fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2, SIZE): inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD fac[i] = fac[i - 1] * i % MOD finv[i] = finv[i - 1] * inv[i] % MOD return fac, finv def renritsu(A, Y): # example 2x + y = 3, x + 3y = 4 # A = [[2,1], [1,3]]) # Y = [[3],[4]] または [3,4] A = np.matrix(A) Y = np.matrix(Y) Y = np.reshape(Y, (-1, 1)) X = np.linalg.solve(A, Y) # [1.0, 1.0] return X.flatten().tolist()[0] class TwoDimGrid: # 2次元座標 -> 1次元 def __init__(self, h, w, wall="#"): self.h = h self.w = w self.size = (h + 2) * (w + 2) self.wall = wall self.get_grid() # self.init_cost() def get_grid(self): grid = [self.wall * (self.w + 2)] for i in range(self.h): grid.append(self.wall + getS() + self.wall) grid.append(self.wall * (self.w + 2)) self.grid = grid def init_cost(self): self.cost = [INF] * self.size def pos(self, x, y): # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed return y * (self.w + 2) + x def getgrid(self, x, y): return self.grid[y][x] def get(self, x, y): return self.cost[self.pos(x, y)] def set(self, x, y, v): self.cost[self.pos(x, y)] = v return def show(self): for i in range(self.h + 2): print(self.cost[(self.w + 2) * i : (self.w + 2) * (i + 1)]) def showsome(self, tgt): for t in tgt: print(t) return def showsomejoin(self, tgt): for t in tgt: print("".join(t)) return def search(self): grid = self.grid move = [(0, 1), (0, -1), (1, 0), (-1, 0)] move_eight = [ (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1), ] # for i in range(1, self.h+1): # for j in range(1, self.w+1): # cx, cy = j, i # for dx, dy in move_eight: # nx, ny = dx + cx, dy + cy def solve(): n = getN() nums = [0] + getList() for i in range(n): nums[i + 1] += nums[i] cnt = Counter(nums) fac, _ = fact_and_inv(n + 2) # print(cnt, nums) ans = 0 for v in cnt.values(): if v != 1: ans += nck(v, 2, fac) print(ans) def main(): n = getN() for _ in range(n): solve() return if __name__ == "__main__": # main() solve()
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s597124473
Accepted
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
def examA(): N = I() A = LI() D = defaultdict(int) for a in A: D[a] += 1 ans = 0 for key, d in D.items(): if key > d: ans += d else: ans += d - key print(ans) return def examB(): N = I() A = LI() S = [0] * (N + 1) for i in range(N): S[i + 1] = S[i] + A[i] D = defaultdict(int) for s in S: D[s] += 1 ans = 0 for d in D.values(): ans += d * (d - 1) // 2 print(ans) return def examC(): N, A, B, C = LI() L = [I() for _ in range(N)] loop = 1 << (2 * N) ans = inf for l in range(loop): cost = 0 bamboo_A = 0 bamboo_B = 0 bamboo_C = 0 for j in range(N): if l & (1 << (2 * j)) > 0: if l & (1 << (2 * j + 1)) > 0: cost += 10 bamboo_A += L[j] else: cost += 10 bamboo_B += L[j] else: if l & (1 << (2 * j + 1)) > 0: cost += 10 bamboo_C += L[j] if bamboo_A == 0 or bamboo_B == 0 or bamboo_C == 0: continue cost += abs(A - bamboo_A) + abs(B - bamboo_B) + abs(C - bamboo_C) - 30 ans = min(ans, cost) print(ans) return def examD(): N = I() P = LI() O_ = [-1] * N start = P[0] - 1 for i in range(N): O_[P[i] - 1] = i # print(O_,start) A = [1] * N B = [1] * N for i in range(start + 1, N): cur = O_[i] - O_[i - 1] if cur > 0: A[i] = A[i - 1] + (cur + 1) B[i] = B[i - 1] - 1 else: A[i] = A[i - 1] + 1 B[i] = B[i - 1] - (-cur + 1) for i in range(start)[::-1]: cur = O_[i] - O_[i + 1] if cur > 0: B[i] = B[i + 1] + (cur + 1) A[i] = A[i + 1] - 1 else: B[i] = B[i + 1] + 1 A[i] = A[i + 1] - (-cur + 1) if A[0] < 1: add = 1 - A[0] for i in range(N): A[i] += add if B[-1] < 1: add = 1 - B[-1] for i in range(N): B[i] += add print(" ".join(map(str, A))) print(" ".join(map(str, B))) return def examE(): return def examF(): ans = 0 print(ans) return from decimal import getcontext, Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(input()) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(input()) def LDI(): return list(map(dec, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord("a") + i) for i in range(26)] alphabet_convert = {chr(ord("a") + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == "__main__": examB() """ 9 7 3 9 1 8 4 5 6 2 """
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s359623566
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N=int(input()) A=list(map(int,input().split()) B=[0] for i in range(N): B+=[B[i]+A[i]] C=[] asn+=1 for i in B: if i in C: ans+=1 else: C+=[i] print(ans)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s965838501
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import sys import os if sys.platform=="darwin": base = os.path.dirname(os.path.abspath(__file__)) name = os.path.normpath(os.path.join(base, '../Documents/input.txt')) #print(name) sys.stdin = open(name) #nCrの計算。nこの中から、r個を取り出す。 import import sys import os if sys.platform=="darwin": base = os.path.dirname(os.path.abspath(__file__)) name = os.path.normpath(os.path.join(base, '../Documents/input.txt')) #print(name) sys.stdin = open(name) #読み込みの高速化 input = sys.stdin.readline #nCrの計算。nこの中から、r個を取り出す。 import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) import copy n = int(input()) a = list(map(int,input().split())) b = [0]*(n+1) b[0] = 0 for i in range(1,n+1): b[i] = b[i-1] + a[i-1] #print(b) c = [0]*(n+1) c = copy.copy(b) c = list(set(c)) #print(c) ans = 0 for i in c: #print(i) chk = b.count(i) #print(chk) if chk >= 2: ans = ans + combinations_count(chk,2) print(ans) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) import copy n = int(input()) a = list(map(int,input().split())) b = [0]*(n+1) b[0] = 0 for i in range(1,n+1): b[i] = b[i-1] + a[i-1] #print(b) c = [0]*(n+1) c = copy.copy(b) c = list(set(c)) #print(c) ans = 0 for i in c: #print(i) chk = b.count(i) #print(chk) if chk >= 2: ans = ans + combinations_count(chk,2) print(ans)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s877684455
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = list(map(int, input().split())) count_list = {} s = 0 for i in range(n): s += a[i] count_list[s] = count_list.get(s, 0) += 1 count = 0 # count += count_list.get(0, 0) * (count_list.get(0, 0)+1) // 2 for i in count_list.keys(): count+= count_list[i] * count_list.get(-i, 0) print((count + count_list.get(0, 0))//2)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s111685169
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = list(map(int, input().split())) ans = 0 s = 0 dic = {} for i in a: s += i dic.get(s, 0) += 1 ans += dic[s] - s != 0 print(ans)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s848561486
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = list(map(int,input().split()) cnt = 0 for i in range(1,n+1): c = 0 for j in range(i): for k in range(j): c += a[k] print(c)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s383436757
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N, P = map(int, input().split()) odd = sum([int(i) % 2 for i in input().split()]) even = N - odd if odd == 0: if P == 0: print(2**even) else: # P==1 print(0) else: print(2**even * (2**odd // 2))
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s751728867
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
a = list(map(int, input().split())) n = 0 for i in range(1, N + 1): for j in range(N + 1 - i): S = 0 for x in a[j : j + i]: S += x if S == 0: n += 1 print(n)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s589095563
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
a
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s717294073
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import bisect from collections import deque n = int(input()) a = [int(i) for i in input().split()] a_sum = [0] for i in range(n): a_sum.append((a_sum[-1]+a[i])) val = deque() cnt = deque() for i in range(n+1): idx = bisect.bisect_left(val, a_sum[i]) if len(val) > idx and val[idx] == a_sum[i]: cnt[idx] += 1 else: # val.insert(idx, a_sum[i]) # cnt.insert(idx, 1) ans = 0 for i in range(len(cnt)): ans += cnt[i]*(cnt[i]-1)//2 print(ans)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s013956819
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) A = list(map(int,input().split())) S = [] sm = 0 ans=0 for a in A: sm += a S.append(sm) S.sort() for s in S: if S[s]==0: ans+=1 F=S.count(0) for i in range(1,F): F=F*i pro=F/2 ans=ans+pro pro=0 else: for s in range(S[n]): C=S.count(s) if C>1: for i in range(1,C): C=C*i pro=C/2 ans=ans+pro pro=0 print(ans)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s533972051
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# -*- coding: utf-8 -*- max_length = 10e5 def func(A, n): # nこの話を数える. count = 0 for i in range(len(A)): if i + n > len(A)c: break s = sum(A[i:i+n]) if s == 0: count += 1 return count def main(): N = int(input()) A = input().split() A = [int(a) for a in A] count = 0 for i in range(1,N): count += func(A, i) print(count) if __name__ == '__main__': main()
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s174274107
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <string> #include <vector> typedef long long ll; using namespace std; int main() { int n = 0; cin >> n; vector<ll> a(n); ll buf = 0; for (int i=0; i<n; i++) { if (i == 0) { a.at(i) = buf; } else { a.at(i) = buf + a.at(i-1); } } sort(a.begin(), a.end()); int count = 1; ll ans = 0; for (int i=1; i<n; i++) { if (a.at(i) != a.at(i-1)) { ans += (count+1)*count/2; count = 1; } else { count++; } } ans += (count+1)*count/2; cout << ans << endl; return 0; }
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s246951237
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N, Q = map(int, input().split()) S = input() qn = [list(map(int, input().split())) for _ in range(Q)] cnt = [0 for _ in range(N + 10)] for i in range(1, N + 1): if S[i - 1 : i + 1] == "AC": cnt[i] = cnt[i - 1] + 1 else: cnt[i] = cnt[i - 1] for q in qn: l, r = q print(cnt[r - 1] - cnt[l - 1])
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s139857974
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
inport bisect N = int(input()) A = [int(i) for i in input().split()] B = [0] X = [0] ans = 0 for i in range(N): X.append(X[i]+A[i]) insert_index = bisect.bisect_left(B,X[i+1]) for j in range(insert_index,i+1): if B[j] == X[i+1]: ans += 1 else: break B.insert(insert_index,X[i+1]) print(ans)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s364734382
Runtime Error
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
def solve(): N,L=map(int,input().split()) a=[0]+[L-int(input())for _ in[0]*N] l=[] cumsum,dir=0,0 for n,prev in zip(a[1:],a): if dir==0 and n>prev or dir==1 and n<prev: cumsum+=n else: l.append(cumsum) cumsum=n+prev dir^=1 else: l.append(cumsum) print(max(l)) if __name__=="__main__": solve() ()
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s029794606
Wrong Answer
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import sys input = sys.stdin.readline # import numpy as np import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random from collections import deque, defaultdict, Counter # from heapq import heappush, heappop from itertools import permutations, combinations, product, accumulate, groupby from bisect import bisect_left, bisect_right, insort_left, insort_right # from operator import itemgetter as ig # sys.setrecursionlimit(10 ** 7) # nf = 10 ** 20 # INF = float("INF") # mod = 10 ** 9 + 7 """ dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)] ddn9 = ddn + [(0, 0)] for dx, dy in dd: nx = j + dx; ny = i + dy if 0 <= nx < w and 0 <= ny < h: def wi(): return list(map(int, sys.stdin.readline().split())) def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()] # WideIntPoint def ws(): return sys.stdin.readline().split() def si(): return int(sys.stdin.readline()) # SingleInt def ss(): return input() def hi(n): return [si() for _ in range(n)] def hs(n): return [ss() for _ in range(n)] # HeightString def s_list(): return list(input()) def mi(n): return [wi() for _ in range(n)] # MatrixInt def mip(n): return [wip() for _ in range(n)] def ms(n): return [ws() for _ in range(n)] def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)] # NumberGrid def grid(n): return [s_list() for _ in range(n)] # 深さ優先探索 def dfs(G, v): global time, first_order,seen,last_order time += 1 first_order[v-1] = time # 行きがけ seen[v-1] = True # v を訪問済みにする # v から行ける各頂点 next_v について for next_v in G[v]: if seen[next_v-1]: continue dfs(G, next_v) time += 1 last_order[v - 1] = time # 帰りがけ """ def main(): a = [0] + list(map(int, input().split())) a = list(accumulate(a)) c = Counter(a) ans = 0 for i in c.values(): ans += i * (i - 1) // 2 print(ans) if __name__ == "__main__": main()
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s324770770
Wrong Answer
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
from collections import Counter class ModFactorial: """ 階乗, 組み合わせ, 順列の計算 """ def __init__(self, n, MOD=10**9 + 7): kaijo = [0] * (n + 10) gyaku = [0] * (n + 10) kaijo[0] = 1 kaijo[1] = 1 for i in range(2, len(kaijo)): kaijo[i] = (i * kaijo[i - 1]) % MOD gyaku[0] = 1 gyaku[1] = 1 for i in range(2, len(gyaku)): gyaku[i] = pow(kaijo[i], MOD - 2, MOD) self.kaijo = kaijo self.gyaku = gyaku self.MOD = MOD def nCm(self, n, m): return (self.kaijo[n] * self.gyaku[n - m] * self.gyaku[m]) % self.MOD def nPm(self, n, m): return (self.kaijo[n] * self.gyaku[n - m]) % self.MOD def factorial(self, n): return self.kaijo[n] N = [int(_) for _ in input().split()][0] a = [int(_) for _ in input().split()] s = [0] * (len(a) + 1) for i in range(len(a)): s[i + 1] = s[i] + a[i] c = Counter() for i in range(len(s)): c[s[i]] += 1 mod = ModFactorial(len(s)) ans = 0 for cnt in c.values(): if cnt < 2: continue ans += mod.nCm(cnt, 2) print(ans)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s877626008
Wrong Answer
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) - 1 LARGE = 10**9 + 7 def ex_euclid(x, y): c0, c1 = x, y a0, a1 = 1, 0 b0, b1 = 0, 1 while c1 != 0: m = c0 % c1 q = c0 // c1 c0, c1 = c1, m a0, a1 = a1, (a0 - q * a1) b0, b1 = b1, (b0 - q * b1) return c0, a0, b0 # precompute fac_list = [1] * (N + 1) fac = 1 for i in range(1, N + 1): fac = (fac * i) % LARGE fac_list[i] = fac fac_inv_list = [1] * (N + 1) for i in range(N + 1): fac_inv_list[i] = pow(fac_list[i], LARGE - 2, LARGE) def nCr(n, r): return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n - r]) % LARGE def pat(n, r): return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n - r]) % LARGE pat = 0 score = 0 for k in range(N + 1): if k - 1 >= N - k: res = ( ((fac_list[k - 1] * fac_list[k]) % LARGE) * fac_inv_list[k - 1 - N + k] ) % LARGE score = (score + (res - pat) * k) % LARGE # print(k, pat, res) pat = res print(score)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Find the number of the non-empty contiguous subsequences of A whose sum is 0. * * *
s770482467
Wrong Answer
p03363
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
def getinputdata(): # 配列初期化 array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() if data != "": array_result.append(data.split(" ")) else: flg = 0 finally: return array_result arr_data = getinputdata() n = int(arr_data[0][0]) arr = [int(arr_data[1][x]) for x in range(n)] cnt = 0 for i in range(0, n): for j in range(i + 2, n + 1): if sum(arr[i:j]) == 0: cnt += 1 print(cnt)
Statement We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.
[{"input": "6\n 1 3 -4 2 2 -2", "output": "3\n \n\nThere are three contiguous subsequences whose sums are 0: (1,3,-4), (-4,2,2)\nand (2,-2).\n\n* * *"}, {"input": "7\n 1 -1 1 -1 1 -1 1", "output": "12\n \n\nIn this case, some subsequences that have the same contents but are taken from\ndifferent positions are counted individually. For example, three occurrences\nof (1, -1) are counted.\n\n* * *"}, {"input": "5\n 1 -2 3 -4 5", "output": "0\n \n\nThere are no contiguous subsequences whose sums are 0."}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s311540733
Accepted
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
f = lambda: map(int, input().split()) N, T = f() q = list(f()) print(T + sum(min(q[i + 1] - q[i], T) for i in range(N - 1)))
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s950467176
Wrong Answer
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
from functools import reduce import math def main(): # 文字列の2進数を数値にする # '101' → '5' # 文字列の頭に'0b'をつけてint()にわたす # binary = int('0b'+'101',0) # 2進数で立っているbitを数える # 101(0x5) → 2 # cnt_bit = bin(5).count('1') # N! を求める # f = math.factorial(N) # 切り捨て # 4 // 3 # 切り上げ # -(-4 // 3) # 初期値用:十分大きい数(100億) # 1e10 # 初期値用:十分小さい数(-100億) # -1e10 # 1文字のみを読み込み # 入力:2 # a = input().rstrip() # 変数:a='2' # スペース区切りで標準入力を配列として読み込み # 入力:2 4 5 7 # a, b, c, d = (int(_) for _ in input().split()) # 変数:a=2 b=4 c=5 d =7 # 1文字ずつ標準入力を配列として読み込み # 入力:2 4 5 7 # a = list(int(_) for _ in input().split()) # 変数:a = [2, 4, 5, 7] # 1文字ずつ標準入力を配列として読み込み # 入力:2457 # a = list(int(_) for _ in input()) # 変数:a = [2, 4, 5, 7] N, T = (int(_) for _ in input().split()) t = list(int(_) for _ in input().split()) sum = T stop_time = T for i in range(1, N): if stop_time > t[i]: sum -= stop_time - t[i] stop_time = t[i] + T elif stop_time < t[i]: stop_time = t[i] + T sum += T print(sum) if __name__ == "__main__": main()
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s595560497
Accepted
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
n, t = [int(x) for x in input().split(" ")] time = [int(x) for x in input().split(" ")] diff = [time[j + 1] - time[j] for j in range(n - 1) if time[j + 1] - time[j] > t] dec = sum(diff) - len(diff) * t print(time.pop() + t - dec)
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s347321327
Runtime Error
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
N, T = input().split() f = None p = None ans = 0 for t in map(int, input().split()) if f is None: f = t p = t - f ans += T rest = p + T - (t - f) if rest > 0: ans -= rest p = t - f print(ans)
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s848040895
Accepted
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
_, T, *t = map(int, open(0).read().split()) print(sum(min(T, j - i) for i, j in zip(t, t[1:])) + T)
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s979383972
Runtime Error
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
N, T = map(int, input().split(" ")) times = [int(input()) for i in range(N)] print(sum([min(T, times[i + 1] - times[i] for i in range(N - 1))]) + times[-1])
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s889311908
Runtime Error
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
INF = 10**12 class Rmin: def __init__(self, size): # the number of nodes is 2n-1 self.n = 1 << (size.bit_length()) self.node = [INF] * (2 * self.n - 1) def Access(self, x): return self.node[x + self.n - 1] def Update(self, x, val): x += self.n - 1 self.node[x] = val while x > 0: x = (x - 1) >> 1 self.node[x] = min(self.node[(x << 1) + 1], self.node[(x << 1) + 2]) return # [l, r) def Get(self, l, r): L, R = l + self.n, r + self.n s = INF while L < R: if R & 1: R -= 1 s = min(s, self.node[R - 1]) if L & 1: s = min(s, self.node[L - 1]) L += 1 L >>= 1 R >>= 1 return s n, q, a, b = map(int, input().split()) qs = [a] + list(map(int, input().split())) dp_l, dp_r = Rmin(n + 1), Rmin(n + 1) dp_l.Update(b, -b) dp_r.Update(b, b) total_diff = 0 for i in range(q): x, y = qs[i], qs[i + 1] diff = abs(y - x) l_min = dp_l.Get(1, y) r_min = dp_r.Get(y, n + 1) res = min(l_min + y, r_min - y) # print(res) dp_l.Update(x, res - diff - x) dp_r.Update(x, res - diff + x) total_diff += diff N = dp_l.n print(total_diff + min(dp_l.node[i + N - 1] + i for i in range(1, n + 1)))
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s569594005
Runtime Error
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): n = I() a = sorted([sorted(LI()) + [_] for _ in range(n)]) b = sorted(a, key=lambda x: x[1]) r = (a[-1][0] - a[0][0]) * (b[-1][1] - b[0][1]) bm = b[-1][1] - a[0][0] bmi = b[0][2] am = a[-1][1] at = 0 k = [[inf, 0]] for i in range(n - 1): kk = [] kk.append(min(k[-1][0], b[i][0], b[i + 1][1])) kk.append(max(k[-1][1], b[i][0])) if kk[0] == k[-1][0]: k[-1][1] = kk[1] else: k.append(kk) k = k[1:] kl = len(k) am = b[-1][1] - a[0][0] ami = a[0][2] bm = 0 mtm = 0 bt = b[0][1] for i in range(n - 1, 0, -1): tm = b[i][0] if mtm < tm: mtm = tm if ami == b[i][2]: break if tm < bt: bt = tm if tm < b[i - 1][1]: tm = b[i - 1][1] bm = mtm if tm > bm: bm = tm tr = am * (bm - bt) if r > tr: r = tr for j in range(kl): ki, km = k[j] if km > bm: break tr = am * (bm - min(ki, bt)) if r > tr: r = tr return r print(main())
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s165088097
Accepted
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
N, T = input().split() T = int(T) L = [int(x) for x in input().split()] R = 0 for i in range(len(L) - 1): su = L[i + 1] - L[i] R += min([su, T]) print(R + T)
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s469173066
Accepted
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
while True: try: ins = input().split(" ") N = int(ins[0]) T = int(ins[1]) a = [] inx = input().split(" ") for i in range(0, N): a.append(int(inx[i])) ans = 0 end = 0 for x in range(0, N): if a[x] < end: ans = ans + a[x] + T - end end = a[x] + T elif a[x] > end: ans += T end = a[x] + T else: ans += T end += T print(ans) except: break
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Assume that the shower will emit water for a total of X seconds. Print X. * * *
s997829933
Accepted
p03733
Input is given from Standard Input in the following format: N T t_1 t_2 ... t_N
import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) def read_tuple(H): """ H is number of rows """ ret = [] for _ in range(H): ret.append(tuple(map(int, read().split()))) return ret def read_col(H): """ H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合 """ ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) def read_matrix(H): """ H is number of rows """ ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return ret # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right # https://atcoder.jp/contests/arc073/tasks/arc073_a # 愚直でよくね? N, T = read_ints() t = read_ints() ans = 0 # t(i+1)<ti+Tだったら差を足してそうじゃなければTを足すのが良さそう for i in range(N - 1): if t[i + 1] < t[i] + T: ans += t[i + 1] - t[i] else: ans += T ans += T # 最後の人 print(ans)
Statement In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
[{"input": "2 4\n 0 3", "output": "7\n \n\nThree seconds after the first person pushes the water, the switch is pushed\nagain and the shower emits water for four more seconds, for a total of seven\nseconds.\n\n* * *"}, {"input": "2 4\n 0 5", "output": "8\n \n\nOne second after the shower stops emission of water triggered by the first\nperson, the switch is pushed again.\n\n* * *"}, {"input": "4 1000000000\n 0 1000 1000000 1000000000", "output": "2000000000\n \n\n* * *"}, {"input": "1 1\n 0", "output": "1\n \n\n* * *"}, {"input": "9 10\n 0 3 5 7 100 110 200 300 311", "output": "67"}]
Print the maximum possible happiness after M handshakes. * * *
s213199994
Accepted
p02821
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N
#!/usr/bin/env python3 import sys input = sys.stdin.readline import cmath pi = cmath.pi exp = cmath.exp def fft(a, inverse=False): n = len(a) h = n.bit_length() - 1 # Swap for i in range(n): j = 0 for k in range(h): j |= (i >> k & 1) << (h - 1 - k) if i < j: a[i], a[j] = a[j], a[i] # Butterfly calculation if inverse: sign = 1.0 else: sign = -1.0 b = 1 while b < n: for j in range(b): w = exp(sign * 2.0j * pi / (2.0 * b) * j) for k in range(0, n, b * 2): s = a[j + k] t = a[j + k + b] * w a[j + k] = s + t a[j + k + b] = s - t b *= 2 if inverse: for i in range(n): a[i] /= n return a def ifft(a): return fft(a, inverse=True) def convolve(f, g): n = 2 ** ((len(f) + len(g) - 1).bit_length()) f += [0] * (n - len(f)) g += [0] * (n - len(g)) F = fft(f) G = fft(g) FG = [Fi * Gi for Fi, Gi in zip(F, G)] fg = [int(item.real + 0.5) for item in ifft(FG)] return fg if __name__ == "__main__": n, m = map(int, input().split()) a = [int(item) for item in input().split()] max_a = max(a) freq = [0] * (max_a + 1) for item in a: freq[item] += 1 f = freq[:] g = freq[:] fg = convolve(f, g) total = sum(a) * n * 2 cnt = n * n - m for i, item in enumerate(fg): use = min(cnt, item) total -= i * use cnt -= use if cnt == 0: break print(total)
Statement Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
[{"input": "5 3\n 10 14 19 34 33", "output": "202\n \n\nLet us say that Takahashi performs the following handshakes:\n\n * In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n * In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n * In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\n* * *"}, {"input": "9 14\n 1 3 5 110 24 21 34 5 3", "output": "1837\n \n\n* * *"}, {"input": "9 73\n 67597 52981 5828 66249 75177 64141 40773 79105 16076", "output": "8128170"}]
Print the maximum possible happiness after M handshakes. * * *
s982972594
Wrong Answer
p02821
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N
def modinv(x, mod): a, b = x, mod u, v = 1, 0 while b: t = a // b a -= t * b a, b = b, a u -= t * v u, v = v, u return u % mod def _garner(xs, mods): M = len(xs) coeffs = [1] * M constants = [0] * M for i in range(M - 1): mod_i = mods[i] v = (xs[i] - constants[i]) * modinv(coeffs[i], mod_i) % mod_i for j in range(i + 1, M): mod_j = mods[j] constants[j] = (constants[j] + coeffs[j] * v) % mod_j coeffs[j] = (coeffs[j] * mod_i) % mod_j return constants[-1] def bit_reverse(d): n = len(d) ns = n >> 1 nss = ns >> 1 ns1 = ns + 1 i = 0 for j in range(0, ns, 2): if j < i: d[i], d[j] = d[j], d[i] d[i + ns1], d[j + ns1] = d[j + ns1], d[i + ns1] d[i + 1], d[j + ns] = d[j + ns], d[i + 1] k = nss i ^= k while k > i: k >>= 1 i ^= k return d class NTT: def __init__(self, mod, primitive_root): self.mod = mod self.root = primitive_root def _ntt(self, a, sign): n = len(a) mod, g = self.mod, self.root tmp = (mod - 1) * modinv(n, mod) % mod # -1/n h = pow(g, tmp, mod) # ^n√g if sign < 0: h = modinv(h, mod) a = bit_reverse(a) m = 1 while m < n: m2 = m << 1 _base = pow(h, n // m2, mod) _w = 1 for x in range(m): for s in range(x, n, m2): u = a[s] d = a[s + m] * _w % mod a[s] = (u + d) % mod a[s + m] = (u - d) % mod _w = _w * _base % mod m <<= 1 return a def ntt(self, a): return self._ntt(a, 1) def intt(self, a): mod = self.mod n = len(a) n_inv = modinv(n, mod) a = self._ntt(a, -1) for i in range(n): a[i] = a[i] * n_inv % mod return a def convolution(self, a, b): mod = self.mod ret_size = len(a) + len(b) - 1 n = 1 << (ret_size - 1).bit_length() _a = a + [0] * (n - len(a)) _b = b + [0] * (n - len(b)) _a = self.ntt(_a) _b = self.ntt(_b) _a = [x * y % mod for x, y in zip(_a, _b)] _a = self.intt(_a) _a = _a[:ret_size] return _a def convolution_ntt(a, b): mods = (1224736769,) ntt1 = NTT(mods[0], 3) x1 = ntt1.convolution(a, b) return x1 m, k = map(int, input().split()) f = list(map(int, input().split())) n = max(f) + 1 g = [0] * n for x in f: g[x] += 1 h = convolution_ntt(g, g) ans = 0 cnt = 0 for i in range(len(h) - 1, -1, -1): if cnt + h[i] < k: ans += h[i] * i cnt += h[i] else: ans += (k - cnt) * i break print(ans)
Statement Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
[{"input": "5 3\n 10 14 19 34 33", "output": "202\n \n\nLet us say that Takahashi performs the following handshakes:\n\n * In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n * In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n * In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\n* * *"}, {"input": "9 14\n 1 3 5 110 24 21 34 5 3", "output": "1837\n \n\n* * *"}, {"input": "9 73\n 67597 52981 5828 66249 75177 64141 40773 79105 16076", "output": "8128170"}]
Print the maximum possible happiness after M handshakes. * * *
s207135973
Runtime Error
p02821
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N
# ----------- gcd ----------- # def gcd(x, y): k, l = x, y if y < 0: k, l = -k, -l while l: k, l = l, k % l return k # --------- IsPrime --------- # def IsPrime(n): if n == 1: return False p = 2 while p * p <= n: if n % p == 0: return False p += 1 return True # --- fraction calculator --- # def fracsum(f1, f2, sign=1): fs = [f1[0] * f2[1] + sign * f1[1] * f2[0], f1[1] * f2[1]] g = gcd(fs[0], fs[1]) fs[0] //= g fs[1] //= g return fs def fracprod(f1, f2): fs = [f1[0] * f2[0], f1[1] * f2[1]] g = gcd(fs[0], fs[1]) fs[0] //= g fs[1] //= g return fs # ------ factorization ------ # def factorization(n): D = {} a = n p = 2 while a != 1: cnt = 0 while a % p == 0: cnt += 1 a //= p if cnt != 0: D[p] = cnt p += 1 if p * p > n and a != 1: D[a] = 1 break return D # --------------fact. calculator-------------- # mod = 0 # <-- input modulo maxf = 0 # <-- input factional limitation def doubling(n, m, modulo=0): y = 1 base = n tmp = m while tmp: if tmp % 2 == 1: y *= base if modulo > 0: y %= modulo base *= base if modulo > 0: base %= modulo tmp //= 2 return y def Vanilla(D): F = [1] for i in D: mL = F[:] dp = i for j in range(D[i]): for k in mL: F.append(dp * k) dp *= i return F def bic(n): cnt = 0 while n % 2 == 0: cnt += 1 n //= 2 return cnt mod = 2013265921 def inved(a, modulo=mod): x, y, u, v, k, l = 1, 0, 0, 1, a, modulo while l != 0: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return x % modulo """D = {i: [] for i in range(39, 40)} for i in range(39, 40): j = 1 bas = 2**i while len(D[i]) < 1: if IsPrime(j*bas+1): D[i].append(j*bas+1) j += 2 print(D)""" # mod = 40961 # mod = 998244353, primod = 50475, invmod = 305218526 mod = 2013265921 # 998244353 = 2^23 * (odd number) primod = 137 """S = factorization(mod - 1) S = {2: S[2]} LL = Vanilla(S) print(LL) LL.sort(reverse=True) for i in range(1, 500): flg = (doubling(i, doubling(2, S[2]), mod) == 1) for j in range(1, len(LL)): flg *= (doubling(i, LL[j], mod) != 1) if flg: print(i)""" def powlimit(n): y = 1 cnt = 0 while y < n: y *= 2 cnt += 1 return y, cnt N, M = map(int, input().split()) A = list(map(int, input().split())) mm = max(A) F = [0 for _ in range(mm + 1)] for i in range(N): F[A[i]] += 1 """N = int(input()) AB = [list(map(int, input().split())) for _ in range(N)] F = [0] + [AB[i][0] for i in range(N)] G = [0] + [AB[i][1] for i in range(N)]""" pl, c = powlimit(2 * mm + 2) # pl, c = powlimit(2*N+2) F = F[:] + [0] * (pl - mm - 1) prim = [doubling(primod, doubling(2, 27 - i), mod) for i in range(27)] invp = [inved(prim[i]) for i in range(27)] def NTT(f, n, cn, inverse=False): if n == 1: return f if n == 2: return [(f[0] + f[1]) % mod, (f[0] - f[1]) % mod] dn = n // 2 fe = [f[2 * i + 0] for i in range(dn)] fo = [f[2 * i + 1] for i in range(dn)] fe = NTT(fe, dn, cn - 1, inverse) fo = NTT(fo, dn, cn - 1, inverse) seed = inverse * prim[cn] + (1 - inverse) * invp[cn] grow = 1 for i in range(dn): right = fo[i] * grow % mod f[i + 0 * dn] = (fe[i] + right) % mod f[i + 1 * dn] = (fe[i] - right) % mod grow *= seed grow %= mod return f X = NTT(F, pl, c) # Y = NTT(G, pl, c) # print(X) # print(Y) Z = [X[i] * X[i] % mod for i in range(pl)] Z = NTT(Z, pl, c, 1) # print(NTT(Z, pl, c, 1)) ipl = inved(pl) for i in range(pl): Z[i] *= ipl Z[i] %= mod S = 2 * max(A) hp = 0 ccnt = 0 while ccnt < M: if ccnt + Z[S] < M: ccnt += Z[S] hp += S * Z[S] else: hp += S * (M - ccnt) ccnt += M - ccnt S -= 1 print(hp) # for i in range(1, max(A)+1): # print(Z[i]*ipl%mod)
Statement Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
[{"input": "5 3\n 10 14 19 34 33", "output": "202\n \n\nLet us say that Takahashi performs the following handshakes:\n\n * In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n * In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n * In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\n* * *"}, {"input": "9 14\n 1 3 5 110 24 21 34 5 3", "output": "1837\n \n\n* * *"}, {"input": "9 73\n 67597 52981 5828 66249 75177 64141 40773 79105 16076", "output": "8128170"}]
Print the maximum possible happiness after M handshakes. * * *
s594683930
Runtime Error
p02821
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N
import sys input_methods = ["clipboard", "file", "key"] using_method = 1 input_method = input_methods[using_method] IN = lambda: map(int, input().split()) mod = 1000000007 # +++++ def count_al(al, vv): """ vvv以上を集めた場合、何要素選択されるか。 """ rui = 0 for v in al: r = get_ok_index(v, al, vv) rui += r return rui def get_ok_index(v, al, ok_value): """ ok_value以上の要素数を返す。 """ if v + al[0] < ok_value: return 0 if v + al[-1] >= ok_value: return len(al) ok = 0 ng = len(al) while ok + 1 < ng: # pa((ok,ng)) m = (ok + ng) // 2 if v + al[m] >= ok_value: ok = m else: ng = m # pa((ok,ng)) return ok + 1 def main(): n, m = IN() al = list(IN()) al.sort(reverse=True) if m == n * n: ret = sum(al) * n * 2 ruisekiwa = al.copy() for i, v in enumerate(al[1:], 1): ruisekiwa[i] = ruisekiwa[i - 1] + v pa(ruisekiwa) ok = al[0] * 10 ng = 0 while ok > ng + 1: vv = (ok + ng) // 2 cc = count_al(al, vv) pa(("ok,ng,vv,cc", ok, ng, vv, cc)) if cc <= m: ok = vv else: ng = vv pa(("ok", ok)) ret = 0 for v in al: ok_id = get_ok_index(v, al, ok) - 1 pa(ok_id) if ok_id == -1: continue ret += ruisekiwa[ok_id] + v * (ok_id + 1) ret += (ok - 1) * (m - count_al(al, ok)) print(ret) # +++++ isTest = False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text = clipboard.get() input_l = input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform == "ios": if input_method == input_methods[0]: ic = input_clipboard() input = lambda: ic.__next__() elif input_method == input_methods[1]: sys.stdin = open("inputFile.txt") else: pass isTest = True else: pass # input = sys.stdin.readline ret = main() if ret is not None: print(ret)
Statement Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
[{"input": "5 3\n 10 14 19 34 33", "output": "202\n \n\nLet us say that Takahashi performs the following handshakes:\n\n * In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n * In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n * In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\n* * *"}, {"input": "9 14\n 1 3 5 110 24 21 34 5 3", "output": "1837\n \n\n* * *"}, {"input": "9 73\n 67597 52981 5828 66249 75177 64141 40773 79105 16076", "output": "8128170"}]
Print the maximum possible happiness after M handshakes. * * *
s803997654
Runtime Error
p02821
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N
n, m = map(int, input().split()) l = [int(i) for i in input().split()] k = int(m ** (1 / 2) // 1) - 1 l = sorted(l, reverse=True) suml = sum(l[: k + 1]) * 2 * (k + 1) kk = (k + 1) ** 2 if (m - kk) % 2 == 0: suml += 2 * sum(l[: int((m - kk) // 2)]) + (m - kk) * l[k + 1] else: suml += ( 2 * sum(l[: int((m - kk) // 2)]) + l[int((m - kk) // 2 + 1)] + (m - kk) * l[k + 1] ) print(suml)
Statement Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
[{"input": "5 3\n 10 14 19 34 33", "output": "202\n \n\nLet us say that Takahashi performs the following handshakes:\n\n * In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n * In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n * In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\n* * *"}, {"input": "9 14\n 1 3 5 110 24 21 34 5 3", "output": "1837\n \n\n* * *"}, {"input": "9 73\n 67597 52981 5828 66249 75177 64141 40773 79105 16076", "output": "8128170"}]
Print the maximum possible happiness after M handshakes. * * *
s660730033
Wrong Answer
p02821
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N
n, m = input().split() print(n, m)
Statement Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
[{"input": "5 3\n 10 14 19 34 33", "output": "202\n \n\nLet us say that Takahashi performs the following handshakes:\n\n * In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n * In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n * In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\n* * *"}, {"input": "9 14\n 1 3 5 110 24 21 34 5 3", "output": "1837\n \n\n* * *"}, {"input": "9 73\n 67597 52981 5828 66249 75177 64141 40773 79105 16076", "output": "8128170"}]
Print the maximum possible happiness after M handshakes. * * *
s496597082
Wrong Answer
p02821
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N
print("hellow")
Statement Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a _power_ of A_i. Takahashi has decided to perform M _handshakes_ to increase the _happiness_ of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses one (ordinary) guest x for his left hand and another guest y for his right hand (x and y can be the same). * Then, he shakes the left hand of Guest x and the right hand of Guest y simultaneously to increase the happiness by A_x+A_y. However, Takahashi should not perform the same handshake more than once. Formally, the following condition must hold: * Assume that, in the k-th handshake, Takahashi shakes the left hand of Guest x_k and the right hand of Guest y_k. Then, there is no pair p, q (1 \leq p < q \leq M) such that (x_p,y_p)=(x_q,y_q). What is the maximum possible happiness after M handshakes?
[{"input": "5 3\n 10 14 19 34 33", "output": "202\n \n\nLet us say that Takahashi performs the following handshakes:\n\n * In the first handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 4.\n * In the second handshake, Takahashi shakes the left hand of Guest 4 and the right hand of Guest 5.\n * In the third handshake, Takahashi shakes the left hand of Guest 5 and the right hand of Guest 4.\n\nThen, we will have the happiness of (34+34)+(34+33)+(33+34)=202.\n\nWe cannot achieve the happiness of 203 or greater, so the answer is 202.\n\n* * *"}, {"input": "9 14\n 1 3 5 110 24 21 34 5 3", "output": "1837\n \n\n* * *"}, {"input": "9 73\n 67597 52981 5828 66249 75177 64141 40773 79105 16076", "output": "8128170"}]