code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
import math x=int(input()) ans=0 for i in range (1,x+1): for j in range(1,x+1): chk=math.gcd(i,j) for k in range (1,x+1): ans=ans+math.gcd(chk,k) print(ans)
import math K = int(input()) Sum = 0 for A in range(1,K+1): for B in range(1,K+1): for C in range(1,K+1): Sum = Sum+math.gcd(math.gcd(A,B),C) print(Sum)
1
35,467,759,909,440
null
174
174
x = int(input()) ans = x + x**2 + x**3 print(ans)
n = int(input()) print(n + (n * n) + (n * n * n))
1
10,175,122,748,700
null
115
115
while True: card=input() if card=='-': break loop=int(input()) for i in range(loop): ch=int(input()) card=card[ch:]+card[:ch] print(card)
#!/usr/bin/env python3 def main(): import sys input = sys.stdin.readline A, B, N = map(int, input().split()) x = min(B - 1, N) print((A * x) // B - A * (x // B)) if __name__ == '__main__': main()
0
null
15,098,009,700,164
66
161
while True: C = input() if C == "-": break count = int(input()) shuffle = [int(input()) for i in range(count)] for h in shuffle: C = C[h:] + C[:h] print(C)
A = input() while(A != '-'): m = int(input()) for i in range(m): h = int(input()) A = A[h:]+A[:h] print(A) A = input()
1
1,924,180,997,792
null
66
66
N,M=map(int,input().split()) S=input() S=S[::-1] now = 0 ok=1 history = [] while True: for i in range(min(M, N-now),0,-1): if S[now+i] == '0': now += i history.append(str(i)) break if i==1: print(-1) ok=0 break if ok==0:break if now == N:break if ok==1:print(' '.join(history[::-1]))
import numpy as np import scipy as sp import math a, b, c = map(int, input().split()) d = a + b + c if(d<22): print("win") else: print("bust")
0
null
129,127,498,615,360
274
260
print('ABC' if input() == 'ARC' else 'ARC')
s = input() print('ABC' if s == 'ARC' else 'ARC')
1
24,227,826,151,290
null
153
153
def main(): MOD = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split())) ans = 1 d = [0] * (max(A) + 1) for a in A: if a == 0: ans *= 3 - d[a] ans %= MOD d[a] += 1 else: ans *= d[a-1] - d[a] d[a] += 1 ans %= MOD print(ans) if __name__ == "__main__": main()
N = int(input()) C = input() WL = [0] RR = [C.count('R')] for i in range(0, N): if C[i] == 'R': WL.append(WL[i]) RR.append(RR[i] - 1) else: WL.append(WL[i] + 1) RR.append(RR[i]) MM = N for i in range(0, N + 1): MM = min(MM, (max(WL[i], RR[i]))) print(MM)
0
null
68,111,048,070,270
268
98
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from itertools import permutations, accumulate, combinations, combinations_with_replacement from math import sqrt, ceil, floor, factorial from bisect import bisect_left, bisect_right, insort_left, insort_right from copy import deepcopy from operator import itemgetter from functools import reduce, lru_cache # @lru_cache(None) from fractions import gcd import sys def input(): return sys.stdin.readline().rstrip() sys.setrecursionlimit(10**6) # ----------------------------------------------------------- # a, v = (int(x) for x in input().split()) b, w = (int(x) for x in input().split()) t = int(input()) if a == b: print("YES") elif a < b: if a + t*v >= b + t*w: print("YES") else: print("NO") else: if a - t*v <= b - t*w: print("YES") else: print("NO")
s, t = map(str, input().split()) x = t + s print(x)
0
null
58,701,275,803,050
131
248
n = int(input()) a = list(map(int, input().split())) t = 1 ans = 0 for i in range(n): if t != a[i]: ans += 1 a[i] = -1 else: t += 1 if all([i == -1 for i in a]): print(-1) else: print(ans)
import time as ti class MyQueue(object): """ My Queue class Attributes: queue: queue head tail """ def __init__(self): """Constructor """ self.length = 50010 self.queue = [0] * self.length # counter = 0 # while counter < self.length: # self.queue.append(Process()) # counter += 1 self.head = 0 self.tail = 0 # def enqueue(self, name, time): def enqueue(self, process): """enqueue method Args: name: enqueued process name time: enqueued process time Returns: None """ self.queue[self.tail] = process # self.queue[self.tail].name = name # self.queue[self.tail].time = time self.tail = (self.tail + 1) % self.length def dequeue(self): """dequeue method Returns: None """ # self.queue[self.head].name = "" # self.queue[self.head].time = 0 self.queue[self.head] = 0 self.head = (self.head + 1) % self.length def is_empty(self): """check queue is empty or not Returns: Bool """ if self.head == self.tail: return True else: return False def is_full(self): """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue): return True else: return False class Process(object): """process class """ def __init__(self, name="", time=0): """constructor Args: name: name time: time """ self.name = name self.time = time def forward_time(self, time): """time forward method Args: time: forward time interval Returns: remain time """ self.time -= time return self.time def time_forward(my_queue, interval, current_time,): """ Args: my_queue: queue interval: time step interval current_time: current time """ value = my_queue.queue[my_queue.head].forward_time(interval) if value <= 0: current_time += (interval + value) print my_queue.queue[my_queue.head].name, current_time my_queue.dequeue() elif value > 0: current_time += interval name, time = my_queue.queue[my_queue.head].name, \ my_queue.queue[my_queue.head].time my_queue.enqueue(my_queue.queue[my_queue.head]) my_queue.dequeue() return current_time my_queue = MyQueue() n, q = [int(x) for x in raw_input().split()] counter = 0 while counter < n: name, time = raw_input().split() my_queue.enqueue(Process(name, int(time))) counter += 1 # end_time_list = [] current_time = 0 while not my_queue.is_empty(): current_time = time_forward(my_queue, q, current_time)
0
null
57,539,185,219,012
257
19
bingoSheet = [0 for x in range(9)] for i in range(3): bingoRow = input().split() for j in range(3): bingoSheet[i*3 + j] = int(bingoRow[j]) bingoCount = int(input()) responses = [] for i in range(bingoCount): responses.append(int(input())) hasBingo = False step = 1 initialIndex = 0 for i in range(3): firstIndex = i*3 subList = [bingoSheet[index] for index in [firstIndex, firstIndex+1, firstIndex+2]] if (all(elem in responses for elem in subList)): hasBingo = True break for i in range(3): firstIndex = i subList = [bingoSheet[index] for index in [firstIndex, firstIndex+3, firstIndex+6]] if (all(elem in responses for elem in subList)): hasBingo = True break subList = [bingoSheet[index] for index in [0, 4, 8]] if (all(elem in responses for elem in subList)): hasBingo = True subList = [bingoSheet[index] for index in [2, 4, 6]] if (all(elem in responses for elem in subList)): hasBingo = True if hasBingo: print('Yes') quit() print('No') quit()
#!/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') YES = "Yes" # type: str NO = "No" # type: str def solve(A: "List[List[int]]", N: int, b: "List[int]"): for i in b: A = [[(a if a != i else 0) for a in l] for l in A] return [NO, YES][any([not any(l) for l in [*A, *[[A[i][j] for i in range(3)] for j in range(3)], [A[0][0], A[1][1], A[2][2]], [A[2][0], A[1][1], A[0][2]]]])] def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)] # type: "List[List[int]]" N = int(next(tokens)) # type: int b = [int(next(tokens)) for _ in range(N)] # type: "List[int]" print(f'{solve(A, N, b)}') if __name__ == '__main__': main()
1
59,616,614,664,748
null
207
207
K = int(input()) A = [i for i in range(1, 10)] if K <= 9: print(A[K-1]) else: K -= 9 f = 1 while f: B = [] for a in A: k = a % 10 if k != 0: B.append(a * 10 + k - 1) K -= 1 if K == 0: print(B[-1]) f = 0 break B.append(a * 10 + k) K -= 1 if K == 0: print(B[-1]) f = 0 break if k != 9: B.append(a * 10 + k + 1) K -= 1 if K == 0: print(B[-1]) f = 0 break A = B
from collections import deque k = int(input()) num_deq = deque([i for i in range(1, 10)]) for i in range(k-1): x = num_deq.popleft() if x % 10 != 0: num_deq.append(10 * x + x % 10 - 1) num_deq.append(10 * x + x % 10) if x % 10 != 9: num_deq.append(10 * x + x % 10 + 1) x = num_deq.popleft() print(x)
1
40,200,704,491,922
null
181
181
def main(): log_no, cut_max = [int(x) for x in input().split()] logs = [int(x) for x in input().split()] bin_l, bin_r = 0, 10 ** 9 while bin_r - bin_l > 1: bin_mid = (bin_l + bin_r) // 2 cut_count = sum((log - 1) // bin_mid for log in logs) if cut_count <= cut_max: bin_r = bin_mid else: bin_l = bin_mid print(bin_r) if __name__ == '__main__': main()
def inverse_mod(a, mod=10**9+7): """ Calculate inverse of the integer a modulo mod. """ return pow(a, mod-2, mod) def combination_mod(n, r, mod=10**9+7): """ Calculate nCr modulo mod. """ r = min(r, n-r) numerator = denominator = 1 for i in range(r): numerator = numerator * (n - i) % mod denominator = denominator * (i + 1) % mod return numerator * inverse_mod(denominator, mod) % mod def create_inverses_table(n, mod=10**9+7): """ Create table for inverses of the integers 0 to n modulo mod. """ inv_table = [0] + [1] * n for x in range(2, n+1): inv_table[x] = -(mod//x) * inv_table[mod % x] % mod return inv_table def solve(): n_blocks, n_colors, n_max_pairs = map(int, input().split()) if n_colors == 1: return int(n_blocks - n_max_pairs == 1) mod = 998244353 inverses = create_inverses_table(max(n_colors, n_max_pairs), mod) e1 = n_colors * pow(n_colors-1, n_blocks-1, mod) % mod e2 = 1 total = e1 * e2 for k in range(1, n_max_pairs+1): e1 = e1 * inverses[n_colors - 1] % mod e2 = e2 * (n_blocks - k) * inverses[k] % mod total += e1 * e2 total %= mod return total def main(): print(solve()) if __name__ == "__main__": main()
0
null
14,752,010,623,648
99
151
import sys import math from collections import deque from collections import defaultdict def main(): n, k = list(map(int,sys.stdin.readline().split())) ans = n//k if n%k != 0: ans += 1 print(ans) return 0 if __name__ == "__main__": main()
n, x, y = map(int, input().split()) x -= 1 y -= 1 def shortest_path(i, j): res = min(abs(i-x)+abs(j-y)+1, j-i) return res ans = [0]*(n-1) for i in range(n-1): for j in range(i+1, n): d = shortest_path(i, j) ans[d-1] += 1 print(*ans, sep='\n')
0
null
60,380,351,253,262
225
187
def main(): S = list(input().rstrip()) N = len(S) if S != list(reversed(S)): print("No") elif S[:int((N-1)/2)] != list(reversed(S[:int((N-1)/2)])): print("No") elif S[int((N+3)/2) - 1:] != list(reversed(S[int((N+3)/2) - 1:])): print("No") else: print("Yes") if __name__ == '__main__': main()
def flg(s): le = len(s) // 2 return s[:le] == s[::-1][:le] s = input() le1 = len(s) // 2 t = s[:le1] print(["No", "Yes"][flg(s) and flg(t)])
1
46,130,319,849,768
null
190
190
N = int(input()) ans = 0 for a in range(1, 10 ** 6 + 1): for b in range(1, 10 ** 6 + 1): if a * b >= N: break ans += 1 print(ans)
n = int(input()) s = list(input()) ans = '' for i in s: ascii_code = (ord(i) + n) if ascii_code >= 91: ascii_code -= 26 ans += chr(ascii_code) print(ans)
0
null
68,513,125,575,388
73
271
''' def main(): a = input() if a < 'a': print("A") else: print("a") ''' def main(): a = input() if a.islower(): print("a") else: print("A") if __name__ == "__main__": main()
a = input() n = ord(a) if ord('A') <= n <= ord('Z'): print('A') else: print('a')
1
11,307,101,222,978
null
119
119
# coding: utf-8 # Here your code ! n=int(input()) A=[int(i) for i in input().split()] q=int(input()) m=[int(i) for i in input().split()] from itertools import combinations x=[] for i in range(len(A)): t=(list(combinations(A,i))) x.append(t) combi=set() for i in x: for j in i: combi.add(sum(j)) for i in m: if i in combi: print("yes") else: print("no")
N=int(input()) *A,=map(int,input().split()) Q=int(input()) *M,=map(int,input().split()) mf=['no']*Q t=[] for i in range(0,2**N): ans=0 for j in range(N): if (i>>j&1): ans+=A[j] t.append(ans) tset=set(t) for i in range(Q): if M[i] in tset: mf[i] = 'yes' for i in mf: print(i)
1
101,306,029,600
null
25
25
N, K = map(int,input().split()) P = list(map(int,input().split())) P.sort() price = sum(P[:K]) print(price)
from sys import stdin,stdout LI=lambda:list(map(int,input().split())) MAP=lambda:map(int,input().split()) IN=lambda:int(input()) S=lambda:input() import math from collections import Counter,defaultdict n=IN() a=LI() ans=0 for i in range(n): ans^=a[i] for i in range(n): print(ans^a[i],end=" ")
0
null
12,169,150,287,150
120
123
n = int(input()) A = list(map(int, input().split())) l = A[0] r = sum(A[1:]) x = abs(l-r) for a in A[1:]: l += a r -= a if x > abs(l-r): x = abs(l-r) print(x)
n=int(input()) a=list(map(int,input().split())) s=sum(a) ans = 12345678901234 cnt = 0 for i in range(n): cnt += a[i] ans = min(ans,abs(s-cnt - cnt)) print(ans)
1
142,147,524,278,970
null
276
276
n=int(input()) a=list(map(int,input().split())) b=a[0] ans=0 for n in range(n): if a[n]>b: b=a[n] else: ans+=b-a[n] print(ans)
N = int(input()) memo = [-1]*500 def fibo(x): if memo[x] != -1: return memo[x] if x == 0 or x == 1: ans=1 memo[x] = ans return ans ans = fibo(x-1) + fibo(x-2) memo[x] = ans return ans print(fibo(N))
0
null
2,319,276,197,370
88
7
import sys input = sys.stdin.readline def main(): N = int(input()) X = input() popcount_X = X.count("1") if popcount_X == 0: ans = [1] * N elif popcount_X == 1: ans = [1] * N ans[-1] = 2 ans[X.index("1")] = 0 else: X_mod_popcount_X_p = int(X, 2) % (popcount_X + 1) X_mod_popcount_X_m = int(X, 2) % (popcount_X - 1) ans = [0] * N for i in range(N): if X[i] == "0": Y = X_mod_popcount_X_p + pow(2, N - 1 - i, mod=popcount_X + 1) Y = Y % (popcount_X + 1) else: Y = X_mod_popcount_X_m - pow(2, N - 1 - i, mod=popcount_X - 1) Y = Y + (popcount_X - 1) Y = Y % (popcount_X - 1) count = 1 while Y > 0: popcount = bin(Y).count("1") Y = Y % popcount count += 1 ans[i] = count print("\n".join(map(str, ans))) if __name__ == "__main__": main()
# -*- coding:utf-8 -*- import sys data = [] count = 0 for i in sys.stdin: data.append(int(i)) count = count+1 if count == 10: break N = len(data) m = 100 for i in range(m): for n in range(N-1): a = data[n] b = data[n+1] if a <= b: data[n] = b data[n+1] = a else: pass for i in range(3): print(data[i])
0
null
4,111,383,635,128
107
2
H, W, K = map(int, input().split()) S = [list(map(int, list(input()))) for _ in range(H)] ans = H*W def countWhite(ytop, ybottom, xleft, xright): ret = sum([sum(s[xleft:xright]) for s in S[ytop:ybottom]]) return ret for h_div in range(1 << H-1): count = 0 cut = [0] for i in range(H): if h_div >> i & 1: cut.append(i+1) count += 1 cut.append(H) if count > ans: continue left = 0 # ここどんなふうに縦に切っても条件を満たさない場合がある for right in range(1, W+1): white = 0 for i in range(len(cut)-1): white = max(white, countWhite(cut[i], cut[i+1], left, right)) if white > K: if left == right - 1: # 条件を満たす縦の切り方がなかった場合 break left = right - 1 count += 1 if count > ans: break else: if count < ans: ans = count print(ans)
import itertools H, W, K = map(int, input().split()) A = [[int(x) for x in input()] for _ in range(H)] def solve(blocks): n_block = len(blocks) n_cut = n_block - 1 sums = [0 for _ in range(n_block)] for c in range(W): adds = [block[c] for block in blocks] if any(a > K for a in adds): return H * W sums = [s + a for s, a in zip(sums, adds)] if any(s > K for s in sums): n_cut += 1 sums = adds return n_cut ans = H * W for mask in itertools.product([0, 1], repeat=H - 1): mask = [1] + list(mask) + [1] pivots = [r for r in range(H + 1) if mask[r]] blocks = [A[p1:p2] for p1, p2 in zip(pivots[:-1], pivots[1:])] blocks = [[sum(row[c] for row in block) for c in range(W)] for block in blocks] ans = min(ans, solve(blocks)) print(ans)
1
48,372,965,265,478
null
193
193
N=int(input()) testimonies=[] for i in range(N): A=int(input()) testimony=[] for j in range(A): testimony.append(list(map(int,input().split()))) testimony[-1][0]-=1 testimonies.append(testimony) ans=0 for i in range(2**N): isContradiction=False for j in range(N): if not i&1<<j:continue for x,y in testimonies[j]: if i&1<<x:x=1 else:x=0 if not x==y: isContradiction=True break if not isContradiction: ans=max(ans,bin(i).count("1")) print(ans)
taro_point = 0 hanako_point = 0 N = int(input()) for _ in range(N): taro,hanako = input().split() list = [taro,hanako] list_new = sorted(list) if taro == hanako: taro_point += 1 hanako_point += 1 elif list_new[1] == hanako: hanako_point +=3 elif list_new[1] == taro: taro_point += 3 print(str(taro_point),str(hanako_point))
0
null
62,021,898,791,002
262
67
import sys input = sys.stdin.readline def gcd(a, b): while b: a, b = b, a%b return a def lcm(a, b): return a//gcd(a, b)*b N, M = map(int, input().split()) a = list(map(int, input().split())) b = [ai//2 for ai in a] cnt = [0]*N for i in range(N): t = b[i] while t%2==0: cnt[i] += 1 t //= 2 if cnt!=[cnt[0]]*N: print(0) exit() L = 1 for bi in b: L = lcm(L, bi) if L>M: print(0) else: print((M-L)//(2*L)+1)
n = int(input()) stocks = [int(x) for x in input().split()] mymoney = 1000 mystock = 0 for i in range(0,len(stocks)-1): # コメントアウト部分はデバッグ用コード #print(stocks[i],stocks[i+1],end=":") if stocks[i] < stocks[i+1]: # 明日の方が株価が高くなる場合は、今日のうちに株を買えるだけ買う #print("buying",end=" ") mystock += mymoney//stocks[i] mymoney = mymoney%stocks[i] elif stocks[i] >= stocks[i+1]: # 明日の方が株価が安くなる場合には、今日のうちに手持ちの株を売却 #print("selling",end=" ") mymoney += mystock*stocks[i] mystock = 0 #print(mymoney,mystock) i += 1 mymoney += mystock * stocks[i] # 最終日に手持ちの株をすべて売却して現金化 mystock = 0 print(mymoney)
0
null
54,283,148,944,612
247
103
input() a = list(input().split()) print(*a[::-1])
import sys input = sys.stdin.readline def main(): T = list(input().rstrip()) ans = ["D" if c == "?" else c for c in T] print("".join(ans)) if __name__ == "__main__": main()
0
null
9,764,492,053,372
53
140
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): S, T = readline().strip().split() print(T + S) return if __name__ == '__main__': main()
A,B = map(str,input().split()) out = B+A print(out)
1
102,928,662,773,992
null
248
248
N, K = map(int, input().split()) *A, = map(int, input().split()) *F, = map(int, input().split()) A.sort() F.sort(reverse=True) def f(x): ans = 0 for i,j in zip(A, F): ans += (i*j-x+j-1)//j if i*j-x>=0 else 0 return ans<=K l, r = -1, 10**18+1 while r-l>1: mid = (r+l)//2 if f(mid): r = mid else: l = mid print(r)
n,k = map(int, input().split()) A = list(map(int,input().split())) F = list(map(int,input().split())) A.sort() F.sort(reverse=True) def is_ok(x): c = 0 for a, f in zip(A, F): c += max(0, a-x//f) if c <= k: return True else: return False ng = -1 ok = 10**18 while ng+1 < ok: c = (ng+ok)//2 if is_ok(c): ok = c else: ng = c print(ok)
1
164,739,449,289,760
null
290
290
N = int(input()) ACcount = 0 WAcount = 0 TLEcount = 0 REcount = 0 for i in range(N): S=input() if S == "AC": ACcount = ACcount + 1 elif S == "WA": WAcount = WAcount + 1 elif S == "TLE": TLEcount = TLEcount + 1 elif S == "RE": REcount = REcount + 1 print("AC x", ACcount) print("WA x", WAcount) print("TLE x", TLEcount) print("RE x", REcount)
#!/usr/bin/env python # -*- coding: utf-8 -*- def main(): values = [] total = 0 open_chars = 0 close_chars = 0 for _ in range(int(input())): s = input().strip() open_required = len(s) close_required = len(s) open_close = 0 for i, c in enumerate(s): if c == '(': open_required = min(i, open_required) open_close += 1 else: close_required = min(len(s) - i - 1, close_required) open_close -= 1 if open_required == 0 and close_required == 0 and open_close == 0: continue elif open_close == len(s): open_chars += len(s) continue elif -open_close == len(s): close_chars += len(s) continue total += open_close values.append([open_required, close_required, open_close, 0]) if total + open_chars - close_chars != 0: print('No') return fvals = values.copy() bvals = values fvals.sort(key=lambda x: (x[0], -x[2])) bvals.sort(key=lambda x: (x[1], x[2])) findex = 0 bindex = 0 while True: while findex < len(fvals) and fvals[findex][3] != 0: findex += 1 while bindex < len(bvals) and bvals[bindex][3] != 0: bindex += 1 if findex >= len(fvals) and bindex >= len(bvals): break fvals[findex][3] = 1 bvals[bindex][3] = -1 values = [v for v in fvals if v[3] == 1] + [v for v in bvals if v[3] == -1][::-1] open_close_f = 0 open_close_b = 0 for (oreq_f, _, ocval_f, _), (_, creq_b, ocval_b, _) in zip(values, values[::-1]): if oreq_f > open_close_f + open_chars: print('No') return if creq_b > open_close_b + close_chars: print('No') return open_close_f += ocval_f open_close_b -= ocval_b print('Yes') if __name__ == '__main__': main()
0
null
16,298,952,365,770
109
152
def resolve(): k=int(input()) list=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(list[k-1]) resolve()
def get_num(n, x): ans = 0 for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1): for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3 + 1) / 2 - 1, -1): for n1 in xrange(min(n2 - 1, x - n3 - n2), 0, -1): if n3 == x - n1 - n2: ans += 1 break return ans data = [] while True: [n, x] = [int(m) for m in raw_input().split()] if [n, x] == [0, 0]: break if x < 3: # print(0) data.append(0) else: # print(get_num(n, x)) data.append(get_num(n, x)) for n in data: print(n)
0
null
25,858,369,945,772
195
58
def main(): mountain=[] for i in range(10): num=int(input()) mountain.append(num) mountain=sorted(mountain) mountain=mountain[::-1] for i in range(3): print(mountain[i]) if __name__=='__main__': main()
# coding: utf-8 def getint(): return int(input().rstrip()) def main(): ls = [] num_of_mount = 10 num_of_top = 3 for i in range(num_of_mount): ls.append(getint()) ls.sort(reverse=True) for i in range(num_of_top): print(ls[i]) if __name__ == '__main__': main()
1
9,670,180
null
2
2
N = int(input()) A = [int(i) for i in input().split()] ans = 0 for i,a in enumerate(A): idx = i+1 if a%2 == 1 and idx%2 == 1: ans += 1 print(ans)
N = int(input()) A = list(map(int, input().split())) res = 0 for i in range(1, N + 1): if i % 2 == 1 and A[i-1] % 2 == 1: res += 1 print(res)
1
7,731,031,133,056
null
105
105
a,b,k = map(int, input().split()) m = k if a > k else a a -= m b -= min(k-m, b) print(f'{a} {b}')
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip.split()) def main(): a,b,k = LI() x = max(a-k,0) y = b if k-a > 0: y = max(b-(k-a),0) print(x,y) main()
1
104,065,975,684,540
null
249
249
def main(): x = int(input()) for a in range(-120, 121): for b in range(-120, 121): if a**5 - b**5 == x: print(a, b) return if __name__ == "__main__": main()
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] y = input() K = int(y) print(x[K-1])
0
null
37,829,955,479,328
156
195
n ,q = map(int, input().split()) ntlist = [] for i in range(n): nt = list(map(str, input().split())) ntlist.append(nt) tp = 0 while (len(ntlist)): nt = ntlist.pop(0) if (int(nt[1])> q): nt[1] = int(nt[1]) - q tp += q ntlist.append(nt) else: tp += int(nt[1]) nt[1] = 0 print(nt[0], tp)
import statistics n=int(input()) x=list(map(int,input().split())) p1 = int(statistics.mean(x)) p2=p1+1 s1=0 s2=0 for i in range(n): s1+=(x[i]-p1)**2 s2+=(x[i]-p2)**2 print(min(s1,s2))
0
null
32,461,168,109,348
19
213
N = int(input()) A = list(map(int, input().split())) MOD = 10**9 + 7 def gcd(n, m): if m == 0: return n return gcd(m, n % m) def lcm(a, b): return a * b // gcd(a, b) L = 1 for a in A: L = lcm(L, a) L %= MOD coef = 0 for a in A: coef += pow(a, MOD - 2, MOD) print((L * coef) % MOD)
h,w = map(int,input().split()) g = [] for _ in range(h): S = input() tmp = [str(i) for i in S] g.append(tmp) from collections import deque # print(g) dp = [[0]*w for _ in range(h)] def dfs(i,j): seen = [[False]*w for _ in range(h)] seen[i][j] = True q = deque([]) q.append((i,j,0)) dist=[(1,0),(-1,0),(0,1),(0,-1)] while q: x,y,cnt = q.popleft() for dx,dy in dist: if 0 <=x+dx<h and 0<=y+dy<w and seen[x+dx][y+dy]==False and g[x+dx][y+dy]=='.': seen[x+dx][y+dy] = True q.append((x+dx,y+dy,cnt+1)) return cnt ans = 0 for i in range(h): for j in range(w): if g[i][j] =='.': ans =max(ans,dfs(i,j)) print(ans)
0
null
91,298,511,759,158
235
241
import itertools N, M, Q = map(int, input().split()) l = [i for i in range(1, M+1)] qus = [] As = [] for _ in range(Q): b = list(map(int, input().split())) qus.append(b) for v in itertools.combinations_with_replacement(l, N): a = list(v) A = 0 for q in qus: pre = a[q[1]-1] - a[q[0]-1] if pre == q[2]: A += q[3] As.append(A) print(max(As))
S = input() T = input() if T.startswith(S) and len(T) == len(S) + 1: print("Yes") else: print("No")
0
null
24,503,489,279,808
160
147
#!/usr/bin/env python3 import sys from collections import Counter input = sys.stdin.readline INF = 10**9 n, k = [int(item) for item in input().split()] a = [int(item) - 1 for item in input().split()] cumsum = [0] * (n + 1) for i in range(n): cumsum[i+1] = cumsum[i] + a[i] cumsum[i+1] %= k ls = list(set(cumsum)) dic = dict() for i, item in enumerate(ls): dic[item] = i cnt = [0] * (n + 10) num = 0 ans = 0 for i, item in enumerate(cumsum): index = dic[item] ans += cnt[index] cnt[index] += 1 num += 1 if num >= k: left = cumsum[i - k + 1] index = dic[left] if cnt[index] > 0: cnt[index] -= 1 num -= 1 print(ans)
import sys from functools import reduce import copy import math from pprint import pprint import collections import bisect import itertools import heapq sys.setrecursionlimit(4100000) def inputs(num_of_input): ins = [input() for i in range(num_of_input)] return ins def int_inputs(num_of_input): ins = [int(input()) for i in range(num_of_input)] return ins def solve(input): nums = string_to_int(input) def euclid(large, small): if small == 0: return large l = large % small return euclid(small, l) nums.sort(reverse=True) eee = euclid(nums[0], nums[1]) return int((nums[0] * nums[1]) / eee) def string_to_int(string): return list(map(lambda x: int(x), string.split())) if __name__ == "__main__": ret = solve(input()) print(ret)
0
null
125,010,924,885,600
273
256
N=int(input()) XY=[[] for _ in range(N)] for i in range(N): A=int(input()) for _ in range(A): x,y = map(int, input().split()) x-=1 XY[i].append([x,y]) ans=0 for bit_state in range(2**N): flag=True for i in range(N): if (bit_state>>i)&1: for x, y in XY[i]: if (bit_state >>x)&1 != y: flag=False if flag: ans=max(ans, bin(bit_state).count("1")) print(ans)
# author: Taichicchi # created: 19.09.2020 00:06:44 import sys K = int(input()) a = 7 % K for k in range(K + 2): if a == 0: print(k + 1) break a = (a * 10 + 7) % K else: print(-1)
0
null
63,520,336,356,148
262
97
#!/usr/bin/env python a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if v <= w: print('NO') exit() if abs(b-a)/(v-w) > t: print('NO') exit() print('YES')
from sys import stdin score = [ 0, # Taro 0 # Hanako ] n = int(stdin.readline().rstrip()) for i in range(n): card_pair = stdin.readline().rstrip().split() if card_pair[0] > card_pair[1]: score[0] += 3 elif card_pair[0] < card_pair[1]: score[1] += 3 else: score[0] += 1 score[1] += 1 print(*score)
0
null
8,482,474,243,870
131
67
import sys class Node(): def __init__(self, key=None, prev=None, next=None): self.key = key self.prev = prev self.next = next class DoublyLinkedList(): def __init__(self): self.head = Node() self.head.next = self.head self.head.prev = self.head def insert(self, x): node = Node(key=x, prev=self.head, next=self.head.next) self.head.next.prev = node self.head.next = node def search(self, x): node = self.head.next while node is not self.head and node.key != x: node = node.next return node def delete_key(self, x): node = self.search(x) self._delete(node) def _delete(self, node): if node is self.head: return None node.prev.next = node.next node.next.prev = node.prev def deleteFirst(self): self._delete(self.head.next) def deleteLast(self): self._delete(self.head.prev) def getKeys(self): node = self.head.next keys = [] while node is not self.head: keys.append(node.key) node = node.next return " ".join(keys) L = DoublyLinkedList() n = int(input()) for i in sys.stdin: if 'insert' in i: x = i[7:-1] L.insert(x) elif 'deleteFirst' in i: L.deleteFirst() elif 'deleteLast' in i: L.deleteLast() elif 'delete' in i: x = i[7:-1] L.delete_key(x) else: pass print(L.getKeys())
from collections import deque n = int(input()) dlist = deque() for i in range(n): code = input().split() if code[0] == "insert": dlist.insert(0,code[1]) if code[0] == "delete": try: dlist.remove(code[1]) except: continue if code[0] == "deleteFirst": dlist.popleft() if code[0] == "deleteLast": dlist.pop() print(*dlist,sep=" ")
1
52,609,584,160
null
20
20
def insertionSort( nums, n, g ): cnt = 0 for i in range( g, len( nums ) ): v = nums[i] j = i - g while 0 <= j and v < nums[j]: nums[ j+g ] = nums[j] j -= g cnt += 1 nums[ j+g ] = v return cnt def shellSort( nums, n ): cnt = 0 g = [] val =0 for i in range( 0, n ): val = 3*val+1 if n < val: break g.append( val ) g.reverse( ) m = len( g ) print( m ) print( " ".join( map( str, g ) ) ) for i in range( 0, m ): cnt += insertionSort( nums, n, g[i] ) print( cnt ) n = int( raw_input( ) ) nums = [] for i in range( 0, n ): nums.append( int( raw_input( ) ) ) shellSort( nums, n ) for i in nums: print( i )
x = int(input()) n_500 = x//500 n_5 = (x%500)//5 print(n_500*1000 + n_5*5)
0
null
21,466,560,708,768
17
185
n = int(input()) a = list(map(int,input().split())) maxketa = max([len(bin(a[i])) for i in range(n)])-2 mod = 10**9+7 ans = 0 for i in range(maxketa): ones = 0 for j in range(n): if (a[j] >> i) & 1: ones += 1 ans = (ans + (n-ones)*ones*(2**i)) % mod print(ans)
import math def main(): mod = 1000000007 N = int(input()) A = list(map(int, input().split())) A_max = sorted(A)[-1] if A_max == 0: print(0) exit() bit_max = int(math.ceil(math.log2(A_max))) i = 0 bit = 1 res = 0 while i <= bit_max: c_zero = 0 c_one = 0 for j in range(N): if A[j] & bit == 0: c_zero += 1 else: c_one += 1 m_bit = bit % mod res += m_bit*c_zero*c_one res %= mod i += 1 bit<<=1 print(res) if __name__ == "__main__": main()
1
123,100,997,375,502
null
263
263
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush import math #from math import gcd #inf = 10**17 #mod = 10**9 + 7 n,k,c = map(int, input().split()) s = input().rstrip() left = [0]*n day = 0 temp = 0 while day < n: if s[day] == 'o': temp += 1 left[day] = temp for i in range(c): if day+i+1 < n: left[day+i+1] = temp day += c else: left[day] = temp day += 1 right = [0]*n day = n-1 temp = 0 while 0 <= day: if s[day] == 'o': temp += 1 right[day] = temp for i in range(c): if day-i-1 >= 0: right[day-i-1] = temp day -= c else: right[day] = temp day -= 1 res = [] for i in range(n): if s[i] == 'o': if i-c-1 < 0: pre = 0 else: pre = left[i-c-1] if i+c+1 >= n: pos = 0 else: pos = right[i+c+1] if pre + pos == k-1: res.append(i+1) for i in range(len(res)): if i-1>=0: l = res[i-1] else: l = -1000000 if i+1<len(res): r = res[i+1] else: r = 10000000 if res[i]-l>c and r-res[i] > c: print(res[i]) if __name__ == '__main__': main()
def main(): N, K, C = map(int, input().split()) S = input() L, R = [-C], [N + C] i, k = 0, 0 while i < N and k < K: if S[i] == 'o': L.append(i) k += 1 i += C i += 1 L.append(N) i, k = N - 1, 0 while 0 <= i and k < K: if S[i] == 'o': R.append(i) k += 1 i -= C i -= 1 R.append(N) l = 0 for i, s in enumerate(S): if s == 'x': continue r = K - l if R[r] <= i or R[r] - L[l] < C: print(i + 1) if L[l + 1] == i: l += 1 main()
1
40,529,863,482,460
null
182
182
print("".join([_.upper() if _.islower() else _.lower() for _ in input()]))
import itertools a = [] while True: n = map(int, raw_input().split()) if n == [0, 0]: break a.append(n) for n in range(len(a)): x = 0 b = [] for m in range(a[n][0]): if m == range(a[n][0]): break b.append(m+1) c = list(itertools.combinations(b, 3)) for l in range(len(c)): sum = c[l][0] + c[l][1] + c[l][2] if sum == a[n][1]: x += 1 print x
0
null
1,400,016,852,934
61
58
N = int(input()) stone = input() R = stone.count('R') ans = stone.count('W', 0, R) print(ans)
from collections import Counter n = int(input()) s = input() b = Counter(s) ans = min(b["R"],b["W"]) a = 0 for i in range(b["R"]): if s[i] == "W": a += 1 print(min(ans,a))
1
6,213,407,744,236
null
98
98
def BubbleSort(C, N): for i in xrange(0, N): for j in reversed(xrange(i+1, N)): if C[j][1] < C[j-1][1]: C[j], C[j-1] = C[j-1], C[j] def SelectionSort(C, N): for i in xrange(N): minj = i for j in xrange(i, N): if C[j][1] < C[minj][1]: minj = j C[i], C[minj] = C[minj], C[i] def isStable(C, N): flag = 0 for i in xrange(1, 14): Ct = [C[j] for j in xrange(N) if C[j][1] == str(i)] if len(Ct) > 1: for k in xrange( len(Ct)-1 ): if Ct[k][2] > Ct[k+1][2]: flag = 1 if flag == 0: print "Stable" else: print "Not stable" # MAIN N = input() C = [] Ct = map(str, raw_input().split()) for i in xrange(N): C.append([Ct[i][0], Ct[i][1::], i]) Ct = list(C) BubbleSort(Ct, N) print " ".join([Ct[i][0]+Ct[i][1] for i in xrange(N)]) isStable(Ct, N) Ct = list(C) SelectionSort(Ct, N) print " ".join([Ct[i][0]+Ct[i][1] for i in xrange(N)]) isStable(Ct, N)
N = int(input()) word = [str(input()) for i in range(N)] dic = {} for i in word: if i in dic: dic[i] += 1 else: dic[i] = 1 max_num = max(dic.values()) can_word = [] for i,j in dic.items(): if j == max_num: can_word.append(i) can_word.sort() for i in can_word: print(i)
0
null
34,977,934,171,898
16
218
n=int(input()) a=list(map(int,input().split())) cnt=[0]*(10**5+1) for i in a: cnt[i]+=1 xxx=sum(a) q=int(input()) for i in range(q): l,r=map(int,input().split()) pin=cnt[l] cnt[r]+=pin cnt[l]=0 xxx+=(r-l)*pin print(xxx)
N = int(input()) Alist = list(map(int,input().split())) sum1 = sum(Alist) dic = {} for a in Alist: if not a in dic: dic[a] = 0 dic[a]+=1 Q = int(input()) Qlist = [] for _ in range(Q): Qlist.append(list(map(int,input().split()))) for q in Qlist: b,c = q n = 0 if b in dic: n = dic[b] dic[b] = 0 else: pass if c in dic: dic[c] += n else: dic[c] = n sum1 += n*(c-b) print(sum1)
1
12,291,177,856,802
null
122
122
N = input() Y = int(N) a = Y%10 if a==3: print("bon") elif a==0: print("pon") elif a==1: print("pon") elif a==6: print("pon") elif a==8: print("pon") elif a==2: print("hon") elif a==4: print("hon") elif a==5: print("hon") elif a==7: print("hon") else: print("hon")
import re n = input() if len(re.findall("2|4|5|7|9", n[-1])) > 0: print("hon") elif len(re.findall("0|1|6|8", n[-1])) > 0: print("pon") else: print("bon")
1
19,165,805,190,458
null
142
142
def main(): K = int(input()) work = 7 answer = -1 for i in range(1, K+1): i_mod = work % K if i_mod == 0 : answer = i break work = i_mod * 10 + 7 print(answer) main()
import sys input = sys.stdin.readline n,p=map(int,input().split()) s=input() ans=0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += i + 1 print(ans) exit() total=[0]*p#pで割った余りで分類 total[0]=1#t[0]=0の分をあらかじめカウント t=[0]*(n+1)#s[i:n]を格納する用の配列 for i in range(n-1,-1,-1): t[i]=t[i+1]+int(s[i])*pow(10,n-1-i,p)#s[i:n]を漸化式で付け加えていく total[t[i]%p]+=1 for i in range(p): ans+=total[i]*(total[i]-1)//2 print(ans)
0
null
32,262,612,895,282
97
205
def f(x): cnt=0 for i in range(N): num=x//F[i] if A[i]>num: cnt+=A[i]-num return cnt N,K=map(int,input().split()) A=list(map(int,input().split())) F=list(map(int,input().split())) A.sort() F.sort(reverse=True) low=0 high=10**12+1 while high-low>0: mid=(high+low)//2 xxx=f(mid) if xxx<=K: high=mid else: if low==mid: low=high else: low=mid print(low)
N,K=map(int,input().split()) A=list(map(int,input().split())) F=list(map(int,input().split())) A.sort() F.sort(reverse=True) l=-1 r=10**13 while r-l!=1: m=(l+r)//2 x=0 for i in range(N): x+=max(0,A[i]-m//F[i]) if x<=K: r=m else: l=m print(r)
1
164,717,171,447,072
null
290
290
import sys readline = sys.stdin.readline def main(): A, B, M = map(int, readline().split()) a = list(map(int, readline().split())) b = list(map(int, readline().split())) ans = min(a) + min(b) for _ in range(M): x, y, c = map(int, readline().split()) ans = min(ans, a[x-1] + b[y-1] - c) print(ans) if __name__ == "__main__": main()
A, B, M = list(map(int, input().split())) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) ans = min(a_list) + min(b_list) for i in range(M): x, y, c = list(map(int, input().split())) cost = a_list[x - 1] + b_list[y - 1] - c if cost < ans: ans = cost print(ans)
1
53,727,771,830,432
null
200
200
N, K = map(int, input().split()) A = list(map(int, input().split())) if K == 1: print(0) else: S, LUT, ans = [0], {0: 1}, 0 for a in A: S.append(S[-1] + a) for i in range(1, N + 1): p = (S[i] - i) % K ans += LUT.get(p, 0) LUT[p] = LUT.get(p, 0) + 1 if i - K + 1 >= 0: LUT[(S[i - K + 1] - i + K - 1) % K] -= 1 print(ans)
import sys sys.setrecursionlimit(10**9) INF=10**18 def input(): return sys.stdin.readline().rstrip() def main(): N,K=map(int,input().split()) A=list(map(int,input().split())) B=[0]*(N+1) for i in range(N): B[i+1]=(A[i]+B[i]-1)%K ans=0 d={} for i in range(1,N+1): if i-K<0: if B[i-1] in d: d[B[i-1]]+=1 else: d[B[i-1]]=1 else: if B[i-1] in d: d[B[i-1]]+=1 else: d[B[i-1]]=1 d[B[i-K]]-=1 if B[i] in d: ans+=d[B[i]] print(ans) if __name__ == '__main__': main()
1
137,756,690,272,102
null
273
273
# import itertools # import math # import sys # sys.setrecursionlimit(500*500) # import numpy as np N = int(input()) # S = input() # n, *a = map(int, open(0)) # N, M = map(int, input().split()) A = list(map(int, input().split())) # B = list(map(int, input().split())) # tree = [[] for _ in range(N + 1)] # B_C = [list(map(int,input().split())) for _ in range(M)] # S = input() # B_C = sorted(B_C, reverse=True, key=lambda x:x[1]) # all_cases = list(itertools.permutations(P)) # a = list(itertools.combinations_with_replacement(range(1, M + 1), N)) # itertools.product((0,1), repeat=n) # A = np.array(A) # cum_A = np.cumsum(A) # cum_A = np.insert(cum_A, 0, 0) # def dfs(tree, s): # for l in tree[s]: # if depth[l[0]] == -1: # depth[l[0]] = depth[s] + l[1] # dfs(tree, l[0]) # dfs(tree, 1) Q = int(input()) B_C = [list(map(int,input().split())) for _ in range(Q)] tot = sum(A) cnt = [0] * 100001 for i in A: cnt[i] += 1 # print(cnt[:6]) for l in B_C: cnt[l[1]] += cnt[l[0]] tot += cnt[l[0]] * (l[1] - l[0]) cnt[l[0]] = 0 print(tot)
def resolve(): N = int(input()) A = list(map(int, input().split())) Q = int(input()) BC = [list(map(int, input().split())) for _ in range(Q)] a = [0] * 100001 for i in A: a[i] += i ans = sum(a) for b, c in BC: if a[b] == 0: print(ans) continue move = a[b] // b a[b] = 0 a[c] += c * move ans += (c - b) * move print(ans) if __name__ == "__main__": resolve()
1
12,143,912,092,994
null
122
122
import math a, b, h, m = list(map(int, input().split())) ang = abs(h * 30 + m * 0.5 - m * 6) print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(ang * math.pi / 180)))
#!/usr/bin/env python3 c = [[0] * 10 for _ in [0] * 10] for i in range(1, int(input()) + 1): c[int(str(i)[0])][int(str(i)[-1])] += 1 print(sum(c[i][j] * c[j][i] for i in range(10) for j in range(10)))
0
null
53,063,641,601,640
144
234
import math while True: try: a,b=map(int,input().split()) print(*[math.gcd(a,b),a*b//math.gcd(a,b)]) except:break
import sys import fractions def lcm(a,b): return int(a*b/fractions.gcd(a,b)) if __name__ == '__main__': for line in sys.stdin: a,b = map(int,line.split()) print(int(fractions.gcd(a,b)),lcm(a,b))
1
567,330,012
null
5
5
N = int(input()) A = list(map(int,(input().split()))) sum=1 if 0 in A: print(0) else: for i in range(N): sum *= A[i] if sum >= int(1e18): break print(sum if sum<= int(1e18) else -1)
l = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" li = [int(x.strip()) for x in l.split(',')] print(li[int(input())-1])
0
null
33,036,017,804,480
134
195
n,k=map(int,input().split()) h=list(map(int,input().split())) sum=0 for l in h: if l>=k: sum+=1 print(sum)
N = int(input()) cc = list(map(int,input().split())) min_sum = float('inf') for i in range(1,101): count = 0 for j in cc: count += (i-j)**2 min_sum = min(min_sum,count) print(min_sum)
0
null
121,751,151,927,940
298
213
S = input() length =len(S) S = list(S) count = 0 for i in range(length): if S[i] == '?': S[i] = 'D' answer = "".join(S) print(answer)
T = input() l = [] for i in range(len(T)): if T[i] == 'P': l.append('P') else: l.append('D') ans = ''.join(l) print(ans)
1
18,539,321,613,842
null
140
140
''' ITP-1_4-C ?¨??????? ???????????´??° a, b ??¨?????????????????? op ?????????????????§???a op b ????¨??????????????????°????????????????????????????????? ????????????????????? op ??????"+"(???)???"-"(???)???"*"(???)???"/"(???)???????????¨?????????????????§????????????????????´????????? ?°???°?????\??????????????¨????????????????¨????????????¨???????????? ???Input ??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§?????? a op b op ??? '?' ?????¨??? ??\?????????????????????????????????????????±???????????????????????£???????????????????????? ???Output ?????????????????????????????????????¨?????????????????????????????????????????????? ''' # import import sys # ?????°?????????????????? for inputData in sys.stdin: inputList = inputData.split() a, op, b = int(inputList[0]), inputList[1], int(inputList[2]) retVal = 0 # 0?????´??? ???????????? if op == '?': # exec end break elif op == '+': retVal = a + b elif op == '-': retVal = a - b elif op == '*': retVal = a * b elif op == '/': retVal = a // b else: retVal = 0 # ???????????? print(retVal)
while True: a, op, b = map(str,input().split()) if op == '+': print(int(a) + int(b)) elif op == '-': print(int(a) - int(b)) elif op == '*': print(int(a) * int(b)) elif op == '/': print(int(a) // int(b)) elif op == '?': break
1
701,854,200,758
null
47
47
H, W, K = map(int, input().split()) c = [] b_h = [0] * H b_w = [0] * W b = 0 for h in range(H): c.append(input().rstrip()) for w in range(W): if c[h][w] == "#": b_h[h] += 1 b_w[w] += 1 b += 1 ans = 0 for hi in range(2 ** H): for wi in range(2 ** W): bsum = b for h in range(H): if hi & (2 ** h) != 0: bsum -= b_h[h] for w in range(W): if wi & 2 ** w != 0: if c[h][w] == '#': bsum += 1 for w in range(W): if wi & (2 ** w) != 0: bsum -= b_w[w] if bsum == K: ans += 1 print(ans)
H,W,K=map(int,input().split()) c=[str(input())for i in range(H)] ans=0 for maskH in range(2**H): for maskW in range(2**W): black=0 for i in range(H): for j in range(W): if ((maskH>>i)&1)==1: continue if ((maskW>>j)&1)==1: continue if c[i][j]=='#': black+=1 if black==K: ans+=1 print(ans)
1
8,958,330,846,920
null
110
110
n, a, b = list(map(int, input().split())) p = 10**9+7 def binom(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) res = factinv[r] % p for i in range(r): res = res * (n - i) % p return res % p factinv = [1, 1] inv = [0, 1] for i in range(2, min(n, 2*10**5) + 1): inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) res = pow(2, n, p) res -= 1 res = (res - binom(n, a, p)) % p res = (res - binom(n, b, p)) % p print(res)
import numpy as np D = int(input()) c = np.array( list(map(int, input().split())) ) # s = [[] for i in range(D)] for i in range(D): s[i] = np.array( list(map(int, input().split())) ) # v = 0 cc = np.array( [0]*26 ) last = np.array( [-1]*26 ) for d in range(D): cc += c av = s[d] - sum( cc ) + cc av2 = av + cc*min((D-d-1),13) m = max(av2) for t in range(26): if av2[t] == m: cc[t] = 0 v += av[t] print(t+1) break # #print( v )
0
null
38,034,031,536,006
214
113
n = int(input()) s = list(input()) count_red = s.count('R') count_white = 0 A = [] for i in range(n): if s[i] == 'R': count_red -= 1 if s[i] == 'W': count_white += 1 A.append(max(count_red, count_white)) if len(set(s)) == 1 and list(set(s)) == ['W']: print(0) else: print(min(A))
s = input() if(len(s)==0): print("") if(s[-1] == "s"): print(s+"es") if(s[-1] != "s"): print(s+"s")
0
null
4,294,978,020,860
98
71
n = int(input()) a = list(filter(lambda x : x & 1 or x % 3 == 0 or x % 5 == 0, map(int, input().split()))) print('APPROVED' if len(a) == n else 'DENIED')
N=int(input()) list1 = list(map(int, input().split())) list2=[] for i in list1: if i%2==0: list2.append(i) else: continue list3=[] for j in list2: if j%3==0 or j%5==0: list3.append(j) else: continue x=len(list2) y=len(list3) if x==y: print('APPROVED') else: print('DENIED')
1
69,104,027,834,008
null
217
217
n = int(input()) p = list(map(int, input().split())) count = 0 m = p[0] for i in p: m = min(m, i) if m == i: count += 1 print(count)
n = int(input()) p = list(map(int, input().split())) ans = 1 p_min = p[0] for i in range(1,n): if p_min >= p[i]: ans += 1 p_min = min(p_min, p[i]) print(ans)
1
85,430,681,139,260
null
233
233
n=int(input()) s=input() ans=0 r,g,b=0,0,0 for i in range(n): if s[i]=="R": r+=1 elif s[i]=="G": g+=1 else: b+=1 for i in range(1,n): for j in range(i+1,n): if (j-i)+j<=n: k=(j-i)+j-1 if s[i-1]!=s[j-1] and s[j-1]!=s[k] and s[k]!=s[i-1]: ans-=1 ans+=r*g*b print(ans)
n = int(input()) S = input() rs = [s=="R" for s in S] gs = [s=="G" for s in S] bs = [s=="B" for s in S] ind_r = [i for i,s in enumerate(rs) if s == 1] ind_g = [i for i,s in enumerate(gs) if s == 1] ind_b = [i for i,s in enumerate(bs) if s == 1] ans = 0 ng = sum(gs) for i in ind_r: for j in ind_b: # print(i,j) kM = max(i,j) + abs(i-j) km = min(i,j) - abs(i-j) ans += ng if (max(i,j) - min(i,j))%2==0: # print("aaa",(max(i,j)+min(i,j))//2) ans -= gs[(max(i,j)+min(i,j))//2] if kM < n: ans -= gs[kM] if 0 <= km: ans -= gs[km] print(ans)
1
36,118,324,456,984
null
175
175
#!/usr/bin/env python3 import sys YES = "Yes" # type: str NO = "No" # type: str def solve(S: str): if S[2] == S[3] and S[4] == S[5]: print(YES) else: print(NO) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str solve(S) if __name__ == '__main__': main()
s = input() s.split() if s[2]==s[3] and s[4]==s[5]: print("Yes") else: print("No")
1
42,120,080,637,998
null
184
184
from math import cos, radians, sqrt a, b, h, m = map(int, input().split()) angle = radians(h*30 + m / 2- m*6) print(sqrt(a**2 + b**2 - 2*a*b*cos(angle)))
N=int(input()) if N==1: print('0') exit() def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def divcount(n): cnt=0 while n>=0: n-=cnt+1 cnt+=1 return cnt-1 s=factorization(N) t=[i[1] for i in s] ans=0 for i in t: ans+=divcount(i) print(ans)
0
null
18,482,438,966,102
144
136
from collections import deque n, m = map(int, input().split()) links = [[] for _ in range(n)] for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 links[a].append(b) links[b].append(a) ans = [-1] * n ans[0] = 0 q = deque([(0, 0)]) while q: room, prev = q.popleft() for next_ in links[room]: if ans[next_] < 0: ans[next_] = room q.append((next_, room)) print('Yes') for i in range(1, n): print(ans[i] + 1)
from collections import deque n, m = map(int, input().split()) to = [[] for _ in range(n + 1)] for i in range(m): a, b = map(int, input().split()) to[a].append(b) to[b].append(a) q = deque([1]) dist = [-1] * (n + 1) # print(to) while q: v = q.popleft() for u in to[v]: if dist[u] != -1: continue q.append(u) dist[u] = v print("Yes") # print(dist) for i in range(2, n + 1): print(dist[i])
1
20,508,801,522,478
null
145
145
import sys printf = sys.stdout.write abc = [] ans = [0 for i in range(26)] for i in range(26): abc.append(str(chr(i + 97))) word = [] for line in sys.stdin: word.append(line) for i in range(len(word)): for j in range(len(word[i])): for k in range(29): if (k + 65) == ord(word[i][j]) or (k + 97) == ord(word[i][j]): ans[k] += 1 for i in range(26): printf(abc[i] + " : " + str(ans[i]) + "\n")
nums = [] while True: in_line = raw_input().split() if int(in_line[0]) == 0 and int(in_line[1]) == 0: break nums.append([int(in_line[0]),int(in_line[1])]) for n in nums: n.sort() print n[0], print n[1]
0
null
1,111,663,697,212
63
43
bldgs = [] for k in range(4): bldgs.append([[0 for i in range(10)] for j in range(3)]) n = int(input()) for i in range(n): b,f,r,v = map(int, input().split(' ')) bldgs[b-1][f-1][r-1] += v for i, bldg in enumerate(bldgs): if i > 0: print('#'*20) for floor in bldg: print(' '+' '.join([str(f) for f in floor]))
n = int(input()) info = [] for i in range(n): b, f, r, v = input().split() b = int(b) f = int(f) r = int(r) v = int(v) if info == []: info.append([b, f, r, v]) else: for x in info: if b == x[0] and f == x[1] and r == x[2]: x[3] += v isAdded = True break else: isAdded = False if isAdded == False: info.append([b, f, r, v]) for building in range(4): for floor in range(3): for room in range(10): print(" ", end = '') arePeople = False for y in info: if building + 1 == y[0] and floor + 1 == y[1] and room + 1 == y[2]: print(y[3], end = '') arePeople = True if arePeople == False: print("0", end = '') print('') if building < 3: print("####################")
1
1,113,271,385,940
null
55
55
n, k = map(int, input().split()) a = list(map(int, input().split())) a2 = [0] for i in range(n): a2.append(a2[-1] + a[i] - 1) a2 = [a2[i] % k for i in range(n + 1)] count = {} temp = a2[:min(k, len(a2))] for i in temp: count.setdefault(i, 0) count[i] += 1 ans = 0 for i in count.values(): ans += (i * (i - 1) // 2) for i in range(1, len(a2) - len(temp) + 1): temp = a2[i: i + len(temp)] temp2 = temp[:-1] ans += temp2.count(temp[-1]) print(ans)
H, W, K = map(int, input().split()) sl = [] for _ in range(H): sl.append(list(input())) ans = 10**8 for i in range(2 ** (H-1)): fail_flag = False comb = [] for j in range(H-1): if ((i >> j) & 1): comb.append(j) comb.append(H-1) # print(comb) sections = [] for k in range(0,len(comb)): if k == 0: sections.append( sl[0:comb[0]+1] ) else: sections.append( sl[comb[k-1]+1:comb[k]+1] ) # print(sections) partition_cnt = 0 sections_w_cnts = [0]*len(sections) for w in range(W): sections_curr_w_cnts = [0]*len(sections) partition_flag = False for i, sec in enumerate(sections): for row in sec: if row[w] == '1': sections_curr_w_cnts[i] += 1 sections_w_cnts[i] += 1 if sections_curr_w_cnts[i] > K: fail_flag = True break if sections_w_cnts[i] > K: partition_flag = True if fail_flag: break if fail_flag: break if partition_flag: sections_w_cnts = [v for v in sections_curr_w_cnts] # sections_w_cnts[:] = sections_curr_w_cnts[:] partition_cnt += 1 if not fail_flag: ans = min(len(comb)-1+partition_cnt, ans) print(ans)
0
null
93,139,005,533,900
273
193
n=int(input()) s=list(input()) if n%2==0: bef=s[:n//2] aft=s[n//2:] if bef==aft: print("Yes") else: print("No") else: print("No")
from sys import stdin from copy import deepcopy import queue class Dice: def __init__(self, nums): self.labels = [None] + [ nums[i] for i in range(6) ] self.pos = { "E" : 3, "W" : 4, "S" : 2, "N" : 5, "T" : 1, "B" : 6 } def rolled(dice, queries): d = deepcopy(dice) for q in queries: if q == "E": d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"] elif q == "W": d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"] elif q == "S": d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"] elif q == "N": d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"] else: return d nums = [int(x) for x in stdin.readline().rstrip().split()] q = int(stdin.readline().rstrip()) dice = Dice(nums) # TとSに対応するクエリを記憶し, resをすぐに呼び出せるようにする memo = [[False] * 7 for i in range(7)] memo[dice.pos["T"]][dice.pos["S"]] = "" # クエリとさいころの東面を記憶 res = { "" : dice.labels[dice.pos["E"]] } # BFSで探索, 解を求めたらreturn Trueで抜け出す # diceの中身をいじってはならない def solve(T, S): if isinstance(memo[T][S], str): return memo[T][S] que = queue.Queue() que.put(dice) sol_q = ["E", "N", "S", "W"] while not que.empty(): d = que.get() if d.pos["T"] == T and d.pos["S"] == S: break else: for i in sol_q: d_next = Dice.rolled(d, i) if memo[d_next.pos["T"]][d_next.pos["S"]] == False: que.put(d_next) memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next.labels[d_next.pos["E"]] else: return memo[T][S] for i in range(q): ts = [int(x) for x in stdin.readline().rstrip().split()] T = dice.labels.index(ts[0]) S = dice.labels.index(ts[1]) if solve(T, S) != False: print(res[memo[T][S]])
0
null
73,599,476,796,138
279
34
s = input() n = len(s) + 1 A = [0] * n for i in range(1, n): if s[i - 1] == "<": A[i] = A[i - 1] + 1 for i in range(n - 1, 0, -1): if s[i - 1] == ">": A[i - 1] = max(A[i - 1], A[i] + 1) print(sum(A))
s=input() n=len(s)+1 mountain=[0,0] count=[0,0] sum=0 for i in range(n-1): if s[i]=="<": mountain[1]+=1 else: if mountain[1]>0: sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]]) count=mountain mountain=[1,0] else: mountain[0]+=1 sum+=(mountain[0]*(mountain[0]-1)+mountain[1]*(mountain[1]+1))//2+max([0,mountain[0]-count[1]]) print(sum)
1
155,949,776,947,808
null
285
285
h,w = map(int,input().split()) f = [] for i in range(h): s = list(map(lambda x:0 if x== "." else 1,list(input()))) f.append(s) from collections import deque def dfs_field(field,st,go): """ :param field: #が1,.が0になったfield st: [i,j] go: [i,j] :return: 色々今は回数returnしている。 """ h = len(field) w = len(field[0]) around = [[-1,0],[1,0],[0,1],[0,-1]] que = deque() visited = set() visited.add(str(st[0])+","+str(st[1])) que.append([st[0],st[1],0]) max_cos = 0 while True: if len(que) == 0: return max_cos top = que.popleft() nowi = top[0] nowj = top[1] cost = top[2] for a in around: ni = nowi+a[0] nj = nowj+a[1] if ni < 0 or ni > h-1 or nj < 0 or nj > w-1: continue if field[ni][nj] == 1: continue if ni == go[0] and nj == go[1]: return cost+1 else: key = str(ni)+","+str(nj) if key not in visited: que.append([ni,nj,cost+1]) visited.add(key) if cost+1 > max_cos: max_cos = cost+1 # print(que) ans = 0 for i in range(h): for j in range(w): if f[i][j] == 0: ct = dfs_field(f,[i,j],[-2,-2]) if ans < ct: ans = ct print(ans)
H,W=map(int,input().split()) S=[list(input())for _ in range(H)] from collections import deque def bfs(h,w,sy,sx,S): maze=[[10**9]*(W)for _ in range(H)] maze[sy-1][sx-1]=0 que=deque([[sy-1,sx-1]]) count=0 while que: y,x=que.popleft() for i,j in [(1,0),(0,1),(-1,0),(0,-1)]: nexty,nextx=y+i,x+j if 0<=nexty<h and 0<=nextx<w: dist1=S[nexty][nextx] dist2=maze[nexty][nextx] else: continue if dist1!='#': if dist2>maze[y][x]+1: maze[nexty][nextx]=maze[y][x]+1 count=max(count,maze[nexty][nextx]) que.append([nexty,nextx]) return count ans=0 for sy in range(H): for sx in range(W): if S[sy][sx]=='.': now=bfs(H,W,sy+1,sx+1,S) ans=max(ans,now) print(ans)
1
94,958,483,420,582
null
241
241
N,K=map(int,input().split()) ans=0 for i in range(K,N+2): if i!=(N+1): anssub=N*(N+1)//2 -(N-i)*(N-i+1)//2 - i*(i-1)//2+1 else: anssub=1 ans+=anssub ans=ans%(10**9+7) print(ans)
n, k = map(int, input().split()) mod = 10 ** 9 + 7 inv = pow(2, mod - 2) % mod def calc(b, e, c): global mod global inv res = (e + b) % mod res = ((res * c) % mod ) * inv return res % mod ans = 0 for i in range(k, n + 2): min_val = calc(0, i - 1, i) max_val = calc(n - i + 1, n, i) ans += (max_val - min_val + 1) % mod ans %= mod print(ans)
1
33,215,675,094,510
null
170
170
n = int(input()) if n % 2 == 0: work = int(n / 2) s = input() a = s[:work] b = s[work:] if a == b: print("Yes") else: print("No") else: print("No")
a = input() print("Yes" if (a[2] == a[3]) and (a[4] == a[5]) else "No")
0
null
94,206,339,455,012
279
184
N, K = map(int, input().split()) MOD = 998244353 S = [] for _ in range(K): l, r = map(int, input().split()) S.append((l, r)) dp = [0] * (N + 1) accDp = [0] * (N + 1) dp[1] = 1 accDp[1] = 1 for i in range(2, N + 1): for l, r in S: r, l = max(0, i - l), max(1, i - r) dp[i] += accDp[r] - accDp[l - 1] dp[i] %= MOD accDp[i] = (accDp[i - 1] + dp[i]) % MOD print(dp[N])
n, m = map(int, input().split()) matrix = [list(map(int, input().split())) for i in range(n)] b = [int(input()) for i in range(m)] for obj in matrix: print(sum(obj[i] * b[i] for i in range(m)))
0
null
1,942,268,885,020
74
56
n = int(input()) t_score = 0 h_score = 0 for i in range(n): t_card, h_card = input().split() if t_card < h_card: h_score += 3 elif t_card > h_card: t_score += 3 else: h_score += 1 t_score += 1 print(t_score, h_score)
t=int(input()) taro=0 hanako=0 for i in range(t): S=input().split() if S[0]==S[1]: taro+=1 hanako+=1 elif S[0]>S[1]: taro+=3 else: hanako+=3 print(taro,hanako)
1
1,971,936,174,212
null
67
67
def havediv( target, elm): s = target / elm if target == s*elm: return True else: return False if __name__ == "__main__": v = map( int, raw_input().split()) ct = 0 i = v[0] while i <= v[1]: if havediv( v[2], i): ct += 1 i += 1 print ct
import math def facts(n): ans = [] for i in range(1, int(math.sqrt(n)+1)): if(n%i==0): ans.append(i) ans.append(n//i) ans = sorted(ans) return ans n,m,q =map(int, input().split()) qs = [] ans = 0 for i in range(q): arr= list(map(int, input().split())) qs.append(arr) def calc(x): global ans tmp = 0 for i in range(q): if(x[qs[i][1]-1]-x[qs[i][0]-1]==qs[i][2]): tmp+=qs[i][3] ans = max(ans, tmp) def dfs(x): if(len(x)==n): calc(x) else: for i in range(x[-1], m+1): x.append(i) dfs(x) x.pop() dfs([1]) print(ans)
0
null
14,044,366,394,456
44
160
n=int(input()) p=list(map(int,input().split())) min_t=10**6 cnt=0 for i in range(n): if min_t>=p[i]: cnt+=1 min_t=min(min_t,p[i]) print(cnt)
n = int(input()) s = input() ans = 0 for i in range(n-2): if s[i] == 'A': if s[i+1] == 'B': if s[i+2] == 'C': ans += 1 print(ans)
0
null
92,319,812,810,030
233
245
import sys import numpy as np # noqa read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines K = int(readline()) C = readline().rstrip().decode() a = 0 # a: 赤から白に変える操作 b = 0 # b: 白から赤に変える操作 for i in range(len(C)): if C[i] == 'R': a += 1 mn = a for i in range(len(C)): if C[i] == 'R': a -= 1 else: b += 1 mn = min(mn, min(a, b) + abs(a-b)) print(mn)
import math def main(): A, B, C = map(int, input().split()) if A == B and B != C: print('Yes') elif A == C and A != B: print('Yes') elif B == C and B != A: print('Yes') else: print('No') main()
0
null
37,184,220,306,638
98
216
n = int(input()) if n%2 == 0 : ans = n//2 print(ans) else : ans = n//2 + 1 print(ans)
print((int(input()) + 1) // 2)
1
58,912,893,564,858
null
206
206
import math n = sum([int(x) for x in str(input()).split()]) a, b = divmod(n, 9) print("No" if b else "Yes")
N = input() SUM = 0 for i in N: SUM += int(i) if SUM % 9 == 0: print('Yes') else : print('No')
1
4,398,597,396,538
null
87
87
# -*- coding: utf-8 -*- r, c = map(int, raw_input().split()) cl= [0] * c for i in xrange(r): t = map(int, raw_input().split()) for i, a in enumerate(t): cl[i] += a print ' '.join(map(str, t)), sum(t) print ' '.join(map(str, cl)), sum(cl)
import sys printf = sys.stdout.write mat = [] new_map = [] r,c = map(int, raw_input().split()) for i in range(r): mat = map(int, raw_input().split()) new_map.append(mat) for i in range(r): new_map[i].append(sum(new_map[i][:])) for j in range(c): print new_map[i][j], printf(" " + str(new_map[i][j + 1]) + "\n") for j in range(c + 1): a = 0 for i in range(r): a += new_map[i][j] if j == c: printf(" " + str(a) + "\n") break else: print a,
1
1,337,777,656,052
null
59
59
def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque from collections import defaultdict from itertools import combinations, permutations, accumulate, groupby, product from bisect import bisect_left,bisect_right from heapq import heapify, heappop, heappush from math import floor, ceil,pi,factorial from operator import itemgetter def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI2(): return [int(input()) for i in range(n)] def MXI(): return [[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf = 10**17 mod = 10**9+7 #main code here! h,w,k=MI() cake=[SI() for i in range(h)] last=[-1 for i in range(w)] for i in range(w): for j in range(h): if cake[j][i]=="#": last[i]=j lis=[[0]*w for i in range(h)] ans=0 for i in range(w): if last[i]==-1: continue if last[i]!=-1: ans+=1 for j in range(h): lis[j][i]=ans if cake[j][i]=="#": if last[i]!=j: ans+=1 #print(lis) pos=[] for i in range(w): if last[i]!=-1: pos.append(i) pos.append(w) for i in range(w): if last[i]==-1: u=pos[bisect_left(pos,i)] #print(u) if u!=w: for j in range(h): lis[j][i]=lis[j][u] else: for j in range(h): lis[j][i]=lis[j][pos[-2]] for i in range(h): print(*lis[i]) #print(lis) if __name__=="__main__": main()
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W, K = map(int, input().split()) grid = [list(input().rstrip()) for _ in range(H)] cnt = 0 res = [[0] * W for _ in range(H)] for h in range(H): num = 0 for w in range(W): if grid[h][w] == "#": cnt += 1 num = cnt res[h][w] = num for h in range(H): num = 0 for w in reversed(range(W)): if res[h][w]: num = res[h][w] res[h][w] = num for w in range(W): for h in range(1, H): if res[h][w] == 0: res[h][w] = res[h - 1][w] for w in range(W): for h in reversed(range(H)): if res[h][w] == 0: res[h][w] = res[h + 1][w] for i in res: print(*i) if __name__ == '__main__': resolve()
1
144,029,554,473,308
null
277
277
h, n, *a = map(int, open(0).read().split()) print(["No", "Yes"][h <= sum(a)])
h,n = map(int,input().split()) a = list(map(int,input().split())) for i in range(n): h = h - a[i] if h <= 0: print('Yes') exit(0) print('No')
1
77,868,308,312,450
null
226
226
a,b,c,k=map(int,input().split()) ai=0 bi=0 ci=0 if a >= k: ai=k else: ai=a if b>= k-ai: bi=k-ai else: bi=b ci= k - ai - bi print(ai-ci)
def backoutput(y): if y.isupper(): return y.lower() elif y.islower(): return y.upper() else: return y first_input = list(map(backoutput, input())) print(*first_input, sep='')
0
null
11,681,616,412,138
148
61
s = input() partition = s.replace('><','>|<').split('|') ans=0 for sub in partition: left = sub.count('<') right = sub.count('>') ans += sum(range(1, max(left, right) + 1)) ans += sum(range(1, min(left, right))) print(ans)
s=list(input()) k=0 bef="x" n=[] ans=0 def kai(n): if n==0: return 0 ret=0 for i in range(1,n+1): ret+=i return ret for i in s: if bef!=i: if bef=="x": st=i bef=i k+=1 continue bef=i n.append(k) k=0 k+=1 n.append(k) n.reverse() if st==">": ans+=kai(n.pop()) while len(n)!=0: if len(n)==1: ans+=kai(n.pop()) else: f=n.pop() s=n.pop() if f>s: ans+=kai(f)+kai(s-1) else: ans+=kai(f-1)+kai(s) #print("{} {}".format(f,s)) print(ans)
1
156,789,072,093,698
null
285
285
# フェルマーの小定理 N, M, K = map(int, input().split()) m = 998244353 result = 0 n = 1 k = 1 for i in range(K + 1): # result += M * mcomb(N - 1, i) * pow(M - 1, N - 1 - i, 998244353) result += n * pow(k, m - 2, m) * pow(M - 1, N - 1 - i, m) result %= m n *= N - 1 - i n %= m k *= i + 1 k %= m result *= M result %= m print(result)
#import numpy as np import math #from decimal import * #from numba import njit #@njit def main(): (N, M, K) = map(int, input().split()) MOD = 998244353 fact = [1]*(N+1) factinv = [1]*(N+1) for i in range(1,N+1): fact[i] = fact[i-1]*i % MOD factinv[i] = pow(fact[i], MOD-2, MOD) def comb(n, k): return fact[n] * factinv[k] * factinv[n-k] % MOD ans = 0 for k in range(K+1): ans += (comb(N-1,k)*M*pow(M-1, N-k-1, MOD))%MOD print(ans%MOD) main()
1
23,290,848,379,836
null
151
151
n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) """ def exhaustive_search(m, i): if i == n: return 0 if m < 0: return 0 if m == A[i]: return 1 return max(exhaustive_search(m, i + 1), exhaustive_search(m - A[i], i + 1)) """ def dp_search(m): dp = [[1] + [0] * m for _ in range(n + 1)] # dp[i][j] i番目まででjを作れるか for i in range(1, n+1): for j in range(1, m+1): if j >= A[i-1]: dp[i][j] = max(dp[i-1][j], dp[i-1][j - A[i-1]]) else: dp[i][j] = dp[i-1][j] return dp[n][m] for mi in m: if dp_search(mi): print("yes") else: print("no")
class Solver(): def __init__(self, A: [int]): self.A = A self.max_depth = len(A) def solve(self, tgt): self.tgt = tgt self.history = (self.max_depth+1)*[4000 * [None]] self.history = [[None for i in range(4000)] for x in range(self.max_depth + 1)] if self._rec_solve(0, 0): return 'yes' else: return 'no' def _rec_solve(self, _sum, index): if self.history[index][_sum] is not None: return self.history[index][_sum] if _sum == self.tgt: self.history[index][_sum] = True return True if index >= self.max_depth or _sum > self.tgt: self.history[index][_sum] = False return False self.history[index][_sum] = self._rec_solve(_sum + self.A[index], index + 1) or self._rec_solve(_sum, index + 1) return self.history[index][_sum] if __name__ == '__main__': n = int(input()) A = [int(i) for i in input().rstrip().split()] q = int(input()) m_ary = [int(i) for i in input().rstrip().split()] s = Solver(A) for val in m_ary: print(s.solve(val))
1
100,364,335,818
null
25
25
N=int(input()) S=set() for i in range(1,N): x=i y=N-i if x<y: S.add(x) print(len(S))
N = int(input()) if N % 2 != 0: print((N + 1) // 2 - 1) else: print(N//2 -1)
1
153,195,827,145,340
null
283
283
n,k=map(int,input().split()) a=list(map(int,input().split())) data=[0]*(n+1) data[1]=1 ans=[1] res=0 for i in range(n): p=a[res] if data[p]==0: data[p]=1 ans.append(p) res=p-1 else: res=ans.index(p) break if len(ans)>k: print(ans[k]) else: m=len(ans)-res k-=res d=k%m print(ans[res+d])
def main(): n, k = map(int, input().split()) a_list = list(map(int, input().split())) visited_list = [-1] * n # 何ワープ目で訪れたか visited_list[0] = 0 city, loop, non_loop = 1, 0, 0 # 今いる街、何ワープでループするか、最初にループするまでのワープ数 for i in range(1, n + 1): city = a_list[city - 1] if visited_list[city - 1] != -1: loop = i - visited_list[city - 1] non_loop = visited_list[city - 1] - 1 break else: visited_list[city - 1] = i city = 1 if k <= non_loop: for _ in range(k): city = a_list[city - 1] else: for _ in range(non_loop + (k - non_loop) % loop + loop): city = a_list[city - 1] print(city) if __name__ == "__main__": main()
1
22,687,260,900,092
null
150
150
nums = list(map(int, input().split())) import random class dice: def __init__(self): self.top = 0 self.right = 0 self.front = 0 self.left = 0 self.back = 0 self.bottom = 0 def set_num(self, nums): self.top, self.front, self.right, self.left, self.back, self.bottom = nums return self def get_right(self, f_top, f_front): while f_top!=self.top or f_front!=self.front: self.roll(random.randint(0,3)) return self.right def roll(self, command): if command==0: self.top, self.front, self.right, self.left, self.back, self.bottom = self.left, self.front, self.top, self.bottom, self.back, self.right elif command==1: self.top, self.front, self.right, self.left, self.back, self.bottom = self.right, self.front, self.bottom, self.top, self.back, self.left elif command==2: self.top, self.front, self.right, self.left, self.back, self.bottom = self.front, self.bottom, self.right, self.left, self.top, self.back elif command==3: self.top, self.front, self.right, self.left, self.back, self.bottom = self.back, self.top, self.right, self.left, self.bottom, self.front d = dice() d.set_num(nums) n = int(input()) for i in range(n): f_t, f_r = map(int, input().split()) print(d.get_right(f_t, f_r))
A,B,C,D,E,F = map(int, input().split()) q = int(input()) for i in range(q): x, y = map(int, input().split()) while A != x: A,B,C,D,E,F = D,B,A,F,E,C #E if A == x: break A,B,C,D,E,F = B,F,C,D,A,E #N while B != y: A,B,C,D,E,F = A,C,E,B,D,F #R print(C)
1
257,051,969,580
null
34
34
N = int(input()) A = [] for i in range(N): a = int(input()) xy = [list(map(int, input().split())) for _ in range(a)] A.append([a, xy]) # print(A) # 下からi桁目のbitが1->人iは正直 # 下からi桁目のbitが0->人iは不親切 # 不親切な人の証言は無視して良い ans = 0 for i in range(2**N): for j in range(N): flag = 0 if (i >> j) & 1: for k in range(A[j][0]): l = A[j][1][k][0] m=A[j][1][k][1] # print(i,j,k,(l,m),(i >> (l-1))) if not (i >> (l-1)) & 1 == A[j][1][k][1]: flag = 1 break if flag == 1: break else: # print(bin(i)) ct = 0 for l in range(N): ct += ((i >> l) & 1) ans = max(ans, ct) print(ans)
def main(): a, b, c = map(int, input().split()) if (a == b and b != c) or (b == c and a != b) or (a == c and a != b): print('Yes') else: print('No') main()
0
null
94,583,690,727,204
262
216
# 公式解説を見てからやった # 複数サイクルでき、1-K回移動可能 # N < 5000?多分、O(N * 2N)くらいで行けそうに見えるが。。。 def main(N,K,P,C): # 一度計算したサイクル情報を一応キャッシュしておく。。。 # あんまり意味なさそう cycleIDs = [ -1 for _ in range(N) ] cycleInfs = [] # print(P) ans = -1e10 cycleID = 0 for n in range(N): v = n currentCycleItemCnt = 0 currentCycleTotal = 0 if cycleIDs[v] != -1: currentCycleItemCnt, currentCycleTotal = cycleInfs[ cycleIDs[v] ] # print(currentCycleItemCnt, currentCycleTotal) else: while True: # 全頂点について、属するサイクルを計算する currentCycleItemCnt += 1 currentCycleTotal += C[v] v = P[v] if v == n: # サイクル発見 cycleInfs.append( (currentCycleItemCnt, currentCycleTotal) ) cycleID += 1 break # 一応、一度サイクルを計算した頂点については、 # その頂点の属するサイクルの情報をメモっておく。。。 cycleIDs[v] = cycleID procCnt = 0 currentCycleSumTmp = 0 while True: # 頂点vにコマが置かれた時の最高スコアを計算し、 # これまでの最高スコアを上回ったら、これまでの最高スコアを更新する procCnt += 1 currentCycleSumTmp += C[v] if K < procCnt: break cycleLoopCnt = 0 if procCnt < K and 0 < currentCycleTotal: cycleLoopCnt = ( K - procCnt ) // currentCycleItemCnt # print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, procCnt) tmp = currentCycleSumTmp + cycleLoopCnt * currentCycleTotal ans = max( ans, tmp ) v = P[v] if v == n: # サイクル終了 break return ans # print(ans) if __name__ == "__main__": N,K = map(int,input().split()) P = [ int(p)-1 for p in input().split() ] C = list(map(int,input().split())) ans=main(N,K,P,C) print(ans)
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()) N,K = map(int,input().split()) P = list(map(int,input().split())) C = list(map(int,input().split())) uf = UnionFind(N) ans = -10**9 for i in range(N): uf.union(i,P[i]-1) for group in uf.all_group_members().values(): size = len(group) SUM = 0 for i in group: SUM += C[i] if SUM < 0: SUM = 0 for i in group: cur = i current_sum = 0 remain = K for _ in range(size): cur = P[cur]-1 current_sum += C[cur] remain -= 1 if remain < 0: break ans = max(ans,current_sum+SUM*(remain//size)) print(ans)
1
5,431,785,859,328
null
93
93
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): from itertools import permutations N = int(readline()) P = tuple(map(int, readline().split())) Q = tuple(map(int, readline().split())) d = {x: i for i, x in enumerate(permutations(range(1, N + 1)))} print(abs(d[Q] - d[P])) if __name__ == '__main__': main()
#!/usr/bin/env python3 n, a, b = map(int, input().split()) if (b - a) % 2 < 1: print((b - a) // 2) else: print(min((a + b - 1) // 2, (2 * n - a - b + 1) // 2))
0
null
104,989,617,596,082
246
253
x = int(input()) money = 100 year = 0 if x <= 100: print(0) exit() while True: money += money*100//10000 year += 1 if money >= x: print(year) exit()
# 1% import math N = int(input()) x = 100 ans = 0 while x < N: x += x // 100 ans += 1 print(ans)
1
27,109,591,951,262
null
159
159
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)
# cook your dish here import sys def file(): sys.stdin = open('input.py', 'r') sys.stdout = open('output.py', 'w') #file() def main(N, arr): #initialising with positive infinity value maxi=float("inf") #initialising the answer variable ans=0 #iterating linesrly for i in range(N): #finding minimum at each step maxi=min(maxi,arr[i]) #increasing the final ans ans+=maxi print("dhh") #returning the answer return ans if __name__ == '__main__': #length of the array '''N = 4 #Maximum size of each individual bucket Arr = [4,3,2,1] #passing the values to the main function answer = main(N,Arr) #printing the result print(answer)''' n=int(input()) l=list(map(int, input().split())) ans=0 for i in range(n): for j in range(i+1,n): ans+=(l[i]*l[j]) print(ans)
0
null
129,336,372,363,630
238
292
a,b,c = map(int,input().split()) k = int(input()) for i in range(k): if a >= b: b *= 2 else: c *= 2 print("Yes" if a < b and b < c else "No")
import sys A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [] for e in sys.stdin: c.append(list(map(int, e.split()))) ans = min(a) + min(b) for i in range(len(c)): temp_val = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2] if temp_val < ans: ans = temp_val print(ans)
0
null
30,505,239,622,890
101
200
#coding:utf-8 import sys ab=sys.stdin.readline() rect=ab.split( ' ' ) for i in range(2): rect[i]=int( rect[i]) print( "{} {}".format( rect[0]*rect[1], rect[0]*2+rect[1]*2) )
while True: a,op,b=raw_input().split() if op == "?":break if op == "+":print int(a) + int(b) if op == "-":print int(a) - int(b) if op == "*":print int(a) * int(b) if op == "/":print int(a) / int(b)
0
null
491,716,061,020
36
47