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
def main(): N = int(input()) A,B = [],[] for _ in range(N): a,b = [int(x) for x in input().split()] A.append(a) B.append(b) A.sort() B.sort() if N % 2 == 1: minMed = A[N//2] maxMed = B[N//2] print(int(maxMed-minMed)+1) else: minMed = A[N//2-1] + A[N//2] maxMed = B[N//2-1] + B[N//2] print(int(maxMed-minMed)+1) if __name__ == '__main__': main()
n = int(input()) A = [] B = [] for i in range(n): a, b = map(int, input().split()) A.append(a) B.append(b) A.sort() B.sort() if n % 2: l = A[n // 2] r = B[n // 2] ans = r - l + 1 print(ans) else: l = A[n // 2 - 1] + A[n // 2] r = B[n // 2 - 1] + B[n // 2] ans = r - l + 1 print(ans)
1
17,455,657,023,012
null
137
137
R, C, K = map(int, input().split()) item = [[0]*C for _ in range(R)] for _ in range(K): r, c, v = map(int, input().split()) item[r-1][c-1] = v dp = [[[0]*C for _ in range(R)] for _ in range(4)] dp[1][0][0] = item[0][0] for h in range(R): for w in range(C): if h!=0: dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w], dp[2][h-1][w], dp[3][h-1][w]) dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w]) if w!=0: dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1]) dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w]) dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w]) dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w]) ans = [] for k in range(4): ans.append(dp[k][-1][-1]) print(max(ans))
f,g,h=range,max,input R,C,K=map(int,h().split()) G=[[0]*-~C for i in f(R+1)] for i in'_'*K:r,c,v=map(int,h().split());G[r][c]=v F=[[[0]*-~C for i in f(R+1)]for i in f(4)] for r in f(1,R+1): for x in f(1,4): for c in f(1,C+1):F[x][r][c]=g(F[x-1][r][c],F[x-1][r][c-1]+G[r][c],F[x][r][c-1],(x<2)*(G[r][c]+g(F[1][r-1][c],F[2][r-1][c],F[3][r-1][c]))) print(F[3][R][C])
1
5,568,023,356,730
null
94
94
N, P = map(int, input().split()) S = [int(x) for x in input()] if P == 2: ans = 0 for i in range(N): if S[N-1-i] % 2 == 0: ans += N-i elif P == 5: ans = 0 for i in range(N): if S[N-1-i] % 5 == 0: ans += N-i else: ans = 0 cnt = [0] * P cnt[0] = 1 dec_mod, pre_mod = 1, 0 for i in range(N): mod = (S[N-1-i] * dec_mod + pre_mod) % P ans += cnt[mod] cnt[mod] += 1 dec_mod = dec_mod * 10 % P pre_mod = mod print(ans)
class SmallLargeOrEqual: def __init__(self, a, b): if a < b: print "a < b" return elif a > b: print "a > b" return else: print "a == b" return if __name__ == "__main__": a,b = map(int,raw_input().split()) SmallLargeOrEqual(a,b)
0
null
29,369,069,847,458
205
38
import sys def read_heights(): current = 0 heights = [current] for c in sys.stdin.read().strip(): current += { '/': 1, '\\': -1, '_': 0 }[c] heights.append(current) return heights heights = read_heights() height_index = {} for i, h in enumerate(heights): height_index.setdefault(h, []).append(i) flooded = [False] * len(heights) floods = [] # search from highest points for h in sorted(height_index.keys(), reverse=True): indexes = height_index[h] for i in range(len(indexes) - 1): start = indexes[i] stop = indexes[i + 1] if start + 1 == stop or flooded[start] or flooded[stop]: continue if any(heights[j] >= h for j in range(start + 1, stop)): continue # flood in (start..stop) floods.append((start, stop)) for j in range(start, stop): flooded[j] = True floods.sort() areas = [] for start, stop in floods: area = 0 top = heights[start] for i in range(start + 1, stop + 1): h = heights[i] area += top - h + (heights[i - 1] - h) * 0.5 areas.append(int(area)) print(sum(areas)) print(' '.join([str(v) for v in [len(areas)] + areas]))
from collections import Counter N = int(input()) As = list(map(int,input().split())) cnt = Counter(As) for i in range(1,N+1): print(cnt[i])
0
null
16,206,218,873,572
21
169
x, y = map(int, input().split()) ans = 0 if x < 4: ans += (4-x)* 100000 if y < 4: ans += (4-y)* 100000 if x + y == 2: ans += 400000 print(ans)
taro = 0 hanako = 0 n = int(input()) for i in range(n): t, h = input().split() if t == h: taro += 1 hanako += 1 elif t > h: taro += 3 else: hanako += 3 print(taro, hanako)
0
null
71,393,538,770,288
275
67
S = input() Q = int(input()) T = 0 s = "" for i in range(Q): q = list(input().split()) if q[0] == "1": T = (T+1) % 2 elif (T == 0 and q[1] == "1") or (T == 1 and q[1] == "2"): s += q[2] else: S += q[2] if T == 0: S = s[::-1] + S print(S) else: S = S[::-1] + s print(S)
# unionfind class Uf: def __init__(self, N): self.p = list(range(N)) self.rank = [0] * N self.size = [1] * N def root(self, x): if self.p[x] != x: self.p[x] = self.root(self.p[x]) return self.p[x] def same(self, x, y): return self.root(x) == self.root(y) def unite(self, x, y): u = self.root(x) v = self.root(y) if u == v: return if self.rank[u] < self.rank[v]: self.p[u] = v self.size[v] += self.size[u] self.size[u] = 0 else: self.p[v] = u self.size[u] += self.size[v] self.size[v] = 0 if self.rank[u] == self.rank[v]: self.rank[u] += 1 def count(self, x): return self.size[self.root(x)] N, M, K = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(M)] CD = [list(map(int, input().split())) for _ in range(K)] uf = Uf(N+1) M = [-1] * (N+1) for a, b in AB: uf.unite(a, b) M[a] -= 1 M[b] -= 1 for c, d in CD: if uf.same(c, d): M[c] -= 1 M[d] -= 1 for i in range(1, N+1): M[i] += uf.count(i) print(" ".join(map(str, M[1:])))
0
null
59,490,147,083,748
204
209
N = int(input()) x = N%10 if x==0 or x==1 or x==6 or x==8: print('pon') elif x==2 or x==4 or x==5 or x==7 or x==9: print('hon') elif x==3: print('bon')
def main(): n = int(input()) S = list(map(int, input().split())) q = int(input()) T = list(map(int, input().split())) res = 0 for i in T: if i in S: res += 1 print(res) if __name__ == '__main__': main()
0
null
9,626,504,852,888
142
22
import sys readline = sys.stdin.readline S = readline().rstrip() DIV = 2019 cur = 0 from collections import defaultdict dic = defaultdict(int) for i in range(len(S) - 1, -1, -1): cur += ((int(S[i]) % DIV) * pow(10, (len(S) - 1 - i), DIV)) % DIV cur %= DIV dic[cur] += 1 ans = 0 # 0は単独でもよい for key, val in dic.items(): if key == 0: ans += val ans += (val * (val - 1)) // 2 print(ans)
in_str = input().split(" ") a = int(in_str[0]) b = int(in_str[1]) if a > b: print("a > b") elif a < b: print("a < b") else: print("a == b")
0
null
15,491,123,448,320
166
38
def main(): N,K=map(int,input().split()) A=[0]+list(map(int,input().split())) for i in range(K+1,N+1): if A[i]>A[i-K]: print("Yes") else: print("No") if __name__=='__main__': main()
import math import sys import itertools from collections import deque # import numpy as np def main(): n = int(input()) d = deque() for _ in range(n): order = input().split() if order[0] == 'insert': d.appendleft(order[1]) elif order[0] == 'delete': try: d.remove(order[1]) except ValueError: pass elif order[0] == 'deleteFirst': d.popleft() elif order[0] == 'deleteLast': d.pop() print(*d) if __name__ == '__main__': main()
0
null
3,605,614,500,642
102
20
#dp[n][t]=max(dp[n-1][t],dp[n-1][t-A[n]]+B[n]) #dp[0][t]=0, dp[n][0]=0,0<=t<=T+max(B)-1, 0<=n<=N def solve(): N, T = map(int, input().split()) X = [list(map(int, input().split())) for _ in range(N)] X.sort() dp = [[0]*(T+3000) for _ in range(N+1)] for n in range(1,N+1): for t in range(1,T+X[n-1][0]): dp[n][t]=dp[n-1][t] if t>=X[n-1][0]: dp[n][t]=max(dp[n][t],dp[n-1][t-X[n-1][0]]+X[n-1][1]) ans = max(dp[N]) return ans print(solve())
n,t=map(int,input().split()) ab=[[0]*2 for i in range(n+1)] for i in range(1,n+1): ab[i][0],ab[i][1]=map(int,input().split()) dp=[[0]*(t+3001) for i in range(n+1)] ab.sort(key=lambda x:x[0]) for i in range(1,n+1): for j in range(t): dp[i][j]=max(dp[i][j],dp[i-1][j]) dp[i][j+ab[i][0]]=max(dp[i][j+ab[i][0]],dp[i-1][j]+ab[i][1]) ans=0 for i in range(n+1): ans=max(ans,max(dp[i])) print(ans)
1
151,121,787,436,970
null
282
282
s = input() start, count, end = 0, 0, len(s)-1 while(start < end): if (s[start] != s[end]): count += 1 start += 1; end -= 1 else: start += 1; end -= 1 else: print(count)
import sys input = sys.stdin.readline s = list(input()) a = 0 #print(len(s)) for i in range((len(s) - 1) // 2): #print(s[i], s[-2-i]) if s[i] != s[-2-i]: a += 1 print(a)
1
119,810,079,756,272
null
261
261
import sys import itertools import collections def search(H, W, S, start): wall_i = ord(b'#') used = [[-1 for h in range(W)] for w in range(H)] qu = collections.deque() qu.append(start) used[start[0]][start[1]] = 0 while qu: h, w = qu.popleft() cost = used[h][w] for h0, w0 in ((h - 1, w), (h + 1, w), (h, w - 1), (h, w + 1)): if not (0 <= h0 < H and 0 <= w0 < W): continue if used[h0][w0] != -1: continue if S[h0][w0] == wall_i: continue used[h0][w0] = cost + 1 qu.append((h0, w0)) return max(cost for costs in used for cost in costs) def resolve(in_): H, W = map(int, next(in_).split()) S = tuple(s.strip() for s in itertools.islice(in_, H)) road_i = ord(b'.') roads = [] for h in range(H): for w in range(W): if S[h][w] == road_i: roads.append((h, w)) ans = max(search(H, W, S, start) for start in roads) return ans def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
import itertools n, m = [int(w) for w in input().split()] wa_n = [0] * n ac_n = [0] * n for i in range(m): p, s = input().split() p = int(p) - 1 if s == "AC": ac_n[p] = 1 else: if ac_n[p] == 1: continue else: wa_n[p] += 1 print(sum(ac_n), sum(list(itertools.compress(wa_n, ac_n))))
0
null
93,688,459,073,952
241
240
from collections import deque def bfs(y,x): q=deque([(y,x)]) visited[y][x]=0 while q: cy,cx=q.popleft() for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]: ny,nx=cy+dy,cx+dx if 0<=ny<h and 0<=nx<w and visited[ny][nx]==-1: if s[ny][nx]=="#":continue visited[ny][nx]=visited[cy][cx]+1 q.append((ny,nx)) res=0 for i in range(h): for j in range(w): if s[i][j]!="#": res=max(res,visited[i][j]) return res h,w=map(int,input().split()) s=[input() for _ in range(h)] ans=0 for i in range(h): for j in range(w): if s[i][j]=="#":continue sh=i sw=j visited=[[-1]*w for _ in range(h)] ans=max(ans,bfs(sh,sw)) print(ans)
from collections import deque def main(): H, W = map(int, input().split()) field = "#"*(W+2) field += "#" + "##".join([input() for _ in range(H)]) + "#" field += "#"*(W+2) INF = 10**9 cost = [INF]*len(field) move = [-1, 1, -(W+2), W+2] def bfs(s, g): q = deque() dequeue = q.popleft enqueue = q.append cost[s] = 0 enqueue(s) while q: now = dequeue() now_cost = cost[now] for dx in move: nv = now + dx if nv == g: cost[g] = now_cost + 1 return if field[nv] == "#" or cost[nv] < INF: continue else: cost[nv] = now_cost + 1 q.append(nv) ans = 0 for si in range(H): for sj in range(W): for gi in range(H): for gj in range(W): start = (si+1)*(W+2)+sj+1 goal = (gi+1)*(W+2)+gj+1 if field[start] == "#" or field[goal] == "#" or start == goal: continue cost = [INF] * len(field) bfs(start, goal) ans = max(ans, cost[goal]) print(ans) if __name__ == "__main__": main()
1
94,385,312,926,450
null
241
241
N, M = map(int, input().split()) parent = [-1] * N def get_group_root(x): if parent[x] < 0: return x return get_group_root(parent[x]) for i in range(0, M): A, B = map(int, input().split()) A -= 1 B -= 1 groupA = get_group_root(A) groupB = get_group_root(B) if groupA == groupB: continue elif parent[groupA] < parent[groupB]: parent[groupB] = A parent[groupA] -= 1 else: parent[groupA] = B parent[groupB] -= 1 def check(x): return x < 0 print(sum(list(map(check, parent))) - 1)
import sys import math input=sys.stdin.buffer.readline h,w=map(int,input().split()) ans=math.ceil(h*w/2) print(1 if min(h,w)==1 else ans)
0
null
26,484,905,135,868
70
196
n = str(input()) if(n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] == "7" or n[-1] == "9"): print("hon") elif(n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8"): print("pon") else: print("bon")
N = str(input()) N = N[::-1] if N[0] == '2' or N[0] =='4' or N[0] =='5' or N[0] =='7' or N[0] =='9' : print('hon') elif N[0] == '0' or N[0] =='1' or N[0] =='6' or N[0] =='8' : print('pon') else: print('bon')
1
19,366,756,691,470
null
142
142
n = input() n = int(n) seq = input().split() sumNum = 0 minNum = 1000000 maxNum = -1000000 for numT in seq: num = int(numT) if(num > maxNum): maxNum = num if(num < minNum): minNum = num sumNum+=num print(minNum,maxNum,sumNum)
n = input() l = map(int, raw_input().split()) max = l[0] min = l[0] s = 0 for i in range(n): if max < l[i]: max = l[i] if min > l[i]: min = l[i] s = s + l[i] print min, max, s
1
725,588,241,208
null
48
48
n = int(input()) s = list(input() for _ in range(n)) keihin = set() for i in s: keihin.add(i) print(len(keihin))
n=int(input()) lst={} for i in range(n): lst[input()]=1 print(len(lst))
1
30,417,504,565,328
null
165
165
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): S = input() Q = II() direction = 1 pre = [] sur = [] for i in range(Q): query = input() if query == '1': direction *= -1 else: _, f, c = query.split() if direction == 1: if f == '1': pre.append(c) else: sur.append(c) else: if f == '1': sur.append(c) else: pre.append(c) if direction == 1: ans = "".join(pre[::-1]) + S + "".join(sur) else: ans = "".join(sur[::-1]) + "".join(S[::-1]) + "".join(pre) print(ans) main()
a, b, c, d = list(map(int, input().split())) turn = True while True: if turn: c -= b if c <= 0: print("Yes") import sys sys.exit() else: a -= d if a <= 0: print("No") import sys sys.exit() turn ^= True
0
null
43,476,328,095,592
204
164
#!/usr/bin/env python # -*- coding: utf-8 -*- var = int(raw_input()) h = str(var / 3600) ms = var % 3600 m = str(ms / 60) s = str(ms % 60) print ":".join([h, m, s])
import itertools N=int(input()) L=list(map(int,input().split())) c=0 if len(L) >=3: for v in itertools.combinations(L, 3): if (v[0] != v[1] and v[1] != v[2]) and v[0] != v[2]: if sorted(v)[-2]+min(v) > max(v): c=c+1 else: c=c else: c=c else: c=0 print(c)
0
null
2,675,901,558,560
37
91
import math x1, y1, x2, y2 = list(map(float, input().split())) x = x2 - x1 y = y2 - y1 ans = math.sqrt(pow(x, 2) + pow(y, 2)) print(ans)
import queue h,w,m = ( int(x) for x in input().split() ) h_array = [ 0 for i in range(h) ] w_array = [ 0 for i in range(w) ] ps = set() for i in range(m): hi,wi = ( int(x)-1 for x in input().split() ) h_array[hi] += 1 w_array[wi] += 1 ps.add( (hi,wi) ) h_great = max(h_array) w_great = max(w_array) h_greats = list() w_greats = list() for i in range( h ): if h_array[i] == h_great: h_greats.append(i) for i in range( w ): if w_array[i] == w_great: w_greats.append(i) ans = h_great + w_great - 1 escaper = False for i in range( len(h_greats) ): hi = h_greats[i] for j in range( len(w_greats) ): wi = w_greats[j] if (hi,wi) not in ps: ans += 1 escaper = True break if escaper: break print(ans)
0
null
2,432,563,839,092
29
89
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall # from decimal import Decimal # from collections import defaultdict, deque sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L, R = [0] * (n1 + 1), [0] * (n2 + 1) for i in range(n1): L[i] = A[left + i] for i in range(n2): R[i] = A[mid + i] L[n1] = float('INF') R[n2] = float('INF') i, j = 0, 0 compare_cnt = 0 for k in range(left, right): compare_cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 return compare_cnt def merge_sort(A, left, right): cnt = 0 if left + 1 < right: mid = (left + right) // 2 cnt += merge_sort(A, left, mid) cnt += merge_sort(A, mid, right) cnt += merge(A, left, mid, right) return cnt def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() A = il() cnt = merge_sort(A, 0, N) print(*A) print(cnt) if __name__ == '__main__': main()
"""Merge Sort.""" def merge(A, left, mid, right): """Merge the two sorted partial sequences A[left:mid] and A[mid:right]. To count the number of comparisons, make a global declaration for the variable cnt. """ L = A[left:mid] L.append(10**9 + 1) R = A[mid:right] R.append(10**9 + 1) i = 0 j = 0 global cnt for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): """Sort elements in list A using Merge Sort algorithm. left is the starting index, initially 0. right is the value added 1 to the last index, initially the length of A. """ if left + 1 < right: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) n = int(input()) S = list(map(int, input().split())) cnt = 0 mergeSort(S, 0, n) print(*S) print(cnt)
1
114,359,952,320
null
26
26
n, m = map(int, input().split()) temp = list(['?'] * n) # print(temp) if (m == 0): if (n == 1): ans = 0 else: ans = '1' + '0' * (n - 1) else: for _ in range(m): s, c = map(int, input().split()) if (s == 1 and c == 0 and n >= 2): print(-1) exit() else: pass if (temp[s-1] == '?'): temp[s - 1] = str(c) elif (temp[s - 1] == str(c)): pass else: print(-1) exit() if (temp[0] == '?'): temp[0] = '1' ans01 = ''.join(temp) ans = ans01.replace('?', '0') print(ans)
n, m = map(int, input().split()) number = [0] * n cou = [0] * n #logging.debug(number)# for i in range(m): s, c = map(int, input().split()) s -= 1 if cou[s] > 0 and c != number[s]: print(-1) exit() else: cou[s] += 1 number[s] = c #logging.debug("number = {}, cou = {}".format(number, cou)) if n > 1 and number[0] == 0 and cou[0] >= 1: print(-1) exit() elif n > 1 and number[0] == 0: number[0] = 1 number = map(str, number) print(''.join(number))
1
60,626,313,987,640
null
208
208
import sys K, X = map(int, sys.stdin.readline().strip().split()) if K * 500 >= X: print('Yes') else: print('No')
icase=0 if icase==0: k,x=map(int,input().split()) if 500*k>=x: print("Yes") else: print("No")
1
97,842,956,703,770
null
244
244
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd 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 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 X = INT() l = [400, 600, 800, 1000, 1200, 1400, 1600, 1800] print(9-bisect(l, X))
N = int(input()) p = list(map(int,input().split())) q = list(map(int,input().split())) import itertools l = list(itertools.permutations(range(1,N+1))) a = 0 b = 0 for i in range(len(l)): s = [i for i in l[i]] if s == p: a = i if s == q: b = i print(abs(a-b))
0
null
53,474,140,787,912
100
246
data = input().split() a = int(data[0]) b = int(data[1]) c = int(data[2]) if a > b or a < 1 or c > 10000: exit() cnt = 0 for num in range(a,b+1): if (c%num) == 0: cnt += 1 print(cnt)
import sys a, b, c = [ int( val ) for val in sys.stdin.readline().split( ' ' ) ] cnt = 0 i = a while i <= b: if ( c % i ) == 0: cnt += 1 i += 1 print( "{}".format( cnt ) )
1
557,056,978,888
null
44
44
debt=100000 week=input() for i in range(week): debt=debt*1.05 if debt%1000!=0: debt=int(debt/1000)*1000+1000 print debt
a=100000 n=int(input()) for i in range(n): a=a*1.05 if a%1000 !=0: a=a-(a%1000)+1000 print(int(a))
1
1,306,375,190
null
6
6
import sys #import string #from collections import defaultdict, deque, Counter #import bisect #import heapq #import math #from itertools import accumulate #from itertools import permutations as perm #from itertools import combinations as comb #from itertools import combinations_with_replacement as combr #from fractions import gcd #import numpy as np stdin = sys.stdin sys.setrecursionlimit(10 ** 7) MIN = -10 ** 9 MOD = 10 ** 9 + 7 INF = float("inf") IINF = 10 ** 18 def solve(): #n = int(stdin.readline().rstrip()) h,n = map(int, stdin.readline().rstrip().split()) A = list(map(int, stdin.readline().rstrip().split())) #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin] #word = [stdin.readline().rstrip() for _ in range(n)] #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)] #zeros = [[0] * w for i in range(h)] s = sum(A) if h <= s: print("Yes") else: print("No") if __name__ == '__main__': solve()
K = int(input()) string = 'ACL' for i in range(K - 1): string = string + 'ACL' print(string)
0
null
40,237,576,424,672
226
69
nb = int(input()) sentence = input() if len(sentence) > nb: print(sentence[0:nb] + '...') else: print(sentence)
X=int(input()) a=int(X/500) s=1000*a X-=500*a b=int(X/5) s+=5*b print(s)
0
null
31,422,898,373,918
143
185
import itertools import math s, w = map(int, input().split()) if s <= w: print("unsafe") else: print("safe")
s = list(input()) k = int(input()) n = len(s) ans = 0 # すべて同じ文字の場合 if s == [s[0]] * n: print((n*k)//2) exit(0) # 先頭と末尾が異なる場合 i = 1 while i < n: if s[i-1] == s[i]: t = 2 i+=1 while i < n and s[i-1] == s[i]: t+=1 i+=1 ans += (t//2)*k i+=1 if s[0] != s[-1]: print(ans) exit(0) # 先頭と末尾が一致する場合 # まず不一致の場合と同様に数えて、左右端の連続長さを数える # 連結したとき、左右の1ブロックのみはそのまま数えられる # 残りのk-1ブロックは、左右がつながった形で数えられる i = 1 left = 1 right = 1 for i in range(n): if s[i] == s[i+1]: left += 1 else: break for i in range(n-1, -1, -1): if s[i] == s[i-1]: right += 1 else: break if s[0] == s[-1]: ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2) print(ans)
0
null
102,364,776,773,692
163
296
n,s=map(int,input().split()) a=list(map(int,input().split())) d=[[0]*(s+1) for _ in range(n+1)] d[0][0]=1 for j in range(0,s+1): for i in range(1,n+1): d[i][j]=2*d[i-1][j] if a[i-1]<=j: d[i][j]+=d[i-1][j-a[i-1]] d[i][j]=d[i][j]%998244353 print(d[n][s])
mod=998244353 n,s=map(int,input().split()) ar=list(map(int,input().split())) dp=[0 for y in range(s+1)] dp[0]=1 for i in range(n): for j in range(s,-1,-1): if j+ar[i]<=s: dp[j+ar[i]]=(dp[j]+dp[j+ar[i]])%mod dp[j]=(dp[j]*2)%mod print(dp[s])
1
17,747,201,966,748
null
138
138
import sys input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return input().rstrip().decode() def II(): return int(input()) def FI(): return float(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() from heapq import * def main(): n,d,a=MI() Q=[] heapify(Q) for _ in range(n): x=LI() heappush(Q,x) ans=0 now=0 li=[[10**10,0]] heapify(li) while Q: #print(Q,li,ans,now) if Q[0][0]<li[0][0]: x,h=heappop(Q) if h-now>0: k=(h-now-1)//a+1 ans+=k now+=k*a heappush(li,[x+2*d+1,-k*a]) else: x,h=heappop(li) now+=h print(ans) if __name__ == "__main__": main()
from math import ceil def binary(N,LIST,num): # 二分探索 # N:探索要素数 l, r = -1, N while r - l > 1: if LIST[(l + r) // 2] > num: # 条件式を代入 r = (l + r) // 2 else: l = (l + r) // 2 return r + 1 n, d, a = map(int, input().split()) xh = sorted(list(map(int, input().split())) for _ in range(n)) x = [i for i, j in xh] h = [j for i, j in xh] bomb, bsum, ans = [0] * (n + 1), [0] * (n + 1), 0 for i, xi in enumerate(x): j = binary(n, x, xi + 2 * d) - 1 bsum[i] += bsum[i - 1] + bomb[i] bnum = max(ceil(h[i] / a - bsum[i]), 0) bomb[i] += bnum bomb[j] -= bnum bsum[i] += bnum ans += bnum print(ans)
1
82,163,261,695,580
null
230
230
n,m=map(int,input().split()) a=[0]*n ans=0 for i in range(m): p,s=input().split() p=int(p)-1 if a[p]!=1: if s=='WA':a[p]-=1 else: ans-=a[p] a[p]=1 for i in range(n): a[i]=max(a[i],0) print(sum(a),ans)
import sys def resolve(in_): N, M = map(int, next(in_).split()) PS = tuple(line.strip().split() for line in in_) ac = set() wa = {} for p, s in PS: if s == 'AC': ac.add(p) if s == 'WA' and p not in ac: wa[p] = wa.setdefault(p, 0) + 1 penalties = 0 for k, v in wa.items(): if k in ac: penalties += v return '{} {}'.format(len(ac), penalties) def main(): answer = resolve(sys.stdin) print(answer) if __name__ == '__main__': main()
1
93,845,729,158,870
null
240
240
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(500000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def calc(p, P): ans = 0 for i in range(1, len(p)): x1, y1 = P[p[i - 1]] x2, y2 = P[p[i]] ans += sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2) return ans def solve(): N = int(input()) P = [] for _ in range(N): X, Y = map(int, input().split()) P.append((X, Y)) ans = 0 num = 0 for p in permutations(range(N)): ans += calc(p, P) num += 1 print(ans / num) def main(): solve() if __name__ == '__main__': main()
S = input() count = 0 ans = 0 for i in range(3): if S[i] == "R": count += 1 ans = max(ans, count) else: ans = max(ans, count) count = 0 print(ans)
0
null
76,524,674,803,900
280
90
k = int(input()) for i in range(k):print("ACL",end="")
import copy n = int(input()) c = input().split() c_sel = copy.deepcopy(c) # check stability of default array ord_dict_def = {} for i in range(n) : if int(c[i][1]) in ord_dict_def.keys() : ord_dict_def[int(c[i][1])] += c[i][0] else : ord_dict_def[int(c[i][1])] = c[i][0] # do bubble for i in range(n) : for j in range(n - 1, i, -1) : if int(c[j - 1][1]) > int(c[j][1]) : c[j - 1], c[j] = c[j], c[j - 1] # check stability for bubble ord_dict_bubble = {} for i in range(n) : if int(c[i][1]) in ord_dict_bubble.keys() : ord_dict_bubble[int(c[i][1])] += c[i][0] else : ord_dict_bubble[int(c[i][1])] = c[i][0] # do selection for i in range(n) : cmin = i for j in range(i + 1, n) : if int(c_sel[j][1]) < int(c_sel[cmin][1]) : cmin = j if i != cmin : c_sel[i], c_sel[cmin] = c_sel[cmin], c_sel[i] # check stability for selection ord_dict_selection = {} for i in range(n) : if int(c_sel[i][1]) in ord_dict_selection.keys() : ord_dict_selection[int(c_sel[i][1])] += c_sel[i][0] else : ord_dict_selection[int(c_sel[i][1])] = c_sel[i][0] stability_bubble = "Stable" stability_selection = "Stable" for i in ord_dict_bubble.keys() : if ord_dict_def[i] != ord_dict_bubble[i] : stability_bubble = "Not stable" if ord_dict_def[i] != ord_dict_selection[i] : stability_selection = "Not stable" print(" ".join(c)) print(stability_bubble) print(" ".join(c_sel)) print(stability_selection)
0
null
1,127,976,854,718
69
16
import math r = float(input()) print("{} {}".format(r*r*math.pi,r*2*math.pi))
r = float(input()) pi = 3.141592653589793 print(pi*r**2, 2*pi*r)
1
635,737,416,718
null
46
46
def main(): a,b,c = map(str,input().split()) print(c + ' ' + a + ' ' + b) main()
def main(): N = int(input()) A = list(map(int, input().split(' '))) A, count = selectionSort(A, N) print(' '.join([str(a) for a in A])) print(count) def selectionSort(A, N): count = 0 for i in range(0, N-1): minj = i for j in range(i, N): if A[j] < A[minj]: minj = j if i != minj: A[i], A[minj] = A[minj], A[i] count += 1 return A, count if __name__ == '__main__': main()
0
null
19,005,167,212,262
178
15
# coding: utf-8 import string d = {} for ch in list(string.ascii_lowercase): d[ch] = 0 while True: try: s = list(input().lower()) except EOFError: break for ch in s: if ch.isalpha(): d[ch] += 1 else: pass for k, v in sorted(d.items()): print('{} : {}'.format(k, v))
bil_date = [] flag = 0 for i in range(4): bil_date.append([[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]) all_date_amo = int(input()) for i in range(all_date_amo): date = [int(indate) for indate in input().split()] bil_date[date[0]-1][date[1]-1][date[2]-1] = bil_date[date[0]-1][date[1]-1][date[2]-1] + date[3] if bil_date[date[0]-1][date[1]-1][date[2]-1] < 0: bil_date[date[0]-1][date[1]-1][date[2]-1] = 0 if bil_date[date[0]-1][date[1]-1][date[2]-1] > 9: bil_date[date[0]-1][date[1]-1][date[2]-1] = 9 for bil in bil_date: for flo in bil: for room in flo: print(' {}'.format(room),end='') print('') if flag == 3: pass else: for i in range(20): print('#',end='') print('') flag = flag + 1
0
null
1,393,264,162,968
63
55
import math a, b, x = map(float, input().split()) if x < a*a*b/2: print(math.degrees(math.atan(a*b*b/(2*x)))) else: print(math.degrees(math.atan(2*((a*a*b-x)/a**3))))
n=int(input()) if n%1000!=0: print(1000-n%1000) else: print(0)
0
null
85,984,353,652,672
289
108
S,W = map(int,input().split()) if W >= S: print("unsafe") if W < S: print("safe")
combined = input().split(" ") s = int(combined[0]) w = int(combined[1]) if w >= s: print("unsafe") else: print("safe")
1
29,162,850,459,408
null
163
163
N=int(input()) S=input() print(bytes((s-65+N)%26+65 for s in S.encode()).decode())
N = int(input()) S = input() print(''.join([chr((ord(s) - ord('A') + N) % 26 + ord('A')) for s in S]))
1
134,411,366,931,172
null
271
271
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)
N=int(input()) A=list(map(int,input().split())) A.sort(reverse=True) cnt=2 ans=A[0] i=1 while cnt<N: ans+=A[i] if (cnt+1)%2==0: i+=1 cnt+=1 print(ans)
0
null
47,179,469,092,994
233
111
import sys input = sys.stdin.readline read = sys.stdin.read n, t = map(int, input().split()) m = map(int, read().split()) AB = sorted(zip(m, m)) A, B = zip(*AB) dp = [[0]*t for _ in range(n+1)] for i, a in enumerate(A[:-1]): for j in range(t): if j < a: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = max(dp[i][j-a]+B[i], dp[i][j]) ans = 0 maxB = [B[-1]]*n for i in range(n-2, 0, -1): maxB[i] = max(B[i], maxB[i+1]) for i in range(n-1): ans = max(ans, dp[i+1][-1] + maxB[i+1]) print(ans)
#dp #dp[T] T分での最大幸福 幸福度B、時間A N,T = map(int,input().split()) li = [list(map(int,input().split())) for _ in range(N)] li = sorted(li,key=lambda x: x[0]) dp = [0]*T counter = 0 for i in range(N-1): A,B = li[i] counter = max(counter,max(dp)+B) if A>T-1: continue for t in range(T-A-1,-1,-1): dp[t+A]=max(dp[t]+B,dp[t+A]) print(max(max(dp)+li[N-1][1],counter))
1
152,008,235,782,820
null
282
282
k = int(input()) a, b = map(int, input().split(" ")) ngflag = True while(a <= b): if a % k == 0: print("OK") ngflag = False break a += 1 if ngflag: print("NG")
N = int(input()) S = input() if N<4: print(0) else: a = [0] * N R, G, B = 0, 0, 0 for i in range(N): if S[i] == "R": a[i] = 1 R += 1 if S[i] == "G": a[i] = 2 G += 1 if S[i] == "B": a[i] = 4 B += 1 rgb = R * G * B cnt = 0 for i in range(N-2): for d in range(1, (N-i-1) // 2+1): if a[i] + a[i+d] + a[i+2*d] == 7: cnt += 1 print(rgb -cnt)
0
null
31,181,484,714,270
158
175
def solve(): N, P = map(int, input().split()) S = input() if P == 2 or P == 5: res = 0 for i in range(N): if int(S[i]) % P == 0: res += i + 1 print(res) else: res = 0 count = [0] * P r = 0 for i in range(N-1, -1, -1): r = (int(S[i]) * pow(10, N-1 - i, P) + r) % P if r == 0: res += 1 res += count[r] count[r] += 1 print(res) if __name__ == '__main__': solve()
import itertools def solve(): s, t = input().split() return t+s print(solve())
0
null
81,086,543,006,380
205
248
import math r=input() a=r*r*math.pi b=2*r*math.pi print "%f %f"%(a,b)
import math r = input() print("%f %f" % (math.pi*r**2, 2*math.pi*r))
1
636,971,833,660
null
46
46
import itertools import functools import math from collections import Counter from itertools import combinations import re N,R=map(int,input().split()) if N >= 10: print(R) else: print( R + ( 100 * ( 10 - N )))
def solve(): n, r = map(int, input().split()) return r + max(0, 100 * (10-n)) print(solve())
1
63,313,055,926,592
null
211
211
N=int(input()) P=list(map(int,input().split())) x=N+1 cnt=0 for i in range(N): if P[i]<x: cnt+=1 x=P[i] print(cnt)
n=int(input()) p=list(map(int,input().split())) ans=0 min_=p[0] for pp in p: min_=min(min_,pp) if min_ ==pp: ans+=1 print(ans)
1
85,207,618,876,188
null
233
233
s = input() if s[0] != s[1] or s[1] != s[2]: print("Yes") else: print("No")
N = int(input()) A = [0]*N B = [0]*N for i in range(N): A[i],B[i] = map(int, input().split()) A.sort() B.sort(reverse=True) if N%2==1: mid = (N+1)//2-1 ans = B[mid]-A[mid]+1 else: mid1 = N//2-1 mid2 = N//2 ans = (B[mid1]+B[mid2])-(A[mid1]+A[mid2])+1 print(ans)
0
null
36,011,694,406,168
201
137
N = int(input()) A = [int(i) for i in input().split()] temp = 0 for i in A: temp ^= i for i in A: print(temp ^ i)
print("ACL"*int(input()))
0
null
7,383,678,126,692
123
69
N = input() lenN = len(N) sumN = 0 for x in N: sumN += int(x) if sumN > 9: sumN %= 9 if sumN % 9 == 0: print('Yes') else: print('No')
from collections import deque nameq = deque() timeq = deque() n, q = map(int, raw_input().split()) for _ in xrange(n): name, time = raw_input().split() nameq.append(name) timeq.append(int(time)) t = 0 while nameq: name = nameq.popleft() time = timeq.popleft() if time > q: time -= q nameq.append(name) timeq.append(time) t += q else: t += time print "%s %d" % (name, t)
0
null
2,189,241,531,988
87
19
N = int(input()) C = list(input()) r = C.count("R") cnt = 0 for i in range(r): if C[i] == "W": cnt += 1 print(cnt)
import sys import math sys.setrecursionlimit(1000000) N = int(input()) K = int(input()) from functools import lru_cache @lru_cache(maxsize=10000) def f(n,k): # print('n:{},k:{}'.format(n,k)) if k == 0: return 1 if k== 1 and n < 10: return n keta = len(str(n)) if keta < k: return 0 h = n // (10 ** (keta-1)) b = n % (10 ** (keta-1)) ret = 0 for i in range(h+1): if i==0: ret += f(10 ** (keta-1) - 1, k) elif 1 <= i < h: ret += f(10 ** (keta-1) - 1, k-1) else: ret += f(b,k-1) return ret print(f(N,K))
0
null
41,379,561,479,640
98
224
n, m, l = [int(x) for x in input().split()] a = [[int(x) for x in input().split()] for y in range(n)] b = [[int(x) for x in input().split()] for y in range(m)] c = [[0 for x in range(l)] for y in range(n)] for i in range(n): for j in range(l): c[i][j] = sum([a[i][x] * b[x][j] for x in range(m)]) for i in c: print(*i)
x = int(input()) for a in range(-501, 501): for b in range(-501, 501): if a**5 - b** 5 == x: print (a, b) exit()
0
null
13,487,560,869,262
60
156
n=int(input()) s=str(input()) if(n%2!=0): print('No') else: if(s[0:len(s)//2]==s[len(s)//2:]): print('Yes') else: print('No')
while True: a, b, c = map(str, input().split()) a = int(a) c = int(c) if(b == '+'): print(a + c) elif(b == '-'): print(a - c) elif(b == '*'): print(a * c) elif(b == '/'): print(a // c) else: break
0
null
73,722,511,845,468
279
47
a = list(map(int,input().split())) if(a[0] < a[1]): print("a < b") elif(a[0] > a[1]): print("a > b") else: 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
363,895,739,536
null
38
38
X, K, D = map(int, input().split()) t = X // D if abs(t) >= K: if X > 0: print(abs(X-(D*K))) elif X < 0: print(abs(X+(D*K))) exit(0) nokori = K - t if X-(D*t) <= 0: if nokori % 2 == 0: print(abs(X-(D*t))) else: print(abs(X-(D*(t-1)))) else: if nokori % 2 == 0: print(abs(X-(D*t))) else: print(abs(X-(D*(t+1))))
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')
0
null
3,896,727,067,272
92
72
import sys A,B = map(int,input().split()) if not ( 1 <= A <= 20 ): sys.exit() if not ( 1 <= B <= 20 ): sys.exit() if not (isinstance(A,int) and isinstance(B,int)): sys.exit() print(A*B) if A <= 9 and B <= 9 else print(-1)
#!/usr/bin/env python3 #%% for atcoder uniittest use import sys input= lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**9) def pin(type=int):return map(type,input().split()) def tupin(t=int):return tuple(pin(t)) def lispin(t=int):return list(pin(t)) #%%code def resolve(): A,B=pin() if A>9 or B>9:print(-1);return print(A*B) #%%submit! resolve()
1
158,554,386,672,240
null
286
286
from collections import deque n, x, y = map(int, input().split()) inf = 100100100 x -= 1 y -= 1 ans = [0] * n for i in range(n): dist = [inf] * n queue = deque() queue.append(i) dist[i] = 0 while queue: current = queue.popleft() d = dist[current] if current - 1 >= 0 and dist[current - 1] == inf: queue.append(current - 1) dist[current - 1] = d + 1 if current + 1 < n and dist[current + 1] == inf: queue.append(current + 1) dist[current + 1] = d + 1 if current == x and dist[y] == inf: queue.append(y) dist[y] = d + 1 if current == y and dist[x] == inf: queue.append(x) dist[x] = d + 1 for j in range(n): ans[dist[j]] += 1 for k in range(1, n): print(ans[k] // 2)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N = ir() answer = (N+1) // 2 print(answer)
0
null
51,699,976,505,110
187
206
from collections import Counter N = int(input()) A = list([int(x) for x in input().split()]) result = dict(Counter(A)) for i in range(1, N+1): if i in result: print(result[i]) else: print(0)
n = int(input()) ls = [0]*n ls1 = list(map(int, input().split())) for i in ls1: ls[i-1] += 1 for j in ls: print(j)
1
32,619,540,818,560
null
169
169
N = int(input()) result = 0 for i in range(1, (N + 1)): if i % 15 == 0: 'Fizz Buzz' elif i % 3 == 0: 'Fizz' elif i % 5 == 0: 'Buzz' else: result = result + i print(result)
import math INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): n=INT() ans=0 for i in range(1,n+1): if i%3==0 or i%5==0: pass else: ans+=i print(ans) if __name__ == '__main__': do()
1
34,909,251,647,240
null
173
173
from itertools import combinations_with_replacement n, m, q = map(int, input().split()) a = [0] * q b = [0] * q c = [0] * q d = [0] * q for i in range(q): a[i], b[i], c[i], d[i] = map(int, input().split()) ans = 0 for v in combinations_with_replacement(list(range(1, m + 1)), n): sm = 0 for i in range(q): if v[b[i] - 1] - v[a[i] - 1] == c[i]: sm += d[i] ans = max(ans, sm) print(ans)
n,k=map(int,input().split()) a=list(map(int,input().split())) a.append(0) s=input() ans=0 for i in range(k,n): if s[i]==s[i-k]: s=s[:i]+'z'+s[i+1:] for i in range(n): ans+=a['sprz'.index(s[i])] print(ans)
0
null
67,380,445,126,492
160
251
input() nums = list(map(int, input().split())) print('{} {} {}'.format(min(nums), max(nums), sum(nums)))
A, B, C = input().split() A = int(A) B = int(B) C = int(C) A, B, C = B, A, C B, A, C = C, A, B C, A, B = A, B, C print(A, B, C)
0
null
19,547,332,666,290
48
178
N = int(input()) S = ["*"]*(N+1) S[1:] = list(input()) Q = int(input()) q1,q2,q3 = [0]*Q,[0]*Q,[0]*Q for i in range(Q): tmp = input().split() q1[i],q2[i] = map(int,tmp[:2]) if q1[i] == 2: q3[i] = int(tmp[2]) else: q3[i] = tmp[2] class BIT: def __init__(self, n, init_list): self.num = n + 1 self.tree = [0] * self.num for i, e in enumerate(init_list): self.update(i, e) #a_kにxを加算 def update(self, k, x): k = k + 1 while k < self.num: self.tree[k] += x k += (k & (-k)) return def query1(self, r): ret = 0 while r > 0: ret += self.tree[r] r -= r & (-r) return ret #通常のスライスと同じ。lは含み、rは含まない def query2(self, l, r): return self.query1(r) - self.query1(l) s_pos = [BIT(N+1,[0]*(N+1)) for _ in range(26)] for i in range(1,N+1): s_pos[ord(S[i]) - ord("a")].update(i,1) alphabets = [chr(ord("a") + i) for i in range(26)] for i in range(Q): if q1[i] == 1: s_pos[ord(S[q2[i]]) - ord("a")].update(q2[i],-1) S[q2[i]] = q3[i] s_pos[ord(q3[i]) - ord("a")].update(q2[i],1) else: ans = 0 for c in alphabets: if s_pos[ord(c) - ord("a")].query2(q2[i],q3[i]+1) > 0: ans += 1 print(ans)
N = int(input()) S = list(input()) Q = int(input()) alphabet = "abcdefghijklmnopqrstuvwxyz" num = dict() for i, var in enumerate(alphabet): num[var] = i class Bit(): def __init__(self, N): self.__N = N self.__arr = [[0] * 26 for _ in range(1 + N)] def add_(self, x, a, i): while(x < self.__N + 1): self.__arr[x][i] += a x += x & -x def sum_(self, x, i): res = 0 while(x > 0): res += self.__arr[x][i] x -= x & -x return res def sub_sum_(self, x, y, i): return self.sum_(y, i) - self.sum_(x, i) Bit = Bit(N) for i, var in enumerate(S): Bit.add_(i+1, 1, num[var]) for i in range(Q): q, l, r = input().split() l = int(l) if q == "1" and r != S[l-1]: temp = S[l-1] S[l-1] = r Bit.add_(l, -1, num[temp]) Bit.add_(l, 1, num[r]) elif q == "2": r = int(r) res = 0 for j in range(26): res += min(1, Bit.sub_sum_(l-1, r, j)) print(res)
1
62,488,737,510,464
null
210
210
from bisect import bisect_left, bisect_right, insort_left import sys readlines = sys.stdin.readline def main(): n = int(input()) s = list(input()) q = int(input()) d = {} flag = {} for i in list('abcdefghijklmnopqrstuvwxyz'): d.setdefault(i, []).append(-1) flag.setdefault(i, []).append(-1) for i in range(n): d.setdefault(s[i], []).append(i) for i in range(q): q1,q2,q3 = map(str,input().split()) if q1 == '1': q2 = int(q2) - 1 if s[q2] != q3: insort_left(flag[s[q2]],q2) insort_left(d[q3],q2) s[q2] = q3 else: ans = 0 q2 = int(q2) - 1 q3 = int(q3) - 1 if q2 == q3: print(1) continue for string,l in d.items(): res = 0 if d[string] != [-1]: left = bisect_left(l,q2) right = bisect_right(l,q3) else: left = 0 right = 0 if string in flag: left2 = bisect_left(flag[string],q2) right2 = bisect_right(flag[string],q3) else: left2 = 0 right2 = 0 if left != right: if right - left > right2 - left2: res = 1 ans += res #print(string,l,res) print(ans) if __name__ == '__main__': main()
import math a,b,c,d = map(int,input().split()) print('Yes' if math.ceil(c/b) <= math.ceil(a/d) else 'No')
0
null
46,377,198,586,108
210
164
n = int(input()) x = input() print(x.count("ABC"))
n = int(input()) X = input() a = 0 for i in range(n-2): if X[i] + X[i+1] + X[i+2] == 'ABC': a +=1 else: a +=0 print(a)
1
99,408,223,127,290
null
245
245
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() c = ns() r = c.count('R') print(r - c[:r].count('R')) return solve()
n=int(input()) data=[[int(num)for num in input().split(' ')] for i in range(n)] state=[[[0 for i in range(10)]for j in range(3)]for k in range(4)] for datum in data: state[datum[0]-1][datum[1]-1][datum[2]-1]+=datum[3] for i in range(4): for j in range(3): s="" for k in range(10): s+=' '+str(state[i][j][k]) print(s) if i!=3: print("####################")
0
null
3,750,226,439,580
98
55
#!/usr/bin/env python3 n, *a = map(int, open(0).read().split()) b = [0] * 60 c = [0] * 60 ans = 0 for i in range(n): for j in range(60): c[j] += i - b[j] if a[i] >> j & 1 else b[j] b[j] += a[i] >> j & 1 for j in range(60): ans += c[j] << j print(ans % (10**9 + 7))
a=input().split() n=(int)(a[0]) q=(int)(a[1]) b=[0 for i in range(2*n)] cnt=0 tmp=0 for i in range(n): B=input().split() b[2*i]=B[0] b[2*i+1]=int(B[1]) while len(b)>0: tmp=b[1]-q if tmp>0: b.append(b[0]) b.append(tmp) del b[0] del b[0] cnt=cnt+q else: cnt=cnt+b[1] print(b[0],cnt) del b[0] del b[0]
0
null
61,645,052,889,618
263
19
N, K = map(int, input().split()) mod = 998244353 move = [] for _ in range(K): L, R = map(int, input().split()) move.append((L, R)) S = [0]*K dp = [0]*(2*N) dp[N] = 1 for i in range(N+1, 2*N): for k, (l, r) in enumerate(move): S[k] -= dp[i-r-1] S[k] += dp[i-l] dp[i] += S[k] dp[i] %= mod print(dp[-1])
N, K = [int(v) for v in input().split()] links = [] for k in range(K): L, R = [int(v) for v in input().split()] links.append((L, R)) links = sorted(links, key=lambda x: x[1]) count = [1] sub = [0, 1] subtotal = 1 for i in range(1, N): v = 0 for l, r in links: r2 = i - l + 1 l2 = i - r if l2 < 0: l2 = 0 if r2 >= 0: v += sub[r2] - sub[l2] count.append(v % 998244353) subtotal = (subtotal + v) % 998244353 sub.append(subtotal ) print(count[-1])
1
2,711,695,351,192
null
74
74
n=int(input()) l0=[[] for _ in range(n)] l1=[[] for _ in range(n)] for i in range(n): a=int(input()) for j in range(a): x,y=map(int,input().split()) if y==0: l0[i].append(x) else: l1[i].append(x) ans=0 for i in range(2**n): s0=set() s1=set() num=0 num1=[] num0=[] for j in range(n): if (i>>j) & 1: num1.append(j+1) for k in range(len(l0[j])): s0.add(l0[j][k]) for k in range(len(l1[j])): s1.add(l1[j][k]) else: num0.append(j+1) for j in range(len(s1)): if s1.pop() in num0: num=1 break if num==0: for j in range(len(s0)): if s0.pop() in num1: num=1 break if num==0: ans=max(ans,len(num1)) print(ans)
import sys import math n=int(input()) A=[] xy=[[]]*n for i in range(n): a=int(input()) A.append(a) xy[i]=[list(map(int,input().split())) for _ in range(a)] ans=0 for bit in range(1<<n): tmp=0 for i in range(n): if bit>>i & 1: cnt=0 for elem in xy[i]: if elem[1]==1: if bit>>(elem[0]-1) & 1: cnt+=1 else: if not (bit>>(elem[0]-1) & 1): cnt+=1 if cnt==A[i]: tmp+=1 else: continue if tmp==bin(bit).count("1"): ans=max(bin(bit).count("1"),ans) print(ans)
1
121,082,139,131,840
null
262
262
l = int(input()) print(l**3 / 27)
def resolve(): L = int(input()) a = L/3 print(a**3) resolve()
1
47,075,220,377,068
null
191
191
n = int(input()) a = list(map(int,input().split())) ans = "APPROVED" for i in range(n): if(a[i]%2==0)and((a[i]%3!=0)and(a[i]%5!=0)): ans = "DENIED" break print(ans)
def main(): N = int(input()) A = list(map(int, input().split())) for i in A: if i % 2 == 0: if i % 3 != 0 and i % 5 != 0: return ("DENIED") return ("APPROVED") print(main())
1
68,805,406,163,138
null
217
217
K=int(input());S="" for i in range(K): S=S+"ACL" print(S)
import math X=int(input()) print(360//math.gcd(360, X))
0
null
7,595,804,758,618
69
125
def magic(a,b,c,k): for i in range(k): if(a>=b): b*=2 elif(b>=c): c*=2 if(a < b and b < c): print("Yes") else: print("No") d,e,f = map(int,input().split()) j = int(input()) magic(d,e,f,j)
a,b,c=map(int,input().split()) K=int(input()) isCheck = None for i in range(K+1): for j in range(K+1): for k in range(K+1): x = a*2**(i) y = b*2**(j) z = c*2**(k) if i+j+k <= K and x < y and y < z: isCheck = True if isCheck: print("Yes") else: print("No")
1
6,915,478,093,680
null
101
101
st = str(input()) q = int(input()) com = [] for i in range(q): com.append(input().split()) for k in com: if k[0] == "print": print(st[int(k[1]):int(k[2])+1]) elif k[0] == "reverse": s = list(st[int(k[1]):int(k[2])+1]) s.reverse() ss = "".join(s) st = st[:int(k[1])] + ss + st[int(k[2])+1:] else: st = st[:int(k[1])] + k[3] + st[int(k[2])+1:]
str=input() n=int(input()) for i in range(n): s=input().split() a=int(s[1]) b=int(s[2]) if s[0] == 'replace': str=str[:a]+s[3]+str[b+1:] elif s[0] == 'reverse': str=str[:a]+str[a:b+1][::-1]+str[b+1:] else: print(str[a:b+1])
1
2,087,451,395,444
null
68
68
import math import collections import itertools def resolve(): S=input() if("RRR" in S): print(3) elif("RR" in S): print(2) elif("R" in S): print(1) else: print(0) resolve()
s = input() n = ans = 0 for c in s: if c == "S": n = 0 continue n += 1 if n > ans: ans = n print(ans)
1
4,907,762,779,008
null
90
90
def insertionSort(A,n,g,count): for i in range(g,N): v = A[i] j = i-g while j >= 0 and A[j] > v: A[j+g] = A[j] j -= g count += 1 A[j+g] = v return count def shellSort(A,n): count = 0 m = 0 G = [] while (3**(m+1)-1)//2 <= n: m += 1 G.append((3**m-1)//2) for i in range(m): count = insertionSort(A,n,G[-1-i],count) return m,G,count import sys input = sys.stdin.readline N = int(input()) A = [int(input()) for _ in range(N)] m,G,count = shellSort(A,N) print(m) print(*G[::-1]) print(count) print('\n'.join(map(str,A)))
def insertionSort(a,n,g): for i in range(g,n): v=a[i] j=i-g while j>=0 and a[j]>v: a[j+g]=a[j] j=j-g global cnt cnt+=1 a[j+g]=v def shellsort(a,n): global cnt cnt=0 g=[i for i in [262913, 65921, 16577, 4193, 1073, 281, 77, 23, 8, 1] if i <= n] m=len(g) #print(g,m) for i in range(m): insertionSort(a,n,g[i]) return a,m,g n=int(input()) a=[int(input()) for i in range(n)] a,m,g=shellsort(a,n) print(m) print(*g) print(cnt) for i in a: print(i)
1
32,046,316,708
null
17
17
_str = "" _k = int(input()) for _i in range(_k): _str += "ACL" print(_str)
s=input() t=input() ans=int(len(s)) for i in range(len(s)-len(t)+1): now=int(0) for j in range(len(t)): if s[i+j]!=t[j]: now+=1 ans=min(now,ans) print(ans)
0
null
2,932,575,985,240
69
82
from collections import Counter s = input() MOD = 2019 ts = [0] cur = 0 for i, j in enumerate(s[::-1], 1): cur = (cur + pow(10, i, MOD) * int(j)) % MOD ts.append(cur) ct = Counter(ts) res = 0 for k, v in ct.items(): if v > 1: res += v * (v-1) // 2 print(res)
import collections S=input() l=len(S) T,d=0,1 A=[0]*2019 A[0]=1 for i in range(l): T+=int(S[l-i-1])*d d*=10 T%=2019 d%=2019 A[T]+=1 B=map(lambda x: x*(x-1)//2,A) print(sum(B))
1
30,830,125,503,100
null
166
166
""" AtCoder Beginner Contest 144 E - Gluttony 愚直解 ・修行の順序は結果に影響しないから、修行を誰に割り振るか:N^K ・メンバーN人をどの問題に当てるか(N人の並べ方):N! -> N^K * N! 間に合わない。 完食にかかる時間のうち最大値がチーム全体の成績なので、 ・消化コストAiを修行で下げる ・消化コストAiの大きい人に、食べにくさFiの小さい食べ物を割り当てる のが良さそう 最大値の最小化、なので、二分探索が使えそうな気もする。 A,F <= 10^6 かかる時間を X 以下にできるか、を考える。 ・消化コストが大きい人に、食べにくさが小さい問題を当てるようにする ・Ai * Fi > Xであれば、(Ai - m) * Fi <= X となるような最小のmをカウントする 全メンバーに対しこれを数え上げた時に、 mの合計 > K であれば、X以下になるように修行することができない(K回までしか修行できず、回数が足りない)ので、最大値の最小はXより上 mの合計 <= K であれば、X以下になるように修行できるので、最大値の最小はX以下 A*F <= 10^12 までなので、40~50程度繰り返せば行けそう """ import math N,K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) if K >= sum(A): print(0) exit() A.sort(reverse=True) F.sort() def is_ok(mid): cnt = 0 for i in range(N): if A[i] * F[i] <= mid: continue else: cnt += math.ceil((A[i] * F[i] - mid) / F[i]) # A[i]が1減少するごとにF[i]減るのでF[i]で割る return cnt <= K # okは全員がX以下になる最小値に着地するので、A*F<=10**12 なので+1して最大のケースにも対応する ok = 10**12 + 1 # 0ではないことが上で保証されてるので、条件を満たさない最大値の0にしておく ng = 0 while ok - ng > 1: mid = (ok + ng) // 2 #print(ok,ng,mid) if is_ok(mid): ok = mid else: ng = mid #print(ok,ng,mid) print(ok)
N,K = map(int,input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A = sorted(A)[::-1] F = sorted(F) sumA = sum(A) if sumA <= K: print(0) else: maxC = 0 for i in range(N): tmp = A[i]*F[i] if maxC < tmp: maxC = tmp L = 0 R = maxC visited = {} visited[maxC]=True while 1: nowC = (L+R)//2 nowA = [] for i in range(N): nowA.append(nowC//F[i]) shugyou = 0 for i in range(N): shugyou += max(A[i]-nowA[i],0) if shugyou <= K: visited[nowC] = True R = nowC if (nowC-1) in visited: if visited[nowC-1] == False: ans = nowC break else: visited[nowC] = False L = nowC if (nowC+1) in visited: if visited[nowC+1] == True: ans = nowC+1 break if nowC == 0: if visited[nowC]==True: ans = 0 break print(ans)
1
165,427,653,357,498
null
290
290
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class UnionFind: def __init__(self, N): self.root = list(range(N + 1)) self.size = [1] * (N + 1) def __getitem__(self, x): root = self.root while root[x] != x: root[x] = root[root[x]] x = root[x] return x def merge(self, x, y): x = self[x] y = self[y] if x == y: return sx, sy = self.size[x], self.size[y] if sx < sy: x, y = y, x sx, sy = sy, sx self.root[y] = x self.size[x] += sy def graph_input(N, M): G = [[] for _ in range(N + 1)] for _ in range(M): a, b = map(int, readline().split()) G[a].append(b) G[b].append(a) return G N, M, K = map(int, readline().split()) friend = graph_input(N, M) block = graph_input(N, K) uf = UnionFind(N + 1) for a in range(N + 1): for b in friend[a]: uf.merge(a, b) answer = [0] * (N + 1) for a in range(N + 1): n = uf.size[uf[a]] - 1 for x in friend[a] + block[a]: if uf[a] == uf[x]: n -= 1 answer[a] = n print(' '.join(map(str, answer[1:])))
from collections import deque N, M, K = map(int, input().split()) friend = [list(map(int, input().split())) for _ in range(M)] block = [list(map(int, input().split())) for _ in range(K)] f = [set() for _ in range(N + 1)] b = [set() for _ in range(N + 1)] for i, j in friend: f[i].add(j) f[j].add(i) for i, j in block: b[i].add(j) b[j].add(i) stack = deque() ans = [0] * (N + 1) visited = [0] * (N + 1) for i in range(1, N + 1): if visited[i]: continue # setは{}で書く link = {i} stack.append(i) visited[i] = 1 while stack: n = stack.pop() # nのフレンド全員について for j in f[n]: if visited[j] == 0: stack.append(j) visited[j] = 1 # link(set)に追加 link.add(j) for i in link: # 全体-既にフレンドの人数-ブロックした人数-自分自身 # set同士で積集合をとる ans[i] = len(link) - len(link & f[i]) - len(link & b[i]) - 1 print(*ans[1:])
1
61,567,190,722,672
null
209
209
n = int(input()) s = input() print(sum(int(s[i:i+3] == "ABC") for i in range(n - 2)))
# import sys input=sys.stdin.readline def main(): H,W,K=map(int,input().split()) mas=[input().strip("\n") for i in range(H)] mincut=H*W for bit in range(2**(H-1)): sep=[] for s in range(H-1): if (bit>>s)&1: sep.append(s) cutcnt=len(sep) cnt=[0]*(len(sep)+1) for j in range(W): ci=0 cntt=cnt[:] for i in range(H): if mas[i][j]=="1": cnt[ci]+=1 if i in sep: ci+=1 if max(cnt)>K: for i in range(len(sep)+1): cnt[i]-=cntt[i] cutcnt+=1 if max(cnt)>K: cutcnt=10000000000 if cutcnt<mincut: mincut=cutcnt print(mincut) if __name__=="__main__": main()
0
null
73,668,965,666,842
245
193
N,K,S=map(int,input().split()) A=[S]*N for i in range(K,N): if S!=1: A[i]=S-1 else: A[i]=S+1 print(*A)
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def matmat(A,B): K,N,M=len(B),len(A),len(B[0]) return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] def matvec(M,v): N=len(v) size=len(M) return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] def main(): mod = 10**9+7 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え #N = int(input()) N, K, S = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル #L = tuple(int(input()) for i in range(N)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 m=10**9 if S!=10**9: ans=[S]*K+[m]*(N-K) else: ans=[m]*K+[1]*(N-K) print(*ans) if __name__ == "__main__": main()
1
90,620,620,564,620
null
238
238
from itertools import permutations as perm N = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) comb = list(perm(range(1, N+1))) def find(x): for i, n in enumerate(comb): if x == n: return i a = find(P) b = find(Q) ans = abs(a - b) print(ans)
import itertools as it n = int(input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) r = list(it.permutations(range(1, n+1))) a = 0 b = 0 for i in range(len(r)): if r[i] == p: a = i if r[i] == q: b = i print(abs(a-b))
1
100,274,636,414,080
null
246
246
def main(): n = int(input()) s = list(map(int, input().split())) q = int(input()) t = list(map(int, input().split())) # 集合的なら # res = len(set(s) & set(p)) # print(res) # 線形探索なら cnt = 0 for i in t: if i in s: cnt += 1 print(cnt) if __name__ == '__main__': main()
n = int(raw_input()) S = map(int, raw_input().split()) q = int(raw_input()) T = map(int, raw_input().split()) ans = 0 for i in T: if i in S: ans += 1 print ans
1
69,267,809,326
null
22
22
import sys n = [int(i) for i in sys.stdin.readline().rstrip()[::-1]] ans = 0 i = 0 p = [n[i],10 - n[i]] now = [0,0] i += 1 ans = min(p[0], p[1] + 1) for i in range(1,len(n)): now[0] = min(p[0] + n[i]%10, p[1] + n[i]%10 + 1) now[1] = min(p[0] + 10 - n[i]%10, p[1] + 9 - n[i]%10) ans = min(now[0], now[1] + 1) p[0],p[1] = now[0],now[1] print(ans)
from collections import deque s = input() n = len(s) stack1 = deque() stack2 = deque() A = 0 a = 0 for ni in range(n): if s[ni] == "\\": stack1.append(ni) elif s[ni] == "/" and len(stack1) > 0 : tmp = stack1.pop() A += ni - tmp while True: if len(stack2) > 0 and stack2[-1][0] > tmp: a += stack2.pop()[1] else: break a += ni - tmp stack2.append([ni,a]) a = 0 print(A) print(len(stack2),*[i[1] for i in stack2])
0
null
35,555,975,448,796
219
21
N = int(input()) As = list(map(int,input().split())) max = 0 sum = 0 for i in range(N): if max < As[i]: max = As[i] else: sum += (max-As[i]) print(sum)
t=input() tla=list(t) tlb=list(t) pd1=0 pd2=0 for i in range(len(tla)): if tla[i]=="?": if i==0: pass elif i==len(tla)-1: tla[i]="D" elif tla[i-1]=="P": tla[i]="D" elif tla[i+1]=="D": tla[i]="P" elif tla[i+1]=="?": tla[i]="P" else: tla[i]="D" if tla[i]=="D": if i==0: pass elif tla[i-1]=="P": pd1+=1 d1=tla.count('D') s1=d1+pd1 for i in range(len(tlb)): if tlb[i]=="?": tlb[i]="D" if tlb[i]=="D": if i==0: pass elif tlb[i-1]=="P": pd2+=1 d2=tlb.count('D') s2=d2+pd2 if s1>s2: print(''.join(tla)) else: print(''.join(tlb))
0
null
11,519,612,683,328
88
140
import sys input = sys.stdin.readline def main(): n = int(input()) fib = [1] * 46 for i in range(2, 46): fib[i] = fib[i - 1] + fib[i - 2] ans = fib[n] print(ans) if __name__ == "__main__": main()
# Triangle from math import * triangle = [int(i) for i in input().rstrip().split()] sides = [triangle[0], triangle[1]] a = sides[0] b = sides[1] angle = triangle[2] triangleArea = 0.5 * a * b * sin(radians(angle)) print(triangleArea) otherSideSquare = a ** 2 + b ** 2 - 2 * a * b * cos(radians(angle)) otherSide = otherSideSquare ** 0.5 circumference = a + b + otherSide print(circumference) height = triangleArea / 0.5 / a print(height)
0
null
86,383,264,772
7
30
t, h = 0, 0 for i in range(int(input())): tc, hc= input().split() if tc > hc: t += 3 elif tc < hc: h += 3 else: t += 1 h += 1 print('%d %d' % (t, h))
cnt = int(input()) taro = 0 hanako = 0 for i in range(cnt): li = list(input().split()) if li[0]>li[1]: taro +=3 elif li[0]==li[1]: taro +=1 hanako +=1 else: hanako +=3 print(taro,hanako)
1
1,996,359,802,118
null
67
67
N = int(input()) A = map(int, input().split()) sortA = sorted(A) result = 0 for i in range(1, N): result += sortA[N - (i // 2) - 1] print(result)
while True: s = input().split() a = int(s[0]) op = s[1] b = int(s[2]) if op == "?": break if op == "+": print(a+b) if op == "-": print(a-b) if op == "*": print(a*b) if op == "/": print(a//b)
0
null
4,883,638,144,530
111
47
x=int(input()) i=0 while True: 360*i%x!=0 i+=1 if 360*i%x==0: break k=360*i/x print(int(k))
N, M, Q = map(int, input().split()) A, B, C, D = [],[],[],[] for i in range(Q): a, b, c, d = map(int, input().split()) A.append(a) B.append(b) C.append(c) D.append(d) L = [] def dfs(S): if len(S) == N: L.append(S) elif S == "": for i in range(M): S = str(i) dfs(S) else: for i in range(int(S[-1]), M): dfs(S+str(i)) dfs("") Ans = 0 for l in L: ans = 0 for a, b, c, d in zip(A,B,C,D): if int(l[b-1]) - int(l[a-1]) == c: ans += d Ans = max(ans, Ans) print(Ans)
0
null
20,396,324,609,992
125
160
import bisect,collections,copy,heapq,itertools,math,string import sys def S(): return sys.stdin.readline().rstrip() def M(): return map(int,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) a, v = M() # おに b, w = M() # にげる t = I() ans = 'NO' if v-w > 0: b_hiku_a = abs(b - a) v_hiku_w = v - w if b_hiku_a <= t * (v-w): ans = 'YES' print(ans)
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) D = abs(A - B) if (V > W) and \ (D / (V - W) <= T): print("YES") else: print("NO")
1
15,130,695,880,868
null
131
131
k= int(input()) s= input() if len(s)>k: r=s[:k]+"..." print(r) else: print(s)
K = int(input())#asking lenght of string wanted to be shorted S = input()#asking string if len(S)>K:##set that S must be greater than K print (S[:K], "...",sep="")# to print only the K number of the string else: print (S)
1
19,727,398,582,988
null
143
143
import math n,m,t = map(int,input().split()) if n%m == 0: print(int(n/m)*t) else: print(math.ceil(n/m)*t)
n,k=map(int,input().split()) l=[i for i in range(1,k+1)][::-1] mod=10**9+7 m=[0]*(k+1) for i in l: a=k//i m[i]=pow(a,n,mod) for j in range(i*2,k+1,i): m[i]-=m[j] ans=0 for i in range(k+1): ans+=m[i]*i ans%=mod print(ans%mod)
0
null
20,580,203,168,438
86
176
X=int(input()) a=[] for i in range(1,X+1): a.append(360*i) for k in range(len(a)): if a[k]%X==0: print(int(a[k]//X)) break
# coding: utf-8 s = input() print("x" * len(s))
0
null
43,197,503,860,070
125
221
#coding:UTF-8 x = input() a = x/3600 b = (x%3600)/60 c = (x%3600)%60 print str(a)+":"+str(b)+":"+str(c)
time = int(input()) s = time % 60 h = time // 3600 m = (time - h * 3600) // 60 print(str(h) + ":" + str(m) + ":" + str(s))
1
320,298,796,808
null
37
37
a,b=open(0);c=1; for i in sorted(b.split()): c*=int(i) if c>10**18:print(-1);exit() print(c)
n = int(input()) a_lst = list(map(int, input().split())) a_lst.sort() if a_lst[0] == 0: answer = 0 else: answer = 1 for i in range(n): a = a_lst[i] answer *= a if answer > 10 ** 18: answer = -1 break print(answer)
1
16,161,462,613,308
null
134
134
N, K = map(int, input().split()) S = [i+1 for i in range(N)] H = [0 for i in range(N)] for i in range(K): d = int(input()) A = list(map(int, input().split())) for j in A: for k in S: if j==k: H[k-1] += 1 ans = 0 for i in H: if i==0: ans += 1 print(ans)
N, K = map(int, input().split()) sunukes = [0 for k in range(N)] for k in range(K): d = int(input()) A = list(map(int, input().split())) for a in A: sunukes[a-1] += 1 assert len(A) == d print(len([k for k in sunukes if k == 0]))
1
24,502,689,657,028
null
154
154
s = input().split() stack = [] for i in s: if i.isdigit(): stack.append(int(i)) else: if i == "+": f = lambda x, y: x + y elif i == "-": f = lambda x, y: x - y elif i == "*": f = lambda x, y: x * y y = stack.pop() x = stack.pop() stack.append(f(x, y)) print(stack[0])
Flag = True data = [] while Flag: H, W = map(int, input().split()) if H == 0 and W == 0: Flag = False else: data.append((H, W)) #print(data) for (H, W) in data: for i in range(H): print('#' * W) print('\n', end="")
0
null
407,723,395,872
18
49
from fractions import gcd n, m = map(int, input().split()) aa = list(map(int, input().split())) lcm = 1 def p2(m): cnt = 0 n = m while 1: if n%2 == 0: cnt += 1 n = n//2 else: break return cnt pp = p2(aa[0]) for a in aa: lcm = a * lcm // gcd(a, lcm) if pp != p2(a): lcm = 10 **18 break tmp = lcm // 2 print((m // tmp + 1) // 2)
import sys import itertools # import numpy as np import time import math sys.setrecursionlimit(10 ** 7) from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from functools import reduce # from math import * from fractions import * N, M = map(int, readline().split()) A = list(map(lambda x: int(x) // 2, readline().split())) def f(n): cnt = 0 while n % 2 == 0: n //= 2 cnt += 1 return cnt t = f(A[0]) for i in range(N): if f(A[i]) != t: print(0) exit(0) A[i] >>= t M >>= t lcm = reduce(lambda a, b: (a * b) // gcd(a, b), A) if lcm > M: print(0) exit(0) print((M // lcm + 1) // 2)
1
101,593,765,665,180
null
247
247
import sys input = sys.stdin.readline N = int(input()) op = [] ed = [] mid = [0] dg = 10**7 for _ in range(N): s = list(input()) n = len(s)-1 a,b,st = 0,0,0 for e in s: if e == '(': st += 1 elif e == ')': if st > 0: st -= 1 else: a += 1 st = 0 for i in range(n-1,-1,-1): if s[i] == ')': st += 1 else: if st > 0: st -= 1 else: b += 1 if a > b: ed.append(b*dg + a) elif a == b: mid.append(a) else: op.append(a*dg + b) op.sort() ed.sort() p = 0 for e in op: a,b = divmod(e,dg) if p < a: print('No') exit() p += b-a q = 0 for e in ed: b,a = divmod(e,dg) if q < b: print('No') exit() q += a-b if p == q and p >= max(mid): print('Yes') else: print('No')
#!/usr/bin/python3 def countpars(s): lc = 0 rc = 0 for ch in s: if ch == '(': lc += 1 else: if lc > 0: lc -= 1 else: rc += 1 return (lc, rc) n = int(input()) ssl = [] ssr = [] for i in range(n): (clc, crc) = countpars(input()) if clc >= crc: ssl.append((clc, crc)) else: ssr.append((clc, crc)) ssl.sort(key=lambda x: x[1]) ssr.sort(reverse=True) lc = 0 rc = 0 for (clc, crc) in ssl: lc -= crc if lc < 0: print('No') exit() lc += clc for (clc, crc) in ssr: lc -= crc if lc < 0: print('No') exit() lc += clc if lc == 0: print('Yes') else: print('No')
1
23,645,756,280,740
null
152
152
import copy def print_list(A): print(*A, sep=" ") def swap(a, b): return b, a def val(str): return int(str[1]) def is_stable(_in, _out, n): for i in range(0, n): for j in range(i+1, n): for a in range(0, n): for b in range(a+1, n): if val(_in[i]) == val(_in[j]) and _in[i] == _out[b] and _in[j] == _out[a]: return False return True def print_stable(_in, _out, n): if is_stable(_in, _out, n): print("Stable") else: print("Not stable") def find_minj(A, i, n): minj = i for j in range(i, n): if val(A[j]) < val(A[minj]): minj = j return minj def bubble_sort(A, n): A0 = copy.copy(A) flg = 1 #逆の隣接要素が存在する i = 0 while flg: flg = 0 for j in range(n-1, i, -1): if val(A[j-1]) > val(A[j]): A[j-1], A[j] = swap(A[j-1], A[j]) flg = 1 i += 1 print_list(A) print_stable(A0, A, n) def selection_sort(A, n): A0 = copy.copy(A) for i in range(0, n): minj = find_minj(A, i, n) if val(A[i]) > val(A[minj]): A[i], A[minj] = swap(A[i], A[minj]) print_list(A) print_stable(A0, A, n) n = int(input()) A = list(map(str,input().split())) B = copy.copy(A) bubble_sort(A, n) selection_sort(B, n)
n = int(input()) *bLst, = input().split() iLst = bLst[:] for i in range(n): for j in range(n-1,i,-1): if bLst[j][1] < bLst[j-1][1]: bLst[j],bLst[j-1] = bLst[j-1],bLst[j] print(*bLst) print("Stable") for i in range(n): min = i for j in range(i,n): if iLst[j][1] < iLst[min][1]: min = j iLst[i],iLst[min] = iLst[min],iLst[i] print(*iLst) if bLst == iLst: print("Stable") else: print("Not stable")
1
24,315,534,430
null
16
16