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 def main(): a, b, ang_ab = [float(x) for x in input().split()] rad_ab = (ang_ab/180)*math.pi c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad_ab)) h = b*math.sin(rad_ab) s = (a*h)/2 l = a+b+c print("{:f} {:f} {:f}".format(s, l, h)) if __name__ == '__main__': main()
import math a, b, C=map(int, input().split()) print("{0:.5f}".format((1/2)*a*b*math.sin(C*math.pi/180.0))) print("{0:.5f}".format(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C*math.pi/180)))) print("{0:.5f}".format(b*math.sin(C*math.pi/180.0)))
1
172,120,832,390
null
30
30
from math import ceil N = int(input()) X = ceil(N / 1.08) if int(X * 1.08) == N: print(int(X)) else: print(':(')
# coding:utf-8 while True: m,f,r = map(int, raw_input().split()) if m == -1 and f == -1 and r == -1: break if m == -1 or f == -1: print 'F' elif m + f >= 80: print 'A' elif m + f >= 65: print 'B' elif m + f >= 50: print 'C' elif m + f >= 30: if r >= 50: print 'C' else: print 'D' else: print 'F'
0
null
63,857,748,257,600
265
57
X, K, D = map(int, input().split()) N = abs(X) // D O = abs(X) - N * D if O <= (D - O): pass else: N += 1 O = D - O if N >= K: print(abs(X) - K * D) else: if (K - N) % 2 == 0: print (O) else: print(D - O)
x, k, d = [int(i) for i in input().split()] if x < 0: x = -x l = min(k, x // d) k -= l x -= l * d if k % 2 == 0: print(x) else: print(d - x)
1
5,282,468,656,118
null
92
92
def main(): N = int(input()) A = list(map(int, input().split())) for i in range(N): if A[i] % 2 == 0 and (A[i] % 3 != 0 and A[i] % 5 != 0): return "DENIED" return "APPROVED" if __name__ == '__main__': print(main())
N=int(input()) A=list(map(int, input().split())) flag = 1 for i in range(len(A)): if A[i] % 2 == 0: if A[i] % 3 != 0 and A[i] % 5 != 0: flag = 0 break print(['DENIED', 'APPROVED'][flag])
1
69,155,283,071,310
null
217
217
n=int(input())-1;print(sum(n//-~i for i in range(n)))
N = int(input()) if N == 1: print(0) exit() if N == 2: print(2) exit() # N >= 3 # 全事象 all_pattern = 10 ** N # 0も9もない pattern_a = 8 ** N # 0あるが9ない pattern_b = 9 ** N - 8 ** N ans = all_pattern - pattern_a - pattern_b * 2 ans = ans % (10**9 + 7) print(ans)
0
null
2,886,609,048,782
73
78
a,b=map(int,input().split()) def gcd(x, y): while y: x, y = y, x % y return x l=gcd(a,b) print(int(a*b/l))
x,k,d = list(map(int, input().split())) x = abs(x) a,b = divmod(x, d) a = min(a, k) x -= a * d #print('a=',a) #print('x=',x) #print('ka=',k-a) x -= d * ((k-a) % 2) print(abs(x))
0
null
59,099,063,706,452
256
92
n, k = map(int, input().split()) ans = 0 a = [] for _ in range(n): a.append(0) for i in range(k): d = int(input()) treat = list(map(int, input().split())) for snuke in treat: a[snuke-1] += 1 for j in range(n): if a[j] == 0: ans += 1 print(ans)
x, k, d = map(int, input().split()) x = abs(x) kk = x // d amari = x % d if kk >= k: ans = (kk - k) * d + amari elif (k - kk) % 2 == 1: ans = abs(amari - d) else: ans = amari print(ans)
0
null
14,958,022,824,268
154
92
n=int(input()) A=[] for i in range(n): a=str(input()) A.append(a) import collections c = collections.Counter(A) ma= c.most_common()[0][1] C=[i[0] for i in c.items() if i[1] >=ma ] C.sort(reverse=False) for j in range(len(C)): print(C[j])
import math n = int(input()) xv = [int(xi) for xi in input().split()] yv = [int(yi) for yi in input().split()] print(sum([abs(xi-yi) for (xi, yi) in zip(xv, yv)])) print(math.sqrt(sum([pow(abs(xi-yi), 2) for (xi, yi) in zip(xv, yv)]))) print(math.pow(sum([pow(abs(xi-yi), 3) for (xi, yi) in zip(xv, yv)]), 1/3)) print(max([abs(xi-yi) for (xi, yi) in zip(xv, yv)]))
0
null
35,179,958,880,040
218
32
from math import sin,cos,pi,sqrt a,b,d=map(float,input().split()) S=a*b*sin(d*pi/180)/2 c=sqrt(a**2+b**2-2*a*b*cos(d*pi/180)) h=2*S/a print(S) print(a+b+c) print(h)
import sys input = sys.stdin.readline def main(): N = int(input()) if N % 2 == 0: ans = (N - 2) // 2 else: ans = (N - 1) // 2 print(ans) if __name__ == "__main__": main()
0
null
76,732,307,786,320
30
283
v = 100000 for _ in [0]*int(input()): v *= 1.05 v += 1000 * (v%1000 > 0) v -= v%1000 print(int(v))
import math def roundup1000(num): return math.ceil(num / 1000) * 1000 debt = 100000 for _ in range(int(input())): debt = roundup1000(debt * 1.05) print(debt)
1
1,298,008,712
null
6
6
def main(): s = int(input()) if s < 3: print(0) else: total = [0]*(s+1) total[3] = 1 mod = 10**9+7 for i in range(4, s+1): total[i] = (total[i-3] + 1) + total[i-1] total[i] %= mod print((total[s-3]+1)%mod) if __name__ == "__main__": main()
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 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 LIST() : return list(MAP()) n = INT() a = LIST() ans = 1 r = 0 g = 0 b = 0 for x in a: ans = ans * ( (r == x) + (g == x) + (b == x) ) % (10**9+7) if r == x: r += 1 elif g == x: g += 1 else: b += 1 print(ans)
0
null
66,817,785,759,580
79
268
n,k,c = map(int,input().split()) s = list(input()) L = [] R = [] i = -1 j = n for ki in range(k): while i < n: i += 1 if s[i] == 'o': L += [i] i += c break for ki in range(k): while 0 <= j: j -= 1 if s[j] == 'o': R += [j] j -= c break for i in range(k): if L[i] == R[-i-1] : print(L[i]+1)
n,k,c=map(int,input().split()) s=input() l=[] r=[] i=0 j=0 while len(l)<k and i<n: if s[i]=='o': l.append(i+1) i+=c+1 else: i+=1 while len(r)<k and j<n: if s[-j-1]=='o': r.append(n-j) j+=c+1 else: j+=1 for n in range(k): if l[n]==r[-n-1]: print(l[n])
1
40,769,278,612,868
null
182
182
def coin(larger=False, single=False): """ ナップサックに入れる重さが W 丁度になる時の価値の最小値 :param larger: False = (重さ = W)の時の最小価値 True = (重さ =< W)の時の最小価値 :param single: False = 重複あり dp[weight <= W+1] = 重さを固定した時の最小価値 dp[W+1] = 重さがWより大きい時の最小価値 """ W2 = W + 1 # dp[W+1] に W より大きい時の全ての場合の情報を持たせる dp_max = float("inf") # 総和価値の最大値 dp = [dp_max] * (W2 + 1) dp[0] = 0 # 重さ 0 の時は価値 0 for item in range(N): if single: S = range(W2, weight_list[item] - 1, -1) else: S = range(W2) for weight in S: dp[min2(weight + weight_list[item], W2)] = min2(dp[min2(weight + weight_list[item], W2)], dp[weight] + cost_list[item]) if larger: return min(dp[w] for w in range(W, W2+1)) else: return dp[W] ####################################################################################################### import sys input = sys.stdin.readline def max2(x, y): return x if x > y else y def min2(x, y): return x if x < y else y W, N = map(int, input().split()) # N: 品物の種類 W: 重量制限 cost_list = [] weight_list = [] for _ in range(N): """ cost と weight が逆転して入力されている場合有り """ weight, cost = map(int, input().split()) cost_list.append(cost) weight_list.append(weight) print(coin(larger=True, single=False))
H, N = map(int,input().split()) X = [list(map(int, input().split())) for i in range(N)] X = sorted(X, key = lambda x:x[0]) DP = [float("inf")]*(H+X[-1][0]+X[-1][0]) DP[X[-1][0]-1] = 0 for i in range(X[-1][0], H+2*X[-1][0]): min = float("inf") for j in range(N): if min > DP[i-X[j][0]]+X[j][1]: min = DP[i-X[j][0]]+X[j][1] DP[i] = min kouho = DP[H+X[-1][0]-1] for i in range(X[-1][0]): if kouho > DP[H+X[-1][0]+i]: kouho = DP[H+X[-1][0]+i] print(kouho)
1
80,746,071,685,808
null
229
229
n = input() dictInProb = set() for i in range(int(n)): cmdAndStr = list(input().split()) if cmdAndStr[0] == "insert": dictInProb.add(cmdAndStr[1]) elif cmdAndStr[0] == "find": if cmdAndStr[1] in dictInProb: print("yes") else: print("no") else: pass
from collections import deque, defaultdict def main(): N, X, Y = map(int, input().split()) g = [[] for _ in range(N)] for i in range(N-1): g[i].append(i+1) g[i+1].append(i) g[X-1].append(Y-1) g[Y-1].append(X-1) ans = defaultdict(int) for i in range(N): q = deque() q.append(i) visit_time = [0 for _ in range(N)] while len(q): v = q.popleft() time = visit_time[v] for j in g[v]: if visit_time[j] == 0 and j != i: q.append(j) visit_time[j] = time + 1 else: visit_time[j] = min(time + 1, visit_time[j]) for v in visit_time: ans[v] += 1 for i in range(1, N): print(ans[i] // 2) if __name__ == '__main__': main()
0
null
22,254,922,542,492
23
187
import sys input = sys.stdin.readline n, s = map(int,input().split()) A = list(map(int,input().split())) mod = 998244353 l = 3050 M = [1] # i!のmod m = 1 for i in range(1, l): m = (m * i) % mod M.append(m) def pow(x, y, mod): # x**y の mod を返す関数 ans = 1 while y > 0: if y % 2 == 1: ans = (ans * x) % mod x = (x**2) % mod y //= 2 return ans def inv(x, mod): # x の mod での逆元を返す関数 return pow(x, mod-2, mod) D = [0] * 3050 M2 = [1] M2I = [0] * l for i in range(l-1): M2.append((M2[-1] * 2) % mod) for i in range(l): M2I[i] = inv(M2[i], mod) i2 = inv(2,mod) D[0] = M2[n] for i in range(n): for j in range(l-1,-1,-1): if j - A[i] >= 0: D[j] = (D[j] + D[j-A[i]] * i2) % mod # print(D[:10]) print(D[s])
n, x, m = (int(x) for x in input().split()) dic = {} count = 1 dic[x]=0 ans = [x] bool = True while (count < n): x = pow(x, 2, m) if x not in dic: dic[x] = count ans.append(x) else: roop = ans[dic[x]:count] ans = sum(ans[:dic[x]]) roop_count = (n-dic[x])//len(roop) roop_hasuu = (n-dic[x])%len(roop) ans+=roop_count*sum(roop)+sum(roop[:roop_hasuu]) print(ans) bool = False count = pow(10, 13) count+=1 if bool: print(sum(ans))
0
null
10,295,546,120,220
138
75
N = int(input()) A = list(map(int, input().split())) A = sorted(A) MAX_A = 1000001 dp = [0]*MAX_A for i in A: if dp[i] == 0: for j in range(i, MAX_A,i): dp[j] += 1 else: dp[i] += 1 c = 0 for i in A: if dp[i] == 1: c += 1 print(c)
n = int(input()) A = list(map(int, input().split())) MAX_N = max(A)+ 1 cnt = [0] * MAX_N for a in A: for i in range(a, MAX_N, a): if cnt[i] <= 2: cnt[i] += 1 ans = 0 for a in A: if cnt[a] == 1: ans += 1 print(ans)
1
14,401,593,938,578
null
129
129
from collections import Counter N = int(input()) A = list(map(int,input().split())) C_A = Counter(A) S = 0 for ca in C_A: S += ca * C_A[ca] Q = int(input()) for q in range(Q): b, c = map(int,input().split()) S += (c - b) * C_A[b] C_A[c] += C_A[b] C_A[b] = 0 print(S)
N, M = map(int, input().split()) d = {} flag = True for i in range(M): s, c = map(int, input().split()) if s in d.keys() and d[s] != c: flag = False d[s] = c if M == 0: if N > 1: d[1] = 1 else: d[1] = 0 elif 1 not in d.keys(): d[1] = 1 elif N > 1 and d[1] == 0: flag = False if M != 0 and max(d.keys()) > N: flag = False if flag: res = 0 for s, c in d.items(): res += c * 10 ** (N - s) print(res) else: print("-1")
0
null
36,540,062,209,620
122
208
n = int(input()) ans = 0 deno = 10 if n % 2 == 1: pass else: while n//deno > 0: ans += n//deno deno *= 5 print(ans)
import math n = int(input()) # nが奇数ならば必ず0 if n % 2 == 1: print(0) else: s = 0 p = 0 while 10 * (5 ** p) <= n: s += n // (10 * (5 ** p)) p += 1 print(s)
1
116,380,105,527,558
null
258
258
n, d = map(int, input().split()) s = 0 for i in range(n): a, b = map(int, input().split()) if (a ** 2 + b ** 2) ** 0.5 <= d: s += 1 print(s)
a=int(input()) b=int(input()) z=1^2^3 print (z^a^b)
0
null
58,609,320,828,788
96
254
N = int(input()) S = input() l = [S[i:i+3] for i in range(0, len(S)-2)] print(l.count('ABC'))
MOD = 998244353 class mint: def __init__(self, x): if isinstance(x, int): self.x = x % MOD elif isinstance(x, mint): self.x = x.x else: self.x = int(x) % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __iadd__(self, other): self.x += other.x if isinstance(other, mint) else other self.x -= MOD if self.x >= MOD else 0 return self def __isub__(self, other): self.x += MOD-other.x if isinstance(other, mint) else MOD-other self.x -= MOD if self.x >= MOD else 0 return self def __imul__(self, other): self.x *= other.x if isinstance(other, mint) else other self.x %= MOD return self def __add__(self, other): return ( mint(self.x + other.x) if isinstance(other, mint) else mint(self.x + other) ) def __sub__(self, other): return ( mint(self.x - other.x) if isinstance(other, mint) else mint(self.x - other) ) def __mul__(self, other): return ( mint(self.x * other.x) if isinstance(other, mint) else mint(self.x * other) ) def __floordiv__(self, other): return ( mint( self.x * pow(other.x, MOD - 2, MOD) ) if isinstance(other, mint) else mint(self.x * pow(other, MOD - 2, MOD)) ) def __pow__(self, other): return ( mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else mint(pow(self.x, other, MOD)) ) __radd__ = __add__ def __rsub__(self, other): return ( mint(other.x - self.x) if isinstance(other, mint) else mint(other - self.x) ) __rmul__ = __mul__ def __rfloordiv__(self, other): return ( mint( other.x * pow(self.x, MOD - 2, MOD) ) if isinstance(other, mint) else mint(other * pow(self.x, MOD - 2, MOD)) ) def __rpow__(self, other): return ( mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else mint(pow(other, self.x, MOD)) ) n,s = map(int, input().split()) a = list(map(int, input().split())) import copy dp = [[0 for _ in range(s+1)] for _ in range(n+1)] dp[0][0]=pow(2,n,MOD) div=pow(2,MOD-2,MOD) for i in range(n): for j in range(s+1): dp[i+1][j]=dp[i][j] if j-a[i]>=0: dp[i+1][j]+=dp[i][j-a[i]]*div dp[i+1][j]%=MOD print(dp[n][s])
0
null
58,523,688,337,312
245
138
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb 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 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 LIST() : return list(MAP()) n = INT() x = [[0]*2 for i in range(n)] for i in range(n): x[i][0], x[i][1] = MAP() x.sort() tmp = -inf ans = n for i in range(n): if tmp > x[i][0] - x[i][1]: ans -= 1 tmp = min(tmp, x[i][0] + x[i][1]) else: tmp = x[i][0] + x[i][1] print(ans)
def solve(N, data): ret = N data.sort(key=lambda x: x[0] - x[1]) most_right = float("-inf") for idx, d in enumerate(data): l, r = d[0] - d[1], d[0] + d[1] if not idx: most_right = r continue if most_right <= l: most_right = r continue ret -= 1 most_right = min(r, most_right) return ret if __name__ == "__main__": N = int(input()) data = [] for _ in range(N): data.append(list(map(int, input().split()))) print(solve(N, data))
1
89,905,661,584,592
null
237
237
n = int(input()) ret = 0 for i in range(n+1): """ if i % 3 == 0 and i % 5 == 0: ret.append('FizzBuzz') elif i % 3 == 0: ret.append('Fizz') elif i % 5 == 0: ret.append('Buzz') else: """ if i % 3 != 0 and i % 5 != 0: ret += i print(ret)
N = int(input()) sum = 0 for i in range(1, N + 1): if not i % 3 == 0 and not i % 5 == 0: sum += i print(sum)
1
34,727,959,446,620
null
173
173
n = int(input()) n_l = list(map(int, input().split())) VORDER = 10 ** 18 ans = 1 if 0 in n_l: ans = 0 else: for i in n_l: ans = i * ans if ans > VORDER: ans = -1 break print(ans)
N=int(input()) A_list=sorted(list(map(int, input().split())), reverse=True) ans=1 for a in A_list: ans*=a if ans>1e+18: ans=-1 break if 0 in A_list: ans=0 print(ans)
1
16,329,844,651,652
null
134
134
import math while 1: try: a,b = map(int, input().split()) print(math.gcd(a,b), int(a*b/math.gcd(a,b))) except: break
import fractions lst = [] for i in range(200): try: lst.append(input()) except EOFError: break nums = [list(map(int, elem.split(' '))) for elem in lst] # gcd res_gcd = [fractions.gcd(num[0], num[1]) for num in nums] # lcm res_lcm = [nums[i][0] * nums[i][1] // res_gcd[i] for i in range(len(nums))] for (a, b) in zip(res_gcd, res_lcm): print('{} {}'.format(a, b))
1
601,388,130
null
5
5
for i in range(1, 10): for j in range(1, 10): k = i * j print(str(i)+'x'+str(j)+'='+str(k))
for i in range(1, 10): for j in range(1, 10): print("{}x{}={}".format(i, j, i*j))
1
939,800
null
1
1
from collections import Counter n=int(input()) a=list(map(int, input().split())) cnt=Counter(a) for k in cnt.values(): if k != 1: print('NO') break else: print('YES')
n, k = (int(i) for i in input().split()) used = [0 for i in range(n)] for i in range(k): val = int(input()) a = [int(j) for j in input().split()] for aa in a: used[aa - 1] = 1 cnt = 0 for i in used: cnt += i == 0 print(cnt)
0
null
49,372,369,260,298
222
154
n=input() a=(int(n)+1)//2 print(a)
import math def gcd(a,b): if a<b: a,b=b,a c=a%b if c==0: return b else: return gcd(b,c) S=[ int(x) for x in input().split()] print(gcd(S[0],S[1]))
0
null
29,619,845,566,696
206
11
import math r=float(input()) print('%f %f' %(math.pi*r*r, 2*math.pi*r))
# import sys # sys.setrecursionlimit(10 ** 6) # import bisect from collections import deque # from decorator import stop_watch # # # @stop_watch def solve(N, ABs): tree_top = [[] for _ in range(N + 1)] for i in range(N - 1): tree_top[ABs[i][0]].append(i) tree_top[ABs[i][1]].append(i) max_color = 0 for tt in tree_top: max_color = max(max_color, len(tt)) ans = [0 for _ in range(N - 1)] for tt in tree_top: colored = [] for i in tt: if ans[i] != 0: colored.append(ans[i]) colored.sort() now_color = 1 colored_point = 0 for i in tt: if ans[i] != 0: continue if colored_point < len(colored) \ and now_color == colored[colored_point]: now_color += 1 colored_point += 1 ans[i] = now_color now_color += 1 print(max_color) for a in ans: print(a) if __name__ == '__main__': # S = input() N = int(input()) # N, M = map(int, input().split()) # As = [int(i) for i in input().split()] # Bs = [int(i) for i in input().split()] ABs = [[int(i) for i in input().split()] for _ in range(N - 1)] solve(N, ABs)
0
null
68,570,131,927,400
46
272
K = int(input()) S = input() if len(S) > K: S_short = S[:K] print("{}...".format(S_short)) else: print(S)
n = int(input()) for i in range(50001): if int(i * 1.08) == n: print(i) exit() print(":(")
0
null
72,995,899,711,840
143
265
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys MAX_PRIME = 10**4 def prime_list(): sqrt_max = int(MAX_PRIME ** 0.5) primes = [True for i in range(MAX_PRIME+1)] primes[0] = primes[1] = False for p in range(sqrt_max): if primes[p]: for px in range(p*2, MAX_PRIME, p): primes[px] = False p_list = [i for i in range(MAX_PRIME) if primes[i]] return p_list def is_prime(n, prime_list): sqrt_n = int(n ** 0.5) for i in prime_list: if i > sqrt_n: break if n % i == 0: return False return True p_list = prime_list() n = int(sys.stdin.readline()) num_p = 0 for i in range(n): x = int(sys.stdin.readline()) if is_prime(x, p_list): num_p += 1 print(num_p)
import math n = int(input()) cnt = 0 for i in range(n): x = int(input()) if x == 2: cnt += 1 elif x <= 1\ or x % 2 == 0: continue else: j = 3 prime = "yes" while j <= math.sqrt(x): if x % j == 0: prime = "no" break else: j += 2 if prime == "yes": cnt += 1 print(cnt)
1
10,580,342,524
null
12
12
n, k = map(int, input().split()) # n, k = (2*10**5, 10) ranges = [] for i in range(k): l, r = map(int, input().split()) # f = (2 * 10 ** 5) // k # l, r = (f * i, f*(i+1)) ranges.append((l, r)) mod = 998244353 counts = [0]*(n+1) sum_dp = [0]*(n+2) counts[0] = 1 sum_dp[1] = 1 for i in range(1, n+1): for r in ranges: left = max(0, i - r[1]) right = max(0, i - r[0] + 1) counts[i] += (sum_dp[right] - sum_dp[left]) counts[i] = counts[i] % mod sum_dp[i+1] = sum_dp[i] + counts[i] print(counts[n-1] % mod)
import itertools N, K = map(int, input().split()) num = [] for i in range(N+1): num.append(i) ans = 0 for i in range(K, N+2): min_i = (i-1)*i//2 max_i = (2*N-i+1)*i//2 ans += max_i - min_i + 1 print(ans%(10**9+7))
0
null
17,921,390,432,120
74
170
import queue import numpy as np import math n = int(input()) A = list(map(int, input().split())) A = np.array(A,np.int64) ans = 0 for i in range(60 + 1): a = (A >> i) & 1 count1 = np.count_nonzero(a) count0 = len(A) - count1 ans += count1*count0 * pow(2, i) ans%=1000000007 print(ans)
# coding: utf-8 s = list(input().rstrip()) ht = [] ponds=[] for i, ch in enumerate(s): if ch == "\\": ht.append(i) elif ch == "/": if ht: b = ht.pop() ap = i - b if not ponds: ponds.append([b, ap]) else: while ponds: p = ponds.pop() if p[0] > b: ap += p[1] else: ponds.append([p[0],p[1]]) break ponds.append([b,ap]) else: pass ans = "" area = 0 for point, ar in ponds: area += ar ans += " " ans += str(ar) print(area) print(str(len(ponds)) + ans)
0
null
61,523,139,104,160
263
21
for i in range(9): for j in range(9): print "%dx%d=%d" %(i+1,j+1, (i+1)*(j+1))
def multi(): for i in range(1, 10): for j in range(1, 10): print(str(i) + "x" + str(j) + "=" + str(i * j)) if __name__ == '__main__': multi()
1
106,050
null
1
1
i = input() a = int(i)//2 b = int(i)%2 print(a+b)
d = int(input()) if d % 2 == 0: print(d//2) else: print((d//2)+1)
1
59,056,738,290,718
null
206
206
c=1 while 1: n=input() if n:print'Case %d: %d'%(c,n) else:break c+=1
class itp1_3b: def out(self,i,x): print "Case "+str(i)+": "+str(x) if __name__=="__main__": run=itp1_3b() i=1 while(True): x=input() if x==0: break run.out(i,x) i+=1
1
497,246,337,408
null
42
42
from itertools import product h, w = map(int, input().split()) maze = [input() for _ in range(h)] def neighbors(ih, iw): for ih1, iw1 in ( (ih - 1, iw), (ih + 1, iw), (ih, iw - 1), (ih, iw + 1), ): if 0 <= ih1 < h and 0 <= iw1 < w and maze[ih1][iw1] == '.': yield (ih1, iw1) def len_maze(ih, iw): # BFS if maze[ih][iw] == '#': return 0 stepped = [[False] * w for _ in range(h)] q0 = [(ih, iw)] l = -1 while q0: q1 = set() for ih0, iw0 in q0: stepped[ih0][iw0] = True for ih1, iw1 in neighbors(ih0, iw0): if not stepped[ih1][iw1]: q1.add((ih1, iw1)) q0 = list(q1) l += 1 return l answer = max(len_maze(ih, iw) for ih, iw in product(range(h), range(w))) print(answer)
from collections import Counter class UnionFind: from collections import deque def __init__(self, v): self.v = v self._tree = list(range(v + 1)) def _root(self, a): queue = self.deque() while self._tree[a] != a: queue.append(a) a = self._tree[a] while queue: index = queue.popleft() self._tree[index] = a return a def union(self, a, b): root_a = self._root(a) root_b = self._root(b) self._tree[root_b] = root_a def find(self, a, b): return self._root(a) == self._root(b) N, M, K = map(int, input().split(' ')) n_friends = Counter() n_groups = Counter() uf = UnionFind(N) for _ in range(M): a, b = map(int, input().split(' ')) a -= 1 b -= 1 uf.union(a, b) n_friends[a] -= 1 n_friends[b] -= 1 for _ in range(K): c, d = map(int, input().split(' ')) c -= 1 d -= 1 if uf.find(c, d): n_friends[c] -= 1 n_friends[d] -= 1 for n in range(N): n_groups[uf._root(n)] += 1 print(*[n_friends[n] + n_groups[uf._root(n)] - 1 for n in range(N)])
0
null
78,392,031,862,532
241
209
n = int(input()) min_price = int(input()) max_diff = -1e9 for _ in range(n - 1): p = int(input()) max_diff = max(p - min_price, max_diff) min_price = min(p, min_price) print(max_diff)
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D sample_input = ''' 3 4 3 2 ''' give_sample_input = False if give_sample_input: sample_input_list = sample_input.split() def input(): return sample_input_list.pop(0) numOfData = int(input()) max_diff = None # minus infty min_val = None # plus infty prev_val = int(input()) for n in range(numOfData-1): val = int(input()) if min_val is None: min_val = prev_val else: min_val = min(prev_val, min_val) if max_diff is None: max_diff = val - min_val else: max_diff = max(val - min_val, max_diff) prev_val = val print(max_diff)
1
13,418,273,880
null
13
13
from bisect import bisect_left def main(): N = int(input()) L = sorted(list(map(int, input().split()))) ans = 0 for ia in range(N): for ib in range(ia+1, N-1): a = L[ia] b = L[ib] ic_end = bisect_left(L, a+b, lo=ib+1) ans += ic_end - (ib+1) print(ans) main()
import sys from bisect import bisect_left,bisect_right sys.setrecursionlimit(10**7) input = sys.stdin.readline N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for b in range(N): for a in range(b): ab = L[a] + L[b] r = bisect_left(L, ab) l = b + 1 ans += max(0, r - l) print(ans)
1
172,596,310,553,380
null
294
294
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 N = input() K = int(input()) lenN = len(N) # has less number before dp0 = [[0]*5 for _ in range(lenN+1)] # not had yet dp1 = [[0]*5 for _ in range(lenN+1)] dp1[0][0] = 1 for i in range(lenN): k = int(N[i]) for zero in range(4): dp0[i+1][zero] += dp0[i][zero] dp0[i+1][zero+1] += dp0[i][zero] * 9 if k != 0: dp0[i+1][zero] += dp1[i][zero] dp0[i+1][zero+1] += dp1[i][zero] * (k-1) dp1[i+1][zero+1] += dp1[i][zero] else: dp1[i+1][zero] += dp1[i][zero] ans = dp0[lenN][K] + dp1[lenN][K] print(ans) if __name__ == '__main__': solve()
def main(): N = input() L = len(N) K = int(input()) dp = [[0 for _ in range(L + 1)] for _ in range(K + 1)] dpp = [[0 for _ in range(L + 1)] for _ in range(K + 1)] dpp[0][0] = 1 for i in range(1, L + 1): n = int(N[i - 1]) for k in range(K + 1): # from dpp kk = k + (1 if n > 0 else 0) if kk <= K: dpp[kk][i] = dpp[k][i - 1] if n > 0: dp[k][i] += dpp[k][i - 1] if k + 1 <= K: dp[k + 1][i] += (n - 1) * dpp[k][i - 1] # from dp dp[k][i] += dp[k][i - 1] if k + 1 <= K: dp[k + 1][i] += 9 * dp[k][i - 1] print(dp[K][L] + dpp[K][L]) if __name__ == '__main__': main()
1
75,595,535,647,280
null
224
224
def main(): import bisect n = int(input()) s = list(input()) q = int(input()) d = {} for i in range(26): d[chr(ord('a')+i)] = [] for i in range(n): d[s[i]].append(i) #print(d) for i in range(q): t,a,b = input().split() if t == '1': a = int(a)-1 if s[a] == b: continue idx = bisect.bisect_left(d[s[a]],a) d[s[a]].pop(idx) bisect.insort_left(d[b],a) s[a] = b else: a = int(a)-1 b = int(b)-1 c = 0 for i in range(26): idx = bisect.bisect_left(d[chr(ord('a')+i)],a) if idx < len(d[chr(ord('a')+i)]) and d[chr(ord('a')+i)][idx] <= b: c += 1 print(c) main()
N = int(input()) D = N % 10 if D in [2, 4, 5, 7, 9]: print("hon") if D in [0, 1, 6, 8]: print("pon") if D == 3: print("bon")
0
null
41,004,842,531,070
210
142
# // Input # // 文字列が1行に与えられます。 # // Output # // 与えられた文字列の小文字と大文字を入れ替えた文字列を出力して下さい。アルファベット以外の文字はそのまま出力して下さい。 line = 'fAIR, LATER, OCCASIONALLY CLOUDY.' line = input() output = '' for i in range(len(line)): if line[i].isupper(): output += line[i].lower() elif line[i].islower(): output += line[i].upper() else: output += line[i] print(output)
from collections import Counter n = int(input()) a = list(map(int, input().split())) a += list(range(1,n+1)) a = Counter(a).most_common() a.sort() for i,j in a: print(j-1)
0
null
17,050,214,281,600
61
169
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) distance = abs(A-B) speed = V-W if distance <= speed*T: print("YES") else: print("NO")
a,v = map(int, input().split()) b,w = map(int, input().split()) t = int(input()) ans = "NO" if a > b: a,b = a*(-1), b*(-1) if a == b: ans = "YES" elif a < b: if v > w and (b-a) <= (v-w)*t: ans = "YES" print(ans)
1
15,195,512,672,772
null
131
131
heap = [] while True: try: n = int(raw_input()) if len(heap) == 0: heap.append(n) elif len(heap) == 1: if n <= heap[0]: heap.append(n) else: heap.insert(0, n) elif len(heap) == 2: if n > heap[0]: heap.insert(0, n) elif n <= heap[1]: heap.append(n) else: heap.insert(1, n) elif n > heap[2]: if n >= heap[0]: heap.insert(0, n) elif n >= heap[1]: heap.insert(1, n) else: heap.insert(2, n) heap.pop() except (EOFError): break for num in heap: print num
heights = [int(input()) for i in range(0, 10)] heights.sort(reverse=True) for height in heights[:3]: print(height)
1
23,252,812
null
2
2
def BubbleSort(A): for i in range(len(A)): for j in range(len(A)-1,i,-1): if A[j][1] < A[j-1][1]: # リストの要素の文字列は2次元配列として記憶される A[j],A[j-1] = A[j-1],A[j] return A def SelectionSort(A): for i in range(len(A)): mini = i for j in range(i,len(A)): if A[j][1] < A[mini][1]: mini = j A[i],A[mini] = A[mini],A[i] return A N = int(input()) # example for input to array : H4 C9 S4 D2 C3 (from cards) array = [i for i in input().split()] array_cp = list(array) result_bs = BubbleSort(array) print(*result_bs) print('Stable') # Bubble sort is stable result_ss = SelectionSort(array_cp) print(*result_ss) if result_ss == result_bs: print('Stable') else: print('Not stable')
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C # Stable Sort # Result: # Modifications # - modify inner loop start value of bubble_sort # This was the cause of the previous wrong answer. # - improve performance of is_stable function import sys ary_len = int(sys.stdin.readline()) ary_str = sys.stdin.readline().rstrip().split(' ') ary = map(lambda s: (int(s[1]), s), ary_str) # a is an array of tupples whose format is like (4, 'C4'). def bubble_sort(a): a_len = len(a) for i in range(0, a_len): for j in reversed(range(i + 1, a_len)): if a[j][0] < a[j - 1][0]: v = a[j] a[j] = a[j - 1] a[j - 1] = v # a is an array of tupples whose format is like (4, 'C4'). def selection_sort(a): a_len = len(a) for i in range(0, a_len): minj = i; for j in range(i, a_len): if a[j][0] < a[minj][0]: minj = j if minj != i: v = a[i] a[i] = a[minj] a[minj] = v def print_ary(a): vals = map(lambda s: s[1], a) print ' '.join(vals) def is_stable(before, after): length = len(before) for i in range(0, length): for j in range(i + 1, length): if before[i][0] == before[j][0]: v1 = before[i][1] v2 = before[j][1] for k in range(0, length): if after[k][1] == v1: v1_idx_after = k break for k in range(0, length): if after[k][1] == v2: v2_idx_after = k break if v1_idx_after > v2_idx_after: return False return True def run_sort(ary, sort_fn): ary1 = list(ary) sort_fn(ary1) print_ary(ary1) if is_stable(ary, ary1): print 'Stable' else: print 'Not stable' ### main run_sort(ary, bubble_sort) run_sort(ary, selection_sort)
1
24,398,037,052
null
16
16
import math import itertools n = int(input()) data = [] for i in range(n): x, y = map(int,input().split()) data.append((x, y)) cnt = 0 for a in itertools.permutations(range(n)): for j in range(n-1): cnt += ((data[a[j+1]][0]-data[a[j]][0])**2 + (data[a[j+1]][1]-data[a[j]][1])**2)**0.5 print(cnt / math.factorial(n))
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n = int(input()) if n & 1: print(0) exit() ans = 0 n //= 2 while n: ans += n // 5 n //= 5 print(ans)
0
null
132,569,633,500,008
280
258
import sys n = int(input()) l = sys.stdin.readlines() s = "" for i in l: x, y, z = sorted(map(lambda x:x*x,map(int, i.split()))) if x + y == z: s += "YES\n" else: s += "NO\n" print(s,end="")
n = int(input()) for cnt in range(n): t = list(map(int, input().split())) t.sort() if t[2]**2 == t[1]**2 + t[0]**2: print('YES') else: print('NO')
1
335,703,940
null
4
4
from decimal import Decimal def main(): a, b = input().split(" ") a = int(a) b = Decimal(b) print(int(a*b)) if __name__ == "__main__": main()
import bisect,collections,copy,heapq,itertools,math,string import sys from decimal import Decimal def S(): return sys.stdin.readline().rstrip() def M(): return map(Decimal,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) a, b = M() ab = a*b print(math.floor(ab))
1
16,609,992,880,558
null
135
135
def main(): n = int(input()) d_lst = list(map(int, input().split())) sum_d_lst = sum(d_lst) ans = 0 for i in range(n): ans += d_lst[i] * (sum_d_lst - d_lst[i]) print(ans // 2) if __name__ == "__main__": main()
n,k=map(int,input().split()) import sys sys.setrecursionlimit(2147483647) def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10**9+7 #割る数 N = 2*n+1 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) ans=1 if k>n: ans=cmb(n+n-1,n,p) else: for i in range(1,k+1): ans+=(cmb(n, i, p)*cmb(n-1,n-i-1,p))%p #print(i,cmb(n, i, p),cmb(n-1,n-i-1,p)) print(ans%p)
0
null
117,585,268,152,352
292
215
# (c) midandfeed r, c = [int(x) for x in input().split()] q = [] sumr = [0]*c tempr = 0 for i in range(r): col = [int(x) for x in input().split()] for j in range(c): sumr[j] += col[j] col.append(sum(col)) q.append(col) sumr.append(sum(sumr)) q.append(sumr) for i in range(r+1): for j in range(c+1): print(q[i][j], end='') if (j != (c)): print(' ', end='') # if (i != (r) ): print()
(r, c) = [int(i) for i in input().split()] a = [] for i in range(r): a.append([int(i) for i in input().split()]) a.append([0 for i in range(c)]) for i in range(r + 1): sum = 0 count = 0 for j in a[i]: print(j, end=' ') sum += j if i != r: a[r][count] += j count += 1 print(sum)
1
1,377,165,042,750
null
59
59
import sys N = input() num = [int(x) for x in input().split()] multiply = 1 if (0 in num): print(0) sys.exit() for i in num: multiply *= i if (multiply > 10**18): print(-1) sys.exit() if (0 < multiply and multiply <= 10**18): print(multiply)
N=int(input()) s,t=[],[] for i in range(N): S,T=input().split() s.append(S) t.append(int(T)) X=input() xs=s.index(X) print(sum(t[xs:])-t[xs])
0
null
56,228,957,283,500
134
243
import numpy as np X = int(input()) x = np.arange(-300, 300, dtype=np.int64) x5 = x**5 diff = np.subtract.outer(x5, x5) i = np.where(diff == X) x, y = i[0][0], i[0][1] x -= 300 y -= 300 print(x, -y)
n,m = map(int,input().split()) s = input() now = n ans_rev = [] while(now != 0): for i in range( max(0,now-m),now+1): if(i == now): print(-1) exit() if(s[i] == '1'): continue ans_rev.append(now - i) now = i break print(' '.join(map(str, ans_rev[::-1])))
0
null
82,625,853,453,088
156
274
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) mod = 10**9+7 # mod = 998244353 dir = [(-1,0),(0,-1),(1,0),(0,1)] alp = "abcdefghijklmnopqrstuvwxyz" INF = 1<<32-1 # INF = 10**18 def main(): n = int(ipt()) cnt = 0 for i in range(n): a,b = map(int,ipt().split()) if a == b: if cnt == 2: print("Yes") exit() else: cnt += 1 else: cnt = 0 print("No") return None if __name__ == '__main__': main()
N = int(input()) zoro = 0 ans = 'No' for i in range(N): D1, D2 = map(int, input().split()) if D1 == D2: zoro += 1 else: zoro = 0 if zoro == 3: ans = 'Yes' break print(ans)
1
2,529,585,737,470
null
72
72
#!/usr/bin/env python3 from collections import deque, Counter from heapq import heappop, heappush from bisect import bisect_right H,W = map(int, input().split()) s = [None for _ in range(H)] for i in range(H): s[i] = input() dp = [[0]*(W+1) for _ in range(H+1)] if s[0][0] == '#': dp[1][1] += 1 for i in range(H): for j in range(W): if (i,j) == (0,0): continue tmp = [] if i > 0: if s[i][j] == '#' and s[i-1][j] == '.': tmp.append(dp[i][j+1]+1) else: tmp.append(dp[i][j+1]) if j > 0: if s[i][j] == '#' and s[i][j-1] == '.': tmp.append(dp[i+1][j]+1) else: tmp.append(dp[i+1][j]) dp[i+1][j+1] = min(tmp) print(dp[H][W])
H, W = map(int, input().split()) L = [input() for _ in range(H)] inf = 10**9 dp = [[inf] * W for _ in range(H)] #[0][0]を埋める if (L[0][0] == '.'): dp[0][0] = 0 else: dp[0][0] = 1 for i in range(H): for j in range(W): #[0][0]の時は無視 if (i == 0 and j == 0): continue #→の場合。一個前のマス。 a = dp[i][j - 1] #↓の場合。一個前のマス。 b = dp[i - 1][j] #.から#に移動するときだけ操作が(1回)必要 if (L[i][j - 1] == "." and L[i][j] == "#"): a += 1 if (L[i - 1][j] == '.' and L[i][j] == '#'): b += 1 # min(dp[i][j],a,b)でもいいが結局問題になるのはa,bの比較だけでは? dp[i][j] = min(a, b) print(dp[-1][-1])
1
49,403,840,857,630
null
194
194
n = int(input()) a = n % 10 if a == 2 or a == 4 or a == 5 or a == 7 or a == 9: print("hon") elif a == 3: print("bon") else: print("pon")
list = input().split(" ") a = int(list[0]) b = int(list[1]) print(a * b)
0
null
17,620,519,700,070
142
133
N,K = map(int,input().split()) hitpoint = list(map(int,input().split())) hitpoint.sort(reverse=True) if N<=K: print(0) else: print(sum(hitpoint[K:]))
import operator def poland(A): l = [] ops = { "+": operator.add, "-": operator.sub, '*' : operator.mul } for i in range(len(A)): item = A.pop(0) if item in ops: l.append(ops[item](l.pop(-2),l.pop())) else: l.append(int(item)) return l.pop() if __name__ == '__main__': A = input().split() print (poland(A[:]))
0
null
39,321,576,036,600
227
18
from collections import deque from sys import stdin n = int(input()) ddl = deque() for i in stdin: inp = i.split() if len(inp) == 2: op, data = inp data = int(data) else: op, data = inp[0], None if op == 'insert': ddl.appendleft(data,) elif op == 'delete': try: ddl.remove(data) except ValueError: pass elif op == 'deleteFirst': ddl.popleft() elif op == 'deleteLast': ddl.pop() print(' '.join([str(item) for item in ddl]))
import collections d=collections.deque() for _ in range(int(input())): e=input() if'i'==e[0]:d.appendleft(e.split()[1]) else: if' '==e[6]: m=e.split()[1] if m in d:d.remove(m) elif len(e)%2:d.popleft() else:d.pop() print(*d)
1
49,313,951,972
null
20
20
n=int(input()) a=False for i in range(200): for j in range(200): if i**5-j**5==n: print(i,j) a=True elif i**5+j**5==n: print(i,-j) a=True if a: break
x=int(input()) for i in range(-118,120): for j in range(-118,120) : if i**5-j**5==x : print(i,j) exit() else : continue
1
25,576,621,106,730
null
156
156
import itertools as it a,b,c = map(int,input().split()) k = int(input()) allcase = list(it.product([0,1,2,3],repeat=k)) for case in allcase: nums = [a,b,c] for step in case: if step == 3: continue nums[step] *= 2 if nums[0] < nums[1] and nums[1] < nums[2]: print('Yes') exit() print('No')
from itertools import permutations n = int( input()) p = tuple(map(int, input().split())) q = tuple(map(int, input().split())) a = [i for i in range(1,n+1)] x = list(permutations(a,n)) y = x.index(p) z = x.index(q) print(abs(y-z))
0
null
53,976,338,569,600
101
246
class UnionFind(): def __init__(self, n): self.n = n self.par = [-1] * n def find(self, x): # 根を求める関数 if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.par[x] > self.par[y]: x, y = y, x self.par[x] += self.par[y] self.par[y] = x def size(self, x): return -self.par[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) n, m = map(int, input().split()) uf = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) uf.unite(a - 1, b - 1) cnt = 0 for i in range(n): cnt += (uf.par[i] < 0) print(cnt - 1)
s,w = map(int, input().split()) ans = "NG" # for i in range(a,b+1): # print(i) if s<=w: print("unsafe") else: print("safe")
0
null
15,801,169,553,214
70
163
# Air Conditioner X = int(input()) print(['No', 'Yes'][X >= 30])
now = int(input()) if now >= 30: print('Yes') else: print('No')
1
5,733,887,231,980
null
95
95
N = int(input()) A = list(map(int, input().split())) L = [i+A[i] for i in range(N)] R = [i-A[i] for i in range(N)] p = {} m = {} for i in range(N): if L[i] not in p: p[L[i]] = 1 else: p[L[i]] += 1 for i in range(N): if R[i] not in m: m[R[i]] = 1 else: m[R[i]] += 1 lower = max(min(p), min(m)) upper = min(max(p), max(m)) ans = 0 for x in range(lower, upper + 1): if x in p and x in m: ans += p[x] * m[x] print(ans)
class Dice: def __init__(self, label: list): self.top, self.front, self.right, self.left, self.back, self.bottom = label def roll(self, direction: str): if direction == "N": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.front, self.bottom, self.right, self.left, self.top, self.back, ) elif direction == "W": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.right, self.front, self.bottom, self.top, self.back, self.left, ) elif direction == "S": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.back, self.top, self.right, self.left, self.bottom, self.front, ) elif direction == "E": self.top, self.front, self.right, self.left, self.back, self.bottom = ( self.left, self.front, self.top, self.bottom, self.back, self.right, ) def output_top(self): print(self.top) (*label,) = map(int, input().split()) dice = Dice(label) for i in input(): dice.roll(i) dice.output_top()
0
null
13,268,826,470,610
157
33
def main(): import re n = int(input()) s = input() rindex = set() gindex = set() bindex = set() for i in range(n): if s[i] == "R": rindex.add(i) elif s[i] == "G": gindex.add(i) else: bindex.add(i) ans = len(rindex) * len(gindex) * len(bindex) for r in rindex: for g in gindex: if r > g: gap = r - g b1 = r + gap b2 = g - gap b3 = g + (gap/2) elif r < g: gap = g - r b1 = g + gap b2 = r - gap b3 = r + (gap/2) if b1 in bindex: ans -= 1 if b2 in bindex: ans -= 1 if b3 in bindex: ans -= 1 print(ans) if __name__ == "__main__": main()
X = int(input()) happy = 0 happy += (X // 500) * 1000 happy += ((X - X // 500 * 500) // 5) * 5 print(happy)
0
null
39,525,378,368,438
175
185
N = int(input()) A = list(map(int,input().split())) ans = "APPROVED" for n in range(N): if A[n] %2 == 0: if A[n] % 3 != 0 and A[n] % 5 != 0: ans = "DENIED" break print(ans)
x = int(input()) if x < 30: print('No') else: print('Yes')
0
null
37,154,334,830,082
217
95
s = input() while s[:2] == 'hi': s = s[2:] if s == '': print('Yes') else: print('No')
import re s = input() if re.sub(r'hi', '', s) == '': print('Yes') else: print('No')
1
53,226,310,003,008
null
199
199
list = input().split(' ') OPERATOR = { '+': lambda a, b: a + b, '*': lambda a, b: a * b, '-': lambda a, b: a - b, '/': lambda a, b: a / b, } stack = [] for item in list: if item in OPERATOR: b = stack.pop() a = stack.pop() stack.append(OPERATOR[item](a, b)) else: stack.append(int(item)) print(stack.pop())
l = input().split() q = [] for e in l: if e == '+': q.append(q.pop() + q.pop()) elif e == '-': q.append(-q.pop() + q.pop()) elif e == '*': q.append(q.pop() * q.pop()) else: q.append(int(e)) print(q[0])
1
35,812,563,888
null
18
18
n,q=map(int,input().split()) Q=[] sum=0 for i in range(n): tmp=input().split() tmp[1]=int(tmp[1]) Q.append(tmp[0]) Q.append(tmp[1]) loop=0 while loop==0: for i in range(len(Q)//2): tmp=[Q[0],Q[1]] if tmp[1]>q: sum+=q Q.append(tmp[0]) Q.append(tmp[1]-q) else: sum+=tmp[1] print(tmp[0],sum) Q.pop(0) Q.pop(0) if len(Q)==0: break
S=input() K=int(input()) N=len(S) ans=None if len(set(S))==1: ans=N*K//2 else: li=[] i=0 while(i<N): j=i c=S[i] cnt=0 while(j<N and c==S[j]): cnt+=1 j+=1 li.append((c,cnt)) i=j res=0 if li[0][0]!=li[-1][0]: for x,y in li: res+=y//2 ans=res*K else: for i in range(1,len(li)-1): res+=li[i][1]//2 ans=res*K+li[0][1]//2+li[-1][1]//2+(li[0][1]+li[-1][1])//2*(K-1) print(ans)
0
null
88,136,300,550,506
19
296
h, n = map(int, input().split()) ab = [] for _ in range(n): ab.append(map(int, input().split())) m = 20010 dp = [1000000000] * m dp[0] = 0 for a, b in ab: for i in range(m): if i - a >= 0: dp[i] = min(dp[i], dp[i - a] + b) print(min(dp[h:]))
import sys input = lambda: sys.stdin.readline().rstrip() INF = 10 ** 9 + 7 H, N = map(int, input().split()) AB = [[] for _ in range(N)] for i in range(N): AB[i] = list(map(int, input().split())) def solve(): dp = [INF] * (H + 1) dp[H] = 0 for h in range(H, 0, -1): if dp[h] == INF: continue next_dp = dp for i in range(N): a, b = AB[i] hh = max(0, h - a) next_dp[hh] = min(dp[hh], dp[h] + b) dp = next_dp print(dp[0]) if __name__ == '__main__': solve()
1
80,732,001,143,178
null
229
229
n,m = map(int,input().split()) par = [i for i in range(n+1)] root = [i for i in range(n+1)] par[0] = 1 def find(x): if par[x] == x: return x else: par[x] = find(par[x]) #経路圧縮 return par[x] def same(x,y): return find(x) == find(y) def unite(x,y): x = find(x) y = find(y) if x == y: return 0 par[x] = y for i in range(m): a,b = map(int,input().split()) unite(a,b) for i in range(n+1): root[i] = find(i) print(len(set(root))-1)
a, b = map(int, input().split(' ')) if a > b: print(str(b) * a) else: print(str(a) * b)
0
null
43,328,938,488,640
70
232
n, m = list(map(int, input().split())) c = list(map(int, input().split())) DP = [i for i in range(n + 1)] for cost in c: for i in range(cost, n + 1): DP[i] = min(DP[i], DP[i - cost] + 1) print(DP[n])
if __name__ == '__main__': n = input().split() c = input().split() dp = [50000] * (int(n[0]) + 1) for i in range(int(n[1])): if int(c[i]) > int(n[0]): continue dp[int(c[i])] = 1 for j in range(int(n[0])): if int(c[i])+j > int(n[0]): break; if dp[j] != 50000: dp[int(c[i])+j] = min(dp[int(c[i])+j], dp[j]+1) print (dp[int(n[0])])
1
137,946,436,068
null
28
28
import math import itertools n = int(input()) data = [] for i in range(n): x, y = map(int,input().split()) data.append((x, y)) cnt = 0 for a in itertools.permutations(range(n)): for j in range(n-1): cnt += ((data[a[j+1]][0]-data[a[j]][0])**2 + (data[a[j+1]][1]-data[a[j]][1])**2)**0.5 print(cnt / math.factorial(n))
n = int(input()) ascii_letters = 'abcdefghijklmnopqrstuvwxyz' for i in range(1,15): if n<=26**i: order=i n-=1 break n-=26**i for i in range(order): print(ascii_letters[n//(26**(order-i-1))],end='') n%=(26**(order-i-1)) print()
0
null
80,474,141,857,928
280
121
A, B, K = map(int, input().split()) i = 0 if A <= K: K = K - A A = 0 if A > K: A = A - K K = 0 if B <= K and A == 0: K = K - B B = 0 if B >= K and A == 0: B = B - K K = 0 print(A) print(B)
r=input().split() A=int(r[0]) B=int(r[1]) K=int(r[2]) if K>=A+B: print("0 0") elif K>=A: print("0 "+str(B-K+A)) else: print(str(A-K)+" "+str(B))
1
104,276,192,708,492
null
249
249
# import bisect # from collections import Counter, defaultdict, deque # import copy # from heapq import heappush, heappop, heapify # from fractions import gcd # import itertools # from operator import attrgetter, itemgetter # import math import sys # import numpy as np ipti = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): x, y = list(map(int,ipti().split())) prize = [300000, 200000, 100000, 0] if x == y == 1: print(1000000) else: x = 4 if x > 3 else x y = 4 if y > 3 else y print(prize[x-1]+prize[y-1]) if __name__ == '__main__': main()
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())) s = input() cnt = 0 for i in range(len(s)//2): if s[i] != s[-1-i]: cnt += 1 print(cnt)
0
null
130,531,866,327,620
275
261
class Stack(list): def __init__(self): self.length = 0 def __len__(self): return self.length def push(self,x): self.insert(len(self),x) self.length += 1 def pop(self): try: if(len(self)==0): raise NameError("stack is empty") tmp = self[len(self)-1] self.length -= 1 return tmp except: print("stack is empty!!!!") return '#' data = Stack() s = input() x = s.split() for i in x: if i == '+': a = data.pop() b = data.pop() data.push(b+a) elif i == '-': a = data.pop() b = data.pop() data.push(b-a) elif i == '*': a = data.pop() b = data.pop() data.push(b*a) else: data.push(int(i)) print(data.pop())
symbol = list(input().split()) stack = [] while len(symbol) > 0: x = symbol.pop(0) if x.isdigit(): stack.append(int(x)) else: a,b = stack.pop(),stack.pop() if x == "+": stack.append(b + a) elif x == "-": stack.append(b - a) elif x == "*": stack.append(b * a) print(stack.pop())
1
35,993,857,952
null
18
18
import sys sys.setrecursionlimit(10**5) def DFS(i,g): if i not in done: done.add(i) circle.add(i) g_list[i]=g for f in F[i]: DFS(f,g) else: return N,M,K=map(int,input().split()) F=[[] for _ in range(N)] B=[[] for _ in range(N)] for f in range(M): f1,f2=map(int,input().split()) F[f1-1].append(f2-1) F[f2-1].append(f1-1) for b in range(K): b1,b2=map(int,input().split()) B[b1-1].append(b2-1) B[b2-1].append(b1-1) Group=[] circle=set() done=set() g_list=[0 for _ in range(N)] g=0 for i in range(N): if i not in done: DFS(i,g) Group.append(circle) circle=set() g+=1 ans=[-1 for _ in range(N)] for i in range(N): G=g_list[i] ans[i]+=len(Group[G]) for fr in F[i]: if fr in Group[G]: ans[i]-=1 for bl in B[i]: if bl in Group[G]: ans[i]-=1 print(*ans)
from collections import defaultdict from collections import deque n,m,k = map(int,input().split()) f_set = {tuple(map(int,input().split())) for _ in range(m)} b_set = {tuple(map(int,input().split())) for _ in range(k)} friends_counts = {key:[] for key in range(1,n+1)} blocks_counts = {key:[] for key in range(1,n+1)} for f in f_set: friends_counts[f[0]].append(f[1]) friends_counts[f[1]].append(f[0]) for b in b_set: blocks_counts[b[0]].append(b[1]) blocks_counts[b[1]].append(b[0]) friends_groups_list = [set() for _ in range(n+1)] #dfs que = deque() groups_count = 0 checked_dict = {key:0 for key in range(1,n+1)} #que.appendleft(1) for i in range(1,n+1): if checked_dict[i] == 1: continue que.appendleft(i) checked_dict[i] = 1 while que: x = que.popleft() friends_groups_list[groups_count].add(x) for i in range(len(friends_counts[x])): if checked_dict[friends_counts[x][i]] == 0: que.appendleft(friends_counts[x][i]) checked_dict[friends_counts[x][i]] = 1 groups_count += 1 result_list=[0]*n #print(blocks_counts) #print(friends_groups_list) for i in range(len(friends_groups_list)): mini_set = friends_groups_list[i] for ms in mini_set: result_list[ms-1] = len(mini_set) - 1 - len(friends_counts[ms]) block_counter_in_minilist = 0 for k in blocks_counts[ms]: if k in mini_set: block_counter_in_minilist += 1 result_list[ms-1] -= block_counter_in_minilist print(" ".join(map(str,result_list))) #cの配列の解釈が違ったらしい。。。 #f_set = {tuple(map(int,input().split())) for _ in range(m)} # #b_set = {tuple(map(int,input().split())) for _ in range(k)} # #c_list = [0] * (n-1) # #result_dict = {key:0 for key in range(1,n+1)} # #for f in f_set: # if abs(f[0]-f[1]) == 1: # c_list[min(f[0],f[1]) - 1] = 1 # #ここでelseで飛び石での友達のsetを作ってもよいが、そもそもsetなのでinでの探索にそんなに時間かからないし、いったんこのままやってみる。 # #for start in range(0,n-2): # if c_list[start] == 0: # #c[start]が1になるまで飛ばす # continue # # for end in range(start+1,n-1): # if c_list[end] == 0: # #友人同士ではないペアまできたらstartをインクリメント # break # # #もし「友人候補」の候補者が、「友人関係でない」かつ「ブロック関係でない」ことをチェックしている。 # if not (start+1,end+2) in f_set and not (end+2,start+1) in f_set and not (start+1,end+2) in b_set and not (end+2,start+1) in b_set: # result_dict[start+1] += 1 # result_dict[end+2] += 1 # #for i in range(1,n+1): # print(result_dict[i]) # #print(c_list)
1
61,764,775,045,596
null
209
209
import math N, D = map(int,input().split()) XY = list(list(map(int,input().split())) for _ in range(N)) count = 0 for i in range(N): if math.sqrt(XY[i][0] ** 2 + XY[i][1] ** 2) <= D: count += 1 print(count)
def solve(): import numpy as np from sys import stdin f_i = stdin N, T = map(int, f_i.readline().split()) AB = [tuple(map(int, f_i.readline().split())) for i in range(N)] AB.sort() max_Ai = AB[-1][0] dp = [[0] * T for i in range(N + 1)] dp = np.zeros(max_Ai + T, dtype=int) for A_i, B_i in AB: dp[A_i:A_i+T] = np.maximum(dp[A_i:A_i+T], dp[:T] + B_i) print(max(dp)) solve()
0
null
79,089,440,517,880
96
282
def main(): n,m,k = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) import itertools sum_a = list(itertools.accumulate(a)) sum_b = list(itertools.accumulate(b)) if sum_a[-1] + sum_b[-1] <= k: print(n+m) return if a[0] > k and b[0] > k: print(0) return for i in range(n): if sum_a[i] > k: break s_a = i - 1 if sum_a[-1] <= k: s_a = n-1 now_sum = 0 if s_a >= 0: now_sum = sum_a[s_a] for i in range(m): if now_sum + sum_b[i] > k: break s_b = i - 1 ans = s_a + 1 + s_b + 1 now_sum = 0 for a_i in range(s_a-1, -2, -1): for b_i in range(s_b+1,m): if a_i < 0: now_sumtime = sum_b[b_i] else: now_sumtime = sum_a[a_i] + sum_b[b_i] if b_i == m-1 and now_sumtime <= k: now_sum = a_i + m + 1 break if now_sumtime > k: now_sum = a_i + b_i + 1 break s_b = b_i-1 ans = max(ans, now_sum) print(ans) if __name__=='__main__': main()
N,M,K=map(int,input().split()) *A,=map(int,input().split()) *B,=map(int,input().split()) def binary_search(func, array, left=0, right=-1): if right==-1:right=len(array)-1 y_left, y_right = func(array[left]), func(array[right]) while True: middle = (left+right)//2 y_middle = func(array[middle]) if y_left==y_middle: left=middle else: right=middle if right-left==1:break return left cumA = [0] for i in range(N): cumA.append(cumA[-1]+A[i]) cumB = [0] for i in range(M): cumB.append(cumB[-1]+B[i]) cumB.append(10**20) if cumA[-1]+cumB[-1]<=K: print(N+M) exit() if A[0] > K and B[0] > K: print(0) exit() ans = 0 for i in range(N+1): if K-cumA[i]<0:break idx = binary_search(lambda x:x<=K-cumA[i],cumB) res = max(0,i+idx) ans = max(ans, res) print(ans)
1
10,683,032,350,468
null
117
117
print(1*(input()[:2]!=input()[:2]))
M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) print(1 if M1 != M2 else 0)
1
124,598,789,191,130
null
264
264
class Dice: __x = 1 __y = 0 def __init__(self,dice): self.dice = dice def output(self): print(self.dice[0]) def move(self,str): if str == 'N': temp = self.dice[0] self.dice[0] = self.dice[1] self.dice[1] = self.dice[5] self.dice[5] = self.dice[4] self.dice[4] = temp elif str == 'S': temp = self.dice[0] self.dice[0] = self.dice[4] self.dice[4] = self.dice[5] self.dice[5] = self.dice[1] self.dice[1] = temp elif str == 'E': temp = self.dice[0] self.dice[0] = self.dice[3] self.dice[3] = self.dice[5] self.dice[5] = self.dice[2] self.dice[2] = temp elif str == 'W': temp = self.dice[0] self.dice[0] = self.dice[2] self.dice[2] = self.dice[5] self.dice[5] = self.dice[3] self.dice[3] = temp di = list(map(int,input().split())) m = list(input()) di = Dice(di) for i in m: di.move(i) di.output()
import sys input = sys.stdin.readline def south(dice): f, u, d, b = [dice["front"], dice["up"], dice["down"], dice["back"]] dice["front"] = u dice["up"] = b dice["down"] = f dice["back"] = d return dice def north(dice): f, u, d, b = [dice["front"], dice["up"], dice["down"], dice["back"]] dice["front"] = d dice["up"] = f dice["down"] = b dice["back"] = u return dice def west(dice): d, l, r, u = [dice["down"], dice["left"], dice["right"], dice["up"]] dice["down"] = l dice["left"] = u dice["right"] = d dice["up"] = r return dice def east(dice): d, l, r, u = [dice["down"], dice["left"], dice["right"], dice["up"]] dice["down"] = r dice["left"] = d dice["right"] = u dice["up"] = l return dice def show(dice): print(" ", dice["up"], " ") print(dice["left"], dice["front"], dice["right"], dice["back"]) print(" ", dice["down"], " ") print() def init_dice(dice_data): return { "front": dice_data[1], "back": dice_data[4], "up": dice_data[0], "right": dice_data[2], "down": dice_data[5], "left": dice_data[3] } def main(): pos = list(map(int, input().split())) move = input().rstrip() dice = init_dice(pos) for i in move: if i == "W": dice = west(dice) elif i == "S": dice = south(dice) elif i == "N": dice = north(dice) elif i == "E": dice = east(dice) print(dice["up"]) if __name__ == "__main__": main()
1
230,460,153,924
null
33
33
r = int(input()) import math ans = 2 * math.pi * r print(ans)
n=int(input()) l = [list(map(int,input().split())) for i in range(n)] ans='No' for i in range(n-2): if l[i][0]==l[i][1] and l[i+1][0]==l[i+1][1] and l[i+2][0]==l[i+2][1]: ans='Yes' print(ans)
0
null
17,064,597,220,154
167
72
from sys import stdin input = stdin.readline def solve(): n,m = map(int,input().split()) p = [tuple(map(int,inp.split())) for inp in stdin.read().splitlines()] father = [-1] * n count = n def getfather(x): if father[x] < 0: return x father[x] = getfather(father[x]) return father[x] def union(x, y): x = getfather(x) y = getfather(y) nonlocal count if x != y: count -= 1 if father[x] > father[y]: x,y = y,x father[x] += father[y] father[y] = x for a,b in p: union(a-1,b-1) print(count - 1) if __name__ == '__main__': solve()
N,M = map(int,input().split()) d,ans,wrong = [0]*N,0,0 for _ in range(M): p,s = input().split() p = int(p)-1 if d[p] != -1: if s == "WA": d[p] += 1 else: wrong += d[p] d[p] = -1 ans += 1 print(ans,wrong)
0
null
47,630,787,668,310
70
240
n = int(input()) Tp = 0 Hp = 0 tmp = "abcdefghijklmnopqrstuvwxyz" alph = list(tmp) for i in range(n): Ta,Ha = input().split() lTa = list(Ta) lHa = list(Ha) num = 0 if (len(Ta) <= len(Ha)): #definition of num num = len(Ta) else: num = len(Ha) if (Ta in Ha and lTa[0] == lHa[0]): #drow a if (Ta == Ha): Tp += 1 Hp += 1 else: Hp += 3 elif (Ha in Ta and Ha != Ta and lTa[0] == lHa[0]): Tp += 3 else: for i in range(len(lTa)): # convert alphabet to number for j in range(26): if (lTa[i] == alph[j]): lTa[i] = int(j) else : continue for i in range(len(lHa)): # convert alphabet to number for j in range(26): if (lHa[i] == alph[j]): lHa[i] = int(j) else : continue for i in range(num): if (lTa[i] < lHa[i]): Hp +=3 break elif (lHa[i] < lTa[i]): Tp +=3 break elif (lHa[i] == lTa[i]): continue print(Tp,Hp)
N = int(input()) taro_p = hana_p = 0 for n in range(N): tw,hw = input().split() if tw == hw: taro_p += 1 hana_p += 1 elif tw < hw: hana_p += 3 else : taro_p += 3 print(taro_p,hana_p)
1
1,998,502,209,510
null
67
67
S = input() N = len(S) ans = [0] * (N + 1) for i in range(N): if S[i] == "<": ans[i + 1] = ans[i] + 1 for i in range(N - 1, -1, -1): if S[i] == ">": if ans[i] <= ans[i + 1]: ans[i] = ans[i + 1] + 1 print(sum(ans))
s = input() k = len(s) a = [0]*(k+1) for i in range(k): if s[i] == '<': a[i+1] = a[i]+1 for j in range(k-1,-1,-1): if s[j] == '>': a[j] = max(a[j],a[j+1]+1) print(sum(a))
1
156,476,029,613,540
null
285
285
n, k = map(int, input().split()) xs = [i for i in range(1, k + 1)] xs.reverse() dict_x = {} mod = 10 ** 9 + 7 def pow(x, y): global mod a = 1 b = x c = y while c > 0: if c & 1: a = (a * b) % mod b = (b * b) % mod c = c >> 1 return a answer = 0 for x in xs: num = k // x a = pow(num, n) # print(a) s = 2 while x * s <= k: a -= dict_x[x * s] s += 1 dict_x[x] = a answer = (answer + a * x) % mod print(answer)
inputs = input().split(' ') D = int(inputs[0]) T = int(inputs[1]) S = int(inputs[2]) t = D / S if T >= t: print('Yes') else: print('No')
0
null
20,060,299,921,100
176
81
N, X, T = list(map(int,input().split())) if (N%X!=0): ans = (N//X + 1) * T else: ans = (N//X) * T print(ans)
import sys,queue,math,copy sys.setrecursionlimit(10**7) input = sys.stdin.readline INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in input().split()] _LI = lambda : [int(x)-1 for x in input().split()] N = int(input()) A = LI() c =[0,0,0] cnt = [0 for _ in range(N)] for i in range(N): cnt[i] = c.count(A[i]) if cnt[i] == 0: print (0) exit (0) for j in range(3): if c[j] == A[i]: c[j] += 1 break ans = 1 for i in range(N): ans = (ans * cnt[i]) % MOD print (ans)
0
null
67,263,613,097,220
86
268
N=int(input()) L=list(map(int,input().split())) cnt=0 for i in range(0,N-2,1): for j in range(i+1,N-1,1): for k in range(j+1,N,1): if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i] and L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j]: cnt=cnt+1 print(cnt)
a = list(map(int, input().split())) sum_a = sum(a) if sum_a >= 22: print('bust') else: print('win')
0
null
61,717,050,818,528
91
260
from sys import stdin import math def isPrime(x): if x == 2 or x == 3: return True elif (x < 2 or x % 2 == 0 or x % 3 == 0): return False s = int(math.sqrt(x) + 1) for i in range(5, s + 1, 2): if x % i == 0: return False return True print(sum([isPrime(int(stdin.readline())) for _ in range(int(stdin.readline()))]))
N = input() ans = 'Yes' if '7' in N else 'No' print(ans)
0
null
17,083,411,563,450
12
172
n, q = list(map(int, input().split())) que = [] for _ in range(n): name, time = input().split() que.append([name, int(time)]) elapsed_time = 0 while que: name, time = que.pop(0) dt = min(q, time) time -= dt elapsed_time += dt if time > 0: que.append([name, time]) else: print (name, elapsed_time)
from collections import namedtuple Task = namedtuple('Task', 'name time') class Queue: def __init__(self, n): self.n = n self._l = [None for _ in range(self.n + 1)] self._head = 0 self._tail = 0 def enqueue(self, x): self._l[self._tail] = x self._tail += 1 if self._tail > self.n: self._tail -= self.n def dequeue(self): if self.isEmpty(): raise IndexError("pop from empty queue") else: e = self._l[self._head] self._l[self._head] = None self._head += 1 if self._head > self.n: self._head -= self.n return e def isEmpty(self): return self._head == self._tail def isFull(self): return self._tail == self.n if __name__ == '__main__': n, q = map(int, input().split()) queue = Queue(n+1) for _ in range(n): name, time = input().split() time = int(time) queue.enqueue(Task(name=name, time=time)) now = 0 while not queue.isEmpty(): task = queue.dequeue() t = task.time if t <= q: now += t print(task.name, now) else: now += q queue.enqueue(Task(task.name, t - q))
1
42,121,236,822
null
19
19
while True: [a,b] = raw_input().split() a = int(a) b = int(b) if a == 0 and b == 0: break if a < b: print a,b else: print b,a
x=[] y=[] while True: i,j=map(int,raw_input().split()) if (i,j)==(0,0): break; x.append(i) y.append(j) X=iter(x) Y=iter(y) for a in X: b=Y.next() if a<b: print('%d %d'%(a,b)) else: print('%d %d'%(b,a))
1
523,917,031,148
null
43
43
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) S = int(input()) mod = 10**9+7 pos = {0: 1} neg = {0: 1} for i in range(1, 10**4): pos[i] = (pos[i-1]*i)%mod neg[i] = pow(pos[i], mod-2, mod) cnt = 1 ans = 0 while 3*cnt<=S: rest = S-3*cnt ans += pos[rest+cnt-1]*neg[rest]*neg[cnt-1] ans %= mod cnt += 1 print(ans)
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, A): C = [0] * (10**6 + 1) for a in A: if C[a] == 1: C[a] = -1 continue if C[a] == -1: continue C[a] = 1 for b in range(a + a, 10 ** 6 + 1, a): C[b] = -1 ans = 0 for a in A: if C[a] == 1: ans += 1 print(ans) if __name__ == '__main__': input = sys.stdin.readline N = int(input()) *A, = map(int, input().split()) main(N, A)
0
null
8,942,917,550,930
79
129
N, M = map(int, input().split()) F = [[] for _ in range(N)] P = [0] * N for i in range(M): A, B = map(int, input().split()) F[A-1].append(B-1) F[B-1].append(A-1) c=0 l = [] for i in range(N): if P[i] == 0: c+=1 l.append(i) while len(l)>0: p=l.pop() P[p] = c for j in F[p]: if P[j] == 0: l.append(j) print(c-1)
n = int(input()) num_of_sug = [] sug = [] for i in range(n): m = int(input()) num_of_sug += [m] sug += [[tuple(map(int, input().split())) for _ in range(m)]] ans = 0 for i in range(2 ** n): liar = [] honest = [] for j in range(n): if ((i >> j) & 1): if j + 1 in liar: break elif j + 1 not in honest: honest += [j + 1] sug_tmp = sug[j] for sug_ in sug_tmp: if sug_[1] == 1: if sug_[0] in liar: break elif sug_[0] not in honest: honest += [sug_[0]] else: if sug_[0] in honest: break elif sug_[0] not in liar: liar += [sug_[0]] else: continue break else: if j + 1 in honest: break elif j + 1 not in liar: liar += [j + 1] else: if ans < len(honest): ans = len(honest) print(ans)
0
null
62,124,014,709,360
70
262
#coding:utf-8 #1_3_C 2015.3.24 while True: x,y = map(int,input().split()) if (x,y) == (0,0): break elif x > y: x,y = y,x print('{} {}'.format(x,y))
while True: xy_list = list(map(int, input().split())) if xy_list[0] == xy_list[1] == 0: break print(*sorted(xy_list))
1
528,899,034,180
null
43
43
H,N=map(int,input().split()) A=input() list_A=A.split() waza=0 for i in range(0,N): waza=waza+int(list_A[i]) if waza>=H: print("Yes") else: print("No")
# Problem B - Common Raccoon vs Monster # input H, N = map(int, input().split()) a_nums = list(map(int, input().split())) # initialization a_sum = sum(a_nums) # output if a_sum>=H: print("Yes") else: print("No")
1
78,223,729,027,978
null
226
226
N = int(input()) A = {} for i in range(N): s = input() if s in A: A[s] += 1 else: A[s] = 1 s_max = max(A.values()) for j in sorted(k for k in A if A[k] == s_max): print(j)
N = int(input()) d = {} for i in range(N): s = input() if s in d.keys(): d[s] += 1 else: d[s] = 1 mx = 0 for i in d.values(): mx = max(mx, i) for i in sorted(d.items()): if i[1] == mx: print(i[0])
1
70,006,267,276,546
null
218
218
N = int(input()) A = list(map(int, input().split())) s = 0 height = 0 for a in A: height = max(height, a) s += height - a print(s)
n, k = map(int, input().split()) pp = list(map(int, input().split())) p = [pp[i]-1 for i in range(n)] c = list(map(int, input().split())) ans = -(10**9+1) for i in range(n): s = 0 x = i for j in range(k): x = p[x] s += c[x] ans = max(ans,s) if i == x: break a = int(k/(j+1)) m = k%(j+1) if m == 0 and a > 1: m = j+1 a -= 1 s *= a ans = max(ans,s) for l in range(m): x = p[x] s += c[x] ans = max(ans, s) print (ans)
0
null
5,012,745,713,700
88
93
def solve(): print(input().replace('?', 'D')) if __name__ == '__main__': solve()
s=input() q=int(input()) que=[list(map(str,input().split())) for i in range(q)] count=0 for i in que: if i[0]=="1": count+=1 ans=[[],[]] ak=count for i in que: if i[0]=="1": count-=1 else: if i[1]=="1": ans[count%2].append(i[2]) else: ans[(count+1)%2].append(i[2]) if ak%2==0: print("".join(reversed(ans[0]))+s+"".join(ans[1])) else: print("".join(reversed(ans[0]))+"".join(reversed(list(s)))+"".join(ans[1]))
0
null
38,018,788,658,822
140
204
n = int(input()) n1 = n pn = [] cnt = 2 ans = 0 while cnt <= int(n ** 0.5): while n1 % cnt == 0: n1 = n1 // cnt pn.append(cnt) cnt += 1 pns = list(set(pn)) ansa = [] for i in pns: ansa.append(pn.count(i)) for i in ansa: x = 1 while i > 0: i -= x if i < 0: break x += 1 ans += 1 print(ans + 1 if n1 != 1 else ans)
import collections import bisect def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a N = int(input()) c = collections.Counter(prime_factorize(N)) sums = [] s=1 ans = 0 for v in c.values(): count = 0 for i in range(1,v+1): if count+i > v: break else: count += i ans += 1 print(ans)
1
16,816,304,195,888
null
136
136
from collections import deque def scan(que, ps, way): Li = 0 pp = ps while len(que) > 0: if way==0: p = que.popleft() else: p = que.pop() if p < ps: Li += ps - p else: break pp = p return Li if __name__=='__main__': D = input() que = deque() p = 0 for c in D: que.append(p) if c == "\\" : p += -1 elif c == "/" : p += 1 que.append(p) Ll = [] Lr = [] ls = que.popleft() if len(que) > 0: rs = que.pop() while len(que) > 0: while len(que) > 0: if que[0] < ls: break else: ls = que.popleft() while len(que) > 0: if que[-1] < rs: break else: rs = que.pop() if len(que) > 0: if ls < rs: Ll.append(scan(que,ls,0)) else : Lr.insert(0,scan(que,rs,1)) L = Ll + Lr if len(L) > 0: print(sum(L)) print(len(L), *L) else: print(0) print(0)
down_positions = [] ponds = [] for index, value in enumerate(raw_input()): if value == '\\': down_positions.append(index) elif value == '/' and down_positions: right = index left = down_positions.pop() area = right - left candidate_area = 0 while ponds and left < ponds[-1][0]: candidate_area += ponds.pop(-1)[1] ponds.append((left, area + candidate_area)) print sum(x[1] for x in ponds) print len(ponds), for pond in ponds: print pond[1],
1
57,640,230,620
null
21
21
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if a <= b: print("YES" if a + v * t >= b + w * t else "NO") else: print("YES" if b - w * t >= a - v * t else "NO")
import sys a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) if (a == b): print('YES') sys.exit(0) if (v <= w): print('NO') sys.exit(0) res = abs(a - b) / (v - w) if (res > t): print('NO') else: print('YES') sys.exit(0)
1
15,092,543,434,418
null
131
131
input() a=[a for a in map(int,input().split())if a%2==0] r="DENIED" for i in a: if i%3 and i%5:break else: r="APPROVED" print(r)
n = int(input()) a = list(map(int, input().split())) for v in a: if v % 2 == 0: if not (v % 3 == 0 or v % 5 == 0): print("DENIED") exit() print("APPROVED")
1
68,957,747,324,630
null
217
217
N, M = list(map(int, input().split())) import math ans = [] if M == 1: ans.append((1, 2)) else: m0 = (1, M+1) m1 = (M+2, 2*M+1) for _ in range(math.ceil(M/2)): if m0[0] < m0[1]: ans.append(m0) if m1[0] < m1[1]: ans.append(m1) m0 = (m0[0]+1, m0[1]-1) m1 = (m1[0]+1, m1[1]-1) for a in ans: print(a[0], a[1])
import math n, m = map(int, input().split()) c = 0 f = [math.floor(n/2), math.floor(n/2) + 1] if n % 2 == 0: while c < m: c += 1 if c == math.floor(n/4) + 1: if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n print(str(f[0]) + ' ' + str(f[1])) if (f[0] - 1) % n == 0: f[0] = n else: f[0] = (f[0] - 1) % n if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n else: while c < m: c += 1 print(str(f[0]) + ' ' + str(f[1])) if (f[0] - 1) % n == 0: f[0] = n else: f[0] = (f[0] - 1) % n if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n
1
28,657,538,405,498
null
162
162