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 sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # 998244353 input=lambda:sys.stdin.readline().rstrip() def resolve(): just, less = 0, INF for d in input()[::-1]: d = int(d) njust = min(just + d, less + d + 1) nless = min(just + (10-d), less + (9-d)) just, less = njust, nless print(min(just, less + 1)) resolve()
N = int(input()) A = sorted(map(int, input().split())) X = 0 Y = 0 B = [] for i in range(N-2): X = i + 1 for j in range(X,N-1): Y = j + 1 for k in range(Y, N): if A[k] < A[i] + A[j]: if A[k] != A[i] and A[i] != A[j] and A[k] != A[j]: B.append((A[i],A[j],A[k])) print(len(B))
0
null
37,749,985,625,770
219
91
n = int(input()) n_li = list(map(int, input().split())) q = int(input()) q_li = list(map(int, input().split())) ans = [0]*q tmp_li = [] for i in range(2**n): check = [0]*n for j in range(n): if ((i >> j) & 1): check[n - 1 - j] = 1 tmp = 0 for a in range(n): if check[a] == 1: tmp += n_li[a] tmp_li.append(tmp) for k in range(q): if q_li[k] in tmp_li: ans[k] = 1 for x in ans: if x == 1: print('yes') else: print('no')
N = int(input()) if N%1000 == 0: print(0) else: print((int(N/1000)+1)*1000-N)
0
null
4,242,791,417,060
25
108
n = int(input()) a = [n] if n != 2: a.append(n - 1) def div_(N, k): while N % k == 0: N /= k if N % k == 1: a.append(k) for k in range(2, int(n ** 0.5) + 1): if n % k == 0: div_(n,k) if k != n / k: div_(n, n // k) if (n - 1) % k == 0: a.append(k) if k != (n - 1) / k: a.append((n - 1) // k) print(len(a))
def make_divisors(n): div=[n] for i in range(2,-int(-n**0.5//1)): if n%i==0: div.append(i) div.append(n//i) if n%(n**0.5)==0: div.append(int(n**0.5)) div.sort() return div n=int(input()) if n>2: ans=make_divisors(n-1) else: ans=[] for i in make_divisors(n): a=n while a%i==0: a=a//i if a%i==1: ans.append(i) print(len(ans))
1
41,344,797,664,060
null
183
183
n = int(input()) out = '' for i in range(3,n+1): if i % 3 == 0: out += ' {0}'.format(i) continue elif i % 10 == 3: out += ' {0}'.format(i) continue n = i while n // 10: n = n // 10 if n % 10 == 3: out += ' {0}'.format(i) n = 0 print(out)
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from itertools import permutations, accumulate, combinations, combinations_with_replacement from math import sqrt, ceil, floor, factorial from bisect import bisect_left, bisect_right, insort_left, insort_right from copy import deepcopy from operator import itemgetter from functools import reduce, lru_cache # @lru_cache(None) from fractions import gcd import sys def input(): return sys.stdin.readline().rstrip() sys.setrecursionlimit(10**6) # ----------------------------------------------------------- # s = input() print(s[:3])
0
null
7,861,262,748,300
52
130
import math a, b, deg = map(int, input().split()) rad = math.radians(deg) S = a * b * math.sin(rad) / 2 c = (a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)) ** (1 / 2) L = a + b + c h = S * 2 / a print(S,L,h)
import math a,b, A = map(float, input().split()) h = b*math.sin(math.radians(A)) S = a*h*0.5 L = a + b + math.sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*math.cos(math.radians(A))) print(S) print(L) print(h)
1
177,139,748,410
null
30
30
search = raw_input().upper() sentence = [] while 1: input_data = raw_input() if input_data == 'END_OF_TEXT': break sentence += [s.upper() for s in input_data.split()] ret = 0 for word in sentence: ret += 1 if word == search else 0 print ret
target=raw_input() ct=0 flag=0 while True: line=raw_input().split(" ") for i in line: if i.lower()==target.lower(): ct+=1 elif i=="END_OF_TEXT": print ct flag=1 if flag==1: break
1
1,832,877,639,428
null
65
65
N = int(input()) ans = 0 for i in range(1,N+1): if i%3 and i%5: ans += i print(ans)
ans = 0 for a in range(1, int(input())+1): if a % 3 != 0 and a % 5 != 0: ans += a print(ans)
1
35,079,156,229,568
null
173
173
N, K = map(int, input().split()) A = list(map(int, input().split())) F = list(map(int, input().split())) A.sort() F.sort(reverse=True) ok = 10**12 ng = -1 def check(time): shugyou = 0 for i in range(N): if A[i]*F[i] > time: shugyou += A[i] - (time//F[i]) return shugyou <= K while ok - ng > 1: mid = (ok + ng)//2 if check(mid): ok = mid else: ng = mid print(ok)
moji = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' memo = {} for i in range(len(moji)): memo.setdefault(moji[i],i) #print(memo) n = int(input()) s = str(input()) ans = '' for i in range(len(s)): ans += moji[(memo[s[i]]+n)%26] print(ans)
0
null
149,412,858,254,000
290
271
M=[] F=[] R=[] while True: m,f,r=map(int,raw_input().split()) if (m,f,r)==(-1,-1,-1): break else: M.append(m) F.append(f) R.append(r) for i in range(len(M)): sum=M[i]+F[i] if M[i]==-1 or F[i]==-1: print('F') elif sum>=80: print('A') elif sum>=65: print('B') elif sum>=50: print('C') elif sum>=30: if R[i]>=50: print('C') else: print('D') else: print('F')
def solve(m, f, r): if (m == -1 or f == -1) or m + f < 30: return "F" for a, b in ((80, "A"), (65, "B"), (50, "C")): if m + f >= a: return b if r >= 50: return "C" return "D" while True: m, f, r = map(int, input().split()) if m == f == r == -1: break print(solve(m, f, r))
1
1,234,446,716,052
null
57
57
def main(): N = int(input()) S = input() cnt = 0 for i in range(N): for j in range(i + 1, N): k = 2 * j - i if k >= N: continue if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]: cnt += 1 print(S.count("R") * S.count("B") * S.count("G") - cnt) if __name__ == "__main__": main()
n = int(input()) s = input() total = s.count("R") * s.count("G") * s.count("B") #l = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"] lR = [0]*n lG = [0]*n lB = [0]*n for i in range(len(s)): if s[i] == "R": lR[i] += 1 elif s[i] == "G": lG[i] += 1 else: lB[i] += 1 #print(lR) #print(lG) #print(lB) for i in range(n): j = 1 if lR[i]: while i-j >= 0 and i+j < n: if lG[i+j]!=0 and lG[i+j] == lB[i-j]: total -= 1 elif lG[i-j]!=0 and lG[i-j] == lB[i+j]: total -= 1 j += 1 elif lG[i]: while i-j >= 0 and i+j < n: if lR[i+j]!=0 and lR[i+j] == lB[i-j]: total -= 1 elif lR[i-j]!=0 and lR[i-j] == lB[i+j]: total -= 1 j += 1 elif lB[i]: while i-j >= 0 and i+j < n: if lG[i+j]!=0 and lG[i+j] == lR[i-j]: total -= 1 elif lG[i-j]!=0 and lG[i-j] == lR[i+j]: total -= 1 j += 1 print(total)
1
36,060,240,571,040
null
175
175
n = int(input()) a = list(map(int,input().split())) maxketa = max([len(bin(a[i])) for i in range(n)])-2 mod = 10**9+7 ans = 0 for i in range(maxketa): ones = 0 for j in range(n): if (a[j] >> i) & 1: ones += 1 ans = (ans + (n-ones)*ones*(2**i)) % mod print(ans)
import sys import itertools # import numpy as np import time import math sys.setrecursionlimit(10 ** 7) from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n = int(input()) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 x = 1 ans = 0 for i in range(60): ones = 0 zeros = 0 for a in A: if a & (1 << i) > 0: ones += 1 else: zeros += 1 ans += (ones * zeros * x) % MOD x *= 2 print(ans % MOD)
1
123,049,471,316,720
null
263
263
for i in range(1,10): for j in range(1,10): print(i,"x",j,"=",i*j,sep="") j+=1 i+=1
#coding:utf-8 import itertools r = range(1,10) for (x,y) in itertools.product(r,r): print('{}x{}={}'.format(x,y,x*y))
1
3,224,518
null
1
1
N, M, X = map(int, input().split()) BOOKS = [tuple(map(int, input().split())) for _ in range(N)] INF = 10 ** 8 ans = INF for selection in range(1 << N): price = 0 values = [0] * M for i in range(N): if selection & (1 << i): x = BOOKS[i] price += x[0] for j in range(M): values[j] += x[j+1] if all(v >= X for v in values): ans = min(ans, price) if ans == INF: print(-1) else: print(ans)
from itertools import product as prod N,M,X=map(int,input().split()) B=[list(map(int,input().split())) for _ in range(N)] ans=float('INF') for v in prod(range(2),repeat=N): scores=[0]*M cost=0 for i in range(N): if v[i]==1: cost+=B[i][0] for j in range(M): scores[j]+=B[i][1+j] if min(scores)>=X: ans=min(ans,cost) print(ans if ans!=float('INF') else -1)
1
22,466,824,214,560
null
149
149
k = int(input()) s = input() a = list(s.split()) if len(s) <= k: print(s) elif len(s) > k: print((s[0:k] + '...'))
#from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(x): if DBG: print(x) # # # # unionfind.py # # # # # usage: uf = Unionfind(n) ; x = uf.root(y); uf.conn(a,b) class Unionfind: def __init__(s,n): s.sz = [1] * n s.ances = [i for i in range(n)] def root(s,x): a = [] y = x while s.ances[y] != y: a.append(y) y = s.ances[y] for z in a: s.ances[z] = y return y def conn(s,x,y): i = s.root(x) j = s.root(y) if i==j: return #k = [i,j].min k = j if (s.sz[i]<s.sz[j]) else i if k==j: s.ances[i] = j else: s.ances[j] = i s.sz[k] = s.sz[i] + s.sz[j] # # # # end unionfind.py # # # # n,m = inm() uf = Unionfind(n) for i in range(m): a,b = inm() uf.conn(a-1,b-1) h = {} x = 0 for i in range(n): r = uf.root(i) if r not in h: h[r] = 1 else: h[r] += 1 x = max(x,h[r]) print(x)
0
null
11,809,991,021,848
143
84
N = int(input()) if N%2 == 1 : print(0) exit() n = 0 i = 0 for i in range(1,26) : n += N//((5**i)*2) print(n)
dice = list(map(int, input().split())) command = str(input()) for c in command: if (c == 'S'): ##2651 --> 1265 dice[1],dice[5],dice[4],dice[0] = dice[0],dice[1],dice[5],dice[4] elif(c == 'N'): dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0] elif (c == 'W'): ##4631 -- > 1463 dice[3], dice[5], dice[2],dice[0] = dice[0], dice[3], dice[5], dice[2] else: dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2],dice[0] print(dice[0])
0
null
57,885,408,471,528
258
33
N, K = list(map(int, input().split())) H = list(map(int, input().split())) H = sorted(H, reverse=True) for i in range(min(K,len(H))): H[i] = 0 print(sum(H))
import sys n,k = map(int,input().split()) ans = 0; h = [int(x) for x in input().split()] h.sort(reverse = True) h = h[k:] if len(h) > 0: ans += sum(h) print(ans)
1
79,300,231,487,358
null
227
227
from collections import Counter n = int(input()) s = input() cnt = Counter(s) ans = cnt["R"]*cnt["G"]*cnt["B"] for i in range(n): for j in range(i+1,n): k = 2*j-i if k >= n: continue if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]: ans -= 1 print(ans)
MAX_A = 10**6 + 1 is_prim = [True] * MAX_A is_prim[0] = is_prim[1] = False for i in range(2, MAX_A): if not is_prim[i]: continue for j in range(i+i, MAX_A, i): is_prim[j] = False def solve(): C = [0] * MAX_A for a in A: C[a] += 1 pairwise = True for p in [i for i in range(MAX_A) if is_prim[i]]: if sum(C[p::p]) > 1: pairwise = False if pairwise: return 'pairwise' from math import gcd g = 0 for a in A: g = gcd(g, a) if g == 1: return 'setwise' return 'not' n = int(input()) A = [*map(int, input().split())] print(solve(), 'coprime')
0
null
20,130,203,994,592
175
85
input_list = map(int, raw_input().split()) ineq = "" if input_list[0] < input_list[1]: ineq = "<" elif input_list[0] > input_list[1]: ineq = ">" else: ineq = "==" print "a %s b" % (ineq)
a,b=map(int, raw_input().split()) if a==b: print "a == b" elif a>b: print "a > b" else: print "a < b"
1
360,063,527,540
null
38
38
x = list(map(int,input().split())) print(x.index(0)+1)
import sys array = list(map(int,input().split())) print(array.index(0)+1)
1
13,473,925,240,320
null
126
126
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 } dice = [ int( i ) for i in raw_input( ).split( " " ) ] roll = raw_input( ) for i in range( len( roll ) ): if "E" == roll[i]: t = dice[ diceface["TOP"] ] dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ] dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ] dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ] dice[ diceface["RIGHT"] ] = t elif "N" == roll[i]: t = dice[ diceface["TOP"] ] dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ] dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ] dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ] dice[ diceface["BACK"] ] = t elif "S" == roll[i]: t = dice[ diceface["TOP"] ] dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ] dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ] dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ] dice[ diceface["FRONT"] ] = t elif "W" == roll[i]: t = dice[ diceface["TOP"] ] dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ] dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ] dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ] dice[ diceface["LEFT"] ] = t print( dice[ diceface["TOP"] ] )
class Dice(object): def __init__(self, n): self.n = n def move(self, to): if to == 'N': self.n[0], self.n[1], self.n[4], self.n[5] = self.n[1], self.n[5], self.n[0], self.n[4] elif to == 'E': self.n[0], self.n[2], self.n[3], self.n[5] = self.n[3], self.n[0], self.n[5], self.n[2] elif to == 'S': self.n[0], self.n[1], self.n[4], self.n[5] = self.n[4], self.n[0], self.n[5], self.n[1] elif to == 'W': self.n[0], self.n[2], self.n[3], self.n[5] = self.n[2], self.n[5], self.n[0], self.n[3] def top(self): return self.n[0] dice = Dice([int(i) for i in input().split()]) move = input() for m in move: dice.move(m) print(dice.top())
1
238,345,820,188
null
33
33
import math x1, y1, x2, y2 = map(float, input().split()) dx = x1 - x2 dy = y1 - y2 d = math.hypot(dx, dy) print(d)
n = int(input()) sumall = int(n * (n+1)/2) sum3 = int(n//3 * (n//3 + 1) * 3/2) sum5 = int(n//5 * (n//5 + 1) * 5/2) sum15 = int(n//15 * (n//15 + 1) * 15/2) print(sumall - sum3 - sum5 + sum15)
0
null
17,625,971,125,160
29
173
N = int(input()) if(N%2 != 0): print(0) else: cnt = 0 n = 1 while n <= N: n *= 5 if(n > N): break num = n*2 cnt += N//num print(cnt)
#submit 16999743 a, b = input().split() a = int(a) b1, b2 = b.split('.') ans = a * (int(b1) * 100 + int(b2)) // 100 print(ans)
0
null
66,336,288,745,692
258
135
N=int(input()) S,T=input().split() list=[] for i in range(N): list.append(S[i]+T[i]) print(''.join(list))
N,K = map(int,input().split()) R,S,P = map(int,input().split()) dp = [] order = input() def jcount(x): if x=='r': ans = P elif x=='s': ans = R else: ans = S return ans counter = 0 for i in range(N): if i < K: counter += jcount(order[i]) dp.append(order[i]) elif order[i] != dp[i-K]: counter += jcount(order[i]) dp.append(order[i]) else: dp.append('x') print(counter)
0
null
109,844,767,105,700
255
251
import Queue n,q=map(int,raw_input().strip().split()) name=[] time=[] qu=Queue.Queue() class task: def __init__(self,name,time): self.name=name self.time=time self.total=0 for i in xrange(n): inp=raw_input().strip().split() qu.put(task(inp[0],int(inp[1]))) curtime=0 while not qu.empty(): tmp=qu.get() if tmp.time>q: tmp.time-=q curtime+=q qu.put(tmp) else: curtime+=tmp.time ed='' if qu.qsize()==0 else '\n' print tmp.name,curtime # print curtime
#16D8101014F 久留米 竜之介 Kurume Ryunosuke Python All = 0 q = [] Queue = [] tmp,time = map(int,input().split()) for i in range(tmp): p,zi =input().split() q.append([p,int(zi)]) while len(q) > 0: if q[0][1]<= time: All+=q[0][1] v=q.pop(0) Queue.append([v[0],All]) else: All+=time q[0][1]-=time last=q.pop(0) q.append(last) for i in range(len(Queue)): print("{0} {1}".format(Queue[i][0],Queue[i][1]))
1
43,122,451,202
null
19
19
n = int(input()) for i in range(n): if (i+1)%3==0: print(" "+str(i+1), end="") else: x = i+1 while(x>0): if x%10==3: print(" "+str(i+1), end="") break else: x = x//10 print("")
n = int(input()) i = 1 for i in range(1, n + 1): if i % 3 == 0: print(' {0}'.format(i), end = '') else: st = str(i) for x in range(0, len(st)): if st[x] == '3': print(' {0}'.format(i), end = '') break print()
1
937,470,639,808
null
52
52
#!/usr/bin/env python # -*- coding: utf-8 -*- N, M, K = map(int, input().split()) result = 0 # max a_time = list(map(int, input().split())) b_time = list(map(int, input().split())) sum = 0 a_num = 0 for i in range(N): sum += a_time[i] a_num += 1 if sum > K: sum -= a_time[i] a_num -= 1 break i = a_num j = 0 while i >= 0: while sum < K and j < M: sum += b_time[j] j += 1 if sum > K: j -= 1 sum -= b_time[j] if result < i + j: result = i + j i -= 1 sum -= a_time[i] print(result)
import math N, X, T = map(int, input().split()) m = math.ceil(N/X) print(m*T)
0
null
7,452,289,567,762
117
86
S = str(input()) print('No') if S == 'AAA' or S == 'BBB' else print('Yes')
s=input() count=0 for i in range(0,len(list(s))-1): if(s[i]!=s[i+1]): count+=1 elif(s[i]==s[i+1]): count+=0 if(count>1 or count==1): print("Yes") else: print("No")
1
54,563,589,830,336
null
201
201
def solve(): a1, a2, a3 = map(int, input().split()) print('bwuisnt'[a1+a2+a3<=21::2]) if __name__ == '__main__': solve()
A1, A2, A3 = (int(x) for x in input().split()) if A1+A2+A3>=22: print("bust") else: print("win")
1
118,300,710,922,670
null
260
260
import bisect as bs N = int(input()) L = list(map(int,input().split())) L.sort() ans = 0 for i in range(len(L)-1): for j in range(i+1, len(L)): ans += bs.bisect_left(L, L[i]+L[j])-j-1 print(ans)
n,k=map(int,input().split()) lst=[list(map(int,input().split())) for i in range(k)] mod=998244353 dp=[0]*(2*n+10) dp[0]=1 dp[1]=-1 for i in range(n): for l,r in lst: dp[i+l]+=dp[i] dp[i+r+1]-=dp[i] dp[i+1]+=dp[i] dp[i+1]%=mod print(dp[n-1])
0
null
87,313,637,964,992
294
74
N, K = map(int, input().split()) sunuke = [False] * N for _ in range(K): d = int(input()) A = list(map(int, input().split())) for a in A: a -= 1 sunuke[a] = True ans = N - sum(sunuke) print(ans)
n=int(input()) arr=list(map(int,input().split())) arr=sorted(arr) #配列を昇順ソートしておく(配列に0がある場合0が先頭に来るので、場合分けの必要がなくなる) ans=1 for val in arr: ans*=val #Pythonは多倍長整数をサポートしているので単に積を求めれば十分 if ans>10**18: print(-1) break else: print(ans)
0
null
20,356,048,390,556
154
134
# -*- coding: utf-8 -*- def main(): n = int(input()) keihin_set = set() for i in range(n): s = input() if not s in keihin_set: keihin_set.add(s) print(len(keihin_set)) if __name__ == "__main__": main()
from collections import Counter n = int(input()) S = [input() for i in range(n)] counter = Counter(S) print(len(counter.keys()))
1
30,241,522,684,208
null
165
165
H = int(input()) W = int(input()) N = int(input()) ans = N // max(H, W) if N % max(H, W) > 0: ans += 1 print(ans)
h=int(input()) w=int(input()) n=int(input()) print(min((n+h-1)//h,(n+w-1)//w))
1
89,036,248,295,140
null
236
236
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) s = input() day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] print(7 - day.index(s))
N = int(input()) A = [] for i in range(N+1): if i % 15 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: A.append(i) print(sum(A))
0
null
84,348,804,868,032
270
173
N = int(input()) import math print(int(math.ceil(N / 1000) * 1000 - N))
n = int(input()) for i in range(11): ans = i*1000 judge = ans-n if judge>=0: break print(judge)
1
8,471,074,215,902
null
108
108
K = int(input()) [A, B] = [int(i) for i in input().split()] for num in range(A, B+1): if num % K == 0: print("OK") exit() print("NG")
S = input() s = "" for i in range(0,len(S)): s += "x" print(s)
0
null
49,629,279,013,820
158
221
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) MOD = 10 ** 9 + 7 N = int(input()) lst1 = [('a', 0)] lst2 = [] for i in range(N - 1): if i % 2 == 0: #lst1 -->lst2 lst2 = [] for s, t in lst1: last = max(ord(s[i]) - ord('a'), t) for j in range(last + 2): lst2.append((s + chr(j + ord('a')), max(t, j))) else: lst1 = [] for s, t in lst2: last = max(ord(s[i]) - ord('a'), t) for j in range(last + 2): lst1.append((s + chr(j + ord('a')), (max(t, j)))) if len(lst2) > len(lst1): lst2.sort() for s, t in lst2: print (s) else: lst1.sort() for s, t in lst1: print (s)
import itertools N = int(input()) A = list(map(int, input().split())) MOD = 10**9+7 A.sort() ac = list(itertools.accumulate(A)) ans = 0 for i in range(N): ans += A[i]*(ac[-1]-ac[i]) print(ans % MOD)
0
null
28,041,579,517,980
198
83
N, M, K = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) def isok(bs, RT): return True if bs <= RT else False def search(B, RT): left = -1 right = M+1 while right-left>1: mid = left+(right-left)//2 if isok(B[mid], RT): left = mid else: right = mid return left def solve(): asum = [0]*(N+1) bsum = [0]*(M+1) for i in range(N): asum[i+1]=asum[i]+A[i] for i in range(M): bsum[i+1]=bsum[i]+B[i] ans = 0 for i in range(N+1): RT = K-asum[i] if RT < 0: break ans = max(ans, i+search(bsum, RT)) print(ans) if __name__ == '__main__': solve()
n, m, k = map(int, input().split(" ")) a = [0]+list(map(int, input().split(" "))) b = [0]+list(map(int, input().split(" "))) for i in range(1, n+1): a[i] += a[i - 1] for i in range(1, m+1): b[i] += b[i - 1] j,mx= m,0 for i in range(n+1): if a[i]>k: break while(b[j]>k-a[i]): j-=1 if (i+j>mx): mx=i+j print(mx)
1
10,775,822,019,710
null
117
117
def aizu005(): cnt = 0 while True: cnt =cnt + 1 x = int(raw_input()) if x == 0 : break else : print "Case " + str(cnt) + ": " + str(x) aizu005()
c = 1 while True: a = int(raw_input()) if a == 0: break print "Case %d: %d" % (c,a) c = c + 1
1
494,051,871,180
null
42
42
H, W, K = map(int, input().split()) s = [list(input()) for _ in range(H)] c = [[0 for _ in range(W)] for _ in range(H)] # 1×wの一次元の配列で考える。分割したマスをそれぞれホワイトチョコをカウントする # データを加工してから貪欲法を行う # bit全探索: 横線で割るパターン全てについて、縦線での折り方を考える ans = (H-1) * (W-1) for div in range(1<<(H-1)): g = 0 # g: 横線で分割するグループ番号(0、1、2...) id = [0] * H #何行目であるかを識別するid: i=1なら グループiになる for i in range(H): id[i] = g if div>>i&1: # 2進法でdivのi桁目が1の時、そこで分割する g += 1 #分割線がきたらgを増やす g += 1 # グループ数は分割線+1になる # 集計に使うc配列を初期化 for i in range(g): for j in range(W): c[i][j] = 0 # グループごとを各列ごとのホワイトチョコを集計する for i in range(H): for j in range(W): c[id[i]][j] += int(s[i][j]) num = g - 1 #すでに横線で折った回数(グループ数-1) now = [0] * g #現状で何個のホワイトチョコがあるか # 各グループの縦割りの確認 def add(j): for i in range(g): now[i] += c[i][j] #j列目のホワイトチョコを足していく for i in range(g): if now[i] > K: return False return True for j in range(W): if not (add(j)): # ホワイトチョコがKを超えていれば、縦で織る。 num += 1 now = [0] * g if not (add(j)): num = (H-1) * (W-1) break #print(g, c, num) # 横割りの回数、各グループの集計、最終的に折った回数 ans = min(ans, num) # 割った回数値の最小を更新 print(ans)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): def divide_choco(bit): divrow_num = bin(bit).count("1") + 1 # 割った回数+1 choco_current = [[0] * w for _ in range(divrow_num)] row_divided_cur = 0 for col, piece in enumerate(choco[0]): choco_current[0][col] = piece for row in range(h - 1): if bit >> row & 1: row_divided_cur += 1 for col, piece in enumerate(choco[row + 1]): choco_current[row_divided_cur][col] += piece return choco_current, divrow_num h, w, k = list(map(int, readline().split())) choco = [] for i in range(h): choco_in = input() choco_add = [int(c) for c in choco_in] choco.append(choco_add) ans = INF for bit in range(1 << (h - 1)): choco_current, divrow_num = divide_choco(bit) choco_cursum = [0] * divrow_num is_exceed = False # 超えてる場合True ans_temp = bin(bit).count("1") if divrow_num > 1: for col in range(w): choco_currow = [choco_current[dr][col] for dr in range(divrow_num)] for drow, pieces in enumerate(choco_currow): if pieces > k: ans_temp += INF elif choco_cursum[drow] + pieces > k: is_exceed = True if is_exceed: choco_cursum = [cc for cc in choco_currow] ans_temp += 1 is_exceed = False else: choco_cursum = [cc + cs for cc, cs in zip(choco_currow, choco_cursum)] else: choco_cursum = 0 for pieces in choco_current[0]: if pieces > k: ans_temp += INF elif choco_cursum + pieces > k: choco_cursum = pieces ans_temp += 1 else: choco_cursum = choco_cursum + pieces ans = min(ans, ans_temp) print(ans) if __name__ == '__main__': main()
1
48,762,869,887,292
null
193
193
a,b,k = map(int,input().split()) t1 = min(a,k) k -= t1 a -= t1 t2 = min(b,k) k -= t2 b -= t2 print(a,b)
n = int(input()) L = sorted(list(map(int,input().split())),reverse = True) ans = 0 for i in L: for j in L: for k in L: if i<j<k: if i + j>k: ans += 1 print(ans)
0
null
54,339,786,948,288
249
91
import sys def input(): return sys.stdin.readline().rstrip() def main(): n = int(input()) ans = 0 for i in range(1, n+1): ans += i*(1 + n//i)*(n//i)//2 print(ans) if __name__=='__main__': main()
count = [0 for i in range(26)] while True: try: s = input() except: break for i in range(len(s)): m = ord(s[i]) - ord("a") if(m >= 0 and m <= 26): count[m] += 1 m = ord(s[i]) - ord("A") if(m >= 0 and m <= 26): count[m] += 1 for i in range(26): print(chr(i + ord("a")), ":", count[i])
0
null
6,352,698,862,048
118
63
import re import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def s(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10 ** 9) mod = 10**9+7 cnt = 0 ans = 0 inf = float("inf") n,k=I() p = l() x = list(itertools.accumulate(p)) if n==1: print((p[0]+1)/2) sys.exit() if n==k: print((x[-1]+k)/2) sys.exit() for i in range(1,n-k+1): ans = max(ans,x[i+k-1]-x[i-1]) print((ans+k)/2)
import sys from collections import deque readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N = int(readline()) if N==1: print('a') exit() d = deque(['a']) ans = [] while d: s = d.popleft() last = ord(max(s)) for i in range(97,last+2): S = s + chr(i) if len(S)==N: ans.append(S) else: d.append(S) ans.sort() for s in ans: print(s) if __name__ == '__main__': main()
0
null
63,545,559,480,268
223
198
A=[0 for i in range(45)] A[0]=1 A[1]=1 for i in range(2,45): A[i]=A[i-1]+A[i-2] B=int(input()) print(A[B])
# B - Papers, Please N = int(input()) my_list = list(input().split()) j = 0 for i in range(0, N): if int(my_list[i]) % 2 == 0: if int(my_list[i]) % 3 != 0 and int(my_list[i]) % 5 != 0: j += 1 if j != 0: print('DENIED') else: print('APPROVED')
0
null
34,364,048,060,192
7
217
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 from functools import reduce import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) n, k = MAP() R, S, P = MAP() t = input() s = '' ans = 0 for i in range(len(t)): if t[i] == 'r': if i >= k and s[i-k] == 'p': s += 'x' else: ans += P s += 'p' elif t[i] == 's': if i >= k and s[i-k] == 'r': s += 'x' else: ans += R s += 'r' else: if i >= k and s[i-k] == 's': s += 'x' else: ans += S s += 's' print(ans)
K=int(input()) A,B=map(int, input().split()) cnt=0 for i in range(B//K+1): if A<=K*i and K*i<=B: cnt+=1 print('OK' if cnt>0 else 'NG')
0
null
66,712,198,701,270
251
158
S = input() s = len(S) ct = 0 for i in range(s): if S[i] != S[(-i-1)]: ct += 1 print(ct//2)
#coding: utf-8 import math n = int(input()) x = [int(i) for i in input().split(" ")] y = [int(i) for i in input().split(" ")] d1 = d2 = d3 = di = 0 for i in range(n): d1 += abs(x[i] - y[i]) d2 += abs(x[i] - y[i])**2 d3 += abs(x[i] - y[i])**3 if di < abs(x[i] - y[i]): di = abs(x[i] - y[i]) print(d1) print(math.pow(d2, 1.0/2.0)) print(math.pow(d3, 1.0/3.0)) print(di)
0
null
60,098,541,462,570
261
32
import math n = float(input()) a = math.floor(n/1.08) x = [] if math.floor((a)*1.08) == n: print(a) elif math.floor((a+1)*1.08) == n: print(a+1) elif math.floor((a+2)*1.08) == n: print(a+2) elif math.floor((a+3)*1.08) == n: print(a+3) elif math.floor((a-1)*1.08) == n: print(a-1) else: print(":(")
H,W = map(int,input().split()) s = [input() for _ in range(H)] DP = [[1000]+[0]*W for _ in range(H+1)] re = [[0]*(W+1) for _ in range(H+1)] DP[0] = [1000]*(W+1) DP[0][1] = DP[1][0] = 0 for i in range(1,H+1): for j in range(1,W+1): if s[i-1][j-1] == ".": DP[i][j] = min(DP[i-1][j],DP[i][j-1]) else: u = DP[i-1][j]+1-re[i-1][j] l = DP[i][j-1]+1-re[i][j-1] DP[i][j] = min(u, l) re[i][j] = 1 print(DP[H][W])
0
null
87,764,583,683,190
265
194
n,m = map(int,input().split()) coins = sorted(list(map(int,input().split())),reverse=True) dp = [float("inf")]*50001 dp[0] = 0 for i in range(50001): for coin in coins: if i+coin > 50000: continue else: dp[i+coin] = min(dp[i+coin], dp[i]+1) print(dp[n])
import sys inf_val = 10**10 m, n = map(int, sys.stdin.readline().split()) numbers = map(int, sys.stdin.readline().split()) dp = [inf_val]*(m+1) dp[0] = 0 for x in numbers: for y in xrange(x, m+1): dp[y] = min(dp[y-x]+1, dp[y]) print dp[m]
1
140,909,429,780
null
28
28
def main(): from sys import setrecursionlimit, stdin, stderr from os import environ from collections import defaultdict, deque, Counter from math import ceil, floor from itertools import accumulate, combinations, combinations_with_replacement setrecursionlimit(10**6) dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0 input = lambda: stdin.readline().rstrip() LMIIS = lambda: list(map(int,input().split())) II = lambda: int(input()) P = 10**9+7 INF = 10**18+10 N,K = LMIIS() P = list(map(lambda x: int(x)-1,input().split())) C = LMIIS() score_sets = [] used = [False]*N tmp = P[0] for i in range(N): if not used[i]: tmp = i score_set = [] while not used[tmp]: used[tmp] = True tmp = P[tmp] score_set.append(C[tmp]) score_sets.append(score_set) ans = -INF for score_set in score_sets: # 合計が最大になる区間を探す len_set = len(score_set) sum_score_set_real = sum(score_set) sum_score_set = max(0,sum_score_set_real) for i in range(len_set): cum_sum_1 = 0 for j in range(i,min(len_set, i+K)): cum_sum_1 += score_set[j] num_move = j-i+1 tmp_max = cum_sum_1 + (K - num_move) // len_set * sum_score_set ans = max(ans, tmp_max) for i in range(1,len_set-1): cum_sum_2 = sum_score_set_real for j in range(i,min(len_set-1-(K-i),len_set-1)): cum_sum_2 -= score_set[j] for j in range(max(i,len_set-1-(K-i)),len_set-1): cum_sum_2 -= score_set[j] num_move = len_set - (j-i+1) tmp_max = cum_sum_2 + (K - num_move) // len_set * sum_score_set ans = max(ans,tmp_max) print(ans) main()
import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().rstrip() def main(): n, k = map(int, input().split()) p = tuple(map(int, input().split())) c = tuple(map(int, input().split())) ans = -10**18 for i in range(n): start, count = i, 1 val = c[start] while p[start]-1 != i: start = p[start]-1 count += 1 val += c[start] start = i if val > 0: a = (k//count-1)*val ans = max(a, ans) num = count + k % count else: a = 0 num = min(k, count) for _ in range(num): a += c[start] start = p[start] - 1 ans = max(a, ans) print(ans) if __name__ == '__main__': main()
1
5,346,931,661,020
null
93
93
n,k=map(int,input().split());s=set(range(1,-~n)) for _ in range(k): input();s-=set(map(int,input().split())) print(len(s))
N,K = list(map(int,input().split())) snacker = set() for i in range(K): dummy=input() for j in [int(k) for k in input().split()]: snacker.add(j) print(N-len(snacker))
1
24,402,307,653,532
null
154
154
n, m, x = map(int, input().split()) ca = [list(map(int, input().split())) for _ in range(n)] # 購買する全パターンを回す most_row_price = 10**10 for i in range(2**n): comb = str(bin(i)[2:]).zfill(n) # 購買パターン毎の購入金額と理解度を算出する money_per_pattern = [0] * n # 購買パターン毎の金額の初期化 understanding = [0] * m # 理解度の初期化 total_money = 0 # 合計購入金額の初期化 for j in range(n): # 購入しないケースは除外する if comb[j] == '0': continue # 購入するケースだけ、金額算出する money_per_pattern[j] = ca[j][0] # 当該パターンの理解度を算出する for k in range(m): understanding[k] += ca[j][k+1] total_money = sum(money_per_pattern) judge_flg = 'ok' for j in range(m): if understanding[j] < x: judge_flg = 'ng' if judge_flg == 'ok': most_row_price = min(total_money, most_row_price) if most_row_price == 10**10: print(-1) else: print(most_row_price)
import sys input = sys.stdin.readline n, r = map(int, input().split()) print(r + 100 * (10 - min(10, n)))
0
null
42,723,490,531,680
149
211
s = input() p = list(s) if p[len(p) - 1] == "?": #最後が?だったら p[len(p) - 1] = "D" # Dにする for i in range(len(p) - 1): if p[i] == "?": # ?だったら if i == 0: # 最初の文字 if p[i + 1] == "D" or p[i + 1] == "?": # 二番目の文字がDか? p[i] = "P" else: # 二番目の文字がDか?でなかったら p[i] = "D" else: p[i] = "D" # D print("".join(p))
t=list(input()) for i in range(len(t)): if t[i]=="?": t[i]="D" print(t[i],end='')
1
18,445,712,192,668
null
140
140
n,k=map(int,input().split()) R,S,P=map(int,input().split()) T=input() t="" count=0 for i in range(n): if i>k-1: if T[i]=="r": if t[i-k]!="p": t=t+"p" count+=P else: t=t+" " if T[i]=="s": if t[i-k]!="r": t=t+"r" count+=R else: t=t+" " if T[i]=="p": if t[i-k]!="s": t=t+"s" count+=S else: t=t+" " else: if T[i]=="r": t=t+"p" count+=P if T[i]=="p": t=t+"s" count+=S if T[i]=="s": t=t+"r" count+=R print(count)
n,m = map(int,input().split()) a = list(map(int,input().split())) a.sort(reverse=True) #必要票数を求める s = sum(a) needed = s/4/m if s%(4*m) == 0 else s//(4*m)+1 for i in range(m): if a[i] < needed: print("No") break else: print("Yes")
0
null
72,564,816,067,418
251
179
from math import gcd n = int(input()) a = list(map(int, input().split())) # 解説AC(a*loga) ans = 0 cnt = [0] * (max(a) + 1) for ai in a: ans = gcd(ans, ai) cnt[ai] += 1 if ans != 1: print('not coprime') elif any(sum(cnt[i::i]) > 1 for i in range(2, max(a) + 1)): print('setwise coprime') else: print('pairwise coprime')
import math N, X, T = map(int, input().split()) t = int(math.ceil(N/X)) print('{}'.format(t*T))
0
null
4,231,214,994,930
85
86
H , W = map(int,input().split()) if H == 1 or W ==1: print(1) exit() if H %2 == 0: tate = H/2 ans = tate * W else: tate1 = H // 2 + 1 tate2 = H // 2 if W % 2 == 0: ans = (tate1 + tate2) * W/2 else: ans = tate1*((W//2)+1) + tate2*(W//2) print(int(ans))
import math def resolve(): H, W = [int(i) for i in input().split()] if H==1 or W==1: print(1) else: print(math.ceil(H*W/2)) resolve()
1
51,110,149,461,430
null
196
196
a, b, c = map(int, raw_input().split()) n = a count = 0 while True: x = c % n if x == 0: count += 1 if n == b: break else: n += 1 print count
#! python3 a, b, c = [int(x) for x in input().strip().split(' ')] r = 0 for i in range(a, b+1): if c % i == 0: r += 1 print(r)
1
562,304,783,654
null
44
44
u, s, e, w, n, d = input().split() t = input() for i in t: if i == 'N': u, s, n, d = s, d, u, n elif i == 'E': u, e, w, d = w, u, d, e elif i == 'S': u, s, n, d = n, u, d, s elif i == 'W': u, e, w, d = e, d, u, w print(u)
print('No' if input().replace('hi', '') else 'Yes')
0
null
26,744,229,357,952
33
199
n,k=map(int,input().split()) li=list(map(int,input().split())) kai=[0] for i in range(1,1001): kai.append(kai[i-1]+i) ka=[0]+[kai[i]/i for i in range(1,len(kai))] lis=[ka[i] for i in li] ans=sum(lis[:k]) mx=ans for i in range(len(li)-k): ans-=lis[i] ans+=lis[i+k] mx=max(ans,mx) print(mx)
x = int(input()) for i in range(-118, 120): for j in range(-119, i): if i ** 5 - j ** 5 == x: a = i b = j print(a, b)
0
null
50,039,394,636,058
223
156
# coding: utf-8 N = int(input()) x_ = N//1.08 ans = ':(' for i in range(1,100000): x = x_+i if int(1.08*x) == N: ans = int(x) break print(ans)
N = int(input()) tax_min = int(N*0.08/1.08) tax_max = int((N+1)*0.08/1.08) if tax_min != tax_max: print(":(") else: print(N - tax_min)
1
125,397,305,922,838
null
265
265
n = int(input()) A = [input() for _ in range(n)] print("AC x " + str(A.count("AC"))) print("WA x " + str(A.count("WA"))) print("TLE x " + str(A.count("TLE"))) print("RE x " + str(A.count("RE")))
ans = { 'AC' : 0, 'WA' : 0, 'TLE' : 0, 'RE' : 0 } for i in range(int(input())): ans[input()] += 1 for k, v in ans.items(): print(k, 'x', v)
1
8,674,478,854,632
null
109
109
n,k = map(int,input().split()) li = [] for i in range(k) : gomi = input() [li.append(int(j)) for j in input().split()] st = set(li) print(n - len(st))
N, K = map(int, input().split()) lst = [0 for _ in range(N)] for i in range(K): d = int(input()) A = list(map(int, input().split())) for j in range(d): lst[A[j] - 1] += 1 print(lst.count(0))
1
24,700,873,642,620
null
154
154
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(): L = int(readline()) ans = pow(L / 3, 3) print(ans) return if __name__ == '__main__': main()
class Stack(object): def __init__(self, _max): if type(_max) == int: self._array = [None for i in range(0, _max)] self._next = 0 def push(self, value): if self.isFull(): raise IndexError self._array[self._next] = value self._next += 1 def pop(self): if self.isEmpty(): raise IndexError self._next -= 1 value = self._array[self._next] self._array[self._next] = None return value def isEmpty(self): return self._next <= 0 def isFull(self): return self._next >= len(self._array) def calculator(exp): stack = Stack(100) ope = ["+", "-", "*"] for item in exp: if item in ope: val1 = stack.pop() val2 = stack.pop() if item == "+": stack.push(val2 + val1) elif item == "-": stack.push(val2 - val1) elif item == "*": stack.push(val2 * val1) else: raise ValueError else: stack.push(int(item)) return stack.pop() if __name__ == "__main__": exp = input().split() print(calculator(exp))
0
null
23,545,992,816,640
191
18
n = int(input()) p = list(map(int,input().split())) ans = n m = 2 * (10 ** 5) for i in range(n): m = min(p[i],m) if p[i] > m: ans -= 1 print(ans)
import sys read = sys.stdin.read readlines = sys.stdin.readlines import numpy as np def main(): n, *a = map(int, read().split()) p = np.array(a) minp = np.minimum.accumulate(p) r = np.count_nonzero(minp >= p) print(r) if __name__ == '__main__': main()
1
85,380,179,493,730
null
233
233
from math import gcd n=int(input()) l=list(map(int,input().split())) mal=max(l) e=[i for i in range(mal+1)] x=2 while x*x <= mal: if x == e[x]: for m in range(x, len(e), x): if e[m] == m: e[m] = x x+=1 #print(e) s=set() f=0 for i in l: st = set() while i > 1: st.add(e[i]) i//=e[i] if not s.isdisjoint(st): f=1 break s |= st if f==0: print('pairwise coprime') exit() p=l[0] for i in range(1,n): p=gcd(p,l[i]) if p==1: print('setwise coprime') else: print('not coprime')
import math n=int(input()) a=list(map(int,input().split())) mxa=max(a) def get_sieve_of_eratosthenes(mxa): fact = [0]*(mxa+1) limit = int(math.sqrt(mxa)) for i in range(2,limit+1): if fact[i]!=0: continue else: fact[i]=i for j in range(i, mxa+1, i): if fact[j]==0: fact[j]=i for i in range(2,mxa+1): if fact[i]==0: fact[i]=i return fact fact = get_sieve_of_eratosthenes(mxa) lst=[0]*(len(fact)) for i in range(n): divisor = set() while a[i]!=1: divisor.add(fact[a[i]]) a[i]//=fact[a[i]] for d in divisor: lst[d]+=1 pair=True st=True for i in lst: if i>=2: pair=False if i==n: st=False if pair: print("pairwise coprime") elif st: print("setwise coprime") else: print("not coprime")
1
4,096,767,244,600
null
85
85
import numpy as np import itertools def check(): N,M,X = map(int, input().split()) A = np.array([[int(i) for i in input().split()] for _ in range(N)]) total = np.sum(A,axis=0) flag = True if all((a>=X for a in total[1:])) else False ans = total[0] if flag: for i in range(1,N+1): for v in itertools.combinations([i for i in range(N)], i): B = np.array([A[j] for j in v]) total2 = np.sum(B, axis=0) sabun = total-total2 if all(a>=X for a in sabun[1:]): ans = min(ans, sabun[0]) print(ans if flag else -1) check()
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N = int(input()) As = list(mapint()) ALL = 0 for a in As: ALL ^= a ans = [ALL^a for a in As] print(*ans)
0
null
17,463,698,574,050
149
123
s = input() if "A" in s: if "B" in s: print("Yes") else: print("No") else: print("No")
s = list(input()) if s[0] != s[1] or s[1] != s[2]: print("Yes") else: print("No")
1
54,918,259,162,282
null
201
201
x, y, z = map(int,input().split()) def swap(a, b, c): i = 0 i = a a = b b = i i = a a = c c = i print(a,b,c) swap(x,y,z)
import sys def is_prime(x): if(x <= 3 and x > 1): return True elif(x % 2 == 0 or x % 3 == 0 or x < 2): return False i = 5 while(i * i <= x): if(x % i == 0 or x % (i + 2) == 0): return False i += 6 return True l = [] count = 0 for input in sys.stdin: l.append(int(input)) for data in range(1,len(l)): if(is_prime(l[data]) == True): count += 1 print count
0
null
18,886,017,598,630
178
12
a,b,m = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) ans = [] ans.append(min(A)+min(B)) for i in range(m): M = list(map(int,input().split())) tmp = A[M[0]-1] + B[M[1]-1] -M[2] ans.append(tmp) print(min(ans))
import sys input = sys.stdin.readline def main(): ans = 10**5 * 2 A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = sorted(a)[0] + sorted(b)[0] for i in range(M): x, y, c = map(int, input().split()) cost = a[x-1] + b[y-1] - c ans = min(ans, cost) print(ans) if __name__ == '__main__': main()
1
54,135,308,774,650
null
200
200
n = int(input()) s=['' for _ in range(n)] for i in range(n): s[i]=input() #x=[[0,0] for _ in range(n)] hp,hm=0,0 p=[] m=[] for i in range(n): t=s[i] lv=0 mn=0 for u in t: if u == '(': lv+=1 elif u == ')': lv-=1 mn=min(mn,lv) #x[i][0],x[i][1]=lv,mn if lv>=0: p.append([lv,mn]) hp+=lv else: lv*=-1 m.append([lv,mn+lv]) hm+=lv if hp!=hm: print('No') exit() p.sort(key=lambda x: x[1],reverse=1) m.sort(key=lambda x: x[1],reverse=1) h=0 lv,mn=0,0 for a,b in p: lv+=a mn+=b if mn<0: print('No') exit() mn=lv lv,mn=0,0 for a,b in m: lv+=a mn+=b if mn<0: print('No') exit() mn=lv print('Yes') #print(lv,mn)
N = int(input()) S = input() ans = [] for i in range(len(S)): if i == len(S) - 1: ans.append(S[i]) break if S[i] != S[i+1]: ans.append(S[i]) print(len(ans))
0
null
96,528,637,723,910
152
293
Ss = input().rstrip() lenS = len(Ss) ans = 0 for S, T in zip(Ss[:lenS//2], Ss[::-1]): ans += S != T print(ans)
a = int(input()) b = int(input()) ans = [1,2,3] ans.remove(a) ans.remove(b) print(ans[0])
0
null
115,289,982,368,548
261
254
import sys import math from collections import defaultdict from collections import deque sys.setrecursionlimit(1000000) MOD = 998244353 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def main(): N, K = NMI() LR = [NLI() for _ in range(K)] dp = [0] * (N*2+10) dp[1] = 1 now = 0 for i in range(1, N+1): now = (now + dp[i]) % MOD for l, r in LR: dp[i+l] = (dp[i+l] + now) % MOD dp[i+r+1] = (dp[i+r+1] - now) % MOD print(dp[N]) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline N, K = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(K)] mod = 998244353 dp = [0]*(N+1) tmp = 1 for i in range(N-1): tmp = (tmp + dp[i]) % mod # dp[i] = tmp for l, r in LR: dp[min(i+l, N)] = (dp[min(i+l, N)] + tmp) % mod dp[min(i+r+1, N)] = (dp[min(i+r+1, N)] - tmp) % mod print(dp[N-1])
1
2,690,064,876,708
null
74
74
#!/usr/bin/env python # encoding: utf-8 import sys class Solution: def __init__(self): self.count = 0 def shell_sort(self): array_length = int(input()) # array = [] # array_length = 10 # array = [15, 12, 8, 9, 3, 2, 7, 2, 11, 1] array = list(map(int, sys.stdin.readlines())) G = [1] while True: g = G[0] * 3 + 1 if g > array_length: break G.insert(0, g) g_length = len(G) result = [] for j in range(g_length): result = self.insertion_sort(array=array, array_length=array_length, g=G[j]) # print(result, 'r', G[j]) print(g_length) print(" ".join(map(str, G))) print(self.count) for k in range(array_length): print(result[k]) def insertion_sort(self, array, array_length, g): # write your code here for i in range(g, array_length): v = array[i] j = i - g while j >= 0 and array[j] > v: array[j + g] = array[j] j -= g self.count += 1 array[j + g] = v # print(" ".join(map(str, array))) return array if __name__ == '__main__': solution = Solution() solution.shell_sort()
def insertionSort(n, A, g): global cnt for i in range(g, n): temp = A[i] j = i - g while j >= 0 and A[j] > temp: A[j + g] = A[j] j -= g cnt += 1 A[j + g] = temp return A def shellSort(A, n): global m global G h = 1 while True: if h > n: break G.append(h) h = 3 * h + 1 G.reverse() m =len(G) for i in range(m): insertionSort(n, A, G[i]) if __name__ == "__main__": n = int(input()) A = [int(input()) for i in range(n)] G = [] m = 0 cnt = 0 shellSort(A, n) print(m) print(*G) print(cnt) for i in range(n): print(A[i])
1
30,506,524,640
null
17
17
def main(): n = int(input()) xy = [] for i in range(n): a = int(input()) xy.append([tuple(map(int, input().split())) for _ in range(a)]) c = 0 for i in range(1 << n): popcnt = bin(i).count('1') if popcnt <= c: continue all_honest = True for j in range(n): if (1 << j) & i != 0: for x, y in xy[j]: x -= 1 # 人の番号をひとつずらす if ((1 << x) & i) >> x != y: all_honest = False break if not all_honest: break if all_honest: c = popcnt print(c) if __name__ == '__main__': main()
import itertools n = int(input()) answers = [] for i in range(n): a = int(input()) answers.append((i, [])) for j in range(a): (x, y) = [int(k) for k in input().split()] answers[i][1].append((x, y)) lst = [] combi_lst = [i for i in range(n)] for i in range(n, -1, -1): for balls in itertools.combinations(combi_lst, i): lst = [True if j in balls else False for j in range(n)] success = True for i, ans in enumerate(answers): if lst[i] == False: continue for x, y in ans[1]: if y == 1 and lst[x - 1] == False: success = False if y == 0 and lst[x - 1] == True: success = False if success: print(sum(lst)) exit()
1
121,587,163,877,590
null
262
262
price_list = [] t = raw_input() for i in range(int(t)): price_list.append(int(input())) maxv = float("-inf") minv = price_list[0] for i in range(1, int(t)): maxv = max([maxv, price_list[i] - minv]) minv = min([minv, price_list[i]]) print maxv
n = int(input()) s_lst = list(str(input()) for _ in range(n)) count_lst = [0, 0, 0, 0] for i in range(n): consequence = s_lst[i] if consequence == 'AC': count_lst[0] += 1 elif consequence == 'WA': count_lst[1] += 1 elif consequence == 'TLE': count_lst[2] += 1 else: count_lst[3] += 1 consequence_lst = ['AC x {}'.format(count_lst[0]), 'WA x {}'.format(count_lst[1]), 'TLE x {}'.format(count_lst[2]), 'RE x {}'.format(count_lst[3])] for i in range(4): con = consequence_lst[i] print(con)
0
null
4,393,384,220,622
13
109
N,K = map(int,input().split()) *A, = map(lambda x:(int(x)%K-1)%K,input().split()) class cumulative_sum: def __init__(self,A): N = len(A) self.S = [0]*(N+1) for i in range(N): self.S[i+1] = (self.S[i] + A[i])%K def get(self,i,j=None): if j==None:j=len(self.S)-1 if j<=i:return 0 return (self.S[j]-self.S[i])%K SumA = cumulative_sum(A) def binary_search(l,r,func): if func(l):return l-1 if not func(r):return r while l+1<r: i = (l+r)//2 if func(i): r = i else: l = i return l def f(j): return cnt[s][j] > idx - K ans = 0 cnt = {} for idx,s in enumerate(SumA.S): if not s in cnt: cnt[s] = [-2*K] cnt[s].append(idx) l = len(cnt[s]) j = binary_search(0,l-1,f) ans += (l-1)-(j+1) print(ans)
from collections import defaultdict n, k = map(int, input().split()) A = list(map(int, input().split())) delta_count = defaultdict(int) sum = [0] delta_count[0] += 1 for i in range(n): sum.append(sum[i] + A[i]) ans = 0 for i in range(1, min(n + 1, k)): x = (sum[i] - i) % k ans += delta_count[x] delta_count[x] += 1 for i in range(min(n + 1, k), n + 1): delta_count[(sum[i - k] - i - k) % k] -= 1 x = (sum[i] - i) % k ans += delta_count[x] delta_count[x] += 1 print(ans)
1
137,801,911,897,288
null
273
273
n,m=map(int,input().split()) q=[list(map(int,input().split())) for _ in range(m)] for i in range(10**n): i=str(i) if len(i)!=n: continue f=1 for j in q: if i[j[0]-1]!=str(j[1]): f=0 break if f: print(i) exit() print("-1")
def main(): n, m = map(int, input().split()) qry = [list(map(int, input().split())) for _ in range(m)] ans = -1 for v in range(0, 1000): s = str(v) if len(s) != n: continue f = True for p, x in qry: if s[p-1] != str(x): f = False break if f: ans = v break print(ans) if __name__ == "__main__": main()
1
60,812,773,699,032
null
208
208
n = int(input()) a = [int(x) for x in input().split()] res = "APPROVED" for i in range(n): if a[i] % 2 == 0: if a[i] % 3 != 0 and a[i] % 5 != 0: res = "DENIED" print(res)
str = input() if str[len(str)-1] == "s": str = str + "es" else: str = str + "s" print(str)
0
null
35,923,821,206,320
217
71
n = int(input()) toko = [int(i) for i in input().split()] ans = [int(0) for i in range(n)] for j in range(n): ##01234 ans[toko[j]-1] = j + 1 print(' '.join(map(str, ans)))
a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(range(1,a[0]+1)) dict = dict(zip(b,c)) for i in range(len(b)): print(dict.get(i+1),end=" ")
1
180,609,645,514,132
null
299
299
import random S = input() i = len(S) m = random.randint(0,i-3) print (S[m] + S[m+1] + S[m+2])
def main(): N,R=map(int,input().split()) if(N<10): inner=R+100*(10-N) else: inner=R print(inner) if __name__ == '__main__': main()
0
null
38,988,257,419,580
130
211
import string import sys #??????????????\????????????ip?????\?????? ip = sys.stdin.readlines() for i in range(len(ip)): ip[i] = int(ip[i].strip("\n")) #??????3?????????????????? h = [0]*3 #????????????????????? for i in range(len(ip)): for j in range(len(ip)): if ip[i] > ip[j]: tmp = ip[i] ip[i] = ip[j] ip[j] = tmp for i in range(3): if h != 0: print(ip[i])
N,T = map(int,input().split()) data = [0] * N M = 0 for i in range(N): data[i] = list(map(int,input().split())) M = max(M,data[i][0]) dp1 = [[0]*T for i in range(N)] for j in range(T): if j < data[0][0]: dp1[0][j] = 0 else: dp1[0][j] = data[0][1] for j in range(T): for i in range(1,N): if data[i][0] <= j: dp1[i][j] = max(dp1[i-1][j],dp1[i-1][j-data[i][0]]+data[i][1]) else: dp1[i][j] = dp1[i-1][j] dp2 = [[0]*T for i in range(N)] for j in range(T): if j < data[N-1][0]: dp2[N-i][j] = 0 else: dp2[N-1][j] = data[N-1][1] for j in range(T): for i in range(N-2,-1,-1): if data[i][0] <= j: dp2[i][j] = max(dp2[i+1][j],dp2[i+1][j-data[i][0]]+data[i][1]) else: dp2[i][j] = dp2[i+1][j] m = 0 for j in range(T): for i in range(N): if i == 0: m = max(m,dp2[i+1][T-1-j] + data[i][1]) elif i == N-1: m = max(m,dp1[i-1][j] + data[i][1]) else: m = max(m,dp1[i-1][j] + dp2[i+1][T-1-j] + data[i][1]) print(m)
0
null
76,004,137,705,928
2
282
str_num = input() num_list = str_num.split() answer = int(num_list[0]) * int(num_list[1]) print(answer)
if __name__ == "__main__": a,b = map(int, input().split(" ")) print(a*b)
1
15,922,135,377,190
null
133
133
import math alpha = [] while True: n = float(raw_input()) if n == 0: break nums_str = raw_input().split() nums = [] for s in nums_str: nums.append(float(s)) ave = sum(nums)/n n_sum = 0.0 for num in nums: n_sum += (num-ave)**2 alpha.append(n_sum/n) for a in alpha: print math.sqrt(a)
import math while True: n=int(input()) if n==0: break s=list(map(int,input().split())) m=sum(s)/len(s) a=0 for i in range(n): a+=(s[i]-m)**2 b=math.sqrt(a/n) print('{:.5f}'.format(b))
1
193,377,908,516
null
31
31
N, K, C = map(int, input().split()) S = input()[::-1] Top = [] Bottom = [] yasumi = 0 ans = [] k = K for i in range(N): if (yasumi == 0) and (S[i] == "o") and (k > 0): Bottom.append(N-i) yasumi += C k -= 1 elif yasumi > 0: yasumi -= 1 S_ = S[::-1] Bottom.sort() j = -1 yasumi = 0 for i in range(N): if (yasumi == 0) and (S_[i] == "o") and (K > 0): j += 1 yasumi += C K -= 1 if j >= len(Bottom): break elif Bottom[j] == i+1: ans.append(i+1) elif yasumi > 0: yasumi -= 1 for i in ans: print(i)
n, k, c = map(int, input().split()) S = input() # 要素の値は何回目の働く日か(0は働いていない状態) by_left = [0] * n by_right = [0] * n # 左から貪欲 rest = 0 cnt = 1 for itr, s in enumerate(S): rest -= 1 if rest <= 0 and s == "o": by_left[itr] = cnt cnt += 1 rest = c + 1 # 右から貪欲 rest = 0 cnt = k for itr, s in enumerate(S[::-1]): rest -= 1 if rest <= 0 and s == "o": by_right[n - itr- 1] = cnt cnt -= 1 rest = c + 1 # 左右からの貪欲で、どちらでも同じ働く回数の値が入っている日が必ず働く日 ans = [itr + 1 for itr, (i, j) in enumerate(zip(by_left, by_right)) if i != 0 and i == j] for a in ans: print(a)
1
40,702,387,734,272
null
182
182
S = input() if S[len(S) - 1] == 's': print(S + 'es') else: print(S + 's')
S=str(input()) if S[-1]=='s': S = S + 'es' else: S = S + 's' print(S)
1
2,391,196,502,140
null
71
71
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n = int(input()) if n == 1: print(1) sys.exit() r = 0 for i1 in range(1, n + 1): y = n // i1 r += y * (y + 1) // 2 * i1 print(r) if __name__ == '__main__': main()
n = int(input()) s = input().replace("ABC", "") print((n-len(s))//3)
0
null
55,455,048,060,400
118
245
N, K = map(int, input().split()) A = list(map(int, input().split())) # 丸太がすべてxの長さ以下になる回数を出し、それがK回以下か判定する def f(x): now = 0 for i in range(N): now += (A[i]-1)//x return now <= K l = 0 r = 10**9 while r-l > 1: mid = (r+l)//2 if f(mid): r = mid else: l = mid print(r)
N, K = map(int, input().split()) A = list(map(int, input().split())) left, right = 0, max(A) while right - left != 1: mid = (left + right) // 2 tmp = 0 for i in A: tmp += i // mid - 1 if i % mid == 0 else i // mid if tmp > K: left = mid else: right = mid print(right)
1
6,473,150,432,192
null
99
99
N = int(input()) d_ls=[] for vakawkawelkn in range(N): D1,D2=map(int, input().split()) if D1==D2: d_ls+=[1] else: d_ls+=[0] flag=0 for i in range(N-2): if d_ls[i]*d_ls[i+1]*d_ls[i+2]==1: flag=1 if flag==0: print("No") else: print("Yes") # 2darray [[0] * 4 for i in range(3)] # import itertools
A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) check1=abs(A-B) check2=(V-W)*T print("YES" if check1<=check2 else "NO")
0
null
8,792,491,542,868
72
131
import math from typing import List, Any def read_int() -> int: return int(input().strip()) def read_ints() -> List[int]: return list(map(int, input().strip().split(' '))) def solve() -> Any: H, W = read_ints() last_S = '' INF = 10**9+1 dist = [ [INF for _ in range(H*W)] for _ in range(H*W) ] for i in range(H*W): dist[i][i] = 0 for i in range(H): S = input().strip() for j in range(W): if S[j] == '#': continue top = (i-1)*W+j left = i*W+j-1 current = i*W+j if j > 0 and S[j-1] == '.': dist[left][current] = dist[current][left] = 1 if i > 0 and last_S[j] == '.': dist[top][current] = dist[current][top] = 1 last_S = S for k in range(H*W): for i in range(H*W): for j in range(H*W): dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]) return max(cell for row in dist for cell in row if cell != INF) if __name__ == '__main__': print(solve())
import sys import math from collections import deque sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)] def main(): H, W = NMI() grid = [SI() for _ in range(H)] DH = [-1, 1, 0, 0] DW = [0, 0, -1, 1] def bfs(sh, sw): queue = deque() seen = make_grid(H, W, -1) queue.append([sh, sw]) seen[sh][sw] = 0 while queue: now_h, now_w = queue.popleft() for dh, dw in zip(DH, DW): next_h = now_h + dh next_w = now_w + dw if not(0 <= next_h < H and 0 <= next_w < W): continue if seen[next_h][next_w] != -1 or grid[next_h][next_w] == "#": continue queue.append([next_h, next_w]) seen[next_h][next_w] = seen[now_h][now_w] + 1 return max([max(l) for l in seen]) ans = 0 for h in range(H): for w in range(W): if grid[h][w] == ".": ans = max(ans, bfs(h, w)) print(ans) if __name__ == "__main__": main()
1
94,495,745,868,216
null
241
241
N = int(input()) A = [] B = [] for _ in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) A.sort() B.sort() if N % 2 == 0: l = A[N // 2 - 1] + A[N // 2] u = B[N // 2 - 1] + B[N // 2] print(u - l + 1) else: l = A[N // 2] u = B[N // 2] print(u - l + 1)
from operator import itemgetter n = int(input()) AB = [list(map(int, input().split())) for _ in range(n)] sortA = sorted(AB, key=itemgetter(0)) sortB = sorted(AB, key=itemgetter(1)) if n%2==1: print(sortB[n//2][1] - sortA[-n//2][0] + 1) else: print(int(((sortB[n//2][1]+sortB[n//2-1][1])/2 - (sortA[n//2][0]+sortA[n//2-1][0])/2) / (1/2) + 1))
1
17,481,086,128,390
null
137
137
a, b = map(int, input().split()) ans = 0 if a >= b: for i in range(a): ans += b * 10**i else: for i in range(b): ans += a * 10**i print(ans)
a, b = map(int, input().split()) c = str(min(a, b)) print(c*max(a, b))
1
84,281,345,415,062
null
232
232
X=int(input()) a=100 cnt=0 while a<X: a=a+a//100 cnt+=1 print(cnt)
# coding: utf-8 # Your code here! num = int(input()) a=0 b=0 for _ in range(num): input2 = input().split() if input2[0]>input2[1]: a=a+3 elif input2[0]<input2[1]: b=b+3 else: a=a+1 b=b+1 print(a,b)
0
null
14,565,762,408,068
159
67
n=int(input());print((n//2)/n if n%2==0 else -(-n//2)/n)
import math import sys from collections import deque import heapq import copy import itertools from itertools import permutations from itertools import combinations import bisect def mi() : return map(int,sys.stdin.readline().split()) def ii() : return int(sys.stdin.readline().rstrip()) def i() : return sys.stdin.readline().rstrip() a=ii() if a%2==0: print(1/2) else: print(math.ceil(a/2)/a)
1
177,093,255,427,982
null
297
297
import sys sys.setrecursionlimit(10**6) #再帰関数の上限 import math from copy import copy, deepcopy from operator import itemgetter from bisect import bisect_left, bisect, bisect_right#2分探索 #bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下 from collections import deque #deque(l), pop(), append(x), popleft(), appendleft(x) ##listでqueの代用をするとO(N)の計算量がかかってしまうので注意 from collections import Counter#文字列を個数カウント辞書に、 #S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items() from itertools import accumulate#累積和 #list(accumulate(l)) from heapq import heapify,heappop,heappush #heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone #import fractions#古いatcoderコンテストの場合GCDなどはここからimportする def input(): return sys.stdin.readline()[:-1] def printl(li): print(*li, sep="\n") def argsort(s, return_sorted=False): inds=sorted(range(len(s)), key=lambda k: s[k]) if return_sorted: return inds, [s[i] for i in inds] return inds def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def matmat(A,B): K,N,M=len(B),len(A),len(B[0]) return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] def matvec(M,v): N=len(v) size=len(M) return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] def main(): mod = 10**9+7 #w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え #N = int(input()) N, K, S = map(int, input().split()) #A = tuple(map(int, input().split())) #1行ベクトル #L = tuple(int(input()) for i in range(N)) #改行ベクトル #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列 m=10**9 if S!=10**9: ans=[S]*K+[m]*(N-K) else: ans=[m]*K+[1]*(N-K) print(*ans) if __name__ == "__main__": main()
# C - Subarray Sum def main(): N, K, S = map(int, input().split()) res = [str(S)] * K + ["1" if S == 10 ** 9 else str(S + 1)] * (N - K) print(" ".join(res)) if __name__ == "__main__": main()
1
91,041,037,679,650
null
238
238
isExist = [False]*2001 n = int( raw_input() ) A = [ int( val ) for val in raw_input().rstrip().split( ' ' ) ] for i in A: for j in range( 2000-i, 0, -1 ): if isExist[j]: isExist[ i+j ] = True isExist[i] = True q = int( raw_input() ) M = [ int( val ) for val in raw_input().rstrip().split( ' ' ) ] for i in range( 0, q ): if isExist[ M[i] ]: print( "yes" ) else: print( "no" )
# -*- coding:utf-8 -*- import sys def exhaustive(lst, size): result = [] for i in range(0, 1 << size): total = 0 for j in range(0, size): if (i & 0x01) == 1: total += lst[j] i = i >> 1 result.append(total) return result if __name__ == "__main__": lst = [val.split() for val in sys.stdin.read().splitlines()] n, data, m, targets = [[int(n) for n in inner_lst] for inner_lst in lst] result = exhaustive(data, int(n[0])) print("\n".join(["yes" if x in result else "no" for x in targets]))
1
97,511,443,172
null
25
25
def solve(): S, W = map(int,input().split()) if S > W: print("safe") else: print("unsafe") if __name__ == '__main__': solve()
def main(): s,w = map(int, input().split()) if w>=s: print("unsafe") else: print("safe") main()
1
29,132,395,838,732
null
163
163
def main(): n = int(input()) X, Y = [], [] for _ in range(n): x, y = map(int, input().split()) X.append(x + y) Y.append(x - y) X.sort() Y.sort() print(max(X[-1] - X[0], Y[-1] - Y[0])) if __name__ == '__main__': main()
import sys STRING = "" for line in sys.stdin: STRING += line.lower() CHRS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',\ 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] for i in CHRS: print("%s : %d" % (i, STRING.count(i)))
0
null
2,566,134,779,444
80
63
import itertools n = int(input()) l = list(map(int, input().split())) p_list = list(itertools.permutations(l, 3)) results = [x for x in p_list if max(x) < (sum(x) - max(x)) and len(x) == len(set(x))] print(int(len(results) / 6))
A, B, C = map(int, input().split()) if A+B+C > 21: print('bust') else: print('win')
0
null
61,877,915,242,540
91
260
from collections import deque H,W = map(int,input().split()) field = [list(input()) for _ in range(H)] dist = [[-1]*W for _ in range(H)] dx = [1,0,-1,0] dy = [0,1,0,-1] mx = 0 for h in range(H): for w in range(W): if field[h][w] == "#": continue dist = [[-1]*W for _ in range(H)] dist[h][w] = 0 que = deque([]) que.append([h,w]) while que != deque([]): u,v = que.popleft() for dir in range(4): nu = u + dx[dir] nv = v + dy[dir] if (nu < 0) or (nu >= H) or (nv < 0) or (nv >= W): continue if field[nu][nv] == "#": continue if dist[nu][nv] != -1: continue que.append([nu,nv]) dist[nu][nv] = dist[u][v] + 1 for i in range(H): for j in range(W): if mx < dist[i][j]: mx = dist[i][j] print(mx)
# ALDS1_2_D: Shell Sort #N = 5 #A = [5, 1, 4, 3, 2] #N = 3 #A = [3, 2, 1] A = [] N = int(input()) for i in range(N): A.append(int(input())) def insertionSort(A, N, g, cnt): #print(" ".join(map(str, A))) for i in range(g, N): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v #print(" ".join(map(str, A))) return cnt def shellSort(A, N): cnt = 0 #m = 2 #listG = [4, 1] h = 1 listG = [] while h <= N: listG.append(h) h = 3*h + 1 listG = listG[::-1] m = len(listG) for g in listG: cnt = insertionSort(A, N, g, cnt) #print(A) print(m) print(" ".join(map(str, listG))) print(cnt) for v in A: print(v) shellSort(A, N)
0
null
47,306,860,702,358
241
17
if 22 > sum(map(int, input().split())): print('win') else: print('bust')
A = sum([int(x) for x in input().split()]) if A >= 22: print('bust') else: print('win')
1
118,861,856,873,642
null
260
260
N, X, M = map(int, input().split()) checked = [-1] * M a = X i = 0 while checked[a] == -1 and i < N: checked[a] = i a = a**2 % M i += 1 if i == N: a = X ans = 0 for _ in range(N): ans += a a = a**2%M print(ans) else: cycle_size = i - checked[a] cycle_num = a cycle = [] cycle_sum = 0 for _ in range(cycle_size): cycle.append(cycle_num) cycle_sum += cycle_num cycle_num = cycle_num**2 % M before_cycle_size = checked[a] before_cycle = [] before_cycle_sum = 0 num = X for _ in range(before_cycle_size): before_cycle.append(num) before_cycle_sum += num num = num**2 % M ans = before_cycle_sum ans += (N-before_cycle_size)//cycle_size * cycle_sum after_cycle_size = (N-before_cycle_size)%cycle_size for i in range(after_cycle_size): ans += cycle[i] print(ans)
import sys import re stri = sys.stdin.readline() ret = re.match( '^(hi)+$', stri) if ret: print("Yes") else: print("No") sys.stdout.flush()
0
null
27,861,619,416,212
75
199
# -*- coding: utf-8 -*- import math x1, y1, x2, y2 = map(float, raw_input().split()) dx = x2-x1 dy = y2-y1 print math.sqrt(dx*dx+dy*dy)
import math x1,y1,x2,y2 = map(float,input().split(" ")) print("{:.5f}".format(math.sqrt((x2-x1)**2 + (y2-y1)**2)))
1
157,044,165,568
null
29
29