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
N = int(input()) A = list(map(int, input().split())) fumidai = 0 previous = 0 for i in range(N): if previous > A[i]: fumidai += previous - A[i] else: previous = A[i] continue print(fumidai)
n = int(input()) A = list(map(int, input().split())) total = 0 min_ = A[0] for i in range(n): if A[i] > min_: min_ = A[i] else: total += (min_ - A[i]) print(total)
1
4,584,283,631,460
null
88
88
def main(): n = int(input()) s = input() if n % 2 == 0: sl = len(s) // 2 s1 = s[:sl] s2 = s[sl:] if s1 == s2: print('Yes') else: print('No') else: print('No') if __name__ == '__main__': main()
N = int(input()) K = int(input()) def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def contain_one(n): a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break return 9*a+(n//max_num) def contain_two(n): if n <=10: return 0 a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break cnt = 0 #10^a位まで for i in range(1, a): cnt += 9*9*i #10^a位 tmp = n // max_num cnt += 9*a*(tmp-1) #nの10^a桁より小さい数 tmp = n % max_num #怪しい if tmp != 0: cnt += contain_one(tmp) return cnt def contain_three(n): if n <=100: return 0 a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break cnt = 0 #10000以上の時ここがダメ for i in range(2, a): if i == 2: cnt += 9**2 * 9 else: #3H(a-2) = aCa-2 cnt += 9**2 * 9 * cmb(i, i-2) #aH2 #cnt += 9**2 * 9 * (i*(i+1)//2) # tmp = tmp * 3 # cnt += tmp tmp = n // max_num if a == 2: cnt += 9**2 * (tmp-1) else: cnt += 9**2 * (tmp-1) * cmb(a, a-2) tmp = n % max_num if tmp != 0: cnt += contain_two(tmp) return cnt if K == 1: print(contain_one(N)) elif K == 2: print(contain_two(N)) else: print(contain_three(N))
0
null
111,476,866,758,568
279
224
n = int(input()) s = input() [print(chr((ord(s[i])+n-65)%26+65),end="") for i in range(len(s))]
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d N = int(input()) alphabet = "abcdefghijklmnopqrstuvwxyz" curr_str = [] def print_str(curr_str): string = "" for i in curr_str: string += alphabet[i] print(string) def dfs(index, curr_str, curr_char): if curr_char > index: return None if curr_char > max(curr_str) + 1: return None if index == N-1: print_str(curr_str + [curr_char]) return None for i in range(N): dfs(index+1, curr_str+[curr_char], i) if N == 1: print("a") else: for i in range(N): dfs(1, [0], i)
0
null
93,293,059,452,670
271
198
MOD = 10 ** 9 + 7 N = int(input()) Sall = pow(10, N, MOD) S0 = S9 = pow(9, N, MOD) S09 = pow(8, N, MOD) ans = (Sall - (S0 + S9 - S09)) % MOD print(ans)
n = int(input()) if n<2: ans = 0 else: ans =(10**n-(9**n)*2+8**n)%(10**9+7) print(ans)
1
3,157,251,553,148
null
78
78
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A= map(int, read().split()) if len(set(A)) == N: print('YES') else: print('NO') return if __name__ == '__main__': main()
n=int(input()) b=list(map(int,input().split())) b.sort() for i in range(n-1): if b[i]==b[i+1]: print("NO") break if i==n-2: print("YES")
1
73,809,451,111,408
null
222
222
import math N = int(input()) num = list(map(int, input().split())) #N = 10**6 #num = list(range(1, N+1)) MAXX = 10**6 + 1 MAXZ = int(math.sqrt(MAXX)+2) furui = [[] for _ in range(MAXX)] furui[1].append(1) count = [0]*MAXX for i in range(2, MAXX): if len(furui[i]) == 0: for k in range(i, MAXX, i): furui[k].append(i) setwise = True pairwise = True for i in range(N): if not setwise and not pairwise: break for fu in furui[num[i]]: count[fu] += 1 if fu > 1 and count[fu] >= N: setwise = False pairwise = False break elif fu > 1 and count[fu] > 1: pairwise = False if pairwise: print('pairwise coprime') elif setwise: print('setwise coprime') else: print('not coprime')
H,W=map(int,input().split()) if H%2==0: if W%2==0: ans=W//2*H else: ans=H//2*W else: if W%2==0: ans=W//2*H else: ans=(W//2+1)*H-H//2 if H==1 or W==1: ans=1 print(ans)
0
null
27,453,570,784,276
85
196
N = int(input()) X = input() def popcnt1(n): return bin(n).count("1") k = [0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1,2,1] #18まで c = 0 for i in range(N): if X[i] == "1": c += 1 m1 = 0 p1 = 0 for i in range(N): if c != 1: if X[i] == "1": m1 += pow(2,N-1-i,c-1) m1 %= c-1 p1 += pow(2,N-1-i,c+1) p1 %= c+1 else: if X[i] == "1": p1 += pow(2,N-1-i,c+1) p1 %= c+1 for i in range(N): if c != 1: if X[i] == "0": B2 = p1 + pow(2,N-1-i,c+1) B2 %= c+1 else: B2 = m1 - pow(2,N-1-i,c-1) B2 %= c-1 else: if X[i] == "0": B2 = p1 + pow(2,N-1-i,c+1) B2 %= c+1 else: print(0) continue S = len(bin(B2)) c2 = popcnt1(B2) if c2 == 0: print(1) else: print(2+k[B2%c2])
c=str(input()) cl=list(c) for i in range(len(cl)): if cl[i].islower(): cl[i]=cl[i].upper() print(cl[i],end='') elif cl[i].isupper(): cl[i] =cl[i].lower() print(cl[i], end='') elif not cl[i].isalpha(): print(cl[i], end='') print('')
0
null
4,908,202,940,318
107
61
from itertools import combinations n = int(input()) l = list(map(int, input().split())) comb = list(combinations(range(n), 3)) ans = 0 for i,j,k in comb: a = l[i] b = l[j] c = l[k] if a == b: continue if b == c: continue if c == a: continue if sum([a,b,c]) <= 2 * max(a,b,c): continue ans += 1 print(ans)
x,y=map(int,input().split()) print("{0} {1} {2:.8f}".format(x//y,x%y,x/y))
0
null
2,803,790,856,032
91
45
N, K = list(map(int, input().split())) p = sorted(list(map(int, input().split())), reverse=False) print(sum(p[:K]))
total,amount=[int(x) for x in input().split()] array=sorted([int(x) for x in input().split()]) print(sum(array[0:amount]))
1
11,606,749,233,242
null
120
120
# input section = raw_input() # map the height of the section height = 0 heights = [0] for p in xrange( len(section) ): if section[p] == '/': height += 1 elif section[p] == '\\': height -= 1 heights.append(height) # search the pools pools = [] water = [] p = 0 while p < len(section): if section[p] == '\\': try: pr = heights[p+1:].index( heights[p] ) pools.append([p, p+1+pr]) p = p+1+pr except: p+=1 else: p+=1 # count for pool in pools: tp = section[pool[0]:pool[1]] depth = 0 s = 0 for p in xrange( len(tp) ): if tp[p] == '/': depth -= 1 elif tp[p] == '\\': depth += 1 s += 2*(depth-1)+1 else: s += depth water.append(s) # print print sum(water) if len(water) == 0: print len(water) else: print len(water), " ".join(map(str, water))
import bisect, collections, copy, heapq, itertools, math, string, sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF = float('inf') 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() X = SS() # 一回の操作でnはN以下になる # 2回目以降の操作はメモ化再帰 # 初回popcountは2種類しかない Xのpopcountから足し引きすればよい pc_X = X.count('1') if pc_X == 0: for i in range(N): print(1) elif pc_X == 1: for i in range(N): if i == X.index('1'): print(0) else: # 1が2つある場合、最後の位が1の場合、奇数 if i == N - 1 or X.index('1') == N - 1: print(2) else: print(1) else: next_X_m1 = 0 next_X_p1 = 0 pc_m1 = pc_X - 1 pc_p1 = pc_X + 1 for i in range(N): if X[i] == '1': next_X_m1 += pow(2, N - 1 - i, pc_m1) next_X_p1 += pow(2, N - 1 - i, pc_p1) dp = [-1] * N dp[0] = 0 def dfs(n): if dp[n] == -1: dp[n] = 1 + dfs(n % bin(n).count('1')) return dp[n] for i in range(N): next = 0 if X[i] == '0': next = (next_X_p1 + pow(2, N - 1 - i, pc_p1)) % pc_p1 else: next = (next_X_m1 - pow(2, N - 1 - i, pc_m1)) % pc_m1 ans = dfs(next) + 1 print(ans) # print(dp) if __name__ == '__main__': resolve()
0
null
4,195,662,506,816
21
107
H = int(input()) W = int(input()) N = int(input()) X = 0 if H <= W: X = N // W if N % W != 0: X = X + 1 else : X = N // H if N % H != 0: X = X + 1 print(X)
n = int(input()) a = list(map(int,input().split())) dic = {} ans = 0 for i in range(n): if i+1-a[i] in dic: ans += dic[i+1-a[i]] if a[i]+(i+1) in dic: dic[(i+1)+a[i]] = dic[(i+1)+a[i]] + 1 else: dic[(i+1)+a[i]] = 1 print(ans)
0
null
57,563,234,737,008
236
157
import sys N = int(sys.stdin.readline().rstrip()) sec = [] for _ in range(N): x, l = map(int, sys.stdin.readline().rstrip().split()) sec.append((x - l, x + l)) sec = sorted(sec, key=lambda x: x[1]) r = -float("inf") ans = 0 for s, t in sec: if r <= s: ans += 1 r = t print(ans)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) es = [] for _ in range(N): x, l = mapint() es.append((x+l, x-l)) es.sort() now = -10**18 idx = 0 ans = 0 while 1: if idx==N: break end, start = es[idx] if start>=now: now = end ans += 1 idx += 1 print(ans)
1
89,875,465,992,220
null
237
237
a, b, c, d = map(int, input().split()) i = 0 i1 = 0 while a > 0: a -= d i += 1 while c > 0: c -= b i1 += 1 if i >= i1: print('Yes') else: print('No')
in_str = input().split(" ") a = int(in_str[0]) b = int(in_str[1]) c = int(in_str[2]) if a < b: if b < c: print("Yes") else: print("No") else: print("No")
0
null
15,119,462,936,138
164
39
from bisect import bisect_left n = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(n): for j in range(i+1, n): ans += bisect_left(L, L[i]+L[j])-j-1 print(ans)
a1=input() a2=[i for i in a1.split()] a3,a4=[a2[i] for i in (0,1)] A,B=int(a3),int(a4) print(max(0,A-2*B))
0
null
169,320,153,883,178
294
291
n,m = map(int,input().split()) p,s = [],[] for _ in range(m): a,b = map(str,input().split()) p.append(a) s.append(b) p = list(map(int,p)) checker = [0] * n penalty = [0] * n ans = 0 for i,j in enumerate(s): if j == "AC" and checker[p[i]-1] == 0: checker[p[i]-1] = 1 elif j == "WA" and checker[p[i]-1] == 0: penalty[p[i]-1] += 1 for k,l in enumerate(checker): if l: ans += penalty[k] print(sum(checker),ans)
N = list(map(int, list(input()))) L = len(N) K = int(input()) dp = [[[0] * (K+1) for j in range(2)] for i in range(L+1)] dp[0][0][0] = 1 for i in range(L): ni = N[i] if ni == 0: for j in range(K): dp[i+1][1][j+1] += dp[i][1][j] * 9 for j in range(K+1): dp[i+1][0][j] += dp[i][0][j] else: for j in range(K+1): dp[i+1][1][j] += dp[i][0][j] for j in range(K): dp[i+1][1][j+1] += (dp[i][0][j] * (ni-1) + dp[i][1][j] * 9) dp[i+1][0][j+1] += dp[i][0][j] for j in range(K+1): dp[i+1][1][j] += dp[i][1][j] print(dp[L][0][K]+dp[L][1][K])
0
null
84,803,320,701,220
240
224
n, k, c = map(int, input().split()) s = str(input()) for i in range(n): if s[i] == 'o': ant = i+1 antlist = [ant] break for i in range(n): if s[n-i-1] == 'o': post = n-i postlist = [post] break for i in range(k-1): ant += c+1 post -= c+1 for i in range(n): if s[ant+i-1] == 'o': ant += i antlist.append(ant) break for i in range(n): if s[post-i-1] == 'o': post -= i postlist.append(post) break postlist.reverse() #print(antlist) #print(postlist) for i in range(k): if antlist[i] == postlist[i]: print(antlist[i])
N, K, C = map(int, input().split()) S = input() L, R = [-1] * K, [-1] * K k = 0; temp = -C for i, s in enumerate(S, 1): if s == 'o' and i > temp + C: L[k] = i; k += 1; temp = i if k == K: break k = K - 1; temp = N + C + 1 for i, s in reversed(list(enumerate(S, 1))): if s == 'o' and i < temp - C: R[k] = i; k -= 1; temp = i if k == -1: break ans = [] for l, r in zip(L, R): if l == r: ans.append(l) for a in ans: print(a)
1
40,692,835,528,800
null
182
182
import sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def S(): return sys.stdin.readline().rstrip() N,T = map(int,S().split()) A = [0] B = [0] for i in range(N): a,b = LI() A.append(a) B.append(b) dp1 = [[0]*(T+1) for i in range(N+1)] # dp[i][j] = 1~i番目から選んでT分以内に食べるときの美味しさの和の最大値 dp2 = [[0]*(T+1) for i in range(N+2)] # dp[i][j] = i~N番目から選んでT分以内に食べるときの美味しさの和の最大値 for i in range(1,N+1): for j in range(T+1): if j >= A[i]: dp1[i][j] = max(dp1[i-1][j],dp1[i-1][j-A[i]]+B[i]) else: dp1[i][j] = dp1[i-1][j] for i in range(N,0,-1): for j in range(T+1): if j >= A[i]: dp2[i][j] = max(dp2[i+1][j],dp2[i+1][j-A[i]]+B[i]) else: dp2[i][j] = dp2[i+1][j] ans = dp1[N][T] for i in range(1,N+1): # 最後にi番目の料理を食べる for j in range(T): ans = max(ans,dp1[i-1][j]+dp2[i+1][T-1-j]+B[i]) print(ans)
numbers = map(long, raw_input().split()) d = numbers[0] / numbers[1] r = numbers[0] % numbers[1] f = float(numbers[0]) / float(numbers[1]) print d, r, ('%.9f' % f)
0
null
75,900,125,561,912
282
45
s = input() q = int(input()) for _ in range(q): x = input().split() a, b = int(x[1]), int(x[2]) if x[0] == 'print': print(s[a:b+1]) if x[0] == 'reverse': s = s[:a] + ''.join(reversed(s[a:b+1])) + s[b+1:] if x[0] == 'replace': s = s[:a] + x[3] + s[b+1:]
import sys if __name__ == '__main__': a, b, c = map(int, input().split()) print(c, a, b)
0
null
19,961,698,680,224
68
178
tmp = input().split() a = int(tmp[0]) b = int(tmp[1]) c = int(tmp[2]) ans = 0 if a == b: if c % a == 0: ans += 1 else: for n in range(a,b + 1): if c % n == 0: ans +=1 else: pass print(ans)
N, M = map(int, input().split()) print(max(-1, N-sum(map(int, input().split()))))
0
null
16,323,537,616,592
44
168
a=raw_input() list=a.split() W=int(list[0]) H=int(list[1]) x=int(list[2]) y=int(list[3]) r=int(list[4]) if r<=x<=W-r and r<=y<=H-r: print 'Yes' else: print 'No'
n, m = map(int, raw_input().split()) A = [] b = [] for i in range(n): A += [map(int, raw_input().split())] for i in range(m): b += [input()] for i in range(n): C = 0 for j in range(m): C += A[i][j] * b[j] print C
0
null
804,864,017,792
41
56
i = int(input()) if i%2==0: x=i/2-1 print(int(x)) else: x=(i-1)/2 print(int(x))
def make_factorial_table(n): result = [0] * (n + 1) result[0] = 1 for i in range(1, n + 1): result[i] = result[i - 1] * i % m return result def mcomb(n, k): if n == 0 and k == 0: return 1 if n < k or k < 0: return 0 return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m m = 1000000007 S = int(input()) fac = make_factorial_table(S + 10) #print(fac) #print(len(fac)) result = 0 for i in range(1, S // 3 + 1): result += mcomb(S - i * 3 + i - 1, i - 1) result %= m print(result)
0
null
78,192,795,410,592
283
79
N = int(input()) A = list(map(int, input().split())) print("APPROVED" if all(a&1 or (a%3==0 or a%5==0) for a in A) else "DENIED")
# A - Connection and Disconnection def count(s, c): count_ = s.count(c*2) while c*3 in s: s = s.replace(c*3, c+'_'+c) while c*2 in s: s = s.replace(c*2, c+'_') return min(count_, s.count('_')) def get_startswith(s, c): key = c while s.startswith(key+c): key += c return len(key) def get_endswith(s, c): key = c while s.endswith(key+c): key += c return len(key) import string S = input() K = int(input()) lower = string.ascii_lowercase ans = 0 if S[0] == S[-1:]: start = get_startswith(S, S[0]) end = get_endswith(S, S[0]) if start == end == len(S): print(len(S) * K // 2) else: ans = 0 ans += start // 2 ans += end // 2 ans += ((start + end) // 2) * (K - 1) for c in lower: ans += count(S[start:len(S)-end], c) * K print(ans) else: for c in lower: ans += count(S, c) print(ans * K)
0
null
122,533,483,264,458
217
296
from collections import deque from math import ceil n,d,a = map(int,input().split()) M = [list(map(int,input().split())) for i in range(n)] M = sorted([(x,ceil(h/a)) for x,h in M]) que = deque() ans = 0 atack = 0 for x,h in M: while len(que) > 0 and que[0][0] < x: tx,ta = que.popleft() atack -= ta bomb_num = max(0, h-atack) atack += bomb_num ans += bomb_num if bomb_num > 0: que.append([x+d*2,bomb_num]) print(ans)
# import dice class dice: def __init__(self): self.top = 1 # self.srf = [[2,4,3,5],[6,4,3,1],[6,2,5,1],[6,5,2,1],[6,4,3,1],[5,4,3,2]] self.bottom = 2 self.up = 5 self.left = 4 self.right = 3 self.reverse = 6 def move(self, dim): if dim == "N": temp = self.top self.top = self.bottom self.bottom = self.reverse self.reverse = self.up self.up = temp elif dim == "E": temp = self.top self.top = self.left self.left = self.reverse self.reverse = self.right self.right = temp elif dim == "W": temp = self.top self.top = self.right self.right = self.reverse self.reverse = self.left self.left = temp elif dim == "S": temp = self.top self.top = self.up self.up = self.reverse self.reverse = self.bottom self.bottom = temp x = [] x = list(map(int, input().split())) mv = [] mv = list(input()) dc = dice() for i in range(len(mv)): dc.move(mv[i]) print(x[dc.top - 1])
0
null
41,346,045,652,588
230
33
a,b = map(int,input().split()) print(a//b,a%b,"{:.5f}".format(a/b))
N = int(input()) edge = [[0] for _ in range(N)] for i in range(N): A = list(map(int, input().split())) for i,a in enumerate(A): A[i] -= 1 edge[A[0]] = sorted(A[2:]) ans = [[0,0] for _ in range(N)] import sys sys.setrecursionlimit(10**8) def dfs(v,now): if len(edge[v])>0: for u in edge[v]: if visited[u]==False: visited[u]=True now += 1 ans[u][0] = now now = dfs(u,now) now += 1 ans[v][1] = now return now visited = [False]*N now = 0 for i in range(N): if visited[i]==False: visited[i]=True now += 1 ans[i][0] = now now = dfs(i,now) for i in range(N): ans[i] = '{} {} {}'.format(i+1,ans[i][0],ans[i][1]) print(*ans,sep='\n')
0
null
305,158,125,800
45
8
n,m=map(int,input().split()) c=list(map(int,input().split())) c.sort(reverse=True) #print(c) dp=[0] for i in range(1,n+1): mini=float("inf") for num in c: if i-num>=0: mini=min(mini,dp[i-num]+1) dp.append(mini) #print(dp) print(dp[-1])
l = input().split() print(int(l.index('0'))+1)
0
null
6,852,235,683,070
28
126
def gcd (a,b): if a%b==0: return b if b%a==0: return a if a>b: return gcd(b,a%b) return gcd(a,b%a) def lcm (a,b): return ((a*b)//gcd(a,b)) inp=list(map(int,input().split())) a=inp[0] b=inp[1] print (lcm(a,b))
import sys x=sys.stdin.readline() arr=x.split() arrInt=list() #print(arr, type(arr)) for i in arr: # print(i) arrInt.append(int(i)) #print(arrInt,type(arrInt)) arrInt.sort() print(' '.join(map(str,arrInt)))
0
null
56,966,983,571,862
256
40
import sys def ISS(): return sys.stdin.readline().rstrip().split() s,t =ISS() print(t+s)
import sys a, b = sys.stdin.readline().split() print(b+a)
1
102,970,766,356,416
null
248
248
n = int(raw_input()) while n > 0: d = map(int, raw_input().split()) d.sort() a = d[0] b = d[1] c = d[2] if (c*c) == (a*a + b*b): print "YES" else: print "NO" n = n-1
n=input() for i in range(n): l=map(int,raw_input().split()) l.sort() if l[0]**2+l[1]**2==l[2]**2:print"YES" else:print"NO"
1
271,721,350
null
4
4
import sys read = sys.stdin.buffer.read def main(): N, D, A, *XH = map(int, read().split()) monster = [0] * N for i, (x, h) in enumerate(zip(*[iter(XH)] * 2)): monster[i] = (x, (h + A - 1) // A) monster.sort() X = [x for x, h in monster] S = [0] * (N + 1) idx = 0 ans = 0 for i, (x, h) in enumerate(monster): d = h - S[i] if d > 0: right = x + 2 * D while idx < N and X[idx] <= right: idx += 1 S[i] += d S[idx] -= d ans += d S[i + 1] += S[i] print(ans) return if __name__ == '__main__': main()
# coding: utf-8 import sys from collections import deque sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def main(): # 左からgreedyに N, D, A = lr() monsters = [] for _ in range(N): x, h = lr() monsters.append((x, h)) monsters.sort() bomb = deque() answer = 0 attack = 0 for x, h in monsters: while bomb: if bomb[0][0] + D < x: attack -= bomb[0][1] bomb.popleft() else: break h -= attack if h > 0: t = -(-h//A) answer += t bomb.append((x + D, A * t)) attack += A * t print(answer) if __name__ == '__main__': main()
1
82,188,054,789,178
null
230
230
from functools import reduce from operator import xor N = int(input()) A = list(map(int, input().split())) XorA = reduce(xor, A) B = [] for a in A: B.append(XorA ^ a) print(*B)
# B - Roller Coaster def main(): cnt = 0 n, k = map(int, input().split()) h = list(map(int, input().split())) print(sum([cnt+1 for v in h if v >= k])) if __name__ == "__main__": main()
0
null
95,774,497,846,368
123
298
''' Rjの最小値を保持することで最大利益の更新判定をn回で終わらせる ''' r = [] n = int(input()) for i in range(n): i = int(input()) r.append(i) minv = r[0] maxv = r[1] - r[0] for j in range(1,n): maxv = max(maxv, r[j]-minv) minv = min(minv, r[j]) print(maxv)
l = 2*10**9 p = -2*10**9 n = int(input()) for _ in range(n): x = int(input()) p = max(x-l,p) l = min(x,l) print(p)
1
13,091,143,838
null
13
13
import sys input = sys.stdin.readline import numpy as np from numba import njit def read(): D = int(input().strip()) C = np.fromstring(input().strip(), dtype=np.int32, sep=" ") S = np.empty((D, 26), dtype=np.int32) for i in range(D): s = np.fromstring(input().strip(), dtype=np.int32, sep=" ") S[i, :] = s[:] M = 10000 RD = np.random.randint(D, size=(M, ), dtype=np.int32) RQ = np.random.randint(26, size=(M, ), dtype=np.int32) DQ = np.stack([RD, RQ]).T return D, C, S, M, DQ @njit def diff_satisfaction(C, S, d, p, last): """d日目にコンテストpを開催するときの、満足度の更新量を求める """ v = 0 for i in range(26): v -= C[i] * (d - last[i]) v += C[p] * (d - last[p]) v += S[d, p] return v @njit def change_schedule(D, C, S, T, d, q, cumsat): """d日目のコンテストをqに変更する """ p = T[d] dp1, dq1 = -1, -1 dp3, dq3 = D, D for i in range(0, d): if T[i] == p: dp1 = i if T[i] == q: dq1 = i for i in range(D-1, d, -1): if T[i] == p: dp3 = i if T[i] == q: dq3 = i cumsat = cumsat - S[d, p] + S[d, q] - C[p] * (dp3-d) * (d-dp1) + C[q] * (dq3-d) * (d-dq1) return cumsat @njit def greedy(D, C, S): T = np.zeros(D, dtype=np.int32) last = -np.ones(26, dtype=np.int32) cumsat = 0 for d in range(D): max_p = 0 max_diff = -999999999 # select contest greedily for p in range(26): diff = diff_satisfaction(C, S, d, p, last) if diff > max_diff: max_p = p max_diff = diff # update schedule cumsat += max_diff T[d] = max_p last[max_p] = d return cumsat, T @njit def solve(D, C, S, M, DQ): cumsat, T = greedy(D, C, S) for i in range(M): d, q = DQ[i, :] newsat = change_schedule(D, C, S, T, d, q, cumsat) if newsat > cumsat: cumsat = newsat T[d] = q for t in T: print(t+1) if __name__ == '__main__': inputs = read() outputs = solve(*inputs) if outputs is not None: print("%s" % str(outputs))
n=int(input()) a=list(map(int,input().split())) t=1 for i in range(n): if a[i]%2==0 and a[i]%3==0: t=1 elif a[i]%2==0 and a[i]%5==0: t=1 elif a[i]%2==1: t=1 else: t=0 break if t==1: print("APPROVED") else: print("DENIED")
0
null
39,344,282,866,538
113
217
a,b,c = map(int,input().split()) K = int(input()) judge = False for i in range(K+1): for j in range(K+1): for k in range(K+1): x = a*2**i y = b*2**j z = c*2**k if i+j+k <= K and x < y and y < z: judge = True if judge: print("Yes") else: print("No")
import collections import sys input = sys.stdin.readline def main(): N = int(input()) S = [input().rstrip() for _ in range(N)] c = collections.Counter(S).most_common() max_freq = None max_S = [] for s, freq in c: if max_freq is None: max_freq = freq max_S.append(s) elif freq == max_freq: max_S.append(s) else: break print('\n'.join(sorted(max_S))) if __name__ == "__main__": main()
0
null
38,588,065,076,964
101
218
def resolve(): N = int(input()) import math print(math.ceil(N/2)) if '__main__' == __name__: resolve()
#!/usr/bin/env python3 from sys import stdin, stdout def solve(): n = int(stdin.readline().strip()) seqA = [] seqB = [] for i in range(n): a,b = map(int, stdin.readline().split()) seqA.append(a) seqB.append(b) seqA = sorted(seqA) seqB = sorted(seqB) mA = seqA[n//2] mB = seqB[n//2] if n%2==0: mA += seqA[n//2-1] mB += seqB[n//2-1] print(mB-mA+1) solve()
0
null
38,114,193,875,680
206
137
s=input() a=len(s) if s[a-1]=='s': print(s+str("es")) else: print(s+str('s'))
N = int(input()) nums = map(int, input().split(" ")) for n in nums: if n % 2 != 0: continue if n % 3 == 0 or n % 5 == 0: continue else: print("DENIED") exit(0) print("APPROVED")
0
null
35,515,253,197,434
71
217
def main(): a, b, c = map(int, input().split()) if 21 < (a + b + c): print('bust') else: print('win') main()
def resolve(): k,x=map(int,input().split()) if k*500 >= x: print("Yes") else: print("No") resolve()
0
null
108,421,007,436,740
260
244
a, b = [int(n) for n in input().split()] print(a*b if 1 <= a <= 9 and 1 <= b <= 9 else '-1')
N = int(input()) L = [] for i in range(N): L.append(input()) print("AC x "+str(L.count('AC'))+ "\nWA x "+str(L.count('WA'))+ "\nTLE x "+str(L.count('TLE'))+ "\nRE x "+str(L.count('RE')))
0
null
83,356,877,847,336
286
109
class Dice: def __init__(self, list1): self.f = list1 def move(self, direct): if direct == "N": self.f[0], self.f[1], self.f[4], self.f[5] = self.f[1], self.f[5], self.f[0], self.f[4] return self.f elif direct == "E": self.f[0], self.f[2], self.f[3], self.f[5] = self.f[3], self.f[0], self.f[5], self.f[2] return self.f elif direct == "S": self.f[0], self.f[1], self.f[4], self.f[5] = self.f[4], self.f[0], self.f[5], self.f[1] return self.f elif direct == "W": self.f[0], self.f[2], self.f[3], self.f[5] = self.f[2], self.f[5], self.f[0], self.f[3] return self.f data = list(map(int, input().split())) direction = input() dice = Dice(data) for i in direction: dice.move(i) print(dice.f[0])
import itertools N = int(input()) l = [] for i in itertools.permutations(list(range(1,N+1))): l.append(i) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) a = 1 b = 1 for i in l: if i < P: a += 1 for i in l: if i < Q: b += 1 print(abs(a-b))
0
null
50,564,972,039,638
33
246
from collections import deque n = int(input()) dq = deque([]) for _ in range(n): L = input().split() if L[0] == 'insert': dq.appendleft(L[1]) elif L[0] == 'delete': if L[1] in dq: dq.remove(L[1]) elif L[0] == 'deleteFirst': dq.popleft() else: dq.pop() print(' '.join(dq))
n = int(input()) a = [int(i) for i in input().split()] a.reverse() print(*a)
0
null
527,165,918,312
20
53
N =input() flag = 0 for i in range(len(N)): if N[i] == "7": flag = 1 break if flag == 1: print("Yes") else: print("No")
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n, *a = map(int, read().split()) r = 0 minp = a[0] for i1 in range(n): if minp >= a[i1]: r += 1 minp = a[i1] print(r) if __name__ == '__main__': main()
0
null
60,004,436,253,790
172
233
from itertools import groupby S=input() K=int(input()) count=0 group=[len(list(value)) for key,value in groupby(S)] for value in group: count+=value//2 count*=K if S[0]==S[-1] and group[0]%2!=0 and group[-1]%2!=0: if len(S)==group[0]: count+=K//2 else: count+=K-1 print(count)
s=str(input()) k=int(input()) ans=0 count=1 c1=0 c2=0 if len(set(s))==1: print(len(s)*k//2) exit() if s[0]==s[-1]: for i in range(len(s)-1): if s[i]==s[i+1]: count+=1 else: if 2<=count: ans+=count//2 count=1 ans+=count//2 i=0 while s[i]==s[0]: c1+=1 i+=1 i=len(s)-1 while s[i]==s[-1]: c2+=1 i-=1 #print(c1,c2) ans*=k if c1%2==1 and c2%2==1: ans+=k-1 print(ans) else: for i in range(len(s)-1): if s[i]==s[i+1]: count+=1 else: if 2<=count: ans+=count//2 count=1 ans+=count//2 print(ans*k)
1
175,613,645,381,798
null
296
296
# -*- coding: utf-8 -*- """ Created on Wed Sep 9 14:33:00 2020 @author: liang """ from math import gcd N, M = map(int, input().split()) A = [int(i) for i in input().split()] flag = False res = 1 for a in A: a //= 2 res *= a//gcd(res,a) if res > M: flag = True break #print(res) """ 存在チェック 2で割り切れる個数同じ? """ for a in A: if int(res/a) == res/a: flag = True if flag: ans = 0 print(ans) else: #ans = (M - res(A)//2)//res + 1 #ans = (M-1)//res//2 + 1 ans= (M//res + 1)//2 print(ans)
#C N=int(input()) A=[int(x) for x in input().split()] P=[0 for i in range(N+1)] P[N]=[A[N],A[N]] for i in range(N-1,-1,-1): MIN,MAX=P[i+1] mi=int(A[i]+(MIN+MIN%2)/2) ma=A[i]+MAX P[i]=[mi,ma] if P[0][0]==1: Q=[0 for i in range(N+1)] Q[0]=1 cnt=1 for i in range(N): Q[i+1]=min((Q[i]-A[i])*2,P[i+1][1]) cnt+=Q[i+1] print(cnt) else: print("-1")
0
null
60,044,061,034,958
247
141
def solve(): N, K, C = map(int, input().split()) workable = [i for i, s in enumerate(input()) if s=="o"] if len(workable) == K: return workable latest = set() prev = workable[-1]+C+1 for x in reversed(workable): if prev - x > C: latest.add(x) prev = x if len(latest) > K: return [] must = [] prev = -C-1 for x in workable: if x - prev > C: if x in latest: must.append(x) prev = x return must for i in solve(): print(i+1)
n, k, c = map(int, input().split()) s = input() left = [-1 for _ in range(k)] right = [-1 for _ in range(k)] bef = -10 ** 10 cnt = 0 for i, ss in enumerate(s): if ss == "o" and i - bef > c: if cnt == k: exit() left[cnt] = i bef = i cnt += 1 cnt = 0 bef = -10 ** 10 for i, ss in enumerate(s[::-1]): if ss == "o" and i - bef > c: if cnt == k: exit() right[k - 1 - cnt] = n - 1 - i bef = i cnt += 1 for ll, rr in zip(left, right): if ll == rr: print(ll + 1)
1
40,514,404,523,360
null
182
182
N = int(input()) print(N**3/27)
# L = x + y + z # S = x*y*z #これをSが最大となるようにyとLの式で表すと # S_max = 1/2 * (L - y) * y * 1/2 * (L - y) = 1/4 * (y**3 - 2*L*y**2 +L**2 * y) L = int(input()) S_list = [] for y in range(L*10**3): y_cal = y / 10**3 s = 1/4 * (y_cal**3 - 2*L*y_cal**2 +L**2 * y_cal) S_list.append(s) S_max = max(S_list) print(S_max)
1
47,235,374,484,740
null
191
191
n, m = map(int, input().split()) V = [set() for _ in range(n)] # 隣接リスト for a, b in [[*map(lambda x: int(x)-1, input().split())] for _ in range(m)]: V[a].add(b) V[b].add(a) from collections import deque G = [-1] * n # グループ色分け for s in range(n): # BFS dq = deque([s]) while dq: p = dq.popleft() if G[p] >= 0: continue G[p] = s # 色付け for c in V[p]: dq.append(c) C = dict() # グループメンバ数集計 for g in G: if not g in C: C[g] = 0 C[g] += 1 print(max(C.values())) # 最大メンバ数
import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy INF = 10**9 """ UnionFind 要素を素集合(互いに素)に分割して管理するデータ構造 O(α)<O(log) 逆アッカーマン関数 """ class UnionFind(): def __init__(self,n): self.n = n self.parents = [-1]*n #各要素の親要素の番号を格納するリスト #要素xが属するグループの根を返す def find(self,x): if self.parents[x]<0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] #要素xと要素yが属するグループを併合する 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 #要素xが属するグループのサイズを返す def size(self,x): return -self.parents[self.find(x)] #要素x,yが同じグループかどうかを返す def same(self,x,y): return self.find(x) == self.find(y) #要素xと同じグループのメンバーを返す def members(self,x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] #すべての根の要素を返す def roots(self): return [i for i,x in enumerate(self.parents) if x<0] #グループの数を返す def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r,self.members(r)) for r in self.roots()) if __name__ == "__main__": n,m = map(int,input().split()) uf = UnionFind(n) for i in range(m): a,b = map(int,input().split()) a-=1 b-=1 uf.union(a,b) ans = 0 for i in range(n): c = uf.size(i) ans = max(ans,c) print(ans)
1
3,959,181,525,280
null
84
84
n=int(input()) G=[] for i in range(n): L=list(map(int,input().split())) G.append(L[2:]) for j in range(len(G[-1])): G[-1][j]-=1 Forder=[-1]*n Lorder=[-1]*n ptr=1 def dfs(v): #print(v) #print(G[v]) #print() global ptr Forder[v]=ptr ptr+=1 for next in G[v]: if Forder[next]!=-1: continue dfs(next) Lorder[v]=ptr ptr+=1 #while True: # #print(Forder,Lorder) # for i in range(n): # if Forder[i]!=-1 and Lorder[i]!=-1: # pass # else: # dfs(i) # continue # # if i==n-1: # break # else: # continue # break # #for i in range(n): # print(i+1,Forder[i],Lorder[i]) ########## for i in range(n): if Forder[i]==-1 or Lorder[i]==-1: dfs(i) for i in range(n): print(i+1,Forder[i],Lorder[i])
import numpy as np from numba import jit R, C, K = map(int, input().split()) G = np.zeros((R+1, C+1), np.int64) for i in range(K): [r, c, v] = list(map(int, input().split())) G[r-1][c-1] = v @jit def main(G, R, C): dp = np.full((R+1, C+1, 4), -1) dp[0][0][0] = 0 if G[0][0] != None: dp[0][0][1] = G[0][0] for r in range(R): for c in range(C): for k in range(4): if dp[r][c][k] == -1: continue if k < 3: # can go right and pick up if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]: dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1] if dp[r][c+1][k] < dp[r][c][k]: dp[r][c+1][k] = dp[r][c][k] if dp[r+1][c][0] < dp[r][c][k]: dp[r+1][c][0] = dp[r][c][k] if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]: dp[r+1][c][1] = dp[r][c][k] + G[r+1][c] return(max(dp[r][c])) ret = main(G, R, C) print(ret)
0
null
2,780,359,297,588
8
94
T=input() tmp=T.replace('?','D') print(tmp)
t=input() print(t.replace("?","D"))
1
18,325,614,516,878
null
140
140
l = len(input()) print("".join(["x" for x in range(l)]))
n=int(input()) s=input() t="" for i in range(len(s)//2): t += s[i] if s == t + t: print("Yes") else: print("No")
0
null
110,125,674,510,330
221
279
def median(q): l = len(q) q = sorted(q, reverse=True) if l%2 == 0: return (q[int(l/2)] + q[int(l/2)-1])/2 else: return q[int((l+1)/2-1)] n = int(input()) a = [] b = [] for i in range(n): x, y = map(int, input().split()) a.append(x) b.append(y) med_a = median(a) med_b = median(b) if n%2 == 0: print(int(2*(med_b - med_a) + 1)) else: print((med_b - med_a) + 1)
N, M = list(map(int, input().split())) A = list(map(int, input().split())) cnt = 0 s = 0 for i in range(N): s += A[i] for i in range(N): if 4*M*A[i] < s: cnt += 1 print(['No', 'Yes'][N - cnt >= M])
0
null
28,083,772,745,980
137
179
S=input() q=int(input()) s=[] r=[] for i in S: s.append(i) t=1 for i in range(q): qv=list(input().split()) if qv[0]=='1': t^=1 else: if int(qv[1])^t==0 or int(qv[1])^t==2: r.append(qv[2]) else: s.append(qv[2]) if t==0: ss=s.copy() s=[] for j in range(len(ss)): s.append(ss[-1-j]) ans=s ans.extend(r) else: rr=r.copy() r=[] for j in range(len(rr)): r.append(rr[-1-j]) ans=r ans.extend(s) answer=''.join(ans) print(answer)
import sys a = sys.stdin.readlines() for i in range(len(a)): b = a[i].split() m =int(b[0]) f =int(b[1]) r =int(b[2]) if m*f < 0 : print "F" elif m==-1 and f==-1 and r==-1: break else: if m+f >= 80: print "A" elif 80 > m+f >=65: print "B" elif 65 > m+f >=50: print "C" elif 50 > m+f >=30 and r < 50: print "D" elif 50 > m+f >=30 and r >= 50: print "C" elif 30 > m+f: print "F"
0
null
29,293,347,017,198
204
57
n, s = map(int, input().split()) print("Yes" if 500*n >= s else "No")
n = int(input()) a = list(map(int,input().split())) c = [0,0,0] count = 1 for i in range(n): match = (a[i]==c[0])+(a[i]==c[1])+(a[i]==c[2]) if match==0: count = 0 break elif match==1 or a[i]==0: c[c.index(a[i])] += 1 else: c[c.index(a[i])] += 1 count = (count*match)%(1e+9+7) if count != 0: c = sorted(c,reverse=True) while 0 in c: c.pop() memory = set() kinds = 0 for x in c: if not x in memory: kinds += 1 for i in range(3,3-kinds,-1): count = (count*i)%(1e+9+7) print(int(count))
0
null
114,226,729,003,768
244
268
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))
a, b, c, d = map(int, input().split()) if d < a: print(d) exit() elif d < a + b: print(a) exit() else: print(a+(-1)*(d-a-b))
1
22,034,737,991,816
null
148
148
# -*- coding: utf-8 -*- """ 全探索 ・再帰で作る ・2^20でTLEするからメモ化した """ N = int(input()) aN = list(map(int, input().split())) Q = int(input()) mQ = list(map(int, input().split())) def dfs(cur, depth, ans): # 終了条件 if cur == ans: return True # memo[現在位置]に数値curがあれば、そこから先はやっても同じだからやらない if cur in memo[depth]: return False memo[depth].add(cur) # 全探索 for i in range(depth, N): if dfs(cur+aN[i], i+1, ans): return True # 見つからなかった return False for i in range(Q): memo = [set() for j in range(N+1)] if dfs(0, 0, mQ[i]): print('yes') else: print('no')
a=int(input()) count1=0 count2=0 count3=0 count4=0 for i in range(a): b=str(input()) count=0 if b=='AC': count1+=1 if b=='RE': count2+=1 if b=='TLE': count3+=1 if b=='WA': count4+=1 print('AC x ',end='') print(count1) print('WA x ',end='') print(count4) print('TLE x ',end='') print(count3) print('RE x ',end='') print(count2)
0
null
4,341,500,560,000
25
109
from sys import stdin A, B, C = [int(_) for _ in stdin.readline().rstrip().split()] K = int(stdin.readline().rstrip()) for i in range(K): if not B > A: B *= 2 elif not C > B: C *= 2 if A < B < C: print("Yes") else: print("No")
#!/usr/bin/env python3 def main(): a, b, c = map(int, input().split()) k = int(input()) for i in range(k): if a < b < c: break elif a >= b: b *= 2 elif b >= c: c *= 2 if a < b < c: print('Yes') else: print('No') if __name__ == "__main__": main()
1
6,888,671,223,552
null
101
101
import sys N,K = map(int,input().split()) array = [ a for a in range(1,N+1) ] for I in range(K): _ = input() sweets = list(map(int,input().split())) for K in sweets: if K in array: array.remove(K) print(len(array))
n, k = map(int, input().split()) a = [1] * n for i in range(k): d = int(input()) tmp = map(int, input().split()) for j in tmp: a[j - 1] = 0 print(sum(a))
1
24,684,921,217,660
null
154
154
import sys input = sys.stdin.readline import numpy as np from collections import defaultdict N,K = map(int,input().split()) # 全要素を-1する A = [0] + [int(i)-1 for i in input().split()] # Acum[i]: A[1]からA[i]までの累積和 Acum = np.cumsum(A) Acum = [i%K for i in Acum] answer = 0 counter = defaultdict(int) # iの範囲で探索 # 1 <= j <= N # j-K+1 <= i <= j-1 for j,x in enumerate(Acum): # (i-K+1)回目から(i-1)回目の探索において、xの出現回数 answer += counter[x] # i回目の結果を辞書に追加 counter[x] += 1 # 辞書にK回追加した場合 if j-K+1 >= 0: # 辞書から一番古い探索記録を削除 counter[Acum[j-K+1]] -= 1 print(answer)
from sys import stdin # read input n,m = [int(x) for x in stdin.readline().strip().split()] sc_dict = {} # create dict for _ in range(m): s, c = [int(x) for x in stdin.readline().strip().split()] if s in sc_dict.keys(): sc_dict[s].append(c) else: sc_dict[s] = [c] # get min min_val = list(str(10**(n-1))) if n > 1 else ['0'] for k, v in sc_dict.items(): if len(v) != 1 and len(set(v)) > 1: print('-1') exit() min_val[k-1] = str(v[0]) min_val = ''.join(min_val) if len(min_val) > 1 and int(min_val) == 0: print('-1') else: print(''.join(min_val))
0
null
98,827,426,948,316
273
208
j = [] for i in range(10) : j.append(int(input())) j.sort(reverse = True) for k in range(3) : print(j[k])
for i in sorted([input() for _ in xrange(10)])[:-4:-1]: print i
1
11,702,532
null
2
2
import bisect def is_ok(a, target, m): num = 0 for val in a: index = bisect.bisect_left(a, target - val) num += len(a) - index if num <= m: return True else: return False n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() ok, ng = 10 ** 10, -1 while ok - ng > 1: mid = (ok + ng) // 2 if is_ok(a, mid, m): ok = mid else: ng = mid rui = [0] * (n + 1) for i in range(n): rui[i+1] = rui[i] + a[i] cnt = 0 ret = 0 for val in a: index = bisect.bisect_left(a, ok - val) num = len(a) - index cnt += num ret += (num * val) + (rui[-1] - rui[index]) ret += (m - cnt) * ng print(ret)
n = int(input()) count_ac, count_wa, count_tle, count_re = 0, 0, 0, 0 for i in range(n): s = input() if s == "AC": count_ac += 1 if s == "WA": count_wa += 1 if s == "TLE": count_tle += 1 if s == "RE": count_re += 1 print("AC x", count_ac) print("WA x", count_wa) print("TLE x", count_tle) print("RE x", count_re)
0
null
58,430,973,151,448
252
109
tmp = input().split(" ") S = int(tmp[0]) W = int(tmp[1]) if S <= W: print("unsafe") else: print("safe")
h = int(input()) w = int(input()) n = int(input()) a = 0 b = 0 c = 0 d = 0 for i in range(h): a += w b += 1 if a >= n: break for i in range(w): c += h d += 1 if c >= n: break if b > d: print(d) else: print(b)
0
null
58,772,499,818,790
163
236
list = [] while True: line = raw_input().split(" ") if line[0] == "0" and line[1] == "0": break line = map(int, line) #print line if line[0] > line[1]: temp = line[0] line[0] = line[1] line[1] = temp print " ".join(map(str, line))
while True: (x, y) = [int(i) for i in input().split()] if x == y == 0: break if x < y: print(x, y) else: print(y, x)
1
534,317,636,908
null
43
43
import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int,readline().split())) DIV = 10 ** 9 + 7 # 各桁の1と0の数を数えて、((1の数) * (0の数)) * (2 ** i桁目(1桁目を0とする))を数える K = max(A) # 最も大きい数が0になるまでループ ans = 0 j = 0 while K: one = 0 for i in range(len(A)): if (A[i] >> j) & 1: one += 1 ans += (one % DIV) * ((N - one) % DIV) * pow(2,j,DIV) ans %= DIV j += 1 K >>= 1 print(ans)
N = int(input()) S = [""] * N T = [0] * N for i in range(N): s, t = input().split() S[i] = s T[i] = int(t) X = input() t = 0 for i in range(N): t += T[i] if S[i] == X: break print(sum(T) - t)
0
null
110,212,934,593,710
263
243
n,x,t = map(int,input().split()) if n % x ==0: print(int(n/x*t)) else: print(int((n//x+1)*t))
n,x,t=map(int, input().split()) tako = n//x amari = n%x ans = tako*t if amari != 0: ans += t print(ans)
1
4,247,854,310,300
null
86
86
n=int(input()) A=list(map(int,input().split())) x=1 A.sort() if 0 in A: print(0) exit() for i in range(n): x*=A[n-i-1] if x>10**18: print(-1) exit() else: continue print(x)
def solve(): N = int(input()) A = [int(i) for i in input().split()] ans = 1 for i in range(N): if ans == -1 and A[i] != 0: continue ans *= A[i] if ans > 10**18: ans = -1 print(ans) if __name__ == "__main__": solve()
1
16,240,228,852,558
null
134
134
import sys nyuukyosha = [] for tou in range(4): nyuukyosha.append([]) for kai in range(3): nyuukyosha[tou].append([]) for heya in range(10): nyuukyosha[tou][kai].append(0) n = int(raw_input()) for i in range(n): data = map(int, raw_input().split()) a = data[0] - 1 b = data[1] - 1 c = data[2] - 1 nyuukyosha[a][b][c] += data[3] for tou in range(4): for kai in range(3): for heya in range(10): sys.stdout.write(" {:}".format(nyuukyosha[tou][kai][heya])) print("") if tou < 3: print("####################")
n,m=map(int,input().strip().split(' ')) if n % 2 == 1: for i in range(1,m+1): print(i,n-i) else: used=set() prev = n+1 for i in range(1,m+1): prev-=1 if abs(i-prev)*2==n: prev-=1 while abs(i-prev) in used: prev-=1 print(i,prev) used.add(abs(i-prev)) used.add(n-abs(i-prev))
0
null
14,749,166,080,954
55
162
import math x = math.pi r = int(input()) x = 2*x*r print(x)
r = int(input()) print((r + r) * 3.14)
1
31,381,488,111,630
null
167
167
n, m = map(int, input().split()) listAC = [0] * n listWAAC = [0] * n listWA = [0] * n for i in range(m): p, s = map(str, input().split()) p = int(p) - 1 if listAC[p] == 1: continue if s == 'AC': listAC[p] += 1 listWAAC[p] += listWA[p] continue listWA[p] += 1 print(sum(listAC), sum(listWAAC))
al = 'abcdefghijklmnopqrstuvwxyz' text = '' while True: try: text += input().lower() except EOFError: break for i in al: print('{} : {}'.format(i, text.count(i)))
0
null
47,830,529,835,312
240
63
#!/usr/bin/env python from fractions import gcd def main(): A, B = map(int, input().split()) print(A * B // gcd(A, B)) if __name__ == '__main__': main()
a, b = map(int, input().split()) i = 1 while True: x = a * i if x % b == 0: print(x) exit() i += 1
1
113,401,204,317,280
null
256
256
#!/usr/bin/env python from fractions import gcd def main(): A, B = map(int, input().split()) print(A * B // gcd(A, B)) if __name__ == '__main__': main()
N = int(input()) if N % 2: p = ((N//2)+1) / N else: p = (N//2) / N print(p)
0
null
144,885,508,843,272
256
297
# ABC152 a, b = map(int, input().split()) print(min(str(a)*b, str(b)*a))
def main(): a, b = map(int, input().split()) str_a = str(a) * b str_b = str(b) * a if str_a < str_b: print(str_a) else: print(str_b) if __name__ == '__main__': main()
1
84,575,961,044,912
null
232
232
x = [1,2,3,4,5,6,7,8,9] y = [1,2,3,4,5,6,7,8,9] for w in x : for c in y : print(w,"x",c,"=",w*c,sep="")
import sys write=sys.stdout.write for i in range(1,10): for j in range(1,10): write(str(i)) write('x') write(str(j)) write('=') write(str(i*j)) print()
1
1,782,660
null
1
1
import sys from collections import deque def read(): return sys.stdin.readline().rstrip() def main(): n, m, k = map(int, read().split()) friend = [[] for _ in range(n)] block = [set() for _ in range(n)] potential = [set() for _ in range(n)] for _ in range(m): a, b = [int(i) - 1 for i in read().split()] friend[a].append(b) friend[b].append(a) for _ in range(k): c, d = [int(i) - 1 for i in read().split()] block[c].add(d) block[d].add(c) sd = set() for u in range(n): if u in sd: continue sn = deque([u]) pf = set() while sn: p = sn.pop() if p in sd: continue sd.add(p) pf.add(p) for f in friend[p]: sn.append(f) for pfi in pf: potential[pfi] = pf print(*[len(potential[i]) - len(block[i] & potential[i]) - len(friend[i]) - 1 for i in range(n)]) if __name__ == '__main__': main()
h,w,k = list(map(int,input().split())); arr = [[int(i) for i in input()] for _ in range(h)] from itertools import product ans = 2000 for cond in product([True,False],repeat=(h-1)): cut = sum(cond) splits = [arr[0][:]] for i in range(1,h): if cond[i-1]: splits.append(arr[i][:]) else: splits[-1] = [splits[-1][j]+arr[i][j] for j in range(w)] check = [max(i) for i in splits] if max(check) > k: break count = [i[0] for i in splits] div = cut for j in range(1,w): addarr = [count[i]+splits[i][j] for i in range(cut+1)] if max(addarr) > k: div += 1 count = [splits[i][j] for i in range(cut+1)] else: count = addarr[:] ans = min(ans,div) print(ans)
0
null
54,853,156,612,100
209
193
H = int(input()) W = int(input()) N = int(input()) print(int(N/max(H,W)) + (1 if N % max(H,W) != 0 else 0))
# n, k = map(int, input().split()) # from collections import OrderedDict # d = OrderedDict() # a = list(input().split()) # b = list(map(int, input().split())) # print(r + max(0, 100*(10-n))) # print("Yes" if 500*n >= k else "No") # s = input() a = int(input()) b = int(input()) c = int(input()) print((c+max(a, b)-1)//max(a, b))
1
88,960,958,802,690
null
236
236
import numpy as np N = int(input()) A = np.array([int(i) for i in input().split()]) A_sort = np.sort(A) #print(A_sort) score = 0 score += A_sort[-1] for i in range(0, (N-2)//2): score += A_sort[-2-i] * 2 if (N-2) % 2 == 1: score += A_sort[-3-i] print(score)
x=input() x=int(x) if x>=30: print('Yes') else: print("No")
0
null
7,438,717,172,480
111
95
s=[input() for _ in range(int(input()))] def c(b):return str(s.count(b)) x=' x ' n='\n' a='AC' w='WA' t='TLE' r='RE' print(a+x+c(a)+n+w+x+c(w)+n+t+x+c(t)+n+r+x+c(r))
N=int(input()) S=[input()for _ in range(N)] from collections import* C=Counter(S) print('AC','x',C['AC']) print('WA','x',C['WA']) print('TLE','x',C['TLE']) print('RE','x',C['RE'])
1
8,679,845,084,846
null
109
109
# import time N,P = list(map(int,input().split())) S = input() if P == 2: c = 0 for i in range(N): u = int(S[i]) if u % 2 == 0: c += i+1 print(c) elif P == 5: c = 0 for i in range(N): u = int(S[i]) if u % 5 == 0: c += i+1 print(c) else: U = [0] a = 0 t = 1 for i in range(N): t %= P a += int(S[-i-1])*t a %= P t *= 10 U.append(a) U.append(10001) # print(U) # t3 = time.time() c = 0 """ for i in range(P): m = U.count(i) c += m*(m-1)//2 print(c) """ U.sort() # print(U) idx = 0 q = -1 for i in range(N+2): if q != U[i]: q = U[i] m = i - idx idx = i c += m*(m-1)//2 print(c) # t4 = time.time() # print(t4-t3) # 10032
''' 0から9までの数字から成る長さNの文字列Sの部分文字列の内、 十進数表記の整数とみなした時、素数Pで割り切れるものの個数を求めよ。 部分文字列は先頭が0であっても良く、文字列の位置で区別する。 terms: 1<=n<=2*10**5 2<=p<=10**4 input: 4 3 3543 output: 6 ''' from collections import defaultdict import sys input = sys.stdin.readline INF = float('inf') mod = 10 ** 9 + 7 eps = 10 ** -7 def inpl(): ''' 一行に複数の整数 ''' return list(map(int, input().split())) n, p = inpl() s = input()[:-1] arr = [int(s[i]) for i in range(n)] ans = 0 if p == 2 or p == 5: ''' 10を割り切ると桁の話が使えないので場合分け 1の位が割り切れればそれだけ ''' for i in range(n): if arr[i] % p == 0: ans += i + 1 print(ans) else: ''' Pが10の約数である2,5だと以下の仮定が成り立たないので使えない ・ある数XがPで割り切れるならそれを10倍したものもPで割り切れる f(i)=Sの下i桁をPで割った時の余り として、f(i)=f(j)になる組を考える。 するとiからj桁目までの値はPで割り切れる(i%p-j%p≡(i-j)%p) pow(x,y,z)=x^y%z ''' dic = defaultdict(int) # dic = { 余り: 個数} now = 0 dic[0]=1 # 余り0ならまず条件一致。それ以外だったら同じあまりが出た時点で条件一致 for i in range(n-1,-1,-1): #下i桁をpで割った余り now += arr[i] * pow(10, n - 1 - i, p) now %= p ans+=dic[now] dic[now] += 1 print(ans)
1
58,211,685,007,728
null
205
205
def solve(): 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() dp = [[0] * T for i in range(N + 1)] for i, AB_i in enumerate(AB, start=1): A_i, B_i = AB_i dp_i = dp[i] dp_pre = dp[i-1] dp_i[:A_i] = dp_pre[:A_i] for j, t in enumerate(zip(dp_pre[A_i:], dp_pre), start=A_i): x, y = t if x < y + B_i: dp_i[j] = y + B_i else: dp_i[j] = x ans = max(dp[k][-1] + AB[k][1] for k in range(N)) print(ans) solve()
def main(): N, T = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N)] dp = [-1] * (T + 3000) dp[0] = 0 c = 0 for a, b in sorted(AB): for j in range(c, -1, -1): if dp[j] == -1: continue t = dp[j] + b if dp[j + a] < t: dp[j + a] = t c = min(c + a, T - 1) print(max(dp)) main()
1
151,459,959,111,272
null
282
282
n=input() data=input().split() data.reverse() print(' '.join(data))
def resolve(): a, b, m = map(int, input().split()) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) ans = min(a_list) + min(b_list) for _ in range(m): x, y, c = map(int, input().split()) ans = min(ans, a_list[x-1]+b_list[y-1]-c) print(ans) resolve()
0
null
27,394,035,241,030
53
200
def func(A): result = 0 min = 0 for a in A: if a < min: result += min - a else: min = a return result if __name__ == "__main__": N = int(input()) A = list(map(int,input().split())) print(func(A))
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return map(fn, readline().split()) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): h = gete(int) w = gete(int) n = gete(int) if h < w: h, w = w, h print((h + n - 1) // h) if __name__ == "__main__": main()
0
null
46,724,895,004,398
88
236
a,b = list(map(int,input().split())) print("%d %d %f" % ((a//b),(a%b),float((a/b))))
N=int(input()) if N % 2 or N < 10: print(0) exit() ans = 0 i = 1 while 2*5**i<=N: ans += N // (2*5**i) i += 1 print(ans)
0
null
58,486,926,173,884
45
258
from math import ceil from functools import reduce print(reduce(lambda x, y: int(ceil(int(ceil(100000 * 1.05 / 1000) * 1000) * 1.05 / 1000) * 1000) if x == 0 else int(ceil(x * 1.05 / 1000) * 1000) , range(int(input()))))
def fibonacciDP(i): if i == 0: return 1 elif i == 1: return 1 else: if dp[i-1] is None and dp[i-2] is None: dp[i-1] = fibonacciDP(i-1) dp[i-2] = fibonacciDP(i-2) elif dp[i-1] is None: dp[i-1] = fibonacciDP(i-1) elif dp[i-2] is None: dp[i-2] = fibonacciDP(i-2) return dp[i-1]+ dp[i-2] def fibonacci(i): if i == 0: return 1 elif i == 1: return 1 else: return fibonacci(i-1)+fibonacci(i-2) n = int(input()) dp = [None]*n print(fibonacciDP(n))
0
null
1,525,417,542
6
7
n=int(input()) a=[[[0 for _ in range(10)]for _ in range(3)]for _ in range(4)] for i in range(n): b,f,r,v=map(int, input().split()) a[b-1][f-1][r-1]+=v for bb in range(4): for ff in range(3): print(*[""]+a[bb][ff]) if bb==3: break else: print("#"*20)
line = int(input()) nums = [[[0 for x in range(0, 10)] for x in range(0, 3)] for x in range(0, 4)] input1 = [] for i in range(line): input1.append(input()) for e in input1: efbv = e.split(" ") e_b, e_f, e_r, e_v = map(int, efbv) nums[e_b - 1][e_f - 1][e_r -1] += e_v for b in range(4): for f in range (3): print(" " + " ".join(map(str, nums[b][f]))) if b != 3: print("#" * 20)
1
1,099,706,728,448
null
55
55
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return map(list, zip(*read_all)) ################# R,C,K = LI() r,c,v = LIR(K,3) def index(i,j,k): return k*C*R + i*C + j a = [[0]*C for _ in range(R)] for i in range(K): a[r[i]-1][c[i]-1] = v[i] dp = [0]*(4*C*R) dp[index(0,0,1)] = a[0][0] for i in range(R): for j in range(C): if i == j == 0: continue upper_max = 0 if i >= 1: for k in range(4): upper_max = max(upper_max,dp[index(i-1,j,k)]) for k in range(4): val1 = 0 val2 = 0 val3 = 0 val4 = 0 if j >= 1: val1 = dp[index(i,j-1,k)] if k == 0 and i >= 1: val2 = upper_max if a[i][j] != 0: if k == 1 and i >= 1: val3 = upper_max + a[i][j] if k >= 1 and j >= 1: val4 = dp[index(i,j-1,k-1)] + a[i][j] dp[index(i,j,k)] = max(val1,val2,val3,val4) ans = 0 for k in range(4): ans = max(ans,dp[index(R-1,C-1,k)]) print(ans)
R,C,K=map(int,input().split()) V=[[0 for _ in range(C)] for _ in range(R)] for i in range(K): r,c,v=map(int,input().split()) V[r-1][c-1]=v dp=[[0 for _ in range(4)] for _ in range(C+1)] for i in range(R): ndp=[[0 for _ in range(4)] for _ in range(C+1)] for j in range(C): ndp[j][0]=max(dp[j]) for j in range(C): v=V[i][j] for n in range(1,4): ndp[j][n]=max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n]) dp=ndp print(max(dp[C-1]))
1
5,537,662,012,148
null
94
94
a,b = [int(x) for x in input().split()] def gcd(x,y): if y == 0: return x return gcd(y,x%y) print(a*b//gcd(a,b))
A, B = map(int,input().split()) import math c = math.gcd(A,B) d = (A*B) / c print(int(d))
1
113,201,988,324,670
null
256
256
A,B,C,D = map(int,input().split()) while(True): C -= B if C <= 0: print("Yes") break A -= D if A<= 0: print("No") break
print(2**int(input()).bit_length()-1)
0
null
55,187,834,902,938
164
228
N = int(input()) S = input() ans = 0 pre = None for s in S: ans += (pre != s) pre = s print(ans)
N = int(input()) A = [int(a) for a in input().split()] print((sum(A)**2 - sum([a**2 for a in A]))//2)
0
null
169,111,899,240,252
293
292
num1, num2 = map(int, input().split()) print(num1*num2)
list = input().split(" ") a = int(list[0]) b = int(list[1]) print(a * b)
1
15,908,985,187,380
null
133
133
x,y = map(int, input().split()) ans = 'No' for i in range(x+1): for j in range(y+1): if i + j > x: continue if i*2 + j*4 == y and i+j == x: ans = 'Yes' print(ans)
a,b = map(int,input().split()) leg = 0 for i in range(0,a+1): if 2*i +4*(a-i) == b: print('Yes') exit() print('No')
1
13,757,492,372,068
null
127
127
def judge(): if t > h: point["t"] += 3 elif t < h: point["h"] += 3 else: point["t"] += 1; point["h"] += 1 n = int(input()) point = {"t": 0, "h": 0} for i in range(n): t, h = input().split() judge() print(point["t"], point["h"])
# -*- coding: utf-8 -*- import math import itertools import sys import copy # 入力 #A, B, C, D = map(int, input().split()) #L = list(map(int, input().split())) #S = list(str(input())) #N = int(input()) X, Y = map(int, input().split()) sum = 0 if X == 1 : sum += 300000 elif X == 2 : sum += 200000 elif X == 3 : sum += 100000 if Y == 1 : sum += 300000 elif Y == 2 : sum += 200000 elif Y == 3 : sum += 100000 if X == 1 and Y == 1 : sum += 400000 print (sum)
0
null
71,202,070,781,792
67
275
x,y = map(int,input().split()) k = [0,3,2,1] + [0]*1000 ans = k[x]+k[y] if x == y == 1: ans += 4 print(ans*100000)
X,Y=map(int,input().split());m=4-min(X,Y) if X==Y==1:print(10**6) elif X<=3and Y<=3:print(((4-X)+(4-Y))*10**5) else:print(m*10**5if m>=0else 0)
1
140,828,610,303,392
null
275
275
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from functools import reduce, lru_cache import functools import collections, heapq, itertools, bisect import math, fractions import sys, copy def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline().rstrip()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline().rstrip()) 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) dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 def main(): N = I() A = LI() C0, C1 = [0] * 60, [0] * 60 for d in range(60): for ai in A: C0[d] += (ai >> d & 1) == 0 C1[d] += (ai >> d & 1) == 1 ans = 0 for (d, (a, b)) in enumerate(zip(C0, C1)): ans = (ans + a * b * (1 << d % MOD)) % MOD print(ans % MOD) if __name__ == '__main__': main()
n, *a = map(int, open(0).read().split()) mod = 10 ** 9 + 7 ans = 0 for i in range(60): cnt = 0 for j in range(n): cnt += a[j] >> i & 1 ans = (ans + (1 << i) * cnt * (n - cnt) % mod) % mod print(ans)
1
122,470,407,664,110
null
263
263
N, K = map(int, input().split()) A = list(map(int, input().split())) if K == 1: print(0) else: S, LUT, ans = [0], {0: 1}, 0 for a in A: S.append(S[-1] + a) for i in range(1, N + 1): p = (S[i] - i) % K ans += LUT.get(p, 0) LUT[p] = LUT.get(p, 0) + 1 if i - K + 1 >= 0: LUT[(S[i - K + 1] - i + K - 1) % K] -= 1 print(ans)
def main(): l = list(str(input())) num = len(l) for i in range(num): if l[i] == '7': print('Yes') return print('No') main()
0
null
85,913,682,956,672
273
172
s = input() a = s.replace('hi', '') if len(a)==0: print('Yes') else: print('No')
s = input() hitachi = "" for i in range(5): hitachi += "hi" if s==hitachi: print("Yes") exit(0) print("No")
1
53,103,210,943,738
null
199
199
class Matrix: def __init__(self, rows, cols, values=None): self.rows = rows self.cols = cols if values is not None: self.values = values else: row = [0 for i in range(cols)] self.values = [row[:] for j in range(rows)] def row(self, i): return self.values[i-1] def col(self, j): return [row[j-1] for row in self.values] def __mul__(self, other): assert self.cols == other.rows m = self.__class__(self.rows, other.cols) for i in range(self.rows): for j in range(other.cols): m[i, j] = sum(a * b for (a, b) in zip(self.row(i), other.col(j))) return m def __getitem__(self, idx): row, col = idx return self.values[row-1][col-1] def __setitem__(self, idx, val): row, col = idx self.values[row-1][col-1] = val def __str__(self): s = [] for row in self.values: s.append(" ".join([str(i) for i in row])) return "\n".join(s) def run(): n, m, l = [int(v) for v in input().split()] m1 = [] for i in range(n): m1.append([int(v) for v in input().split()]) m2 = [] for i in range(m): m2.append([int(v) for v in input().split()]) print(Matrix(n, m, m1) * Matrix(m, l, m2)) run()
# n??m????????? A ??¨ m??l ????????? B ?????\??????????????????????????§?????? n??l ????????? C ???????????????????????°?????? n, m, l = map(int, input().split()) # n x m ??????????????? A = [[0 for i in range(m)] for j in range(n)] # m x l ??????????????? B = [[0 for i in range(l)] for j in range(m)] # n x l ??????(????????????)????????? C = [[0 for i in range(l)] for j in range(n)] # m x n ??????????¨??????\????????????????????? for i in range(0, n): A[i][:m] = map(int, input().split()) # print(sheet_nxm) # m x n ??????????¨??????\????????????????????? for i in range(0, m): B[i][:l] = map(int, input().split()) # print(sheet_mxl) # C(n x l)??????????¨???????A????????¨B???????????? for i in range(0, n): for j in range(0, l): for k in range(0, m): C[i][j] += A[i][k] * B[k][j] # print(C) # C??????????????? for i in range(0, n): for j in range(0, l): print("{0}".format(C[i][j]), end="") if j != l - 1: print(" ", end="") else: print("")
1
1,444,956,592,482
null
60
60
def resolve(): x,y=(int(i) for i in input().split()) if x==1 and y==1: print(1000000) return c=0 if x==1: c+=300000 if x==2: c+=200000 if x==3: c+=100000 if y==1: c+=300000 if y==2: c+=200000 if y==3: c+=100000 print(c) if __name__ == "__main__": resolve()
h, n = map(int, input().split()) print("Yes" if sum(map(int, input().split())) >= h else "No")
0
null
109,507,313,681,530
275
226
def resolve(): X = int(input()) m = 100 cnt = 0 while m < X: m += m//100 cnt += 1 print(cnt) if '__main__' == __name__: resolve()
s=list(input()) n=len(s) k=int(input()) count=[] i=0 while i<=n-1: j=0 while i+j+1<=n-1 and s[i+j]==s[i+j+1]: j+=1 count.append(j+1) i+=(j+1) length=len(count) if length==1: print((n*k)//2) else: if s[0]==s[-1]: ans=0 for l in range(length): if l!=0 and l!=length-1: ans+=(count[l]//2)*k ans+=(count[0]//2+count[-1]//2) ans+=((count[0]+count[-1])//2)*(k-1) print(ans) else: ans=0 for m in count: ans+=(m//2)*k print(ans)
0
null
101,023,200,040,688
159
296
n, k = map(int, input().split()) ans = 0 for i in range(k, n+2): l = (i*(i-1))*0.5 h = (i*(2*n-i+1))*0.5 ans += (h-l+1) print(int(ans) % (10**9+7))
n,k=map(int,input().split()) DIV = 10**9+7 count = 0 for i in range(k,n+2): min_k = i*(i-1)/2 max_k = i*(2*n-i+1)/2 count += max_k - min_k + 1 print(int(count % DIV))
1
33,172,506,631,720
null
170
170
array = input().split() stack = [] while True: if len(array) == 0: break e = array.pop(0) if e.isdigit(): stack.append(e) else: num1 = stack.pop() num2 = stack.pop() stack.append(str(eval(num2 + e + num1))) print(stack[0])
Stack=[] def push(x): Stack.append(x) def pop(): return Stack.pop() def solve(): s_list=raw_input().split() for i in range(len(s_list)): if s_list[i]=='+': b=pop() a=pop() push(a+b) elif s_list[i]=='-': b=pop() a=pop() push(a-b) elif s_list[i]=='*': b=pop() a=pop() push(a*b) else: push(int(s_list[i])) print(pop()) def main(): if __name__=="__main__": solve() main()
1
38,211,229,980
null
18
18
H = int(input()) i = len(bin(H))-2 print(2**i-1)
import sys def input(): return sys.stdin.readline()[:-1] N,D,A=map(int,input().split()) s=[tuple(map(int, input().split())) for i in range(N)] s.sort() d=2*D+1 t=0 p=0 l=[0]*N a=0 for n,i in enumerate(s): while 1: if t<N and s[t][0]<i[0]+d: t+=1 else: break h=i[1]-p*A if h>0: k=-(-h//A) a+=k p+=k l[t-1]+=k p-=l[n] print(a)
0
null
81,256,801,937,178
228
230
str = raw_input() li = [] for a in list(str): if a.islower(): li.append(a.upper()) elif a.isupper(): li.append(a.lower()) else: li.append(a) print "".join(li)
def abc177_e(): n = int(input()) A = [int(x) for x in input().split()] def prime_factorize(n:int)->set: ''' nの素因数分解 ''' arr = [] while n % 2 == 0: arr.append(2) n = n // 2 f = 3 while f*f <= n: if n%f == 0: arr.append(f) n = n // f else: f += 2 if n != 1: arr.append(n) return set(arr) import math gcd_all = A[0] factors = [0]*(10**6 + 1) pairwise = True for ai in A: gcd_all = math.gcd(gcd_all, ai) for p in prime_factorize(ai): if factors[p]: pairwise = False factors[p] = 1 if pairwise: ans = 'pairwise coprime' elif gcd_all == 1: ans = 'setwise coprime' else: ans = 'not coprime' print(ans) if __name__ == '__main__': abc177_e()
0
null
2,781,840,222,880
61
85
t = str(input()) ans = t.replace("?","D") print(ans)
t=input() result='' for i in range(len(t)-1): if t[i]=='?': try: if result[i-1]=='P': result+='D' else: if t[i+1]=='P': result+='D' else: result+='P' except: if t[i+1]=='P': result+='D' else: result+='P' else: result+=t[i] if t[len(t)-1]=='?' or t[len(t)-1]=='D': print(result+'D') else: print(result+'P')
1
18,475,828,826,840
null
140
140