code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
import sys sys.setrecursionlimit(10 ** 8) ini = lambda: int(sys.stdin.readline()) inm = lambda: map(int, sys.stdin.readline().split()) inl = lambda: list(inm()) ins = lambda: sys.stdin.readline().rstrip() debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw)) n, m = inm() sc = [tuple(inm()) for i in range(m)] def digits(x): if x < 10: return 1 if x < 100: return 2 return 3 def solve(): for x in range(1000): if digits(x) != n: continue sx = str(x) ok = True for i in range(m): s, c = sc[i] if sx[s - 1] != str(c): ok = False break if ok: return x return -1 print(solve())
n,m=map(int,input().split()) def exit(): import sys print(-1) sys.exit() num=['']*n for s,c in (map(int,input().split()) for i in range(m)): if n>1 and [s,c]==[1,0]: exit() if num[s-1]!='': if num[s-1]==c: continue else: exit() else: num[s-1]=c else: if n==1: print(num[0] if num[0]!='' else 0, end='') else: print(num[0] if num[0]!='' else 1, end='') for i in range(1,n): print(num[i] if num[i]!='' else 0, end='')
1
60,769,265,185,092
null
208
208
N, P = map(int, input().split()) S = input() if P in [2, 5]: ans = 0 for i, s in enumerate(S, 1): if int(s) % P == 0: ans += i print(ans) else: dp = [0] * (N+1) for i, s in enumerate(S, 1): dp[i] = (dp[i-1]*10 + int(s)) % P digit = 1 for i in range(N): j = N - i dp[j] = (dp[j] * digit) % P digit = (digit * 10) % P d = {} ans = 0 for r in dp: if r in d: ans += d[r] d[r] += 1 else: d[r] = 1 print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N = int(readline()) cnt = 0 ans = -1 for _ in range(N): x, y = map(int, readline().split()) if x == y: cnt += 1 ans = max(ans, cnt) else: cnt = 0 if ans >=3: print('Yes') else: print('No') if __name__ == '__main__': main()
0
null
30,408,104,029,952
205
72
def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) s=input() from collections import Counter c=Counter(s) if len(c.keys())>=2: print("Yes") else: print("No")
print('Yes' if ['A','B'] == sorted(set(input())) else 'No')
1
55,087,256,830,400
null
201
201
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 x = list(map(int, readline().split())) print(x.index(0) + 1) if __name__ == '__main__': solve()
# encoding:utf-8 while True: a, op, b = raw_input().split() if op == "?": break a, b = map(int, (a,b)) if op == "+": print(a+b) elif op == "-": print(a-b) elif op == "*": print(a*b) else: print(a/b)
0
null
7,041,220,286,880
126
47
import math #import numpy as np import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): n,p = map(int,ipt().split()) s = input() ans = 0 if p == 2: for i in range(n): if int(s[i])%2 == 0: ans += i+1 print(ans) elif p == 5: for i in range(n): if int(s[i])%5 == 0: ans += i+1 print(ans) else: d = defaultdict(int) pi = 0 nk = 10%p for i in s[::-1]: pi = (pi+int(i)*nk)%p d[pi] += 1 nk = (nk*10)%p for i in d.values(): ans += i*(i-1)//2 ans += d[0] print(ans) return if __name__ == '__main__': main()
k=int(input()) if k==1: print('ACL') elif k==2: print('ACLACL') elif k==3: print('ACLACLACL') elif k==4: print('ACLACLACLACL') elif k==5: print('ACLACLACLACLACL')
0
null
30,126,915,238,180
205
69
#coding:UTF-8 while True: a,op,b = map(str,raw_input().split()) a = int(a) b = int(b) if op == '+': print(a+b) elif op == '-': print(a-b) elif op == '*': print(a*b) elif op == '/': print(a/b) else: break
while True: t = input() if t.find("?") > 0: break print(int(eval(t)))
1
688,891,697,340
null
47
47
n = int(input()) s = [] t = [] for i in range(n): s_, t_ = map(str, input().split()) s.append(s_) t.append(int(t_)) x = input() for i in range(n): if s[i] == x: break ans = 0 for j in range(n-1, i, -1): ans += t[j] print(ans)
import sys import heapq, math from itertools import zip_longest, permutations, combinations, combinations_with_replacement from itertools import accumulate, dropwhile, takewhile, groupby from functools import lru_cache from copy import deepcopy class UnionFind: def __init__(self, n: int): self._n = n self._parents = [i for i in range(n)] self._rank = [1 for _ in range(n)] def unite(self, x: int, y: int) -> None: px = self.find(x) py = self.find(y) # 一致していないときはリンクをつける if px != py: self._link(px, py) def _link(self, x: int, y: int): if self._rank[x] < self._rank[y]: self._parents[x] = y elif self._rank[x] > self._rank[y]: self._parents[y] = x else: self._parents[x] = y self._rank[y] += 1 def same(self, x: int, y: int) -> bool: px = self.find(x) py = self.find(y) return px == py def find(self, x: int) -> int: if self._parents[x] == x: return x self._parents[x] = self.find(self._parents[x]) return self._parents[x] N, M = map(int, input().split()) uf = UnionFind(N + 1) for i in range(M): A, B = map(int, input().split()) uf.unite(A, B) s = set() for i in range(1, N + 1): s.add(uf.find(i)) print(len(s) - 1)
0
null
49,873,473,868,178
243
70
S = input() T = input() ans = 1001 for i in range(len(S)-len(T)+1): ans = min(ans, sum(S[i+j] != T[j] for j in range(len(T)))) print(ans)
s = input() t = input() T = list(t) sl = len(s) tl = len(t) ans = 10**18 for i in range((sl-tl)+1): cnt = 0 S = list(s[i:i+tl]) for a,b in zip(S,T): if a != b: cnt += 1 if ans > cnt: ans = cnt print(ans)
1
3,649,586,193,760
null
82
82
def main(): N, X, Y = map(int, input().split()) count_list = [0] * N for i in range(1, N): for j in range(i + 1, N + 1): distance = min(j-i, abs(j-Y) + abs(i-X) + 1) count_list[distance] += 1 for i in range(1, N): print(count_list[i]) if __name__ == '__main__': main()
#174 A X = input() print('Yes') if int(X)> 29 else print('No')
0
null
24,892,253,579,004
187
95
a=list(map(int,input().split())) if a[0]>a[1]*2: print(a[0]-a[1]*2) else: print('0')
a,b = map(int,(input().split())) result = a - (b * 2) if result <= 0: result = 0 print(result)
1
166,815,295,497,048
null
291
291
L = int(input()) L = L / 3 ans = L * L * L print(ans)
#!/usr/bin/env python from sys import stdin, stderr def main(): S = stdin.readline().strip() if (len(S) % 2) != 0: print('No') return 0 for i in xrange(0, len(S), 2): if S[i:i+2] != 'hi': print('No') return 0 print('Yes') return 0 if __name__ == '__main__': main()
0
null
49,906,459,769,660
191
199
a,b = map(int,input().split()) if a<b: print("a < b") elif a==b: print("a == b") elif a>b: print("a > b")
import string L = string.split(raw_input()) a = int(L[0]) b = int(L[1]) if a == b: print "a == b" elif a > b: print "a > b" elif a < b: print "a < b"
1
364,665,409,328
null
38
38
N = int(input()) A = list(map(int, input().split())) ary = [0]*(N-1) for i in reversed(range(N-1)): if i+1 >= (N-1): ary[i] = A[N-1] else: ary[i] = ary[i+1] + A[i+1] s = 0 for i in range(N-1): s += A[i]*ary[i] print(s%(10**9+7))
import math import collections K = int(input()) S = input() L = list(S) if len(L) <= K: print(S) else: M = L[:K] print(''.join(M)+'...')
0
null
11,711,491,409,280
83
143
#!/usr/bin/env python #-*- coding: utf-8 -*- if __name__ == '__main__': N = int(raw_input()) l = map(int, raw_input().split()) cnt = 0 for i in range(0, N): minj = i for j in range(i, N): if l[j] < l[minj]: minj = j if i != minj: l[i], l[minj] = l[minj], l[i] cnt += 1 print ' '.join(map(str, l)) print cnt
n = int(raw_input()) a = map(int,raw_input().split(' ')) nswap=0 for i in range(n): min_v = a[i] min_p = i for j in range(i,n): if min_v > a[j]: min_v = a[j] min_p = j if min_p != i: a[i],a[min_p]=a[min_p],a[i] nswap+=1 print ' '.join([str(v) for v in a]) print nswap
1
21,130,331,322
null
15
15
n = int(input()) a = set(input().split()) if len(a) == n: print("YES") else: print("NO")
n = int(input()) if n/1.08==n//1.08: print(n//1.08) elif int(-(-n//1.08) * 1.08) == n: print(int(-(-n//1.08))) else: print(':(')
0
null
100,320,637,966,870
222
265
n = int(input()) k = input() final = 0 for i in range(0, n - 1): if k[i] != k[i + 1]: final += 1 print(final + 1)
N = int(input()) S = input() res = "" pre = "" for s in S: if pre != s: res += s pre = s print(len(res))
1
170,258,292,772,188
null
293
293
''' 参考 https://drken1215.hatenablog.com/entry/2020/06/21/224900 ''' N = int(input()) A = list(map(int, input().split())) INF = 10 ** 5 cnt = [0] * (INF+1) Q = int(input()) BC = [] for _ in range(Q): BC.append(list(map(int, input().split()))) for a in A: cnt[a] += 1 total = sum(A) for b, c in BC: total += (c-b) * cnt[b] cnt[c] += cnt[b] cnt[b] = 0 print(total)
n = int(input()) a = list(map(int,input().split())) q = int(input()) bc = [list(map(int,input().split())) for i in range(q)] list = [0]*(10**5) for i in range(n) : list[a[i]-1] += 1 wa = sum(a) for i in range(q) : wa += (bc[i][1]-bc[i][0])*list[bc[i][0]-1] print(wa) list[bc[i][1]-1] += list[bc[i][0]-1] list[bc[i][0]-1] = 0
1
12,184,801,482,480
null
122
122
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) S, T = read().decode('utf-8').rstrip().split() A = [None] * (N+N) A[::2] = S A[1::2] = T ans = ''.join(A) print(ans)
N = int(input()) S,T = input().split() print(''.join([X+Y for (X,Y) in zip(S,T)]))
1
111,792,680,273,220
null
255
255
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def print_array(a): print(" ".join(map(str, a))) def insertion_sort(a, n): print_array(a) for i in range(1, n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j + 1] = a[j] j -= 1 a[j + 1] = v print_array(a) return a def main(): n = int(input()) a = list(map(int, input().split())) b = insertion_sort(a, n) if __name__ == "__main__": main()
s = input() n = len(s) k = int(input()) start = True start_count = 0 start_char = s[0] inside_num = 0 end_count = 0 end_char = "" memory = s[0] count = 1 for i in range(1,n): if s[i] == memory: count += 1 else: if start: start_count = count start = False else: inside_num += count//2 count = 1 memory = s[i] end_count = count end_char = memory ans = 0 if start_char == end_char: if end_count == n: ans = n*k//2 else: ans += inside_num*k ans += (start_count+end_count)//2*(k-1)+start_count//2+end_count//2 else: inside_num += start_count//2 inside_num += end_count//2 ans += inside_num*k print(ans)
0
null
87,276,998,856,110
10
296
N,K,S=map(int,input().split()) ans=[S]*K if S==10**9: ans.extend([S-1]*(N-K)) else: ans.extend([S+1]*(N-K)) print(*ans)
A = int(input()) B = int(input()) for x in range(1, 4): if x not in [A, B]: print(x) break
0
null
101,126,769,126,040
238
254
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub sys.setrecursionlimit(100000) input = sys.stdin.readline INF = 2**62-1 def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input().strip() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap def f(n): r = 2 ret = 1 for i in range(n, n-r, -1): ret *= i for i in range(1, r+1): ret //= i return ret * 2 + n class Bisect: def __init__(self, func): self.__func = func def bisect_left(self, x, lo, hi): while lo < hi: mid = (lo+hi)//2 if self.__func(mid) < x: lo = mid+1 else: hi = mid return lo def bisect_right(self, x, lo, hi): while lo < hi: mid = (lo+hi)//2 if x < self.__func(mid): hi = mid else: lo = mid+1 return lo @mt def slv(N, M, A): A.sort(reverse=True) print(A) b = Bisect(f) i = b.bisect_left(M, 1, N) if f(i) != M: i -= 1 l = f(i) ans = 0 for j in range(i): ans += A[j] * 2 ans += A[j] * (i-1) rem = M - l print(i, l, rem) j = 0 while rem != 0: ans += A[j] + A[i] rem -= 1 if rem == 0: break ans += A[j] + A[i] rem -= 1 if rem == 0: break j += 1 return ans import numpy as np @mt def slv2(N, M, A): C = Counter(A) L = 1 << (max(A).bit_length() + 1) B = [C[i] for i in range(L)] D = np.fft.rfft(B) D *= D E = list(map(int, np.round(np.fft.irfft(D)))) ans = 0 c = 0 i = L - 1 while c != M: n = E[i] if c + n > M: n = M-c c += n ans += i * n i -= 1 return ans def main(): N, M = read_int_n() A = read_int_n() print(slv2(N, M,A)) # N = 10**5 # M = random.randint(1, N**2) # A = [random.randint(1, 10**5) for _ in range(N)] # print(slv(N, M, A)) if __name__ == '__main__': main()
import math #import numpy as np import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): n,m = map(int,ipt().split()) a = [int(i) for i in ipt().split()] a.sort() maa = max(a) pn = [0]*(2*maa+1) pn[0] = n pa = 0 for i in a: for j in range(pa+1,i+1): pn[j] = pn[pa] pn[i+1] = pn[pa]-1 pa = i+1 l = 0 r = 2*maa while l < r: mid = l+(r-l+1)//2 nm = 0 for i in a: if mid <= i: nm += n else: nm += pn[mid-i] if nm >= m: l = mid else: r = mid-1 pt = [0]*(2*maa+1) pp = maa+1 for i in a[::-1]: for j in range(pp-1,i,-1): pt[j] = pt[pp] pt[i] = pt[pp]+i pp = i for j in range(pp-1,-1,-1): pt[j] = pt[pp] ans = 0 sm = 0 for i in a: sm += pn[max(0,l-i)] ans += pt[max(0,l-i)]+pn[max(0,l-i)]*i print(ans-l*(sm-m)) return if __name__ == '__main__': main()
1
108,085,193,145,420
null
252
252
A, B, M = map(int, input().split()) price_A = list(map(int, input().split())) price_B = list(map(int, input().split())) min_A = min(price_A) min_B = min(price_B) ans = min_A + min_B for i in range(M): x, y, c = map(int, input().split()) ans = min(price_A[x-1]+price_B[y-1]-c,ans) print(ans)
A, B, M = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] x = [] y = [] c = [] for _ in range(M): xt, yt, ct = [int(x) for x in input().split()] x.append(xt) y.append(yt) c.append(ct) # 割引券を使わない場合の最小値 ret = min(a) + min(b) # 割引券を使った場合 for i in range(len(x)): t = a[x[i] - 1] + b[y[i] - 1] - c[i] if ret > t: ret = t print(ret)
1
53,986,539,026,810
null
200
200
def main(): import sys import math input = sys.stdin.buffer.readline n = int(input()) A = list(map(int, input().split())) ans = 0 node = 1 max_node = sum(A) for i in range(n+1): ans += node max_node -= A[i] node = min(max_node,(node-A[i])*2) if node < 0: print(-1) exit(0) print(ans) if __name__ == '__main__': main()
a = [] for i in range(0,2): l = list(map(int,input().split())) a.append(l) d = a[1][::-1] print(' '.join(map(str,d)))
0
null
9,831,827,556,642
141
53
while 1: tmp = map(int, raw_input().split()) if tmp[0] == tmp[1] == 0: break else: print " ".join(map(str, sorted(tmp)))
#146_F n, m = map(int, input().split()) s = input()[::-1] ans = [] flg = True cur = 0 while cur < n and flg: for to in range(cur + m, cur, -1): if to > n: continue if s[to] == '0': ans.append(to - cur) cur = to break if to == cur + 1: flg = False if flg: print(*ans[::-1]) else: print(-1)
0
null
69,908,288,525,290
43
274
import sys N, M, L = map(int, raw_input().split()) a = [] b = [] for n in range(N): a.append(map(int, raw_input().split())) for m in range(M): b.append(map(int, raw_input().split())) c = [[0 for l in xrange(L)] for n in xrange(N)] for n in xrange(N): for l in xrange(L): for m in xrange(M): c[n][l] += a[n][m] * b[m][l] for n in xrange(N): for l in xrange(L-1): sys.stdout.write(str(c[n][l])+" ") print c[n][L-1]
h, w = map(int, input().split()) print(1) if h == 1 or w == 1 else print((h * w + 1) // 2)
0
null
26,299,032,302,980
60
196
''' Created on 2020/09/03 @author: harurun ''' from dataclasses import * @dataclass class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def main(): import sys pin=sys.stdin.readline N,M=map(int,pin().split()) uf=UnionFind(N) for i in range(M): A,B=map(int,pin().split()) A-=1 B-=1 uf.union(A, B) ans=0 for j in range(N): ans=max(ans,uf.size(j)) print(ans) return main() #解説AC
n,x,m = map(int, input().split()) #xに何番目にきたかを記録していく。-1じゃなければ一回以上きている table = [-1] * m extra = [] l = 0 total = 0 #table[x]は周期が始まる点 while table[x] == -1: extra.append(x) table[x] = l l += 1 total += x x = (x*x) % m #周期の長さ c = l - table[x] #周期の和 s = 0 for i in range(table[x], l): s += extra[i] ans = 0 #周期がnより長い場合 if n <= l: for i in range(n): ans += extra[i] else: #最初の一週目を足す ans += total n -= l #残りの周期の周の和を足す ans += s*(n//c) n %= c for i in range(n): ans += extra[table[x]+i] print(ans)
0
null
3,418,878,831,914
84
75
#! /usr/bin/python3 m=100 for _ in range(int(input())): m = int(m*1.05+0.999) print(m*1000)
N,K=map(int,input().split()) MOD=int(1e9)+7 dp=[0]*(K+1) for i in range(K): j=K-i dp[j]+=pow(K//j, N, MOD) k=2*j while k<=K: dp[j]=(dp[j]-dp[k]+MOD) % MOD k+=j ans=0 for i in range(1,K+1): ans+=dp[i]*i ans%=MOD print(ans)
0
null
18,502,948,939,748
6
176
import math a, b, x = map(int, input().split()) if a**2 * b <= 2 * x: h = (a**2 * b - x) / a**2 * 2 theta = h / (a**2 + h**2)**0.5 ans = math.degrees(math.asin(theta)) else: h = 2 * x / a / b theta = h / (b**2 + h**2)**0.5 ans = math.degrees(math.acos(theta)) print(ans)
N = int(input()) A = sorted([int(x) for x in input().split()], reverse=True) ans = 0 for i in range(N): if i == 0: continue else: ans += A[i//2] print(ans)
0
null
86,011,084,558,260
289
111
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string import math import time #import random def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def show(*inp,end='\n'): if show_flg: print(*inp,end=end) YN=['Yes','No'] mo=10**9+7 inf=float('inf') l_alp=string.ascii_lowercase u_alp=string.ascii_uppercase ts=time.time() #sys.setrecursionlimit(10**6) input=lambda: sys.stdin.readline().rstrip() show_flg=False #show_flg=True n,m=LI() ## Segment Tree ## ## Initializer Template ## # Range Sum: sg=SegTree(n,0) # Range Minimum: sg=SegTree(n,inf,min,inf) class SegTree: def __init__(self,n,init_val=0,function=lambda a,b:a+b,ide=0): self.n=n self.ide_ele=ide_ele=ide self.num=num=2**(n-1).bit_length() self.seg=seg=[self.ide_ele]*2*self.num self.segfun=segfun=function #set_val for i in range(n): self.seg[i+self.num-1]=init_val #built for i in range(self.num-2,-1,-1) : self.seg[i]=self.segfun(self.seg[2*i+1],self.seg[2*i+2]) def update(self,k,x): k += self.num-1 self.seg[k] = x while k: k = (k-1)//2 self.seg[k] = self.segfun(self.seg[k*2+1],self.seg[k*2+2]) def query(self,p,q): if q<=p: return self.ide_ele p += self.num-1 q += self.num-2 res=self.ide_ele while q-p>1: if p&1 == 0: res = self.segfun(res,self.seg[p]) if q&1 == 1: res = self.segfun(res,self.seg[q]) q -= 1 p = p//2 q = (q-1)//2 if p == q: res = self.segfun(res,self.seg[p]) else: res = self.segfun(self.segfun(res,self.seg[p]),self.seg[q]) return res def __str__(self): # 生配列を表示 rt=self.seg[self.num-1:self.num-1+self.n] return str(rt) s=[int(i) for i in input()] def dp(b,m): # N log (N) N=len(b)-1 n=N+1 sg=SegTree(n,inf,min,inf) sg.update(0,0) dp=[0]+[inf]*(N) for i in range(N): if b[i+1]==1: continue dp[i+1]=sg.query(max(i-m+1,0),i+1)+1 sg.update(i+1,dp[i+1]) #show(seg) show(sg) return dp dp1=dp(s,m) step=dp1[n] if step==inf: print(-1) exit() dp2=dp(s[::-1],m)[::-1] show(dp1,'dp1') move=[0] ans=[] j=1 for i in range(step,0,-1): # N while j<=n and dp2[j]!=i-1: j+=1 move.append(j) for i in range(len(move)-1): ans.append(move[i+1]-move[i]) print(*ans)
N,M = map(int, input().split()) S = list(input()) cnt,cnt1 = 0,0 for s in S: if s == "1": cnt1 += 1 else: cnt = max(cnt, cnt1) cnt1 = 0 if cnt >= M: print(-1) exit() ans = [] pos = N while pos > 0: for m in range(M, 0, -1): if pos - m < 0: continue if S[pos - m] == "1": continue ans.append(m) pos -= m break print(*ans[::-1])
1
138,346,915,578,400
null
274
274
# coding:utf-8 import sys # ??\??? n = int(input()) display = [] for i in range(n): num = i + 1 # 3??§?????????????????´??? if (num % 3 == 0): display.append(num) continue # ????????????????????????3????????????????????´??? original = num while (num != 0): last_digit = int(num % 10) if (last_digit == 3): display.append(original) num = 0 num = int(num / 10) for x in display: sys.stdout.write(' ' + str(x)) print('')
n = int(input()) i = 1 ret = "" while True: x = i if x % 3 == 0: ret += " " + str(i) elif x % 10 == 3: ret += " " + str(i) else: x //= 10 while x != 0: if x % 10 == 3: ret += " " + str(i) break x //= 10 i+=1 if i > n: break print(ret)
1
928,938,706,432
null
52
52
H, W = map(int, input().split()) total = H*W if H == 1 or W == 1: ans = 1 elif total % 2 == 0: ans = total//2 else: total += 1 ans = total//2 print(ans)
import sys from collections import Counter input = sys.stdin.readline def main(): a = input().strip() n = int(input()) l = len(a) b = Counter(a) if len(b) == 1: c = (n * l) // 2 print(c) exit() su = 0 ans = [] for i in range(1, l): if a[i] == a[i - 1]: su += 1 else: ans.append(su + 1) su = 0 ans.append(su + 1) rev = 0 for j in ans: rev += j // 2 if a[0] == a[-1]: dif = ans[0]//2 + ans[-1]//2 - (ans[0]+ans[-1])//2 print(rev*n - dif*(n - 1)) else: print(rev*n) if __name__ == '__main__': main()
0
null
113,001,918,321,788
196
296
import math import sys from decimal import Decimal a,b,c = map(int,input().split()) if c-a-b <= 0: print('No') sys.exit() if Decimal((c-a-b)*(c-a-b) - 4*a*b) > 0: print("Yes") else: print('No')
H, W = [int(x) for x in input().split()] if H == 1 or W == 1: print(1) else: print((H * W + 1) // 2)
0
null
51,371,680,570,980
197
196
# 28 # ALDS_11_C - 幅優先探索 from collections import deque n = int(input()) u_l = [] k_l = [] v_l = [] for i in range(n): _v_l = [] for j, _ in enumerate(input().split()): if j == 0: u_l.append(int(_)) elif j == 1: k_l.append(int(_)) else: _v_l.append(int(_)) v_l.append(_v_l) d_l = [-1]*n d_l[0] = 0 s_dq = deque([1]) while len(s_dq) > 0: _s = s_dq.popleft() _s -= 1 for i in range(k_l[_s]): _v = v_l[_s][i] if d_l[_v-1] == -1: s_dq.append(_v) d_l[_v-1] = d_l[_s] + 1 for _id, _d in zip(range(1,n+1), d_l): print(_id, _d)
n=input() a=map(int,raw_input().split()) b=sorted(a) print b[0],b[-1],sum(a)
0
null
363,275,094,560
9
48
import sys, math from functools import lru_cache from collections import deque sys.setrecursionlimit(500000) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def main(): S = input() for i in range(1, 6): if S == 'hi'*i: print('Yes') return print('No') if __name__ == '__main__': main()
s = input() q = int(input()) f1 = 1 f2 = 2 st = "" se = "" for _ in range(q): q = input().split() if int(q[0]) == 1: f1,f2 = f2,f1 elif int(q[0]) == 2: if int(q[1]) == f1: st = q[2] + st elif int(q[1]) == f2: se += q[2] ans = st + s + se if f1 == 1: print(ans) else: ans = list(ans) ans.reverse() ans = "".join(ans) print(ans)
0
null
55,169,839,066,490
199
204
while True: try: r,c = map(int,raw_input().split()) if r == c == 0: break except EOFError: break array = [] for i in range(r): array.append(map(int,raw_input().split())) # column sum # add a new sum-row c_sum_row = [0 for ii in range(c)] for k in range(c): for j in range(r): c_sum_row[k] += array[j][k] array.append(c_sum_row) # row sum # append sum item to end of each row for k in range(r+1): array[k].append(sum(array[k])) for k in range(r+1): print ' '.join(map(str,array[k]))
N = int(input()) D1, D2 = [], [] for i in range(N): li = list(map(int,input().split())) D1.append(li[0]) D2.append(li[1]) for i in range(N-2): if D1[i]==D2[i] and D1[i+1]==D2[i+1] and D1[i+2]==D2[i+2]: print('Yes') break else: print('No')
0
null
1,936,057,321,120
59
72
from collections import defaultdict N = int(input()) A = list(map(int, input().split())) dic = defaultdict(int) ans = sum(A) for a in A: dic[a] += 1 Q = int(input()) for i in range(Q): b, c = map(int, input().split()) ans -= dic[b] * b ans -= dic[c] * c dic[c] += dic[b] dic[b] = 0 ans += dic[c] * c print(ans)
import sys for stdin in sys.stdin: inlist = stdin.split() a = int(inlist[0]) b = int(inlist[2]) op = inlist[1] if op == "?": break elif op == "+": print(a + b) elif op == "-": print(a - b) elif op == "/": print(a // b) elif op == "*": print(a * b)
0
null
6,446,733,048,480
122
47
# D - Triangles import bisect N=int(input()) Li=list(map(int,input().split())) Li.sort() ans=0 for i in range(N): for j in range (i+1,N): a=Li[i]+Li[j] t=bisect.bisect_left(Li,a) ans+=t-(j+1) print(ans)
import bisect N = int(input()) L = [int(n) for n in input().split()] L = sorted(L) total = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): b = L[j] right_endpoint = bisect.bisect_left(L, a+b, j) total += right_endpoint - j - 1 print(total)
1
171,077,561,265,378
null
294
294
import math a, b, C = map(float, input().split()) S = (a * b * math.sin(math.radians(C))) / 2 L = a + b + (a**2 + b**2 - 2 * a * b * math.cos(math.radians(C)))**0.5 h = b * math.sin(math.radians(C)) print(S) print(L) print(h)
A,B=map(int,input().split()) ma,mi=0,0 ma=max(A,B) mi=min(A,B) if A%B==0 or B%A==0: print(ma) else : for i in range(2,ma+1): if (ma*i)%mi==0: print(ma*i) break i+=(mi-1)
0
null
56,820,767,819,578
30
256
def atc_142b(NK_input: str, hi_input: str) -> int: N, K = map(int, NK_input.split(" ")) hi = [int(i) for i in hi_input.split(" ")] hi = sorted(hi) for i in range(0, len(hi)): if hi[i] >= K: return len(hi) - i return 0 NK_input_value = input() hi_input_value = input() print(atc_142b(NK_input_value, hi_input_value))
# -*- coding: utf-8 -*- N = int(input()) g = N // 2 k = ( N + 1 ) // 2 if N % 2 == 0: print(g) else: print(k)
0
null
119,268,839,540,618
298
206
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop, heapify from functools import reduce, lru_cache 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 TUPLE(): return tuple(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 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N = INT() A = LIST() LR = [[A[-1], A[-1]]] for b in A[::-1][1:]: LR.append([-(-LR[-1][0]//2)+b, LR[-1][1]+b]) LR = LR[::-1] if LR[0][0] <= 1 <= LR[0][1]: pass else: print(-1) exit() ans = 1 tmp = 1 for i, (L, R) in enumerate(LR[1:], 1): tmp = min(2*tmp-A[i], R-A[i]) ans += tmp+A[i] print(ans)
import math a, b, C = map(int, input().split()) print('{0:.4f}'.format(0.5*a*b*math.sin(math.radians(C)))) L = (a+b) + math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(C))) print(L) print('{0:.4f}'.format(math.sin(math.radians(C)) * b))
0
null
9,525,415,369,596
141
30
n=int(input()) m=int(input()) print(6-m-n)
c= '123' a= str(input()) b= str(input()) c= c.replace(a, '') c= c.replace(b, '') print(c)
1
110,961,435,279,640
null
254
254
N=int(input()) for i in range(50000): if int(i*1.08)==N: print(i) exit() print(':(')
def resolve(): from decimal import Decimal N = Decimal(input()) for X in range(1, 50000+1): if (int(X * 1.08) == N): print(X) return print(':(') return resolve()
1
126,080,081,033,572
null
265
265
H, W = map(int, input().split()) Maze = [[1 if a == "#" else 0 for a in input()] for _ in range(H)] DP = [[float('inf')] * W for _ in range(H)] if Maze[0][0] == 1: DP[0][0] = 1 else: DP[0][0] = 0 for i in range(H): for j in range(W): if Maze[i][j] == 1: if i + 1 < H: DP[i+1][j] = DP[i][j] if j + 1 < W: DP[i][j+1] = min(DP[i][j+1], DP[i][j]) if Maze[i][j] == 0: if i + 1 < H: if Maze[i+1][j] != 1: DP[i + 1][j] = DP[i][j] else: DP[i + 1][j] = DP[i][j] + 1 if j + 1 < W: if Maze[i][j + 1] != 1: DP[i][j + 1] = min(DP[i][j + 1], DP[i][j]) else: DP[i][j + 1] = min(DP[i][j + 1], DP[i][j]+1) print(DP[H-1][W-1])
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines read = sys.stdin.buffer.read sys.setrecursionlimit(10 ** 7) INF = float('inf') H, W = map(int, readline().split()) masu = [] for _ in range(H): masu.append(readline().rstrip().decode('utf-8')) # print(masu) dp = [[INF]*W for _ in range(H)] dp[0][0] = int(masu[0][0] == "#") dd = [(1, 0), (0, 1)] # 配るDP for i in range(H): for j in range(W): for dx, dy in dd: ni = i + dy nj = j + dx # はみ出す場合 if (ni >= H or nj >= W): continue add = 0 if masu[ni][nj] == "#" and masu[i][j] == ".": add = 1 dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add) # print(dp) ans = dp[H-1][W-1] print(ans)
1
49,561,799,738,162
null
194
194
N = int(input()) As = sorted(list(map(int, input().split()))) sieve = [True] * 1000001 prev = 0 for i in range(N): if As[i] == prev: sieve[As[i]] = False continue else: prev = As[i] try: for j in range(2, 1000000 // prev + 1): sieve[prev * j] = False except: continue count = 0 As = list(set(As)) for i in range(len(As)): if sieve[As[i]] is True: count += 1 print(count)
n = int(input()) a = list(map(int, input().split())) a.sort() m = a[-1] c = [0] * (m + 1) for ai in a: for i in range(ai, m + 1, ai): c[i] += 1 ans = 0 for ai in a: if c[ai] == 1: ans += c[ai] print(ans)
1
14,382,621,904,908
null
129
129
def main(): N,R=map(int,input().split()) if(N<10): inner=R+100*(10-N) else: inner=R print(inner) if __name__ == '__main__': main()
SN=[5,1,2,6] WE=[4,1,3,6] def EWSN(d): global SN,WE if d == "S" : SN = SN[3:4] + SN[0:3] WE[3] = SN[3] WE[1] = SN[1] elif d == "N": SN = SN[1:4] + SN[0:1] WE[3] = SN[3] WE[1] = SN[1] elif d == "E": WE = WE[3:4] + WE[0:3] SN[3] = WE[3] SN[1] = WE[1] elif d == "W": WE = WE[1:4] + WE[0:1] SN[3] = WE[3] SN[1] = WE[1] dice = list(map(int,input().split(" "))) op = input() for i in op: EWSN(i) print(dice[SN[1] - 1])
0
null
31,797,781,599,680
211
33
s,t=map(str,input().split()) print(t+s,sep='')
ST = list(map(str, input().split())) word = ST[::-1] print("".join(word))
1
102,899,859,099,050
null
248
248
a, b = map(int, input().split()) (x, y) = (a, b) if a<=b else (b, a) for _ in range(y): print(x, end='')
def main(): a, b = input().split() ansA = '' ansB = '' for _ in range(int(b)): ansA += a for _ in range(int(a)): ansB += b if ansA > ansB: print(ansB) elif ansA <= ansB: print(ansA) main()
1
84,110,706,882,070
null
232
232
N, K = map(int, input().split()) *A, = map(int, input().split()) for i in range(N-K): print("Yes" if A[i]<A[i+K] else "No")
# coding: utf-8 import itertools from functools import reduce from collections import deque N, K = list(map(int, input().split(" "))) A = list(map(int, input().split(" "))) for i in range(N): if i > K-1: if A[i] > A[i-K]: print("Yes") else: print("No")
1
7,028,470,105,150
null
102
102
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_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 #from decimal import * N = INT() if N%2: print(0) exit() ans = 0 i = 1 while 1: if 2*5**i <= N: ans += N //(2*5**i) i += 1 else: break print(ans)
import math import sys readline = sys.stdin.readline def main(): n = int(readline().rstrip()) if n % 2 == 1: print(0) else: n = n // 2 num = 0 for i in range(1, 100): num += n // (5 ** i) print(num) if __name__ == '__main__': main()
1
116,434,340,368,818
null
258
258
[N,K,S] = list(map(int,input().split())) cnt = 0 output = [] if S != 10**9: for i in range(K): output.append(S) for i in range(N-K): output.append(S+1) else: for i in range(K): output.append(S) for i in range(N-K): output.append(1) print(*output)
n, k = map(int, input().split()) l = [0 for i in range(k + 1)] ans = 0 mod = 1000000007 for i in range(k, 0, -1): l[i] = pow(k // i, n, mod) tmp = 2 * i while tmp <= k: l[i] -= l[tmp] tmp += i for i in range(k + 1): ans += i * l[i] ans %= mod print(ans)
0
null
64,055,510,750,990
238
176
S=input();N=len(S);print(sum(S[i]!=S[N-i-1] for i in range(N//2)))
s = list(input()) ans = 0 halfidx = int((len(s)/2)) ary = s[0:halfidx] rary = list(reversed(s))[0:halfidx] for i in range(0,halfidx): if (ary[i] != rary[i]): ans = ans + 1 print(ans)
1
120,265,249,254,470
null
261
261
t = int(raw_input()) a = raw_input().split() small = int(a[0]) large = int(a[0]) total = 0 for i in a: v = int(i) if v < small: small = v if v > large: large = v total = total + v print small,large,total
input() x = input() a = x.split() b = list(map(int,a)) print("{} {} {}".format(min(b),max(b),sum(b)))
1
736,538,148,680
null
48
48
#coding:UTF-8 while True: a,op,b = map(str,raw_input().split()) a = int(a) b = int(b) if op == '+': print(a+b) elif op == '-': print(a-b) elif op == '*': print(a*b) elif op == '/': print(a/b) else: break
N,R=input().split() n,r=int(N),int(R) if n>=10: print(r) else: print(r+100*(10-n))
0
null
31,861,992,986,680
47
211
def main(): ## IMPORT MODULE #import sys #sys.setrecursionlimit(100000) #input=lambda :sys.stdin.readline().rstrip() #f_inf=float("inf") #MOD=10**9+7 if 'get_ipython' in globals(): ## SAMPLE INPUT n = 4 S = ['((()))', '((((((', '))))))', '()()()'] else: ## INPUT n = int(input()) #a, b = map(int, input().split()) S = [input() for _ in range(n)] ## SUBMITION CODES HERE def CNT(A): tmp, Min = 0, 0 for a in A: if a == '(': tmp += 1 else: tmp -= 1 Min = min(Min, tmp) return (-Min, tmp-Min) T = [CNT(s) for s in S] pls = [] mis = [] for l, r in T: if l <= r: pls.append((l, r)) else: mis.append((l, r)) pls.sort(key=lambda a: a[0]) mis.sort(key=lambda a: a[1], reverse=True) total = pls + mis levl = 0 for l, r in total: levl -= l if levl < 0: print('No') exit() levl += r print('Yes' if levl == 0 else 'No') main()
(N,) = [int(x) for x in input().split()] brackets = [input() for i in range(N)] delta = [] minDelta = [] for s in brackets: balance = 0 mn = 0 for c in s: if c == "(": balance += 1 else: balance -= 1 mn = min(mn, balance) delta.append(balance) minDelta.append(mn) if sum(delta) == 0: # Want to get balance as high as possible # Take any positive as long there's enough balance to absorb their minDelta # Can sort since anything that works will only increase balance and the ones with worse minDelta comes later posIndices = [i for i in range(N) if delta[i] > 0] posIndices.sort(key=lambda i: minDelta[i], reverse=True) # At the top can take all with zero delta, just need to absorb minDelta eqIndices = [i for i in range(N) if delta[i] == 0] # When going back down, want to preserve existing balance as much as possible but take a hit for stuff that does need to use the balance to absorb minDelta negIndices = [i for i in range(N) if delta[i] < 0] negIndices.sort(key=lambda i: delta[i] - minDelta[i], reverse=True) balance = 0 for i in posIndices + eqIndices + negIndices: if balance + minDelta[i] < 0 or balance + delta[i] < 0: print("No") exit() balance += delta[i] assert balance == 0 print("Yes") else: print("No")
1
23,697,154,368,470
null
152
152
import sys sys.setrecursionlimit(1 << 25) readline = sys.stdin.buffer.readline read = sys.stdin.readline # 文字列読み込む時はこっち import numpy as np from functools import partial array = partial(np.array, dtype=np.int64) zeros = partial(np.zeros, dtype=np.int64) full = partial(np.full, dtype=np.int64) ra = range enu = enumerate def exit(*argv, **kwarg): print(*argv, **kwarg) sys.exit() def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def a_int(): return int(readline()) def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64) def read_matrix(H, W): '''return np.ndarray shape=(H,W) matrix''' lines = [] for _ in range(H): lines.append(read()) lines = ' '.join(lines) # byte同士の結合ができないのでreadlineでなくreadで return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W) 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, readline().split()))) return tuple(map(list, zip(*ret))) def read_tuple(H): '''H is number of rows''' ret = [] for _ in range(H): ret.append(tuple(map(int, readline().split()))) return ret MOD = 10**9 + 7 INF = 2**31 # 2147483648 > 10**9 # default import from collections import defaultdict, Counter, deque from operator import itemgetter, xor, add from itertools import product, permutations, combinations from bisect import bisect_left, bisect_right # , insort_left, insort_right from functools import reduce from math import gcd def lcm(a, b): # 最小公倍数 g = gcd(a, b) return a // g * b # from numba import njit # @njit('(i8,i8,i8[:])',cache=True) N = a_int() XY = read_matrix(N, 2) X = XY[:, 0] Y = XY[:, 1] f0 = X - Y f1 = X + Y print(max(f0.max() - f0.min(), f1.max() - f1.min()))
n=int(input()) l=[list(map(int,input().split())) for i in range(n)] a=10**9 z_max=-1*a z_min=a w_max=-1*a w_min=a for x,y in l: #点のx座標とy座標の和の最大値と最小値の差か座標の差の最大値と最小値の差が答え z_max=max(z_max,x+y) z_min=min(z_min,x+y) w_max=max(w_max,x-y) w_min=min(w_min,x-y) print(max(z_max-z_min,w_max-w_min))
1
3,422,546,112,618
null
80
80
import math point =list(map(float, input().split())) p1 = point[0] p2 = point[1] p3 = point[2] p4 = point[3] l = math.sqrt((p3 - p1)**2 + (p4 - p2)**2) print(l)
import math if __name__ == '__main__': x1, y1, x2, y2 = [float(i) for i in input().split()] d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) print("{0:.5f}".format(d))
1
160,550,885,560
null
29
29
t=int(input()) print("{}:{}:{}".format(t//60**2,t%60**2//60,t%60**2%60))
N,K = list(map(int, input().split())) mod = int(1e9+7) # N+1からK個をとる手法 # だけどmin - maxまで一飛ばしで作れるはずなので引き算でもとめてよい ans = 0 for i in range(K,N+2): ans = (ans + i * (N+1-i) + 1) % mod print(ans)
0
null
16,858,104,889,010
37
170
num = input() num = int(num) print(num**3)
n = int(input()) ns = list(map(int, input().split())) # min, max, sum は関数名なので # 別名を使うとよい min0 = 10000000 max0 = -10000000 sum0 = 0 for x in ns: min0 = min(min0, x) max0 = max(max0, x) sum0 += x print(min0, max0, sum0)
0
null
514,209,643,112
35
48
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) idx_B = M-1 m = sum(B) an = M ans = 0 for a in [0] + A: m += a while idx_B >= 0 and m > K: m -= B[idx_B] idx_B -= 1 an -= 1 if m > K: break if an > ans: ans = an an += 1 print(ans)
def resolve(): N, M, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) def isok(num): if num >= N: anum = N bnum = num-anum else: anum = num bnum = 0 atotal = sum(A[:anum]) btotal = sum(B[:bnum]) if atotal + btotal <= K: return True i = 0 while not (anum-1-i < 0 or bnum+i >= M): atotal -= A[anum-1-i] btotal += B[bnum+i] if atotal + btotal <= K: return True i += 1 return False left = -1 right = N+M+1 while (right - left) > 1: mid = left + (right - left)//2 if isok(mid): left = mid else: right = mid print(left) if '__main__' == __name__: resolve()
1
10,803,548,363,348
null
117
117
N, K = map(int, input().split()) people = [] for i in range(K): _ = input() a = list(map(int, input().split())) people += a print(N - len(set(people)))
N = int(input()) S = input() ans =0 for i in range(2,N): if S[i] == 'C' and S[i-1] == 'B' and S[i-2] == 'A': ans += 1 print(ans)
0
null
61,879,012,455,072
154
245
def main(): A, B, K = map(int, input().split()) r = max(0, A + B - K) a = min(r, B) t = r - a print(t, a) if __name__ == '__main__': main()
a,b,c = [int(hoge) for hoge in input().split()] print("NYoe s"[4*a*b < (c-a-b)**2 and a+b<c::2])
0
null
77,549,741,603,400
249
197
from bisect import * n,m,k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) # Aの累積和を保存しておく # 各Aの要素について、Bが何冊読めるか二分探索する。 # 計算量: AlogB A.insert(0, 0) for i in range(1,len(A)): A[i] += A[i-1] for i in range(1, len(B)): B[i] += B[i-1] ans = 0 for i in range(len(A)): rest_time = k - A[i] if rest_time >= 0: numb = bisect_right(B, rest_time) anstmp = i + numb ans = max(ans, anstmp) print(ans)
import sys import math import itertools import collections from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def main(): N, M, K = NMI() A = NLI() B = NLI() cumsum_A = [0 for _ in range(len(A)+1)] cumsum_B = [0 for _ in range(len(B)+1)] cnt = 0 for n in range(N): cnt += A[n] cumsum_A[n+1] = cnt cnt = 0 for m in range(M): cnt += B[m] cumsum_B[m+1] = cnt ans = 0 b= M for n in range(N+1): remain_K = K - cumsum_A[n] if remain_K < 0: break else: for m in range(b,-1,-1): if cumsum_B[m]> remain_K: continue else: b = m ans = max(ans,n+m) break print(ans) if __name__ == '__main__': main()
1
10,799,980,434,240
null
117
117
n = input() a = n[-1] if a in '3': print('bon') elif a in '0168': print('pon') else: print('hon')
n = int(input()) h = [2,4,5,7,9] p = [0,1,6,8] b = [3] t = n%10 if t in h: print("hon") elif t in p: print("pon") else: print("bon")
1
19,196,887,268,328
null
142
142
from random import random class Node: def __init__(self, key, value:int=-1): self.left = None self.right = None self.key = key self.value = value self.priority = int(random()*10**7) # self.count_partial = 1 self.sum_partial = value class Treap: #Node [left, right, key, value, priority, num_partial, sum_partial] def __init__(self): self.root = None def update(self, node) -> Node: if node.left is None: # left_count = 0 left_sum = 0 else: # left_count = node.left.count_partial left_sum = node.left.sum_partial if node.right is None: # right_count = 0 right_sum = 0 else: # right_count = node.right.count_partial right_sum = node.right.sum_partial # node.count_partial = left_count + right_count + 1 node.sum_partial = left_sum + node.value + right_sum return node def merge(self, left :Node, right:Node): if left is None or right is None: return left if right is None else right if left.priority > right.priority: left.right = self.merge(left.right,right) return self.update(left) else: right.left = self.merge(left,right.left) return self.update(right) # def node_size(self, node:Node) -> int: # return 0 if node is None else node.count_partial def node_key(self, node: Node) -> int: return -1 if node is None or node.key is None else node.key def node_sum(self, node: Node) -> int: return 0 if node is None else node.sum_partial #指定された場所のノードは右の木に含まれる def split(self, node:None, key:int) -> (Node, Node): if node is None: return None,None if key <= self.node_key(node): left,right = self.split(node.left, key) node.left = right return left, self.update(node) else: left,right = self.split(node.right, key) node.right = left return self.update(node),right def insert(self, key:int, value:int =-1): value = value if value > 0 else key left, right = self.split(self.root, key) new_node = Node(key,value) self.root = self.merge(self.merge(left,new_node),right) def erase(self, key:int): # print('erase pos=',pos,'num=',self.search(pos),'num_nodes=',self.root.count_partial) middle,right = self.split(self.root, key+1) # print(middle.value if middle is not None else -1,middle.count_partial if middle is not None else -1,right.value if right is not None else -1,right.count_partial if right is not None else -1) left,middle = self.split(middle, key) # print(left.value if left is not None else -1,left.count_partial if left is not None else -1, middle.value if middle is not None else -1,middle.count_partial if middle is not None else -1,) self.root = self.merge(left,right) def printTree(self, node=None, level=0): node = self.root if node is None else node if node is None: print('level=',level,'root is None') return else: print('level=',level,'k=',node.key,'v=',node.value, 'p=',node.priority) if node.left is not None: print('left') self.printTree(node.left,level+1) if node.right is not None: print('right') self.printTree(node.right,level+1) def find(self, key): #return self.search_recursively(pos,self.root) v = self.root while v: v_key = self.node_key(v) if key == v_key: return v.value elif key < v_key: v = v.left else: v = v.right return -1 def interval_sum(self, left_key, right_key): lt_left, ge_left = self.split(self.root,left_key) left_to_right, gt_right = self.split(ge_left, right_key + 1) res = self.node_sum(left_to_right) self.root = self.merge(lt_left, self.merge(left_to_right, gt_right)) return res def main(): from sys import setrecursionlimit, stdin, stderr from os import environ from collections import defaultdict, deque, Counter from math import ceil, floor from itertools import accumulate, combinations, combinations_with_replacement setrecursionlimit(10**6) dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0 input = lambda: stdin.readline().rstrip() LMIIS = lambda: list(map(int,input().split())) II = lambda: int(input()) P = 10**9+7 INF = 10**18+10 N,D,A = LMIIS() enemies = [] for i in range(N): x, h = LMIIS() enemies.append((x, ceil(h/A))) enemies.sort() bomb = Treap() ans = 0 for i, (x, h) in enumerate(enemies): left = x - D right = x + D remain_h = h - bomb.interval_sum(left, right) if remain_h <= 0: continue ans += remain_h bomb.insert(x + D, remain_h) print(ans) main()
n = int(input()) S = input() distinct = 1 for i in range(1, len(S)): if S[i-1] != S[i]: distinct += 1 print(distinct)
0
null
126,509,795,827,030
230
293
from statistics import median N = int(input()) A = [] B = [] for n in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) #AB = sorted(AB, key=lambda x: x[0]) #print(AB) cenA = median(A) cenB = median(B) if N % 2 == 1: print(int(cenB - cenA + 1)) elif N % 2 == 0: print(int((cenB - cenA)*2 + 1)) else: print('RE')
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) n = int(input()) s = input() if (n % 2 != 0): print("No") exit() for i in range(n//2): if (s[i] != s[n//2 + i]): print("No") exit() print("Yes")
0
null
81,693,958,692,710
137
279
# coding=utf-8 def insertionSort(A, N): print ' '.join(map(str, A)) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print ' '.join(map(str, A)) return A n = int(raw_input().rstrip()) a = map(int, raw_input().rstrip().split()) insertionSort(a, n)
n = int(input()) input_list = [int(x) for x in input().split()] def sort_print(n, input_list): # index[0]~ [n-1]?????§?¨?????????? # ???????????????index??\???????????\?????°???????????°?????\????????????print??? for i in range(n): index = i num = input_list[index] while index-1 >=0 and input_list[index-1] > num: input_list[index] = input_list[index-1] index -= 1 input_list[index] = num result = [str(x) for x in input_list] print(' '.join(result)) sort_print(n, input_list)
1
5,996,257,498
null
10
10
import itertools import math n = int(input()) x = [] num = [] for i in range(n): x.append([int(t) for t in input().split()]) num.append(i) s = 0 for i in itertools.permutations(num): i = list(i) #print(x,i) for j in range(n-1): s += math.sqrt((x[i[j]][0] - x[i[j+1]][0])**2 + (x[i[j]][1] - x[i[j+1]][1])**2) #print(s) s /= math.factorial(n) print(s)
N = int(input()) town = [list(map(int, input().split())) for _ in range(N)] s = 0 for i in range(N): for j in range(N): if i == j: continue s += ((town[i][0] - town[j][0])**2 + (town[i][1] - town[j][1])**2)**0.5 print(s / N)
1
148,859,856,384,522
null
280
280
from collections import deque n, q = map(int, input().split()) ps = [input().split() for _ in range(n)] que = deque(ps) time = 0 while que: p, rest = que.popleft() elapsed = min(q, int(rest)) time += elapsed rest = str(int(rest) - elapsed) if int(rest) > 0: que.append([p, rest]) else: print(p, time)
X = input().split() print(X[2], X[0], X[1])
0
null
19,085,079,702,850
19
178
N = int(input()) S = input() l = [S[i:i+3] for i in range(0, len(S)-2)] print(l.count('ABC'))
def main(): H,W,M = map(int,input().split()) s = [] h_cnt = [0 for i in range(H)] w_cnt = [0 for i in range(W)] for i in range(M): h,w = map(int,input().split()) s.append([h-1,w-1]) h_cnt[h-1] += 1 w_cnt[w-1] += 1 h_m,w_m = max(h_cnt), max(w_cnt) h_mp,w_mp = [],[] for i in range(H): if h_cnt[i] == h_m: h_mp.append(i) for i in range(W): if w_cnt[i] == w_m: w_mp.append(i) f = 0 for i in range(M): if h_cnt[s[i][0]] == h_m and w_cnt[s[i][1]] == w_m: f += 1 if len(w_mp)*len(h_mp)-f<1: print(h_m+w_m-1) else: print(h_m+w_m) if __name__ == "__main__": main()
0
null
51,973,448,266,880
245
89
N, M, Q = map(int, input().split()) cond = [] for i in range(Q): a, b, c, d = map(int, input().split()) cond.append((a - 1, b - 1, c, d)) def dfs(A, head): if len(A) == N: score = 0 for a, b, c, d in cond: if A[b] - A[a] == c: score += d return score ans = 0 for n in range(head, M + 1): ans = max(ans, dfs(A + [n], n)) return ans print(dfs([1], 1))
# -*- coding: utf-8 -*- """ Created on Thu Sep 3 23:43:13 2020 @author: liang """ N ,M ,Q = map(int, input().split()) A = list() lis = list() ans = 0 def make_list(n,m): if n == N: A.append(lis.copy()) return for i in range(m,M+1): lis.append(i) make_list(n+1,i) lis.pop() make_list(0,1) #print(A) calc = [list(map(int,input().split())) for _ in range(Q)] for a in A: tmp = 0 for c in calc: if a[c[1]-1] - a[c[0]-1] == c[2]: tmp += c[3] if tmp > ans: ans = tmp print(ans)
1
27,429,178,790,902
null
160
160
n = int(input()) lis = list(map(int,input().split())) lis = sorted(lis, reverse=True) ans = lis[0] res = [] for i in range(1,n): res.append(lis[i]) res.append(lis[i]) for i in range(n - 2): ans += res[i] print(ans)
import queue ans = 0 N = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) q = queue.Queue() q.put(0) for a in range(len(A)): ans += q.get() q.put(A[a]) if a != 0: q.put(A[a]) print(ans)
1
9,244,841,947,748
null
111
111
a,b,c,k = map(int,input().split()) print(k if k<a else a if a+b>k else a-(k-a-b))
N = int(input()) A = [0]*N B = [0]*N for i in range(N): A[i], B[i] = map(int, input().split()) A = sorted(A) B = sorted(B) if N % 2 == 1: print(B[(N+1)//2-1] - A[(N+1)//2-1] + 1) else: b = B[N//2-1] + B[N//2] a = A[N//2-1] + A[N//2] print(b-a+1)
0
null
19,668,827,484,290
148
137
import sys from itertools import combinations_with_replacement, product import numpy as np def input(): return sys.stdin.readline().rstrip() def main(): n, m, x = map(int, input().split()) data = np.zeros((n,m),int) clist = np.zeros(n, int) ans=10**10 for i in range(n): ca = list(map(int, input().split())) clist[i]=ca[0] data[i]=np.array(ca[1:]) for bit in list(product([0,1],repeat=n)): if all(np.dot(np.array(bit), data)>=x): ans=min(ans,np.dot(np.array(bit),clist.T)) if ans==10**10: print(-1) else: print(ans) if __name__ == '__main__': main()
N,M,X = map(int,input().split()) a = [list(map(int,input().split())) for i in range(N)] d = [] for i in range(2**N): b = [0] * (M+1) e = i for j in range(N): if e >= (2**(N-j-1)) : e -= (2**(N-j-1)) for k in range(M+1): b[k] += a[j][k] c = 1 for j in range(1,M+1): if b[j] < X: c = 0 break if c == 1: d.append(b[0]) if len(d) > 0: ans = min(d) else: ans = -1 print(ans)
1
22,268,843,891,140
null
149
149
def move_dice(d, dir): if(dir == 'N'): d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4] if(dir == 'S'): d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1] if(dir == 'E'): d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2] if(dir == 'W'): d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3] dice = list(map(int, input().split())) command = input() for c in command: move_dice(dice, c) print(dice[0])
x = list(map(int, input().split())) d = list(input()) for i in d: if i == 'S': t=x[1] x[1]=x[0] x[0]=x[4] x[4]=x[5] x[5]=t elif i == 'N': t=x[1] x[1]=x[5] x[5]=x[4] x[4]=x[0] x[0]=t elif i == 'E': t=x[2] x[2]=x[0] x[0]=x[3] x[3]=x[5] x[5]=t elif i == 'W': t=x[2] x[2]=x[5] x[5]=x[3] x[3]=x[0] x[0]=t print(x[0])
1
229,752,297,010
null
33
33
# ABC170 n = int(input()) a = list(map(int, input().split())) a.sort() a_max = max(a) dp = [True for _ in range(a_max+1)] ans = 0 for i in range(n): if dp[a[i]]: for j in range(0, a_max+1, a[i]): dp[j] = False if i > 0: if a[i] == a[i-1]: continue if i < n-1: if a[i] == a[i+1]: continue ans += 1 print(ans)
S = int(input()) h = S // 3600 m = (S % 3600) // 60 s = (S % 3600) % 60 print(str(h) + ':' + str(m) + ':' + str(s))
0
null
7,365,138,076,100
129
37
#coding: UTF-8 N = int(input()) a = [int(input()) for i in range(N)] ans = set() maxv = -9999999999 minv = a[0] for i in range(1,N): if (a[i] - minv) > maxv: maxv = a[i] - minv if a[i] < minv: minv = a[i] print(maxv)
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D sample_input = ''' 3 4 3 2 ''' give_sample_input = False if give_sample_input: sample_input_list = sample_input.split() def input(): return sample_input_list.pop(0) numOfData = int(input()) max_diff = None # minus infty min_val = None # plus infty prev_val = int(input()) for n in range(numOfData-1): val = int(input()) if min_val is None: min_val = prev_val else: min_val = min(prev_val, min_val) if max_diff is None: max_diff = val - min_val else: max_diff = max(val - min_val, max_diff) prev_val = val print(max_diff)
1
13,449,226,422
null
13
13
N = [int(c) for c in input()] dp = 0,1 for n in N: a = min(dp[0]+n,dp[1]+10-n) b = min(dp[0]+n+1,dp[1]+10-(n+1)) dp = a,b print(dp[0])
import sys H = int(next(sys.stdin.buffer)) ans = 0 i = 1 while H > 0: H //= 2 ans += i i *= 2 print(ans)
0
null
75,390,766,930,468
219
228
import sys import time import math def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ N = int(input()) ls = [0] * 50505 for i in range(len(ls)): ls[i] = int(i * 1.08) for i in range(N, 0, -1): if ls[i] == N: print(i) sys.exit() print(':(') # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
sortingThreeNum = list(map(int, input().split())) sortingThreeNum.sort() print(sortingThreeNum[0], sortingThreeNum[1], sortingThreeNum[2])
0
null
63,096,134,125,832
265
40
import sys input=sys.stdin.readline sys.setrecursionlimit(10 ** 8) from itertools import accumulate from itertools import permutations from itertools import combinations from collections import defaultdict from collections import Counter import fractions import math from collections import deque from bisect import bisect_left from bisect import bisect_right from bisect import insort_left import itertools from heapq import heapify from heapq import heappop from heapq import heappush import heapq from copy import deepcopy from decimal import Decimal alf = list("abcdefghijklmnopqrstuvwxyz") ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") #import numpy as np INF = float("inf") #d = defaultdict(int) #d = defaultdict(list) MOD = 10**9+7 N = int(input()) A = list(map(int,input().split())) L = A[0] for i in range(1,N): g = math.gcd(L,A[i]) L = L*A[i]//g ans = 0 L %= MOD for i in range(N): ans += (L*pow(A[i],MOD-2,MOD)) ans %= MOD print(ans)
from sys import stdin input = stdin.readline from fractions import gcd mod = 10**9+7 n = int(input()) a = list(map(int,input().split())) d = 1 for i in range(n): d *= a[i] // gcd(a[i],d) ans = 0 for i in range(n): ans += d//a[i] print(ans%mod)
1
87,835,791,051,192
null
235
235
n = int(input()) fives = [0] if n % 2 == 1: print(0) else: i = 0 while 1: temp5 = (n // (5** (i +1))) //2 if temp5 != 0: fives.append(temp5) i += 1 else: break print(sum(fives))
from fractions import gcd from functools import reduce, lru_cache MOD = 10**9+7 N = int(input()) A = list(map(int, input().split())) def lcm(x, y): return int(x*y)//int(gcd(x, y)) B = [1 for i in range(N)] global_lcm = reduce(lcm, A) % MOD ans = 0 for i in range(N): ans += (global_lcm*pow(A[i], MOD-2, MOD)) % MOD ans %= MOD print(ans)
0
null
101,582,036,774,052
258
235
import sys def main(): lines = sys.stdin.readlines() input_num = 0 ans = [] for line in lines: # print(line) # rm '\n' from string of a line line = line.strip('\n') input_num = int(line) n = input_num # print input_num print "", index_num = 1 flag = 0 while True: # END CHECKNUM if index_num != 1 or flag == 1: if (index_num + 1) > n: break else: index_num += 1 # Go on below else: flag = 1 x = index_num if x % 3 == 0: print index_num, continue if x % 10 == 3: print index_num, continue else: while x > 0: x /= 10 if x % 10 == 3: print index_num, break break if __name__ == "__main__": main()
n = int(input()) i = 1 while i <= n: if i%3 == 0: print(' ' + str(i), end="") else: num = i while 0 < num: if num % 10 == 3: print(' ' + str(i), end="") break num //= 10 i += 1 print()
1
916,822,214,798
null
52
52
H = int(input()) W = int(input()) N = int(input()) ans = 0 num = 0 big = 0 if H < W: big = W else: big = H while num < N: num += big ans += 1 print(ans)
# 2020/08/16 # AtCoder Beginner Contest 030 - A # Input h = int(input()) w = int(input()) n = int(input()) # Calc ans = n // max(h, w) if n % max(h, w) > 0: ans = ans + 1 # Output print(ans)
1
88,783,893,557,888
null
236
236
#coding: utf-8 a, v = map(int,input().split()) b, w = map(int,input().split()) t = int(input()) dist = abs(a-b) dist += (t*w) if dist <= v*t: print('YES') else: print('NO')
import sys a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if v <= w: print('NO') sys.exit() a_b_dist = abs(a-b) v_w_dist = abs(v-w) if v_w_dist * t < a_b_dist: print('NO') sys.exit() print('YES')
1
15,199,029,713,052
null
131
131
s = input() q = int(input()) for _ in range(q): query = list(input().split()) l,r = map(int,query[1:3]) if query[0] == 'replace': p = query[3] s = s[:l] + p + s[r+1:] elif query[0] == 'reverse': s = s[:l] + ''.join(list(reversed(s[l:r+1]))) + s[r+1:] else: print(s[l:r+1])
import math H,W=map(int,input().split()) if W==1: print(1) elif H==1: print(1) else: A=math.ceil(H*W/2) print(A)
0
null
26,340,976,571,490
68
196
N, K, C = map(int, input().split()) S = input() def get_positions(): res = [] i = 0 while i < N and len(res) < K: if S[i] == "o": res.append(i) i = i + C + 1 else: i += 1 return res l = get_positions() S = S[::-1] r = get_positions() for i in range(K): r[i] = N - 1 - r[i] S = S[::-1] lastl = [-1] * (N + 1) for i in range(K): lastl[l[i] + 1] = i for i in range(N): if lastl[i + 1] == -1: lastl[i + 1] = lastl[i] lastr = [-1] * (N + 1) for i in range(K): lastr[r[i]] = i for i in range(N-1, -1, -1): if lastr[i] == -1: lastr[i] = lastr[i + 1] for i in range(N): if S[i] == "x": continue li = lastl[i] ri = lastr[i + 1] cnt = 0 if li != -1: cnt += (li + 1) if ri != -1: cnt += (ri + 1) if li != -1 and ri != -1 and r[ri] - l[li] <= C: cnt -= 1 if cnt >= K: continue print(i + 1)
N, K, C = map(int, input().split()) S = input().rstrip() P = [0]*(N+1) cl, l, cr, r = 0, 1, 0, 1 for i in range(N): if cl > C and S[i] != "x": cl = 0; l += 1 cl += 1 P[i+1] += l if cr > C and S[-1-i] != "x": cr = 0; r += 1 cr += 1 P[N-2-i] += r for i in range(N): if P[i] < K and S[i] == "o": print(i+1)
1
40,561,266,426,032
null
182
182
N = int(input()) cnt = 0 flg = False for _ in range(N): a, b = map(int, input().split()) if a != b: cnt = 0 else: cnt += 1 if cnt >= 3: flg = True if flg: print('Yes') else: print('No')
n=int(input()) alist=[0]*n for i in range(n): a,b=map(int, input().split()) if a==b: alist[i]=alist[max(i-1,0)]+1 if max(alist)>=3: print('Yes') else: print('No')
1
2,472,301,391,392
null
72
72
import sys read = sys.stdin.read T1, T2, A1, A2, B1, B2 = map(int, read().split()) answer = 0 v1 = A1 - B1 v2 = A2 - B2 d = v1 * T1 + v2 * T2 if d == 0: print('infinity') exit() elif v1 * d > 0: print(0) exit() if v1 * T1 % -d == 0: print(v1 * T1 // -d * 2) else: print(v1 * T1 // -d * 2 + 1)
n,x,y=map(int,input().split()) x,y=x-1,y-1 c=[0 for i in range(n-1)] for i in range(n): for j in range(i+1,n): l=min(j-i,abs(i-x)+abs(j-y)+1) c[l-1]+=1 for i in range(n-1): print(c[i])
0
null
87,686,748,579,500
269
187
T=input() N=len(T) l=[] for i in range(N): if T[i]=="?": l.append("D") else: l.append(T[i]) ans="" for i in range(N): ans+=l[i] print(ans)
import sys sys.setrecursionlimit(10**6) input = lambda: sys.stdin.readline().rstrip() inf = float("inf") # 無限 s = input() # question_count = s.count("?") # max_str = {"point":0,"str":""} # for i in range(2**question_count): # swap_str = "" # for j in range(question_count): # if ((i>>j)&1): # swap_str += "P" # else: # swap_str += "D" # check_str = str(s) # for char in range(question_count): # check_str = check_str.replace("?",swap_str[char],1) # point = 0 # point += check_str.count("D") # point += check_str.count("PD") # if max_str["point"] < point: # max_str["point"] = point # max_str["str"] = check_str # print(point,check_str) # print(max_str["str"]) print(s.replace("?","D"))
1
18,450,741,592,482
null
140
140
N = int(input()) A = list(map(int, input().split())) s = 0 for i in range(1, N): if A[i-1] > A[i]: s += A[i-1] - A[i] A[i] = A[i-1] print(s)
Station = [] Station = input() if Station == "AAA": print("No") elif Station == "BBB": print("No") else: print("Yes")
0
null
29,460,551,429,860
88
201
d = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(d)] t = [int(input()) for _ in range(d)] TYPES = 26 history = [-1] * TYPES satisfaction_level = [0] * (d+1) def last(day, i): if history[i] == -1: return 0 else: return history[i] def satisfaction(day, typ): # コンテスト実施記録を更新 history[typ] = day # 満足度の減少 decrease = sum((c[i]*(day-last(day,i)) for i in range(TYPES))) value = s[day-1][typ] - decrease + satisfaction_level[day-1] satisfaction_level[day] = value return value for day, typ in enumerate(t): print(satisfaction(day+1, typ-1))
D = int(input()) C = list(map(int,input().split())) S = [list(map(int,input().split())) for _ in range(D)] # B T = [int(input()) for _ in range(D)] # 初期化 ans = 0 # 満足度 last = [-1]*26 # 満足度を計算 for d in range(D): # 開催するコンテストID contest_id = T[d]-1 # 満足度をプラス ans += S[d][contest_id] # 最終開催日を更新 last[contest_id] = d # 開催されなかったコンテストの処理 for i in range(26): ans -= C[i]*(d - last[i]) # 出力 print(ans)
1
9,978,525,996,700
null
114
114
def main(): from collections import namedtuple from operator import attrgetter Dish = namedtuple('Dish', 'time deliciousness') N, T = map(int, input().split()) dishes = [] for _ in range(N): a, b = map(int, input().split()) d = Dish(time=a, deliciousness=b) dishes.append(d) dishes.sort(key=attrgetter('time')) dp = [0] * T ma = 0 ret = 0 for d in dishes: ret = max(ret, ma + d.deliciousness) for t in range(T - 1, d.time - 1, -1): dp[t] = max(dp[t], dp[t - d.time] + d.deliciousness) ma = max(ma, dp[t]) print(ret) if __name__ == '__main__': main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
n = int(input()) s = input() if n % 2 == 1: print('No') else: m = int(n/2) s1 = s[: m] s2 = s[m: ] if s1 == s2: print('Yes') else: print('No')
0
null
149,482,685,020,640
282
279
N = int(input()) P = [p for p in map(int,input().split())] ans = 0 min_p = P[0] for p in P: if min_p >= p: min_p = p ans += 1 print(ans)
n = int(input()) p = list(map(int,input().split())) c = 0 m = 10**9 for i in range(n): if p[i] < m: m = p[i] c += 1 print(c)
1
85,042,711,567,074
null
233
233
N, K = map(int, input().split()) sunuke = [1] * N for i in range(K): di = int(input()) tmp = map(int, input().split()) for j in tmp: sunuke[j-1] = 0 print(sum(sunuke))
import sys data=int(input()) print(data*data*data)
0
null
12,560,811,833,008
154
35
import sys readline = sys.stdin.readline N,K = map(int,readline().split()) DIV = 998244353 L = [None] * K R = [None] * K for i in range(K): L[i],R[i] = map(int,readline().split()) dp = [0] * (N + 1) sdp = [0] * (N + 1) dp[1] = 1 sdp[1] = 1 for i in range(2, len(dp)): for j in range(K): li = max(i - R[j], 0) ri = i - L[j] if ri < 0: continue dp[i] += (sdp[ri] - sdp[li - 1]) dp[i] %= DIV sdp[i] = sdp[i - 1] + dp[i] sdp[i] %= DIV print(dp[N])
week_list =["","SAT","FRI","THU","WED","TUE","MON","SUN"] print(week_list.index(input()))
0
null
67,981,227,081,500
74
270
num=int(input()) command=[input().split() for i in range(num)] dic={} for i in command: if i[0]=="insert": dic[i[1]]=1 if i[0]=="find": if i[1] in dic: print("yes") else: print("no")
if __name__ == "__main__": n = int(input()) ops = [] words = [] for _ in range(n): op, word = input().split() ops.append(op) words.append(word) db = set() for op, word in zip(ops, words): if op=='insert': db.add(word) else: if word in db: print("yes") else: print("no")
1
79,452,606,860
null
23
23
n = int(input()) s = input() print(sum(int(s[i:i+3] == "ABC") for i in range(n - 2)))
import re n = int(input()) text = input() pattern = "ABC" result = re.findall(pattern, text) print(len(result))
1
99,335,350,097,314
null
245
245
X=int(input()) count=8 for i in range(600,2001,200): if X<i: print(count) exit() count-=1
import sys from fractions import gcd [print("{} {}".format(gcd(*x), x[0] * x[1] // gcd(*x))) for x in [list(map(int, x.split())) for x in sys.stdin]]
0
null
3,326,944,588,110
100
5
# ALDS1_4_C.py N = int(input()) dict = {} for i in range(N): query, s = input().split() if query == "insert": dict[s] = True else: print('yes' if s in dict else 'no')
n = input() dictInProb = set() for i in range(int(n)): cmdAndStr = list(input().split()) if cmdAndStr[0] == "insert": dictInProb.add(cmdAndStr[1]) elif cmdAndStr[0] == "find": if cmdAndStr[1] in dictInProb: print("yes") else: print("no") else: pass
1
78,207,917,678
null
23
23
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') def solve(S: str, T: str): return T+S def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str T = next(tokens) # type: str print(f'{solve(S, T)}') if __name__ == '__main__': main()
import sys from bisect import bisect_right, bisect_left sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) A = list(map(int, input().split())) A_i, A_j = [], [] for i in range(n): A_i.append(-A[i] - (i + 1)) for j in range(n): A_j.append(A[j] - (j + 1)) A_j.sort() res = 0 for a in A_i: idx_1 = bisect_left(A_j, a) idx_2 = bisect_right(A_j, a) res += idx_2 - idx_1 print(res) if __name__ == '__main__': resolve()
0
null
64,845,097,563,172
248
157
N,K=map(int,input().split()) P=list(map(int,input().split())) from itertools import accumulate acc=[0] acc.extend(accumulate(P)) ans=0 for i in range(N-K+1): exp=(acc[K+i]-acc[i]+K)/2 ans=max(exp,ans) print(ans)
N,K=map(int,input().split()) p=list(map(int,input().split())) q=[] q.append(0) for i in range(len(p)): q.append(q[-1]+p[i]) maxi=q[K]-q[0] for i in range(1,N-K+1): sub=q[K+i]-q[i] if sub>=maxi: maxi=sub print((maxi+K)/2)
1
75,264,850,129,060
null
223
223