code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
def resolve(): N = int(input()) A = list(map(int, input().split())) broken = 0 cnt = 1 for i in range(N): if cnt == A[i]: cnt += 1 else: broken += 1 print(broken if broken != N else -1) if '__main__' == __name__: resolve()
n=int(input()) a=list(map(int,input().split())) ans=0 ch=1 for x in range(n): if a[x]==ch: ans+=1 ch+=1 if ans==0: print(-1) else: print(n-ans)
1
114,529,906,056,062
null
257
257
n=int(input()) c=input().split();d=c[:] for i in range(n-1): for j in range(0,n-i-1): if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j] b=[s[1]for s in d];m=b.index(min(b[i:]),i) if b[i]>b[m]:d[i],d[m]=d[m],d[i] print(*c);print("Stable") print(*d) print(["Not stable","Stable"][c==d])
import copy N = int(input()) bscs = [(int(c[-1]), c) for c in input().split(" ")] sscs = copy.copy(bscs) for i in range(N): j = N - 1 while j > i: if bscs[j][0] < bscs[j - 1][0]: tmp = bscs[j] bscs[j] = bscs[j - 1] bscs[j - 1] = tmp j -= 1 print(" ".join([c[1] for c in bscs])) print("Stable") for i in range(N): minj = i for j in range(i, N): if sscs[j][0] < sscs[minj][0]: minj = j tmp = sscs[i] sscs[i] = sscs[minj] sscs[minj] = tmp print(" ".join([c[1] for c in sscs])) print("Stable" if bscs == sscs else "Not stable")
1
23,611,315,068
null
16
16
import sys import math import itertools from collections import deque import copy import bisect MOD = 10 ** 9 + 7 INF = 10 ** 18 + 7 input = lambda: sys.stdin.readline().strip() n, k = map(int, input().split()) inv_list = [1] # 0で割るというのは定義されないので無視。 for i in range(n): inv_list.append(int(MOD - inv_list[(MOD % (i + 2)) - 1] * (MOD // (i + 2)) % MOD)) if k >= n: ans = 1 for i in range(2 * n - 1): ans *= (i + 1) ans %= MOD for i in range(n): ans *= inv_list[i] ans *= inv_list[i] ans %= MOD ans *= n ans %= MOD print(ans) else: ans = 1 nCm = 1 nmHm = 1 for i in range(k): nCm *= n - i nCm *= inv_list[i] nCm %= MOD nmHm *= (n - 1) - i nmHm *= inv_list[i] nmHm %= MOD ans += nCm * nmHm ans %= MOD print(ans)
n,k = map(int,input().split()) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, n + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) ans = 0 #con = cmb(n,k,mod) #print(con) for i in range(min(k+1,n+1)): ans += cmb(n,i,mod)*cmb(n-1,i,mod) ans %= mod print(ans)
1
67,015,411,374,052
null
215
215
import math a,b,C=map(float,input().split()) θ=math.radians(C) h=b*math.sin(θ) S=(a*h)/2 c=math.sqrt(a**2+b**2-2*a*b*math.cos(θ)) L=a+b+c print(S,L,h,sep="\n")
x,y = map(int,input().split()) y =y**2 count=0 for i in range(x): a,b = map(int,input().split()) if a**2+b**2 <=y: count+=1; print(count)
0
null
3,090,546,288,320
30
96
import sys input = sys.stdin.buffer.readline N, K = map(int, input().split()) A = list(map(int, input().split())) A = [a - 1 for a in A] log_K = 1 while 1 << log_K < K: log_K += 1 # print(f'{log_K=}') D = [[0] * N for _ in range(log_K)] for i in range(N): D[0][i] = A[i] for k in range(log_K - 1): for i in range(N): D[k + 1][i] = D[k][D[k][i]] # print(f'{D=}') now = 0 k = 0 while K > 0: if K & 1: now = D[k][now] K = K >> 1 k += 1 print(now + 1)
from collections import deque from sys import stdin n = int(input()) ddl = deque() for i in stdin: inp = i.split() if len(inp) == 2: op, data = inp data = int(data) else: op, data = inp[0], None if op == 'insert': ddl.appendleft(data,) elif op == 'delete': try: ddl.remove(data) except ValueError: pass elif op == 'deleteFirst': ddl.popleft() elif op == 'deleteLast': ddl.pop() print(' '.join([str(item) for item in ddl]))
0
null
11,363,328,583,432
150
20
while True: H, W = list(map(int, input().split())) if H == 0 and W == 0: break for h in range(H): for w in range(W): if w == (W - 1): print('#') break print('#', end="") print()
s=str(input().upper()) if s=="ABC": print("ARC") if s=="ARC": print("ABC")
0
null
12,373,099,466,390
49
153
while 1: H, W = map(int, raw_input().split()) if H == W == 0: break print '#'*W print ('#'+'.'*(W-2)+'#'+'\n')*(H-2)+'#'*W + '\n'
while True: H, W = map(int, input().split()) if not(H or W): break print('#' * W) for i in range(H-2): print('#' + '.' * (W - 2), end='') print('#') print('#' * W, end='\n\n')
1
820,092,272,572
null
50
50
A,B,N = list(map(int, input().split())) #floor(A*x // B vs A * (x/B) #x= pB + q (0<=q<B) # Ap +(Aq// B) - AP x = B-1 if B<=N else N print((A*x) // B)
A, B = map(int, input().split()) Xbmin = 10 * B Xbmax = 10 * B + 10 ans = -1 for x in range(Xbmin, Xbmax): if 100 * A <= x * 8 and x * 8 < 100 * (A + 1): ans = x break print(ans)
0
null
42,549,092,123,438
161
203
import math pages = int(input()) print(math.ceil(pages/2))
def main(): n = int(input()) print((n+1)//2) if __name__ == "__main__": main()
1
58,789,855,654,348
null
206
206
n=int(input()) a=list(map(int,input().split())) toki=a[0] shigi=0 for i in range(1,n): if toki>a[i]: shigi += toki-a[i] else:toki=a[i] print(shigi)
N = int(input()) A = list(int(x) for x in input().split()) ans = 0 for i in range(N): if i == N - 1: break if A[i] > A[i+1]: sa = A[i] - A[i+1] A[i+1] += sa ans = ans + sa print(ans)
1
4,508,553,123,008
null
88
88
n = int(input()) a = list(map(int,input().split())) q = int(input()) m = list(map(int,input().split())) s = [list(map(int,bin(x)[2:].zfill(n))) for x in range(2**n)] anset=set() for j in s: ans=0 for k in range(n): ans+=a[k]*j[k] anset.add(ans) for i in range(q): if m[i] in anset: print('yes') else: print('no')
def create_sums(ns): if len(ns) == 0: return set() s = create_sums(ns[1:]) return {e + ns[0] for e in s} | s | {ns[0]} def run_set(): _ = int(input()) # flake8: noqa ns = [int(i) for i in input().split()] sums = create_sums(ns) _ = int(input()) # flake8: noqa for q in (int(j) for j in input().split()): if q in sums: print("yes") else: print("no") if __name__ == '__main__': run_set()
1
98,422,162,816
null
25
25
# -*- coding: utf-8 -*- import math s = list(input()) q = int(input()) for i in range(q): n = list(input().split()) if 'print' in n: for j in range(int(n[1]), int(n[2]) + 1): print(str(s[j]), end='') print() elif 'reverse' in n: for k in range(math.floor((int(n[2]) - int(n[1]) + 1) / 2)): s[int(n[1]) + k], s[int(n[2]) - k] = s[int(n[2]) - k], s[int(n[1]) + k] elif 'replace' in n: for l in range(int(n[1]), int(n[2]) + 1): s.pop(int(n[1])) count = int(n[1]) for m in list(n[3]): s.insert(count, m) count += 1
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 #from decimal import * _, D1 = MAP() _, D2 = MAP() if D1+1 == D2: print("0") else: print("1")
0
null
62,902,048,658,170
68
264
n=int(input()) a=list(map(int,input().split())) ans=0 c=sum(a) for i in range(n): c=c-a[i] b=(a[i]*c) ans=ans+b d=ans%(1000000007) print(d)
N = int(input()) A = list(map(int, input().split())) B = [] b = 0 e = 10 ** 9 + 7 for i in range(N - 1): b += A[N - 1 - i] b = b % e B.append(b) result = 0 for i in range(N - 1): result += A[i] * B[N - 2 - i] result = result % e print(result)
1
3,850,299,448,880
null
83
83
import sys def input(): return sys.stdin.readline().rstrip() def main(): H, W, K = map(int, input().split()) S = [tuple(map(int, list(input()))) for _ in range(H)] ans = 10 ** 9 for bit in range(1 << (H-1)): canSolve = True ord = [0] * (H + 1) N = 0 for i in range(H): if bit & 1 << i: ord[i+1] = ord[i] + 1 N += 1 else: ord[i+1] = ord[i] nums = [0] * (H + 1) for w in range(W): one = [0] * (H + 1) overK = False for h in range(H): one[ord[h]] += S[h][w] nums[ord[h]] += S[h][w] if one[ord[h]] > K: canSolve = False if nums[ord[h]] > K: overK = True if not canSolve: break if overK: N += 1 nums = one if canSolve and ans > N: ans = N print(ans) if __name__ == '__main__': main()
from sys import stdin def main(): #入力 readline=stdin.readline h,w,k=map(int,readline().split()) grid=[readline().strip() for _ in range(h)] ans=float("inf") for i in range(1<<(h-1)): div=[(i>>j)&1 for j in range(h-1)] l=len([0 for i in range(h-1) if div[i]])+1 cnt=[0]*l tmp=0 for j in range(w): now=0 flag=False for i_2 in range(h): if grid[i_2][j]=="1": cnt[now]+=1 if cnt[now]>k: flag=True break if i_2<h-1 and div[i_2]==1: now+=1 if flag: tmp+=1 cnt=[0]*l now=0 flag=False for i_2 in range(h): if grid[i_2][j]=="1": cnt[now]+=1 if cnt[now]>k: flag=True break if i_2<h-1 and div[i_2]==1: now+=1 if flag: break else: tmp+=l-1 ans=min(ans,tmp) print(ans) if __name__=="__main__": main()
1
48,410,704,598,428
null
193
193
#!/usr/bin/env python3 from queue import Queue def II(): return int(input()) def MII(): return map(int, input().split()) def LII(): return list(map(int, input().split())) def main(): H, W = MII() S = [input() for _ in range(H)] dp = [[10**9] * W for _ in range(H)] dp[0][0] = (S[0][0] == '#') + 0 for i in range(H): for j in range(W): a = dp[i-1][j] b = dp[i][j-1] if S[i-1][j] == '.' and S[i][j] == '#': a += 1 if S[i][j-1] == '.' and S[i][j] == '#': b += 1 dp[i][j] = min(dp[i][j], a, b) print(dp[H-1][W-1]) if __name__ == '__main__': main()
import random s = input() num = random.randint(0,len(s)-3) print(s[num:num+3])
0
null
32,010,823,766,000
194
130
S = str(input()) print(len(S) * "x")
s = input() q = len(s) print("x"*q)
1
72,835,587,562,726
null
221
221
def check(k, W, p): s = 0 count = 1 for w in W: if s + w > p: count += 1 s = 0 s += w return count <= k n, k = map(int, input().split()) W = [int(input()) for _ in range(n)] right = sum(W) left = max(right // k, max(W)) - 1 while right - left > 1: p = (left + right) // 2 if check(k, W, p): right = p else: left = p print(right)
import sys def h1(key): return key % M def h2(key): return 1 + key % (M - 1) def H(key, i): return (h1(key) + i * h2(key)) % M def my_insert(dic, key): i = 0 while 1: j = H(key, i) if dic[j] is None: dic[j] = key return j else: i += 1 def my_search(dic, key): i = 0 while 1: j = H(key, i) if dic[j] == key: return True elif dic[j] is None or i >= M: return False else: i += 1 def str2int(s): res = s res = res.replace("A", "1") res = res.replace("C", "2") res = res.replace("G", "3") res = res.replace("T", "4") return int(res) M = 1000003 dic = [None] * M n = int(sys.stdin.readline()) for k in range(n): cmd, s = sys.stdin.readline().split() if cmd == "insert": my_insert(dic, str2int(s)) else: print("yes" if my_search(dic, str2int(s)) else "no")
0
null
83,310,162,400
24
23
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): R = int(input()) print(int(R**2)) if __name__ == "__main__": main()
import sys n, m, l = [ int( val ) for val in sys.stdin.readline().split( " " ) ] matrixA = [ [ int( val ) for val in sys.stdin.readline().split( " " ) ] for row in range( n ) ] matrixB = [ [ int( val ) for val in sys.stdin.readline().split( " " ) ] for row in range( m ) ] matrixC = [ [ sum( matrixA[i][k] * matrixB[k][j] for k in range( m ) ) for j in range( l ) ] for i in range( n ) ] for i in range( n ): print( " ".join( map( str, matrixC[i] ) ) )
0
null
73,104,945,201,224
278
60
N = int(input()) n_list = [] count = 1 max_val = 1 res = 0 for x in range(1,100): for y in range(x,100): for z in range(y,100): res = x**2 +y**2 + z**2 + x*y + y*z + z*x for i in range(int(x!=y) + int(y!=z) + int(z!=x)-1): count *= 3-i if max_val < res: for i in range(max_val, res+1): if i != res: n_list.append(0) else: n_list.append(count) max_val = res+1 else: n_list[res-1] += count count = 1 for i in range(N): print(n_list[i])
S, W = [int(x) for x in input().split()] if W >= S: print('unsafe') else: print('safe')
0
null
18,662,223,908,106
106
163
# Aizu Problem ALDS_1_2_C: Stable Sort # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input2.txt", "rt") def printA(A): print(' '.join([str(a) for a in A])) def bubble_sort(A): for i in range(len(A) - 1): for j in range(len(A) - 1, i, -1): if A[j][1] < A[j - 1][1]: A[j], A[j - 1] = A[j - 1], A[j] return A def selection_sort(A): for i in range(len(A)): mini = i for j in range(i, len(A)): if A[j][1] < A[mini][1]: mini = j if mini != i: A[i], A[mini] = A[mini], A[i] return A def is_stable(A, B): for val in range(1, 10): v = str(val) if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]: return False return True N = int(input()) A = list(input().split()) A_bubble = bubble_sort(A[:]) printA(A_bubble) print("Stable" if is_stable(A, A_bubble) else "Not stable") A_select = selection_sort(A[:]) printA(A_select) print("Stable" if is_stable(A, A_select) else "Not stable")
n = int(input()) s = input() ans=[] for i in s: a = chr(ord('A')+(ord(i)-ord('A')+n)%26) ans.append(a) print(('').join(ans))
0
null
66,951,246,828,732
16
271
L = int(input()) a = L/3 ans = a**3 print(ans)
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) 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) INF = 10**9 mod = 10**9+7 D = i() c = l() C = sorted(c) C.reverse() rank = [0]*26 ans = [0]*D for i in range(D): s = l() ans[i] = s.index(max(s))+1 for i in range(26): rank[i] = C.index(c[i])+1 for i in range(10): d = D//rank[i] for j in range(i,D,2**d+20): ans[j] = i+1 for i in ans: print(i)
0
null
28,304,256,935,300
191
113
S = int(input()) mod = 10**9 + 7 MN = 3 N = S//3 + S % 3 dp = [0] * (S+1) dp[0] = 1 for i in range(1, S+1): for j in range(0, (i-3)+1): dp[i] += dp[j] dp[i] %= mod print(dp[S])
# @oj: atcoder # @id: hitwanyang # @email: [email protected] # @date: 2020-09-15 19:45 # @url: import sys,os from io import BytesIO, IOBase import collections,itertools,bisect,heapq,math,string from decimal import * # region fastio BUFSIZE = 8192 BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ ## 注意嵌套括号!!!!!! ## 先有思路,再写代码,别着急!!! ## 先有朴素解法,不要有思维定式,试着换思路解决 def main(): x=int(input()) dp=[0]*(x+1) mod=10**9+7 for i in range(x+1): if i<3: dp[i]=0 continue dp[i]=1 for j in range(3,i-3+1): if i-j>5: dp[i]+=(1+dp[i-j]%mod-1) else: dp[i]+=dp[i-j]%mod print (dp[-1]%mod) if __name__ == "__main__": main()
1
3,277,326,604,708
null
79
79
import sys input = sys.stdin.readline def main(): K = int(input()) t = 7 t %= K for i in range(K+1): if t == 0: print(i+1) break t = (t * 10 + 7) % K else: print(-1) main()
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() k = readInt() n = 7 for i in range(10**6): if n%k==0: print(i+1) exit() else: n = (n*10+7)%k print(-1)
1
6,115,560,098,648
null
97
97
import queue n, m = map(int, input().split()) a = [[] for _ in range(n)] ans = 0 for _ in range(m): x, y = map(int, input().split()) a[x-1].append(y-1) a[y-1].append(x-1) route = set() route.add(0) q = queue.Queue() q.put(0) for i in range(n): if not i in route: route.add(i) q.put(i) ans += 1 while not q.empty(): c = q.get() for k in a[c]: if not k in route: q.put(k) route.add(k) if len(route) == n: print(ans) break
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) N, M = mapint() class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} uf = UnionFind(N) for _ in range(M): a, b = mapint() uf.union(a-1, b-1) print(uf.group_count()-1)
1
2,307,354,378,432
null
70
70
n=int(input()) A=list(map(int,input().split())) if not 1 in A: print(-1) else: c=1 for i in range(n): if A[i]==c: c+=1 print(n-c+1)
a, b = map(int, input().split()) c, d = map(int, input().split()) print(1 if c != a else 0)
0
null
119,988,605,970,108
257
264
n=int(input()) while 1: for i in range(2,int(n**0.5)+1): if n%i<1: break else: print(n); break n+=1
def isPrime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True X = int(input()) while True: if isPrime(X): print(X) break X += 1
1
105,554,282,104,480
null
250
250
from collections import deque n, m = map(int, input().split()) nodes = range(1,n+1) edges = {v: set() for v in nodes} for _ in range(m): a, b = map(int, input().split()) edges[a].add(b) edges[b].add(a) visited = {v: False for v in nodes} cnt = -1 for v in nodes: if not visited[v]: visited[v] = True que = deque([v]) while que: p = que.popleft() for q in edges[p]: if not visited[q]: visited[q] = True que.append(q) cnt += 1 print(cnt)
class UnionFind: par = None def __init__(self, n): self.par = [0] * n def root(self, x): if(self.par[x] == 0): return x else: self.par[x] = self.root(self.par[x]) return self.root(self.par[x]) def unite(self, x, y): if(self.root(x) != self.root(y)): self.par[self.root(x)] = self.root(y) def same(self, x, y): return self.root(x) == self.root(y) N, M = list(map(int, input().split())) UF = UnionFind(N) for i in range(M): A, B = list(map(int, input().split())) UF.unite(A - 1, B - 1) ans = 0 for i in range(N): if(UF.par[i] == 0): ans += 1 print(ans - 1)
1
2,266,036,651,050
null
70
70
from collections import OrderedDict n, x, y = map(int, input().split()) x = x-1 y = y-1 dist_hist = OrderedDict({i: 0 for i in range(1, n)}) for i in range(n-1): for j in range(i+1, n): if i<=x and j>=y: dist = j-i + 1 - (y-x) elif i<=x and x<j<y: dist = min(j-i, x-i + 1 + y-j) elif x<i<y and y<=j: dist = min(i-x + 1 + j-y, j-i) elif x<i<y and x<j<y: dist = min(j-i, i-x + 1 + y-j) else: dist = j - i dist_hist[dist] += 1 [print(value) for value in dist_hist.values()]
X=int(input()) A=[] i,p=0,True while p: a=i**5 A.append(a) for b in A: if a-b==X: p=False print(i,A.index(b)) break elif a+b==X: p=False print(i,-1*A.index(b)) break i+=1
0
null
34,824,613,862,262
187
156
t=int(input()) count = 0 flag = False for test in range(t): a,b = map(int,input().split()) if a==b: count+=1 if count==3: flag=True else: count=0 if flag: print("Yes") else: print("No")
def resolve(): a,b = map(int,input().split()) if 1<=a<=9 and 1<=b<=9: print(a*b) else: print(-1) resolve()
0
null
79,940,795,280,820
72
286
n = int(input()) div = [] div2 = [] ans = 0 for i in range(1,10**6+1): if n%i == 0: div+=[i,n//i] if (n-1)%i == 0: div2+=[i,(n-1)//i] div = set(div) div2 = set(div2) # print(div) a = [1] for i in div: if i > 1: t = n while t: if t%i == 0: t = t//i else: if t%i == 1: ans += 1 a += [i] break # for i in div2: # if i > 1: # t = n-1 # while t: # if t == 1: # ans += 1 # a += [i] # t //= i # # if n%(i-1) == 1: # # ans += 1 # # a += [i-1] # print(ans) # print(a) # print(div) # print(div2) for i in div2: a+=[i] a = set(a) # print(a) print(len(a)-1)
l=[chr(i) for i in range(97, 97+26)] print( l[int(l.index(input()))+1] )
0
null
67,172,963,411,880
183
239
n = int(input()) lst = [0] * 10**6 for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): t = (x**2 + y**2 + z**2 + (x+y+z)**2) // 2 lst[t] += 1 for i in range(1, n+1): print(lst[i])
N = int(input()) ans = [0]*(N+1) root = int(N**0.5) for x in range(1, root+1): for y in range(1, root+1): for z in range(1, root+1): F = x**2 + y**2 + z**2 + x*y + y*z + z*x if F <= N: ans[F] += 1 else: continue for i in range(1, N+1): print(ans[i])
1
7,947,184,196,150
null
106
106
s = input() k = int(input()) li = list(s) lee = len(s) if len(list(set(li))) == 1: print((lee)*k//2) exit() def motome(n,list): count = 0 kaihi_flag = False li = list*n for i,l in enumerate(li): if i == 0: continue if l == li[i-1] and not kaihi_flag: count += 1 kaihi_flag = True else: kaihi_flag = False #print(count) #print(count*k) return count if k >= 5 and k%2 == 1: a = motome(3,li) b = motome(5,li) diff = b - a ans = b + (k-5)//2*diff print(ans) elif k >=5 and k%2 == 0: a = motome(2,li) b = motome(4,li) diff = b - a ans = b + (k-4)//2*diff print(ans) else: count = 0 kaihi_flag = False li = li*k for i,l in enumerate(li): if i == 0: continue if l == li[i-1] and not kaihi_flag: count += 1 kaihi_flag = True else: kaihi_flag = False #print(count) #print(count*k) print(count)
s = input() k = int(input()) n = len(s) ss = set(s) # print(ss) ans = 0 if len(ss) == 1: print(k*n//2) # print('y') exit() if n == 1: print(n//2) exit() streaks = [] cnt = 0 now = s[0] for i in range(n): if now == s[i]: cnt += 1 else: streaks.append(cnt) now = s[i] cnt = 1 streaks.append(cnt) # print(streaks) m = len(streaks) if s[0] == s[-1]: for i in range(1, m-1): ans += streaks[i]//2 # print(ans) ans *= k # print(ans) ans += (streaks[0] + streaks[m-1])//2*(k-1) # print(ans) ans += streaks[0]//2 + streaks[m-1]//2 # print(ans) else: for i in range(m): ans += streaks[i]//2 ans *= k print(ans)
1
175,909,778,440,368
null
296
296
h = int(input()) w = int(input()) n = int(input()) if n % max(h, w) == 0: print(int(n//max(h, w))) else: print(int(n//max(h, w))+1)
a, b, c, k = map(int, input().split()) if k <= a: print(k) elif k <= a + b: print(a) elif k <= a + b + c: print(a - (k-a-b)) else: print(a - c)
0
null
55,166,806,670,178
236
148
N = int(input()) l = [] for _ in range(N): A, B = map(int, input().split()) l.append((A, B)) t = N//2 tl = sorted(l) tr = sorted(l, key=lambda x:-x[1]) if N%2: print(tr[t][1]-tl[t][0]+1) else: a1, a2 = tl[t-1][0], tr[t][1] a3, a4 = tl[t][0], tr[t-1][1] print(a4-a3+a2-a1+1)
n=int(input()) A=[] B=[] for i in range(n): a,b=map(int,input().split()) A.append(a) B.append(b) A.sort() B.sort() if n%2==1: print(B[n//2]-A[n//2]+1) else: print(int(((B[n//2]+B[n//2-1])/2-(A[n//2]+A[n//2-1])/2)*2+1))
1
17,306,526,230,560
null
137
137
n, m = [int(s) for s in input().split()] ans = "Yes" if m == n else "No" print(ans)
a,b = input().split(' ') print('Yes' if a == b else 'No')
1
83,675,880,684,862
null
231
231
n=int(input()) mod=998244353 A=list(map(int,input().split())) import sys # mod=10**9+7 ; inf=float("inf") from math import sqrt, ceil from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化 input=lambda: sys.stdin.readline().strip() sys.setrecursionlimit(11451419) from decimal import ROUND_HALF_UP,Decimal #変換後の末尾桁を0や0.01で指定 #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)) from functools import lru_cache from bisect import bisect_left as bileft, bisect_right as biright from fractions import Fraction as frac #frac(a,b)で正確なa/b #メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10) #引数にlistはだめ #######ここまでテンプレ####### #ソート、"a"+"b"、再帰ならPython3の方がいい #######ここから天ぷら######## C=Counter(A) if A[0]!=0 or A.count(0)>1: print(0);exit() Q=[C[i] for i in range(max(A)+1)] #print(Q) ans=1 for i in range(len(Q)-1): ans*= pow(Q[i],Q[i+1],mod) ans%=mod print(ans)
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines n, k = map(int, readline().split()) p = list(map(int, readline().split())) l = [i for i in range(1, 1001)] av = np.cumsum(l) / l tmp = [av[i - 1] for i in p] cs = list(np.cumsum(tmp)) if n == k: print(cs[-1]) exit() ans = 0 for i in range(n - k): ans = max(ans, cs[i + k] - cs[i]) print(ans)
0
null
114,733,961,906,412
284
223
N = int(input()) N += 1 print(N // 2)
import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) s=input() n=len(s) ans=0 for i in range(n//2): if s[i]!=s[-1-i]: ans+=1 print(ans)
0
null
89,707,291,658,390
206
261
N,*D = map(int,open(0).read().split()) import itertools print(sum(a * b for a,b in itertools.combinations(D,2)))
n = int(input()) a = [int(x) for x in input().split()] res = 0 for i in range(n): for j in range(i+1,n): res += a[i] * a[j] print(res)
1
168,631,628,316,800
null
292
292
n,k=map(int,input().split()) a=list(map(int,input().split())) a.append(0) s=input() ans=0 for i in range(k,n): if s[i]==s[i-k]: s=s[:i]+'z'+s[i+1:] for i in range(n): ans+=a['sprz'.index(s[i])] print(ans)
from sys import stdin a = stdin.readline().rstrip() a = int(a) print(a*a)
0
null
126,490,947,928,304
251
278
from collections import Counter N = int(input()) S = list(input()) cnt = Counter(S) Red, Green, Blue = (cnt['R'], cnt['G'], cnt['B']) patn = Red*Green*Blue cnt = 0 for i in range(N): for j in range(i+1, N): if (2*j - i) >= N: break elif S[i] != S[j] and S[j] != S[2*j-i] and S[i] != S[2*j-i]: cnt += 1 print(patn-cnt)
N = int(input()) S = input() ans = S.count("R") * S.count("G") * S.count("B") for i in range(N-2): r = S[i] for j in range(i+1,N-1): g = S[j] if r == g: continue k = 2*j - i if k >= N: continue b = S[k] if r != b and g != b: ans -= 1 print(ans)
1
35,915,944,222,830
null
175
175
N = int(input()) Stones = list(input()) count_red = 0 count_white = 0 for i in range(N): if Stones[i] == "R": count_red += 1 for i in range(count_red): if Stones[i] == "W": count_white += 1 print(count_white)
from sys import stdin n = int(stdin.readline()) c = stdin.readline()[:-1] red = c.count("R") ans = red numwhite = 0 for i in range(n): numwhite += 1 if c[i] == "W" else 0 numred = i - numwhite + 1 resred = red - numred ans = min(ans,max(resred,numwhite)) print(ans)
1
6,287,354,139,972
null
98
98
n = int(input()) d = list(map(int,input().split())) ans = 0 for i in range(n): ans += d[i] * (sum(d) - d[i]) print(ans // 2)
import itertools N = int(input()) D = list(input().split()) a = itertools.combinations(D,2) sum= 0 for i,j in a: sum += eval("{} * {}".format(i,j)) print(sum)
1
168,078,482,318,912
null
292
292
import sys n=int(input()) s=input() if n%2==1: print("No") sys.exit() else: s1=s[:n//2] s2=s[n//2:] # print(s1,s2) if s1==s2: print("Yes") else: print("No")
import math def main(): n = int(input()) ans = 0 for i in range(n): x = int(input()) if x == 2: ans += 1 elif x % 2 == 0: pass else: flag = True j = 3 while j <= math.sqrt(x): if x % j == 0: flag = False break j += 2 if flag: ans += 1 print(ans) if __name__ == '__main__': main()
0
null
73,123,549,446,152
279
12
n=int(input()) A=list(map(int,input().split())) for i in range(1,n): print(" ".join(map(str,A))) j=i while A[j]<A[j-1] and j>0: (A[j],A[j-1])=(A[j-1],A[j]) j=j-1 else: print(" ".join(map(str,A)))
import itertools import functools import math from collections import Counter def CHK(): X,Y,A,B,C=map(int,input().split()) p=sorted(list(map(int,input().split())),reverse=True) q=sorted(list(map(int,input().split())),reverse=True) r=sorted(list(map(int,input().split())),reverse=True) apples = sorted(p[:X] + q[:Y] + r, reverse=True) ans = sum(apples[:X+Y]) print(ans) CHK()
0
null
22,295,026,781,126
10
188
def Ii():return int(input()) def Mi():return map(int,input().split()) def Li():return list(map(int,input().split())) a,b = Mi() print(a*b)
data = input().split(' ') print(int(data[0]) * int(data[1]))
1
15,798,174,230,058
null
133
133
a, b = input().split() c, d = input().split() print(1 if a != c else 0)
a = list(map(int, input().split())) b = list(map(int, input().split())) if a[0] == b[0]: print(0) else: print(1)
1
124,961,963,747,994
null
264
264
n,k=map(int,input().split()) i=0 while n//k**(i+1)>=1: i+=1 print(i+1)
import math n = int(input()) xlist = list(map(float, input().split())) ylist = list(map(float, input().split())) #x, y = [list(map(int, input().split())) for _ in range(2)] 로 한방에 가능 print(sum(abs(xlist[i] - ylist[i]) for i in range(n))) print(pow(sum(abs(xlist[i] - ylist[i]) ** 2 for i in range(n)),0.5)) print(pow(sum(abs(xlist[i] - ylist[i]) ** 3 for i in range(n)),1/3)) print(max(abs(xlist[i] - ylist[i])for i in range(n)))
0
null
32,058,117,664,032
212
32
A = list(map(int, input().split())) for i in range(len(A)): if A[i] == 0: print(i+1)
m1, d1 = map(int, input().split()) m2, d2 = map(int, input().split()) ans = 1 if m1 == m2: ans = 0 print(ans)
0
null
68,634,172,584,468
126
264
for i in range(9): for j in range(9): print("{}x{}={}".format(i+1,j+1,(i+1)*(j+1)))
def __main(): x = 1; while x <= 9 : y = 1; while y <= 9 : z = x * y; print(str(x) + "x" + str(y) + "=" + str(z) ) y = y + 1 x = x + 1 __main()
1
2,425,948
null
1
1
s = input() n = len(s) Ans = [0] * (n + 1) top = set() bottom = set() if s[0] == ">": top.add(0) else: bottom.add(0) for i in range(len(s)-1): left = s[i] right = s[i+1] if left == "<" and right == ">": top.add(i+1) elif left == ">" and right == "<": bottom.add(i+1) if s[n-1] == ">": bottom.add(n) else: top.add(n) for b in list(bottom): counter = 0 for i in range(b, n+1): if i in top: break else: Ans[i] = counter counter += 1 counter = 0 for i in range(b-1, -1, -1): if i in top: break else: Ans[i] = counter + 1 counter += 1 #print(Ans) for t in list(top): if t == 0: Ans[0] = Ans[1] + 1 if t == n: Ans[n] = Ans[n-1] + 1 else: Ans[t] = max(Ans[t-1] + 1, Ans[t+1] + 1) #print(top) #print(bottom) print(sum(Ans))
n=int(input()) l="" for i in range(1,n+1): if i % 3==0 or i % 10 == 3 or (i % 100)//10 == 3 or (i % 1000)//100 == 3 or (i % 10000)//1000 == 3: l+=" "+str(i) print(l)
0
null
78,344,263,504,900
285
52
n = int(input()) x = list(map(float, input().split())) y = list(map(float, input().split())) def minc_dis(n, x, y, p): sum = 0 for i in range(n): sum = sum + (abs(x[i] - y[i])) ** p return sum ** (1/p) def cheb_dis(n, x, y): dis = 0 for i in range(n): dif = abs(x[i] - y[i]) if dis < dif: dis = dif return dis for p in range(1 , 4): print(minc_dis(n, x, y, p)) print(cheb_dis(n, x, y)) #print(cheb_dis(2, [1, 2, 3], [2, 0, 4]))
# coding: utf-8 n = int(input()) x = [float(i) for i in input().split()] y = [float(i) for i in input().split()] dl = [abs(i - j) for (i,j) in zip(x,y)] for p in range(1,4): d = sum([i ** p for i in dl]) ** (1/p) print("{:.8f}".format(d)) print("{:.8f}".format(max(dl)))
1
217,826,428,762
null
32
32
n, k = map(int, input().split()) A = tuple(map(int, input().split())) A = sorted(A, reverse=True) l = 0 r = max(A)+1 def cut(l, k): # 長さlの丸太を最大とすることができるかどうかを返す for a in A: if a > l: k -= (-(-a//l) - 1) return k >= 0 while r-l > 1: mid = (r+l)//2 if cut(mid, k): r = mid else: l = mid print(r)
def check(List,mid): tmp=0 for l in List: tmp+=(-(-l//mid)-1) return tmp n,k=map(int,input().split()) a=list(map(int,input().split())) lo=0 hi=max(a)+1 while hi - lo > 1: mid=(lo+hi)//2 if check(a,mid)<=k: hi=mid else: lo=mid print(hi)
1
6,483,587,226,400
null
99
99
import sys def calc_cell(x, y): return '.' if (x + y) % 2 else '#' def print_chessboard(height, width): for y in range(height): l = [] for x in range(width): l.append(calc_cell(x, y)) print ''.join(l) if __name__ == '__main__': while True: h, w = map(int, sys.stdin.readline().split()) print_chessboard(h, w) if not h or not w: break print
n=int(input()) a=[int(i) for i in input().split()] a.sort(reverse=True) if n%2: print(sum(a[:(n+1)//2])*2-a[0]-a[n//2]) else: print(sum(a[:n//2])*2-a[0])
0
null
5,083,350,679,822
51
111
K = int(input()) S = input() if len(S) <= K: print(S) else: print("{0}...".format(S[0:K]))
K = int(input()) S = input() if len(S) <= K: print (S) else: print (f'{S[:K]}...')
1
19,501,947,814,216
null
143
143
K = int(input()) A, B = map(int, input().split()) flag = 0 for n in range(A, B+1): if n % K == 0: flag = 1 break if flag == 0: print("NG") else: print("OK")
n, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(0, n - k): print("Yes" if a[i + k] > a[i] else "No")
0
null
16,856,329,869,942
158
102
n = input() print('Yes' if '7' in n else 'No')
s = input() t = input() a = len(s) - len(t) + 1 c1= 0 for i in range(a): c2 = 0 for j in range(len(t)): if s[i+j] == t[j]: c2 += 1 else: continue c1 = max(c1,c2) print(len(t)-c1)
0
null
19,101,896,849,262
172
82
n=int(input()) mod=998244353 A=list(map(int,input().split())) import sys # mod=10**9+7 ; inf=float("inf") from math import sqrt, ceil from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化 input=lambda: sys.stdin.readline().strip() sys.setrecursionlimit(11451419) from decimal import ROUND_HALF_UP,Decimal #変換後の末尾桁を0や0.01で指定 #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)) from functools import lru_cache from bisect import bisect_left as bileft, bisect_right as biright from fractions import Fraction as frac #frac(a,b)で正確なa/b #メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10) #引数にlistはだめ #######ここまでテンプレ####### #ソート、"a"+"b"、再帰ならPython3の方がいい #######ここから天ぷら######## C=Counter(A) if A[0]!=0 or A.count(0)>1: print(0);exit() Q=[C[i] for i in range(max(A)+1)] #print(Q) ans=1 for i in range(len(Q)-1): ans*= pow(Q[i],Q[i+1],mod) ans%=mod print(ans)
import sys import collections input = sys.stdin.readline MOD = 998244353 def main(): N = int(input()) D = list(map(int, input().split())) if D[0] != 0: print(0) return D.sort() Dmax = max(D) Ditems = collections.Counter(D).items() Dcount = list(zip(*Ditems)) Dset = set(Dcount[0]) if Dset != set(range(Dmax+1)): print(0) return if Dcount[1][0] != 1: print(0) return ans = 1 for i in range(2, Dmax+1): ans *= pow(Dcount[1][i-1], Dcount[1][i], MOD) ans %= MOD print(ans%MOD) if __name__ == "__main__": main()
1
154,737,898,164,740
null
284
284
n = int(input()) dp = [0]*(n+1) for i in range(1,n+1): x = n//i for j in range(1,x+1): dp[i*j]+=1 sum_div = 0 for i in range(1,n+1): sum_div += i*dp[i] print(sum_div)
n = int(input()) ans = 0 for i in range(1, n + 1): j = i while j <= n: ans += j j += i print(ans)
1
11,116,824,047,780
null
118
118
N = int(input()) A = list(map(int, input().split())) mod = 10**9+7 S = sum(A)**2 T = 0 for a in A: T+=a**2 S -= T S //= 2 S%=mod print(S)
# C - Sum of product of pairs N = int(input()) A = list(int(a) for a in input().split()) MOD = 10**9 + 7 csA = [0] * (N+1) for i in range(N): csA[i+1] = csA[i] + A[i] ans = 0 for i in range(N-1): ans += (A[i] * (csA[N] - csA[i+1])) % MOD print(ans%MOD)
1
3,840,541,934,462
null
83
83
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) from collections import defaultdict, deque from sys import exit import math import copy from bisect import bisect_left, bisect_right from heapq import * import sys # sys.setrecursionlimit(1000000) INF = 10 ** 17 MOD = 1000000007 from fractions import * def inverse(f): # return Fraction(f.denominator,f.numerator) return 1 / f def combmod(n, k, mod=MOD): ret = 1 for i in range(n - k + 1, n + 1): ret *= i ret %= mod for i in range(1, k + 1): ret *= pow(i, mod - 2, mod) ret %= mod return ret def bunsu(n): ret = [] for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: tmp = 0 while (True): if n % i == 0: tmp += 1 n //= i else: break ret.append((i, tmp)) ret.append((n, 1)) return ret MOD = 998244353 def solve(): n, k = getList() nums = getList() dp = [0 for i in range(k+1)] dp[0] = 1 for i, num in enumerate(nums): new = [0 for i in range(k+1)] for j, d in enumerate(dp): new[j] += d * 2 if (j + num) <= k: new[j+num] += d dp = [ne%MOD for ne in new] print(dp[-1]) def main(): # n = getN() # for _ in range(n): solve() if __name__ == "__main__": solve()
import sys input = sys.stdin.readline mod = 998244353 N, S = map(int, input().split()) A = list(map(int, input().split())) ans = 0 dp = [0] * (S+1) dp[0] = pow(2, N, mod) two_inv = pow(2, mod-2, mod) for i, a in enumerate(A): for j in range(a, S+1)[::-1]: dp[j] = (dp[j] + dp[j-a] * two_inv) % mod print(dp[S])
1
17,543,564,814,078
null
138
138
s = input() mid = len(s)//2 q = s[:mid] if len(s)%2 == 0: t = list(s[mid:]) else: t = list(s[mid+1:]) t.reverse() cnt = 0 for i in range(mid): cnt += s[i] != t[i] print(cnt)
s=input() t=s[::-1] cnt=0 for i in range(len(t)//2): if s[i]!=t[i]: cnt+=1 print(cnt)
1
120,090,367,575,250
null
261
261
import sys readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines read = sys.stdin.buffer.read sys.setrecursionlimit(10 ** 7) H, W = map(int, readline().split()) import math if H == 1 or W == 1: print(1) exit() total = H * W ans = (total + 2 - 1) // 2 print(ans)
H, W = map(int, input().split()) ans = 1 if H == 1 or W == 1 else (H*W+1) // 2 print(ans)
1
50,775,268,919,662
null
196
196
S = input() T = input() list_s = [] list_t = [] counter = 0 for i in range(0, len(S)): list_s.append(S[i]) list_t.append(T[i]) if S[i] != T[i]: list_s[i] = list_t[i] counter += 1 print(counter)
S=list(input()) T=list(input()) total = 0 for i in range(len(S)): if S[i] == T[i]: continue else: total += 1 print(str(total))
1
10,534,231,683,590
null
116
116
n,k = list(map(int, input().split())) p = list(map(int, input().split())) p.sort() print(sum(p[0:k]))
n, k = list(map(int, input().split())) p = list(map(int, input().split())) ps = sorted(p) print(sum(ps[:k]))
1
11,692,220,503,978
null
120
120
from itertools import product [N, M, X] = [int(i) for i in input().split()] bk = [[int(i) for i in input().split()] for _ in range(N)] ans = 12*10**5 + 1 for seq in product(range(2), repeat=N): S = [0]*(M+1) for i in range(N): for j in range(M+1): S[j] += seq[i]*bk[i][j] if min(S[1:M+1]) >= X: ans = min(ans, S[0]) if ans == 12*10**5 + 1: print(-1) else: print(ans)
n=int(input()) arr=list(map(int,input().split())) ans=sum(arr) if n==0: if arr[0]==1: print(1) else: print(-1) exit() for i in range(n): if i<=30 and arr[i]>=2**i: print(-1) exit() if n<=30 and arr[n]>2**n: print(-1) exit() maxs=[0]*(n+1) maxs[0]=1 for i in range(1,n): maxs[i]=2*maxs[i-1]-arr[i] tmp=arr[n] for i in range(n-1,-1,-1): maxs[i]=min(maxs[i],tmp) tmp+=arr[i] mins=[0]*(n+1) for i in range(n-1,-1,-1): mins[i]=(mins[i+1]+arr[i+1]+1)//2 for i in range(n): if maxs[i]<mins[i]: print(-1) exit() ans+=sum(maxs) print(ans)
0
null
20,529,713,008,288
149
141
#!/usr/bin python3 # -*- coding: utf-8 -*- n = int(input()) print(int(not n))
import math n = int(input()) x = n/1.08 t1 = math.ceil(x) t2 = math.floor(x) if math.floor(t1 * 1.08) == n: print(t1) elif math.floor(t2*1.08) == n: print(t2) else: print(':(')
0
null
64,533,638,005,120
76
265
n,k = map(int, input().split()) price = list(map(int, input().split())) count = 0 sum = 0 while count < k: abc = min(price) sum += abc price.pop(price.index(abc)) count += 1 print(sum)
n,k = list(map(int, input().split())) p = list(map(int, input().split())) p.sort() print(sum(p[0:k]))
1
11,632,971,261,440
null
120
120
N=input() a=int(N[0]) b=int(N[1]) c=int(N[2]) if a==7 or b==7 or c==7: print('Yes') else : print('No')
x=list(input()) print('Yes' if '7' in x else 'No')
1
34,100,004,406,720
null
172
172
while True: hw = [int(x) for x in input().split()] h, w = hw[0], hw[1] if h == 0 and w == 0: break for hh in range(h): for ww in range(w): print('#', end = '') print('') print('')
s=input();print("Yes"if s=="hi"*(len(s)//2)else"No")
0
null
27,148,131,264,250
49
199
import statistics as stats while True: n = int(input()) if n == 0: break data = list(map(int, input().split())) SD = stats.pstdev(data) print("{:.5f}".format(SD))
import math n, m = [int(i) for i in input().split()] t = 0 tt = 0 def com(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) if n > 1: t = com(n,2) if m > 1: tt = com(m,2) print(t+tt)
0
null
22,724,586,810,240
31
189
N, M = list(map(int, input().split())) H = list(map(int, input().split())) good = [True]*N for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 if H[a] >= H[b]: good[b] = False if H[a] <= H[b]: good[a] = False print(good.count(True))
n = int(input()) a = sorted([int(x) for x in input().split()]) print(a[0],a[-1],sum(a))
0
null
12,872,559,958,658
155
48
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")
n, k = map(int, input().split()) alst = list(map(int, input().split())) MOD = 10 ** 9 + 7 N = n + 10 fact = [0 for _ in range(N)] invfact = [0 for _ in range(N)] fact[0] = 1 for i in range(1, N): fact[i] = fact[i - 1] * i % MOD invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD) for i in range(N - 2, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD def nCk(n, k): if k < 0 or n < k: return 0 else: return fact[n] * invfact[k] * invfact[n - k] % MOD alst.sort() ans = 0 for i, num in enumerate(alst): ans -= num * nCk(n - 1 - i, k - 1) ans %= MOD for i, num in enumerate(alst[::-1]): ans += num * nCk(n - 1 - i, k - 1) ans %= MOD print(ans)
0
null
103,708,395,986,850
254
242
import math def main(): h,w = map(int, input().split()) if h == 1 or w == 1: print(1) else: print(math.ceil(h*w/2)) if __name__ == "__main__": main()
N = int(raw_input()) nums = map(int, raw_input().split(" ")) count = 0 for i in range(0, len(nums)): for j in range(len(nums)-1, i, -1): if nums[j-1] > nums[j]: temp = nums[j-1] nums[j-1] = nums[j] nums[j] = temp count += 1 nums = map(str, nums) print(" ".join(nums)) print(count)
0
null
25,454,599,971,082
196
14
M,N = map(int,input().rstrip().split(" ")) ans=False for a in range(M + 1): b=M-a if 2 * a + 4 * b == N: ans=True if ans: print("Yes") else: print("No")
import statistics while True: n = int(input()) if n == 0: break str = input().split() list = [] for i in range(n): list.append(int(str[i])) print(statistics.pstdev(list))
0
null
7,051,625,296,200
127
31
s=list(input()) t=[] for i in range(3): t.append(s[i]) r=''.join(t) print(r)
def resolve(): s = input() print(s[:3]) if 'unittest' not in globals(): resolve()
1
14,764,881,420,576
null
130
130
import sys from collections import deque S = deque(input()) Q = int(input()) reverse = False for _ in range(Q): q = sys.stdin.readline() if q[0] == "1": reverse = not reverse else: _, f, c = q.split() if f == "1": if reverse: S.append(c) else: S.appendleft(c) else: if reverse: S.appendleft(c) else: S.append(c) if reverse: S.reverse() ans = "".join(S) print(ans)
n = int(input()) a = list(map(int, input().split())) p = sorted([(x, i) for i, x in enumerate(a)], reverse=True) dp = [[0 for _ in range(n+1)] for _ in range(n+1)] for s in range(1, n+1): for x in range(s+1): y = s-x if x > 0: dp[x][y] = max(dp[x][y], dp[x-1][y] + abs(p[s-1][1] - x + 1) * p[s-1][0]) if y > 0: dp[x][y] = max(dp[x][y], dp[x][y-1] + abs(n-y - p[s-1][1]) * p[s-1][0]) print(max(dp[x][n-x] for x in range(n+1)))
0
null
45,275,238,279,652
204
171
kazu = input() kazu = int(kazu) for i in range( kazu ): print("ACL",end = '')
n,q = map(int,raw_input().split()) task = [] lst = [] a = 0 for i in range(n): name,time = raw_input().split() task.append(int(time)) lst.append(name) while True: if task[0] > q: task[0] = task[0] - q task.append(task.pop(0)) lst.append(lst.pop(0)) a += q else: a += task[0] print lst[0],a task.pop(0) lst.pop(0) if len(lst) == 0: break
0
null
1,139,074,188,450
69
19
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return map(fn, readline().split()) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): k, x = geta(int) if k * 500 >= x: print('Yes') else: print("No") if __name__ == "__main__": main()
N=int(input()) s=input() ans=s.count('ABC') print(ans)
0
null
98,899,222,418,122
244
245
N = int(input()) sqrt_N = int(N ** 0.5) dividers_for_N = [] ans_list = [] for i in range(1, sqrt_N + 1): if (N - 1) % i == 0: ans_list.append(i) if i != (N - 1) // i: ans_list.append((N - 1) // i) if N % i == 0: dividers_for_N.append(i) if i != N // i: dividers_for_N.append(N // i) dividers_for_N.remove(1) ans_list.remove(1) for i in dividers_for_N: num = N while num % i == 0: num //= i if num % i == 1: ans_list.append(i) ans = len(ans_list) print(ans)
def chmin(dp, i, *x): dp[i] = min(dp[i], *x) INF = float("inf") # dp[i] := min 消耗する魔力 to H -= i h, n = map(int, input().split()) dp = [0] + [INF]*h for _ in [None]*n: a, b = map(int, input().split()) for j in range(h + 1): chmin(dp, min(j + a, h), dp[j] + b) print(dp[h])
0
null
61,382,323,652,078
183
229
n, m = map(int, input().split()) nums = [0] * n check_flgs = [0] * n cnt = 0 for _ in range(m): s, c = map(int, input().split()) if check_flgs[s-1] == 0: nums[s-1] = c cnt += 1 check_flgs[s-1] = 1 elif check_flgs[s-1] != 0: if nums[s-1] == c: cnt += 1 continue else: break ans = "" for num in nums: ans += str(num) if cnt == m and n == 1: print(int(ans)) elif cnt == m and n >= 2 and nums[0] != 0: print(int(ans)) elif cnt == m and n >= 2 and nums[0] == 0 and check_flgs[0] == 0: print("1" + ans[1:]) else: print("-1")
dict = {'ABC':'ARC', 'ARC':'ABC'} print(dict[input()])
0
null
42,495,706,516,838
208
153
n = int(input()) x = list(map(int, input().split())) ans = 10**6 for i in range(1, 101): str = 0 for j in x: str += (j-i)**2 ans = min(ans, str) print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) inf = 10**17 mod = 10**9+7 n, k = map(int, input().split()) r, s, p = map(int, input().split()) t = input().rstrip() memo = [None] * n ans = 0 for i in range(n): if t[i] == 'r': if i - k < 0 or (0 <= i - k and memo[i - k] != 'p'): ans += p memo[i] = 'p' elif n <= i + k or (i + k < n and t[i + k] != 's'): memo[i] = 'r' else: memo[i] = 's' if t[i] == 's': if i - k < 0 or (0 <= i - k and memo[i - k] != 'r'): ans += r memo[i] = 'r' elif n <= i + k or (i + k < n and t[i + k] != 'p'): memo[i] = 's' else: memo[i] = 'p' if t[i] == 'p': if i - k < 0 or (0 <= i - k and memo[i - k] != 's'): ans += s memo[i] = 's' elif n <= i + k or (i + k < n and t[i + k] != 'r'): memo[i] = 'p' else: memo[i] = 'r' print(ans)
0
null
85,986,023,736,158
213
251
N=int(input()) A=list(map(int,input().split(' '))) acc = A[0] S = sum(A) ans= abs(S-2*acc) for i in A[1:]: acc += i ans = min(ans,abs(S-2*acc)) print(ans)
n, k = map(int, input().split()) p = [int(x) for x in input().split()] c = [int(x) for x in input().split()] loop_max = [] loop_len = [] S = [] ans = [] for i in range(len(p)): now = i temp_len = 0 temp_s = 0 temp_l = [] while True: now = p[now] - 1 temp_len += 1 temp_s += c[now] temp_l.append(temp_s) # 最初に戻ってきたら if now == i: break loop_len.append(temp_len) loop_max.append(temp_l) S.append(temp_s) for i in range(len(S)): mod = k % loop_len[i] if k % loop_len[i] != 0 else loop_len[i] if S[i] > 0: if max(loop_max[i][:mod]) > 0: ans.append(((k-1)//loop_len[i])*S[i] + max(loop_max[i][:mod])) else: ans.append(((k - 1) // loop_len[i]) * S[i]) else: ans.append(max(loop_max[i])) print(max(ans))
0
null
73,917,034,887,292
276
93
from collections import deque n, m = map(int, input().split()) # dist = [-1 for i in range(n)] prenodes = [-1 for i in range(n)] G = [[] for i in range(n)] ab = [] for i in range(m): ab.append(list(map(int, input().split()))) for i in range(m): G[ab[i][0]-1].append(ab[i][1]-1) G[ab[i][1]-1].append(ab[i][0]-1) # print(G) # dist[0] = 0 prenodes[0] = 0 que = deque([0]) while len(que) != 0: v = que.popleft() for vi in G[v]: if prenodes[vi] != -1: continue que.append(vi) # dist[vi] = dist[v] + 1 prenodes[vi] = v ans = "Yes" for i in range(n): if prenodes[i] == -1: ans = "No" break if ans == "No": print(ans) else: print(ans) for i in range(1, n): print(prenodes[i]+1)
N, M=map(int, input().split()) g = [[] for _ in range(N+1)] for _ in range(M): a, b = [int(x) for x in input().split()] g[a].append(b) g[b].append(a) from collections import deque queue=deque([1]) d=[None]*(N+1) d[1]=0 ans=[0]*(N+1) while queue: v=queue.popleft() for i in g[v]: if d[i] is None: d[i]=d[v]+1 ans[i]=v queue.append(i) print("Yes") for i in range(2,len(ans)): print(ans[i])
1
20,409,951,964,922
null
145
145
n = int(input()) lis =[] for i in range(1,n+1): lis.append(i) odd =[] for j in lis: if j % 2 != 0: odd.append(j) print(len(odd)/len(lis))
n=int(input()) x=0--n//2 print(x/n)
1
176,890,641,425,118
null
297
297
a, b, c = [int(_) for _ in input().split()] if a + b > c: print("No") elif 4 * a * b < (c - b - a) ** 2: print("Yes") else: print("No")
from decimal import Decimal a,b,c=map(lambda x:Decimal(x)**Decimal("0.5"),input().split()) print("Yes" if a+b<c else "No")
1
51,596,683,797,088
null
197
197
def main(): S = list(input()) K = int(input()) cnt = 0 if K == 1: T = S for i in range(len(T)-1): if T[i] == T[i+1]: T[i+1] = '.' ans = T.count('.') print(ans) return if len(S) == 1: ans = max(0, (K - (K%2==1))//2) print(ans) return if len(set(S)) == 1: tmp = len(S)*K tmp = tmp - (tmp%2 == 1) ans = tmp//2 print(ans) return T3 = S + S + S for i in range(len(T3)-1): if T3[i] == T3[i+1]: T3[i+1] = '.' T2aster = T3[len(S):(2*len(S))].count('.') T3aster = T3.count('.') ans = T3aster + T2aster * (K-3) print(ans) if __name__ == "__main__": main()
# A - Connection and Disconnection def count(s, c): count_ = s.count(c*2) while c*3 in s: s = s.replace(c*3, c+'_'+c) while c*2 in s: s = s.replace(c*2, c+'_') return min(count_, s.count('_')) def get_startswith(s, c): key = c while s.startswith(key+c): key += c return len(key) def get_endswith(s, c): key = c while s.endswith(key+c): key += c return len(key) import string S = input() K = int(input()) lower = string.ascii_lowercase ans = 0 if S[0] == S[-1:]: start = get_startswith(S, S[0]) end = get_endswith(S, S[0]) if start == end == len(S): print(len(S) * K // 2) else: ans = 0 ans += start // 2 ans += end // 2 ans += ((start + end) // 2) * (K - 1) for c in lower: ans += count(S[start:len(S)-end], c) * K print(ans) else: for c in lower: ans += count(S, c) print(ans * K)
1
175,886,131,784,620
null
296
296
import math print((int)(math.ceil((int)(input())/2)))
a=input() b=list(a) c=b[0:3] d="".join(c) print(d)
0
null
36,995,201,581,922
206
130
N = int(input()) a_lst = list(map(int, input().split())) print(sum((i + 1) % 2 == 1 and a % 2 == 1 for i, a in enumerate(a_lst)))
N = int(input()) an = x = [int(i) for i in input().split()] count = 0 for i in range(len(an)): if ((i + 1) % 2 == 0): continue if (an[i] % 2 != 0): count = count + 1 print(count)
1
7,731,894,859,998
null
105
105
d, t, s = map(int, input().split()) dist = t * s - d if dist >= 0: print("Yes") elif dist < 0: print("No")
import sys try: #d = int(input('D: ')) #t = int(input('T: ')) #s = int(input('S: ')) nums = [int(e) for e in input().split()] except ValueError: print('エラー:整数以外を入力しないでください') sys.exit(1) if 1 <= nums[0] <= 10000 and 1 <= nums[1] <= 10000 and 1 <= nums[2] <= 10000: take_time = nums[0] / nums[2] if take_time <= nums[1]: print("Yes") else: print("No") else: print('エラー:各入力は1~10000までの整数です')
1
3,507,667,413,490
null
81
81
S = list(input()) A = [0]*(len(S)+1) node_value = 0 for i in range(len(S)): if S[i] == "<": node_value += 1 A[i+1] = node_value else: node_value = 0 node_value = 0 for i in range(len(S)-1,-1,-1): if S[i] == ">": node_value += 1 A[i] = max(A[i], node_value) else: node_value = 0 print(sum(A))
import queue def bfs(g, s=1): global q dist = [-1] * len(g) dist[1] = 0 q = queue.Queue() q.put(s) while not q.empty(): v = q.get() if not G[v][1]: continue for vi in G[v][2:]: if dist[vi] >= 0: continue q.put(vi) dist[vi] = dist[v] + 1 return dist n = int(input()) G = [None] for i in range(n): G.append(list(map(int, input().split()))) d = bfs(G) for i in range(1, n + 1): print('%d %d' % (i, d[i]))
0
null
78,075,634,553,202
285
9
from collections import defaultdict N = int(input()) X = list(map(int, input().split())) ctr = defaultdict(int) ans = 0 for i in range(N): ctr[i + X[i]] += 1 ans += ctr[i - X[i]] print(ans)
import math def fact(n): ans = 1 for i in range(2, n+1): ans*= i return ans def comb(n, c): return fact(n)//(fact(n-c)*c) n = int(input()) nums = list(map(int, input().split())) ans = 0 l = {} r = [] for i in range(1,n+1): if(i + nums[i-1] not in l): l[i+nums[i-1]] =0 l[i+nums[i-1]]+=1 if((-1*nums[i-1])+i in l): ans+=l[(-1*nums[i-1])+i] print(ans)
1
26,240,145,763,312
null
157
157
# 27 N, A, B = map(int, input().split(' ')) ans = 0 if (A + B) != 0: taple = divmod(N, A + B) ans = taple[0] * A if B == 0: ans = N elif taple[1] > A: ans += A else: ans += taple[1] print(ans)
import math def main(): v = list(map(int, input().split())) n = v[0] a = v[1] b = v[2] answer = 0 if n < a: answer = n elif n < a+b: answer = a elif a == 0 and b == 0: answer = 0 else: answer += math.floor(n / (a+b)) * a rest = n % (a+b) if rest <= a: answer += rest else: answer += a print(answer) if __name__ == "__main__": main()
1
55,895,561,796,590
null
202
202
a,b,c,k = map(int, input().split()) goukei = 0 if k>=a: k -= a goukei += a else: goukei += k k = 0 if k>=b: k -= b else: k = 0 if k>0: goukei -= k print(goukei)
a, b, c, k = map(int, input().split()) if k <= a: print(k) elif k <= a + b: print(a) elif k <= a + b + c: print(a - (k-a-b)) else: print(a - c)
1
21,951,753,708,820
null
148
148
import math n, d = map(int, input().split()) xy = [list(map(int, input().split())) for _ in range(n)] count = 0 for i in range(n): count = count + 1 if math.sqrt(xy[i][0]**2 + xy[i][1]**2) <= d else count print(count)
a = str(input()) a = a.swapcase() print(a)
0
null
3,731,045,076,128
96
61
N = int(input()) A = list(map(int, input().split())) def ans(): if 0 in A: return print(0) product = 1 for num in A: product = product * num if product > 10 ** 18: return print(-1) print(product) ans()
def Li(): return list(map(int, input().split())) N = int(input()) A = Li() ans = 1 if 0 in A: ans = 0 else: for i in A: ans *= i if ans > pow(10, 18): ans = -1 break print(ans)
1
16,151,688,858,020
null
134
134
def A(): d, t, s = map(int, input().split()) print("Yes" if t*s>=d else "No") def B(): s = input() t = input() sa = len(s) - len(t) ret = 10000000000 for i in range(sa+1): cnt = 0 for j in range(len(t)): if s[j+i] != t[j]: cnt += 1 ret = min(ret, cnt) print(ret) def C(): int(input()) A = list(map(int, input().split())) S = sum(A) T = 0 for e in A: T += e*e print((S * S - T)//2) class UF: def __init__(self, N): self.N = N self.sz = [1] * N self.par = [i for i in range(N)] self.d = [1] * N def find(self, x): if self.par[x] == x: return x self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.d[y] > self.d[x]: self.par[x] = y self.sz[y] += self.sz[x] else: self.par[y] = x self.sz[x] += self.sz[y] if self.d[x] == self.d[y]: self.d[x] += 1 def D(): n, m = map(int, input().split()) uf = UF(n+1) for i in range(m): a, b = map(int, input().split()) uf.unite(a, b) print(max(uf.sz)) D()
import sys import resource def root(x): if par[x] == x: return x par[x] = root(par[x]) return par[x] def union(x, y): rx = root(x) ry = root(y) if rx != ry: par[rx] = ry return 0 sys.setrecursionlimit(10 ** 6) n, m=map(int, input().split(" ")) par = list(range(n + 1)) for i in range(m): a, b = map(int, input().split(" ")) union(a, b) #print(par) maxi = 0 count = 1 #print(par) countpar = [0 for i in range(n + 1)] #print(len(countpar), len(par)) for i in range(1, n + 1): countpar[root(par[i])] += 1 print(max(countpar)) #print(countpar, par)
1
4,028,918,406,448
null
84
84
#!/usr/bin/env python3 n = int(input()) ans = [0] * (n + 1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): w = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x if w <= n: ans[w] += 1 for i in range(1, n + 1): print(ans[i])
N = int(input()) myans = [ 0 for n in range(N+1)] upper = int(N**(2/3)) #print(upper) for x in range(1, 105): for y in range(1, 105): for z in range(1, 105): v = x**2 + y**2 + z**2 + x*y + y*z + z*x if v < N+1: myans[v] += 1 #print(myans) for a,b in enumerate(myans): if a != 0: print(b)
1
8,008,415,879,828
null
106
106
the_string = input() L1,R1,d1 = the_string.split() L=int(L1) R=int(R1) d=int(d1) count=0 for i in range(L,R+1): if(i%d)==0: count+=1 print(count)
D = {} s, t = input().split() a, b = map(int, input().split()) D[s] = a D[t] = b D[input()] -= 1 print(D[s], D[t])
0
null
39,597,058,146,800
104
220
def solve(N): if N%2==1: return 0 N2=(N-N%10)//10 count_zero=N2 x=5 while N2>=x: count_zero+=N2//x x*=5 return count_zero N=int(input()) print(solve(N))
def main(S, T): if len(S)+1 == len(T) and S == T[:-1]: return 'Yes' else: return 'No' if __name__ == '__main__': S = input() T = input() ans = main(S, T) print(ans)
0
null
68,682,260,396,632
258
147
from collections import deque n = int(input()) data = deque(list(input() for _ in range(n))) ans = deque([]) co = 0 for i in data: if i[6] == ' ': if i[0] == 'i': ans.insert(0, i[7:]) co += 1 else: try: ans.remove(i[7:]) co -= 1 except: pass else: if i[6] == 'F': del ans[0] co -= 1 else: del ans[-1] co -= 1 for i in range(0, co-1): print(ans[i], end=' ') print(ans[co-1])
from collections import deque def process_command(dll, commands): for cmd in commands: # print(cmd) if cmd.startswith('insert') or cmd.startswith('delete '): t = cmd.split(' ') cmd = t[0] num_str = t[1] if cmd == 'insert': dll.appendleft(int(num_str)) elif cmd == 'delete': if int(num_str) in dll: temp = [] result = dll.popleft() while result != int(num_str): temp.append(result) result = dll.popleft() temp = temp[::-1] dll.extendleft(temp) elif cmd == 'deleteFirst': dll.popleft() elif cmd == 'deleteLast': dll.pop() # print(dll) # print('=' * 64) if __name__ == '__main__': # ??????????????\??? commands = [] num = int(input()) for i in range(num): commands.append(input()) # ?????? dll = deque() process_command(dll, commands) # ??????????????? # dll.reverse() print('{0}'.format(' '.join(map(str, dll))))
1
49,898,373,914
null
20
20