code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
A,B,K = list(map(int, input().split())) if A > K: A -= K else: K -= A A = 0 if B > K: B -= K else: B = 0 print(A,B) A -= min(A, K)
A,B,K = map(int,input().split()) if K>A+B: A,B = 0,0 elif K>A: A,B = 0,B-K+A else: A -= K print(f'{A} {B}')
1
104,639,995,010,930
null
249
249
mod = 10 ** 9 + 7 n = int(input()) a = map(int, input().split()) cnt = [0] * (n + 1) cnt[-1] = 3 ret = 1 for x in a: ret = ret * cnt[x - 1] % mod cnt[x - 1] -= 1 cnt[x] += 1 print(ret)
MOD=10**9+7 class Fp(int): def __new__(self,x=0):return super().__new__(self,x%MOD) def inv(self):return self.__class__(super().__pow__(MOD-2,MOD)) def __add__(self,value):return self.__class__(super().__add__(value)) def __sub__(self,value):return self.__class__(super().__sub__(value)) def __mul__(self,value):return self.__class__(super().__mul__(value)) def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv()) def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD)) __radd__=__add__ __rmul__=__mul__ def __rsub__(self,value):return self.__class__(-super().__sub__(value)) def __rfloordiv__(self,value):return self.__class__(self.inv()*value) def __iadd__(self,value):self=self+value;return self def __isub__(self,value):self=self-value;return self def __imul__(self,value):self=self*value;return self def __ifloordiv__(self,value):self=self //value;return self def __ipow__(self,value):self=self**value;return self def __neg__(self):return self.__class__(super().__neg__()) def main(): N,*A=map(int, open(0).read().split()) C=[0]*(N+1) C[-1]=3 ans=Fp(1) for a in A: ans*=C[a-1] C[a-1]-=1 C[a]+=1 print(ans) if __name__ == "__main__": main()
1
129,973,478,446,308
null
268
268
s = input() k = int(input()) l=len(s) s+='?' ch = 1 ans=0 j=0 for i in range(l): if s[i]==s[i+1]: ch+=1 else: ans+=ch//2 if j==0: st=ch if s[i+1]=='?': gl=ch ch=1 j=1 ans*=k if st%2==1 and gl%2==1 and s[0]==s[l-1]: ans+=k-1 if st==l: ans=l*k//2 print(ans)
l = list(input()) a = False b = False c = False if l[0] == 'R': a = True if l[1] == 'R': b = True if l[2] == 'R': c = True if a and b and c: print(3) elif (a and b) or (b and c): print(2) elif a or b or c: print(1) else: print(0)
0
null
90,549,142,322,000
296
90
class Element: def __init__(self, x): self.x = x self.lh = None self.rh = None class MyDeque: def __init__(self): self.top = self.tail = None def insert(self, x): elm = Element(x) if self.top is None: self.top = self.tail = elm else: elm.rh = self.top self.top.lh = self.top = elm def delete(self, x): elm = self.top while elm is not None: if elm.x == x: if elm.lh is None and elm.rh is None: self.top = self.tail = None else: if elm.lh is None: self.top = elm.rh else: elm.lh.rh = elm.rh if elm.rh is None: self.tail = elm.lh else: elm.rh.lh = elm.lh break elm = elm.rh def delete_first(self): if self.top is self.tail: self.top = self.tail = None else: self.top = self.top.rh self.top.lh = None def delete_last(self): if self.top is self.tail: self.top = self.tail = None else: self.tail = self.tail.lh self.tail.rh = None def print_que(self): elm = self.top q=[] while elm is not None: q.append(elm.x) elm = elm.rh print(*q) from sys import stdin que = MyDeque() N = int(input()) for _ in range(N): cmd = stdin.readline().strip().split() if cmd[0] == 'insert': que.insert(cmd[1]) #que.print_que() elif cmd[0] == 'delete': que.delete(cmd[1]) #que.print_que() elif cmd[0] == 'deleteFirst': que.delete_first() #que.print_que() elif cmd[0] == 'deleteLast': que.delete_last() #que.print_que() que.print_que()
a,b,c,d = map(int, input().split()) ac = a * c ad = a * d bc = b * c bd = b * d print(max([ac, ad, bc, bd]))
0
null
1,533,518,905,000
20
77
line = input() result = line.swapcase() print(result)
# coding: utf-8 # Your code here! n = input() t = "" for i in range(len(n)): m = str(n[i]) if (n[i].islower()): m = n[i].upper() else: m = n[i].lower() t += m print(t)
1
1,509,578,942,518
null
61
61
n = int(input()) d = list(map(int, input().split())) a = [0] * n for i in range(n): a[d[i]] += 1 if a[0] == 1 and d[0] == 0: ans = 1 for i in range(1, n): ans *= a[i-1]**a[i] ans %= 998244353 print(ans) else: print(0)
n = int(input()) d = list(map(int,input().split())) MOD = 998244353 if d[0] != 0: print(0) exit() d.sort() for i in range(1,n): if d[i] - d[i-1] > 1: print(0) exit() if d[i] == 0: print(0) exit() count = 1 tmp = 1 ans = 1 for i in range(2,n): if d[i] != d[i-1]: ans *= pow(tmp,count,MOD) #print(tmp,count) tmp = count count = 1 else: count+=1 ans *= pow(tmp,count,MOD) ans %= MOD #print(tmp,count) print(ans)
1
155,277,333,571,448
null
284
284
from scipy.sparse.csgraph import floyd_warshall as fw N, M, L = map(int, input().split()) S = [[float("inf") for i in range(N)] for i in range(N)] for i in range(M): a, b, c = map(int, input().split()) S[a-1][b-1] = c S[b-1][a-1] = c Sdist = fw(S) Ssup_init = [[float("inf") for i in range(N)] for i in range(N)] for i in range(N): for j in range(N): if Sdist[i][j]<=L: Ssup_init[i][j] = 1 Ssup = fw(Ssup_init) Q = int(input()) for i in range(Q): s, t = map(int, input().split()) if Ssup[s-1][t-1]==float("inf"): print(-1) else: print(int(Ssup[s-1][t-1]-1))
from collections import deque,defaultdict import bisect N = int(input()) S = [input() for i in range(N)] def bend(s): res = 0 k = 0 for th in s: if th == '(': k += 1 else: k -= 1 res = min(k,res) return res species = [(bend(s),s.count('(')-s.count(')')) for s in S] ups = [(b,u) for b,u in species if u > 0] flats = [(b,u) for b,u in species if u == 0] downs = [(b,u) for b,u in species if u < 0] ups.sort() high = 0 for b,u in ups[::-1] + flats: if high + b < 0: print('No') exit() high += u rdowns = [(b-u,-u) for b,u in downs] rdowns.sort() high2 = 0 for b,u in rdowns[::-1]: if high2 + b < 0: print('No') exit() high2 += u if high == high2: print('Yes') else: print('No')
0
null
98,297,799,477,478
295
152
import sys stdin = sys.stdin inf = 1 << 60 mod = 1000000007 ni = lambda: int(ns()) nin = lambda y: [ni() for _ in range(y)] na = lambda: list(map(int, stdin.readline().split())) nan = lambda y: [na() for _ in range(y)] nf = lambda: float(ns()) nfn = lambda y: [nf() for _ in range(y)] nfa = lambda: list(map(float, stdin.readline().split())) nfan = lambda y: [nfa() for _ in range(y)] ns = lambda: stdin.readline().rstrip() nsn = lambda y: [ns() for _ in range(y)] ncl = lambda y: [list(ns()) for _ in range(y)] nas = lambda: stdin.readline().split() h, w, k = na() s = nsn(h) ans = inf for bits in range(2 ** (h - 1)): binf = "{0:b}".format(bits) res = sum([int(b) for b in binf]) divcnt = res + 1 cnt = [0] * divcnt flag = True j = 0 while j < w: cur = 0 for i in range(h): if (s[i][j] == '1'): cnt[cur] += 1 if bits >> i & 1: cur += 1 if max(cnt) > k: if flag: res = inf break res += 1 for i in range(divcnt): cnt[i] = 0 flag = True else: flag = False j += 1 ans = min(ans, res) print(ans)
import math H, W, K = map(int, input().split()) S = [list(map(lambda x: int(x=='1'), input())) for _ in range(H)] def cal_min_vert_div(hs): cnt = 0 n_h_div = len(hs) n_white = [0]*n_h_div for i in range(W): for j in range(n_h_div): n_white[j] += hs[j][i] if n_white[j] > K: n_white = [hs[k][i] for k in range(n_h_div)] cnt += 1 if max(n_white)>K: return math.inf break return cnt ans = math.inf for mask in range(2**(H-1)): hs = [] tmp = S[0] for i in range(H-1): if mask>>i & 1: hs.append(tmp) tmp = S[i+1] else: tmp = [tmp[w]+S[i+1][w] for w in range(W)] hs.append(tmp) tmp = cal_min_vert_div(hs)+sum(map(int, bin(mask)[2:])) ans = min(ans, tmp) print(ans)
1
48,521,182,965,650
null
193
193
class Dice: def __init__(self): # 初期値がない場合 # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定 self.t = 1 self.s = 2 self.e = 3 self.w = 4 self.n = 5 self.b = 6 self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3} def __init__(self, t, s, e, w, n, b): # 初期値が指定される場合 self.t = t self.s = s self.e = e self.w = w self.n = n self.b = b self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3} def rot(self, way): if way == 0: self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s elif way == 1: self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n elif way == 2: self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e elif way == 3: self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w def main(): import random t,s,e,w,n,b = map(int, input().split()) dice2 = Dice(t,s,e,w,n,b) q = int(input()) for _ in range(q): top, front = map(int, input().split()) while True: if dice2.t == top and dice2.s == front: break else: seed = random.randint(0, 3) dice2.rot(seed) print(dice2.e) if __name__ == '__main__': main()
class Dice: def __init__(self, U, S, E, W, N, D): self.u, self.d = U, D self.e, self.w = E, W self.s, self.n = S, N def roll(self, commmand): if command == 'E': self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e elif command == 'W': self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w elif command == 'S': self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s else: self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n def rightside(self, upside, forward): self.structure = {self.u:{self.w: self.s, self.s: self.e, self.e: self.n, self.n: self.w}, self.d:{self.n: self.e, self.e: self.s, self.s: self.w, self.w: self.n}, self.e:{self.u: self.s, self.s: self.d, self.d: self.n, self.n: self.u}, self.s:{self.u: self.w, self.w: self.d, self.d: self.e, self.e: self.u}, self.w:{self.u: self.n, self.n: self.d, self.d: self.s, self.s: self.u}, self.n:{self.u: self.e, self.e: self.d, self.d: self.w, self.w: self.u}} print(self.structure[upside][forward]) U, S, E, W, N, D = [int(i) for i in input().split()] turns = int(input()) dice1 = Dice(U, S, E, W, N, D) for i in range(turns): upside, forward = [int(k) for k in input().split()] dice1.rightside(upside, forward)
1
260,262,320,330
null
34
34
N = int(input()) S = int(N**(1/2)) for i in range(S,0,-1): if N%i == 0: A = N//i B = i break print(A+B-2)
word = list(map(int,input().split())) score = list(map(int,input().split())) score.sort() score.reverse() gokei = 0 for i in range(word[0]): gokei += score[i] if score[word[1]-1]*4*word[1] >= gokei: print('Yes') else: print('No')
0
null
99,964,220,973,216
288
179
str = list(input()) q = int(input()) for i in range(q): s = list(input().split()) s[1] = int(s[1]) s[2] = int(s[2]) if s[0] == 'print': print(''.join(str[s[1]:s[2]+1])) elif s[0] == 'reverse': str[s[1]:s[2]+1] = ''.join(reversed(str[s[1]:s[2]+1])) elif s[0] == 'replace': str[s[1]:s[2]+1:1] = s[3]
def sprint(str, a, b): print(str[a:b+1]) def reverse(str, a, b): str1 = str[:a] str2 = str[a: b+1] str3 = str[b+1:] str = str1 + str2[::-1] + str3 return str def replace(str, a, b, p): str1 = str[:a] str3 = str[b+1:] str = str1 + p + str3 return str str = input() q = int(input()) for i in range(q): L = input().split() if L[0] == "replace": str = replace(str, int(L[1]), int(L[2]), L[3]) if L[0] == "reverse": str = reverse(str, int(L[1]), int(L[2])) if L[0] == "print": sprint(str, int(L[1]), int(L[2]))
1
2,087,057,151,900
null
68
68
A, B, C = map(int, input().split()) print('Yes' if len(set([A, B, C]))==2 else 'No')
H, A = map(int, input().split()) ans = (H // A) + ( 1 if (H % A) != 0 else 0) print(ans)
0
null
72,485,854,072,644
216
225
from typing import List def DFS(G: List[int]): global time time = 0 n = len(G) for u in range(n): if color[u] == "WHITE": DFS_Visit(u) def DFS_Visit(u: int): global time color[u] = "GRAY" time += 1 d[u] = time for v in G[u]: if color[v] == "WHITE": pi[v] = u DFS_Visit(v) color[u] = "BLACK" time += 1 f[u] = time if __name__ == "__main__": n = int(input()) G = [] color = ["WHITE" for _ in range(n)] pi = [None for _ in range(n)] d = [0 for _ in range(n)] f = [0 for _ in range(n)] for _ in range(n): command = list(map(int, input().split())) G.append([x - 1 for x in command[2:]]) DFS(G) for i in range(n): print(f"{i + 1} {d[i]} {f[i]}")
n,d = map(int,input().split(" ")) ans = 0 for i in range(n): a,b = map(int,input().split(" ")) if (a*a + b*b) <= d*d: ans += 1 print(ans)
0
null
2,986,943,145,888
8
96
def get_cusum(lst): cusum = [0] + lst for i in range(1, len(cusum)): cusum[i] = cusum[i] + cusum[i-1] return cusum def main(): n, m, k = map(int, input().split(" ")) book_a = get_cusum(list(map(int, input().split(" ")))) book_b = get_cusum(list(map(int, input().split(" ")))) ans = 0 top = m # print(book_a) # print(book_b) for i in range(n + 1): if book_a[i] > k: break while book_b[top] > k - book_a[i]: top -= 1 ans = max(ans, i+top) print(ans) main()
# Tsundoku import numpy as np N, M, K = map(int,input().split()) A = np.array([0] + list(map(int, input().split()))) B = np.array([0] + list(map(int, input().split()))) a = np.cumsum(A) b = np.cumsum(B) ans = 0 j = M for i in range(N+1): if a[i] > K: break while b[j] > K - a[i]: j -= 1 ans = max(ans, i+j) print(ans)
1
10,825,786,521,692
null
117
117
a,b = map(int,input().split()) if a >= 10: print(str(b)) else: print(str(b+100*(10-a)))
N,R = map(int,input().split(" ")) if N>10: print(R) else: print(R+100*(10-N))
1
63,289,359,219,040
null
211
211
import sys input = sys.stdin.readline from collections import defaultdict def prime(n: int) -> defaultdict: f, i = defaultdict(int), 2 while i * i <= n: while n % i == 0: f[i] += 1; n //= i i += 1 if n != 1: f[n] = 1 return f def solve(n: int) -> int: if n == 1: return 1 r, l = n, 0 while (r - l) > 1: m = (l + r) // 2 if m * (m + 1) // 2 <= n: l = m else: r = m return l n, res = int(input()), 0 for k, v in prime(n).items(): res += solve(v) print(res)
n = int(input()) N = n arr = [n] while n % 2 == 0: arr.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: arr.append(f) n //= f else: f += 2 if n != 1: arr.append(n) arr.sort() import collections c = collections.Counter(arr) k = list(c.keys()) v = list(c.values()) x = [] for i in range(len(k)): for p in range(1,v[i]+1): x.append(k[i]**p) x.sort() ans = 0 n = N while n != 1 and len(x) != 0: if n % x[0] == 0: n //= x[0] x.pop(0) ans += 1 else: x.pop(0) print(ans)
1
16,803,913,466,418
null
136
136
# 具体例を試す import math import sys import os from operator import mul sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin = open(inputFile, "r") INF = float("inf") A,B,N = LI() # ans = 0 # a = [0]*N # for x in range(1,N+1): # # ans = max(ans,math.floor(A*x/B) - A * math.floor(x/B)) # a[x-1]=math.floor(A*x/B) - A * math.floor(x/B) x = min(N,B-1) ans = math.floor(A*x/B) - A * math.floor(x/B) print(ans)
s = int(input()) MOD = 10**9 + 7 dp = [0] * (s+10) dp[0] = 1 for i in range(3, s+10): dp[i] = sum(dp[:i-2]) dp[i] %= MOD print(dp[s]%MOD)
0
null
15,734,330,996,050
161
79
# Author: cr4zjh0bp # Created: Sat Mar 14 20:41:10 UTC 2020 import sys stdin = sys.stdin inf = 1 << 60 mod = 1000000007 ni = lambda: int(ns()) nin = lambda y: [ni() for _ in range(y)] na = lambda: list(map(int, stdin.readline().split())) nan = lambda y: [na() for _ in range(y)] nf = lambda: float(ns()) nfn = lambda y: [nf() for _ in range(y)] nfa = lambda: list(map(float, stdin.readline().split())) nfan = lambda y: [nfa() for _ in range(y)] ns = lambda: stdin.readline().rstrip() nsn = lambda y: [ns() for _ in range(y)] ncl = lambda y: [list(ns()) for _ in range(y)] nas = lambda: stdin.readline().split() from collections import Counter s = ns() n = len(s) s = s + "$" k = ni() c = [] cnt = 1 for i in range(len(s) - 1): if s[i] == s[i + 1]: cnt += 1 elif cnt > 1: c.append(cnt) cnt = 1 if (len(c) == 1 and c[0] == n) or n == 1: print(n * k // 2) elif s[0] != s[-2]: print(sum([x // 2 for x in c[:]]) * k) else: a, b = 1, 1 if s[0] == s[1]: a = c[0] if s[-2] == s[-3]: b = c[-1] print(sum([x // 2 for x in c[:]]) * k - (a // 2 + b // 2 - (a + b) // 2) * (k - 1))
n = int(input()) a = list(map(int, input().split())) x = 0 for a_i in a: x ^= a_i for a_i in a: print(x ^ a_i)
0
null
93,774,743,992,108
296
123
N, M = map(int, input().split()) A = list(map(int, input().split())) for i in range(0, M): N -= A[i] if N < 0: print('-1') else: print(N)
W, H, x, y, r = [int(temp) for temp in input().split()] if r <= x <= (W - r) and r <= y <= (H - r) : print('Yes') else : print('No')
0
null
16,266,366,002,912
168
41
N, K, C = map(int, input().split()) S = input() length = len(S) INF = float('inf') Ls = [-INF] n = 0 for i, c in enumerate(S): if c == 'o' and i - Ls[-1] > C: Ls.append(i) n += 1 if n >= K: break Rs = [INF] n = 0 for i, c in enumerate(reversed(S)): if c == 'o' and Rs[-1] - (length-1-i) > C: Rs.append(length-1-i) n += 1 if n >= K: break Rs.reverse() for l, r in zip(Ls[1:], Rs[:-1]): if l == r: print(l+1)
if __name__ == '__main__': a, b, c = [int(i) for i in input().split()] ans = [1 if c % i == 0 else 0 for i in range(a, b + 1)] print(sum(ans))
0
null
20,630,230,597,600
182
44
s=input() l=len(s) list_s=list(s) ans="" if(s[l-1]!="s"): list_s.append("s") elif(s[l-1]=="s"): list_s.append("es") for i in range(0,len(list_s)): ans+=list_s[i] print(ans)
palavra= input() tam= len(palavra) if palavra[tam-1]=='s': print(palavra+'es') else: print(palavra+'s')
1
2,365,226,876,700
null
71
71
print((lambda a: len([i for i in range(a[0], a[1]+1) if a[2] % i == 0]))(list(map(int, input().split()))))
n, k = list(map(int, input().split())) if n < k: ans = min(n, abs(n - k)) else: q = n // k ans = min(abs(n - (q * k)), abs(n - (q * k) - k)) print(ans)
0
null
20,036,401,492,800
44
180
n, m = map(int, input().split()) num = [None] * n a = [tuple(map(int, input().split())) for _ in range(m)] for pos, val in a: if num[pos - 1] != None and num[pos - 1] != val: print(-1) exit() num[pos - 1] = val if n == 1 and num[0] == None: num[0] = 0 canBeZero = False for i in range(n): if num[i] == None: num[i] = 0 if canBeZero else 1 if num[i]: canBeZero = True ret = str(int(''.join(map(str, num)))) print(ret if len(ret) == n else -1)
n,m = map(int,input().split()) li = [list(map(int,input().split())) for _ in range(m)] if n==1 and all([i[1]==0 for i in li]): print(0) exit() for i in range(10**(n-1),10**n): p = list(map(int,list(str(i)))) for s,c in li: if p[s-1] != c:break else: print(i) exit() print(-1)
1
60,944,578,988,040
null
208
208
x=input() if ((x>='A') and (x<='Z')): print('A') elif (x>='a') and (x<='z'): print('a')
# coding: utf-8 # Your code here! a = input() big = ["A","B","C","D","E","F","G","H","I","J","K","L", "M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] small = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] if a in big: print("A") else: print("a")
1
11,334,724,170,210
null
119
119
while True: height, width = [int(x) for x in input().split(" ")] if height == 0 and width ==0: break #start line print("{0}".format("#" * width)) for h in range(0, (height - 2)): for w in range(width): if w == 0 or w == (width - 1): print ("#", end="") else: print (".", end="") print("\n", end="") #end line print("{0}".format("#" * width)) print("\n", end="")
n = int(input()) ans = 0 if n%2 == 0: ans = n//2 print(ans) else: ans = n//2 +1 print(ans)
0
null
29,866,459,265,380
50
206
from collections import deque import sys dlist = deque() func = {'insert':dlist.appendleft, 'delete':dlist.remove, 'deleteFirst':dlist.popleft, 'deleteLast':dlist.pop} n = int(sys.stdin.readline()) for line in sys.stdin: command = line.split() if len(command) == 2: command[1] = int(command[1]) try: func[command[0]](*command[1:]) except ValueError: pass print(*dlist)
a, b, c, d = map(int,input().split()) inf = -10**9 ans = max(a*c, a*d) ans = max(ans, b*c) ans = max(ans, b*d) print(ans)
0
null
1,547,914,220,338
20
77
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): N, M = map(int, input().split()) if N == M: print('Yes') else: print('No') if __name__ == '__main__': solve()
N=int(input()) X=[int(x) for x in input().split()] ans=10**9 for p in range(-200, 200): ref=0 for x in X: ref+=(x-p)**2 #print(ref) ans=min(ans, ref) print(ans)
0
null
74,278,957,903,068
231
213
tmp = input().split(" ") a = int(tmp[0]) b = int(tmp[1]) c = int(tmp[2]) if a + b + c >= 22: print("bust") else: print("win")
n = int(input()) A = [None] * n for i in range(n): A[i] = int(input()) def insertionSort(A, n, g): cnt = 0 for i in range(g, n, 1): # Insertion Sort # e.g. if g == 4 and i == 8: [4] 6 2 1 [10] 8 9 5 [3] 7 j = i - g # e.g. j = 4 k = i # e.g. k = 8 while j >= 0 and A[j] > A[k]: #print("i:{} j:{} k:{} A:{}".format(i, j, k, A)) A[j], A[k] = A[k], A[j] k = j # e.g. k = 4 j = k - g # e.g. j = 4 - 0 = 0 cnt += 1 #print("j reduced to {}, k reduced to {}".format(j, k)) return(cnt) def shellSort(A, n): g = [0] m = 0 sum = 0 while True: if (3*m + 1 <= n): g.insert(0, 3*m + 1) m = 3*m + 1 else: break for i in range(len(g)): cnt = insertionSort(A, n, g[i]) sum += cnt print(len(g)) print(str(g).replace('[', '').replace(']', '').replace(',', '')) print(sum) for i in range(n): print(A[i]) def main(): shellSort(A, n) main()
0
null
59,302,991,698,262
260
17
import sys input=sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode('utf-8') import numpy as np def main(): x=II() for i in range(-300,300): for j in range(-300,300): if i**5==x+j**5: print(i,j) exit() if __name__=="__main__": main()
X=int(input()) A=0 B=0 for i in range(-120,120): for k in range(-120,120): if i**5==X+k**5: A=i B=k break print(A,B)
1
25,551,962,744,490
null
156
156
N, K = map(int, input().split()) H = list(map(int, input().split())) A = [i for i in H if i >= K] print(len(A))
N, K = map(int, input().split()) h = list(map(int, input().split())) person = 0 for i in range(0, N): if h[i] >= K: person += 1 print(person)
1
178,875,225,917,542
null
298
298
x = int(input()) print((x//500)*1000+((x-500*(x//500))//5)*5)
x = int(input()) num = (x//500)*1000 num += ((x%500)//5)*5 print(num)
1
42,750,254,945,380
null
185
185
N = int(input()) ans = 0 for x in range(1, N + 1): n = N // x #ans += n * (2 * x + (n - 1) * x) // 2 ans += n * ( x + n * x) // 2 print(ans)
class dice: def __init__(self,dice): self.dice = dice def roll_n(self): d = self.dice self.dice = [d[1],d[5],d[2],d[3],d[0],d[4]] def roll_e(self): d = self.dice self.dice = [d[3],d[1],d[0],d[5],d[4],d[2]] def roll_s(self): d = self.dice self.dice = [d[4],d[0],d[2],d[3],d[5],d[1]] def roll_w(self): d = self.dice self.dice = [d[2],d[1],d[5],d[0],d[4],d[3]] def top(self): return self.dice[0] def roll(self,command): if command=='N':self.roll_n() if command=='E':self.roll_e() if command=='S':self.roll_s() if command=='W':self.roll_w() def main(): com1 = 'SSSWSSS' com2 = 'WWWW' d = dice(list(map(int,input().split()))) q = int(input()) for _ in range(q): a,b = map(int,input().split()) for c in com1: if b==d.dice[1]:break d.roll(c) for c in com2: if a==d.dice[0]:print (d.dice[2]) d.roll(c) if __name__ == '__main__': main()
0
null
5,655,190,240,612
118
34
def shuffle(s,n): if len(s) <= 1: return s ans = s[n:] + s[:n] return ans def main(): while True: strings = input() if strings == "-": break n = int(input()) li = [] for i in range(n): li.append(int(input())) for i in li: strings = shuffle(strings, i) print(strings) if __name__ == "__main__": main()
while True: data = input() if(data == "-"):break m = int(input()) tmp = [] for i in range(m): num = int(input()) if(len(tmp) == 0): tmp = data[num:] + data[:num] data = "" else: data = tmp[num:] + tmp[:num] tmp = "" if(data): print(data) else: print(tmp)
1
1,882,968,786,468
null
66
66
#!/usr/bin/env python3 import sys def input(): return sys.stdin.readline()[:-1] def main(): N = int(input()) ans = N // 2 if N % 2 == 0: ans -= 1 print(ans) if __name__ == '__main__': main()
S = input() L = len(S) for i in range((L-1)//2): if S[i] != S[L-1-i]: print("No") exit() for i in range((L-1)//4): if S[i] != S[(L-1)//2-1-i]: print("No") exit() for i in range(L-1, L - (L-1)//4, -1): if S[i] != S[i - (L-1)//2-1]: print("No") exit() print("Yes")
0
null
99,999,538,867,230
283
190
x,y=map(int,input().split()) dict={1:300000,2:200000,3:100000} if x==1 and y==1: print(1000000) else: if x<=3 and y<=3: print(dict[x]+dict[y]) elif x<=3: print(dict[x]) elif y<=3: print(dict[y]) else: print(0)
x, y = map(int, input().split(" ")) total = 0 rewards = {1: 300000, 2: 200000, 3: 100000} x1 = rewards[x] if (x <= 3) else 0 y1 = rewards[y] if (y <= 3) else 0 if (x == 1 and y == 1): total += 400000 if (x1 != None): total += x1 if (y1 != None): total += y1 print(total)
1
140,879,915,061,646
null
275
275
import sys from collections import Counter c = Counter() for line in sys.stdin.readlines(): c.update(line.lower()) for a in 'abcdefghijklmnopqrstuvwxyz': print a + ' :', c.get(a, 0)
N = int(input()) lsa = list(map(int,input().split())) a = 1 for i in range(N): if lsa[i] == a: a += 1 if a == 1: ans = -1 else: ans = N-(a-1) print(ans)
0
null
57,884,557,659,162
63
257
A, B, C, D = map(int, input().split()) ctr = 0 while True: if C <= 0: print("Yes") break if A <= 0: print("No") break if ctr % 2 == 0: C -= B else: A -= D ctr += 1
A, B, C, D = list(map(int, input().split())) import math if math.ceil(A / D) >= math.ceil(C / B): print('Yes') else: print('No')
1
29,906,600,637,410
null
164
164
A, B, C, K = map(int ,input().split()) Xa = min(K,A) K2 = K - Xa Xb = min(K2,B) Xc = K2 - Xb print(Xa - Xc)
a, b, c, k = map(int, input().split()) ans = 0 if k <= a: ans = k elif k <= a+b: ans = a else: ans = 2*a +b - k print(ans)
1
21,752,348,210,968
null
148
148
#!usr/bin/env python3 def string_two_numbers_spliter(): a, b = [int(i) for i in input().split()] return a, b def main(): a, b = string_two_numbers_spliter() if a < b: print('a < b') elif a > b: print('a > b') else: print('a == b') if __name__ == '__main__': main()
# encoding:utf-8 input = map(int, raw_input().split()) a, b = input if a == b: print("a == b") elif a > b: print("a > b") else: print("a < b")
1
358,920,605,342
null
38
38
def main(): h,n=map(int,input().split()) dp=[10**9]*(h+1) dp[h]=0 for i in range(n): a,b=map(int,input().split()) for j in range(h,0,-1): nxt=j-a if nxt<0: nxt=0 if dp[nxt]>dp[j]+b: dp[nxt]=dp[j]+b print(dp[0]) main()
H,N = map(int,input().split()) INF = 10 ** 10 dp = [INF] * (H + 1) dp[0] = 0 for i in range(N): attack,magic = map(int,input().split()) for j in range(len(dp)): if dp[j] == INF: continue target = j + attack if j + attack > H: target = H if dp[target] > dp[j] + magic: dp[target] = dp[j] + magic print(dp[-1])
1
81,578,581,784,932
null
229
229
N=int(input()) dp=[0]*(N+1) dp[0]=1 dp[1]=1 for i in range(2,N+1): dp[i]=dp[i-1]+dp[i-2] ans=dp[N] print(ans)
A=[0 for i in range(45)] A[0]=1 A[1]=1 for i in range(2,45): A[i]=A[i-1]+A[i-2] B=int(input()) print(A[B])
1
1,801,122,400
null
7
7
a = list(map(int, input().split())) if a[0]*500 < a[1]: print('No') else: print('Yes')
k, x = input().split() K = int(k) X = int(x) result = 500 * K if result >= X: print("Yes") else: print("No")
1
98,052,050,195,218
null
244
244
H, N = map(int, input().split()) A = [] B = [] for n in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) INF = float('inf') dp = [INF] * (H + max(A)) dp[0] = 0 # dp[i]を、HP iを減らすために必要な最小の魔力とする for hp in range(1, H+1): for n in range(N): dp[hp] = min(dp[max(hp-A[n],0)] + B[n], dp[hp]) print(dp[H])
from sys import stdin input = stdin.readline def main(): H, N = list(map(int, input().split())) A = [0]*N B = [0]*N for i in range(N): A[i], B[i] = map(int, input().split()) # dp = [[0]*(H+1) for _ in range(N+1)] dp = [0]*(H+1) for j in range(H+1): dp[j] = float('inf') dp[0] = 0 for i in range(1, N+1): for j in range(1, H+1): # dp[i][j] = dp[i-1][j] if j > A[i-1]: dp[j] = min(dp[j], dp[j-A[i-1]]+B[i-1]) else: dp[j] = min(dp[j], B[i-1]) # for i in range(N+1): # print(dp[i]) print(dp[H]) if(__name__ == '__main__'): main()
1
81,223,927,862,978
null
229
229
W,H,x,y,r=map(int,input().split()) print("Yes"*(r<=x<=W-r)*(r<=y<=H-r)or"No")
import sys ERROR_INPUT = 'input is invalid' ERROR_INPUT_NOT_UNIQUE = 'input is not unique' def main(): S = get_input1() T = get_input2() count = 0 for t in T: for s in S: if t == s: count += 1 break print(count) def get_input1(): n = int(input()) if n > 10000: print(ERROR_INPUT) sys.exit(1) li = [] for x in input().split(' '): if int(x) < 0 or int(x) > 10 ** 9: print(ERROR_INPUT) sys.exit(1) li.append(x) return li def get_input2(): n = int(input()) if n > 500: print(ERROR_INPUT) sys.exit(1) li = [] for x in input().split(' '): if int(x) < 0 or int(x) > 10 ** 9: print(ERROR_INPUT) sys.exit(1) elif int(x) in li: print(ERROR_INPUT_NOT_UNIQUE) sys.exit(1) li.append(x) return li main()
0
null
250,120,149,618
41
22
n = int(input()) point = [0, 0] for i in range(n): a, b = input().split() if a > b: point[0] += 3 elif a < b: point[1] += 3 else: point[0] += 1 point[1] += 1 print(*point)
# 使えるのは、'a' ~ 今まで使われた次の文字 n = int(input()) def dfs(cnt,s): if cnt == n: print(s) return biggest = 'a' c = 0 while c < len(s):# 最後はどこまで? if s[c] == biggest: biggest = chr(ord(biggest)+1) c += 1 else: c += 1 #print(c) for i in range(0,ord(biggest) - ord('a')+1): sc = chr(ord('a') + i) #print(sc) s += sc dfs(cnt + 1, s) s = s[:-1] dfs(0,"")
0
null
27,177,932,487,972
67
198
arg_01, arg_02, arg_03 = map(int,input().split()) if arg_01<arg_02<arg_03: print('Yes') else: print('No')
while(True): input = raw_input().split() a = int(input[0]) b = int(input[2]) if input[1] == "?": break elif input[1] == "+": print a + b elif input[1] == "-": print a - b elif input[1] == "*": print a * b elif input[1] == "/": print a / b
0
null
530,792,324,508
39
47
X=int(input()) A=0 B=0 for i in range(-120,120): for k in range(-120,120): if i**5==X+k**5: A=i B=k break print(A,B)
# 2020/09/18 # AtCoder Beginner Contest 150 - B # Input n = int(input()) s = input() cnt = 0 abc = 'ABC' # Calc for i in range(n-2): for j in range(3): if s[i+j] != abc[j]: break if j == 2: cnt = cnt + 1 # Output print(cnt)
0
null
62,755,220,804,640
156
245
W,H,x,y,r = (int(i) for i in input().split()) answer = "Yes" if x - r < 0 : answer = "No" elif y - r < 0 : answer = "No" elif x + r > W : answer = "No" elif y + r > H : answer = "No" print(answer)
W, H, x, y, r = map(int, input().split()) print( 'Yes' if r <= x <= W - r and r <= y <= H - r else 'No')
1
458,126,897,028
null
41
41
def shuffle(): h = int(input()) for i in range(h): s.append(s[0]) del s[0] while True: s = list(input()) if s == ['-']: break m = int(input()) for i in range(m): shuffle() print(''.join(s))
data = raw_input().split() #figure = [chr(i) for i in range(ord('0'), ord('9')+1)] stack = [] for i in range(len(data)): if data[i] == "+": stack[-2] = stack[-2] + stack[-1] del stack[-1] #print stack elif data[i] == "-": stack[-2] = stack[-2] - stack[-1] del stack[-1] #print stack elif data[i] == "*": stack[-2] = stack[-2] * stack[-1] del stack[-1] #print stack else: stack.append(int(data[i])) #print stack print stack[0]
0
null
988,175,716,416
66
18
S = list(input()) K = int(input()) #print(S) N=len(S) #if K==1: kosuu=[] cnt=1 for i in range(N-1): if S[i]==S[i+1]: cnt+=1 if i==N-2: kosuu.append(cnt) elif S[i]!=S[i+1]: kosuu.append(cnt) cnt=1 #print('kosuu', kosuu) dammy=0 for i in range(len(kosuu)): dammy+=kosuu[i]//2 #else: if K==1: out=dammy elif S[0]!=S[-1]: out = dammy * K elif len(S)==1: out=K//2 elif len(kosuu)==1: out=(kosuu[0]*K)//2 else: #kotei=kosuu[1:-1] #少ないとき kotei = dammy - kosuu[0]//2 - kosuu[-1]//2 aida = (kosuu[0] + kosuu[-1]) // 2 #print('aida',aida) out = kosuu[0]//2 + (kotei*K) + aida*(K-1) + kosuu[-1]//2 print(out)
def solve(S): pre = S[0] flag = False ans = 0 cnt = 0 for s in S[1:]: if flag: if pre == s: cnt += 1 else: ans += cnt // 2 cnt = 0 flag = False else: if pre == s: cnt += 2 flag = True pre = s if flag: ans += cnt // 2 return ans S = input() K = int(input()) if len(S) == 1: print(K // 2) elif len(S) == S.count(S[0]): print((len(S)*K)//2) else: if K == 1: print(solve(S)) elif K == 2: print(solve(S + S)) else: ans2 = solve(S + S) ans3 = solve(S + S + S) print(ans2 + (ans3-ans2)*(K - 2))
1
175,471,353,123,260
null
296
296
n=int(input()) a=list(map(int,input().split())) ans=[x for x in range(n)] for i in range(n): ans[(a[i] - 1)] = i + 1 for aaa in ans: print(aaa)
n,*a=map(int,open(0).read().split()) b=[0]*n for i in range(n): b[a[i]-1]=str(i+1) print(' '.join(b))
1
181,116,692,822,620
null
299
299
n=int(input()) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr ans=0 l=len(factorization(n)) s=factorization(n) for i in range(l): for j in range(1,1000): if s[i][1]>=j: ans+=1 s[i][1]-=j else: break if n==1: print(0) else: print(ans)
import itertools n = int(input()) ans = 0 def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def q(m): check = 0 while m >= check * (check + 1) / 2: check += 1 return check - 1 a = prime_factorize(n) gr = itertools.groupby(a) for key, group in gr: ans += q(len(list(group))) print(ans)
1
16,887,491,135,228
null
136
136
a = input() b = input().split() for i in b: i = int(i) b.reverse() c = " ".join(b) print(c)
n = int(raw_input()) num = map(int, raw_input().split()) num.reverse() print " ".join(map(str, num))
1
999,053,397,748
null
53
53
from sys import stdin import math s,t = stdin.readline().rstrip().split() print(t + s)
def ABC_149_A(): S,T = map(str, input().split()) print(T+S) if __name__ == '__main__': ABC_149_A()
1
103,298,496,945,308
null
248
248
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *D = map(int, read().split()) csum = accumulate(D) ans = sum(s * d for s, d in zip(csum, D[1:])) print(ans) return if __name__ == '__main__': main()
A,B,C,D=map(float,input().split()) E=(C-A)**2 F=(D-B)**2 print((float)(E+F)**(1/2))
0
null
84,450,827,735,702
292
29
S = ['S', 'H', 'C', 'D'] D = map(str, range(1, 14)) n = input() T = [tuple(raw_input().split()) for _ in xrange(n)] for t in [(s, d) for s in S for d in D]: if t not in T: print ' '.join(t)
card = [] suit = ["S","H","C","D"] for s in suit: for i in range(1,14): card.append(s + " " + str(i)) n = int(input()) for i in range(n): card.remove(input()) for c in card: print(c)
1
1,052,106,264,730
null
54
54
import sys input = sys.stdin.readline n,m = map(int,input().split()) a = [int(i) for i in input().split()] a = sorted(list(set(a))) from fractions import gcd lc = a[0] if n != 1: for num,i in enumerate(a[1:]): if lc == 0: break lc = lc * i // gcd(lc, i) if gcd(lc, i) == min(i,lc): for j in a[:num+1]: if (i/j)%2 == 0: lc = 0 break if lc == 0: print(0) else: print((m+lc//2)//lc)
from math import gcd from functools import reduce n,m=map(int,input().split()) lst=list(map(lambda x : int(x)//2,input().split())) divi=0 x=lst[0] while x%2==0: x//=2 divi+=1 for i in range(1,n): divi2=0 x=lst[i] while x%2==0: x//=2 divi2+=1 if divi!=divi2 : print(0) exit() work=reduce(lambda x,y: x*y//gcd(x,y),lst) print((m//work+1)//2)
1
101,597,930,325,722
null
247
247
N,K=map(int,input().split()) h=list(map(int, input().split())) A=0 for i in h: if i>=K: A=A+1 print(A)
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,K = map(int,readline().split()) H = list(map(int,readline().split())) ans = 0 for h in H: if h >= K: ans += 1 print(ans)
1
178,719,513,282,270
null
298
298
import heapq def main(): _ = int(input()) A = sorted(list(map(int, input().split())), reverse=True) q = [] heapq.heapify(q) ans = A[0] tmp_score = min(A[0], A[1]) heapq.heappush(q, (-tmp_score, A[0], A[1])) heapq.heappush(q, (-tmp_score, A[1], A[0])) for a in A[2:]: g = heapq.heappop(q) ans += -g[0] tmp_score1 = min(a, g[1]) tmp_push1 = (-tmp_score1, a, g[1]) tmp_score2 = min(a, g[2]) tmp_push2 = (-tmp_score2, a, g[2]) heapq.heappush(q, tmp_push1) heapq.heappush(q, tmp_push2) print(ans) if __name__ == '__main__': main()
import sys input=sys.stdin.readline import numpy as np from numpy.fft import rfft,irfft n,m=[int(j) for j in input().split()] l=np.array([int(j) for j in input().split()]) a=np.bincount(l) fft_len=1<<18 fft = np.fft.rfft ifft = np.fft.irfft Ff = fft(a,fft_len) x=np.rint(ifft(Ff * Ff,fft_len)).astype(np.int64) p=x.cumsum() i=np.searchsorted(p,n*n-m) q=n*n-m-p[i-1] ans=(x[:i]*np.arange(i,dtype=np.int64)).sum()+i*q print(int(l.sum()*2*n-ans))
0
null
58,641,246,994,408
111
252
def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) n,m,k=sep() a=lis() b=lis() from bisect import bisect_right a_c=[a[0]] b_c=[b[0]] for i in range(1,n): a_c.append(a_c[-1]+ a[i]) for i in range(1,m): b_c.append(b_c[-1] + b[i]) m=-1 m=max(m,bisect_right(b_c,k)) for i in range(n): if a_c[i]<=k: t=k-a_c[i] t2=bisect_right(b_c,t) m=max(i+1+t2,m) else: break print(max(0,m))
a,b,k = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) from itertools import accumulate A = list(accumulate(A)) B = list(accumulate(B)) A = [0] + A B = [0] + B ans = 0 num = b for i in range(a+1): if A[i] > k: continue while True : if A[i] + B[num] > k: num -=1 else: ans = max(ans,i+num) break print(ans)
1
10,795,319,904,332
null
117
117
import sys import numpy as np import math import collections from collections import deque from functools import reduce # input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) axor = 0 for ai in a: axor ^= ai ans = [] for ni in range(n): ans.append(str(axor ^ a[ni])) print(" ".join(ans))
N = int(input()) A=list(map(int,input().split())) sumxor=0 for i in range(N): sumxor=sumxor^A[i] for i in range(N): print(sumxor^A[i],"",end='') print()
1
12,500,705,314,958
null
123
123
n = int( raw_input( ) ) t = [ int( val ) for val in raw_input( ).rstrip( ).split( " " ) ] q = int( raw_input( ) ) s = [ int( val ) for val in raw_input( ).split( " " ) ] cnt = 0 for si in s: for ti in t: if si == ti: cnt += 1 break print( cnt )
ns = int(input()) s = list(map(int, input().split())) nt = int(input()) t = list(map(int, input().split())) count = 0 for i in t: # 配列に番兵を追加 s += [i] j = 0 while s[j] != i: j += 1 s.pop() if j == ns: continue count += 1 print(count)
1
68,363,719,490
null
22
22
n = input() A=[int(j) for j in input().split()] nums = [0,0,0] ans = 1 for a in A: ans = (ans*nums.count(a))%(10**9 +7) for i in range(len(nums)): if nums[i] == a: nums[i] = a+1 break print(ans)
MOD = 10**9 + 7 class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): return ( ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other) ) def __sub__(self, other): return ( ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other) ) def __mul__(self, other): return ( ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other) ) def __truediv__(self, other): return ( ModInt( self.x * pow(other.x, MOD - 2, MOD) ) if isinstance(other, ModInt) else ModInt(self.x * pow(other, MOD - 2, MOD)) ) def __pow__(self, other): return ( ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, MOD)) ) __radd__ = __add__ def __rsub__(self, other): return ( ModInt(other.x - self.x) if isinstance(other, ModInt) else ModInt(other - self.x) ) __rmul__ = __mul__ def __rtruediv__(self, other): return ( ModInt( other.x * pow(self.x, MOD - 2, MOD) ) if isinstance(other, ModInt) else ModInt(other * pow(self.x, MOD - 2, MOD)) ) def __rpow__(self, other): return ( ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(other, self.x, MOD)) ) def solve(N, A): ret = ModInt(1) count = [3 if not i else 0 for i in range(N + 1)] for a in A: ret *= count[a] if not ret: break count[a] -= 1 count[a + 1] += 1 return ret if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) print(solve(N, A))
1
130,439,347,362,630
null
268
268
import collections n=int(input()) data=[""]*n for i in range(n): data[i]=input() data=sorted(data) count=collections.Counter(data) num=max(count.values()) for v,k in count.items(): if k==num: print(v)
import collections N = int(input()) cnt = collections.defaultdict(int) for _ in range(N): s = input() cnt[s] += 1 max_v = max(cnt.values()) ans = sorted([k for k, v in cnt.items() if v == max_v]) for s in ans: print(s)
1
69,925,174,261,070
null
218
218
x = input().split() a, b, c =x d = int(a)+int(b)+int(c) if d<22: print("win") else: print("bust")
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(input()) X = input() cnt_init = X.count("1") x_init = int(X, 2) a = x_init % (cnt_init + 1) if cnt_init - 1 != 0: b = x_init % (cnt_init - 1) for i in range(n): if X[i] == "0": cnt = cnt_init + 1 x = (a + pow(2, (n - i - 1), cnt)) % cnt res = 1 else: cnt = cnt_init - 1 if cnt != 0: x = (b - pow(2, (n - i - 1), cnt)) % cnt res = 1 else: x = 0 res = 0 while x: cnt = bin(x).count("1") x %= cnt res += 1 print(res) if __name__ == '__main__': resolve()
0
null
63,709,886,844,780
260
107
s=input() n=int(input()) if len(s)==1:print(n//2);exit() if len(set(s))==1:print(len(s)*n//2);exit() c=1 l=[] for x in range(1,len(s)): if s[x-1]==s[x]: c+=1 if x==len(s)-1:l.append(c) else:l.append(c);c=1 t=0 if s[0]==s[-1] and l[0]%2==1 and l[-1]%2==1:t=n-1 print(sum([i//2 for i in l])*n+t)
from collections import Counter S1 = input() K = int(input()) S1C = Counter(S1) if len(S1C) == 1: print(len(S1) * K // 2) exit() start = S1[0] end = S1[-1] now = S1[0] a1 = 0 flag = False for s in S1[1:]: if flag: flag = False now = s continue else: if s == now: a1 += 1 flag = True now = s S2 = S1 + S1 start = S2[0] end = S2[-1] now = S2[0] a2 = 0 flag = False for s in S2[1:]: if flag: flag = False now = s continue else: if s == now: a2 += 1 flag = True now = s b = a2 - 2 * a1 print(a1 * K + b * (K-1))
1
175,482,987,185,184
null
296
296
N = int(input()) A = list(map(int, input().split())) MAX = max(A) # remap AR = [0] * (MAX+1) V = [False] * (MAX+1) for i in range(N): AR[A[i]] += 1 pairwise, setwise = True, True # sieve for i in range(2, MAX+1): if V[i]: continue cnt, j = 0, i while j < MAX+1: cnt += AR[j] V[j] = True j += i if cnt > 1: pairwise = False if cnt == len(A): setwise = False if pairwise: print('pairwise coprime') elif setwise: print('setwise coprime') else: print('not coprime')
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10 from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def debug(*args): if debugmode: print(*args) def input(): return sys.stdin.readline().strip() def STR(): return input() def INT(): return int(input()) def FLOAT(): return float(input()) def MAP(): return map(int, input().split()) def S_MAP(): return map(str, input().split()) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 9) inf = sys.maxsize mod = 10 ** 9 + 7 dx = [0, 0, 1, -1, 1, -1, -1, 1] dy = [1, -1, 0, 0, 1, -1, 1, -1] debugmode = True n = INT() a = LIST() arr = [0 for _ in range(n)] arr[0] = a[0] for i in range(1, n): arr[i] = arr[i - 1] + a[i] s = arr[-1] mn = inf for i in range(n): mn = min(mn, abs(s / 2 - arr[i])) print(int(mn * 2))
0
null
72,947,457,359,152
85
276
n = int(raw_input()) print '', for i in range(1, n+1): if i % 3 == 0: print '%s' % i, elif '3' in str(i): print '%s' % i,
def az11(): n, xs = int(input()), map(int,raw_input().split()) print min(xs), max(xs), sum(xs) az11()
0
null
807,767,825,372
52
48
n=int(input()) def prime(n): dic={} f=2 m=n while f*f<=m: r=0 while n%f==0: n//=f r+=1 if r>0: dic[f]=r f+=1 if n!=1: dic[n]=1 return dic def counter(dic): ans=0 for val in dic.values(): i=1 while i*(i+3)/2<val: i+=1 ans+=i return ans print(counter(prime(n)))
def main(): n = int(input()) bit = input()[::-1] count = bit.count("1") count_plus = count+1 count_minus = count-1 pow_plus = [1 % count_plus] for i in range(n): pow_plus.append(pow_plus[-1]*2 % count_plus) if count_minus != 0: pow_minus = [1 % count_minus] for i in range(n): pow_minus.append(pow_minus[-1]*2 % count_minus) else: pow_minus = [] bit_plus = 0 bit_minus = 0 for i in range(n): if bit[i] == "1": bit_plus = (bit_plus+pow_plus[i]) % count_plus if count_minus != 0: for i in range(n): if bit[i] == "1": bit_minus = (bit_minus+pow_minus[i]) % count_minus ans = [] for i in range(n): if bit[i] == "1": if count_minus == 0: ans.append(0) continue bit_ans = (bit_minus-pow_minus[i]) % count_minus count = count_minus else: bit_ans = (bit_plus+pow_plus[i]) % count_plus count = count_plus cnt = 1 while bit_ans: b = str(bin(bit_ans)).count("1") bit_ans = bit_ans % b cnt += 1 ans.append(cnt) for i in ans[::-1]: print(i) main()
0
null
12,576,284,341,152
136
107
a, b, m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) li = [list(map(int,input().split())) for i in range(m)] kouho = [min(a)+min(b)] for l in li: kouho.append(a[l[0]-1] + b[l[1]-1] -l[2]) print(min(kouho))
import sys a = [] n, m = map(int, input().split()) for i in range(n): ai = list(map(int, input().split())) ai.append(sum(ai)) a.append(ai) for i in range(n): print(" ".join(list(map(str, a[i])))) ai = [] for j in range(m + 1): s = 0 for i in range(n): s += a[i][j] ai.append(s) print(" ".join(list(map(str, ai))))
0
null
27,534,077,450,362
200
59
l=sorted(map(int,raw_input().split())) print l[0], l[1], l[2]
import sys l = [int(i) for i in sys.stdin.readline().split()] l.sort() print(" ".join(map(str, l)))
1
422,313,956,932
null
40
40
def main(): N, M, K = map(int, input().split()) MOD = 998244353 fac = [0] * 10 ** 6 inv = [0] * 10 ** 6 finv = [0] * 10 ** 6 def COM_init(): fac[0] = 1 fac[1] = 1 inv[1] = 1 finv[0] = 1 finv[1] = 1 for i in range(2, 2 * 10**5 +10): fac[i] = fac[i-1] * i % MOD inv[i] = -inv[MOD%i] * (MOD//i) % MOD finv[i] = finv[i-1]*inv[i]%MOD def COM(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[n-k] * finv[k] % MOD) % MOD COM_init() ans = 0 for i in range(K+1): ans += M * pow(M-1, N-i-1, MOD) * COM(N-1, i) ans %= MOD print(ans) if __name__ == "__main__": main()
if __name__ == '__main__': M=998244353 n,m,k=map(int,input().split()) p,c=[m],[1] for i in range(1,n): p+=[p[-1]*(m-1)%M] c+=[c[-1]*(n-i)*pow(i,-1,M)%M] print(sum(p[n-i-1]*c[i] for i in range(k+1))%M)
1
23,310,818,924,330
null
151
151
n, m = [int (x) for x in input().split(' ')] a = [[0 for i in range(m)] for j in range(n)] b = [0 for i in range(m)] c = [0 for i in range(n)] for s in range(0,n): a[s] = [int (x) for x in input().split(' ')] for s in range(0,m): b[s] = int(input()) for s in range(0,n): for t in range(0,m): c[s] += a[s][t] * b[t] for t in range(0,n): print("%d" % c[t])
# coding:utf-8 array = map(int, raw_input().split()) n = array[0] m = array[1] a = [[0 for i in range(m)] for j in range(n)] b = [0 for i in range(m)] answer = [0 for i in range(n)] for i in range(n): a[i] = map(int, raw_input().split()) for j in range(m): b[j] = input() for i in range(n): for j in range(m): answer[i] += a[i][j] * b[j] for i in range(n): print answer[i]
1
1,178,071,084,610
null
56
56
#!/usr/bin/env python def GCD(x,y): while y!=0: tmp=y y=x%y x=tmp return x if __name__ == "__main__": x,y=list(map(int,input().split())) if x<y: tmp=x x=y y=tmp print(GCD(x,y))
#coding:UTF-8 def GCD(x,y): d=0 if x < y: d=y y=x x=d if y==0: print(x) else: GCD(y,x%y) if __name__=="__main__": a=input() x=int(a.split(" ")[0]) y=int(a.split(" ")[1]) GCD(x,y)
1
8,500,554,682
null
11
11
while True: a = input() b = a.split(' ') H = int(b[0]) W = int(b[1]) if H == 0 and W == 0: break elif H % 2 == 0: for i in range(H//2): if W % 2 == 0: print('#.'*int(W//2)) print('.#'*int(W//2)) elif W % 2 == 1: print('#.'*int((W-1)//2)+'#') print('.#'*int((W-1)//2)+'.') elif H % 2 == 1: for e in range((H-1)//2): if W % 2 == 0: print('#.'*int(W//2)) print('.#'*int(W//2)) elif W % 2 == 1: print('#.'*int((W-1)//2)+'#') print('.#'*int((W-1)//2)+'.') if W % 2 == 0: print('#.'*int(W//2)) elif W % 2 == 1: print('#.'*int((W-1)//2)+'#') print()
H = 1 W = 1 while H and W: H, W = input().split() H = int(H) W = int(W) if H == 0\ and W == 0: break for h in range(H): for w in range(W): if h % 2 and w % 2\ or h % 2 == 0 and w % 2 == 0: print("#", end = "") else: print(".", end = "") if w == W - 1: print() print()
1
865,430,494,460
null
51
51
n = int(input()) a = [int(i) for i in input().split()] print(' '.join(map(str, reversed(a))))
# -*- coding: utf-8 -*- 'import sys' input() a=[int(i) for i in input().split()] a.reverse() f=0 for i in range(len(a)): if f: print(" ",end="") print("{}".format(a[i]),end="") f=1 print("")
1
997,377,558,580
null
53
53
n=int(input()) xy=[list(map(int, input().split())) for i in range(n)] z=list(map(lambda x: x[0]+x[1], xy)) w=list(map(lambda x: x[0]-x[1], xy)) print(max(max(z)-min(z), max(w)-min(w)))
n = int(input()) xy_array = [list(map(int, input().split())) for _ in range(n)] th = pow(10, 9) z_max = -th z_min = th w_max = -th w_min = th for x, y in xy_array: z_max = max(x + y, z_max) z_min = min(x + y, z_min) w_max = max(x - y, w_max) w_min = min(x - y, w_min) ans = max(z_max - z_min, w_max - w_min) print(ans)
1
3,407,020,263,972
null
80
80
n = int(input()) print(sum((n - 1) // i for i in range(1, n)))
N = int(input()) count = 0 for A in range(1, N): N_ = (N - 1) // A count += N_ print(count)
1
2,595,639,843,070
null
73
73
x,n=map(int,input().split()) *p,=map(int,input().split()) q=[0]*(102) for pp in p: q[pp]=1 diff=1000 ans=-1 for i in range(0,102): if q[i]: continue cdiff=abs(i-x) if cdiff<diff: diff=cdiff ans=i print(ans)
x,n=[int(x) for x in input().split()] if n!=0: p=[int(x) for x in input().split()] l=list(range(110)) for i in p: l.remove(i) L=[] for i in l: L.append(abs(i-x)) m=min(L) print(l[L.index(m)]) else: print(x)
1
14,053,515,712,518
null
128
128
n = int(input()) ab=[list(map(int,input().split())) for i in range(n)] import math from collections import defaultdict d = defaultdict(int) zerozero=0 azero=0 bzero=0 for tmp in ab: a,b=tmp if a==0 and b==0: zerozero+=1 continue if a==0: azero+=1 continue if b==0: bzero+=1 continue absa=abs(a) absb=abs(b) gcd = math.gcd(absa,absb) absa//=gcd absb//=gcd if a*b >0: d[(absa,absb)]+=1 else: d[(absa,-absb)]+=1 found = defaultdict(int) d[(0,1)]=azero d[(1,0)]=bzero ans=1 mod=1000000007 for k in list(d.keys()): num = d[k] a,b=k if b>0: bad_ab = (b,-a) else: bad_ab = (-b,a) if found[k]!=0: continue found[bad_ab] = 1 bm=d[bad_ab] if bm == 0: mul = pow(2,num,mod) if k==bad_ab: mul = num+1 else: mul = pow(2,num,mod) + pow(2,bm,mod) -1 ans*=mul ans+=zerozero ans-=1 print(ans%mod)
from itertools import groupby from statistics import median from sys import exit N = int(input()) line = ([(index, v) for index, v in enumerate(input())]) def types(line): return line[1] def index(line): return line[0] gp = groupby(sorted(line, key=types), types) d = {} for k, v in gp: indexes = set([i for i, value in v]) d[k] = indexes if 'R' not in d or 'G' not in d or 'B' not in d: print(0) exit() delete = 0 for differ in range(1, N): for start in range(N): if start + differ*2 > N - 1: break i = line[start] j = line[start + differ] k = line[start + differ*2] if len({i[1], j[1], k[1]}) != 3: continue upper = max(i[0], j[0], k[0]) lower = min(i[0], j[0], k[0]) median_num = median([i[0], j[0], k[0]]) if upper - median_num == median_num - lower: delete += 1 print(len(d['R']) * len(d['G']) * len(d['B']) - delete)
0
null
28,578,168,562,592
146
175
A, B = [x for x in input().split(" ")] print(int(A) * int(float(B) * 100 + 0.5) // 100)
import sys read = sys.stdin.read #readlines = sys.stdin.readlines from math import ceil def main(): n = tuple(map(int, tuple(input()))) if sum(n) % 9 == 0: print('Yes') else: print('No') if __name__ == '__main__': main()
0
null
10,425,409,871,708
135
87
n, m = map(int, input().split()) a = [int(x) for x in input().split()] s = sum(a) print('Yes' if len(list(filter(lambda x : x >= s * (1/(4*m)), a))) >= m else 'No')
if __name__ == '__main__': N, M = map(int, input().split()) A = list(map(int, input().split())) total = sum(A) threshold = total / (4*M) count = sum([a>=threshold for a in A]) if count >= M: print('Yes') else: print('No')
1
38,637,891,129,560
null
179
179
n = int(input()) al = list(map(int, input().split())) ail = [] for i,a in enumerate(al): ail.append((a,i+1)) ail.sort() ans = [] for i,a in ail: ans.append(a) print(*ans)
# C N = int(input()) # A = list(map(int, input().split())) order_number = {} for num, order in enumerate(map(int, input().split())): order_number[num+1] = order for order, number in sorted(order_number.items(), key=lambda x: x[1]): print(order, end=" ") print()
1
181,201,093,115,810
null
299
299
h,w=map(int,input().split()) g=[[*input()] for _ in range(h)] from collections import * def bfs(sx,sy): d=[[-1]*w for _ in range(h)] d[sx][sy]=0 q=deque([(sx,sy)]) while q: x,y=q.popleft() t=d[x][y]+1 for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]: nx,ny=x+dx,y+dy if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0: d[nx][ny]=t q.append((nx,ny)) return d import numpy as np a=0 for sx in range(h): for sy in range(w): if g[sx][sy]=='#': continue a=max(a,np.max(bfs(sx,sy))) print(a)
n=int(input()) l=[list(map(int,input().split())) for i in range(n)] s=[] for i in range(n): if l[i][0]==l[i][1]: s.append(1) else: s.append(0) g=[] for i in range(n-2): g.append(s[i]*s[i+1]*s[i+2]) ok=0 for i in range(n-2): if g[i]==1: ok=1 break if ok==1: print("Yes") else: print("No")
0
null
48,387,016,140,958
241
72
import sys if sys.argv[-1] == 'ONLINE_JUDGE': import os import re with open(__file__) as f: source = f.read().split('###''nbacl') for s in source[1:]: s = re.sub("'''.*", '', s) sp = s.split(maxsplit=1) if os.path.dirname(sp[0]): os.makedirs(os.path.dirname(sp[0]), exist_ok=True) with open(sp[0], 'w') as f: f.write(sp[1]) from nbmodule import cc cc.compile() import numpy as np from numpy import int64 from nbmodule import solve f = open(0) N, M = [int(x) for x in f.readline().split()] AB = np.fromstring(f.read(), dtype=int64, sep=' ').reshape((-1, 2)) ans = solve(N, AB) print(ans) ''' ###nbacl nbmodule.py import numpy as np from numpy import int64 from numba import njit from numba.types import i8 from numba.pycc import CC import nbacl.dsu as dsu cc = CC('nbmodule') @cc.export('solve', (i8, i8[:, ::1])) def solve(N, AB): t = np.full(N, -1, dtype=int64) for i in range(AB.shape[0]): dsu.merge(t, AB[i, 0] - 1, AB[i, 1] - 1) ret = 0 for _ in dsu.groups(t): ret += 1 return ret - 1 if __name__ == '__main__': cc.compile() ###nbacl nbacl/dsu.py import numpy as np from numpy import int64 from numba import njit @njit def dsu(t): t = -1 @njit def merge(t, x, y): u = leader(t, x) v = leader(t, y) if u == v: return u if -t[u] < -t[v]: u, v = v, u t[u] += t[v] t[v] = u return u @njit def same(t, x, y): return leader(t, x) == leader(t, y) @njit def leader(t, x): if t[x] < 0: return x t[x] = leader(t, t[x]) return t[x] @njit def size(t, x): return -t[leader(t, x)] @njit def groups(t): for i in range(t.shape[0]): if t[i] < 0: yield i '''
# -*- coding: utf-8 -*- def resolve(T,v): lv = v while lv != T[lv]: lv = T[lv] T[v] = lv return lv def solve(): N, M = map(int, input().split()) T = list(range(N+1)) for i in range(M): u, v = map(int, input().split()) lu = resolve(T,u) lv = resolve(T,v) if lv == lu: continue T[lv] = lu #print(f'===round{i}===') #print(T) #print([resolve(T,v) for v in range(N+1)]) return len(set(resolve(T,v) for v in range(1,N+1)))-1 if __name__ == '__main__': print(solve())
1
2,310,957,481,120
null
70
70
# -*- coding: utf-8 -*- import functools @functools.lru_cache(maxsize=None) def fib(n): if n <= 1: return 1 else: return fib(n - 1) + fib(n - 2) if __name__ == '__main__': n = int(input()) print(fib(n))
N = int(input()) A_lis = list(map(int,input().split())) ls = [0] * N for i in range(N-1): ls[A_lis[i]-1] += 1 for a in ls: print(a)
0
null
16,386,035,661,798
7
169
n,p = map(int,input().split()) s = input() l = [0 for i in range(p)] l[0] = 1 ten = 1 cnt = 0 ans = 0 if p == 2 or p == 5: for i in range(n): if int(s[i]) % p == 0: ans += i+1 else: for i in range(n): cnt = (cnt + int(s[-i-1]) * ten) % p l[cnt] += 1 ten = (ten * 10) % p for i in l: if i > 1: ans += i * (i - 1) // 2 print(ans)
N = int(input()) sum = N + N**2 + N**3 print(sum)
0
null
34,194,084,851,864
205
115
import sys sys.setrecursionlimit(10**7) def MI(): return map(int,sys.stdin.readline().rstrip().split()) class UnionFind: def __init__(self,n): self.par = [i for i in range(n+1)] # 親のノード番号 self.rank = [0]*(n+1) def find(self,x): # xの根のノード番号 if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def same_check(self,x,y): # x,yが同じグループか否か return self.find(x) == self.find(y) def unite(self,x,y): # x,yの属するグループの併合 x = self.find(x) y = self.find(y) if self.rank[x] < self.rank[y]: x,y = y,x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x N,M = MI() UF = UnionFind(N) for _ in range(M): a,b = MI() UF.unite(a,b) A = UF.par A = [UF.find(A[i]) for i in range(1,N+1)] print(len(set(A))-1)
from collections import deque N,M = map(int,input().split()) l = [[] for _ in range(N+1)] for _ in range(M): a,b = map(int,input().split()) l[a].append(b) l[b].append(a) check = [0]*(N+1) cnt = 0 for i in range(1,N+1): if check[i] == 1: continue st = deque([i]) check[i] = 1 while st: s = st.popleft() for t in l[s]: if check[t] == 0: check[t] = 1 st.append(t) continue cnt += 1 print(cnt-1)
1
2,286,641,264,406
null
70
70
n = int(input()) A = list(map(int, input().split())) cumsum = [[0 for j in range(2)] for i in range(60)] ans = [0] * 60 #print(cumsum) for i in range(len(A) - 1, -1, -1): plus_num = A[i] bit_num = format(plus_num, "060b") #print(bit_num) for i, bit in enumerate(bit_num): bit = int(bit) if bit == 0: ans[i] += cumsum[i][1] else: ans[i] += cumsum[i][0] cumsum[i][bit] += 1 #print(ans) #print(cumsum) ans_num = 0 mod = 10**9 + 7 for i, cnt in enumerate(ans): ans_num += 2**(59-i) * cnt ans_num %= mod print(ans_num)
import numpy as np n = int(input()) a = list(map(int,input().split())) mod = 10**9+7 ans = 0 a=np.array(a) for i in range(60): keta = a>>i & 1 num1 = int(keta.sum()) num0 = n - num1 ans+= ((2**i)%mod)*(num1*num0) ans%=mod print(ans)
1
123,423,685,968,660
null
263
263
import itertools N = int(input()) c = [] d = 0 for i in range(N): x1, y1 = map(int, input().split()) c.append((x1,y1)) cp = list(itertools.permutations(c)) x = len(cp) for i in range(x): for j in range(N-1): d += ((cp[i][j][0]-cp[i][j+1][0])**2 + (cp[i][j][1] - cp[i][j+1][1])**2)**0.5 print(d/x)
bingoSheet = [0 for x in range(9)] for i in range(3): bingoRow = input().split() for j in range(3): bingoSheet[i*3 + j] = int(bingoRow[j]) bingoCount = int(input()) responses = [] for i in range(bingoCount): responses.append(int(input())) hasBingo = False step = 1 initialIndex = 0 for i in range(3): firstIndex = i*3 subList = [bingoSheet[index] for index in [firstIndex, firstIndex+1, firstIndex+2]] if (all(elem in responses for elem in subList)): hasBingo = True break for i in range(3): firstIndex = i subList = [bingoSheet[index] for index in [firstIndex, firstIndex+3, firstIndex+6]] if (all(elem in responses for elem in subList)): hasBingo = True break subList = [bingoSheet[index] for index in [0, 4, 8]] if (all(elem in responses for elem in subList)): hasBingo = True subList = [bingoSheet[index] for index in [2, 4, 6]] if (all(elem in responses for elem in subList)): hasBingo = True if hasBingo: print('Yes') quit() print('No') quit()
0
null
104,281,465,955,600
280
207
N=int(input());M=N//500;M*=1000;X=500*(N//500);N-=X;M+=(N//5)*5;print(M)
n = int(input()) s = str(input()) new_s = s[0] for i in range(1,len(s)): if s[i] == s[i-1]: continue else: new_s += s[i] print(len(new_s))
0
null
106,509,031,767,962
185
293
NN = input().split() N = int(NN[0]) K = int(NN[1]) LL = input().split() list1 =[] for i in LL: list1.append(int(i)) list1.sort() total = 0 for i in range(K): total += list1[i] print(total)
col,row = map(int,input().split()) matrix = [] vector = [] for _ in range(col): matrix.append([int(j) for j in input().split()]) for _ in range(row): vector.append(int(input())) for i in range(col): ans = 0 for x,y in zip(matrix[i],vector): ans += x * y print(ans)
0
null
6,450,647,814,832
120
56
from random import * D=int(input()) C=list(map(int,input().split())) S=[list(map(int,input().split())) for i in range(D)] X=[0]*26 XX=X[:] Y=X[:] YY=X[:] P=[] SC=0 N,M,L,O=0,0,0,0 for i in range(D): for j in range(26): X[j]+=C[j] XX[j]+=X[j] N,M=-1,-10**20 L,O=N,M for j in range(26): if Y==-1: N,M=0,X[0]+S[i][0] if M<X[j]+S[i][j]: L,O=N,M N,M=j,X[j]+S[i][j] elif O<X[j]+S[i][j]: L,O=j,X[j]+S[i][j] XX[N]-=X[N] X[N]=0 P.append([N,L]) SC+=X[N] SC2=0 for i in range(10**5): SC2=SC d,q=randrange(0,D),randrange(0,26) SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX) or randrange(0,1000)==0: P[d][0]=q XX=YY[:] SC=SC2 for d in range(D): for q in range(26): SC2=SC SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d][0]=q XX=YY[:] SC=SC2 for i in range(D): SC2=SC d,q=i,P[i][1] SC2-=S[d][P[d][0]] SC2+=S[d][q] for j in range(26): Y[j]=0 YY[P[d][0]],YY[q]=0,0 for j in range(D): if j==d: Z=q else: Z=P[j][0] Y[P[d][0]]+=C[P[d][0]] Y[q]+=C[q] Y[Z]=0 YY[P[d][0]]+=Y[P[d][0]] YY[q]+=Y[q] if SC2-sum(YY)>=SC-sum(XX): P[d]=P[d][::-1] XX=YY[:] SC=SC2 for i in range(D): print(P[i][0]+1)
# -*- coding: utf-8 -*- import sys import math from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop, heappush import itertools import random from decimal import * input = sys.stdin.readline def inputInt(): return int(input()) def inputMap(): return map(int, input().split()) def inputList(): return list(map(int, input().split())) def inputStr(): return input()[:-1] inf = float('inf') mod = 1000000007 #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- def main(): D = inputInt() C = inputList() S = [] for i in range(D): s = inputList() S.append(s) ans1 = [] ans2 = [] for i in range(D): bestSco1 = 0 bestSco2 = 0 bestI1 = 1 bestI2 = 1 for j,val in enumerate(S[i]): if j == 0: tmpAns = ans1 + [j+1] tmpSco = findScore(tmpAns, S, C) if bestSco1 < tmpSco: bestSco2 = bestSco1 bestI2 = bestI1 bestSco1 = tmpSco bestI1 = j+1 else: tmpAns1 = ans1 + [j+1] tmpAns2 = ans2 + [j+1] tmpSco1 = findScore(tmpAns1, S, C) tmpSco2 = findScore(tmpAns2, S, C) if bestSco1 < tmpSco1: bestSco2 = bestSco1 bestI2 = bestI1 bestSco1 = tmpSco1 bestI1 = j+1 if bestSco1 < tmpSco2: bestSco2 = bestSco1 bestI2 = bestI1 bestSco1 = tmpSco2 bestI1 = j+1 ans1.append(bestI1) ans2.append(bestI2) for i in ans1: print(i) def findScore(ans, S, C): scezhu = [inf for i in range(26)] sco = 0 for i,val in enumerate(ans): tmp = S[i][val-1] scezhu[val-1] = i mins = 0 for j,vol in enumerate(C): if scezhu[j] == inf: mins = mins + (vol * (i+1)) else: mins = mins + (vol * ((i+1)-(scezhu[j]+1))) tmp -= mins sco += tmp return sco #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- #-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- if __name__ == "__main__": main()
1
9,616,824,259,478
null
113
113
N = int(input()) A = list(map(int,input().split())) di = {} for i in range(N): if A[i] in di: di[A[i]] += 1 else: di[A[i]] = 1 if max(di.values()) != 1: print("NO") else: print("YES")
N = int(input()) d = {} ans = [] for i in range(N): S = input() d.setdefault(S,0) d[S] += 1 max = max(d.values()) for key in d.keys(): if d[key] == max: ans.append(key) ans = sorted(ans) for word in ans: print(word)
0
null
71,639,853,111,690
222
218
from decimal import Decimal x = int(input()) money = 100 ans = 0 while 1: ans += 1 money = money + int(money * Decimal(str(0.01))) if money >= x: print(ans) exit()
def main(): n = int(input()) print(b(n)) def b(n: int) -> int: m = 100 i = 0 while True: m = m * 101 // 100 i += 1 if m >= n: break return i if __name__ == '__main__': main()
1
26,903,171,536,920
null
159
159
N = int(input()) aaa = list(map(int, input().split())) i = 1 ans = 0 for a in aaa: if a == i: i += 1 else: ans += 1 print(ans if ans != N else -1)
n = input() renga = list(map(int, input().split(" "))) ni = 1 remains = 0 for r in renga: if ni == r: ni += 1 remains += 1 if ni == 1: print(-1) else: print(len(renga) - remains)
1
114,855,273,566,980
null
257
257
#coding:utf-8 i = input() q = [] for n in range(i): l = map(int, raw_input(). split()) a = min(l) l.remove(min(l)) b = min(l) c = max(l) if a ** 2 + b ** 2 == c ** 2: q.append("YES") else: q.append("NO") for s in xrange(len(q)): print(q[0]) q.pop(0)
n=int(input()) for i in range(n): x=list(map(int,input().split())) a,b,c=sorted(x) if a**2+b**2==c**2: print('YES') else: print('NO')
1
298,333,112
null
4
4
import sys input = sys.stdin.buffer.readline from collections import defaultdict def main(): N,K = map(int,input().split()) a = list(map(int,input().split())) d = defaultdict(int) cum = [0] for i in range(N): cum.append((cum[-1]+a[i]-1)%K) ans = 0 for i in range(N+1): ans += d[cum[i]] d[cum[i]] += 1 if i >= K-1: d[cum[i-K+1]] -= 1 print(ans) if __name__ == "__main__": main()
import sys from collections import Counter from itertools import accumulate read = sys.stdin.read N, K, *A = map(int, read().split()) a = list(accumulate([0] + A)) a = [(a[i] - i) % K for i in range(N + 1)] answer = 0 if N < K: for i in Counter(a).values(): answer += i * (i - 1) // 2 else: dic = Counter(a[:K]) for i in dic.values(): answer += i * (i - 1) // 2 here = K for i, x in enumerate(a[K:]): dic[a[i]] -= 1 answer += dic[x] dic[x] += 1 print(answer)
1
137,646,408,070,358
null
273
273
A, B, C = map(int, input().split()) if A == B == C or A != B and B != C and A != C: print("No") else: print("Yes")
a = map(int, input().split()) res = "No" if len(set(a)) == 2: res = "Yes" print(res)
1
68,011,983,128,668
null
216
216
import sys N,K = map(int,input().split()) H = sorted(list(map(int,input().split())),reverse = True) for i in range(N): if not H[i] >= K: print(i) sys.exit() print(N)
mem_num, over_height = map(int, input().split()) members_hgt = list(map(int, input().split())) cnt = 0 for i in members_hgt: if i >= over_height: cnt += 1 print(cnt)
1
179,062,147,507,584
null
298
298