code1
stringlengths
17
427k
code2
stringlengths
17
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.7M
180,677B
code1_group
int64
1
299
code2_group
int64
1
299
import math n = float(input()) area = "%.6f" % float(n **2 * math.pi) circ = "%.6f" % float(n * 2 * math.pi) print(area, circ)
import math r = float(input()) s = r * r * math.pi l = r * 2.0 * math.pi print("{:f} {:f}".format(s, l))
1
644,428,764,038
null
46
46
day1=input().rstrip().split() day2=input().rstrip().split() if int(day2[1])==1: print(1) else: print(0)
while True: a, op, b = map(str, input().split()) if op == "?": break if op == "/": op = "//" formula = a + op + b print(eval(formula))
0
null
62,385,111,727,992
264
47
def DFS(num): global time time +=1 color[num]="gray" D[num][0]=time for i in M[num]: if color[i]=="white": DFS(i) color[num]="black" time +=1 D[num][1]=time n=int(input()) M=[[] for _ in range(n+1)] for i in range(n): for j in list(map(int,input().split()))[2:]: M[i+1].append(j) color=["white" for _ in range(n+1)] D=[[0,0] for _ in range(n+1)] time=0 for i in range(n): if color[i+1]=="white": DFS(i+1) for i in range(n): print(i+1,*D[i+1])
n = int(input()) g = [] for i in range(n): a = list(map(int,input().split())) g.append(a[2:]) d = [0]*n f = [0]*n global t t = 0 def find(x): global t if len(g[x-1]) == 0: t += 1 f[x-1] = t else: for i in g[x-1]: if d[i-1] == 0: t += 1 d[i-1] = t find(i) t += 1 f[x-1] = t for i in range(n): if d[i] == 0: t += 1 d[i] = t find(i+1) for i in range(n): print(i+1, d[i], f[i])
1
2,645,441,828
null
8
8
K=int(input()) A,B=map(int,input().split()) for x in range(A,B+1): if x%K==0: print("OK") break else: print("NG")
#coding:utf-8 #1_4_C 2015.3.29 while True: data = input().split() if data[1] == '?': break elif data[1] == '+': print(int(data[0]) + int(data[2])) elif data[1] == '-': print(int(data[0]) - int(data[2])) elif data[1] == '*': print(int(data[0]) * int(data[2])) elif data[1] == '/': print(int(data[0]) // int(data[2]))
0
null
13,586,294,817,220
158
47
class Dice: def __init__(self): self.front = '1' self.back = '6' self.top = '5' self.bottom = '2' self. right = '3' self.left = '4' def turnRight(self): temp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = temp return self.top def turnLeft(self): temp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = temp return self.top def turnFront(self): temp = self.top self.top = self.back self.back = self.bottom self.bottom = self.front self.front = temp return self.top def turnBack(self): temp = self.top self.top = self.front self.front = self.bottom self.bottom = self.back self.back = temp return self.top mydice = Dice() mydice.top, mydice.front, mydice.right, mydice.left, mydice.back, mydice.bottom = input().split() n = int(input()) for q in range(n): top, front = input().split() for rotate in range(3): mydice.turnFront() if mydice.top == front: break mydice.turnRight() if mydice.top == front: break mydice.turnFront() while top != mydice.top: mydice.turnRight() print(mydice.right)
N, K = map(int, input().split(' ')) h_ls = map(int, input().split(' ')) cnt = 0 for i in h_ls: if i >= K: cnt += 1 print(cnt)
0
null
89,456,012,781,280
34
298
x, y = map(int, input().split()) mod = 10 ** 9 + 7 if (x + y) % 3 != 0: ans = 0 else: n, m = (2 * x - y) / 3, (2 * y - x) / 3 ans = 0 if n >= 0 and m >= 0: n, m = int(n), int(m) ans = 1 for i in range(min(m, n)): ans = ans * (n + m - i) % mod ans *= pow(i + 1, mod - 2, mod) print(ans % mod)
X,Y=map(int,input().split()) if 2*Y<X or 2*X<Y: print(0) exit() if not((X%3==0 and Y%3==0) or (X%3==1 and Y%3==2) or (X%3==2 and Y%3==1)): print(0) exit() P=10**9+7 A=(2*Y-X)//3 B=(2*X-Y)//3 num = 1 for i in range(A+1, A+B+1): num=num*i%P den = 1 for j in range(1, B+1): den = den*j%P den = pow(den,P-2,P) print((num*den)%P)
1
149,902,783,192,850
null
281
281
#!/usr/bin/env python # -*- coding: utf-8 -*- import fileinput if __name__ == '__main__': for line in fileinput.input(): tokens = line.strip().split() a, b = int(tokens[0]), int(tokens[1]) if a == b == 0: pass elif a <= b: print '%d %d' % (a, b) elif b < a: print '%d %d' % (b, a)
x, y, z = map(int, input().split()) print(z, end='') print(" ", end='') print(x, end='') print(" ", end='') print(y, end='')
0
null
19,436,470,457,956
43
178
import fractions mod=10**9+7 def lcm(m,n):return m//fractions.gcd(m,n)*n n=int(input()) a=list(map(int,input().split())) l=a[0] ans=0 for i in a:l=lcm(i,l) for i in a:ans+=l*pow(i,mod-2,mod)%mod print(ans%mod)
s = input() ans = s + 'es' if s[-1]=='s' else s + 's' print(ans)
0
null
44,892,505,922,110
235
71
# coding: utf-8 x = int(input()) ans = x // 500 x = x - ans * 500 ans = ans * 1000 ans += (x // 5 * 5) print(ans)
#!/usr/bin/env python3 import sys def solve(S: str): print(S[0:3]) return 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()
0
null
28,825,289,666,650
185
130
s, t = input("").split(" ") res = t + s print(res)
s,t = input().split() print(t,s,sep='')
1
102,874,710,306,380
null
248
248
s=input() count=s.count("B") if count==3 or count==0: print("No") else: print("Yes")
s=input() if s[0]==s[1]==s[2]: print("No") if s[0]!=s[1] or s[1]!=s[2]: print("Yes")
1
54,653,643,635,540
null
201
201
n = input() s1 = [] s2 = [] for i in range(len(n)): if n[i] == '\\': s1.append(i) elif n[i] == '/' and len(s1) > 0: a = s1.pop(-1) s2.append([a, i - a]) i = 0 while len(s2) > 1: if i == len(s2) - 1: break elif s2[i][0] > s2[i + 1][0]: s2[i + 1][1] += s2.pop(i)[1] i = 0 else: i += 1 s = [] total = 0 for i in s2: s.append(str(int(i[1]))) total += int(i[1]) print(total) if len(s2) == 0: print('0') else: print('{} {}'.format(len(s2), ' '.join(s)))
#https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_D s = str(input()) l = len(s) h = [0] for i in range(l): if s[i] == '\\': h.append(h[i]-1) elif s[i] == '/': h.append(h[i]+1) else: h.append(h[i]) a = [] m = -200000 n = 0 for i in range(l+1): if m == h[i] and i != 0: a.append([n,i,m]) m = -200000 if m < h[i] or i == 0: m = h[i] n = i if (m in h[i+1:]) == False: m = -200000 b = [] tmp = 0 for i in range(len(a)): for j in range(a[i][0],a[i][1]): tmp += a[i][2] - h[j] if s[j] == '/': tmp += 1 / 2 elif s[j] == '\\': tmp -= 1 / 2 b.append(int(tmp)) tmp = 0 if len(b) != 0: i=0 while True: if b[i] == 0: del b[i] i -= 1 i += 1 if i == len(b): break A = sum(b) k = len(b) print(A) print(k,end = '') if k != 0: print(' ',end='') for i in range(k-1): print(b[i],end=' ') print(b[len(b)-1]) else: print('')
1
60,715,152,928
null
21
21
n,m = map(int,input().split()) A = list(map(int,input().split())) if (sum(A) <= n): print(n - sum(A)) else: print("-1")
# https://qiita.com/takayg1/items/7008e4c9584e42ae13c7 from collections import deque N, M = (int(i) for i in input().split()) graph = [deque([]) for _ in range(N + 1)] for _ in range(M): a, b = (int(i) for i in input().split()) graph[a].append(b) graph[b].append(a) seen = [-1] * (N + 1) def dfs(v): stack = [v] while stack: v = stack[-1] if graph[v]: w = graph[v].popleft() if seen[w] < 0: seen[w] = 0 stack.append(w) else: stack.pop() ans = 0 for i in range(N): if seen[i + 1] < 0: dfs(i + 1) ans += 1 print(ans - 1)
0
null
17,129,412,746,460
168
70
a,b,c=map(int,input().split()) import math d=math.sin(math.radians(c)) print(a*b*d/2) e=math.cos(math.radians(c)) x=math.sqrt(a**2+b**2-2*a*b*e) print(a+b+x) print(2*(a*b*d/2)/a)
from math import sin, cos, radians a, b, C = (float(x) for x in input().split()) s = a * b * sin(radians(C)) * 0.5 l = (a **2 + b**2 - 2 * a * b * cos(radians(C))) ** 0.5 + a + b h = s * 2 / a print(s) print(l) print(h)
1
169,153,613,978
null
30
30
import sys for i in range(1,10): for j in range(1,10): print("{0}x{1}={2}".format(i,j,i*j))
# -*- coding: utf-8 -*- from collections import deque ################ DANGER ################ test = "" #test = \ """ 9 6 1 1 2 2 3 3 4 4 5 5 6 4 7 7 8 8 9 ans 5 """ """ 5 4 1 1 2 2 3 3 4 3 5 ans 2 """ """ 5 4 5 1 2 1 3 1 4 1 5 ans 1 """ ######################################## test = list(reversed(test.strip().splitlines())) if test: def input2(): return test.pop() else: def input2(): return input() ######################################## n, taka, aoki = map(int, input2().split()) edges = [0] * (n-1) for i in range(n-1): edges[i] = tuple(map(int, input2().split())) adjacencyL = [[] for i in range(n+1)] for edge in edges: adjacencyL[edge[0]].append(edge[1]) adjacencyL[edge[1]].append(edge[0]) ################ DANGER ################ #print("taka", taka, "aoki", aoki) #import matplotlib.pyplot as plt #import networkx as nx #G = nx.DiGraph() #G.add_edges_from(edges) #nx.draw_networkx(G) #plt.show() ######################################## takaL = [None] * (n+1) aokiL = [None] * (n+1) takaL[taka] = 0 aokiL[aoki] = 0 takaQ = deque([taka]) aokiQ = deque([aoki]) for L, Q in ((takaL, takaQ), (aokiL, aokiQ)): while Q: popN = Q.popleft() for a in adjacencyL[popN]: if L[a] == None: Q.append(a) L[a] = L[popN] + 1 #print(L) print(max(aokiL[i] for i in range(1, n+1) if takaL[i] < aokiL[i]) - 1)
0
null
58,524,054,135,560
1
259
import sys input=lambda: sys.stdin.readline().strip() n=int(input()) A=[] # PM=[[0,0] for i in range(n)] for i in range(n): now=0 mini=0 for j in input(): if j=="(": now+=1 else: now-=1 ; mini=min(mini,now) PM[i]=[mini,now] if sum( [PM[i][1] for i in range(n)] )!=0 : print("No") exit() MINI=0 NOW=0 PMf=[PM[i] for i in range(n) if PM[i][1]>=0] PMf.sort() for i in range(len(PMf)): MINI=min(MINI , NOW+PMf[-i-1][0] ) NOW+=PMf[-i-1][1] if MINI<0 : print("No") ; exit() PMs=[PM[i] for i in range(n) if PM[i][1]<0] PMs=sorted(PMs , key=lambda x : x[1]-x[0]) for i in range(len(PMs)): MINI=min(MINI , NOW+PMs[-i-1][0] ) NOW+=PMs[-i-1][1] if MINI<0 : print("No") ; exit() print("Yes")
x, y = map(int, input().split()) lst = [] ans = 'No' for i in range(x): lst.append(2) for i in range(x): if sum(lst) == y: ans = 'Yes' break lst[i] = 4 if sum(lst) == y: ans = 'Yes' print(ans)
0
null
18,641,990,432,214
152
127
x,y = map(int,input().split()) if y % 2 != 0: print('No') elif x * 2 <= y <= x * 4: print('Yes') else: print('No')
x, y = map(int, input().split()) t = (4*x-y)/2 k = x - t if (int(t) -t == 0) and (t>=0) and (k>=0): print('Yes') else: print('No')
1
13,623,999,395,260
null
127
127
from bisect import * n,m = map(int,input().split()) S = input() ok = [] for i,s in enumerate(S[::-1]): if s == '0': ok.append(i) now = 0 ans = [] while now != n: nxt = ok[bisect_right(ok, now + m) - 1] if nxt == now: ans = [str(-1)] break else: ans.append(str(nxt - now)) now = nxt print(' '.join(ans[::-1]))
import sys N,M=map(int,input().split()) S=input() lst=[] koma=N rs=0 ME=0 pn=0 while koma>0 and pn==0: rs+=1 if int(S[koma-rs])==0: ME=rs if koma-rs==0 or rs==M: lst.append(ME) if ME==0: pn+=1 koma-=ME rs=rs-ME ME=0 if pn>0: print(-1) else: lst.reverse() print(*lst)
1
139,741,787,259,500
null
274
274
import sys, math from functools import lru_cache import numpy as np import heapq from collections import defaultdict sys.setrecursionlimit(10**9) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def sieve(n): res = [i for i in range(n)] i = 2 while i*i < n: if res[i] < i: i += 1 continue j = i*i while j < n: if res[j] == j: res[j] = i j += i i += 1 return res def factor(n, min_factor): res = set() while n > 1: res.add(min_factor[n]) n //= min_factor[n] return res def main(): N = ii() A = np.array(list(mi())) m = max(A) s = sieve(m+1) d = defaultdict(bool) g = np.gcd.reduce(A) if g > 1: print('not coprime') return for a in A: f = factor(a, s) for v in f: if d[v]: print('setwise coprime') return d[v] = True print('pairwise coprime') if __name__ == '__main__': main()
n = list(map(int, list(input()))) count = 0 n = n[::-1] + [0] for idx, num in enumerate(n): if num == 10: n[idx+1] += 1 elif num == 5: if n[idx+1] >= 5: n[idx+1] += 1 count += 10 - num else: count += num elif num <= 4: count += num else: count += 10 - num n[idx+1] += 1 print(count)
0
null
37,678,442,383,450
85
219
s=input() for _ in range(int(input())): a=input().split() i,j=map(int, a[1:3]) if a[0] == "print": print(s[i:j+1]) elif a[0] == "reverse": t1=s[0:i] t2=list(s[i:j+1]) t2.reverse() t3=s[j+1:] s=t1+"".join(t2)+t3 else: s=s[0:i]+a[3]+s[j+1:]
s = input() n = int(input()) for _ in range(n): line = input().split() order = line[0] a = int(line[1]) b = int(line[2]) p = line[3] if len(line) == 4 else '' if order == 'print': print(s[a:b+1]) elif order == 'reverse': s = s[:a] + ''.join(reversed(s[a:b+1])) + s[b+1:] elif order == 'replace': s = s[:a] + p + s[b+1:]
1
2,098,165,151,034
null
68
68
#!/usr/bin/env python # encoding: utf-8 import copy class Solution: def stable_sort(self): # write your code here array_length = int(input()) b_array = [str(x) for x in input().split()] s_array = copy.deepcopy(b_array) bubble_result = self.bubble_sort(b_array=b_array, array_length=array_length) selection_result = self.selection_sort(s_array=s_array, array_length=array_length) # check whether selection sort is stable if bubble_result == selection_result: print("Stable") else: print("Not stable") @staticmethod def selection_sort(s_array, array_length): # selection sort selection_count = 0 for i in range(array_length): min_j = i for j in range(i, array_length): if s_array[j][1] < s_array[min_j][1]: min_j = j s_array[i], s_array[min_j] = s_array[min_j], s_array[i] if i != min_j: selection_count += 1 result = " ".join(map(str, s_array)) print(result) return result @staticmethod def bubble_sort(b_array, array_length): flag, bubble_count, cursor = 1, 0, 0 while flag: flag = 0 for j in range(array_length - 1, cursor, -1): if b_array[j][1] < b_array[j - 1][1]: b_array[j], b_array[j - 1] = b_array[j - 1], b_array[j] flag = 1 bubble_count += 1 cursor += 1 result = " ".join(map(str, b_array)) print(result) print("Stable") return result if __name__ == '__main__': solution = Solution() solution.stable_sort()
def comp(a,b): if a[1] > b[1]: return True else: return False def bubble_sort(a): for i in range(n): for j in reversed(range(i+1,n)): if comp(a[j-1],a[j]): a[j],a[j-1]=a[j-1],a[j] return a def selection_sort(a): for i in range(n): mini = i for j in range(i,n): if comp(a[mini],a[j]): mini=j a[mini],a[i]=a[i],a[mini] return a def stable(original_a,sorted_a): for num in range(1,10): suite_ord = [] for v in original_a: if v[1] == str(num): suite_ord.append(v[0]) for v in sorted_a: if v[1] == str(num): if v[0]==suite_ord[0]: del suite_ord[0] else: return "Not stable" return "Stable" n = int(raw_input()) cards = raw_input().split(' ') sorted_cards = bubble_sort(cards[:]) print ' '.join(sorted_cards) print stable(cards,sorted_cards) sorted_cards = selection_sort(cards[:]) print ' '.join(sorted_cards) print stable(cards,sorted_cards)
1
25,715,796,340
null
16
16
#!/usr/bin/env python def main(): N = int(input()) D = list(map(int, input().split())) ans = 0 for i in range(N-1): d1 = D[i] for d2 in D[i+1:]: ans += d1 * d2 print(ans) if __name__ == '__main__': main()
def gcd(a, b): if (a == 0): return b return gcd(b%a, a) def lcm(a, b): return (a*b)//gcd(a, b) n = int(input()) numbers = list(map(int, input().split())) l = numbers[0] for i in range(1, n): l = lcm(l, numbers[i]) ans = 0 for i in range(n): ans += l//numbers[i] MOD = 1000000007 print(ans%MOD)
0
null
128,110,811,302,140
292
235
import itertools n, m, x = map(int, input().split()) books = [] for i in range(n): ins = list(map(int, input().split())) books.append({"c": ins[0], "a": ins[1: m+1]}) ans = float('inf') for i in range(1, n+1): book_list = list(itertools.combinations(list(range(n)), i)) for lis in book_list: cost_sum = 0 a_sum = [0] * m ok = 0 ok_list = [False] * m for j in lis: cost_sum += books[j]['c'] for k in range(m): a_sum[k] += books[j]['a'][k] if not ok_list[k] and a_sum[k] >= x: ok += 1 ok_list[k] = True if ok == m and ans > cost_sum: ans = cost_sum if ans == float('inf'): print(-1) else: print(ans)
a,b,c,k=map(int,input().split()) if k < a: print(k) elif k <= a+b: print(a) else: print(2*a+b-k)
0
null
21,957,185,460,700
149
148
n = int(input()) xl = [list(map(int, input().split())) for _ in range(n)] arms = [[xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]] for i in range(n)] arms.sort(key=lambda x: x[1]) ans = 1 ne = arms[0][1] for i in range(n): if arms[i][0] >= ne: ne = arms[i][1] ans += 1 print(ans)
N, *A = map(int, open(0).read().split()) X = [(x-l, x+l) for x, l in zip(*[iter(A)]*2)] X.sort() ans = 1 L, R = X[0] for l, r in X[1:]: if R <= l: ans += 1 L = l R = r elif R > r: R = r print(ans)
1
89,807,666,335,594
null
237
237
import sys readline = sys.stdin.readline N,X,Y = map(int,readline().split()) X -= 1 Y -= 1 ans = [0] * N for i in range(N - 1): for j in range(i + 1, N): val = min(abs(i - j),abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X)) ans[val] += 1 for i in range(1, len(ans)): print(ans[i])
N,X,Y=map(int,input().split()) ANS=[0 for i in range(N-1)] for i in range(N-1): for k in range(i+1,N): d=min(k-i,abs(X-i-1)+abs(Y-k-1)+1) ANS[d-1]+=1 for i in ANS: print(i)
1
44,316,889,710,450
null
187
187
import math alpha = [] while True: n = float(raw_input()) if n == 0: break nums_str = raw_input().split() nums = [] for s in nums_str: nums.append(float(s)) ave = sum(nums)/n n_sum = 0.0 for num in nums: n_sum += (num-ave)**2 alpha.append(n_sum/n) for a in alpha: print math.sqrt(a)
import math while True: a_2 = 0 n = int(input()) if n == 0: break score = [int(x) for x in input().split()] m = sum(score)/len(score) #print(m) for i in range(len(score)): a_2 += (score[i]-m)*(score[i]-m)/n #print(a_2) print('%.4f'% math.sqrt(a_2))
1
189,663,934,080
null
31
31
n = input() s = input().split() q = input() t = input().split() ans = 0 for c1 in t: for c2 in s: if c1 == c2: ans += 1 break print(ans)
n = int(raw_input()) elems = map(int, raw_input().split(' ')) cumul = 0 res = 0 for j in range(len(elems)): res += elems[j] * cumul cumul += elems[j] print res
0
null
83,790,168,764,120
22
292
import sys while True: ins = input().split() h = int(ins[0]) w = int(ins[1]) if h == 0 and w == 0: break for i in range(h): for j in range(w-1): sys.stdout.write("#") print("#") print("")
while True: (H, W) = [int(x) for x in input().split()] if H == W == 0: break for hc in range(H): [print('#', end='') for wc in range(W)] print() print()
1
778,994,329,948
null
49
49
from math import gcd def setwise_coprime_check_fun(A_list, N): gcd_all = A_list[0] for i in range(N - 1): gcd_all = gcd(gcd_all, A_list[i + 1]) if gcd_all == 1: break return gcd_all def preprocess_fun(A_max): p_flg = [True] * (A_max + 1) D = [0] * (A_max + 1) p_flg[0] = False p_flg[1] = False for i in range(2, A_max + 1, 1): if p_flg[i]: for j in range(i, A_max + 1, i): p_flg[j] = False D[j] = i return D def pairwise_coprime_check(A_list, D, A_max): p_count = [0] * (A_max + 1) for A in A_list: temp = A d = 0 while temp != 1: if p_count[D[temp]] == 1 and d != D[temp]: return 0 p_count[D[temp]] = 1 d = D[temp] temp = temp // D[temp] return 1 ## 標準入力 N = int(input()) A_list = list(map(int, input().split(" "))) # 整数の最大値を取得 A_max = max(A_list) # 本体 if(setwise_coprime_check_fun(A_list, N) != 1): print("not coprime") else: D = preprocess_fun(A_max) if pairwise_coprime_check(A_list, D, A_max) == 1: print("pairwise coprime") else: print("setwise coprime")
import sys input=sys.stdin.readline def gcd(a,b): if b==0: return a else: return gcd(b,a%b) def calc(): n=int(input()) arr=list(map(int,input().split())) g=arr[0] cnt=[0]*(10**6+1) for val in arr: g=gcd(g,val) cnt[val]+=1 for i in range(2,10**6+1): tmp=0 for j in range(i,10**6+1,i): tmp+=cnt[j] if tmp>=2: break if i==10**6: print('pairwise coprime') elif g==1: print('setwise coprime') else: print('not coprime') calc()
1
4,141,993,020,100
null
85
85
import math r = int(input()) pi = int(math.pi) a = (pi * (r)**2) ans = a / pi print(int(ans))
a = int(input()) ans = a * a print(ans)
1
145,222,743,375,622
null
278
278
from decimal import Decimal a, b = input().split() a = Decimal(a) b = Decimal(b) print(int(a*b))
a,b = input().split() a = int(a) b_list = list(b) b_list.pop(1) b_list = [int(s) for s in b_list] p_100 = a*b_list[0]*100 + a*b_list[1]*10 + a*b_list[2] p = p_100//100 print(p)
1
16,519,210,247,772
null
135
135
def swap(a, b ,item): c = item[a] item[a] = item[b] item[b] = c AB = input().split() a = int(AB[0]) b = int(AB[1]) while a!=0 or b!=0: if a>b: swap(0, 1, AB) print(int(AB[0]), int(AB[1])) AB = input().split() a = int(AB[0]) b = int(AB[1])
import math while True: line = int(input()) if line == 0: break l = [float(s) for s in input().split()] avg = sum(l) / len(l) a2 = 0 for i in l: a2 += (avg - i) ** 2 print(math.sqrt(a2 / len(l)))
0
null
357,137,554,950
43
31
import sys import string from collections import Counter def main(): s = sys.stdin.read() c = Counter(s.lower()) for char in string.ascii_lowercase: print(char, ":", c.get(char, 0)) if __name__ == "__main__": main()
N,M = map(int, input().split(" ")) if M >= N: print("Yes") else: print("No")
0
null
42,265,108,967,440
63
231
n,k=[int(x) for x in input().split()] d=[int(x) for x in input().split()] t=[x for x in d if x>=k] print(len(t))
n = int(input()) a = list(map(int, input().split())) s = a[0] for i in range(1,n): s ^= a[i] ans = [0]*n for j in range(n): ans[j] = s ^ a[j] print(*ans)
0
null
95,717,881,119,818
298
123
import math import sys pin=sys.stdin.readline def main(): N,X,M=map(int,pin().split()) A=X d=[X] su=X for i in range(N-1): A=(A**2)%M if A in d: t=d.index(A) T=N-i-1 d=d[t:] l=len(d) su+=sum(d)*(T//l) T=T%(T//l) su+=sum(d[:T]) print(su) return d.append(A) su+=A print(su) return main()
D = int(input()) c = list(map(int, input().split())) s = [] for _ in range(D): s.append(list(map(int, input().split()))) t = [] for _ in range(D): t.append(int(input())) # last(d, i)を計算するためのメモ dp = [0] * 26 def dec(d): # d日の終わりに起こる満足度の減少計算の関数 s = 0 for j in range(26): s += c[j] * (d - dp[j]) return s # vは満足度 v = 0 for i in range(D): # 初日の満足度 if (i == 0): v += s[i][t[i] - 1] # 開催されたコンテストの日付をメモ dp[t[i] - 1] = (i + 1) v -= dec(i + 1) print(v) continue # elif (0 < i and i < D - 1): v += s[i][t[i] - 1] dp[t[i] - 1] = (i + 1) v -= dec(i + 1) print(v)
0
null
6,363,329,808,068
75
114
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = 10**6#float('inf') mod = 10 ** 9 + 7 #mod = 998244353 #from decimal import * #import numpy as np #decimal.getcontext().prec = 10 N, T = MAP() AB = [LIST() for _ in range(N)] AB.sort(key = lambda x:x[0]) t = [0]*T ans = 0 for A, B in AB: for i in range(T-1, 0, -1): if t[i]: if T <= i+A: ans = max(ans, t[i]+B) else: t[i+A] = max(t[i+A], t[i]+B) if T <= A: ans = max(ans, B) else: t[A] = max(t[A], B) ans = max(ans, max(t)) print(ans)
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n, k = map(int, input().split()) cnt = 0 while 0 < n: n //= k cnt += 1 print(cnt)
0
null
108,268,577,143,830
282
212
def main(): T = input() T = T.replace('?', 'D') # cnt = 0 # cnt_pd = t.count('PD') # cnt_d = t.count('D') # cnt = cnt_d + cnt_pd print(T) main()
s = input() a = [str(c) for c in s] for i in range (len(a)-1): if a[i]=='?': if i!=0 and a[i-1]=='P': a[i]='D' elif a[i+1]=='D' or a[i+1]=='?': a[i]='P' else: a[i]='D' if a[len(a)-1]=='?': a[len(a)-1]='D' print(*a,sep='')
1
18,601,503,716,640
null
140
140
# 高橋くんのモンスターは体力Aで攻撃力B # 青木くんのモンスターは体力Cで攻撃力D # 高橋くんが勝つならYes、負けるならNoを出力する A, B, C, D = map(int, input().split()) while A > 0 and C > 0: C -= B A -= D if C <= 0: print('Yes') elif A <= 0: print('No')
n = int(input()) s = input() ans = [] for i in range(len(s)): temp = ord(s[i]) +n if temp > 0x5a: temp -= 26 ans.append(chr(temp)) for k in range(len(ans)): print(ans[k], end = "")
0
null
81,706,493,971,488
164
271
a = list(map(int,input().split())) T = a.index(0) print(T+1) #
L= list(map(int,input().split())) a=1 for i in range(5): if L[i]!=0: a+=1 else: print(a)
1
13,369,036,968,650
null
126
126
def main(): H, W, M = map(int, input().split()) h_dic = [0] * H w_dic = [0] * W boms = set() for _ in range(M): h, w = map(int, input().split()) h, w = h-1, w-1 h_dic[h] += 1 w_dic[w] += 1 boms.add((h, w)) hmax = max(h_dic) wmax = max(w_dic) h_maxs = [idx for idx, v in enumerate(h_dic) if v==hmax] w_maxs = [idx for idx, v in enumerate(w_dic) if v==wmax] # 爆弾数はたかだか3*10~5なので、総当りで解ける for h in h_maxs: for w in w_maxs: if (h, w) not in boms: print(hmax + wmax) return print(hmax + wmax - 1) return if __name__ == "__main__": main()
from collections import defaultdict H, W, M = map(int, input().split()) row_bom_cnt = defaultdict(int) col_bom_cnt = defaultdict(int) row_max = 0 col_max = 0 boms = [list(map(int, input().split())) for _ in range(M)] for rm, cm in boms: row_bom_cnt[rm] += 1 col_bom_cnt[cm] += 1 row_max = max(row_max, row_bom_cnt[rm]) col_max = max(col_max, col_bom_cnt[cm]) target_row = set() for r, val in row_bom_cnt.items(): if val == row_max: target_row.add(r) target_col = set() for c, val in col_bom_cnt.items(): if val == col_max: target_col.add(c) cnt = 0 for rm, cm in boms: if rm in target_row and cm in target_col: cnt += 1 if len(target_row) * len(target_col) == cnt: print(row_max + col_max - 1) else: print(row_max + col_max)
1
4,695,401,861,402
null
89
89
a, b, c, d = [float(temp) for temp in input().split()] from math import sqrt dis = sqrt((c - a) ** 2 + (d - b) ** 2) print('%0.5f'%dis)
x1,y1,x2,y2=map(float,input().split()) a=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1) print(a**(1/2))
1
159,135,296,804
null
29
29
while 1: h,w = map(int,raw_input().split()) if h==w==0: break print ("#"*w+"\n")*h
if __name__ == '__main__': a, b, c, k = map(int, input().split()) if k <= a: print(k) elif a < k and k <= (a+b): print(a) else: print(a - (k-a-b))
0
null
11,410,882,998,400
49
148
for i in range(200): try: a,b=map(int,input().split()) print(len(str(a+b))) except: pass
def solve(Mi,i): if Mi == 0: return True if i < n and min(A[i:]) <= Mi <= sum(A[i:]): r1 = solve(Mi-A[i],i+1) if r1: return r1 r2 = solve(Mi,i+1) if r2: return r2 n = input() A = map(int,raw_input().split()) q = input() M = map(int,raw_input().split()) for Mi in M: print "yes" if solve(Mi,0) else "no"
0
null
49,274,226,662
3
25
n, k = map(int, input().split()) d = [0]*k a = [0]*k for i in range(k): d[i] = int(input()) a[i] = list(map(int, input().split())) ans = [0]*100 for i in range(k): for j in range(d[i]): ans[a[i][j]-1] = 1 print(n-sum(ans))
import itertools import math n = int(input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) arr = [i for i in itertools.permutations([i for i in range(1, n+1)])] a = arr.index(p) b = arr.index(q) print(abs(a-b))
0
null
62,384,345,556,312
154
246
n,m=map(int,input().split()) a=list(map(int,input().split())) h=sum(a) if n<h: print('-1') else: print(n-h)
a = int(input()) b = int(input()) l = [a, b] if not 1 in l: print('1') elif not 2 in l: print('2') else: print('3')
0
null
71,348,678,289,320
168
254
lists = [] for i in range(10): a = int(input()) lists.append(a) f = sorted(lists, reverse = True) for i in range(3): print(f[i])
mounts =[int(input()) for i in range(10)] mounts.sort(reverse = True) for i in range(3): print(mounts[i])
1
28,251,636
null
2
2
n = input() R = [] for i in range(n): R.append(input()) min_v = R[0] max_v = -1000000000000 for i in range(1, n): temp = R[i] - min_v if (temp >= max_v): max_v = temp temp = R[i] if (min_v >= temp): min_v = temp print max_v
def main(): N = input() a = [input() for y in range(N)] a_max = -10**9 a_min = a[0] for j in xrange(1,len(a)): if a[j] - a_min > a_max: a_max = a[j] - a_min if a[j] < a_min: a_min = a[j] print a_max main()
1
13,476,227,842
null
13
13
n = int(input()) a = list(map(int, input().split())) ruiseki = 0 count = 0 for i in range(n-1): ruiseki += a[i] count += ruiseki * a[i+1] mod = 10**9 + 7 if count >= mod: print(count%mod) else: print(count)
D, T, S = map(int,input().split()) Distance = T * S if(D <= Distance): print('Yes') else: print('No')
0
null
3,736,517,405,792
83
81
#!usr/bin/env pypy3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate, combinations_with_replacement, compress import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res 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)] sys.setrecursionlimit(1000000) def main(): N, M, Q = LI() abcd = [LI() for _ in range(Q)] ans = 0 for A in combinations_with_replacement(range(1, M + 1), N): tmp = 0 for (a, b, c, d) in abcd: tmp += d if (A[b-1] - A[a-1] == c) else 0 ans = max(ans, tmp) print(ans) main()
import numpy as np import itertools N, M, Q = map(int, input().split()) G = [] for i in range(Q): a, b, c, d = map(int, input().split()) G.append([a, b, c, d]) ans = 0 A = np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N))) n = len(A) score = np.zeros(n, np.int32) for a, b, c, d in G: cond = A[:, b - 1] - A[:, a - 1] == c score += d * cond print(score.max())
1
27,584,119,398,610
null
160
160
n, k, s = map(int,input().split()) if s == 10**9: ans = [1 for i in range(n)] for i in range(k): ans[i] = 10**9 else: ans = [10**9 for i in range(n)] for i in range(k): ans[i] = s print(" ".join(map(str,ans)))
N,K,S = map(int,input().split()) ANS = [S] * K if S != 10 ** 9: ANS += [S+1] * (N-K) else: ANS += [S-1] * (N-K) print(" ".join(map(str,ANS)))
1
90,712,245,102,300
null
238
238
k = int(input()) ans = 0 def gcd(a,b): if a % b == 0: return b c = a % b return gcd(b,c) for l in range(1,k+1): for m in range(l,k+1): for n in range(m,k+1): tmp1 = gcd(l,n) tmp2= gcd(tmp1,m) if (l==m==n): ans+=tmp2 elif(l==m or m==n): ans+= 3*tmp2 else: ans += 6*tmp2 print(ans)
num=input() numline=list(num) a=int(numline[len(numline)-1]) if(a==3): print("bon") elif(a==0 or a==1 or a==6 or a==8): print("pon") else: print("hon")
0
null
27,475,285,741,292
174
142
n=input() cnt=0 for i in range(3): if n[i]=="7": cnt+=1 if cnt==0: print("No") else: print("Yes")
n = input() ans = 'No' for i in n : if i == '7' : ans = 'Yes' print(ans)
1
34,389,023,867,430
null
172
172
n = int(input()) d = {} for _ in range(n): s = input() if not s in d.keys(): d[s] = 1 print(len(d))
n = int(input()) a_list = [] for _ in range(n): mini_list = [] a = int(input()) for _ in range(a): mini_list.append(list(map(int, input().split()))) a_list.append(mini_list) ans = 0 for i in range(2**n): ans_list = [0]*n cnt=0 while i!=0: ans_list[cnt] = i%2 cnt+=1 i//=2 flg = True for j, syogens in enumerate(a_list): if ans_list[j]==0: pass else: for syogen in syogens: person = syogen[0]-1 status = syogen[1] if ans_list[person] != status: flg=False if flg: ans = max(ans,sum(ans_list)) print(ans)
0
null
75,764,110,843,232
165
262
H ,W = map(int,input().split()) from collections import deque S = [input() for i in range(H)] directions = [[0,1],[1,0],[-1,0],[0,-1]] counter = 0 #インデックス番号 xが行番号 yが列番号 for x in range(H): for y in range(W): if S[x][y]=="#": continue que = deque([[x,y]]) memory = [[-1]*W for _ in range(H)] memory[x][y]=0 while True: if len(que)==0: break h,w = que.popleft() for i,k in directions: x_new,y_new = h+i,w+k if not(0<=x_new<=H-1) or not(0<=y_new<=W-1) : continue elif not memory[x_new][y_new]==-1 or S[x_new][y_new]=="#": continue memory[x_new][y_new] = memory[h][w]+1 que.append([x_new,y_new]) counter = max(counter,max(max(i) for i in memory)) print(counter)
from collections import deque H,W=map(int,input().split()) S=[[c=='#' for c in input()] for _ in range(H)] def bfs(i,j): if S[i][j]: return 0 que=deque() que.append((i,j)) vis=[row[:] for row in S] vis[i][j]=1 ans=-1 while que: ans+=1 for _ in range(len(que)): i,j=que.popleft() for ni,nj in nbs(i,j): if not vis[ni][nj]: que.append((ni,nj)) vis[ni][nj]=1 return ans def nbs(i,j): for ni,nj in (i-1,j),(i,j+1),(i+1,j),(i,j-1): if 0<=ni<H and 0<=nj<W: yield ni,nj ans=0 for i in range(H): for j in range(W): ans=max(ans,bfs(i,j)) print(ans)
1
94,672,161,111,372
null
241
241
n, m =map(int,input().split()) c = list(map(int,input().split())) INF = 10**100 dp = [INF]*500000 dp[0] = 0 for i in range (n+1): for j in c: dp[i+j] = min(dp[i+j],dp[i]+1) print(dp[n])
n,m = map(int,input().split()) coins = list(map(int,input().split())) dp = [20**10]*(n+1) dp[0] = 0 for coin in coins: for price in range(coin,n+1): dp[price] = min(dp[price],dp[price-coin]+1) print(dp[n])
1
141,535,667,880
null
28
28
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, M, K = mapint() 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()} uf = UnionFind(N) blocks = set() friends = [0]*N possi = [0]*N for _ in range(M): a, b = mapint() uf.union(a-1, b-1) friends[a-1] += 1 friends[b-1] += 1 for _ in range(K): a, b = mapint() if uf.same(a-1, b-1): friends[a-1] += 1 friends[b-1] += 1 for i in range(N): possi[i] = uf.size(i)-friends[i]-1 print(*possi)
import collections def Z(): return int(input()) def ZZ(): return [int(_) for _ in input().split()] def main(): N, M, K = ZZ() F = [0] * (N+1) output = [] par = [i for i in range(N+1)] rank = [0] * (N+1) # 要素xの親ノードを返す def find(x): if par[x] == x: return x par[x] = find(par[x]) return par[x] # 要素x, yの属する集合を併合 def unite(x, y): x, y = find(x), find(y) if x == y: return if rank[x] < rank[y]: par[x] = y else: par[y] = x if rank[x] == rank[y]: rank[x] += 1 return # xとyが同じ集合に属するか? def same(x, y): return find(x) == find(y) for _ in range(M): a, b = ZZ() F[a] += 1 F[b] += 1 unite(a, b) for i in range(1, N+1): find(i) cnt = collections.Counter(par) for _ in range(K): c, d = ZZ() if same(c, d): F[c] += 1 F[d] += 1 for i in range(1, N+1): cc = cnt[par[i]] - F[i] - 1 output.append(cc) print(*output) return if __name__ == '__main__': main()
1
61,788,264,324,352
null
209
209
n = int(input()) Ai = list(map(int, input().split())) sum_ans = sum(Ai) ans = 0 mod = 1000000007 for i in range(n-1): sum_ans -= Ai[i] ans += sum_ans * Ai[i] ans %= mod print(ans)
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') MOD = 10 ** 9 + 7 def I(): return int(input()) def F(): return float(input()) def SS(): return input() def LI(): return [int(x) for x in input().split()] def LI_(): return [int(x)-1 for x in input().split()] def LF(): return [float(x) for x in input().split()] def LSS(): return input().split() def resolve(): N = I() A = LI() ans = (sum(A) ** 2 - sum([i ** 2 for i in A])) // 2 % MOD print(ans) if __name__ == '__main__': resolve()
1
3,829,945,279,300
null
83
83
n = int(input()) s,t = input().split() for i in range(n): print(s[i]+t[i],end="")
N = int(input()) S, T = input().split() S_list = list(S) T_list = list(T) ans = "" for i, j in zip(S_list, T_list): ans += i + j print(ans)
1
112,271,389,991,888
null
255
255
x, k, d = map(int, input().split()) x = abs(x) num = x // d if num >= k: ans = x - k*d else: if (k-num)%2 == 0: ans = x - num*d else: ans = min(abs(x - num*d - d), abs(x - num*d + d)) print(ans)
n = int(raw_input()) d = [100 for i in range(n)] G = [0 for i in range(n)] v = [[0 for i in range(n)] for j in range(n)] def BFS(s): for e in range(n): if v[s][e] == 1: if d[e] > d[s] + 1: d[e] = d[s]+1 BFS(e) for i in range(n): G = map(int, raw_input().split()) for j in range(G[1]): v[G[0]-1][G[j+2]-1] = 1 d[0] = 0 for i in range(n): BFS(i) for i in range(n): if d[i] == 100: d[i] = -1 for i in range(n): print i+1, d[i]
0
null
2,582,238,070,034
92
9
s = input() print(s+'es') if s.endswith('s') else print(s+'s')
n=int(input()) l =[] for i in range(n): s =input() l.append(s) l = set(l) print(len(l))
0
null
16,346,711,006,620
71
165
inps = input().split() if len(inps) >= 3: a = int(inps[0]) b = int(inps[1]) c = int(inps[2]) if a < b and b < c: print("Yes") else: print("No") else: print("Input illegal.")
n, k = map(int, input().split()) a = list(map(int, input().split())) ng = 0 ok = 10 ** 9 + 1 def check(x): cnt = 0 for l in a: cnt += (l-1)//x return cnt <= k while abs(ok-ng) > 1: m = (ok + ng) // 2 if check(m): ok = m else: ng = m print(ok)
0
null
3,405,034,042,988
39
99
print('NYoe s'['AAA'<input()<'BBB'::2])
import collections import heapq import math import random import sys input = sys.stdin.readline sys.setrecursionlimit(500005) ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) rs = lambda: input().rstrip() n = ri() a = rl() N = 1000000 f = [0] * (N + 10) for v in a: f[v] += 1 for i in range(N, 0, -1): if f[i] == 0: continue j = i * 2 while j <= N: f[j] += f[i] j += i cnt = sum(f[i] == 1 for i in a) print(cnt)
0
null
34,528,178,942,290
201
129
N=int(input()) ac = wa = tle = re =0 for cnt in range(N): S=input() if S=='AC': ac=ac+1 elif S=='WA': wa=wa+1 elif S=='TLE': tle=tle+1 elif S=='RE': re=re+1 print('AC x '+str(ac)+'\nWA x '+str(wa)+'\nTLE x '+str(tle)+'\nRE x '+str(re))
n ,k = map(int, input().split()) lis = list(map(int, input().split())) for i in range(k, n): l = lis[i-k] r = lis[i] if r > l: print('Yes') else: print('No')
0
null
7,859,357,844,782
109
102
import math a, b, C = map(int, input().split()) C = math.radians(C) print(0.5*a*b*math.sin(C)) print(a+b+math.sqrt(a*a+b*b-2*a*b*math.cos(C))) print(b*math.sin(C))
import math a, b, C = map(int, input().split()) rad_C = math.radians(C) c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(rad_C)) h = b * math.sin(rad_C) L = a + b + c s = a * h / 2 print(s) print(L) print(h)
1
167,251,550,930
null
30
30
num = input() lst = [] for x in num: lst.append(int(x)) total = sum(lst) if total % 9 == 0: print('Yes') else: print('No')
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy import bisect mod = 10**9+7 def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) if __name__ == "__main__": x,y = map(int,input().split()) if (x+y)%3 != 0: print(0) sys.exit() n = (2*y-x)//3 m = (2*x-y)//3 ans = cmb(int(n+m),int(n),mod) print(ans)
0
null
77,565,699,483,932
87
281
import itertools n = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) N = [i for i in range(1,n+1)] N_dict = {v:(i+1) for i,v in enumerate(itertools.permutations(N, n))} #print(N_dict) print(abs(N_dict[P] - N_dict[Q]))
import itertools n = int(input()) s = list(map(int, input().split(' '))) t = list(map(int, input().split(' '))) hoge = list(itertools.permutations(range(1, n+1))) p = 0 q = 0 for i in range(len(hoge)): if list(hoge[i]) == s: p = i if list(hoge[i]) == t: q = i print(abs(p - q))
1
100,814,022,895,840
null
246
246
N,u,v = map(int, input().split()) G=[[] for i in range(N)] for i in range(N-1): s,t = map(int, input().split()) G[s-1].append(t-1) G[t-1].append(s-1) def expro(u): D=[0]*N D[u]=0 S=[] S.append(u) L=[] q=0 while(q<N): l=S[q] for i in range(len(G[l])): m=G[l][i] if(len(G[l])==1 and l!=u): L.append(l) if(D[m]==0 and m!=u): D[m]=D[l]+1 S.append(m) #S.remove(l) q+=1 return L,D L,D = expro(u-1) M,E = expro(v-1) k=0 ans=0 #print(G) #print(D) #print(L) for i in M: if D[i]<E[i]: if k<E[i]: k=E[i] ans=E[i]-1 print(ans)
from collections import defaultdict, deque N, u, v = map(int, input().split()) u -= 1 v -= 1 dic = defaultdict(list) for i in range(N-1): a, b = map(int, input().split()) dic[a-1] += [b-1] dic[b-1] += [a-1] dist1 = [float('inf')]*N dist2 = [float('inf')]*N q1 = deque([u]) q2 = deque([v]) dist1[u] = 0 dist2[v] = 0 while q1: e = q1.popleft() for p in dic[e]: if dist1[p]>dist1[e]+1: dist1[p] = dist1[e]+1 q1 += [p] while q2: e = q2.popleft() for p in dic[e]: if dist2[p]>dist2[e]+1: dist2[p] = dist2[e]+1 q2 += [p] ans = -1 j = 0 for i in range(N): if ans<dist2[i]-1 and dist1[i]<dist2[i]: ans = dist2[i]-1 if u==v: ans = 0 print(ans)
1
117,768,648,552,368
null
259
259
N = int(input()) S, T = input().split() L = [S[i]+T[i] for i in range(N)] print(*L, sep="")
n = int(input()) a,b = input().split() print(''.join(a[i]+b[i] for i in range(n)))
1
111,832,271,408,598
null
255
255
# f=open('in','r') # input=lambda:f.readline().strip() n=int(input()) r=list(map(int,input().split())) mod=1000000007 s=sum(r)%mod x=0 for u in r: x+=u**2 x%=mod t=500000004 print((s**2-x)*t%mod)
from collections import deque n = int(input()) d = deque() for _i in range(n): line = input().split() order = line[0] if order in ('insert', 'delete'): key = line[1] if order == 'insert': d.appendleft(key) elif order == 'delete': try: d.remove(key) except ValueError: pass elif order == 'deleteFirst': d.popleft() elif order == 'deleteLast': d.pop() else: raise ValueError('Invalid order: {order}') print(' '.join(d))
0
null
1,937,017,483,028
83
20
import sys if __name__ == "__main__": n, m = map(lambda x: int(x), input().split()) coins = list(map(lambda x: int(x), input().split())) table = [sys.maxsize] * (n + 2) table[0] = 0 for i in range(n + 1): for coin in coins: if (i + coin <= n): table[i + coin] = min(table[i + coin], table[i] + 1) print(table[n])
N,M=list(map(int,input().split())) C=list(map(int,input().split())) dp=[0]+[50001 for _ in range(N)] for i in range(M): for j in range(C[i],N+1): if C[i] > N: break elif dp[j-C[i]] != 50001: dp[j] = min(dp[j],dp[j-C[i]] + 1) print(dp[N])
1
143,208,558,528
null
28
28
s = int(input()) t = h = 0 for _ in range(s): tc, hc = input().split() if tc == hc: t += 1 h += 1 elif tc > hc : t += 3 else: h += 3 print(t, h)
n,m=map(int,input().split()) lst=list(map(int,input().split())) if n<sum(lst) : print(-1) else : print(n-sum(lst))
0
null
16,984,523,116,810
67
168
#ABC168-B k=int(input()) s=str(input()) if len(s)>k: print(s[:k]+'...') else: print(s)
n = int(input()) ac = 0 wa = 0 tle = 0 re = 0 for i in range(n): x = input() if (x == "AC"): ac = ac + 1 elif (x == "WA"): wa = wa + 1 elif (x == "TLE"): tle = tle + 1 else: re = re + 1 print("AC", "x", ac) print("WA", "x", wa) print("TLE", "x", tle) print("RE", "x", re)
0
null
14,203,842,140,410
143
109
from collections import deque import sys def input(): return sys.stdin.readline().strip() q = deque(input()) Q = int(input()) flipped = False for _ in range(Q): q_t, *q_b = input().split() if q_t == "1": flipped = not flipped else: F, C = q_b if (F == "2" and not flipped) or (F == "1" and flipped): q.append(C) else: q.appendleft(C) q = list(q) if flipped: print("".join(q[::-1])) else: print("".join(q))
#!/usr/bin/env python3 #import #import math #import numpy as np s = input() q = int(input()) inv = False fro = "" end = "" for _ in range(q): query = list(map(str, input().split())) if query[0] == "1": inv = not inv else: t = int(query[1]) instr = query[2] if not inv: if t == 1: fro = instr + fro else: end = end + instr else: if t == 1: end = end + instr[::-1] else: fro = instr[::-1] + fro ans = fro + s + end if not inv: print(ans) else: print(ans[::-1])
1
57,609,179,476,992
null
204
204
from collections import defaultdict from math import gcd N = int(input()) A = list(map(int, input().split())) A_set = set(A) num = 10 ** 6 primes = [0] * (num + 1) primes[0] = 1 primes[1] = 1 for i in range(2, num + 1): if primes[i] != 0: continue cnt = 1 while i * cnt <= num: primes[i * cnt] = i cnt += 1 def func(n): res_dic = defaultdict(int) while n > 1: x = primes[n] res_dic[x] += 1 n //= x return res_dic pairwise = True cnt_dic = defaultdict(int) for a in A: dic = func(a) for k in dic.keys(): cnt_dic[k] += 1 if cnt_dic[k] > 1: pairwise = False break g = A[0] for a in A[1:]: g = gcd(g, a) if pairwise: print('pairwise coprime') elif g == 1: print('setwise coprime') else: print('not coprime')
import bisect, collections, copy, heapq, itertools, math, string import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) n = I() M = 1046527 NIL = -1 H = [None] * M com = [] ch = [] for i in range(n): com_, ch_ = input().split() com.append(com_) ch.append(ch_) table = str.maketrans({ 'A':'1', 'C':'2', 'G':'3', 'T':'4', }) def getChar(ch): return int(ch.translate(table)) def h1(key): return key % M def h2(key): return 1 + (key % (M - 1)) def insert(ch): key = getChar(ch) i = 0 while True: h = (h1(key) + i * h2(key)) % M if H[h] is None: H[h] = ch break else: i += 1 def find(ch): key = getChar(ch) i = 0 while True: h = (h1(key) + i * h2(key)) % M if H[h] == ch: return 1 elif H[h] is None: return 0 else: i += 1 for i in range(n): if com[i][0] == 'i': insert(ch[i]) else: if find(ch[i]): print('yes') else: print('no')
0
null
2,082,984,488,960
85
23
import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # 二分探索、浮き沈みの沈みに注意 N, K = lr() A = np.array(lr()); A.sort() F = np.array(lr()); F.sort(); F = F[::-1] def check(x): cost = np.maximum(0, A - (x // F)).sum() return cost <= K ok = 10 ** 15; ng = -1 while abs(ng-ok) > 1: mid = (ok+ng) // 2 if check(mid): ok = mid else: ng = mid print(ok)
import sys def print_arr(arr): for i in range(len(arr)): sys.stdout.write(str(arr[i])) if i != len(arr) - 1: sys.stdout.write(' ') print() def insertion_sort(arr, g): n = len(arr) cnt = 0 for i in range(n): key = arr[i] j = i - g while j >= 0 and arr[j] > key: arr[j + g] = arr[j] j -= g cnt += 1 arr[j + g] = key return cnt def shell_sort(arr, G): cnt = 0 for i in range(len(G)): cnt += insertion_sort(arr, G[i]) return cnt def get_gaps(n): lst = [] v = 1 cnt = 1 while v <= n: lst.append(v) v += 3**cnt cnt += 1 if len(lst) == 0: lst.append(1) return list(reversed(lst)) n = int(input()) arr = [None] * n for i in range(n): arr[i] = int(input()) G = get_gaps(n) cnt = shell_sort(arr, G) print(len(G)) print_arr(G) print(cnt) for i in range(n): print(arr[i])
0
null
82,051,550,430,172
290
17
s = input() if s in ['hi','hihi','hihihi','hihihihi','hihihihihi']: print('Yes') else: print('No')
n = int(input()) data = [input().split() for i in range(n)] for i in range(n - 2): if int(data[i][0]) == int(data[i][1]) and int(data[i + 1][0]) == int(data[i+1][1]) and int(data[i+2][0]) == int(data[i+2][1]): print('Yes') break else: print('No')
0
null
27,967,082,768,768
199
72
#!/usr/bin/env python3 def main(): n, k = map(int, input().split()) r, s, p = map(int, input().split()) t = input() c = "" ans = 0 for i in range(n): if t[i] == "r": if i >= k and c[i-k] == 'p': c += 'x' else: c += "p" ans += p elif t[i] == "s": if i >= k and c[i-k] == 'r': c += 'x' else: c += "r" ans += r else: if i >= k and c[i-k] == 's': c += 'x' else: c += "s" ans += s print(ans) if __name__ == "__main__": main()
from collections import deque H, W = map(int, input().split()) L = [str(input()) for _ in range(H)] ans = 0 for h in range(H): for w in range(W): if L[h][w] == '#': continue else: flag = [[-1] * W for _ in range(H)] depth = [[0] * W for _ in range(H)] flag[h][w] = 0 q = deque([(h, w)]) while q: i, j = q.popleft() d = depth[i][j] if i != H - 1: if L[i+1][j] == '.' and flag[i+1][j] < 0: flag[i+1][j] = 0 depth[i+1][j] = d + 1 q.append((i+1, j)) if i != 0: if L[i-1][j] == '.' and flag[i-1][j] < 0: flag[i-1][j] = 0 depth[i-1][j] = d + 1 q.append((i-1, j)) if j != W - 1: if L[i][j+1] == '.' and flag[i][j+1] < 0: flag[i][j+1] = 0 depth[i][j+1] = d + 1 q.append((i, j+1)) if j != 0: if L[i][j-1] == '.' and flag[i][j-1] < 0: flag[i][j-1] = 0 depth[i][j-1] = d + 1 q.append((i, j-1)) ans = max(ans, d) print(ans)
0
null
100,186,051,594,710
251
241
def main(): h, n = list(map(int, input().split())) A, B = [], [] for _ in range(n): a, b = list(map(int, input().split())) A.append(a) B.append(b) mx = max(A) INF = float('inf') dp = [INF] * (h + mx + 1) dp[0] = 0 for i in range(1, h + mx + 1): for a, b in zip(A, B): if i - a < 0: dp[i] = min(dp[i], b) else: dp[i] = min(dp[i], dp[i - a] + b) print(min(dp[h:h + mx + 1])) if __name__ == '__main__': main()
h,n=map(int,input().split()) inf=100000000000 dp=[inf]*(h+1) dp[h]=0 for i in range(n): a,b=map(int,input().split()) for j in range(h,-1,-1): dp[max(j-a,0)]=min(dp[max(j-a,0)],dp[j]+b) print(dp[0])
1
81,390,454,235,052
null
229
229
N = int(input()) A = list(map(int, input().split())) # <- note that this has (N - 1) elements #print(A) A_0 = [x - 1 for x in A] #print(A_0) ans = [0] * N # <- represents number of immediate subordinates of each person for i in range(0, N - 1): ans[A_0[i]] += 1 for i in range(0, N): print(ans[i])
n = int(input()) s = str(input()) count = 0 if n % 3 == 1 or n % 3 == 0: for i in range(n-1): if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C': count += 1 elif n % 3 == 2: for i in range(n-2): if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C': count += 1 print(count)
0
null
65,970,883,167,146
169
245
n = int(input()) g = [[] for _ in range(n)] for i in range(n): a = int(input()) for _ in range(a): x,y = map(int,input().split()) g[i].append((x-1,y)) ans = 0 for bit in range(1<<n): f = True for i in range(n): if bit&(1<<i) and f: for x,y in g[i]: if y ==1 and bit&(1<<x): continue elif y ==0 and bit&(1<<x)==0: continue else: f = False break if f: ans = max(ans,bin(bit).count('1')) print(ans)
n=int(input()) a=[] l=[] for i in range(n): A=int(input()) L=[list(map(int,input().split())) for _ in range(A)] a.append(A) l.append(L) ans=0 for i in range(2**n): b=[0]*n for j in range(n): if (i>>j)&1: b[j]=1 for k in range(n): for h in range(a[k]): hito=l[k][h][0]-1 singi=l[k][h][1] if b[k]==1 and b[hito]!=singi: break else: continue break else: ans=max(ans,sum(b)) print(ans)
1
121,360,172,868,608
null
262
262
cnt = int(input()) chain = 0 first = 0 second = 0 for i in range(cnt): nList = list(map(int, input().split())) first = nList.pop() second = nList.pop() if first == second: chain = chain + 1 if chain >= 3: break else: chain = 0 if chain >= 3: print("Yes") else: print("No")
N=int(input()) A=[] for i in range(N): D=list(map(int,input().split())) A.append(D) for i in range(N-2): if A[i][0]==A[i][1] and A[i+1][0]==A[i+1][1] and A[i+2][0]==A[i+2][1]: print('Yes') break else: print('No')
1
2,522,575,408,122
null
72
72
print("YNeos"["".join(input().split("hi"))!=""::2])
from sys import stdin input = stdin.readline def solve(): N = int(input()) res = [] while True: N -= 1 N,r = divmod(N,26) res.append(chr(ord('a')+r)) if N == 0: break print(''.join(reversed(res))) if __name__ == '__main__': solve()
0
null
32,471,650,622,020
199
121
N=int(input()) A=map(int, input().split()) P=1000000007 ans = 1 cnt = [3 if i == 0 else 0 for i in range(N + 1)] for a in A: ans=ans*cnt[a]%P if ans==0: break cnt[a]-=1 cnt[a+1]+=1 print(ans)
N = int(input()) A = map(int, input().split()) B = [3 if i == 0 else 0 for i in range(N + 1)] MOD = 1000000007 ans = 1 for a in A: ans = ans * B[a] % MOD if ans == 0: break else: B[a] -= 1 B[a + 1] += 1 print(ans)
1
130,167,463,638,698
null
268
268
import bisect N=int(input()) S=list(str(input())) def ci(x): return "abcdefghijklmnopqrstuvwxyz".find(x) d=[[] for _ in range(26)] for i,s in enumerate(S): d[ci(s)].append(i) for i in range(int(input())): t,x,y=input().split() if t=="1": x=int(x)-1 if S[x]!=y: l=bisect.bisect_left(d[ci(S[x])],x) d[ci(S[x])].pop(l) bisect.insort(d[ci(y)],x) S[x]=y else: x,y=int(x)-1,int(y)-1 c=0 for j in range(26): l=bisect.bisect_left(d[j],x) if l<len(d[j]) and d[j][l] <= y: c += 1 print(c)
SIZE = 2**20 # 2**20 > N=500000 class SegmentTree: def __init__(self, size): self.size = size self.seg = [0] * (2 * size) def update(self, pos, ch): # update leaf i = self.size + pos - 1 self.seg[i] = 1 << (ord(ch)-ord('a')) # update tree while i > 0: i = (i - 1) // 2 self.seg[i] = self.seg[i*2+1] | self.seg[i*2+2] def _query(self, a, b, k, left, right): if right<a or b<left: return 0 if a<=left and right<=b: return self.seg[k] vl = self._query(a,b,k*2+1, left, (left+right)//2) vr = self._query(a,b,k*2+2, (left+right)//2+1, right) return vl | vr def query(self, a, b): return self._query(a,b,0,0,self.size-1) def resolve(): N = int(input()) S = input().strip() Q = int(input()) table = [[] for _ in range(26)] sg = SegmentTree(SIZE) for i,ch in enumerate(S): sg.update(i, ch) for i in range(Q): query = input().strip().split() if query[0] == '1': pos = int(query[1])-1 sg.update(pos, query[2]) else: left = int(query[1])-1 right = int(query[2])-1 bits = sg.query(left, right) count = 0 for j in range(26): count += (bits>>j) & 1 print(count) resolve()
1
62,648,863,978,238
null
210
210
print((int(input())+1)//2)
x = int(input()) print(x//2+x%2)
1
58,861,596,506,328
null
206
206
s = input() n = len(s) left = [0 for _ in range(n+1)] right = [0 for _ in range(n+1)] tmp = 0 for i in range(n): if s[i] == '<': tmp += 1 else: tmp = 0 left[i+1] = tmp tmp = 0 for i in range(n-1, -1, -1): if s[i] == '>': tmp += 1 else: tmp = 0 right[i] = tmp ans = 0 for i in range(n+1): ans += max(right[i], left[i]) print(ans)
#16D8101014F 久留米 竜之介 Kurume Ryunosuke Python All = 0 q = [] Queue = [] tmp,time = map(int,input().split()) for i in range(tmp): p,zi =input().split() q.append([p,int(zi)]) while len(q) > 0: if q[0][1]<= time: All+=q[0][1] v=q.pop(0) Queue.append([v[0],All]) else: All+=time q[0][1]-=time last=q.pop(0) q.append(last) for i in range(len(Queue)): print("{0} {1}".format(Queue[i][0],Queue[i][1]))
0
null
77,943,337,827,900
285
19
a,b = map(int,input().split()) ans = 0 if a == 1 or b == 1: print(1) elif a*b % 2 == 0: print(int(a*b/2)) else: print(int((a*b-1)/2 + 1))
n=int(input()) minv=int(input()) maxv=-float('inf') for _ in range(n-1): tmp=int(input()) maxv=max(maxv,tmp-minv) minv=min(minv,tmp) print(maxv)
0
null
25,382,066,957,380
196
13
# author: Taichicchi # created: 20.09.2020 11:13:28 import sys from math import factorial from scipy.special import comb MOD = 10 ** 9 + 7 S = int(input()) m = S // 3 cnt = 0 for n in range(1, m + 1): cnt += int(comb(S - 3 * n + 1, n - 1, exact=True, repetition=True)) % MOD cnt %= MOD print(cnt)
N=int(input()) DP=[-1]*10000 DP[0]=1 DP[1]=0 DP[2]=0 mod=10**9+7 for i in range(3,N+1): DP[i]=(DP[i-3]+DP[i-1])%mod print(DP[N])
1
3,332,649,811,900
null
79
79
i=input() print(int(i)**2)
def main(): print(int(input())**2) if __name__ == "__main__": main()
1
144,872,459,433,680
null
278
278
h,w,k= map(int, input().split()) s = [[int(i) for i in input()] for i in range(h)] for i in range(h): for j in range(1,w): s[i][j]+=s[i][j-1] for i in range(w): for j in range(1,h): s[j][i]+=s[j-1][i] # 1行目、一列目をゼロにする。 s=[[0]*w]+s for i in range(h+1): s[i]=[0]+s[i] ans=float('inf') #bit 全探索 for i in range(2**(h-1)): line=[] for j in range(h-1): if (i>>j)&1: line.append(j+1) cnt=len(line) line=[0]+line+[h] x=0 flag=True for k1 in range(1,w+1): v=0 for l in range(len(line)-1): # どう分割してもダメな奴に✖︎のフラグ立てる if s[line[l+1]][k1]-s[line[l+1]][k1-1]-s[line[l]][k1]>k: flag=False v=max(s[line[l+1]][k1]-s[line[l+1]][x]-s[line[l]][k1]+s[line[l]][x],v) if v>k: cnt+=1 x=k1-1 if flag: ans=min(cnt,ans) print(ans)
h,w,k=map(int,input().split()) ans=10**9 choco=[list(input()) for i in range(h)] sumL=[[0 for i in range(w+1)] for j in range(h+1)] for i in range(h): for j in range(w): sumL[i][j]=sumL[i-1][j]+sumL[i][j-1]-sumL[i-1][j-1]+int(choco[i][j]) for stat in range(2**(h-1)): cnt=0;previous=-1 flg=0 cut=format(stat,"b").zfill(h-1) cutl=[] for hi in range(h-1): if cut[hi]=="1": cutl.append(hi) cnt+=1 cutl.append(h-1) cutl.append(-1) for yoko in range(w): for seg in range(len(cutl)): if sumL[cutl[seg]][yoko]-sumL[cutl[seg]][previous]-sumL[cutl[seg-1]][yoko]+sumL[cutl[seg-1]][previous]>k and yoko-previous<=1:flg=1 elif sumL[cutl[seg]][yoko]-sumL[cutl[seg]][previous]-sumL[cutl[seg-1]][yoko]+sumL[cutl[seg-1]][previous]>k:previous=yoko-1;cnt+=1 if not flg and cnt < ans:ans=cnt print(ans)
1
48,436,092,799,392
null
193
193
n=int(input()) s,t=input().split() ans="" for i,j in zip(list(s),list(t)):ans+=i+j print(ans)
MOD = int(1e9+7) N = int(input()) # all posible list Na = pow(10, N, MOD) # number of list without 0 N0 = pow(9, N, MOD) # number of list without both 0 and 9 N09 = pow(8, N, MOD) M = Na - 2*N0 + N09 print(M%MOD)
0
null
57,375,373,114,164
255
78
T = list(input()) N = len(T) count = 0 for i in range(N): if T[i] == '?': T[i] = 'D' if (i < N - 1) and T[i] == 'P' and T[i + 1] == 'D': count += 1 elif T[i] == 'D': count += 1 #print(count) ans = ''.join(T) print(ans)
import math N=int(input()) sum=0 for i in range(1,N+1): for j in range(1,N+1): x=math.gcd(i,j) for k in range(1,N+1): y=math.gcd(x,k) sum = sum+y print(sum)
0
null
26,791,505,150,560
140
174
l = int(input()) print((l/3)**3)
n = int(input()) a = list(map(int,input().split())) largest = max(a) b = [True] * (largest+1) dict = {} ans = 0 for num in a: if num in dict.keys(): b[num] = False else: dict[num] = 1 y = num * 2 while(y <= largest): b[y] = False y += num for num in a: if b[num] == True: ans += 1 print(ans)
0
null
30,765,002,386,440
191
129
n = int(input()) string = input() ans = 0 for i in range(0, n-2): if string[i] == "A" and string[i+1] == "B" and string[i+2] == "C": ans += 1 print(ans)
def countABC(n, s): return s.count("ABC") def main(): n = int(input()) s = str(input()) print(countABC(n, s)) if __name__ == '__main__': main()
1
99,303,311,040,360
null
245
245
N = int(input()) cnt = 0 for _ in range(N): d1, d2 = map(int, input().split()) if d1 == d2: cnt += 1 else: cnt = 0 if cnt == 3: print("Yes") break else: print("No")
N=int(input()) f=0 for i in range(N): a,b=map(int,input().split()) if a==b: f+=1 else: f=0 if f==3: print('Yes') break else: print('No')
1
2,502,323,936,332
null
72
72
from collections import deque h,w=map(int,input().split()) s=[input() for _ in range(h)] #マップ vi=[ [-1 for _ in range(w)] for _ in range(h)]#visit st=deque() d=[[0,1],[-1,0],[1,0],[0,-1]] mx=0 for i in range(h): for j in range(w): vi=[ [-1 for _ in range(w)] for _ in range(h)] st.append([i,j,0]) while st: h1,w1,k=st.popleft() if 0<=h1<h and 0<=w1<w and vi[h1][w1]==-1 and s[h1][w1]==".": vi[h1][w1]=k for m in d: st.append([h1+m[0],w1+m[1],k+1]) for m in vi: mx=max(mx,max(m)) print(mx)
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) diff1 = (A1 - B1) * T1 diff2 = (A2 - B2) * T2 if diff1 > 0: diff1, diff2 = -1 * diff1, -1 * diff2 if diff1 + diff2 < 0: print(0) elif diff1 + diff2 == 0: print('infinity') else: q, r = divmod(-diff1, diff1 + diff2) print(2*q + (1 if r != 0 else 0))
0
null
113,221,568,658,450
241
269
a, b = sorted(map(int, input().split())) c = str(a) print(c*b)
ri = lambda S: [int(v) for v in S.split()] def rii(): return ri(input()) a, b = rii() print(min(str(a) * b, str(b) * a))
1
84,074,249,667,938
null
232
232
n=int(input()) res=0 for i in range(1,n+1): if int(i*1.08)==n: res=i if res != 0: print(res) else: print(":(")
def main(): def inputs(): li = [] count = 0 try: while count < 200: li.append(input()) count += 1 except EOFError: return li return li li = inputs() for x in li: a = x.split(" ") result = len(str(int(a[0]) + int(a[1]))) print(result) return None if __name__ == '__main__': main()
0
null
63,149,477,663,240
265
3
X,Y=map(int,input().split()) print("Yes" if Y%2==0 and 2*X<=Y<=4*X else "No")
X,Y = map(int, input().split()) if X * 2 > Y: print('No') elif X * 4 < Y: print('No') else: for i in range(0,X+1): if Y == (X * 2) + (i * 2): print('Yes') break else: print('No')
1
13,873,470,445,226
null
127
127
from collections import deque n, m = map(int, input().split()) name = ['']*n time = ['']*n for i in range(n): name[i], time[i] = input().split() time = list(map(int, time)) Q = deque([i for i in range(n)]) t = 0 while Q!=deque([]): q = Q.popleft() if time[q]<=m: t += time[q] print(name[q] + ' ' + str(t)) else: t += m time[q] -= m Q.append(q)
X = int(input()) x500 = X//500 amari = X - x500 * 500 x5 = amari // 5 print(x500*1000+x5*5)
0
null
21,394,201,530,490
19
185