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
r=input().split() N=int(r[0]) d_pre=input().split() d=[int(s) for s in d_pre] ans=N-sum(d) if ans>=0: print(ans) else: print(-1)
N, M = map(int, input().split()) print(max(-1, N-sum(map(int, input().split()))))
1
31,926,387,343,620
null
168
168
class Card: def __init__(self, data, i): self.suit = data[0] self.value = data[1] self.initord = i def BubbleSort(cards, N): for i in range(N): for j in range(N - 1, i, -1): if cards[j].value < cards[j - 1].value: cards[j], cards[j - 1] = cards[j - 1], cards[j] def SelectionSort(cards, N): for i in range(N): min_j = i for j in range(i + 1, N): if cards[j].value < cards[min_j].value: min_j = j cards[i], cards[min_j] = cards[min_j], cards[i] N = int(input()) cards = [Card(data, i) for i, data in enumerate(input().split())] cards1 = cards.copy() cards2 = cards.copy() BubbleSort(cards1, N) SelectionSort(cards2, N) print(*[card.suit + card.value for card in cards1]) for i in range(N - 1): if cards1[i].value == cards1[i + 1].value: if cards1[i].initord > cards1[i + 1].initord: print("Not stable") break else: print("Stable") print(*[card.suit + card.value for card in cards2]) for i in range(N - 1): if cards2[i].value == cards2[i + 1].value: if cards2[i].initord > cards2[i + 1].initord: print("Not stable") break else: print("Stable")
N, K = list(map(int, input().split())) P = list(map(int, input().split())) s = sum(P[:K]) ans = s for i in range(N-K): s = s - P[i] + P[i+K] ans = max(ans,s) print((ans + K) / 2)
0
null
37,359,846,357,432
16
223
n = int(input()) A = list(map(int, input().rstrip().split(" "))) q = int(input()) M = list(map(int, input().rstrip().split(" "))) existBits = 1 for a in A: existBits |= existBits << a if(__name__ == '__main__'): for m in M: judge = (existBits << m) if(((existBits >> m) & 1) == 1): print("yes") else: print("no")
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) value = [] for i in range(2 ** n): ans = 0 for j in range(n): # このループが一番のポイント if ((i >> j) & 1): # 順に右にシフトさせ最下位bitのチェックを行う ans += a[j] value.append(ans) for mm in range(len(m)): if m[mm] in value: print("yes") else: print("no")
1
101,360,410,302
null
25
25
N = 26 D = int(input()) c_list = list(map(int, input().split())) s_table = [] for _ in range(D): s_table.append(list(map(int, input().split()))) data = [] for _ in range(D): data.append(int(input()) - 1) def calc(data): last = [-1] * N satisfaction = 0 for i in range(D): j = data[i] satisfaction += s_table[i][j] last[j] = i for k in range(N): satisfaction -= c_list[k] * (i - last[k]) print(satisfaction) return satisfaction calc(data)
D = int(input()) C = [int(T) for T in input().split()] S = [[] for TD in range(0,D)] for TD in range(0,D): S[TD] = [int(T) for T in input().split()] Type = 26 Last = [0]*Type Sats = 0 for TD in range(0,D): Test = int(input())-1 Last[Test] = TD+1 Sats += S[TD][Test] for TC in range(0,Type): Sats -= C[TC]*(TD+1-Last[TC]) print(Sats)
1
9,969,185,023,200
null
114
114
N = int(input()) music = [] for _ in range(N): s, t = map(str, input().split()) music.append([s, int(t)]) number = input() ans = 0 flag = False for i in range(N): if flag: ans += music[i][1] elif number == music[i][0]: flag = True print(ans)
N=int(input()) music=[] T=[] ans=0 for i in range(N): s, t=input().split() t=int(t) music.append(s) T.append(t) X=input() num=music.index(X) for j in range(num+1, N): ans+=T[j] print(ans)
1
97,294,286,347,930
null
243
243
import math H = int(input()) l = math.log(H,2) ll = math.floor(l)+1 ans = 2 ** ll -1 print(ans)
n = int(raw_input()) debt=100000 for i in range(n): debt*=1.05 if debt % 1000 != 0: debt = (int(debt / 1000)+1) * 1000 else: debt = int(debt) print debt
0
null
40,072,525,953,280
228
6
def resolve(): s = input() if "RRR" in s: res = 3 elif "RR" in s: res = 2 elif "R" in s: res = 1 else: res = 0 print(res) resolve()
N = int(input()) tax_min = int(N*0.08/1.08) tax_max = int((N+1)*0.08/1.08) if tax_min != tax_max: print(":(") else: print(N - tax_min)
0
null
65,285,324,325,330
90
265
a,k,d = map(int, input().split()) if a < 0: x = -a else: x = a y = x % d l = x // d m = k - l if m < 0: ans = x - (k * d) elif m % 2 ==0: ans = y else : ans = y - d print(abs(ans))
#E H,W,K = map(int,input().split()) S = [list(str(input())) for _ in range(H)] inf = float("inf") ans = inf T = 2**(H-1) for i in range(T): b = bin(i) b = b.lstrip("0b") blist = list(b) lb = len(b) clist = blist[::-1] while lb < H-1: clist.append("0") lb+=1 r = clist.count("1") count = r nw = [0]*(r+1) for w in range(W): nind = 0 for h in range(H): if h > 0: if clist[h-1] == "1": nind+=1 if S[h][w] == "1": nw[nind]+=1 if w == 0: pass else: for k in nw: if k > K: count+=1 nw = [0]*(r+1) nind = 0 for h in range(H): if h > 0: if clist[h-1] == "1": nind+=1 if S[h][w] == "1": nw[nind]+=1 if max(nw) > K: count = inf break ans = min(ans,count) print(ans)
0
null
26,948,899,600,910
92
193
n=int(input()) st=[] for i in range(n): s,t=input().split() st.append((s,t)) x=input() flg=False ans=0 for i in range(n): if flg: ans+=int(st[i][1]) if st[i][0]==x: flg=True print(ans)
def main(): musics = int(input()) title = [] time = [] for _ in range(musics): s, t = input().split() title.append(s) time.append(int(t)) last_song = input() for i in range(musics): if title[i] == last_song: print(sum(time[i + 1:])) break if __name__ == '__main__': main()
1
96,998,879,190,600
null
243
243
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()) # class UnionFind(): # par = [] # sizes = [] # def __init__(self, N): # self.par = [i for i in range(N)] # self.sizes = [1 for _ in range(N)] # def root(self, x: int)-> int: # if (self.par[x] == x): # return x # return self.root(self.par[x]) # def unite(self, x: int, y: int): # rootX = self.root(x) # rootY = self.root(y) # if rootX == rootY: # return # self.par[rootX] = rootY # self.sizes[rootY] += self.sizes[rootX] # def maxSize(self)-> int: # return max(self.sizes) def friends(N, As): uf = UnionFind(N) setAs = list(set(As)) for val in setAs: uf.union(val[0]-1, val[1]-1) ans = 0 for i in range(N): temp = uf.size(i) if ans < temp: ans = temp return ans if __name__ == "__main__": nm = list(map(int, input().split())) As =[tuple(map(int, input().split())) for _ in range(nm[1])] print(friends(nm[0], As))
w = input().lower() count = 0 while True: s = input() if s == "END_OF_TEXT": break count += s.lower().split().count(w) print(count)
0
null
2,864,604,611,010
84
65
A = [] b = [] n,m = [int(i) for i in input().split()] for i in range(n): A.append([int(j) for j in input().split()]) for i in range(m): b.append(int(input())) for i in range(n): print(sum([x*y for x,y in zip(A[i],b)]))
data = list(map(int, list(input().split()))) row = data[0] column = data[1] matrix = [[0 for i in range(column)] for j in range(row)] vector = [[0] for k in range(column)] vector_multi = [[0] for l in range(row)] for i in range(row): data_row = list(map(int, list(input().split()))) for j in range(column): matrix[i][j] = data_row[j] for i in range(column): vector[i] = int(input()) for i in range(row): element = 0 for j in range(column): element += matrix[i][j] * vector[j] vector_multi[i][0] = element for i in vector_multi: print(i[0])
1
1,189,647,466,180
null
56
56
mol=[] for i in range(10): mol.append(int(input())) mol.sort(key=None,reverse=True) for i in range(3): print(mol[i])
a = [] for i in range(10) : a.append(int(input())) a.sort() a.reverse() print("%d\n%d\n%d" % (a[0], a[1], a[2]))
1
22,926,708
null
2
2
a,b,k = map(int,input().split()) if a < k: print(max(0,a-k),max(0,b+a-k)) else: print(max(0,a-k),b)
h,w,k=map(int,input().split()) s=[[int(j) for j in input()] for i in range(h)] def popcount(x): global h ret=0 for i in range(h-1): ret+=(x>>i&1) return ret #できない場合は除く ans=1000000000000000 for i in range(2**(h-1)): p=popcount(i) div=[0]*(p+1) ans_sub=p f=False for j in range(w): now=0 div[now]+=s[0][j] for l in range(h-1): if i>>l&1: now+=1 div[now]+=s[l+1][j] if all(i<=k for i in div): continue else: div=[0]*(p+1) now=0 div[now]=s[0][j] for l in range(h-1): if i>>l&1: now+=1 div[now]+=s[l+1][j] ans_sub+=1 f=any(i>k for i in div) if not f:ans=min(ans,ans_sub) print(ans)
0
null
76,594,687,861,912
249
193
# D - Moving Piece n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) assert len(p) == len(c) == n visited = [False] * n scc = [] for i in range(n): if not visited[i]: scc.append([]) j = i while not visited[j]: visited[j] = True scc[-1].append(j) j = p[j] - 1 n_scc = len(scc) subsum = [[0] for i in range(n_scc)] for i in range(n_scc): for j in scc[i]: subsum[i].append(subsum[i][-1] + c[j]) for j in scc[i]: subsum[i].append(subsum[i][-1] + c[j]) def lister(k): for i in range(n_scc): l = len(scc[i]) loop_score = max(0, subsum[i][l]) for kk in range(1, min(k, l) + 1): base = loop_score * ((k - kk) // l) for j in range(kk, l + kk + 1): yield base + subsum[i][j] - subsum[i][j - kk] print(max(lister(k)))
n,k=map(int,input().split()) p=list(map(int,input().split())) c=list(map(int,input().split())) p=[x-1 for x in p] mi=set(range(n)) g={} # g[id]=[ary] while mi: x0=mi.pop() ary=[c[x0]] x=x0 while p[x]!=x0: x=p[x] mi.discard(x) ary.append(c[x]) cnt=len(ary) tmp=0 ary*=2 cary=[tmp] for x in ary: tmp+=x cary.append(tmp) g[x0]=[cnt,cary] ans=-float('inf') for cnt,cary in g.values(): x,y=divmod(k,cnt) tmp1=max(0,cary[cnt]*x) tmp2=-float('inf') for i in range(cnt): for j in range(y): tmp2=max(tmp2,cary[i+j+1]-cary[i]) ans=max(ans,tmp1+tmp2) if x: tmp1=max(0,cary[cnt]*(x-1)) tmp2=-float('inf') for i in range(cnt): for j in range(cnt): tmp2=max(tmp2,cary[i+j+1]-cary[i]) ans=max(ans,tmp1+tmp2) print(ans)
1
5,311,758,080,030
null
93
93
def resolve(): print("Yes" if "7" in input() else "No") if '__main__' == __name__: resolve()
n = int(input()) s = input() def rot(c, r): base = 65 return chr((ord(c)-base+r)%26+base) print(''.join([rot(i, n) for i in s]))
0
null
84,506,268,126,190
172
271
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): L = int(input()) print((L/3)**3) if __name__ == '__main__': main()
n = int(input()) a = n/3 print(a**3)
1
46,947,200,057,420
null
191
191
N=input() N=float(N) import math X=math.ceil(N/1.08) if int(X*1.08)==N: print(X) else: print(':(')
S = input() L = len(S) cnt = 0 for i in range(L//2): if S[i] == S[-1-i]: continue else: cnt += 1 print(cnt)
0
null
122,921,583,001,634
265
261
N = int(input()) d = list(map(int, input().split())) ans = 0 for i in range(N): for j in range(N-1): if i == j: break else: ans = ans + d[i]*d[j] print(ans)
N = int(input()) D = list(map(int, input().split())) S_1 = sum(D) S_2 = sum([d**2 for d in D]) print((sum(D)**2-S_2)//2)
1
168,396,036,693,742
null
292
292
n = int(input()) x = int(n**(1/2))+1 for i in range(1, x+1): if n%i == 0: p = i q = n//i print(p+q-2)
from collections import deque N = int(input()) p = 1 for i in range(2,int(N ** (1/2)+1)): if N % i == 0: p = i print(int(p+N/p)-2)
1
161,540,218,955,062
null
288
288
K = int(input()) A, B = map(int, input().split()) for n in range(A, B+1): if n%K ==0: print("OK") exit() print("NG")
from sys import stdin rs = stdin.readline ri = lambda : int(rs()) ril = lambda : list(map(int, rs().split())) def main(): K = ri() A, B = ril() for i in range(A, B + 1): if i % K == 0: ans = 'OK' break else: ans = 'NG' print(ans) if __name__ == '__main__': main()
1
26,619,230,353,548
null
158
158
import numpy as np mod = 998244353 n, s = map(int, input().split()) dp = np.zeros((n+1, s+1), dtype=int) dp[0, 0] = 1 for i, a in enumerate(map(int, input().split())): dp[i+1] = dp[i] * 2 % mod dp[i+1][a:] = (dp[i+1][a:] + dp[i][:-a]) % mod print(dp[-1, -1])
pi = 3.141592653589 r = float(input()) c = pi*r**2 s = 2*pi*r print('%.5f %.5f' % (c,s))
0
null
9,183,981,522,784
138
46
import itertools N = int(input()) L = [] for i in range(N): x,y = map(int,input().split()) L.append([x,y]) cnt = 0 total = 0 for v in itertools.permutations(L): for i in range(N-1): x_1 = v[i][0] y_1 = v[i][1] x_2 = v[i+1][0] y_2 = v[i+1][1] total += ((x_2 - x_1) ** 2 + (y_2 - y_1) ** 2) ** 0.5 cnt += 1 print(total/cnt)
import itertools import math N=int(input()) zahyou=[list(map(int,input().split()))for i in range(N)] jyunban=list(itertools.permutations(range(N))) dist=list() for i in range(len(jyunban)): tmp=0 for j in range(N-1): tmp+=math.sqrt((zahyou[jyunban[i][j]][0]-zahyou[jyunban[i][j+1]][0])**2+(zahyou[jyunban[i][j]][1]-zahyou[jyunban[i][j+1]][1])**2) dist.append(tmp) print(sum(dist)/math.factorial(N))
1
148,362,412,141,090
null
280
280
x, y = map(int,input().split()) if (y%2 == 1): print("No") else: if (y < x*2): print("No") elif (y > x*4): print("No") else: print("Yes")
from itertools import accumulate,chain n,*s=open(0).read().split() t=[2*i.count("(")-len(i) for i in s] st=[[min(accumulate(s_,lambda a,b: a+(1 if b=="(" else -1),initial=0)),t_] for s_,t_ in zip(s,t)] now=0 for c,d in chain(sorted([x for x in st if x[1]>=0])[::-1],sorted([x for x in st if x[1]<0],key=lambda z:z[1]-z[0])[::-1]): if now+c<0: print("No");break now+=d else: print("No" if now else "Yes")
0
null
18,828,035,460,872
127
152
D = int(input()) C = [int(x) for x in input().split()] S = [[int(i) for i in input().split()] for D in range(D)] T = [0]*D for i in range(D): T[i] = int(input()) score = [0]*26 last = [-1]*26 for i in range(D): score[T[i]-1] += S[i][T[i]-1] last[T[i]-1] = i for j in range(26): score[j] -= C[j]*(i-last[j]) print(sum(score))
from math import gcd K = int(input()) ans = 0 for h in range(1, K+1): for i in range(1, K+1): for j in range(1, K+1): ans += gcd(h, gcd(i, j)) print(ans)
0
null
22,642,663,930,312
114
174
import math def merge(a,l,m,r): global cnt L = a[l:m]+[math.inf] R = a[m:r]+[math.inf] i = 0 j = 0 for k in range(l,r): cnt+=1 if L[i]<=R[j]: a[k] = L[i] i+=1 else: a[k]=R[j] j+=1 def mergeSort(a,l,r): if l+1<r: m = (l+r)//2 mergeSort(a,l,m) mergeSort(a,m,r) merge(a,l,m,r) n = int(input()) a = list(map(int, input().split())) cnt = 0 mergeSort(a,0,n) print(*a) print(cnt)
N = int(input()) a = N//2 b = N%2 if b==0: a -=1 print(a)
0
null
76,464,988,989,830
26
283
from math import gcd n=int(input()) a=list(map(int,input().split())) x=[-1]*(10**6+5) x[0]=0 x[1]=1 i=2 while i<=10**6+1: j=2*i if x[i]==-1: x[i]=i while j<=10**6+1: x[j]=i j+=i i+=1 z=[0]*(10**6+5) g=gcd(a[0],a[0]) for i in range(n): g=gcd(g,a[i]) if g!=1: print("not coprime") else: f=0 for i in range(n): p=1 while a[i]>=2: if p==x[a[i]]: a[i]=a[i]//p continue else: p=x[a[i]] z[p]+=1 a[i]=a[i]//p for i in range(10**6+1): if z[i]>=2: f=1 print("pairwise coprime" if f==0 else "setwise coprime")
#!/usr/bin/env python3 import sys # import math # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product # product(iter, repeat=n) # from itertools import accumulate # accumulate(iter[, f]) # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from copy import deepcopy # to copy multi-dimentional matrix without reference # from fractions import gcd # for Python 3.4 def main(): mod = 1000000007 # 10^9+7 inf = float('inf') sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) h, w, k = mi() L = [] for _ in range(h): L.append(list(map(int, li()))) L_trans = [[None] * h for _ in range(w)] for i in range(h): for j in range(w): L_trans[j][i] = L[i][j] d = 2 ** (h-1) cost = [float('inf')] * d for state in range(d): bit_count = bin(state)[2:].count('1') separated = [[0] * (bit_count + 1) for _ in range(w)] for i in range(w): current = 0 for j in range(h): if j >= 1 and 1 << (j-1) & state: current += 1 if L_trans[i][j]: separated[i][current] += 1 previous = [0] * (bit_count + 1) cnt = 0 # print(separated) for i in range(w): if any(map(lambda x: x > k, separated[i])): break if all(map(lambda x: x <= k, [elm + previous[ind] for ind, elm in enumerate(separated[i])])): # print(f"just add: {previous} {separated[i]}") for ind, elm in enumerate(separated[i]): previous[ind] += elm # 追加 else: cnt += 1 # print(f"count up: {previous} {separated[i]}") for ind, elm in enumerate(separated[i]): previous[ind] = elm # 上書き else: cost[state] = bit_count + cnt # print(cost) print(min(cost)) if __name__ == "__main__": main()
0
null
26,455,262,198,428
85
193
n = int(input()) ls = [] rs = [] for _ in range(n): x, y = map(int, input().split()) ls.append(x) rs.append(y) ls = sorted(ls) rs = sorted(rs) if n % 2 == 1: print(rs[len(rs)//2] - ls[len(ls)//2] + 1) else: a = (rs[len(rs)//2-1] * 10 + rs[len(rs)//2] * 10) // 2 b = (ls[len(ls)//2-1] * 10 + ls[len(ls)//2] * 10) // 2 print((a - b) // 5 + 1)
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def MAP1() : return map(lambda x:int(x)-1,input().split()) def LIST() : return list(MAP()) def LIST1() : return list(MAP1()) def solve(): N = INT() a = [] b = [] for i in range(N): A, B = MAP() a.append(A) b.append(B) a.sort() b.sort() if N % 2 == 1: am = a[(N+1)//2-1] bm = b[(N+1)//2-1] ans = bm - am + 1 else: am = ( a[N//2-1]+a[N//2] ) / 2 bm = ( b[N//2-1]+b[N//2] ) / 2 ans = int( ( bm - am ) * 2 + 1 ) print(ans) if __name__ == '__main__': solve()
1
17,218,907,287,978
null
137
137
class UnionFind(): """ unionfindtree のクラス グループを管理するデータ構造. 全てのメソッドの計算量が O(log(n)) よりも小さい init: 管理対象の個数 n を用いて初期化 find: ある要素 x の親がどの要素か返す union: ある要素 x と y が属しているグループを結合して1つのグループとする msize: ある要素 x が属するグループの大きさを返す """ def __init__(self, n): self.n = n self.parents = [-1]*n self.rank = [0]*n self.size = [1]*n def find(self, x): """ ある要素 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, y の属するグループを結合するメソッド x と y のランク(子の数)の小さい方が結合先の親となる """ x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.size[y] += self.size[x] self.parents[x] = y else: self.size[x] += self.size[y] self.parents[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def msize(self, x): """ ある要素 x の属するグループの大きさを返すメソッド """ return self.size[self.find(x)] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def main(): N, Q = map(int, input().split()) uf = UnionFind(N) for _ in range(Q): u, v = map(int, input().split()) uf.union(u-1, v-1) print(uf.group_count()-1) if __name__ == "__main__": main()
print(7 - ['SUN','MON','TUE','WED','THU','FRI','SAT'].index(input()))
0
null
67,423,131,310,752
70
270
from heapq import * import sys from collections import * from itertools import * from decimal import * import copy from bisect import * import math sys.setrecursionlimit(4100000) def gcd(a,b): if(a%b==0):return(b) return (gcd(b,a%b)) input=lambda :sys.stdin.readline().rstrip() N,K=map(int,input().split()) A=list(map(int,input().split())) def main(n): return(sum([max(i//n-(i%n==0)*1,0) for i in A])<=K) #print(main(5)) ng=0 ok=10**18 while ok-ng>1: mid=(ok+ng)//2 if main(mid): ok=mid else: ng=mid print(ok)
import sys import math t1, t2 = [int(i) for i in sys.stdin.readline().split()] a1, a2 = [int(i) for i in sys.stdin.readline().split()] b1, b2 = [int(i) for i in sys.stdin.readline().split()] a1 -= b1 a2 -= b2 _sum = a1 * t1 + a2 * t2 if _sum == 0: print("infinity") elif _sum * a1 > 0: print("0") else: cnt = (-a1 * t1) / _sum res = math.ceil(cnt) * 2 - 1 + (cnt % 1 == 0) print(res)
0
null
68,727,906,537,816
99
269
import sys import math import bisect def main(): n = int(input()) ans = ((n+1)//2) / n print('%.10f' % ans) if __name__ == "__main__": main()
n = int(input()) if (n % 2 == 1): count = (n // 2) + 1 else: count = n // 2 print("{:.10f}".format(count/n))
1
177,600,368,170,300
null
297
297
def main(): s = input() k = int(input()) count_l = [] i = 0 counter = 1 while True: if len(s) == 1: count_l.append(counter) break elif s[i] == s[i+1]: counter += 1 else: count_l.append(counter) counter = 1 i += 1 if i == len(s)-1: if counter == 1: break else: count_l.append(counter) break answer = 0 if len(count_l) >= 3 and s[0] == s[-1] and k >= 2: sub_l = [count_l[0] + count_l[-1]] + count_l[1:-1] for i in range(len(sub_l)): answer += (sub_l[i] // 2) * (k - 1) for j in range(len(count_l[:-1])): answer += count_l[j] // 2 answer += count_l[-1] // 2 elif len(count_l) == 1: answer += (count_l[0] * k) // 2 else: for i in range(len(count_l)): answer += (count_l[i] // 2) * k print(answer) if __name__ == "__main__": main()
import queue n = int(input()) alp = "abcdefghijklmn" q = queue.Queue() q.put("a") while not q.empty(): qi = q.get() if len(qi) == n: print(qi) elif len(qi) < n: idx = alp.index(max(qi)) for i in range(idx+2): q.put(qi+alp[i])
0
null
113,836,373,929,578
296
198
s=input() for i in range(len(s)-1): if s[i]!=s[i+1]: print("Yes") exit() print("No")
cnt = 0 for _ in range(int(input())): a, b = map(int, input().split()) if a == b: cnt += 1 else: cnt = 0 if cnt > 2: print("Yes") quit() print("No")
0
null
28,634,806,263,300
201
72
while True: try: a, b = map(int, input().split()) i = a + b c = 1 while i: if int(i/10) == 0: print(c) break c+=1 i /= 10 except Exception: break
while True: m, f, r = map(int, input().split()) if m == f == r == -1: break s = m + f if m == -1 or f == -1: print("F") elif s >= 80: print("A") elif s >= 65: print("B") elif s >= 50 or r >= 50: print("C") elif s >= 30: print("D") else: print("F")
0
null
619,178,632,570
3
57
class Dice: def __init__(self,s1,s2,s3,s4,s5,s6): self.s1 = s1 self.s2= s2 self.s3= s3 self.s4= s4 self.s5 = s5 self.s6= s6 def east(self): prev_s1 = self.s1 #prev_s1を固定していないと以前の値が後述でs1に値を代入するとき変わってしまう。 prev_s3 = self.s3 prev_s4 = self.s4 prev_s6 = self.s6 self.s1 = prev_s4 self.s3 = prev_s1 self.s4 = prev_s6 self.s6 = prev_s3 def west(self): prev_s1 = self.s1 prev_s3 = self.s3 prev_s4 = self.s4 prev_s6 = self.s6 self.s1 = prev_s3 self.s3 = prev_s6 self.s4 = prev_s1 self.s6 = prev_s4 def south(self): prev_s1 = self.s1 prev_s2 = self.s2 prev_s5 = self.s5 prev_s6 = self.s6 self.s1 = prev_s5 self.s2 = prev_s1 self.s5 = prev_s6 self.s6 = prev_s2 def north(self): prev_s1 = self.s1 prev_s2 = self.s2 prev_s5 = self.s5 prev_s6 = self.s6 self.s1 = prev_s2 self.s2 = prev_s6 self.s5 = prev_s1 self.s6 = prev_s5 def top(self): return self.s1 s1,s2,s3,s4,s5,s6 = map(int,input().split()) dice = Dice(s1,s2,s3,s4,s5,s6) order = input() for c in order: if c =='N': dice.north() elif c =='S': dice.south() elif c =='E': dice.east() elif c == 'W': dice.west() print(dice.top())
N = input() if '7' in N: print('Yes') else: print('No')
0
null
17,336,302,039,650
33
172
def main(): A,B,M=map(int,input().split()) a=[int(_) for _ in input().split()] b=[int(_) for _ in input().split()] ans=min(a)+min(b) for m in range(M): x,y,c=map(int,input().split()) ans=min(ans,a[x-1]+b[y-1]-c) print(ans) main()
from sys import stdin import math import re import queue input = stdin.readline MOD = 1000000007 INF = 122337203685477580 def solve(): A,B,M = map(int, input().split()) v1 =list(map(int, input().split())) v2 =list(map(int, input().split())) res = INF for i in range(M): X,Y,C = map(int, input().split()) res = min(res,v1[X-1] + v2[Y-1] - C) res = min(res,min(v1) + min(v2)) res = max(0,res) print(res) if __name__ == '__main__': solve()
1
53,949,290,726,308
null
200
200
N=int(input()) if N%2==1: print(0) exit(0) ans=N//10 cur=N//10 while cur//5>0: cur//=5 ans+=cur print(ans)
h = int(input()) ans = 0 cnt = 1 while h > 1: ans += cnt h /= 2 cnt = cnt * 2 if int(h) == 1: ans += cnt print(ans)
0
null
97,702,715,293,598
258
228
n=int(input()) A=[int(i) for i in input().split()] mod=10**9+7 ans=0 cnt=[0 for i in range(61)] for i in range(n): now=A[i] bek=1 for q in range(61): if now&1==0: ans+=cnt[q]*bek else: ans+=(i-cnt[q])*bek bek=bek*2%mod cnt[q]+=now&1 now>>=1 ans=ans%mod #print(ans) print(ans)
def main(): N=int(input()) A=list(map(int,input().split())) mod=10**9+7 ans=0 for i in range(60): c=0 for j in A: if j>>i&1: c+=1 ans+=pow(2,i,mod)*c*(N-c) ans%=mod print(ans) if __name__=='__main__': main()
1
123,376,862,821,450
null
263
263
import math a,b,x = map(int,input().split()) if x >= (a**2) * b / 2 : theta = math.atan(2*(b-x/(a**2))/a) print(math.degrees(theta)) else : theta = math.pi/2-math.atan(2*x/((a*(b**2)))) print(math.degrees(theta))
from math import atan,pi a,b,x=map(int,input().split()) if b-x/a**2 <= x/a**2:print(atan((b-x/a**2)/(a/2))*(180/pi)) else: y = x/a*2/b print(atan(b/y)*(180/pi))
1
163,205,945,267,768
null
289
289
text = input() result = '' for i in range(len(text)): code = ord(text[i]) if ord('A') <= code <= ord('Z'): result += chr(code + 32) elif ord('a') <= code <= ord('z'): result += chr(code - 32) else: result += chr(code) print(result)
#!/usr/bin/env python # coding: utf-8 def ri(): return int(input()) def rl(): return list(input().split()) def rli(): return list(map(int, input().split())) def main(): k = ri() print("ACL"*k) if __name__ == '__main__': main()
0
null
1,805,377,148,868
61
69
import bisect import math N, D, A = map(int, input().split()) XH_array = [list(map(int, input().split())) for _ in range(N)] XH_array = sorted(XH_array, key=lambda x: x[0]) X_array = [xh[0] for xh in XH_array] # print(X_array) ans = 0 bomb_count = [0] * N now_bomb = 0 for i, xh in enumerate(XH_array): # print(now_bomb, bomb_count) x, h = xh remain = h - A * now_bomb if remain <= 0: now_bomb += bomb_count[i] continue bomb_add = math.ceil(remain / A) ans += bomb_add bomb_count[i] += bomb_add bomb_end = bisect.bisect_right(X_array, x + 2 * D) bomb_count[bomb_end - 1] -= bomb_add now_bomb += bomb_count[i] print(ans)
n=int(input()) a=list(map(int,input().split())) num1=[0]*(2*(10**5)+10) num2=[0]*(2*(10**5)+10) for i in range(n): if a[i]+i+1<2*(10**5)+5: num1[a[i]+i+1]+=1 if a[i]+1<i+1: num2[-a[i]+i+1]+=1 ans=0 for i in range(len(num1)): ans+=num1[i]*num2[i] print(ans)
0
null
54,230,750,672,960
230
157
import sys input = sys.stdin.readline M1,D1 = map(int, input().split()) M2,D2 = map(int, input().split()) if(M1+1==M2):print(1) else: print(0)
import sys input = sys.stdin.readline def main(): M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) if M1 == M2: ans = 0 else: ans = 1 print(ans) if __name__ == "__main__": main()
1
124,429,448,316,512
null
264
264
from __future__ import division, print_function from sys import stdin n = int(stdin.readline()) result = [0, 0] for _ in range(n): taro, hanako = stdin.readline().split() if taro > hanako: result[0] += 3 elif taro < hanako: result[1] += 3 else: result[0] += 1 result[1] += 1 print(*result)
n = int(input()) point = [0, 0] for i in range(n): a, b = input().split() if a > b: point[0] += 3 elif a < b: point[1] += 3 else: point[0] += 1 point[1] += 1 print(*point)
1
1,989,607,163,610
null
67
67
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor from operator import mul from functools import reduce sys.setrecursionlimit(2147483647) INF = 10 ** 20 def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 1000000007 n, k = LI() A = [0] + LI() for i in range(1, n + 1): A[i] = (A[i] + A[i - 1]) % k for i in range(n + 1): A[i] = (A[i] - i) % k ans = 0 D = defaultdict(int) for j in range(n, -1, -1): ans += D[A[j]] D[A[j]] += 1 if j + k - 1 < n + 1: D[A[j + k - 1]] -= 1 if k == 1: print(0) else: print(ans)
data = int(input()) if data>=30: print("Yes") else: print("No")
0
null
71,550,932,359,608
273
95
import sys num = int(sys.stdin.readline().strip()) r0 = int(sys.stdin.readline().strip()) r1 = int(sys.stdin.readline().strip()) max_dis = r1 - r0 min_num = min(r0, r1) for i in range(0, num-2): r = int(sys.stdin.readline().strip()) max_dis = max(max_dis, r - min_num) min_num = min(min_num, r) print max_dis
import sys d = -float('inf') n = int(input()) l = int(input()) for s in sys.stdin: r = int(s) d = max(d, r-l) l = min(l, r) print(d)
1
13,142,578,780
null
13
13
def mod_pow(a, n): res = 1 while n > 0: if n & 1: res = res * a % mod a = a * a % mod n >>= 1 return res n = int(input()) a = list(map(int, input().split())) mod = 10 ** 9 + 7 cnt = [0] * 60 for v in a: for i in range(60): if (v >> i) & 1: cnt[i] += 1 pow_2 = [1] for i in range(60): pow_2.append(pow_2[-1] * 2 % mod) res = 0 for v in a: for i in range(60): if (v >> i) & 1: res = (res + (n - cnt[i]) * pow_2[i] % mod) % mod else: res = (res + cnt[i] * pow_2[i] % mod) % mod print(res * mod_pow(2, mod - 2) % mod)
import sys for line in sys.stdin: list = line.split() print len(str(eval(list[0])+eval(list[1])))
0
null
61,461,570,196,298
263
3
x=int(input()) for i in range(int(x**.5),0,-1): if x%i==0: break print(i+x//i-2)
N = list(map(int,input().split())) print(N[0]*N[1])
0
null
88,404,203,108,000
288
133
import sys, math input = sys.stdin.readline MAX = 2e9 def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L = A[left:mid] L.append(MAX) R = A[mid:right] R.append(MAX) merged = [] index_L = 0 index_R = 0 comp_cnt = 0 for _ in range(n1+n2): cand_L = L[index_L] cand_R = R[index_R] comp_cnt += 1 if (cand_L < cand_R): merged.append(cand_L) index_L += 1 else: merged.append(cand_R) index_R += 1 A[left:right] = merged return comp_cnt def merge_sort(A, left, right): comp_cnt = 0 if (left + 1 < right): # Devide mid = (left + right) // 2 # Solve _, cnt = merge_sort(A, left, mid) comp_cnt += cnt _, cnt = merge_sort(A, mid, right) comp_cnt += cnt # Conquer comp_cnt += merge(A, left, mid, right) return A, comp_cnt def main(): N = int(input()) S = list(map(int, input().split())) left = 0 right = len(S) merged, cnt = merge_sort(S, left, right) print(" ".join([str(x) for x in merged])) print(cnt) if __name__ == "__main__": main()
R=int(input()) print(2*R*3.1419)
0
null
15,722,688,547,380
26
167
#!/usr/bin/env python def solve(A: int, B: int, C: int, K: int): if A >= K: return K K -= A if B >= K: return A K -= B return A - K def main(): A, B, C, K = map(int, input().split()) answer = solve(A, B, C, K) print(answer) if __name__ == "__main__": main()
a,b,c,k = list(map(int,input().split())) ans = 0 if a >= k: print(k) elif a+b >= k: print(a) else: ans += a k -= (a+b) ans -= k print(ans)
1
21,863,401,071,694
null
148
148
A = int(input()) B = int(input()) ans = {1, 2, 3} ans -= {A, B} print(ans.pop())
ans = [1,2,3] for i in [0,1]: y = int(input()) ans.remove(y) print(ans[0])
1
110,355,946,051,052
null
254
254
n = list(input()) n1 = [int(i) for i in n] sum = 0 for i in n1: sum += i if sum % 9 == 0: print('Yes') else: print('No')
n = int(input()) p = [int(input()) for i in range(n)] max_diff = -float('inf') min_n = p[0] for i in range(1, n): max_diff = max(max_diff, p[i] - min_n) min_n = min(min_n, p[i]) print(max_diff)
0
null
2,207,277,864,078
87
13
A = int(input()) B = int(input()) print(6//(A*B))
A=["1","2","3"] A.pop(A.index(input())) A.pop(A.index(input())) print(A[0])
1
110,577,852,808,064
null
254
254
import sys N = str(input()) for i in N: if i == '7': print('Yes') sys.exit() print('No')
# %% x = input() if x[0]=="7" or x[1]=="7" or x[2]=="7": ans = "Yes" else: ans = "No" print(ans) # %%
1
34,481,028,730,148
null
172
172
X = int(input()) if X >= 400 and X <= 599: print(8) elif X >= 600 and X <= 799: print(7) elif X >= 800 and X <= 999: print(6) elif X >= 1000 and X <= 1199: print(5) elif X >= 1200 and X <= 1399: print(4) elif X >= 1400 and X <= 1599: print(3) elif X >= 1600 and X <= 1799: print(2) elif X >= 1800 and X <= 1999: print(1)
def main(): n = int(input()) # d,t,s = map(int, input().split()) a = list(map(int, input().split())) # s = input() mod = 10**9+7 s = sum(a) sm = 0 for i in a: s -= i sm += i * s % mod print(sm % mod) if __name__ == '__main__': main()
0
null
5,259,780,528,420
100
83
#!/usr/bin/env python # -*- coding:utf-8 -*- #from __future__ import print_function import time import sys import io import re import math start = time.clock() i = 0 m=int(raw_input()) n=map(int, raw_input().split()) o=int(raw_input()) p=map(int, raw_input().split()) for j in xrange(o): if int(p[j]) in n: i+=1 print i
s = input() small = 'abcdefghijklmnopqrstuvwxyz' large = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ans = '' for i in s: q = 0 while q < 26: if i == small[q]: ans += large[q] break elif i == large[q]: ans += small[q] break q += 1 if q == 26: ans += i print(ans)
0
null
771,545,405,510
22
61
import itertools n = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) Psort = sorted(P) Pp = list(itertools.permutations(Psort)) a = Pp.index(P) b = Pp.index(Q) print(abs(a-b))
import numpy as np n=int(input()) a=np.array([0]*4) for i in range(n): s= str(input()) if s=='AC': a[0]+=1 elif s=='WA': a[1]+=1 elif s=='TLE': a[2]+=1 elif s=='RE': a[3]+=1 print('AC x '+str(a[0])) print('WA x '+str(a[1])) print('TLE x '+str(a[2])) print('RE x '+str(a[3]))
0
null
54,913,729,708,432
246
109
from collections import deque import itertools h, w = map(int, input().split()) g = [input() for _ in range(h)] # x,yはスタートの座標 def bfs(x, y): # 最初は全て未訪問なので-1で初期化 d = [[-1] * w for _ in range(h)] # スタート地点への距離は0 d[x][y] = 0 q = deque([(x, y)]) while q: tx, ty = q.popleft() # 右、上、左、下 for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]: nx, ny = tx + dx, ty + dy # グリッドの範囲(縦方向, 横方向)内、通路(壁ではない)、未訪問(== -1)の場合 if 0 <= nx < h and 0 <= ny < w and g[nx][ny] == '.' and d[nx][ny] < 0: d[nx][ny] = d[tx][ty] + 1 q.append((nx, ny)) # 最終的なdを平坦化して最大値を返す return max(list(itertools.chain.from_iterable(d))) # 全てのマスについて max_count = 0 for x in range(h): for y in range(w): # スタートが通路であるかチェックする必要がある if g[x][y] == ".": max_count = max(max_count, bfs(x, y)) print(max_count)
from collections import deque import copy H,W=map(int,input().split()) MAP=[list(input()) for y in range(H)] def Maze(_x, _y): MAP2=copy.deepcopy(MAP) q=deque([[_x,_y]]) MAP2[_y][_x]=0 while q: xy=q.popleft() for d in [(0,-1),(-1,0),(0,1),(1,0)]: x2,y2=xy[0]+d[0],xy[1]+d[1] if x2<0 or y2<0 or x2>=W or y2>=H: continue if MAP2[y2][x2]=='.': q.append([x2,y2]) MAP2[y2][x2]=MAP2[xy[1]][xy[0]]+1 maxM=0 for y in range(H): for x in range(W): if type(MAP2[y][x])==int: maxM=max(maxM, MAP2[y][x]) return maxM ans=0 for y in range(H): for x in range(W): if MAP[y][x]=='.': ans=max(ans, Maze(x,y)) print(ans)
1
94,683,375,667,332
null
241
241
X,N=map(int,input().split()) P=set(map(int,input().split())) l=[0]+[(1+i//2)*(-1 if i%2==0 else 1) for i in range(101)] for i in l: if X+i not in P: print(X+i) break
def gcd(_a, _b): if _a%_b==0:return _b else:return gcd(_b, _a%_b) A, B=map(int, input().split()) print(A*B//gcd(A, B))
0
null
63,841,087,096,788
128
256
while True: h,w=map(int,input().split()) if(h==0): break for i in range(h): for j in range(w): print("#",end="") print() print()
while True: H, W = map(int, raw_input().split()) if H == 0 and W == 0: break for i in range(H): width = "" for j in range(W): width += "#" print width print ""
1
772,778,184,640
null
49
49
def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] n = int(input()) l = make_divisors(n - 1) l2 = make_divisors(n) del l2[0] ans = len(l) - 1 for i in l2: k2 = n while True: if k2 % i == 1: ans += 1 k2 /= i if k2 % 1 != 0: break print(ans)
from sys import exit import math import collections ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) a,b = mi() print((a*b)//math.gcd(a,b))
0
null
77,614,043,183,248
183
256
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)
""" s=1817181712114 なら 4 10 100 2000 10000 700000 1000000 80000000 100000000 7000000000 10000000000 800000000000 1000000000000 の数列とみて, 各々%Pを取ってzero sum range P=2,5がコーナー """ from collections import Counter def make_modlist(Len,mod): modlist=[0]*Len modlist[0]=1 for i in range(1,Len): modlist[i]=10*modlist[i-1]%mod return modlist n,p=map(int,input().split()) a=list(map(int,input())) ans=0 a.reverse() if p==2 or p==5: for i in range(n): if a[i]%p==0: ans+=n-i else: d=make_modlist(n,p) b=[0]*(n+1) for i in range(n): b[i+1]=a[i]*d[i]%p for i in range(1,n+1): b[i]+=b[i-1] b[i]%=p for i in Counter(b).values(): ans+=i*(i-1)//2 print(ans)
0
null
99,535,178,260,980
275
205
s = input() suffix = '' if s.endswith('s'): suffix = 'es' else: suffix = 's' print(s + suffix)
n=int(input()) count=0 for i in range(0,n): if(i%2==0): count+=1 else: count+=0 print(count/n)
0
null
90,206,273,998,400
71
297
# from fractions import gcd # P = 10**9+7 # N = int(input()) # S = list(map(int, input().split())) # l = {2:0} # for num in S: # temp = num # M = temp//2+2 # cnt = 0 # while temp%2 == 0: # cnt += 1 # temp //= 2 # l[2] = max(l[2], cnt) # i = 3 # while temp > 1 and i < M: # cnt = 0 # while temp%i == 0: # cnt += 1 # temp //= i # if cnt > 0: # if i in l: # l[i] = max(l[i], cnt) # else: # l[i] = cnt # i += 2 # if temp > 1: # if temp in l: # l[temp] = max(l[temp], 1) # else: # l[temp] = 1 # ans = 0 # for i in range(N): # ans = (temp//S[i]+ans)%P # print(ans) from fractions import gcd P = 10**9+7 N = int(input()) S = list(map(int, input().split())) temp = S[0] for i in range(1, N): temp = temp*S[i] // gcd(temp, S[i]) temp %= P ans = 0 for num in S: ans = ((temp*pow(num, P-2, P))%P+ans)%P print(ans)
import math case_num = 0 N = int(input()) for num in range(N - 1): num += 1 case_num += ( math.ceil(N / num) - 1 ) print(case_num)
0
null
45,289,483,009,810
235
73
def divisors(n): i = 1 table = set() while i * i <= n: if not n % i: table.add(i) table.add(n//i) i += 1 table = list(table) return table N = int(input()) k = 2 res = 0 while k*k<=N: n = N while not n%k: n//=k if (n%k==1 or n==1) and n!=N: res += 1 k += 1 a = divisors(N-1) print(len(a)+res)
#!/usr/bin/env python import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10**6) INF = float("inf") def main(): N = int(input()) S = input().decode().rstrip() if N%2==0 and S[0:N//2]==S[N//2:]: print("Yes") else: print("No") if __name__ == "__main__": main()
0
null
93,694,796,111,110
183
279
print("Yes" if input().count("7") > 0 else "No")
print(["No","Yes"]["7" in input()])
1
34,271,236,560,260
null
172
172
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1 for i in range(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, M=[int(i) for i in input().split(" ")] uf = UnionFind(N) for i in range(M): A,B=[int(i) for i in input().split(" ")] uf.union(A-1,B-1) d={} for i in range(N): root = uf.find(i) d[root]=d.get(root,0)+1 print(max(d.values()))
S = input() Q = int(input()) now = 1 head = '' last = '' for _ in range(Q): query = input().split() if query[0] == '1': now = now * -1 if query[0] == '2': if now * (int(query[1])-1.5) == 0.5: last += query[2] else: head += query[2] ans = head[::-1] + S + last if now == 1: print(ans) else: print(ans[::-1])
0
null
30,516,221,399,312
84
204
x=int(input()) c=100 i=0 while True: i+=1 c=c+c//100 if x<=c: print(i) exit()
def judge(lists): lists.sort() if lists[0] ** 2 + lists[1] ** 2 - lists[2] ** 2: return False else: return True def run(): N = int(input()) for _ in range(N): if judge([int(x) for x in input().split()]): print("YES") else: print("NO") if __name__ == '__main__': run()
0
null
13,571,693,286,688
159
4
k=int(input()) s=input() if len(s)<=k: print(s) else: for i in range(k): print(s[i],end="") print("...",end="")
# Begin Header {{{ from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations, combinations_with_replacement # }}} End Header # _________コーディングはここから!!___________ mod = 10**9+7 n = int(input()) ans=0 ans+=pow(10, n, mod) ans-=pow(9, n, mod)*2 ans+=pow(8, n, mod) print(ans%mod)
0
null
11,472,741,233,842
143
78
H = int(input()) W = int(input()) N = int(input()) x = H if H>W else W x2 = 0 if N%x==0 else 1 print(N//x + x2)
n = list(map(int, input().split())) a = n[0] b = n[1] d = a // b r = a % b f = a / b print('{} {} {:.5f}'.format(d, r, f))
0
null
44,907,363,858,940
236
45
N, K = map(int, input().split()) P = list(map(lambda x:int(x) - 1,input().split())) C = list(map(int, input().split())) ans = -10**9 for i in range(N): tmp_max = [-10**9]*(N+1) total = 0 current_block = P[i] for j in range(1, N + 1): total += C[current_block] tmp_max[j] = max(tmp_max[j-1], total) if current_block == i: break current_block = P[current_block] if total <= 0: ans = max(ans, tmp_max[j]) else: n = K // j r = K % j if r == 0: ans = max(ans, total*(n-1) + tmp_max[j]) else: ans = max(ans, total*n + tmp_max[r]) print(ans)
def main(): INF = 10**9 n,k = map(int,input().split()) P = [0] + list(map(int,input().split())) C = [0] + list(map(int,input().split())) scores = [0]*n for s in range(1,n+1): start = s dp = [-INF]*(n+1) dp[0] = 0 for i in range(n): p = P[s] dp[i+1] = dp[i] + C[p] if start == p: break s = p if k <= i+1: scores[start-1] = max(dp[1:k+1]) elif dp[i+1]<=0: scores[start-1] = max(dp[1:]) else: r = k%(i+1) q = k//(i+1) if r>0: scores[start-1] = max(max(dp[1:r+1])+dp[i+1]*q, max(dp[1:])) else: scores[start-1] = dp[i+1]*(q-1)+max(dp[1:]) print(max(scores)) main()
1
5,449,881,778,810
null
93
93
from collections import defaultdict N, X, Y = map(int, input().split()) INF = 10**20 ans = {i:0 for i in range(N)} d = defaultdict(list) for i in range(1, N): d[i].append(i+1) d[i+1].append(i) d[X].append(Y) d[Y].append(X) for i in range(1, N+1): dist = [-1]*(N+1) q = [i] dist[i] = 0 while q: a = q.pop() for b in d[a]: if dist[b]==-1 or dist[b] > dist[a]+1: dist[b] = dist[a] + 1 q.append(b) for j in range(i+1, N+1): ans[dist[j]] += 1 for i in range(1,N): print(ans[i])
S =input() if len(S) % 2 != 0: print('No') exit() for i in range(0,len(S),2): if S[i:i+2] != 'hi': print('No') exit() print('Yes')
0
null
48,569,988,951,202
187
199
N=int(input()) for i in range(N): a, b, c = map(int, input().split()) if(a*a==b*b+c*c or b*b==a*a+c*c or c*c==b*b+a*a): print('YES') else: print('NO')
class Dice: def __init__(self): d = map(int, raw_input().split(" ")) self.c = raw_input() self.rows = [d[0], d[4], d[5], d[1]] self.cols = [d[0], d[2], d[5], d[3]] def __move_next(self, x, y): temp = y.pop(0) y.append(temp) x[0] = y[0] x[2] = y[2] def __move_prev(self, x, y): temp = y.pop(3) y.insert(0, temp) x[0] = y[0] x[2] = y[2] def execute(self): for i in self.c: self.__move(i, self.rows, self.cols) def __move(self, com, x, y): if com == "N": self.__move_prev(y, x) elif com == "S": self.__move_next(y, x) elif com == "E": self.__move_prev(x, y) elif com == "W": self.__move_next(x, y) def print_top(self): print self.rows[0] dice = Dice() dice.execute() dice.print_top()
0
null
120,213,669,028
4
33
#import time count=0 def merge(A,left,mid,right): global count L=A[left:mid]+[2**30] R=A[mid:right]+[2**30] i=0 j=0 for k in range(left,right): count+=1 if L[i]<=R[j]: A[k]=L[i] i+=1 else: A[k]=R[j] j+=1 def mergeSort(A,left,right): if left+1 < right: mid = int((left+right)/2) mergeSort(A,left,mid) mergeSort(A,mid,right) merge(A,left,mid,right) #start = time.time() n=int(input()) s=list(map(int,input().split())) count=0 mergeSort(s,0,n) print(s[0],end='',sep='') for i in range(1,n): print(" ",s[i],end='',sep='') print() print(count) #end=time.time()-start #end*=1000 #print ("Time:{0}".format(end) + "[m_sec]")
import math import sys # 比較回数をここに記録 # 理論上 n * lg n を越えることはない。 _exchange = 0 def merge_sort(A, left, right): """数列 A を in place に昇順にソートする。 left は A の先頭のインデックス、right は末尾のインデックスのひとつ後ろ。 """ if left + 1 < right: mid = (left + right) // 2 merge_sort(A, left, mid) merge_sort(A, mid, right) merge(A, left, mid, right) def merge(A, left, mid, right): """ソート済みの部分列をマージする。 数列 A の left から mid - 1 の要素、mid から right - 1 までの 2つの部分列はソート済みである。これをマージして、left から right - 1 まで ソートする。 """ first = A[left:mid] first.append(math.inf) # 番兵 second = A[mid:right] second.append(math.inf) # 番兵 global _exchange i = j = 0 for k in range(left, right): _exchange += 1 if first[i] <= second[j]: A[k] = first[i] i += 1 else: A[k] = second[j] j += 1 if __name__ == '__main__': n = int(input()) A = list(map(int, sys.stdin.readline().split())) merge_sort(A, 0, n) print(*A) print(_exchange)
1
113,727,940,610
null
26
26
n = int(input()) list_ = [] for _ in range(n): x, l = map(int, input().split()) list_.append([x-l, x+l]) list_.sort(key=lambda x: x[1]) res = n pos = -float('inf') for l, r in list_: if l < pos: res -= 1 else: pos = r print(res)
def main(): N = int(input()) # K > 1 def divisor_set(x): ret = set() if x > 1: ret.add(x) d = 2 while d * d <= x: if x % d == 0: ret.add(d) ret.add(x // d) d += 1 return ret # N % K == 1 # (N-1) % K == 0 # K > 1 ans = 0 ans += len(divisor_set(N - 1)) # N % K == 0 # N //= K ---> M # (M-1) % K == 0 for k in divisor_set(N): x = N while x % k == 0: x //= k if x % k == 1: ans += 1 print(ans) if __name__ == '__main__': main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
0
null
65,216,996,331,098
237
183
from collections import deque N,U,V = map(int, input().split()) U,V = U-1, V-1 E = [[] for _ in range(N)] for _ in range(N-1): a,b = map(int, input().split()) a,b = a-1, b-1 E[a].append(b) E[b].append(a) def BFS(root): D = [ 0 for _ in range(N) ] visited = [False for _ in range(N)] willSearch = [ False for _ in range(N)] Q = deque() Q.append(root) willSearch[root] = True while len(Q) > 0: now = Q.pop() visited[now] = True for nx in E[now]: if visited[nx] or willSearch[nx]: continue willSearch[nx] = True D[nx] = D[now] + 1 Q.append(nx) return D UD = BFS(U) VD = BFS(V) #print(UD) #print(VD) #初手で青木くんのPOINTにしか行けないケース if E[U] == [V]: print(0) exit(0) ans=0 for i in range(N): if UD[i]<=VD[i]: ans=max(ans,VD[i]-1) print(ans)
ma = lambda :map(int,input().split()) n,u,v = ma() u,v = u-1,v-1 tree = [[] for i in range(n)] import collections for i in range(n-1): a,b = ma() tree[a-1].append(b-1) tree[b-1].append(a-1) que = collections.deque([(v,0)]) vis = [False]*n dist_v = [0]*n while que: now,c = que.popleft() vis[now] = True dist_v[now] = c for node in tree[now]: if not vis[node]: que.append((node,c+1)) que = collections.deque([(u,0)]) vis = [False]*n dist_u = [0]*n while que: now,c = que.popleft() vis[now] = True dist_u[now] = c for node in tree[now]: if not vis[node]: que.append((node,c+1)) ans = 0 for i in range(n): if dist_u[i] < dist_v[i]: ans = max(ans,dist_v[i]) print(ans-1)
1
117,406,313,085,748
null
259
259
import sys import math N = int(input()) def solve(num): d = math.floor(num**(1/2)) for i in range(1,d+1): if num % i == 0: yield [i,num//i] if N == 2: print(1) sys.exit() cnt = 0 for a,b in solve(N-1): if a == b: cnt += 1 else: cnt += 2 cnt -= 1 for s in solve(N): if s[0] == s[1]: s.pop() for a in s: if a == 1: continue tmp = N while True: tmp,m = divmod(tmp, a) if m == 0: continue elif m == 1: cnt += 1 break print(cnt)
N=int(input()) n=N ans=0 def make_divisors(n): divisors = [] for i in range(1,int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n//i: divisors.append(n//i) return divisors l=make_divisors(N-1) r=make_divisors(N) ans=len(l)-1 for i in range(len(r)): N=n K=r[i] if K==1: continue while(N%K==0): N=N//K if N%K==1: #print(K) ans+=1 print(ans)
1
41,442,082,205,262
null
183
183
import sys sys.setrecursionlimit(10**6) read = sys.stdin.read #readlines = sys.stdin.readlines from collections import defaultdict def main(): def from10to2(p): res = [] while p: p, t = divmod(p, 2) res.append(str(t)) return "".join(res[::-1]) def from2to10(p): res = 0 num2 = 1 for c in p[::-1]: if c == '1': res += num2 num2 *= 2 return res def f(p): if p == 0: return 0 elif d1[p] > 0: return d1[p] else: ppop = from10to2(p).count('1') p2 = p % ppop fp = f(p2) + 1 d1[p] = fp return fp n = int(input()) x = list(input()) numof1 = x.count('1') bin2_p = [0] * n num2 = 1 for i1 in range(1, n+1): bin2_p[-i1] = num2 num2 = (num2 * 2) % (numof1 + 1) bin2_m = [0] * n num2 = 1 if numof1 == 1: pass else: for i1 in range(1, n+1): bin2_m[-i1] = num2 num2 = (num2 * 2) % (numof1 - 1) xas10 = from2to10(x) xas10_p = xas10 % (numof1 + 1) if numof1 == 1: xas10_m = 0 else: xas10_m = xas10 % (numof1 - 1) d1 = defaultdict(int) d1[0] = 0 for j1 in range(n): if x[j1] == '1': if numof1 == 1: print(0) else: t0 = xas10_m - bin2_m[j1] t0 = t0 % (numof1 - 1) if t0 == 0: print(1) else: print(f(t0) + 1) else: t0 = xas10_p + bin2_p[j1] t0 = t0 % (numof1 + 1) if t0 == 0: print(1) else: print(f(t0) + 1) if __name__ == '__main__': main()
while True: xy_list = list(map(int, input().split())) if xy_list[0] == xy_list[1] == 0: break print(*sorted(xy_list))
0
null
4,332,025,341,280
107
43
n, m, q = map(int,input().split()) a, b, c, d = [0] * q, [0] * q, [0] * q, [0] * q for i in range(q): a[i], b[i], c[i], d[i] = map(int,input().split()) def score(l): res = 0 for i in range(q): temp = l[b[i] - 1] - l[a[i] - 1] if temp == c[i]:res += d[i] return res def dfs(l): global ans if len(l) == n: ans = max(ans, score(l)) return #中で使われている関数の終了 if l: temp = l[-1] else: temp = 1 for v in range(temp, m + 1): l.append(v) dfs(l) l.pop() ans = 0 dfs([]) print(ans)
import itertools N, M, Q = map(int,input().split()) ans = 0 A = [] B = [] C = [] D = [] for _ in range(Q): a, b, c, d = map(int,input().split()) A.append(a-1) B.append(b-1) C.append(c) D.append(d) ans = 0 for seq in itertools.combinations_with_replacement(range(M),N): tmp = 0 for i in range(Q): if seq[B[i]] - seq[A[i]] == C[i]: tmp += D[i] ans = max(ans,tmp) print(ans)
1
27,817,693,634,746
null
160
160
N=int(input()) for i in range(N): lst=sorted([int(s) for s in input().split()],reverse=True) if lst[0]**2 == lst[1]**2+lst[2]**2: print("YES") else: print("NO")
N=int(input()) S={input() for _ in range(N)} print(len(S))
0
null
15,049,238,011,808
4
165
N = int(input()) N_List = {i:0 for i in range(1,N+1)} E_List = list(map(int,input().split())) for i in E_List: N_List[i] += 1 for i in N_List.values(): print(i)
n=int(input()) a=list(map(int,input().split())) ans=[0 for s in range(n)] for i in range(n-1): x = int(a[i]) ans[x-1] +=1 for j in range(n): print(ans[j])
1
32,783,806,746,270
null
169
169
n = int(input()) ans = [] def dfs(A): if len(A) == n: ans.append(''.join(A)) return for i in range(len(set(A))+1): v = chr(i+ord('a')) A.append(v) dfs(A) A.pop() dfs([]) ans.sort() for i in range(len(ans)): print(ans[i])
FAST_IO = 0 if FAST_IO: import io, sys, atexit rr = iter(sys.stdin.read().splitlines()).next sys.stdout = _OUTPUT_BUFFER = io.BytesIO() @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) else: rr = raw_input rri = lambda: int(rr()) rrm = lambda: map(int, rr().split()) rrmm = lambda n: [rrm() for _ in xrange(n)] #### MOD = 10**9 + 7 YES, NO, IMP = "YES", "NO", "IMPOSSIBLE" from collections import defaultdict as ddic N=rri() A = rrmm(N) X = [] Y = [] for x, y in A: X.append(x-y) Y.append(x+y) #print X #print Y xlo, xhi = min(X), max(X) ylo, yhi = min(Y), max(Y) print(max(yhi-ylo, xhi-xlo))
0
null
27,969,231,833,748
198
80
from collections import deque N, X, Y = map(int, input().split()) ans = [0 for i in range(N)] dqs = [-1, 1] for i in range(N-1): vis = [-1 for _ in range(N)] Q = deque([i]) vis[i] = 0 while Q: q = Q.popleft() for dq in dqs: if 0 <= q + dq < N: if vis[q + dq] == -1: vis[q + dq] = vis[q] + 1 Q.append(q + dq) if q + dq > i: ans[vis[q + dq]] += 1 if q==X-1: if vis[Y-1] == -1: vis[Y-1] = vis[q] + 1 Q.append(Y-1) if Y-1 > i: ans[vis[Y-1]] += 1 if q==Y-1: if vis[X-1] == -1: vis[X-1] = vis[q] + 1 Q.append(X-1) if X-1 > i: ans[vis[X-1]] += 1 for a in ans[1:]: print(a)
from math import atan, pi a, b, x = map(int, input().split()) if a * a * b > 2 * x: ans = atan(a * b * b / 2 / x) else: ans = atan((2 * a * a * b - 2 * x) / a / a / a) ans *= 180 / pi print(ans)
0
null
104,016,830,214,010
187
289
h = int(input()) def rc(h): if h == 1: return 1 t = rc(h//2)*2 return t + 1 print(rc(h))
def is_prime(x): if x == 2: return True if (x < 2) or (x%2 == 0): return False return all(x%i for i in xrange(3, int(x**(0.5) + 1), 2)) N = input() print sum(is_prime(input()) for i in range(N))
0
null
40,129,893,987,850
228
12
N = input() print(N[:3])
a,b,*cc = map(int, open(0).read().split()) if sum(cc) >= a: print('Yes') else: print('No')
0
null
46,193,427,705,332
130
226
S = input() count = 0 if S[0] == 'R' or S[1] == 'R' or S[2] == 'R': count = 1 if (S[0] == 'R' and S[1] == 'R') or (S[1] == 'R' and S[2] == 'R'): count = 2 if S[0] == 'R' and S[1] == 'R' and S[2] == 'R': count = 3 print(count)
MOD = 10**9+7 n = int(input()) A = list(map(int, input().split())) colors = [0]*3 dp = [0]*n for i in range(n): c = colors.count(A[i]) dp[i] = c if c == 0: break colors[colors.index(A[i])] += 1 ans = 1 for x in dp: ans = ans*x % MOD print(ans % MOD)
0
null
67,689,797,916,532
90
268
# -*- coding:utf-8 -*- def solve(): import math N, K = list(map(int, input().split())) As = list(map(int, input().split())) left, right = 1, 10**9 while left != right: mid = (left+right)//2 cut = 0 for a in As: if a/mid > 1: cut += math.ceil(a/mid) - 1 if cut <= K: # 切って良い回数を満たしている if left+1 == right: print(left) return right = mid else: # 切って良い回数を満たしていない if left+1 == right: print(right) return left = mid if __name__ == "__main__": solve()
# coding: utf-8 # Your code here! N,K=map(int,input().split()) A=list(map(float, input().split())) low=0 high=10**9+1 while high-low!=1: mid=(high+low)//2 cut_temp=0 ans=-1 for a in A: cut_temp+=-(-a//mid)-1 if cut_temp>K: low=mid else: high=mid print(high)
1
6,547,571,218,158
null
99
99
a,b,c,k = map(int,input().split()) if k < a: ans = k elif k < a + b: ans = a else: ans = a - (k - a - b) print(ans)
def resolve(): s, w = map(int, input().split()) if s <= w: print("unsafe") else: print("safe") resolve()
0
null
25,533,919,709,860
148
163
n, m = map(int, input().split()) ac = [0]*n wa = [0]*n for _ in range(m): p, s = input().split() p = int(p)-1 if s == 'AC': ac[p] = 1 elif s == 'WA' and ac[p] == 0: wa[p] += 1 ans, pen = 0, 0 for i in range(n): if ac[i]: ans += 1 pen += wa[i] print(ans, pen)
n, m, x = map(int, input().split()) ca = [list(map(int, input().split())) for _ in range(n)] ans = 12*(10**5)+1 for i in range(2**n): a = [0] * m cs = 0 for j in range(n): if (i >> j) & 1: cs += ca[j][0] for k in range(1, m+1): a[k-1] += ca[j][k] flag = True for j in range(m): if a[j] < x: flag = False break if flag: ans = min(ans, cs) if ans == 12*(10**5)+1: ans = -1 print(ans)
0
null
57,871,385,720,878
240
149
N = int(input()) #https://img.atcoder.jp/abc178/editorial-E-phcdiydzyqa.pdf z_list = list() w_list = list() for i in range(N): x,y = map(int, input().split()) z_list.append(x + y) w_list.append(x - y) print(max(max(z_list)-min(z_list),max(w_list)-min(w_list)))
N,T = map(int, input().split()) abl = [] for _ in range(N): a,b = map(int, input().split()) abl.append((a,b)) abl.sort() dp = [ [0]*6001 for _ in range(N+1) ] for i in range(N): a,b = abl[i] for t in range(6001): dp[i+1][t] = max(dp[i+1][t], dp[i][t]) if t < T: dp[i+1][t+a] = max(dp[i][t]+b, dp[i][t+a]) ans = max(dp[N]) print(ans)
0
null
77,374,569,391,600
80
282
n,k = input().split(" ") cost = input().split(" ") a = [] for i in cost: a.append(int(i)) a.sort() sum = 0 for i in range(int(k)): sum += int(a[i]) print(sum)
from math import floor,ceil,sqrt,factorial,log from collections import Counter, deque from functools import reduce import numpy as np import itertools def S(): return input() def I(): return int(input()) def MS(): return map(str,input().split()) def MI(): return map(int,input().split()) def FLI(): return [int(i) for i in input().split()] def LS(): return list(MS()) def LI(): return list(MI()) def LLS(): return [list(map(str, l.split() )) for l in input()] def LLI(): return [list(map(int, l.split() )) for l in input()] def LLSN(n: int): return [LS() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] N,K = MI() P = LI() P = sorted(P) ans = sum(P[:K]) print(ans)
1
11,644,602,028,640
null
120
120
x = list(map(int, input().split())) ans = 0 for i in x: if i == 1: ans += 300000 elif i == 2: ans += 200000 elif i == 3: ans += 100000 if sum(x) == 2: ans += 400000 print(ans)
x, y = map(int, input().split()) ans = 0 def calc(z): ans = 0 if z == 1: ans += 300000 elif z == 2: ans += 200000 elif z == 3: ans += 100000 return ans if x == 1 and y == 1: ans += 400000 print(ans+calc(x)+calc(y))
1
140,997,482,911,208
null
275
275
d,t,s = list(map(int, input().split())) if d/s<=t: print("Yes") else: print("No")
from sys import stdin import sys import math from functools import reduce import itertools n = int(stdin.readline().rstrip()) p = [int(x) for x in stdin.readline().rstrip().split()] m = n count = 0 for i in range(n): m = min([m, p[i]]) if m == p[i]: count = count + 1 print(count)
0
null
44,243,141,022,288
81
233
w1, w2 = input().split() a,b = map(int,input().split()) c = input() l = [[w1,a],[w2,b]] ans = "" for i in range(2): x,y = l[i][0],l[i][1] if x==c: ans += str(y-1) else: ans += str(y) if i==0: ans += ' ' print(ans)
n = int(input()) ret = 0 b = 1 while n > 0: ret += b n //= 2 b *= 2 print(ret)
0
null
75,604,312,309,900
220
228
#!/usr/bin/env python3 import sys sys.setrecursionlimit(300000) from pprint import pprint def solve(N: int, A: "List[int]"): memo = [{} for _ in range(N + 1)] def rec(idx, rest, can_use=True): k = (rest, can_use) if rest * 2 >= N - idx + 2: return 0 if rest == 0: return 0 if k in memo[idx]: return memo[idx][k] ret = 0 if not can_use: ret = rec(idx + 1, rest) elif rest * 2 > (N - idx): ret = A[idx] + rec(idx + 1, rest - 1, False) else: a = A[idx] + rec(idx + 1, rest - 1, False) b = rec(idx + 1, rest) ret = max(a, b) memo[idx][k] = ret return ret ret = rec(0, N // 2) print(ret) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [int(next(tokens)) for _ in range(N)] # type: "List[int]" solve(N, A) if __name__ == '__main__': main()
n=list(map(int,input())) keta=len(n) satsu=0 for i in range(keta): tmp = n.pop() if i == keta-1: n.append(0) if tmp == 10: tmp=0 n[-1]=n[-1]+1 if tmp > 5 or (tmp==5 and n[-1] >= 5): satsu += 10 - tmp n[-1] = n[-1] + 1 else: satsu += tmp print(satsu+n[0])
0
null
54,555,374,469,470
177
219
import math A, B = [int(s) for s in input().split(' ')] def lcm(x, y): return (x * y) // math.gcd(x, y) print(lcm(A, B))
#!/usr/bin/env python from fractions import gcd def main(): A, B = map(int, input().split()) print(A * B // gcd(A, B)) if __name__ == '__main__': main()
1
113,051,760,775,808
null
256
256
W,H,x,y,r=map(int,input().split()) if 0<=x-r<x<x+r<=W and 0<=y-r<y<y+r<=H: print("Yes") else: print("No")
temp = int(input()) print("Yes" if temp>= 30 else "No")
0
null
3,116,232,318,012
41
95
H,W,M = map(int,input().split()) hlist = [0]*H wlist = [0]*W sets = set() for i in range (M): h,w = map(lambda x: int(x)-1,input().split()) hlist[h]+=1 wlist[w]+=1 sets.add((h,w)) hmax = 0 hind = [] for i in range(H): if hmax < hlist[i]: hmax = hlist[i] hind = [i] elif hmax == hlist[i]: hind.append(i) wmax = 0 wind = [] for i in range(W): if wmax < wlist[i]: wmax = wlist[i] wind = [i] elif wmax == wlist[i]: wind.append(i) flag = False for h in hind: for w in wind: if (h,w) not in sets: flag = True break if flag: break if flag: print(hmax + wmax) else: print(hmax + wmax - 1)
def cube(x): return x**3 def main(): x = int(input()) ans = cube(x) print(ans) if __name__=='__main__': main()
0
null
2,462,762,489,340
89
35
A,B,C,K=map(int,input().split()) ans=0 if A>K: ans+=K else: ans+=A if B>K-A: ans+=0 else: if (K-A-B)<C: ans+=-(K-A-B) else: ans+=-C print(ans)
import sys input = sys.stdin.readline h,n = map(int,input().split()) ab = [list(map(int,input().split()))for i in range(n)] amx = 0 for i in range(n): if amx < ab[i][0]: amx = ab[i][0] #dp[i] = モンスターの削る体力がiの時の魔力の消費の最小値 dp = [float('inf')]*(amx + h + 1) dp[0] = 0 for i in range(amx + h + 1): for m in ab: if i-m[0] >= 0: dp[i] = min(dp[i], dp[i-m[0]] + m[1]) ans = float('inf') for i in range(h,amx + h + 1): ans = min(ans, dp[i]) print(ans)
0
null
51,443,556,618,432
148
229
n=input() fn_first=1 fn_second=1 if n >= 2: for x in xrange(n-1): tmp = fn_first fn_first = fn_first + fn_second fn_second = tmp print fn_first
n = int(input()) a = sorted(map(int,input().split()))[::-1] ans = 2 * sum(a[:(n-1)//2+1]) - a[0] if n % 2 == 1: ans -= a[(n-1)//2] print(ans)
0
null
4,566,082,284,830
7
111
while True: L = raw_input().split() a = int(L[0]) o = (L[1]) b = int(L[2]) if o == "?": break elif o == "+": print a + b elif o == "-": print a - b elif o == "*": print a * b elif o == "/": print a/b
while True: t = input() if t.find("?") > 0: break print(int(eval(t)))
1
693,126,128,512
null
47
47
n = int(input()) first_list = ['AC', 'WA', 'TLE', 'RE'] list = [] for _ in range(n): list.append(input()) for i in first_list: print(i, 'x', list.count(i))
import sys input = sys.stdin.readline n, m, l = map(int, input().split()) INF = float("INF") d = [[INF] * n for _ in range(n)] for i in range(n): d[i][i] = 0 for i in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 d[a][b] = c d[b][a] = c for k in range(n): for i in range(n): for j in range(n): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] # print() # print(*d, sep='\n') for i in range(n): for j in range(n): if i == j: continue if d[i][j] <= l: d[i][j] = 1 else: d[i][j] = INF for k in range(n): for i in range(n): for j in range(n): if d[i][j] > d[i][k] + d[k][j]: d[i][j] = d[i][k] + d[k][j] # print() # print(*d, sep='\n') q = int(input()) for i in range(q): s, t = map(int, input().split()) s -= 1 t -= 1 if d[s][t] == INF: print(-1) else: print(d[s][t]-1)
0
null
91,041,670,108,580
109
295