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
debt = 100000.0 a = int(input()) for i in range(a): debt = debt * 1.05 if(debt % 1000): debt = (debt // 1000) * 1000 + 1000 print(int(debt))
n = int(raw_input()) S = [] S = map(int, raw_input().split()) q = int(raw_input()) T = [] T = map(int, raw_input().split()) count = 0 for i in T: if i in S: count += 1 print count
0
null
32,769,844,028
6
22
import sys input = sys.stdin.buffer.readline H, W, K = map(int, input().split()) B = {} for _ in range(K): r, c, v = map(int, input().split()) B[(r, c)] = v dp = [[0]*(W+1) for _ in range(4)] for i in range(1, H+1): for j in range(1, W+1): if (i, j) in B: v = B[(i, j)] dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j]) dp[1][j] = max(dp[1][j-1], dp[0][j]+v) dp[2][j] = max(dp[2][j-1], dp[1][j-1]+v) dp[3][j] = max(dp[3][j-1], dp[2][j-1]+v) else: dp[0][j] = max(dp[0][j-1], dp[0][j], dp[1][j], dp[2][j], dp[3][j]) dp[1][j] = dp[1][j-1] dp[2][j] = dp[2][j-1] dp[3][j] = dp[3][j-1] print(max(dp[i][-1] for i in range(4)))
l, r, d = map(int, input().split(' ')) count = 0 while(l <= r): if(l % d == 0): count += 1 l += 1 print(count)
0
null
6,553,122,814,420
94
104
n = int(input()) s = [] t = [] for i in range(n): si, ti = input().split() s.append(si) t.append(int(ti)) x = input() insleep = s.index(x) ans = sum(t[insleep+1:]) print(ans)
N = int(input()) music_list = [input().split(' ') for i in range(N)] X = input() sleep_switch = False total_time = 0 for music in music_list: if not sleep_switch: if music[0] == X: sleep_switch = True else: total_time += int(music[1]) print(total_time)
1
96,667,929,846,422
null
243
243
import re def revPolish(f): f = re.sub(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)', lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))), f) if f[-1] in ('+','-','*','/'): return revPolish(f) else: return f if __name__=='__main__': print(revPolish(input()))
s = input().split() stack = [] for a in s: if a == '+': stack.append(stack.pop() + stack.pop()) elif a == '-': stack.append(-(stack.pop() - stack.pop())) elif a == '*': stack.append(stack.pop() * stack.pop()) else: stack.append(int(a)) print(stack[0])
1
37,241,475,768
null
18
18
def s0():return input() def s1():return input().split() def s2(n):return [input() for x in range(n)] def s3(n):return [input().split() for _ in range(n)] def s4(n):return [[x for x in s] for s in s2(n)] def n0():return int(input()) def n1():return [int(x) for x in input().split()] def n2(n):return [int(input()) for _ in range(n)] def n3(n):return [[int(x) for x in input().split()] for _ in range(n)] def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)] def p0(b,yes="Yes",no="No"): print(yes if b else no) # from sys import setrecursionlimit # setrecursionlimit(1000000) # from collections import Counter,deque,defaultdict # import itertools # import math # import networkx as nx # from bisect import bisect_left,bisect_right # from heapq import heapify,heappush,heappop a,b,m=n1() A=n1() B=n1() X=n3(m) A2=sorted(A) B2=sorted(B) ans=A2[0]+B2[0] for a,b,c in X: if A[a-1]+B[b-1]-c<ans: ans=A[a-1]+B[b-1]-c print(ans)
A,B,M=map(int,input().split()) alist=list(map(int,input().split())) blist=list(map(int,input().split())) answer=min(alist)+min(blist) for _ in range(M): x,y,c=map(int,input().split()) disc=alist[x-1]+blist[y-1]-c answer=min(answer,disc) print(answer)
1
53,803,366,336,678
null
200
200
import itertools n = int(input()) for i in itertools.count(): if (i * 1000) >= n: break print(i * 1000 - n)
n = int(input()) r = n % 1000 if r == 0: print("0") else: otu = 1000 - r print(otu)
1
8,485,970,547,652
null
108
108
def insertion(A,n): for i in range(0,n): tmp = A[i] j = i - 1 while(A[j] > tmp and j >= 0): A[j+1] = A[j] j-=1 A[j+1] = tmp printList(A) def printList(A): print(" ".join(str(x) for x in A)) n = int(input()) A = [int(x) for x in input().split()] insertion(A,n)
N = input() A = map(int,raw_input().split()) for i in range(N-1): print A[i], print A[-1] for i in range(1,N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v for i in range(N-1): print A[i], print A[-1]
1
5,442,738,760
null
10
10
N, K = map(int,input().split()) P = [int(x)-1 for x in input().split()] C = [int(x) for x in input().split()] def loop(s): value = 0 done = set() while s not in done: done.add(s) s = P[s] value += C[s] return len(done), value def f(s,K): ans = -10**18 total = 0 done = set() while s not in done: done.add(s) s = P[s] total += C[s] ans = max(ans,total) K -= 1 if K==0: return ans lamb, value = loop(s) if K > 2*lamb: if value > 0: K -= lamb total += (K//lamb)*value ans = max(ans,total) K -= (K//lamb)*lamb K += lamb if value <= 0: K = min(K,lamb+5) while K > 0: s = P[s] total += C[s] ans = max(ans,total) K -= 1 return ans print(max([f(s,K) for s in range(N)]))
n = int(input()) x = input() original_pop_count = x.count('1') one_pop_count = original_pop_count - 1 # 0になりうる zero_pop_count = original_pop_count + 1 # X mod p(X) += 1 の前計算 one_mod = 0 zero_mod = 0 for b in x: if one_pop_count != 0: one_mod = (one_mod * 2 + int(b)) % one_pop_count zero_mod = (zero_mod * 2 + int(b)) % zero_pop_count # f の前計算 f = [0] * 220000 pop_count = [0] * 220000 for i in range(1, 220000): # pop_count[i] = pop_count[i // 2] + i % 2 pop_count[i] = bin(i)[2:].count('1') f[i] = f[i % pop_count[i]] + 1 for i in range(n-1, -1, -1): if x[n-i-1] == '1': if one_pop_count != 0: nxt = one_mod nxt -= pow(2, i, one_pop_count) nxt %= one_pop_count print(f[nxt] + 1) else: print(0) elif x[n-i-1] == '0': nxt = zero_mod nxt += pow(2, i, zero_pop_count) nxt %= zero_pop_count print(f[nxt] + 1)
0
null
6,753,126,837,510
93
107
values = [] while True: v = int(input()) if 0 == v: break values.append(v) for i, v in enumerate(values): print('Case {0}: {1}'.format(i + 1, v))
x = [] while True: if 0 in x: break x.append(int(input())) x.pop() for i, v in enumerate(x): print(('Case %d: %d') % (i+1, v))
1
489,078,520,060
null
42
42
import sys SUITS = ('S', 'H', 'C', 'D') cards = {suit:{i for i in range(1, 14)} for suit in SUITS} n = input() # 読み捨て for line in sys.stdin: suit, number = line.split() cards[suit].discard(int(number)) for suit in SUITS: for i in cards[suit]: print(suit, i)
result = [(temp1 + str(temp2)) for temp1 in ('S ','H ','C ','D ') for temp2 in range(1,14)] for check in range(int(input())) : result.remove(input()) for temp in result : print(temp)
1
1,058,390,481,218
null
54
54
i=1 for i in range(9): i+=1 print(f'1x{i}={1*i}') for i in range(9): i+=1 print(f'2x{i}={2*i}') for i in range(9): i+=1 print(f'3x{i}={3*i}') for i in range(9): i+=1 print(f'4x{i}={4*i}') for i in range(9): i+=1 print(f'5x{i}={5*i}') for i in range(9): i+=1 print(f'6x{i}={6*i}') for i in range(9): i+=1 print(f'7x{i}={7*i}') for i in range(9): i+=1 print(f'8x{i}={8*i}') for i in range(9): i+=1 print(f'9x{i}={9*i}')
a = [1,2,3,4,5,6,7,8,9] b = [1,2,3,4,5,6,7,8,9] if __name__ == "__main__": for x in a: for y in b: print(x,end="") print("x",end="") print(y,end="") print("=",end="") print(x*y) else: pass
1
318,432
null
1
1
import sys chash = {} for i in range( ord( 'a' ), ord( 'z' )+1 ): chash[ chr( i ) ] = 0 for line in sys.stdin: for i in range( len( line ) ): if line[i].isalpha(): chash[ line[i].lower() ] += 1 for i in range( ord( 'a' ), ord( 'z' )+1 ): print( "{:s} : {:d}".format( chr( i ), chash[ chr( i ) ] ) )
import sys s=sys.stdin.read().lower() [print(chr(i),':',s.count(chr(i)))for i in range(97,123)]
1
1,636,418,875,172
null
63
63
x,y=map(int,input().split()) print("{0} {1} {2:.8f}".format(x//y,x%y,x/y))
#coding: UTF-8 l = raw_input().split() a = int(l[0]) b = int(l[1]) if 1 <= a and b <= 1000000000: d = a / b r = a % b f = float (a )/ b print "%d %d %f" %(d, r, f)
1
593,619,028,122
null
45
45
N, M = map(int, input().split()) res = [] if N % 2 == 0: x = 0 for i in range(N // 2 // 2): res.append((x + 1, (x + 2 * i + 1) % N + 1)) x -= 1 x %= N for i in range((N // 2 - 1) // 2): res.append((x + 1, (x - (N // 2 - 1) // 2 * 2 + 2 * i) % N + 1)) x -= 1 x %= N else: for i in range(N // 2): res.append((i + 1, N - i - 1)) for i in range(M): a, b = res[i] print(a, b)
n=int(input()) f = False match=0 for i in range(n): a,b=map(int,input().split()) if a==b: match+=1 f |= (match == 3) else: match=0 if f: print("Yes") else: print("No")
0
null
15,614,675,821,900
162
72
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) d=abs(a-b) u = v-w if d-u*t<=0: print("YES") else: print('NO')
A,B,M=map(int,input().split()) a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] xyc=[[int(i)for i in input().split()]for j in range(M)] res=min(a)+min(b) for x,y,c in xyc: tmp=a[x-1]+b[y-1]-c res=min(res,tmp) print(res)
0
null
34,489,163,130,896
131
200
class Dice: def __init__(self,s1,s2,s3,s4,s5,s6): self.s1 = s1 self.s2= s2 self.s3= s3 self.s4= s4 self.s5 = s5 self.s6= s6 def east(self): prev_s1 = self.s1 #prev_s1を固定していないと以前の値が後述でs1に値を代入するとき変わってしまう。 prev_s3 = self.s3 prev_s4 = self.s4 prev_s6 = self.s6 self.s1 = prev_s4 self.s3 = prev_s1 self.s4 = prev_s6 self.s6 = prev_s3 def west(self): prev_s1 = self.s1 prev_s3 = self.s3 prev_s4 = self.s4 prev_s6 = self.s6 self.s1 = prev_s3 self.s3 = prev_s6 self.s4 = prev_s1 self.s6 = prev_s4 def south(self): prev_s1 = self.s1 prev_s2 = self.s2 prev_s5 = self.s5 prev_s6 = self.s6 self.s1 = prev_s5 self.s2 = prev_s1 self.s5 = prev_s6 self.s6 = prev_s2 def north(self): prev_s1 = self.s1 prev_s2 = self.s2 prev_s5 = self.s5 prev_s6 = self.s6 self.s1 = prev_s2 self.s2 = prev_s6 self.s5 = prev_s1 self.s6 = prev_s5 def top(self): return self.s1 s1,s2,s3,s4,s5,s6 = map(int,input().split()) dice = Dice(s1,s2,s3,s4,s5,s6) order = input() for c in order: if c =='N': dice.north() elif c =='S': dice.south() elif c =='E': dice.east() elif c == 'W': dice.west() print(dice.top())
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])
1
226,128,269,758
null
33
33
import sys input = sys.stdin.buffer.readline def main(): N,K = map(int,input().split()) a = list(map(int,input().split())) f = list(map(int,input().split())) a.sort() f.sort(reverse=True) l,r = -1,max(a)*max(f)+1 while r-l>1: mid = (r+l)//2 count = 0 for cost,dif in zip(a,f): if mid >= cost*dif: continue rest = cost*dif-mid count += -(-rest//dif) if count <= K: r = mid else: l = mid print(r) if __name__ == "__main__": main()
n, k = map(int, input().split()) *a, = map(int, input().split()) for i, j in zip(a, a[k:]): print('Yes' if i < j else 'No')
0
null
85,766,719,064,292
290
102
def main(): N = int(input()) A = list(map(int, input().split())) xor = 0 for a in A: xor ^= a ans = [xor ^ a for a in A] print(*ans) if __name__ == "__main__": main()
A, B = list(map(int,input().split())) if A - 2 * B >= 0: print(A - 2 * B) else: print(0)
0
null
89,361,022,107,808
123
291
from copy import copy import random import math import sys input = sys.stdin.readline D = int(input()) c = list(map(int,input().split())) s = [list(map(int,input().split())) for _ in range(D)] last = [0]*26 ans = [0]*D score = 0 for i in range(D): ps = [0]*26 for j in range(26): pl = copy(last) pl[j] = i+1 ps[j] += s[i][j] for k in range(26): ps[j] -= c[k]*(i+1-pl[k]) idx = ps.index(max(ps)) last[idx] = i+1 ans[i] = idx+1 score += max(ps) for k in range(1,40001): na = copy(ans) x = random.randint(1,365) y = random.randint(1,365) na[x-1] = na[y-1] last = [0]*26 ns = 0 for i in range(D): last[na[i]-1] = i+1 ns += s[i][na[i]-1] for j in range(26): ns -= c[j]*(i+1-last[j]) if k%100 == 1: T = 80-(79*k/40000) p = pow(math.e,-abs(ns-score)/T) if ns > score or random.random() < p: ans = na score = ns for a in ans: print(a)
n = int(input()) s = str(input()) s += "A" q = s[0] ans = 0 for i in range(n+1): if(q==s[i]): None else: ans += 1 q = s[i] print(ans)
0
null
89,618,212,742,034
113
293
a = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for i in range(1, n + 1): b, f, r, v = map(int, input().split()) a[b-1][f-1][r-1] += v for i in range(4): for j in range(3): for k in range(10): print("", a[i][j][k], end="") if k == 9: print() if j == 2 and i != 3: print("####################")
n = int(input()) s = input() h = int(n/2) s=list(s) if s[0:h] == s[h:n]: print("Yes") else: print("No")
0
null
73,704,843,466,338
55
279
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print('\n'.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) mod = 998244353 n,k = readints() s = [readints() for i in range(k)] a = [0] * (n+1) a[1] = 1 b = [0] * k for i in range(2,n+1): for j in range(k): l,r = s[j] if i-l>0: b[j] += a[i-l] if i-r-1>0: b[j] -= a[i-r-1] a[i] += b[j] a[i] %= mod print(a[-1])
MOD = 998244353 def main(): # もらうdp + 累積和 N, K = (int(i) for i in input().split()) LR = [[int(i) for i in input().split()] for j in range(K)] dp = [0] * (N+2) dpsum = [0] * (N+1) dp[1] = 1 dpsum[1] = 1 for i in range(2, N+1): for le, ri in LR: L = max(0, i - ri - 1) R = i - le if R < 1: continue dp[i] += dpsum[R] - dpsum[L] dp[i] %= MOD dpsum[i] += dpsum[i-1] + dp[i] dpsum[i] %= MOD print(dp[N]) # print(dpsum) if __name__ == '__main__': main()
1
2,748,223,231,360
null
74
74
import sys n = int(input()) r0 = int(input()) r1 = int(input()) mx = r1-r0 mn = min(r1,r0) l = map(int,sys.stdin.readlines()) for i in l: if mx < i - mn: mx = i - mn elif mn > i: mn = i print(mx)
a,b=map(int,input().split());print(a//b,a%b,'%.8f'%(a/b))
0
null
301,373,274,400
13
45
L,R,d = list(map(int,input().strip().split())) print(R//d-(L-1)//d)
li =list(map(int,input().split())) n =li[0] m =li[1] k =li[2] count =0 for i in range(n,m+1): if i%k ==0: count +=1 print(count)
1
7,536,234,283,578
null
104
104
import bisect n = int(input()) l = list(map(int, input().split())) ans = 0 l.sort() for i in range(n-2): for j in range(i+1, n-1): c_i = bisect.bisect_left(l, l[i]+l[j]) if c_i > j: ans += c_i - j - 1 else: continue print(ans)
import itertools import bisect N = int(input()) L = list(map(int, input().split())) ans = 0 LS = sorted(L) l = len(LS) for i in range(l): for j in range(l): if i < j: k = bisect.bisect_left(LS,LS[i]+LS[j]) ans += k-j-1 print(ans)
1
171,503,205,538,070
null
294
294
N, M, K = map(int, input().split()) friend = {} for i in range(M): A, B = map(lambda x: x-1, map(int, input().split())) if A not in friend: friend[A] = [] if B not in friend: friend[B] = [] friend[A].append(B) friend[B].append(A) block = {} for i in range(K): C, D = map(lambda x: x-1, map(int, input().split())) if C not in block: block[C] = [] if D not in block: block[D] = [] block[C].append(D) block[D].append(C) first = {} for i in range(N): if i not in first: first[i] = i if i in friend: queue = [] queue.extend(friend[i]) counter = 0 while counter < len(queue): item = queue[counter] first[item] = i if item in friend: for n in friend[item]: if n not in first: queue.append(n) counter += 1 size = {} for key in first: if first[key] not in size: size[first[key]] = 1 else: size[first[key]] += 1 for i in range(N): if i not in friend: print(0) continue no_friend = 0 if i in block: for b in block[i]: if first[b] == first[i]: no_friend += 1 print(size[first[i]] - len(friend[i]) - no_friend - 1)
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) n, m, k = map(int, input().split()) u = UnionFind(n + 1) already = [0] * (n + 1) for i in range(m): a, b = map(int, input().split()) u.union(a, b) already[a] += 1 already[b] += 1 for i in range(k): c, d = map(int, input().split()) if u.same(c, d): already[c] += 1 already[d] += 1 for i in range(1, n + 1): print(u.size(i) - already[i] - 1)
1
61,549,367,529,400
null
209
209
import math N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 def lcm(x, y): return (x // math.gcd(x, y)) * y LCM = A[0] for i in range(N-1): LCM = lcm(LCM, A[i+1]) #LCM %= mod ans = 0 for a in A: ans += LCM * pow(a, mod-2, mod) % mod ans %= mod print(ans)
N = int(input()) Ss = input().rstrip() ans = Ss.count('ABC') print(ans)
0
null
93,814,768,037,052
235
245
n, m = map(int, input().split()) c = list(map(int, input().split())) # dp[i][j] = i 番目までを使用して総和がj になる組み合わせ INF = 5 * 10 ** 4 dp = [[INF] * (n + 1) for _ in range(m + 1)] dp[0][0] = 0 for i in range(1, m + 1): for j in range(n + 1): if j >= c[i - 1]: dp[i][j] = min( dp[i - 1][j], dp[i - 1][j - c[i - 1]] + 1, dp[i][j - c[i - 1]] + 1 )# dp[i - 1][j - c[i - 1]] だと、複数回 コインを使う場合に対応していない else: dp[i][j] = dp[i - 1][j] print(dp[m][n])
N,K = map(int,input().split()) p = list(map(int,input().split())) l = [] for i in range(N): l.append(((1+p[i])*(p[i]/2))/p[i]) que = [0]*(N+1) for i in range(1,N+1): que[i] = l[i-1]+que[i-1] ans = 0 for i in range(K,len(l)): ans = max(ans,que[i+1]-que[i+1-K]) if N == K: print(max(que)) else: print(ans)
0
null
37,409,154,487,278
28
223
X,K,D = map(int,input().split()) X = abs(X) if X - D * K >= 0: print(X - D * K) else: n = X // D X -= n * D if (K - n) % 2 == 0: print(X) else: print(abs(X - D))
x,k,d = list(map(int, input().split())) x = abs(x) a,b = divmod(x, d) a = min(a, k) x -= a * d #print('a=',a) #print('x=',x) #print('ka=',k-a) x -= d * ((k-a) % 2) print(abs(x))
1
5,187,909,986,040
null
92
92
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**7) from pprint import pprint as pp from pprint import pformat as pf # @pysnooper.snoop() #import pysnooper # debug import math #from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder import bisect class Solver: def __init__(self, n, a_s): self.n = n self.a_s = a_s self.extra = 1 if self.n % 2 == 0 else 2 self.dp = self.prepare_dp() def prepare_dp(self): dp = [None] * (self.n + 1) for i, _ in enumerate(dp): dp[i] = [-1 * math.inf] * (1 + self.extra) dp[0][0] = 0 return dp def run(self): extra = 1 + self.n % 2 for i, a in enumerate(self.a_s): for j in range(self.extra): self.dp[i + 1][j + 1] = self.dp[i][j] for j in range(self.extra + 1): v = self.dp[i][j] if (i + j) % 2 == 0: v += a self.dp[i + 1][j] = max(self.dp[i + 1][j], v) #print('self.dp') # debug #print(self.dp) # debug return self.dp[n][extra] if __name__ == '__main__': n = int(input()) a_s = list(map(int, input().split())) ans = Solver(n, a_s).run() #print('ans') # debug print(ans) #print('\33[32m' + 'end' + '\033[0m') # debug
import sys sys.setrecursionlimit(10 ** 9) def solve(pick, idx): if pick == 0: return 0 if idx >= n: return -float('inf') if (pick, idx) in dp: return dp[pick, idx] if n-idx+2 < pick*2: return -float('inf') total = max(A[idx] + solve(pick-1, idx+2), solve(pick, idx+1)) dp[(pick, idx)] = total return total n = int(input()) A = list(map(int, input().split())) dp = {} pick = n//2 print(solve(pick, 0))
1
37,481,134,584,480
null
177
177
N = int(input()) flag = 0 ans = "No" for i in range(N): A,B = input().split() if A == B: flag += 1 else: flag = 0 if flag == 3: ans = "Yes" break print(ans)
def read_a(n, m): A = [] for _ in range(0, n): A.append([int(x) for x in input().split()]) return A def read_b(m): B = [] for _ in range(0, m): B.append(int(input())) return B def multiply(A, B): C = [] for a in A: C.append(sum(map(lambda x, y:x*y, a, B))) return C def main(): n, m = [int(x) for x in input().split()] A = read_a(n, m) B = read_b(m) C = multiply(A, B) print("\n".join([str(x) for x in C])) if __name__ == '__main__': main()
0
null
1,799,793,471,652
72
56
import sys input = sys.stdin.buffer.readline N = int(input()) AB = [list(map(int, input().split())) for _ in range(N)] ans = "No" for i in range(N-2): ok = (AB[i][0] == AB[i][1] and AB[i+1][0] == AB[i+1][1] and AB[i+2][0] == AB[i+2][1]) if ok: ans = "Yes" print(ans)
N = int(input()) zoro_count = 0 zoro = False for n in range(N): dn1,dn2 = map(int, input().split()) if dn1 == dn2: zoro_count += 1 else: zoro_count = 0 if zoro_count >= 3: zoro = True if zoro: print('Yes') else: print('No')
1
2,500,313,494,930
null
72
72
a=input() b=input() if (a=="1" and b=="2")or(a=="2" and b=="1"): print("3") if (a=="1" and b=="3")or(a=="3" and b=="1"): print("2") if (a=="3" and b=="2")or(a=="2" and b=="3"): print("1")
money = 100000 for _ in range(int(input())): money += int(money * 0.05) if money % 1000 != 0: while money % 1000 != 0: money += 1 print(money)
0
null
55,559,946,383,260
254
6
N, M, Q = map(int, input().split()) cond = [] for i in range(Q): a, b, c, d = map(int, input().split()) cond.append((a - 1, b - 1, c, d)) def dfs(A, head): if len(A) == N: score = 0 for a, b, c, d in cond: if A[b] - A[a] == c: score += d return score ans = 0 for n in range(head, M + 1): ans = max(ans, dfs(A + [n], n)) return ans print(dfs([1], 1))
from collections import deque n = int(input()) answer = deque() for i in range(n): command = input() if " " in command: command, key = command.split() if command == "insert": answer.appendleft(key) elif command == "delete": if key in answer: answer.remove(key) elif command == "deleteFirst": answer.popleft() elif command == "deleteLast": answer.pop() print(*answer)
0
null
13,707,322,497,150
160
20
import sys input = sys.stdin.readline def main(): N = int( input()) U = [] V = [] for _ in range(N): x, y = map( int, input().split()) u, v = x+y, x-y U.append(u) V.append(v) U.sort() V.sort() print( max(U[-1]-U[0], V[-1]-V[0])) if __name__ == '__main__': main()
def main(): N = int(input()) X = [] Y = [] for _ in range(N): x, y = (int(i) for i in input().split()) X.append(x + y) Y.append(x - y) ans = max(max(X) - min(X), max(Y) - min(Y)) print(ans) if __name__ == '__main__': main()
1
3,408,800,982,620
null
80
80
import math N=int(input()) price=math.ceil(N/1.08) print(price if math.floor(price*1.08)==N else ":(")
n = int(input()) p2 = (n + 1) / 1.08 p1 = n / 1.08 if p2 > int(p2) >= p1: print(int(p2)) else: print(":(")
1
125,785,968,696,048
null
265
265
n=int(input()) s={} for i in range(n): si = input() if si not in s: s[si] = 1 else: s[si]+=1 sa = sorted(s.items()) ma = max(s.values()) for a in sorted(a for a in s if s[a]==ma): print(a)
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし N,R = MI() print(R if N >= 10 else R+100*(10-N))
0
null
66,823,340,315,200
218
211
# E - Payment N = input().strip() s = 0 carry = 0 five = False for c in reversed(N): x = int(c) + carry if x == 5 and not five: s += x carry = 0 five = True elif x >= 5: if five: x += 1 s += 10 - x carry = 1 five = False else: s += x carry = 0 five = False s += carry print(s)
W,H,x,y,r = map(int,input().split()) if x-r<0 or W<x+r or y-r<0 or H<y+r: print('No') else: print('Yes')
0
null
35,928,032,496,060
219
41
N = int(input().rstrip()) A = list(map(int, input().rstrip().split())) def bubble_sort(A, N): count = 0 flag = 1 while flag: flag = 0 for j in range(N-1, 0, -1): if A[j] < A[j-1]: A[j], A[j-1] = A[j-1], A[j] count += 1 flag = 1 return A, count A, count = bubble_sort(A, N) string = list(map(str, A)) print(' '.join(string)) print(count)
# encoding: utf-8 def bubble_sort(A, N): flag = 1 count = 0 while flag: flag = 0 for j in xrange(N-1, 0, -1): if A[j] < A[j-1]: A[j], A[j-1] = A[j-1], A[j] flag = 1 count += 1 return A, count def main(): N = input() A = map(int, raw_input().split()) A, count = bubble_sort(A, N) print " ".join(map(str,A)) print count main()
1
16,122,036,580
null
14
14
n, k = map(int, input().split()) a = list(map(int, input().split())) f = list(map(int, input().split())) a.sort() f.sort() high = max(a)*max(f) low = 0 while high > low: mid = (high+low)//2 b = 0 for i in range(n): b += max(a[i]-mid//f[n-i-1],0) if b > k: low = mid + (low==mid) else: high = mid - (high==mid) mid = (high+low)//2 print(mid)
a, b = list(map(int, input().split())) if a * 500 >= b: my_result = 'Yes' else: my_result = 'No' print(my_result)
0
null
131,427,213,181,248
290
244
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N,K = LI() f = [1] r = [1] s = 1 for i in range(1,N+2): s = (s * i) % MOD f.append(s) r.append(pow(s,MOD-2,MOD)) def comb(a,b): return f[a] * r[b] * r[a-b] ans = 0 for k in range(min(K,N-1)+1): ans = (ans + comb(N,k) * comb(N-1,k)) % MOD print(ans) if __name__ == '__main__': main()
MOD = 1000000007#い つ も の n,k = map(int,input().split()) nCk = 1#nC0 ans = 1 if k > n-1: k = n-1 for i in range(1,k+1,1): nCk = (((nCk*(n-i+1))%MOD)*pow(i,1000000005,1000000007))%MOD ans = (ans%MOD + ((((nCk*nCk)%MOD)*(n-i)%MOD)*pow(n,1000000005,1000000007)%MOD)%MOD)%MOD print(ans)
1
66,953,378,152,836
null
215
215
s=str(input()) s=list(s) q=int(input()) sb=[0]*(q+1) sa=[0]*(q+1) sbi=0 sai=0 ta=0 for i in range(q): temp=str(input()) temp=list(temp) if temp[0]=="1": ta=ta+1 else: if (temp[2]=="1" and ta%2==0) or (temp[2]=="2" and ta%2!=0): sb[sbi]=temp[4] sbi=sbi+1 else: sa[sai]=temp[4] sai=sai+1 lsb=sb.index(0) lsa=sa.index(0) sb.reverse() ans=sb[len(sb)-lsb:len(sb)]+s+sa[0:lsa] if ta%2!=0: ans.reverse() print("".join(ans))
from fractions import gcd from functools import reduce n = int(input()) a_list = [int(x) for x in input().split()] temp = reduce(lambda x, y: (x * y) // gcd(x, y), a_list) mod = 10 ** 9 + 7 ans = sum([temp // a for a in a_list]) % mod print(ans)
0
null
72,036,364,656,046
204
235
N = int(input()) s = [] t = [] for i in range(N) : p, q = input().split() s.append(p) t.append(int(q)) X = input() xi = s.index(X) ans = 0 for i in range(xi+1, N) : ans += t[i] print(ans)
n=int(input()) a=list() for i in range(n): s,t=input().split() a.append([s,int(t)]) x=input() flag=False ans=0 for i in a: if flag: ans+=i[1] if i[0]==x: flag=True print(ans)
1
97,130,407,863,138
null
243
243
h, w, k = map(int, input().split()) s = [list(map(int, list(input()))) for _ in range(h)] result = [] if h*w<=k: result.append(0) else: for i in range(2**(h-1)): checker, num, p = 0, i ,[0] for _ in range(h): p.append(p[-1]+num%2) checker += num%2 num >>= 1 x = 0 c = [0 for _ in range(checker+1)] for j in range(w): num = i nex = [0 for _ in range(checker+1)] for m in range(h): nex[p[m]] += s[m][j] if max(nex) > k: x = float('inf') break if all(nex[m]+c[m] <= k for m in range(checker+1)): c = [c[I]+nex[I] for I in range(checker+1)] else: x += 1 c = nex result.append(checker+x) print(min(result))
n = input() print("Yes" if "7" in n else "No")
0
null
41,409,199,018,968
193
172
N,X,M=map(int, input().split()) p=[0]*(M+2) sum=[0]*(M+2) p[X]=1 sum[1]=X f=0 for i in range(2,N+1): X=(X**2)%M if p[X]!=0: j=p[X] f=i break else: sum[i]=X+sum[i-1] p[X]+=i if f==0: print(sum[N]) else: d,mod=divmod(N-j+1,i-j) print(d*(sum[i-1]-sum[j-1])+sum[j+mod-1])
process_num, qms = map(int, input().split()) raw_procs = [input() for i in range(process_num)] if __name__ == '__main__': procs = [] for row in raw_procs: name, time = row.split() procs.append({ "name": name, "time": int(time), }) total_time = 0 current_proc = 0 while len(procs) > 0: if procs[current_proc]["time"] > qms: procs[current_proc]["time"] = procs[current_proc]["time"] - qms total_time += qms if current_proc == len(procs)-1: current_proc = 0 else: current_proc += 1 else: total_time += procs[current_proc]["time"] print("{} {}".format(procs[current_proc]["name"], total_time)) del procs[current_proc] if current_proc == len(procs): current_proc = 0
0
null
1,413,598,218,314
75
19
from collections import deque n,q = tuple([int(i) for i in input().split()]) lines = [input().split() for i in range(n)] pro = deque([[i[0], int(i[1])] for i in lines]) time = 0 while True: left = pro.popleft() if left[1] - q > 0: time += q pro.append([left[0], left[1] - q]) else: time += left[1] print(' '.join([left[0], str(time)])) if len(pro) == 0: break;
import queue n, quantum = map(int, input().split()) q = queue.Queue() for _ in range(n): name, time = input().split() q.put([name, int(time)]) spend_time = 0 while q.qsize() > 0: name, time = q.get() tmp = min(quantum, time) spend_time += tmp time -= tmp if time == 0: print('{} {}'.format(name, spend_time)) else: q.put([name, time])
1
42,082,691,520
null
19
19
def main(): a, b, k = map(int, input().split()) if a >= k: remain_a = a - k remain_b = b else: remain_a = 0 if k - a >= b: remain_b = 0 else: remain_b = b - (k - a) print(remain_a, remain_b) if __name__ == "__main__": main()
a,b,k = map(int,input().split()) if a == k : print(0,b) elif a > k : print(a-k,b) elif a < k : c = b - (k-a) if c >= 0 : print(0,c) else : print(0,0)
1
103,894,615,853,250
null
249
249
n=int(input()) if n==2: count=1 else: count=2 for i in range(2,int(n**0.5)+1): if n%i==0: k=n//i while k>0: if k%i==0: k=k//i else: if k%i==1: count+=1 break elif (n-1)%i==0: count+=1 if i!=(n-1)//i: count+=1 print(count)
import sys from collections import defaultdict def input(): return sys.stdin.readline().strip() from math import sqrt def factor(n): """ nの約数を個数と共にリストにして返す。 ただしあとの都合上1は除外する。 """ if n == 1: return 0, [] if n == 2: return 1, [2] if n == 3: return 1, [3] d = int(sqrt(n)) num = 1 factor_pre = [] factor_post = [n] for i in range(2, d): if n % i == 0: factor_pre.append(i) factor_post.append(n // i) num += 2 if d * d == n: factor_pre.append(d) num += 1 elif n % d == 0: factor_pre.append(d) factor_post.append(n // d) num += 2 factor_post.reverse() return num, factor_pre + factor_post def main(): N = int(input()) """ 題を満たすKは、 N = K^e * n、(n, K) = 1 として n = K * m + 1 (m ¥in ¥mathbb{N}) とかければ良い。 2つ目の式からnとKが互いに素なのは明らかなので、問題文は N = K^e * (K * m + 1) (m ¥in ¥mathbb{N}) なるKを求めることに同値。 なのでまずはNの約数を全列挙して、あとはNをそれで割った商がKで割って1余るか確かめれば良い。 """ _, fact = factor(N) ans, ans_list = factor(N - 1) # print(ans_list) # print("Now we check the list {}".format(fact)) for K in fact: n = N while n % K == 0: n //= K if n % K == 1: ans += 1 ans_list.append(K) # print("{} added".format(K)) # print("ans={}: {}".format(ans, ans_list)) print(ans) if __name__ == "__main__": main()
1
41,150,658,490,068
null
183
183
def resolve(): N,K,C = map(int,input().split()) S=input() dpt1=[0]*K dpt2=[0]*K pnt = 0 for i in range(K): while S[pnt]=="x": pnt+=1 dpt1[i]=pnt pnt += C+1 pnt = N-1 for i in range(K-1,-1,-1): while S[pnt] == "x": pnt -=1 dpt2[i]=pnt pnt-=C+1 for a,b in zip(dpt1,dpt2): if a == b: print(a+1) if __name__ == "__main__": resolve()
n, k, c = map(int, input().split()) s = input() s2 = s[::-1] dp1 = [0] * (n + 2) dp2 = [0] * (n + 2) for (dp, ss) in zip([dp1, dp2], [s, s2]): for i in range(n): if ss[i] == 'x': dp[i+1] = dp[i] elif i <= c: dp[i+1] = min(1, dp[i] + 1) else: dp[i+1] = max(dp[i-c] + 1, dp[i]) dp2 = dp2[::-1] for i in range(1, n+1): if s[i-1] == 'o' and dp1[i-1] + dp2[i+1] < k: print(i)
1
40,670,503,032,220
null
182
182
S = input() if S == 'MON': print("6") elif S == 'TUE': print("5") elif S == 'WED': print("4") elif S == 'THU': print("3") elif S == 'FRI': print("2") elif S == 'SAT': print("1") elif S == 'SUN': print("7")
m = [] for _ in range(10): r = int(input()) m.append(r) m.sort() print (m[9]); print (m[8]); print (m[7]);
0
null
66,366,181,273,742
270
2
import bisect N=int(input()) L=list(map(int,input().split())) L=sorted(L) ans=0 for i in range(N): for j in range(i+1,N): k=bisect.bisect_left(L,L[i]+L[j]) ans+=k-j-1 print(ans)
print("YNeos"["".join(input().split("hi"))!=""::2])
0
null
112,277,878,921,088
294
199
n = input() ans = 0 for i in range(len(n)): ans += int(n[i]) ans %= 9 print("Yes" if ans % 9 == 0 else "No")
N = int(input()) n = str(N) le = len(n) M = 0 for i in range(le): nn = int(n[i]) M += nn if M % 9 == 0: print("Yes") else: print("No")
1
4,388,098,462,612
null
87
87
N = int(input()) ret = False if N % 2 == 0: S = input() if S[:N//2] == S[N//2:]: ret = True if ret: print("Yes") else: print("No")
S=int(input()) T=list(input()) t=S//2 p=0 for i in range(t): if S%2==1: p=-1 break elif T[i]!=T[i+t]: p=-1 break if p==-1 or t==0: print("No") elif p==0: print("Yes")
1
147,293,995,007,330
null
279
279
#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) n = inn() ls = [] rs = [] z = 0 for i in range(n): ss = ins() l = r = 0 for c in ss: if c=='(': l += 1 else: if l>0: l -= 1 else: r += 1 rr = r l = r = 0 for j in range(len(ss)-1,-1,-1): c = ss[j] if c==')': r += 1 else: if r>0: r -= 1 else: l += 1 r = rr if l>r: ls.append((r,l-r)) elif l<r: rs.append((l,r-l)) else: z = max(z,r) ls.sort() rs.sort() #ddprint(ls) #ddprint(rs) #ddprint(z) l = r = 0 for rr,ll in ls: if l<rr: print('No') exit() l = l+ll for ll,rr in rs: if r<ll: print('No') exit() r = r+rr print('Yes' if l==r>=z else 'No')
import sys readline = sys.stdin.readline N = int(readline()) S = [readline().rstrip() for _ in range(N)] def count_cb_ob(s): st = [] for i, si in enumerate(s): if si == '(' or len(st) == 0 or st[-1] != '(': st.append(si) else: st.pop() return st.count(')'), st.count('(') cb_obs = map(count_cb_ob, S) f, b, s = [], [], [] for down, up in cb_obs: (f if down < up else (s if down == up else b)).append((down, up)) f = sorted(f) b = sorted(b, key=lambda x:x[1], reverse=True) count = 0 ans = 'Yes' for down, up in (*f, *s, *b): count -= down if count < 0: ans = 'No' count += up if count != 0: ans = 'No' print(ans)
1
23,689,147,278,460
null
152
152
N = int(input()) print(int(N / 2)) if N % 2 == 0 else print(N // 2 + 1)
N = int(input()) A = N / 2 A = int(A) B = (N + 1) / 2 B = int(B) if N % 2 == 0: print(A) else: print(B)
1
59,190,838,495,712
null
206
206
a_len = int(input()) a_ar = sorted([int(n) for n in input().split(" ")]) b_len = int(input()) b_ar = [int(n) for n in input().split(" ")] dp = [0 for n in range(2001)] for a in a_ar: new_dp = dp[:] new_dp[a] = 1 for i,d in enumerate(dp): if d and i + a <= 2000: new_dp[i + a] = 1 elif i + a > 2000: break dp = new_dp for b in b_ar: if dp[b]: print("yes") else: print("no")
x=input() ret = '' for a in x: if a.islower() : a = a.upper() elif a.isupper(): a = a.lower() ret += a print(ret)
0
null
786,004,178,818
25
61
import math #import numpy as np import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): n,u,v = map(int,ipt().split()) way = [[] for _ in range(n+1)] for _ in range(n-1): a,b = map(int,ipt().split()) way[a].append(b) way[b].append(a) ta = [-1]*(n+1) tt = [-1]*(n+1) ta[v] = 0 #AOKI tt[u] = 0 qa = queue.Queue() qt = queue.Queue() qt.put((0,u,-1)) qa.put((0,v,-1)) while not qa.empty(): ti,pi,pp = qa.get() for i in way[pi]: if i == pp: continue if ta[i] == -1: ta[i] = ti+1 qa.put((ti+1,i,pi)) while not qt.empty(): ti,pi,pp = qt.get() if ta[pi] <= ti: continue for i in way[pi]: if i == pp: continue if ta[i] > ti: tt[i] = ti+1 qt.put((ti+1,i,pi)) ma = 0 for i in range(1,n+1): if tt[i] == -1: continue if ma < tt[i]+max(0,ta[i]-tt[i]-1): ma = tt[i]+max(0,ta[i]-tt[i]-1) print(ma) return if __name__ == '__main__': main()
from collections import deque n, u, v = map(int, input().split()) u-=1; v-=1; a = []; b = []; dist = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) a -= 1; b -= 1 dist[a].append(b) dist[b].append(a) def bfs(u): d = [-1]*n stack = deque([u]) d[u] = 0 while len(stack)!=0: s = stack.popleft() for t in dist[s]: if d[t]==-1: d[t] = d[s]+1 stack.append(t) return d A = bfs(v) T = bfs(u) ans=0 for i in range(n): if A[i]>T[i]: ans = max(A[i]-1, ans) print(ans)
1
116,912,577,822,080
null
259
259
#dp #dp[T] T分での最大幸福 幸福度B、時間A N,T = map(int,input().split()) li = [list(map(int,input().split())) for _ in range(N)] li = sorted(li,key=lambda x: x[0]) dp = [0]*T counter = 0 for i in range(N-1): A,B = li[i] counter = max(counter,max(dp)+B) if A>T-1: continue for t in range(T-A-1,-1,-1): dp[t+A]=max(dp[t]+B,dp[t+A]) print(max(max(dp)+li[N-1][1],counter))
import sys input = lambda: sys.stdin.readline().rstrip() s = input() n = len(s) if n == s.count("hi")*2: print("Yes") else: print("No")
0
null
102,470,712,545,348
282
199
# -*- coding: utf-8 -*- class Card: def __init__(self, str): self.suit = str[0] self.value = int(str[1]) def __str__(self): return self.suit + str(self.value) def swap(A, i, j): tmp = A[i] A[i] = A[j] A[j] = tmp def BubbleSort(C, N): for i in range(N): for j in range(N-1, i, -1): if C[j].value < C[j-1].value: swap(C, j, j-1) # C[j] と C[j-1] を交換 def SelectionSort(C, N): for i in range(N): minj = i for j in range(i, N): if C[j].value < C[minj].value: minj = j swap(C, i, minj) # C[i] と C[minj] を交換 def isStable(A, B): for i in range(1, len(B)): if B[i-1].value == B[i].value: for j in range(len(A)): if A[j] == B[i-1]: break if A[j] == B[i]: return False return True N = int(input()) A = [Card(t) for t in input().split()] if len(A) != N: raise B = A[:] S = A[:] BubbleSort(B, N) SelectionSort(S, N) print(' '.join(map(str, B))) print('Stable' if isStable(A, B) else 'Not stable') print(' '.join(map(str, S))) print('Stable' if isStable(A, S) else 'Not stable')
N = int(input()) l = input().split() l2 = l[:] for j in range(N): for i in range(N-1): if l[i][1] > l[i+1][1]: l[i], l[i+1] = l[i+1], l[i] for i in range(0,len(l)-1): print(l[i],end=' ') print(l[N-1]) print("Stable") for j in range(0,len(l2)-1): min = l2[j][1] a = j for i in range(j,len(l2)): if min > l2[i][1]: min = l2[i][1] a = i l2[j],l2[a] = l2[a],l2[j] for i in range(0,len(l2)-1): print(l2[i],end=' ') print(l2[N-1]) if l==l2: print("Stable") else: print("Not stable")
1
26,544,807,740
null
16
16
from collections import deque N, X, Y = map(int, input().split()) ans = [0] * N for i in range(N-1): dist_list = [-1] * N d = deque([[i]]) dist = 0 while d[0]: tag = d.popleft() next_tag = [] for t in tag: if dist_list[t] == -1: dist_list[t] = dist if t - 1 >= 0: if dist_list[t - 1] == -1: next_tag.append(t-1) if t + 1 < N: if dist_list[t + 1] == -1: next_tag.append(t + 1) if t == X-1: if dist_list[Y-1] == -1: next_tag.append(Y-1) if t == Y-1: if dist_list[X-1] == -1: next_tag.append(X-1) d.append(next_tag) dist += 1 for j in range(i+1, N): ans[dist_list[j]] += 1 for i in range(1,N): print(ans[i])
from collections import Counter def dis(i,j, x,y): return min(j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+(j-x)) n, x, y = map(int, input().split()) x,y = x-1,y-1 D = [] for i in range(n-1): for j in range(i+1, n): D.append(dis(i,j, x,y)) cD = Counter(D) for i in range(1, n): print(cD[i])
1
44,109,371,226,328
null
187
187
from collections import deque from collections import defaultdict n, m = map(int, input().split()) g = defaultdict(list) s = set(list(range(1, n+1))) ans = 0 for i in range(m): a, b = map(int, input().split()) g[a].append(b) g[b].append(a) while s: root = s.pop() q = deque() q.append(root) done = set() done.add(root) while q: node = q.popleft() for adj in g[node]: if adj not in done: done.add(adj) q.append(adj) s.remove(adj) ans += 1 print(ans - 1)
a,b,c,k=[int(i) for i in input().split()] if a>=k: print(k) elif a+b>=k: print(a) else: print(a-(k-a-b))
0
null
12,060,220,609,788
70
148
a,b,c=map(int,input().split()) bj = a+b+c if bj <= 21: print("win") else: print("bust")
def resolve(): A = sum(map(int, input().split())) print("bust" if A >= 22 else "win") if '__main__' == __name__: resolve()
1
119,104,260,145,470
null
260
260
a,b,x=map(int,input().split()) import math v=a*a*b if x>=v/2: print(180*math.atan(2*(v-x)/(a*a*a))/math.pi) else: print(90-(180*math.atan(2*x/(a*b*b)))/math.pi)
import math a, b, x = map(float, input().split()) if a * a * b <= x * 2: h = 2 * (b - x / a / a) ret = math.degrees(math.atan2(h, a)) else: h = 2 * x / a / b ret = 90 - math.degrees(math.atan2(h, b)) print(ret)
1
163,493,102,091,200
null
289
289
k = int(input()) a, b = map(int, input().split()) while a <= b: if a % k == 0: print('OK') exit() a += 1 print('NG')
K = int(input()) A,B = list(map(int,input().split())) flag=False for i in range(A,B+1): if i%K == 0: flag=True print("OK" if flag else "NG")
1
26,673,025,213,420
null
158
158
a = list(map(int,input().split())) print(a[0]*a[1] if a[0] <= 9 and a[1] <= 9 else -1)
A, B = map(int, input().split()) if 1<=A<=9 and 1<=B<=9: print(A*B) else: print(-1)
1
158,426,878,823,918
null
286
286
D=int(input()) c=list(map(int,input().split())) s=[] for i in range(D): s.append(list(map(int,input().split()))) t=[] for i in range(D): t.append(int(input())) last_di=[0]*26 m=0 for i in range(D): m+=s[i][t[i]-1] last_di[t[i]-1]=i+1 for j in range(26): m-=c[j]*((i+1)-last_di[j]) print(m)
import numpy as np import copy d=int(input()) c=np.array(list(map(int,input().split()))) curc=copy.deepcopy(c) s=[] ans=[] score=0 for i in range(d): s.append(list(map(int,input().split()))) for i in range(d): t=int(input()) score+=s[i][t-1] curc[t-1]=0 score-=sum(curc) curc+=c print(score)
1
10,003,936,392,608
null
114
114
from collections import deque slope = input() down_slope = deque() total_slopes = deque() for i in range(len(slope)): if slope[i] == '\\': down_slope.append(i) elif slope[i] == '/': area = 0 if len(down_slope) > 0: while len(total_slopes) > 0 and total_slopes[-1][0] > down_slope[-1]: area += total_slopes[-1][1] total_slopes.pop() area += i-down_slope[-1] total_slopes.append([down_slope[-1],area]) down_slope.pop() if len(total_slopes) > 0: total_slopes = [i[1] for i in total_slopes] print(sum(total_slopes)) print(len(total_slopes),end=' ') print(' '.join(map(str,total_slopes))) else: print(0) print(0)
a, b, k = list(map(int, input().split(' '))) print(max(0, a-k), max(0, b-max(0, k-a)))
0
null
52,335,808,138,700
21
249
from copy import deepcopy def bubbleSort(C, N): for i in range(N): for j in range(N - 1, i, - 1): if C[j][1] < C[j - 1][1]: C[j], C[j - 1] = C[j - 1], C[j] def selectionSort(C, N): for i in range(N): minj = i for j in range(i, N): if C[j][1] < C[minj][1]: minj = j C[i], C[minj] = C[minj], C[i] N = int(input()) C = list(map(str, input().split())) C1 = deepcopy(C) C2 = deepcopy(C) bubbleSort(C1, N) selectionSort(C2, N) O = [[] for _ in range(9)] for i in range(N): j = int(C[i][1]) - 1 O[j].append(C[i][0]) O1 = [[] for _ in range(9)] for i in range(N): j = int(C1[i][1]) - 1 O1[j].append(C1[i][0]) O2 = [[] for _ in range(9)] for i in range(N): j = int(C2[i][1]) - 1 O2[j].append(C2[i][0]) for i in range(N): if i == N - 1: print(C1[i]) else: print(C1[i], end=' ') if O == O1: print('Stable') else: print('Not stable') for i in range(N): if i == N - 1: print(C2[i]) else: print(C2[i], end=' ') if O == O2: print('Stable') else: print('Not stable')
N = int(input()) C = input().split() _C = C.copy() for i in range(N): for j in range(N-1, i, -1): if (C[j][1] < C[j-1][1]): C[j], C[j-1] = C[j-1], C[j] print(*C) print("Stable") for i in range(N): m = i for j in range(i, N): if (_C[j][1] < _C[m][1]): m = j _C[i], _C[m] = _C[m], _C[i] print(*_C) if(C ==_C): print("Stable") else: print("Not stable")
1
26,259,699,172
null
16
16
def main(): n, r = map(int, input().split(" ")) print(r+100*(10-min(10,n))) if __name__ == "__main__": main()
[print('{}x{}={}'.format(i, j, i * j)) for i in range(1, 10) for j in range(1, 10)]
0
null
31,803,791,175,580
211
1
n = int(input()) d = dict() for i in range(n): s = input() if(s not in d.keys()): d[s] = 1 else: d[s] +=1 max = max(d.values()) ans = [] for i in d.keys(): if(d[i] == max): ans.append(i) for i in sorted(ans): print(i)
t = input().lower() cnt = 0 while True: w = input() if w == 'END_OF_TEXT': break cnt += len(list(filter(lambda x: x == t, [v.lower() for v in w.split(' ')]))) print(cnt)
0
null
36,127,160,757,980
218
65
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) x, y, z = inm() print(z, x, y)
A,B,C,D = map(int, input().split()) n = 0 if C%B ==0: if A-(C//B-1)*D > 0: print('Yes') else: print('No') elif C%B != 0: if A-(C//B)*D > 0: print('Yes') else: print('No')
0
null
33,974,023,435,830
178
164
h,n = map(int,input().split()) A = list(map(int,input().split())) if h-sum(A)>0 : print("No") else: print("Yes")
h, n = map(int, input().split()) A = [int(i) for i in input().split()] A.sort(reverse=True) max_point = sum(A[:n]) ans = 'Yes' if max_point < h: ans = 'No' print(ans)
1
77,524,081,719,612
null
226
226
s=int(input()) h=s//3600 s-=h*3600 m=s//60 s-=m*60 print(str(h)+":"+str(m)+":"+str(s))
S = int(input()) h = int(S/3600) m = int((S-h*3600)/60) s = int(S-h*3600-m*60) time = [h, m, s] time_str = map(str,time) print(":".join(time_str))
1
339,602,781,100
null
37
37
N = int(input()) S, T = input().split() mix = [] for i in range(N): mix.append(S[i]) mix.append(T[i]) print(*mix, sep='')
def resolve(): n,m = map(int,input().split()) print('Yes' if n==m else 'No') resolve()
0
null
97,385,077,748,938
255
231
import sys from sys import exit from collections import deque from copy import deepcopy from bisect import bisect_left, bisect_right, insort_left, insort_right from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9+7 def lcm(x,y): return x*y//gcd(x,y) def lgcd(l): return reduce(gcd,l) def llcm(l): return reduce(lcm,l) def powmod(n,i,mod=MOD): return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod) def div2(x): return x.bit_length() def div10(x): return len(str(x))-(x==0) def intput(): return int(input()) def mint(): return map(int,input().split()) def lint(): return list(map(int,input().split())) def ilint(): return int(input()), list(map(int,input().split())) def judge(x, l=['Yes', 'No']): print(l[0] if x else l[1]) def lprint(l, sep='\n'): for x in l: print(x, end=sep) def ston(c, c0='a'): return ord(c)-ord(c0) def ntos(x, c0='a'): return chr(x+ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self,x,d=1): self.setdefault(x,0) self[x] += d def list(self): l = [] for k in self: l.extend([k]*self[k]) return l class comb(): def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self,k): l,n,mod = self.l, self.n, self.mod k = n-k if k>n//2 else k while len(l)<=k: i = len(l) l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod) return l[k] def pf(x,mode='counter'): C = counter() p = 2 while x>1: k = 0 while x%p==0: x //= p k += 1 if k>0: C.add(p,k) p = p+2-(p==2) if p*p<x else x if mode=='counter': return C S = set([1]) for k in C: T = deepcopy(S) for x in T: for i in range(1,C[k]+1): S.add(x*(k**i)) if mode=='set': return S if mode=='list': return sorted(list(S)) class UnionFind(): # インデックスは0-start # 初期化 def __init__(self, n): self.n = n self.parents = [-1]*n self.group = n # private function def root(self, x): if self.parents[x]<0: return x else: self.parents[x] = self.root(self.parents[x]) return self.parents[x] # x,yが属するグループの結合 def union(self, x, y): x = self.root(x) y = self.root(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 self.group -= 1 # x,yが同グループか判定 def same(self, x, y): return self.root(x)==self.root(y) # xと同じグループの要素数を取得 def size(self, x): return -self.parents[self.root(x)] ###################################################### N,M,K=mint() T=UnionFind(N) block=[0]*N for _ in range(M): a,b=mint() T.union(a-1,b-1) block[a-1]+=1 block[b-1]+=1 for _ in range(K): c,d=mint() if T.same(c-1,d-1): block[c-1]+=1 block[d-1]+=1 ans=[T.size(i)-block[i]-1 for i in range(N)] lprint(ans,' ')
class UF(): def __init__(self, N): self.par = [-1] * N def union(self, x, y): p1,p2 = self.find(x), self.find(y) if p1 == p2: return if self.par[p1] > self.par[p2]: p1,p2 = p2,p1 self.par[p1] += self.par[p2] self.par[p2] = p1 def find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def size(self, x): return -self.par[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) N,M,K = map(int,input().split()) uf = UF(N) adj = [ [] for _ in range(N)] for _ in range(M): u,v = map(int,input().split()) u -= 1 v -= 1 adj[u].append(v) adj[v].append(u) uf.union(u,v) res = [] for n in range(N): res.append(uf.size(n) - 1 - len(adj[n])) for _ in range(K): u,v = map(int,input().split()) u -= 1 v -= 1 if uf.same(u,v): res[u] -= 1 res[v] -= 1 print(" ".join(map(str, res)))
1
61,699,662,949,198
null
209
209
from collections import Counter N, P = map(int, input().split()) S = list(input()) cnt = 0 if P in [2, 5]: for i, s in enumerate(S): if int(s) % P == 0: cnt += (i + 1) else: num = 0 mods = Counter() for i, s in enumerate(reversed(S)): num += int(s) * pow(10, i, P) num %= P mods[num] += 1 mods[0] += 1 for i, s in enumerate(S): mods[num] -= 1 cnt += mods[num] num -= int(s) * pow(10, N - 1 - i, P) num %= P print(cnt)
from collections import defaultdict import sys def input():return sys.stdin.readline().strip() def main(): N, P = map(int, input().split()) S = input() ans = 0 if P in [2, 5]: for i, c in enumerate(S[::-1]): if int(c) % P == 0: ans += N-i else: d = defaultdict(int) d[0] = 1 num = 0 ten = 1 for c in S[::-1]: num += int(c) * ten num %= P d[num] += 1 ten *= 10 ten %= P ans = sum([d[i]*(d[i]-1)//2 for i in range(P)]) print(ans) if __name__ == "__main__": main()
1
58,248,603,562,358
null
205
205
a = [int(s) for s in input().split()] N = a[0] bks = a[1] bd = a[2] s = [input().split() for i in range(N)] anslist = [] for i in range(2**N): templist = [] for t in range(bks+1): templist.append(int(0)) for j in range(N): if (i >> j) & 1 == 1: for k in range(bks + 1): templist[k] += int(s[j][k]) anslist.append(templist) ans = int(-1) flag = int(0) for i in range(2**N): flag = 0 for j in range(1, bks+1): if anslist[i][j] < bd: flag = 1 break else: pass if flag == 0: if anslist[i][0] < ans or ans == -1: ans = anslist[i][0] print(ans)
n=int(input()) table=[[0]*n for i in range(60)] for i,v in enumerate(map(int,input().split())): for j in range(60): table[j][n-1-i]=v%2 v//=2 if v==0:break #print(*table,sep='\n') ans=0 mod1,mod2=10**9+7,998244353 mod=mod1 a=1 for t in table: o,z=0,0 for v in t: if v: o+=1 ans=(ans+z*a)%mod else: z+=1 ans=(ans+o*a)%mod a=a*2%mod print(ans)
0
null
72,246,768,447,652
149
263
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(N, M, A): b_lcm = 1 d2 = set() for a in A: b = a // 2 b_lcm = b_lcm//math.gcd(b_lcm, b) * b for i in range(100000000): if a % 2 == 0: a //= 2 else: d2.add(i) break return -(-(M // b_lcm)//2) if len(d2) == 1 else 0 def main(): N, M = read_int_n() A = read_int_n() print(slv(N, M, A)) if __name__ == '__main__': main()
n, m = map(int, input().split()) a = list(map(int, input().split())) num = sum(a) cnt = 0 for i in range(n): if a[i] < num/(4*m): continue else: cnt += 1 if cnt >= m: print("Yes") else: print("No")
0
null
70,419,710,644,326
247
179
a,b,c,d=map(int,input().split()) for i in range(a, 0, -d): c=c-b a=a-d if c<=0: print("Yes") else: print("No")
s = input().split() stack = [] for a in s: if a == '+': stack.append(stack.pop() + stack.pop()) elif a == '-': stack.append(-(stack.pop() - stack.pop())) elif a == '*': stack.append(stack.pop() * stack.pop()) else: stack.append(int(a)) print(stack[0])
0
null
14,816,954,460,540
164
18
str = input() s_ans = 'Yes' if len(str)%2 == 1: s_ans ='No' else: for i in range(0,len(str),2): moji = str[i:i+2] if str[i:i+2] != 'hi': s_ans = 'No' break print(s_ans)
s = "hi" S = input() flag = False for i in range(5): if S==s: flag=True break s = s+"hi" if flag: print("Yes") else: print("No")
1
53,191,921,950,508
null
199
199
N = int(input()) ans = (N * 100 + 99) // 108 if N==int(ans*1.08): print(ans) else: print(':(')
n = int(input()) for i in range(1,n+1): ans = int(i*1.08) if ans == n: print(i) break else: print(":(")
1
125,354,440,330,570
null
265
265
n = str(input()) ns = n.swapcase() print(ns)
N=int(input()) S=input() ans=S[0] for s in S: if ans[-1]!=s: ans+=s print(len(ans))
0
null
86,217,156,260,950
61
293
N=int((input())) if N%1000==0: print(0) else: N=str(N) a = len(N) if a>=3: x = int(N[a-3]+N[a-2]+N[a-1]) print(1000-x) elif a==2: x = int(N[a-2]+N[a-1]) print(1000-x) else : x = int(N[a-1]) print(1000-x)
import sys def input(): return sys.stdin.readline().rstrip() N = int(input()) num = (N + 1000 - 1 )// 1000 print(num * 1000 - N)
1
8,414,405,796,470
null
108
108
#!/usr/bin/env python class PrimeFactor(): def __init__(self, n): ''' Note: make the table of Eratosthenes' sieve and minFactor[] for fast_factorization. ''' self.n = n self.table = [True for _ in range(n+1)] self.table[0] = self.table[1] = False self.minFactor = [-1 for _ in range(n+1)] for i in range(2, n+1): if not self.table[i]: continue self.minFactor[i] = i for j in range(i*i, n+1, i): self.table[j] = False self.minFactor[j] = i def fast_factorization(self, n): ''' Note: factorization return the form of {factor: num}. ''' data = {} while n > 1: if self.minFactor[n] not in data: data[self.minFactor[n]] = 1 else: data[self.minFactor[n]] += 1 n //= self.minFactor[n] return data def count_divisors(self, n): ''' Note: return the number of divisors of n. ''' ret = 1 for v in self.fast_factorization(n).values(): ret *= (v+1) return ret n = int(input()) ans = 0 a = PrimeFactor(n) for i in range(1, n): ans += a.count_divisors(i) print(ans)
import math A = list(map(float, input().split())) ans = math.sqrt((A[0]-A[2])**2 + (A[1]-A[3])**2) print(ans)
0
null
1,347,897,871,840
73
29
n = input() if n[0] == '7' or n[1] == '7' or n[2] == '7': ans = 'Yes' else: ans = 'No' print(ans)
H, W= map(int, input().split()) A=[] b=[] ans=[0 for i in range(H)] for i in range(H): A.append(list(map(int, input().split()))) for j in range(W): b.append(int(input())) for i in range(H): for j in range(W): ans[i]+=A[i][j]*b[j] print(ans[i])
0
null
17,650,600,388,972
172
56
n = int(input()) a = list(map(int, input().split())) q = int(input()) sm = sum(a) hm = [0] * (10 ** 5 + 1) for i in a: hm[i] += 1 for _ in range(q): b, c = map(int, input().split()) sm += (c - b) * hm[b] hm[c] += hm[b] hm[b] = 0 print(sm)
num = map(int, raw_input().split()) flg=1 while flg==1: flg=0 for i in range(2): if num[i]>num[i+1]: box = num[i] num[i]=num[i+1] num[i+1]=box flg=1 print "%d %d %d" % (num[0],num[1],num[2])
0
null
6,329,364,232,948
122
40
s=input() if len(s)%2!=0: print("No") else: bool=False for i in range(len(s)): if i%2==0: if s[i]!="h": print("No") bool=True break else: if s[i]!="i": print("No") bool=True break if bool is False: print("Yes")
n = int(input()) d = input() x = d[0] count = 1 for i in d: if i != x: count += 1 x = i print(count)
0
null
111,713,474,996,380
199
293
N = int(input()) A = list(map(int,input().split())) c = 0 if N%2 == 0: for i in range(N//2): c += A[2*i+1] cm = c # print(c) for i in range(N//2): # print(2*i,2*i+1) c += A[2*i]-A[2*i+1] cm = max(c,cm) print(cm) else: dp = [[0]*(3) for _ in range(N//2)] # print(dp) # 初期化 dp[0][0] = A[0] dp[0][1] = A[1] dp[0][2] = A[2] for i in range(0,N//2-1): dp[i+1][0] = dp[i][0] + A[2*i+2] dp[i+1][1] = max(dp[i][0] + A[2*i+3], dp[i][1] + A[2*i+3]) dp[i+1][2] = max(dp[i][0] + A[2*i+4], dp[i][1] + A[2*i+4], dp[i][2] + A[2*i+4]) # print(dp) print(max(dp[N//2-1][0],dp[N//2-1][1],dp[N//2-1][2]))
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) INF = float("inf") import bisect N = int(input()) a = [0] + list(map(int, input().split())) o = [a[2*i+1] for i in range(N//2)] o = list(itertools.accumulate(o)) dp = [0 for i in range(N+1)] dp[0] = dp[1] = 0 dp[2] = max(a[1], a[2]) if N > 2: dp[3] = max([a[1], a[2], a[3]]) if N > 3: for i in range(4, N+1): if i % 2 == 0: dp[i] = max(dp[i-2] + a[i], o[(i-3)//2] + a[i-1]) else: dp[i] = max([dp[i-2] + a[i], dp[i-3] + a[i-1], o[(i-2)//2] ]) print(dp[N])
1
37,316,538,934,542
null
177
177
N = int(input()) A = [int(i) for i in input().split()] A1 = 1 if 0 in A: print(0) else: for j in range(N): A1 *= A[j] if A1>10**18: print(-1) break else: print(A1)
import itertools, bisect 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): cindex = bisect.bisect_left(L, int(L[i]) + int(L[j])) ans += cindex-1 - j print(ans)
0
null
94,347,883,589,610
134
294
while True: n = int(input()) if n == 0: break s = list(map(int, input().split())) kei = 0 for p in s: kei += p m = kei / n a = 0 for p in s: a += ((p - m)**2) / n import math h = math.sqrt(a) print(h)
from math import sqrt def solve(n): s = list(map(float,input().split())) m = sum(s)/n a = sqrt(sum([(si-m)**2 for si in s])/n) print('{0:.6f}'.format(a)) while True: n = int(input()) if n==0:break solve(n)
1
192,245,417,200
null
31
31
N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) P=[i-1 for i in P] idle_max=-10**27 for s in range(0,N): k=K-1 score=0 s=P[s] score+=C[s] count=1 idle_max=max(idle_max,score) visited={s:[count,score]} while k and not P[s] in visited: k-=1 count+=1 s=P[s] score+=C[s] visited[s]=[count,score] idle_max=max(idle_max,score) #print(visited) if k: c1,score1=visited[s] c2,score2=visited[P[s]] c1+=1 s=P[s] score1+=C[s] score+=C[s] k-=1 n=c1-c2 score+=(score1-score2)*(k//n) k%=n idle_max=max(idle_max,score) while k: k-=1 s=P[s] score+=C[s] idle_max=max(idle_max,score) print(idle_max)
import numpy as np def is_good(mid, key): x = A - mid // F return x[x > 0].sum() <= key def binary_search(key): bad, good = -1, 10 ** 18 while good - bad > 1: mid = (bad + good) // 2 if is_good(mid, key): good = mid else: bad = mid return good N, K = map(int, input().split()) A = np.array(input().split(), dtype=np.int64) F = np.array(input().split(), dtype=np.int64) A.sort() F[::-1].sort() print(binary_search(K))
0
null
84,849,956,631,510
93
290
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n,x,y=nii() x-=1 y-=1 ans=[0 for i in range(n)] for i in range(n-1): for j in range(i+1,n): dist1=j-i dist2=abs(i-x)+1+abs(j-y) dist=min(dist1,dist2) ans[dist]+=1 for i in ans[1:]: print(i)
import sys readline = sys.stdin.readline N,X,Y = map(int,readline().split()) X -= 1 Y -= 1 ans = [0] * N for i in range(N - 1): for j in range(i + 1, N): val = min(abs(i - j),abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X)) ans[val] += 1 for i in range(1, len(ans)): print(ans[i])
1
44,128,043,518,130
null
187
187
N=int(input()) print(int((N-1-(N+1)%2)/2))
import math a = math.ceil(int(input())/2) print(int(a-1))
1
153,152,299,813,020
null
283
283
from math import gcd from functools import reduce def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm(*numbers): return reduce(lcm_base, numbers, 1) def evencount(n): cnt=0 while n%2==0: cnt+=1 n//=2 return cnt n,m=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]//=2 if all(evencount(i) == evencount(a[0]) for i in a): d=lcm(*a) print((m+d)//2//d) else:print(0)
from math import gcd def lcm(a, b): return a * b // gcd(a, b) n, m = map(int, input().split()) a = list(map(int, input().split())) l = [0] * n for i in range(n): tmp = a[i] while tmp % 2 == 0: tmp //= 2 l[i] += 1 if i > 0 and l[i] != l[i - 1]: print(0) exit(0) res = 1 for i in range(n): res = lcm(res, a[i] // 2) print(m // res - m // (res * 2))
1
101,482,910,348,922
null
247
247
k = int(input()) a, b = map(int, input().split()) check = False for i in range(a, b + 1): if i % k == 0: check = True print("OK" if check else "NG")
import sys #input = sys.stdin.buffer.readline def main(): N,M = map(int,input().split()) s = str(input()) s = list(reversed(s)) ans = [] now = 0 while now < N: for i in reversed(range(min(M,N-now))): i += 1 if s[now+i] == "0": now += i ans.append(i) break if i == 1: print(-1) exit() print(*reversed(ans)) if __name__ == "__main__": main()
0
null
83,132,590,712,810
158
274
A, B, C, K = map(int, input().split()) count_A = 0 count_B = 0 count_C = 0 count = 0 if A >= K: count_A += K else: # A < K K -= A count_A += A if B >= K: count_B += K else: K -= B count_B += B count_C += K print(count_A - count_C)
A,B,C,K = map(int,input().split()) point = 0 if K-A >=0: point += A else: point += K if K-A-B > 0: point -= K-A-B print(point)
1
21,783,196,616,002
null
148
148
N = int(input()) L = [] for i in range(N): L.append(list(input().split())) S = input() ans = 0 f = 0 for i in range(N): if f == 1: ans += int(L[i][1]) if L[i][0] == S: f = 1 print(ans)
N = int(input()) P = tuple(map(int, input().split())) count = 0 min_num = float('inf') for i in P: if i < min_num: count += 1 min_num = i print(count)
0
null
91,101,752,502,600
243
233
X, N = map(int, input().split()) if not N ==0: A = [int(x) for x in input().split()] index = 0 value = abs(A[0] - X) up_list = [0]*(N+1) down_list = [0]*(N+1) for i in range(N): if abs(A[i] - X ) < N+1: if A[i] - X >= 0: up_list[A[i]-X] = 1 if A[i] - X <= 0: down_list[abs(A[i]- X)] = 1 j = 0 while True: if down_list[j] == 0: print(X-j) break if up_list[j] ==0: print(X+j) break if j>N+1: print('fail') break j+=1 else: print(X)
import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): N,M=mi() A=list(mi()) sum_vote = sum(A) count = 0 for a in A: if a >= sum_vote / (4*M): count +=1 print("Yes" if count >= M else "No") if __name__ == "__main__": main()
0
null
26,447,217,321,910
128
179
string = input() string=list(string) count = len(string) summary = 0 for i in range(count): if string[i]=="?": string[i]="D" #print(string) for i in string: print(i, end="")
import sys input = sys.stdin.readline t = list(input()) t.pop() n = len(t) res = 0 for i in range(n): if t[i] == '?': t[i] = 'D' print(''.join(t))
1
18,503,907,938,012
null
140
140
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: map(int, stdin.readline().split()) rlf = lambda: map(float, stdin.readline().split()) INF, NINF = float('inf'), float('-inf') def main(): L, R, d = rli() ans = 0 for x in range(L, R+1): if x % d == 0: ans += 1 print(ans) stdout.close() if __name__ == "__main__": main()
l, r, d = map(int, input().split()) ans = 0 for i in range(l, r+1): if i % d == 0: ans += 1 print(ans)
1
7,555,224,149,980
null
104
104
def solve(N, A): a = [(i, ai) for i, ai in enumerate(A)] a.sort(key=lambda x: x[1], reverse=True) # import numpy as np # dp = np.zeros((N+1, N+1), np.int8) dp = [[0] * (N + 1) for _ in range(N + 1)] dp[0][0] = 0 for i, ai in enumerate(a): for l in range(i+1): r = i - l dp[i+1][l] = max(dp[i+1][l], dp[i][l] + ai[1] * ((N-1-r) - ai[0])) dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + ai[1] * (ai[0] - l)) print(max(dp[N])) if __name__ == '__main__': N = int(input()) A = list(map(int, input().split())) solve(N, A)
n = int(input()) a = list(map(int, input().split())) b = [] for i, v in enumerate(a): b.append([v, i]) b.sort(reverse = True) dp = [[0] * (n+1) for _ in range(n+1)] ans = 0 for i in range(n+1): for j in range(n+1-i): if i > 0: dp[i][j] = max(dp[i][j], dp[i-1][j] + b[i+j-1][0] * (b[i+j-1][1] - (i - 1))) if j > 0: dp[i][j] = max(dp[i][j], dp[i][j-1] + b[i+j-1][0] * ((n - j) - b[i+j-1][1])) for i in range(n+1): ans = max(ans, dp[i][n-i]) print(ans)
1
33,737,620,931,740
null
171
171