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
W = input() counter = 0 T = [] while True: string = input() if string == "END_OF_TEXT": break else: T.append(string) for i in range(len(T)): memo = T[i].split() for j in range(len(memo)): if memo[j].lower() == W: counter += 1 print(counter)
w = input().lower() n = 0 while True: t = input() if t == 'END_OF_TEXT': break n += t.lower().split().count(w) print(n)
1
1,842,398,229,280
null
65
65
#A S=input() T=input() ans='No' if S != T: if S==T[:(len(S))]: if T[-1].islower(): ans='Yes' print(ans)
def main(): A = int(input()) B = int(input()) ans = 6 - A - B print(ans) if __name__ == "__main__": main()
0
null
66,425,948,749,860
147
254
H,W=map(int,input().split()) S=[input() for _ in range(H)] ans=float("inf") counter=[[999]*W for _ in range(H)] def search(i,j,count): global ans if counter[i][j]!=999: ans=min(ans,count+counter[i][j]) return(counter[i][j]) dist=999 if i==H-1 and j==W-1: ans=min(ans,count) return 0 countj=count counti=count if j<W-1: if S[i][j]=="." and S[i][j+1]=="#": countj+=1 dist=search(i,j+1,countj) + (S[i][j]=="." and S[i][j+1]=="#") if i<H-1: if S[i][j]=="." and S[i+1][j]=="#": counti+=1 dist=min(dist,search(i+1,j,counti)+(S[i][j]=="." and S[i+1][j]=="#")) counter[i][j]=dist return dist search(0,0,(S[0][0]=="#")*1) print(ans)
import sys input = sys.stdin.readline H, W = map(int, input().split()) s = [input().rstrip() for _ in range(H)] dp = [[1000]*W for _ in range(H)] if s[0][0] == '#': dp[0][0] = 1 else: dp[0][0] = 0 for j in range(W): for i in range(H): if i <= H - 2: if s[i][j] == '.' and s[i+1][j] == '#': dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1) else: dp[i+1][j] = min(dp[i+1][j], dp[i][j]) if j <= W - 2: if s[i][j] == '.' and s[i][j+1] == '#': dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1) else: dp[i][j+1] = min(dp[i][j+1], dp[i][j]) print(dp[H-1][W-1])
1
49,602,581,871,100
null
194
194
print(input()[1] == "B" and "ARC" or "ABC")
def shuffle(word, length): li = list(word) ad = li[0:length] li += ad del li[0:length] return ''.join(li) while True: str = input() if str == '-': break num = int(input()) for i in range(num): rn = int(input()) str = shuffle(str, rn) print(str)
0
null
13,136,608,510,320
153
66
print((lambda x:int(x[1])+max(0,100*(10-int(x[0]))))(input().split()))
import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): A,B=mi() print(max(0,A-2*B)) if __name__ == "__main__": main()
0
null
114,479,170,612,230
211
291
n = int(input()) s = input() ans = 0 for pin in range(10**3): str_pin = str(pin) str_pin = str_pin.zfill(3) nex = 0 for i in range(n): searching_for = str_pin[nex] now_s = s[i] if searching_for == now_s: nex += 1 if nex == 3: ans += 1 break print(ans)
n = int(input()) s = input() cnt = 0 for i in range(1000): c = [i // 100, (i // 10) % 10, i % 10] f = 0 for j in range(n): if s[j] == str(c[f]): f+=1 if f == 3: break if f == 3: cnt += 1 print(cnt)
1
129,092,760,269,900
null
267
267
k = int(input()) s = input() l = len(s) if l > k: print(s[0:k] + '...') else: print(s)
n=int(input()) a=list(map(int,input().strip().split()))[:n] counter=0 for i in range (0,n,2): if(a[i]%2==1): counter+=1 print(counter)
0
null
13,670,990,483,910
143
105
n,x,m = map(int,input().split()) mod = m ans = 0 bit = [-1 for i in range(m)] cycle = False for i in range(n): if i == 0 : a = x bit[a] = i ans += a else: a = (a**2)% mod if bit[a] != -1: cy_st = bit[a] cy_fi = i -1 cycle = True break else: bit[a] = i ans += a if cycle: ans2 = 0 b = -1 for j in range(cy_st): if j == 0 : b = x ans2 += b else: b = (b**2)% mod ans2 += b cy_num = ans - ans2 cy_repe = (n-cy_st) // (cy_fi - cy_st + 1) ans3 = cy_num * cy_repe cy_amari = (n-cy_st) % (cy_fi - cy_st + 1) if b == -1: for j in range(cy_amari): if j == 0 : b = x ans3 += b else: b = (b**2)% mod ans3 += b else: for i in range(cy_amari): b = (b**2)% mod ans3 += b print(ans2+ans3) else: print(ans)
d,t,s = map(int, input().split()) if(d-t*s>0): print("No") else: print("Yes")
0
null
3,204,417,437,440
75
81
from fractions import gcd def lcm(a,b): return a*b//gcd(a,b) n,m=map(int,input().split()) a=list(map(int,input().split())) h=list(map(lambda x:x//2,a)) l=1 for i in range(n): l=lcm(l,h[i]) for i in range(n): if (l//h[i])%2==0: print(0) exit() print((m//l+1)//2)
n = int(input()) Tp = 0 Hp = 0 tmp = "abcdefghijklmnopqrstuvwxyz" alph = list(tmp) for i in range(n): Ta,Ha = input().split() lTa = list(Ta) lHa = list(Ha) num = 0 if (len(Ta) <= len(Ha)): #definition of num num = len(Ta) else: num = len(Ha) if (Ta in Ha and lTa[0] == lHa[0]): #drow a if (Ta == Ha): Tp += 1 Hp += 1 else: Hp += 3 elif (Ha in Ta and Ha != Ta and lTa[0] == lHa[0]): Tp += 3 else: for i in range(len(lTa)): # convert alphabet to number for j in range(26): if (lTa[i] == alph[j]): lTa[i] = int(j) else : continue for i in range(len(lHa)): # convert alphabet to number for j in range(26): if (lHa[i] == alph[j]): lHa[i] = int(j) else : continue for i in range(num): if (lTa[i] < lHa[i]): Hp +=3 break elif (lHa[i] < lTa[i]): Tp +=3 break elif (lHa[i] == lTa[i]): continue print(Tp,Hp)
0
null
52,116,111,768,490
247
67
import sys input = sys.stdin.readline INF = 99999#1001001001 from collections import deque def linput(ty=int, cvt=list): return cvt(map(ty,input().split())) def pad(mxy, wall="#"): w = len(mxy[0]) gp = wall*(w+2) re = [gp,] re_app = re.append for vx in mxy: re_app(wall+vx+wall) re_app(gp) return re vD = [(0,1),(1,0)] vQ = deque([]) vQ_app, vQ_popl = vQ.append, vQ.popleft def main(): H,W = linput() mM = [input().rstrip() for _ in [0,]*H] mM = pad(mM, "$") res = 0 cnt = 0 for sr in range(1,1+1): for sc in range(1,1+1): if mM[sr][sc]=="#": res += 1 mV = [[INF,]*(W+2) for _ in [INF,]*(H+2)] mV[sr][sc] = res vQ_app((sr,sc)) while vQ: r,c = vQ_popl() now_cost = mV[r][c] now_s = mM[r][c] for dr,dc in vD: nr,nc = r+dr, c+dc if mM[nr][nc]=="$": continue next = now_s=="."!=mM[nr][nc] new_cost = now_cost + next if new_cost < mV[nr][nc]: vQ_app((nr,nc)) mV[nr][nc] = new_cost cnt += 1 #print(res,cnt,X,Y,H) if cnt>999999: break #print(*mV,sep="\n")### res = mV[H][W] print(res) if __name__ == "__main__": main()
#!/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()
1
49,304,674,578,400
null
194
194
S=input() Q=int(input()) p=0 u=0 l="" r="" for i in range(Q): q=list(input().split()) if q[0]=="1": u+=1 else: if q[1]=="1" and u%2==0 or q[1]=="2" and u%2==1: l=l+q[2] else: r=r+q[2] if u%2==0: l=l[::-1] S=l+S+r else: S=S[::-1] r=r[::-1] S=r+S+l print(S)
def dist(x, y, i, j): dx = x[i] - x[j] dy = y[i] - y[j] return (dx * dx + dy * dy) ** 0.5 n = int(input()) x = [0] * n y = [0] * n for i in range(n): x[i], y[i] = map(int, input().split()) ans = 0 for i in range(n): for j in range(i + 1, n): ans += dist(x, y, i, j) * 2 / n print(ans)
0
null
102,576,576,517,632
204
280
N = int(input()) D = N % 10 if D in [2, 4, 5, 7, 9]: print("hon") if D in [0, 1, 6, 8]: print("pon") if D == 3: print("bon")
input_n = input() n = str(input_n) listN = list(n) #listN = n.split(' ') if listN[len(listN) - 1] == "s": listN.append("e") listN.append("s") else: listN.append("s") for i in range(len(listN)): print(listN[i], end = "")
0
null
10,852,742,506,310
142
71
n = int(input()) a = list(map(int, input().split())) m, s = 0, 0 for i in range(n): m = max(m, a[i]) s += m - a[i] print(s)
n = int(input()) A = list(map(int, input().split())) m = A[0] ans = 0 for a in A[1:]: m = max(m,a) if m > a: ans += m-a print(ans)
1
4,577,120,854,592
null
88
88
from math import gcd from collections import defaultdict n = int(input()) AB = [list(map(int, input().split())) for _ in range(n)] MOD = 1000000007 box = defaultdict(int) zeros = 0 for a, b in AB: if a == b == 0: zeros += 1 else: if a != 0 and b == 0: box[(-1, 1, 0)] += 1 elif a == 0 and b != 0: box[(1, 0, 1)] += 1 else: g = gcd(a, b) ga = a // g gb = b // g if (a // b) < 0: s = -1 else: s = 1 box[(s, abs(ga), abs(gb))] += 1 nakawaru = dict() others = 0 for (s, i, j), v in box.items(): if (-s, j, i) in box.keys(): if (s, i, j) not in nakawaru.keys() and (-s, j, i) not in nakawaru.keys(): nakawaru[(s, i, j)] = (box[(s, i, j)], box[(-s, j, i)]) else: others += v seed = 1 for i, j in nakawaru.values(): seed *= (pow(2, i, MOD) + pow(2, j, MOD) - 1) seed %= MOD ans = zeros + pow(2, others, MOD) * seed - 1 ans %= MOD print(ans)
import sys from collections import defaultdict from math import gcd def input(): return sys.stdin.readline().strip() mod = 1000000007 def main(): N = int(input()) fish = defaultdict(int) """ b / aで値を管理するのは浮動小数点誤差が怖いので、 g = gcd(a, b) として(a//g, b//g)のタプルで管理するのが良い。 """ zero = 0 for _ in range(N): a, b = map(int, input().split()) if a == 0 and b == 0: zero += 1 elif a == 0: fish[(0, 1)] += 1 elif b == 0: fish[(1, 0)] += 1 else: g = gcd(a, b) if a < 0: a, b = -a, -b fish[(a // g, b // g)] += 1 #print(fish) """ 仲の悪い組を(S1, T1), (S2, T2),...とすれば(Si, Ti)からの魚の選び方と (Sj, Tj)からの魚の選び方は独立じゃん。 なぜ気づかなかったのか。。。 """ ans = 1 finished = set([]) for a, b in fish: if (a, b) in finished: continue finished.add((a, b)) s = fish[(a, b)] if b > 0: t = fish[(b, -a)] if (b, -a) in fish else 0 finished.add((b, -a)) else: t = fish[(-b, a)] if (-b, a) in fish else 0 finished.add((-b, a)) ans *= pow(2, s, mod) + pow(2, t, mod) - 1 ans %= mod #print("(a, b)=({}, {}) -> s={}, t={}, val={}".format(a, b, s, t, pow(2, s, mod) + pow(2, t, mod) - 1)) print((ans + zero - 1) % mod) if __name__ == "__main__": main()
1
20,852,049,992,928
null
146
146
a,b,c=map(int,input().split()) if (4*a*b)<(c-a-b)**2 and c-a-b>0: print('Yes') else: print('No')
from numba import njit import numpy as np d = int(input()) cs = list(map(int, input().split())) cs = np.array(cs, dtype=np.int64) sm = [list(map(int, input().split())) for _ in range(d)] sm = np.array(sm, dtype=np.int64) @njit('i8(i8[:], i8)', cache=True) def total_satisfaction(ts, d): ls = np.zeros(26, dtype=np.int64) s = 0 for i in range(d): t = ts[i] t -= 1 s += sm[i][t] ls[t] = i + 1 dv = cs * ((i+1) - ls) s -= dv.sum() return s @njit('i8(i8, i8, i8, i8, i8[:])', cache=True) def differential(s, i, t, d, ls): t -= 1 bk = ls[t] s += sm[i][t] ls[t] = i + 1 dv = cs * ((i+1) - ls) s -= dv.sum() ls[t] = bk return s ts = np.array([], dtype=np.int64) for i in range(d): sc = 0 if len(ts) > 0: tt = np.array(ts, dtype=np.int64) sc = total_satisfaction(tt, i) ls = np.zeros(26, np.int64) for i, t in enumerate(ts, 1): ls[t-1] = i mx = -99999999 mxt = -1 for t in range(1, 26+1): df = differential(sc, len(ts), t, i + 1, ls) s = sc + df if s > mx: mx = s mxt = t ts = np.append(ts, [mxt]) print(mxt)
0
null
30,637,863,752,608
197
113
# import sys # sys.setrecursionlimit(10 ** 6) # import bisect # from collections import deque # from decorator import stop_watch # # # @stop_watch def solve(N, As): ans = 0 i = 1 for A in As: if A == i: i += 1 else: ans += 1 ans = -1 if ans == N else ans print(ans) if __name__ == '__main__': # S = input() N = int(input()) # N, M = map(int, input().split()) As = [int(i) for i in input().split()] # Bs = [int(i) for i in input().split()] solve(N, As)
n = int(input()) a = list(map(int, input().split())) ans = 0 cnt = 0 for i in range(n) : if a[i] == cnt + 1 : cnt += 1 if cnt > 0 : print(n-cnt) else : print("-1")
1
114,780,236,697,060
null
257
257
import sys import os import math import bisect import itertools import collections import heapq import queue import array # 時々使う # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall # from decimal import Decimal # from collections import defaultdict, deque # 再帰の制限設定 sys.setrecursionlimit(10000000) def ii(): return int(sys.stdin.buffer.readline().rstrip()) def il(): return list(map(int, sys.stdin.buffer.readline().split())) def fl(): return list(map(float, sys.stdin.buffer.readline().split())) def iln(n): return [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] def iss(): return sys.stdin.buffer.readline().decode().rstrip() def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split())) def isn(n): return [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] def lcm(x, y): return (x * y) // math.gcd(x, y) MOD = 10 ** 9 + 7 INF = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() D = [il() for _ in range(N)] for i in range(N - 2): for j in range(i, i + 3): if D[j][0] != D[j][1]: break else: print('Yes') exit() else: print('No') if __name__ == '__main__': main()
a = int(input()) count = 0 for i in range(a): x,y = map(int,input().split(" ")) if x == y: count += 1 else: count = 0 if count == 3: print('Yes') exit() print("No")
1
2,472,503,937,570
null
72
72
input_line = input() Line = input_line.split() Line = [int(s) for s in Line] if Line[0]*500 >= Line[1]: print("Yes") else: print("No")
k, y = [int(i) for i in input().split()] print('Yes' if 500 * k >= y else 'No')
1
98,124,137,855,914
null
244
244
H=int(input()) b=0 while 2**b <= H: b+=1 print(2**(b)-1)
from functools import reduce print("Yes" if reduce(lambda a, b: (a+b)%9, map(int, input()), 0) == 0 else "No")
0
null
42,501,981,171,968
228
87
i = 0 while True: i += 1 num = raw_input() if num == "0": break print "Case %d: %s" % (i,num)
x=input() i=1 while (x!='0'): print("Case {0}: {1}".format(i,x)); i+=1; x=input()
1
485,501,444,032
null
42
42
a = map(int, raw_input().split()) j = 0 for i in xrange(a[0], a[1]+1): j=j if a[2] % i else j+1 print j
n,k=[int(x) for x in input().split()] ans=0 l=[0]*(k+1) i=k mod=1000000007 while i>0: l[i]=pow(k//i,n,mod) j=2*i while j<=k: l[i]=(l[i]-l[j]+mod)%mod j+=i i-=1 for i in range(1,k+1): ans+=(l[i]*i)%mod print(ans%mod)
0
null
18,699,746,338,536
44
176
from math import gcd from collections import defaultdict n = int(input()) AB = [list(map(int, input().split())) for _ in range(n)] MOD = 1000000007 box = defaultdict(int) zeros = 0 for a, b in AB: if a == b == 0: zeros += 1 else: if a != 0 and b == 0: box[(-1, 1, 0)] += 1 elif a == 0 and b != 0: box[(1, 0, 1)] += 1 else: g = gcd(a, b) ga = a // g gb = b // g if (a // b) < 0: s = -1 else: s = 1 box[(s, abs(ga), abs(gb))] += 1 nakawaru = dict() others = 0 for (s, i, j), v in box.items(): if (-s, j, i) in box.keys(): if (s, i, j) not in nakawaru.keys() and (-s, j, i) not in nakawaru.keys(): nakawaru[(s, i, j)] = (box[(s, i, j)], box[(-s, j, i)]) else: others += v seed = 1 for i, j in nakawaru.values(): seed *= (pow(2, i, MOD) + pow(2, j, MOD) - 1) seed %= MOD ans = zeros + pow(2, others, MOD) * seed - 1 ans %= MOD print(ans)
from math import gcd from collections import defaultdict MOD = 10**9+7 n = int(input()) cnt = defaultdict(lambda: [0, 0]) zeros = 0 for _ in range(n): a, b = map(int, input().split()) if a == b == 0: zeros += 1 continue if a < 0: a *= -1 b *= -1 g = gcd(a, b) a //= g b //= g if b > 0: cnt[(a, b)][0] += 1 else: if a == 0 and b < 0: cnt[(a, -b)][0] += 1 else: cnt[(-b, a)][1] += 1 ans = 1 for v, v2 in cnt.values(): ans *= 1+pow(2, v, MOD)-1+pow(2, v2, MOD)-1 ans %= MOD ans = (ans+zeros-1) % MOD print(ans)
1
20,859,231,993,598
null
146
146
from collections import deque n = int(input()) a = deque() for i in range(n): s = input().split(" ") if s[0] == "insert": a.appendleft(int(s[1])) elif s[0] == "delete": if int(s[1]) in a: a.remove(int(s[1])) elif s[0] == "deleteLast": a.pop() elif s[0] == "deleteFirst": a.popleft() b = list(a) for i in range(len(b)): if i == len(b)-1: print(b[i]) else: print(b[i],end=" ")
import itertools def actual(n, D): """ combinations でゴリ押し """ comb = itertools.combinations(D, 2) # return sum([x * y for x, y in comb]) """ 「順番を考慮しない2要素の選び方」を全探索する際のポイント 内側のループ変数の始点を外側のループ変数 +1 から始めるとよい。 これにより、内側のループで選ぶインデックスが必ず外側のループで選ぶインデックスより大きくなり、 同じ選び方を 2 回見てしまうことを回避できます。 """ # s = 0 # for i in range(len(D)): # for j in range(i + 1, len(D)): # s += D[i] * D[j] # # return s """ O(N)で解くパターン ex: a, b, c, d a*b + a*c + a*d = a * (b + c +d) b*c + b*d = b * ( c +d) c*d = c * ( d) """ s = 0 for i in range(len(D) - 1): s += D[i] * sum(D[i + 1:]) return s n = int(input()) D = list(map(int, input().split())) print(actual(n, D))
0
null
84,197,257,382,790
20
292
import sys import numpy as np import numba from numba import njit i8 = numba.int64 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines @njit((i8[:], ), cache=True) def main(S): N = len(S) L = np.empty(N, np.int64) R = np.empty(N, np.int64) x = y = 0 n = 0 for s in S: if s == 0: y += 1 elif s == 1: if y: y -= 1 else: x += 1 else: L[n], R[n] = x, y n += 1 x = y = 0 L, R = L[:n], R[:n] L1, R1 = L[L > R], R[L > R] L2, R2 = L[L <= R], R[L <= R] ind = R1.argsort() L1, R1 = L1[ind], R1[ind] ind = L2.argsort()[::-1] L2, R2 = L2[ind], R2[ind] L = np.concatenate((L1, L2)) R = np.concatenate((R1, R2)) n = 0 for i in range(len(L)): if n < R[i]: return False n += L[i] - R[i] return n == 0 N = int(readline()) S = np.array(list(read()), np.int64) - ord('(') print('Yes' if main(S) else 'No')
def parseSpaceDivideIntArgs(arg): tmpArr = arg.split() ret = [] for s in tmpArr: ret.append(int(s)) return ret instr = input() # instr = "1 2 3" instrSpl = parseSpaceDivideIntArgs(instr) a = instrSpl[0] b = instrSpl[1] c = instrSpl[2] if a < b & b < c: print("Yes") else: print("No")
0
null
12,020,729,727,160
152
39
N,M = map(int,input().split()) a = [-1]*N ans = 0 for i in range(M): s,c = map(int,input().split()) if a[s-1] == -1: a[s-1] = c elif a[s-1] != c: ans = -1 break if a[0] == 0 and N>1: ans = -1 if ans != -1: if a[0] == -1 and N>1: a[0] = 1 if a[0] == -1 and N == 1: a[0] = 0 for i in range(N): if a[i] == -1: a[i] = 0 a[i] = str(a[i]) ans = "".join(a) print(ans)
# 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")
0
null
30,392,314,906,430
208
38
from collections import deque N = int(input()) C = input() r = deque() lr = 0 for i in range(N): if C[i] == 'R': lr += 1 r.append(i) ans = 0 for i in range(N): if lr == 0: break if C[i] == 'W': if i < r[-1]: ans += 1 r.pop() lr -= 1 else: break print(ans)
N = int(input()) C = input() a = 0 rr = 0 lw = 0 for i in range(N): if C[i] == 'R': rr += 1 a = rr for i in range(0, N): if C[i] == 'W': lw = lw+1 else: rr = rr-1 a = min(a, max(lw, rr)) print(a)
1
6,247,336,525,952
null
98
98
n=int(input()) L=sorted(list(map(int,input().split()))) ans=0 for i in range(n): for j in range(i+1,n): l=j;r=n while abs(l-r)>1: mid=(r+l)//2 if L[i]<L[j]+L[mid] and L[j]<L[i]+L[mid] and L[mid]<L[i]+L[j]: l=mid else: r=mid ans+=l-j print(ans)
from bisect import bisect_left n = int(input()) a = list(map(int,input().split())) a.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): ind = bisect_left(a,a[i]+a[j]) ans += ind-j-1 print(ans)
1
172,274,345,805,458
null
294
294
from collections import deque def getMaxDistance(s,startY,startX): d = deque() distances = [[0 for _ in range(w)] for j in range(h)] dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] maxDistance = 0 d.append(startX) d.append(startY) while d: x = d.popleft() y = d.popleft() if s[y][x]=='#': continue maxDistance = max(maxDistance, distances[y][x]) for i in range(4): xx = x + dx[i] yy = y + dy[i] if not (0 <= yy < h and 0 <= xx < w): continue if s[yy][xx] != '.': continue if distances[yy][xx] != 0: continue if xx == startX and yy == startY: continue d.append(xx) d.append(yy) distances[yy][xx] = distances[y][x] + 1 return maxDistance h,w=map(int,input().split()) s=[list(input()) for _ in range(h)] maxDistance = 0 for i in range(h): for j in range(w): maxDistance = max(maxDistance, getMaxDistance(s,i,j)) print(maxDistance)
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heappushpop, heapify import copy import sys INF = float('inf') mod = 10**9+7 sys.setrecursionlimit(10 ** 6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().split())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] h, w = LI() s = SRL(h) ans = [] for i in range(h): for j in range(w): if s[i][j] == "#": continue v = [[-1] * w for _ in range(h)] q = deque() q.append((i, j)) v[i][j] = 1 goal = tuple() while q: r, c = q.popleft() for x, y in ((1, 0), (-1, 0), (0, -1), (0, 1)): if r + x < 0 or r + x > h - 1 or c + y < 0 or c + y > w - 1 or s[r + x][c + y] == "#" or v[r + x][c + y] > 0: continue v[r + x][c + y] = v[r][c] + 1 q.append((r + x, c + y)) ans.append(max(chain.from_iterable(v)) - 1) print(max(ans))
1
94,726,544,524,930
null
241
241
N = int(input()) A = map(int, input().split()) B = [3 if i == 0 else 0 for i in range(N + 1)] MOD = 1000000007 ans = 1 for a in A: ans = ans * B[a] % MOD if ans == 0: break else: B[a] -= 1 B[a + 1] += 1 print(ans)
def main(): mod = 1000000007 n = int(input()) cnt = [0] * (n + 2) cnt[0] = 3 res = 1 for x in input().split(): v = int(x) res *= cnt[v] - cnt[v + 1] res %= mod cnt[v + 1] += 1 print(res) main()
1
130,453,922,732,736
null
268
268
while True: i = list(map(int, input().split())) if i[0] == 0 and i[1] == 0: break else: for j in range(i[0]): for k in range(i[1]): if j % 2 == 0 and k % 2 == 0: print("#", end='') elif j % 2 == 1 and k % 2 == 1: print("#", end='') else: print(".", end='') print("\n", end='') print("\n", end='')
import sys import math H, W = map(int, raw_input().split()) while H > 0 or W > 0 : for y in xrange(H) : for x in xrange(W) : if (x + y) % 2 == 0 : sys.stdout.write("#") else : sys.stdout.write(".") print print H, W = map(int, raw_input().split())
1
879,850,223,460
null
51
51
class Tree(): def __init__(self, n, edge, indexed=1): self.n = n self.tree = [[] for _ in range(n)] for e in edge: self.tree[e[0] - indexed].append(e[1] - indexed) self.tree[e[1] - indexed].append(e[0] - indexed) def setroot(self, root): self.root = root self.parent = [None for _ in range(self.n)] self.parent[root] = -1 self.depth = [None for _ in range(self.n)] self.depth[root] = 0 self.order = [] self.order.append(root) self.size = [1 for _ in range(self.n)] stack = [root] while stack: node = stack.pop() for adj in self.tree[node]: if self.parent[adj] is None: self.parent[adj] = node self.depth[adj] = self.depth[node] + 1 self.order.append(adj) stack.append(adj) for node in self.order[::-1]: for adj in self.tree[node]: if self.parent[node] == adj: continue self.size[node] += self.size[adj] import sys input = sys.stdin.readline N, u, v = map(int, input().split()) u -= 1; v -= 1 E = [tuple(map(int, input().split())) for _ in range(N - 1)] t = Tree(N, E) t.setroot(u); dist1 = t.depth t.setroot(v); dist2 = t.depth tmp = 0 for i in range(N): if dist1[i] < dist2[i]: tmp = max(tmp, dist2[i]) print(tmp - 1)
''' Created on 2020/09/10 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write N,M=map(int,pin().split()) if N==3: ans=[1,0,0] for _ in [0]*M: s,c=map(int,pin().split()) if s==1 and c==0: print(-1) return if s!=1 and ans[s-1]!=0 and ans[s-1]!=c: print(-1) return ans[s-1]=c a="" for i in ans: a+=str(i) print(a) return elif N==2: ans=[1,0] for _ in [0]*M: s,c=map(int,pin().split()) if s==1 and c==0: print(-1) return if s!=1 and ans[s-1]!=0 and ans[s-1]!=c: print(-1) return ans[s-1]=c a="" for i in ans: a+=str(i) print(a) return else: if M==0: print(0) return s,c=map(int,pin().split()) ans=c for j in range(M-1): s,c=map(int,pin().split()) if c!=ans: print(-1) return print(ans) return main()
0
null
88,837,660,319,268
259
208
n = int(input()) dp = [0 for _ in range(46)] dp[0] = 1 dp[1] = 1 for i in range(2, 46): dp[i] = dp[i-1] + dp[i-2] print(dp[n])
a = int(input()) if a % 2 == 0: print(str(int(a//2))) else: print(str(int(a//2)+1))
0
null
29,476,045,872,820
7
206
# 問題:https://atcoder.jp/contests/abc142/tasks/abc142_b n, k = map(int, input().strip().split()) h = list(map(int, input().strip().split())) res = 0 for i in range(n): if h[i] < k: continue res += 1 print(res)
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n,k = list(map(int, input().split())) h = list(map(int, input().split())) ans = sum(item>=k for item in h) print(ans)
1
178,930,442,160,700
null
298
298
N=int(input()) X=input() A=[0,1,1,2,1,2,1,2,1,2,1,2,1,2,2,3,1] ppx=0 for i in range(N): if X[i]=="1": ppx+=1 if ppx<=1: ppxm1=1 else: ppxm1=ppx-1 Xmod=[0,0] XmodP=[0]*N XmodM=[0]*N XmodP[0]=1%(ppx+1) XmodM[0]=1%(ppxm1) Xmod=[XmodP[0]*(X[-1]=="1"),XmodM[0]*(X[-1]=="1")] for i in range(N-1): XmodP[i+1]=(XmodP[i]*2)%(ppx+1) XmodM[i+1]=(XmodM[i]*2)%(ppxm1) if X[-2-i]=="1": Xmod[0]=(Xmod[0]+XmodP[i+1])%(ppx+1) Xmod[1]=(Xmod[1]+XmodM[i+1])%(ppxm1) for i in range(N): if X[i]=="0": Xm=(Xmod[0]+XmodP[-1-i])%(ppx+1) else: Xm=(Xmod[1]-XmodM[-1-i])%(ppxm1) if ppx==1 and X[i]=="1": print(0) elif Xm==0: print(1) else: px=0 temp=Xm while temp>0: if temp%2==1: px+=1 temp=(temp-1)/2 else: temp=temp/2 p=Xm%px print(A[p]+2)
from collections import deque s=deque(input()) q=int(input()) qq=[list(input().split()) for i in range(q)] rl=1 fleft=deque() fright=deque() for i in qq: if i[0]=='1': rl*=-1 else: if i[1]=='1': if rl==1: fleft.appendleft(i[2]) else: fright.append(i[2]) else: if rl==1: fright.append(i[2]) else: fleft.appendleft(i[2]) fleft.reverse() s.extendleft(fleft) s.extend(fright) if rl==-1: s.reverse() print(''.join(s))
0
null
32,848,389,389,860
107
204
S = input() T = input() print('Yes') if T[:len(S)] == S else print('No')
def main(): S = input() T = input() if S == T[:-1]: print("Yes") else: print("No") if __name__ == '__main__': main()
1
21,565,753,736,330
null
147
147
import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = readline().decode().rstrip() if '7' in N: print('Yes') else: print('No')
n = int(input()) lst = [0] *4 for i in range(n): a = input() if a == 'AC': lst[0] += 1 if a == 'WA': lst[1] += 1 if a == 'TLE': lst[2] += 1 if a == 'RE': lst[3] += 1 print('AC x',lst[0]) print('WA x',lst[1]) print('TLE x',lst[2]) print('RE x',lst[3])
0
null
21,521,224,458,482
172
109
n, m, k = map(int, input().split()) a_books = [int(i) for i in input().split()] b_books = [int(i) for i in input().split()] time = 0 count = 0 for i in range(n): time += a_books[i] if time > k: time -= a_books[i] i -= 1 break count += 1 for j in range(m): time += b_books[j] if time > k: time -= b_books[j] j -= 1 break count += 1 max_count = count #print(max_count, time) while j < m and i >= 0: time -= a_books[i] i -= 1 count -= 1 j += 1 while j < m: time += b_books[j] if time > k: time -= b_books[j] j -= 1 break count += 1 j += 1 if count > max_count: max_count = count #print(count, time) #print(max_count) print(max_count)
import numpy as np from numba import njit @njit("i8[:](i8, i8[:], i8[:])", cache=True) def cumsum(K, L, cL): for i, a in enumerate(L): cL[i] = cL[i - 1] + L[i] if cL[i] > K: cL[i] = 0 break cL = cL[cL != 0] cL = np.append(0, cL) return cL @njit("i8(i8, i8[:], i8[:])", cache=True) def solve(K, A, cB): ans_max = 0 for i, a in enumerate(A): ans = 0 K -= a ind = np.searchsorted(cB, K, side="right") - 1 ans = i + ind if ans > ans_max: ans_max = ans if ind == 0 or K < 0: break return ans_max N, M, K = map(int, input().split()) A = np.array(input().split(), dtype=np.int64) B = np.array(input().split(), dtype=np.int64) cA = np.zeros(N, dtype=np.int64) cB = np.zeros(M, dtype=np.int64) # np.cumsumだとoverflowする cA = cumsum(K, A, cA) cB = cumsum(K, B, cB) A = np.append(0, A) ans = solve(K, A, cB) print(max(ans, len(cA) - 1, len(cB) - 1))
1
10,821,099,319,462
null
117
117
N, M = map(int, input().split()) edge = [[] for _ in range(N)] for i in range(M): a,b = map(int, input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) from collections import deque def solve(): prev = [-1]*N prev[0]='Yes' d = deque([(0,0)]) while len(d): v,cnt = d.popleft() for u in edge[v]: if prev[u]==-1: prev[u]=v+1 d.append((u,cnt+1)) if -1 in prev: return ['No'] return prev print(*solve(),sep='\n')
N = int(input()) l = [] for i in range(N): l.append([int(x) for x in input().split()]) xlim = [] ylim = [] def cha(a): return [a[0]-a[1],a[0]+a[1]] for i in range(N): ylim.append(cha(l[i])[1]) xlim.append(cha(l[i])[0]) xlim.sort() ylim.sort() print(max(xlim[-1]-xlim[0],ylim[-1]-ylim[0]))
0
null
12,027,183,069,522
145
80
x, y, a, b, c = map(int, input().split()) p = [int(i) for i in input().split()] q = [int(i) for i in input().split()] r = [int(i) for i in input().split()] p = list(reversed(sorted(p))) q = list(reversed(sorted(q))) r = list(reversed(sorted(r))) apple = p[:x] + q[:y] + r apple = list(reversed(sorted(apple))) print(sum(apple[:x+y]))
from math import gcd mod = 1000000007 n = int(input()) zero = 0 bad = {} for i in range(n): x, y = map(int, input().split()) if x == 0 and y == 0: zero += 1 continue g = gcd(x, y) x //= g y //= g if y < 0: x, y = -x, -y if y==0 and x<0: x, y = -x, -y is_rotate90 = (x <= 0) if is_rotate90: x, y = y, x y = -y if not (x, y) in bad: bad[x, y] = [0, 0] if is_rotate90: bad[x, y][0] += 1 else: bad[x, y][1] += 1 # print(bad) cnt = 1 for x, y in bad: c1, c2 = bad[x, y] c3 = 1 c3 += pow(2, c1, mod) - 1 c3 += pow(2, c2, mod) - 1 cnt = cnt * c3 % mod ans = (cnt + zero - 1) % mod # print('cnt',cnt) # print('zero',zero) # print('ans',ans) print((ans+mod) % mod)
0
null
32,920,005,553,468
188
146
X,N=map(int,input().split()) P=set(map(int,input().split())) l=[0]+[(1+i//2)*(-1 if i%2==0 else 1) for i in range(101)] for i in l: if X+i not in P: print(X+i) break
x, n = map(int, input().split()) p = list(map(int, input().split())) for i in range(n): if p[i] - x >= 0: p[i] = 2 * (p[i] - x) else: p[i] = (x - p[i]) * 2 - 1 p = sorted(p) i = 0 while i in p: i += 1 if i % 2 == 0: j = round(i / 2) + x else: j = x - round((i + 1) / 2) print(j)
1
14,010,341,756,076
null
128
128
n = int(input()) a = list(map(int, input().split())) m = 1 count = 0 for i in range(n): if a[i] != m: count += 1 else: m += 1 print(count if count < n else -1)
n=int(input()) a=[int(x) for x in input().rstrip().split()] now=1 cnt=0 for i in range(n): if now==a[i]: now+=1 else: cnt+=1 if n==cnt: print(-1) else: print(cnt)
1
114,721,717,522,060
null
257
257
w = str.lower(raw_input()) t = [] while True: line = raw_input() if line == "END_OF_TEXT": break else: t += (map(str.lower, line.split(" "))) count = 0 for i in xrange(len(t)): if w == t[i]: count += 1 print count
W = input() cnt = 0 while True: t = input() if t == 'END_OF_TEXT': break else: cnt += t.lower().split().count(W) print(cnt)
1
1,821,079,115,360
null
65
65
X = int(input()) print((X//500)*1000+(X%500)//5*5)
x=int(input()) hundred=x//500 x-=hundred*500 five=x//5 print(hundred*1000+five*5)
1
42,847,399,595,248
null
185
185
import math def koch(n, p1, p2): if n == 0: return s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3] t = [(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3] u = [(t[0] - s[0]) * math.cos(math.radians(60)) - (t[1] - s[1]) * math.sin(math.radians(60)) + s[0], (t[0] - s[0]) * math.sin(math.radians(60)) + (t[1] - s[1]) * math.cos(math.radians(60)) + s[1]] koch(n - 1, p1, s) print(s[0], s[1]) koch(n - 1, s, u) print(u[0], u[1]) koch(n - 1, u, t) print(t[0], t[1]) koch(n - 1, t, p2) n = int(input()) p1 = (0, 0) p2 = (100, 0) print(p1[0], p1[1]) koch(n, p1, p2) print(p2[0], p2[1])
import math a, b, C = map(int, input().split()) C = C / 180 * math.pi S = a * b * math.sin(C) / 2 print(S) print(a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))) print(2 * S / a)
0
null
145,767,511,330
27
30
''' Auther: ghoshashis545 Ashis Ghosh College: jalpaiguri Govt Enggineering College ''' from os import path import sys from heapq import heappush,heappop from functools import cmp_to_key as ctk from collections import deque,defaultdict as dd from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right from itertools import permutations from datetime import datetime from math import ceil,sqrt,log,gcd def ii():return int(input()) def si():return input().rstrip() def mi():return map(int,input().split()) def li():return list(mi()) abc='abcdefghijklmnopqrstuvwxyz' # mod=1000000007 mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def bo(i): return ord(i)-ord('a') def solve(): # for _ in range(ii()): n,k = mi() seg = [] for i in range(k): seg.append(li()) dp = [0]*(n+1) dp[1] = 1 for i in range(2,n+1): dp[i] += dp[i-1] dp[i] %= mod for j in range(k): if seg[j][0] >= i: continue l = max(1,i - seg[j][1]) r = i - seg[j][0] dp[i] += dp[r] - dp[l-1] dp[i] += mod dp[i] %= mod print((dp[n] - dp[n-1] + mod)%mod) if __name__ =="__main__": if path.exists('input.txt'): sys.stdin=open('input.txt', 'r') sys.stdout=open('output.txt','w') else: input=sys.stdin.readline solve()
S=input() if S.count("RRR") ==1: print(3) elif S.count("RR")==1: print(2) elif S.count("R")>=1: print(1) else: print(0)
0
null
3,783,382,557,068
74
90
import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline s = readline() if s[2] == s[3] and s[4] == s[5]: print('Yes') else: print('No')
S = input() if len(S)==6 : if S[2] == S[3] and S[4] == S[5] : print("Yes") else: print("No")
1
41,791,469,512,994
null
184
184
X = int(input()) a = 100 for i in range(1, 100000): a = a * 101 // 100 if a >= X: print(i) exit()
import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().rstrip() def main(): n, k = map(int, input().split()) p = tuple(map(int, input().split())) c = tuple(map(int, input().split())) ans = -10**18 for i in range(n): start, count = i, 1 val = c[start] while p[start]-1 != i: start = p[start]-1 count += 1 val += c[start] start = i if val > 0: a = (k//count-1)*val ans = max(a, ans) num = count + k % count else: a = 0 num = min(k, count) for _ in range(num): a += c[start] start = p[start] - 1 ans = max(a, ans) print(ans) if __name__ == '__main__': main()
0
null
16,179,152,602,880
159
93
import fractions while 1: try: a,b=map(int,input().split()) c=fractions.gcd(a,b) print(c,(a*b)//c) except:break
def pd(n): i = 2 ans = [] while i ** 2 <= n: while n % i == 0: n /= i ans.append(i) i += 1 if n > 1: ans.append(n) return ans def gcd(a, b): gcd = 1 pd_a = pd(a) pd_b = pd(b) for i in pd_a: if i in pd_b: pd_b.remove(i) gcd *= i return int(gcd) def lcm(a, b): lcm = a pd_a = pd(a) pd_b = pd(b) for i in pd_a: if i in pd_b: pd_b.remove(i) for j in pd_b: lcm *= j return int(lcm) while True: try: s = input() a,b = [int(i) for i in s.split(' ')] except: break print(gcd(a, b), lcm(a, b))
1
661,879,158
null
5
5
A, B = map(int, input().split()) a = [i for i in range(int((A-1)*100/8 ), int((A+1)*100/8 ))] b = [i for i in range(int((B-1)*100/10), int((B+1)*100/10))] a = [i for i in a if int(i*0.08) == A] b = [i for i in b if int(i*0.10) == B] ans = list(set(a) & set(b)) if ans and min(ans) > 0: print(min(ans)) else: print(-1)
a, b = map(int, input().split()) ans = -1 for money in range(pow(10, 4)): if int(money*0.08) == a and int(money*0.1) == b: ans = money break print(ans)
1
56,686,680,994,478
null
203
203
import itertools import bisect N = int(input()) LS = list(map(int,input().split())) LS.sort() ans = 0 for a,b in itertools.combinations(LS,2): a,b = min(a,b),max(a,b) lo = b - a up = a + b cnt = bisect.bisect_left(LS,up) - bisect.bisect_right(LS,lo) - 1 if lo < a: cnt -= 1 if cnt <= 0: continue ans += cnt print(ans // 3)
from sys import exit N,K = map(int,input().split()) town = [None]+list(map(int,input().split())) flag = [None]+[0]*N remain = K piece = 1 cnt = 1 while remain > 0: if flag[town[piece]] != 0: q = cnt-flag[town[piece]] piece = town[piece] remain -= 1 break else: piece = town[piece] flag[piece] = cnt remain -= 1 cnt += 1 if remain == 0: print(piece) exit(0) remain %= q while remain > 0: piece = town[piece] remain -= 1 print(piece)
0
null
96,891,679,906,028
294
150
n = int(input()) l = list(map(int, input().split())) t = 0 for i in range(len(l)): for j in range(i + 1, len(l)): for k in range(j + 1, len(l)): sum = l[i] + l[j] + l[k] if sum - max(l[i], l[j], l[k]) > max(l[i], l[j], l[k]): if l[i] != l[j] and l[i] != l[k] and l[j] != l[k]: t += 1 print(t)
n = int(input()) st = list(map(int,input().split())) st.sort(reverse = True) count = 0 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): if (st[i] != st[j] != st[k]) and (st[i] < st[j] + st[k]): count += 1 print(count)
1
5,044,479,056,632
null
91
91
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) X1 = T1 * (A1 - B1) X2 = T2 * (A2 - B2) D = X1 + X2 if D == 0: print("infinity") else: if X1 < 0: X1, X2 = [-X1, -X2] else: D = -D if D < 0: print("0") else: if X1 % D == 0: print((X1 // D) * 2) else: print((X1 // D) * 2 + 1)
from collections import deque n,m=map(int,input().split()) s=deque(input()) a=0 for i in range(n+1): if s[i]=="1": a=a+1 if a==m: print(-1) break else: a=0 if a==0: b=deque([]) d=n while d>0: if d<=m: b.appendleft(d) d=0 else: i=m while i>0: if s[d-i]=="1": i=i-1 else: b.appendleft(i) d=d-i for j in range(i): s.pop() break for i in range(len(b)): print(b[i],end=" ")
0
null
134,977,055,797,078
269
274
MOD = int(1e9+7) N, K = map(int, input().split()) count = [0] * (K+1) ans = 0 for now in range(K, 0, -1): count[now] = pow(K // now, N, MOD) for j in range(2*now ,K+1, now): count[now] -= count[j] if count[now] < 0: count[now] += MOD ans += now * count[now] print(ans % MOD)
N, K = map(int, input().split()) mod = 10 ** 9 + 7 cnt = [0] * (K + 1) answer = 0 for i in range(K, 0, -1): tmp = pow(K // i, N, mod) - sum(cnt[::i]) cnt[i] = tmp answer = (answer + tmp * i) % mod print(answer)
1
36,665,890,981,888
null
176
176
N, M, X = list(map(int, input().split())) list = [list(map(int, input().split())) for i in range(N)] def calc_cost(li): """ 与えられた部分リストが各アルゴリズムの条件を 満たすか確認し、そのコストを計算。 条件満たさないときは100000000を出力 """ # flag = True cost = 0 for item in li: cost += item[0] for i in range(M): algo_sum = 0 for item in li: algo_sum += item[i + 1] if algo_sum < X: return 100000000 return cost cost = 100000000 for i in range(2 ** N): in_list = [] for j in range(N): if (i >> j) & 1: in_list.append(list[j]) temp_cost = calc_cost(in_list) if temp_cost == -1: break cost = min(cost, temp_cost) if cost == 100000000: cost = -1 print(cost)
N=int(input()) A=list(map(int,input().split())) count=0 for i,a in enumerate(A): n=i+1 if n%2==1 and a%2==1: count+=1 print(count)
0
null
15,041,375,517,762
149
105
import math H = int(input()) count = 0 atk = 0 for i in range(10 ** 12): if H == 1: for j in range(0,atk+1): count += 2 ** j break else: H = math.floor(H / 2) atk += 1 print(count)
H=int(input()) ans = 0 count = 0 while H>0: H=int(H/2) ans+=2**count count+=1 print(ans)
1
80,010,423,663,268
null
228
228
# Python 3+ #------------------------------------------------------------------------------- import sys #ff = open("test.txt", "r") ff = sys.stdin cnt = 1 for line in ff : if int(line) == 0 : break print("Case {0}: {1}".format(cnt, line), end="") cnt += 1
a=1 while True: i = input() if i==0: break else : print "Case %d: %d"%(a,i) a+=1
1
481,987,753,828
null
42
42
from collections import defaultdict n=int(input()) MAX=10000 d = defaultdict(int) def col(x,y,z): if x == y and x == z : return 1 if x == y or y == z or z == x : return 3 return 6 # x <= y <= z for i in range(1,MAX): wkx = i**2 if wkx > MAX: break for j in range(i,MAX): wky = wkx + j**2 + i * j if wky > MAX : break for k in range(j,MAX): wkz = wky + k**2 + i * k + j * k if wkz > MAX : break d[wkz] = d[wkz] + col(i,j,k) for i in range(n): k = i + 1 print(d[k])
n = int(input()) l = [0]*10000 for x in range(1, 100): for y in range(1, 100): for z in range(1, 100): ind = x**2+y**2+z**2+x*y+y*z+z*x if ind <= 10000: l[ind-1]+=1 for i in range(n): print(l[i])
1
7,994,148,378,720
null
106
106
K = int(input()) N = 10**6 a = [0] * N a[0] = 7 for i in range(1, N): a[i] = (a[i-1] * 10 + 7) % K a[0] %= K for i in range(N): if a[i] == 0: print(i+1) break else: print(-1)
k = int(input()) ans = 1 a = 7 % k while a != 0: ans += 1 a = (10*a + 7) % k if ans == 10**6: ans = -1 break print(ans)
1
6,170,075,373,060
null
97
97
# 入力 InpList=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] K=int(input()) result=0 # 処理 print(InpList[K-1])
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] k = int(input()) ans = l[k - 1] print(ans)
1
50,186,824,398,700
null
195
195
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from fractions import Fraction from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations, accumulate from operator import add, mul, sub, itemgetter, attrgetter import sys # sys.setrecursionlimit(10**6) # readline = sys.stdin.buffer.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(readline()) def read_int_n(): return list(map(int, readline().split())) def read_float(): return float(readline()) def read_float_n(): return list(map(float, readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.perf_counter() ret = f(*args, **kwargs) e = time.perf_counter() error_print(e - s, 'sec') return ret return wrap class Combination: def __init__(self, n, mod): 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) self.MOD = mod self.N = n self.g1 = g1 self.g2 = g2 self.inverse = inverse def __call__(self, n, r): if (r < 0 or r > n): return 0 r = min(r, n-r) return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD @mt def slv(N, K): ans = 0 M = 10**9 + 7 C = Combination(N*2+1, M) def H(n, r): return C(n+r-1, r) K = min(N-1, K) for k in range(K+1): m = N - k t = C(N, k) * H(m, k) ans += t ans %= M return ans def main(): N, K = read_int_n() print(slv(N, K)) if __name__ == '__main__': main()
R,C,K=map(int,input().split()) Value=[[0]*(C+1) for _ in range(R+1)] for _ in range(K): r,c,v=map(int,input().split()) Value[r][c]=v DP=[[0,0,0,0] for _ in range(C+1) ] for y in range(1,R+1): #下に移動 for x in range(1,C+1): DP[x][0]=max(DP[x]) DP[x][1]=DP[x][0]+Value[y][x] DP[x][2]=DP[x][3]=0 #右に移動 for x in range(1,C+1): for k in range(0,3+1): DP[x][k]=max(DP[x][k],DP[x-1][k]) for k in range(1,3+1): DP[x][k]=max(DP[x][k],DP[x-1][k-1]+Value[y][x]) print(max(DP[-1]))
0
null
36,573,117,124,404
215
94
def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) from collections import deque def main(): mod=10**9+7 S=input() from collections import deque dq=deque() for c in S: dq.appendleft(c) rev=0 Q=I() for _ in range(Q): q=input().split() if q[0]=="1": rev=(rev+1)%2 else: f=int(q[1]) c=q[2] if (rev+f)%2==1: dq.append(c) else: dq.appendleft(c) ans=[] if rev: while dq: ans.append(dq.popleft()) else: while dq: ans.append(dq.pop()) print(''.join(map(str, ans))) main()
from sys import exit x, n = map(int, input().split()) p = list(map(int, input().split())) for d in range(x+1): #0に達した時点で0を出力して終了するので、大きい側は気にしなくてよい for s in [-1, 1]: a = x + d*s if not a in p: print(a) exit()
0
null
35,742,401,268,486
204
128
def gcd(x, y): if x < y: x, y = y, x while y != 0: x, y = y, x % y return x if __name__ == "__main__": x, y = list(map(int, input().split())) print(gcd(x, y))
import sys import math def gcd(x, y): if y == 0: return x return gcd(y, x%y) x, y = map(int, raw_input().split()) print gcd(min(x, y), max(x, y))
1
8,154,068,002
null
11
11
N, M = map(int, input().split()) S = input() ans = [] now_pos = N while now_pos > 0: next_pos = max(0, now_pos - M) for i in range(M): if S[next_pos + i] == "0": ans.append(now_pos - (next_pos + i)) now_pos = next_pos + i break else: print(-1) exit() print(" ".join(map(str, ans[::-1])))
def main(): N, M = map(int, input().split()) *G, = map(int, input()) ans = [] cur = N ecur = cur - 1 while cur > 0: ncur = cur while (cur - ecur) <= M and ecur >= 0: if G[ecur] == 0: ncur = ecur ecur -= 1 if ncur == cur: print(-1) return ans.append(cur - ncur) cur = ncur ans.reverse() print(*ans) if __name__ == '__main__': main()
1
139,106,706,555,250
null
274
274
n = int(input()) l = list(map(int,input().split())) h = 0 sum = 0 for i in range(n): if l[i] <= h: sum += h - l[i] else: h = l[i] print(sum)
import numpy as np from scipy.sparse.csgraph import floyd_warshall N,M,L = map(int,input().split()) gurahu = np.zeros((N,N)) for k in range(M): a,b,c = map(int,input().split()) gurahu[a-1,b-1] = c gurahu[b-1,a-1] = c gurahu = floyd_warshall(gurahu, directed=False) gurahu = np.where((gurahu <= L) & (gurahu > 0), 1, 0) gurahu = floyd_warshall(gurahu) - np.ones((N, N)) Q = int(input()) for k in range(Q): s,t = map(int,input().split()) ans = gurahu[s-1,t-1] if ans == float('inf'): print(-1) else: print(int(ans))
0
null
89,208,698,317,568
88
295
n, k = map(int, input().split()) w = [int(input()) for i in range(n)] l = max(w) r = sum(w) while l < r: m = (l + r) // 2 stack = car = 0 for i in w: stack += i if stack > m: stack = i car += 1 if car < k: r = m else: l = m + 1 print(l)
n, k = map(int, input().split()) W = [int(input()) for _ in range(n)] def can_load(W, k, q, n): i = 0 for _ in range(k): s = 0 while i < n and s + W[i] <= q: s += W[i] i += 1 if i == n: return True else: return False # 積載量をmidと仮定して二分探索 hi = 10 ** 9 # OK lo = 0 # NG while hi - lo > 1: mid = (hi + lo) // 2 if can_load(W, k, mid, n): hi = mid else: lo = mid print(hi)
1
90,963,710,200
null
24
24
C = input() N = ord(C) print(chr(N + 1))
n = int(raw_input()) num_list = [int(raw_input()) for i in xrange(n)] minv = num_list[0] maxv = -1000000000 for i in xrange(1, n): tmp = num_list[i] - minv maxv = tmp if tmp > maxv else maxv minv = num_list[i] if minv > num_list[i] else minv # print "i = %d, tmp = %d, maxv = %d, minv = %d" % (i, tmp, maxv, minv) print maxv
0
null
45,973,901,969,252
239
13
from sys import stdin input = stdin.readline from time import time from random import randint from copy import deepcopy start_time = time() def calcScore(t, s, c): scores = [0]*26 lasts = [0]*26 for i in range(1, len(t)): scores[t[i]] += s[i][t[i]] dif = i - lasts[t[i]] scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2 lasts[t[i]] = i for i in range(26): dif = len(t) - lasts[i] scores[i] -= c[i] * dif * (dif-1) // 2 return scores def greedy(c, s): day_lim = len(s) socres = [0]*26 t = [0]*day_lim lasts = [0]*26 for i in range(1, day_lim): pls = [v for v in socres] mns = [v for v in socres] for j in range(26): pls[j] += s[i][j] mns[j] -= c[j] * (i - lasts[j]) sum_mns = sum(mns) pt = sum_mns - mns[0] + pls[0] idx = 0 for j in range(1, 26): tmp = sum_mns - mns[j] + pls[j] if pt < tmp: pt = tmp idx = j t[i] = idx lasts[idx] = i for j in range(26): if j == idx: socres[j] = pls[j] else: socres[j] = mns[j] return socres, t def subGreedy(c, s, t, day): day_lim = len(s) socres = [0]*26 t = [0]*day_lim lasts = [0]*26 for i in range(1, day_lim): if day <= i: pls = [v for v in socres] mns = [v for v in socres] for j in range(26): pls[j] += s[i][j] mns[j] -= c[j] * (i - lasts[j]) sum_mns = sum(mns) pt = sum_mns - mns[0] + pls[0] idx = 0 for j in range(1, 26): tmp = sum_mns - mns[j] + pls[j] if pt < tmp: pt = tmp idx = j t[i] = idx lasts[idx] = i for j in range(26): if j == idx: socres[j] = pls[j] else: socres[j] = mns[j] else: scores[t[i]] += s[i][t[i]] lasts[t[i]] = i for j in range(26): dif = i - lasts[j] scores[j] -= c[j] * dif return socres, t D = int(input()) c = list(map(int, input().split())) s = [[0]*26 for _ in range(D+1)] for i in range(1, D+1): s[i] = list(map(int, input().split())) scores, t = greedy(c, s) sum_score = sum(scores) while time() - start_time < 1.86: typ = randint(1, 100) if typ <= 70: for _ in range(300): tmp_t = deepcopy(t) tmp_t[randint(1, D)] = randint(0, 25) tmp_scores = calcScore(tmp_t, s, c) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) elif typ <= 98: for _ in range(100): tmp_t = deepcopy(t) dist = randint(1, 15) p = randint(1, D-dist) q = p + dist tmp_t[p], tmp_t[q] = tmp_t[q], tmp_t[p] tmp_scores = calcScore(tmp_t, s, c) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score or randint(1, 100) <= 3: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) elif typ <= 100: tmp_t = deepcopy(t) day = randint(D//4*3, D) tmp_scores, tmp_t = subGreedy(c, s, tmp_t, day) sum_tmp_score = sum(tmp_scores) if sum_score < sum_tmp_score: sum_score = sum_tmp_score t = deepcopy(tmp_t) scores = deepcopy(tmp_scores) for v in t[1:]: print(v+1)
w = input() t = [] while True: s = [1 if i.lower() == w else 'fin' if i == 'END_OF_TEXT' else 0 for i in input().split()] t += s if 'fin' in s: break print(t.count(1))
0
null
5,711,335,216,202
113
65
s = input() n = len(s) t = s[:(n-1)//2] u = s[(n+3)//2-1:] if (s == s[::-1] and t == t[::-1] and u == u[::-1]): print('Yes') else: print('No')
t = input() n = len(t) t += "a" ans = "" for i in range(n): if t[i] == "?": ans += "D" else: ans += t[i] print(ans)
0
null
32,308,871,967,254
190
140
n = int(input()) c = 0 m = 0 for x in range(n): a, b = input().split() if a==b: c += 1 else: c = 0 m = max(m, c) if m >= 3: print("Yes") else: print("No")
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n = inp() a = [inpl() for _ in range(n)] a = [x == y for x,y in a] res = False for i in range(n-2): if sum(a[i:i+3]) == 3: res = True print('Yes' if res else 'No')
1
2,476,375,590,052
null
72
72
def main(): INP = list(map(int, input().split())) list1 = [INP[0],INP[1]] list2 = [INP[2],INP[3]] if INP[0] < 0 and INP[1] > 0: list1.extend([-1,0,1]) if INP[2] < 0 and INP[3] > 0: list2.extend([-1,0,1]) ans = -(10**18) for item in list1: for item2 in list2: ans = max(ans,item*item2) print(ans) if __name__ == '__main__': main()
tmp = [int(e) for e in input().split()] a = tmp[0] b = tmp[1] c = tmp[2] d = tmp[3] res = a * c tmp = a * d if tmp > res: res = tmp tmp = b * c if tmp > res: res = tmp tmp = b * d if tmp > res: res = tmp print(res)
1
3,075,606,193,230
null
77
77
import itertools n = int(input()) d = list(map(int, input().split())) sum = 0 for i in itertools.combinations(d, 2): sum += i[0] * i[1] print(sum)
import itertools def actual(n, D): """ combinations でゴリ押し """ comb = itertools.combinations(D, 2) # return sum([x * y for x, y in comb]) """ 「順番を考慮しない2要素の選び方」を全探索する際のポイント 内側のループ変数の始点を外側のループ変数 +1 から始めるとよい。 これにより、内側のループで選ぶインデックスが必ず外側のループで選ぶインデックスより大きくなり、 同じ選び方を 2 回見てしまうことを回避できます。 """ # s = 0 # for i in range(len(D)): # for j in range(i + 1, len(D)): # s += D[i] * D[j] # # return s """ O(N)で解くパターン ex: a, b, c, d a*b + a*c + a*d = a * (b + c +d) b*c + b*d = b * ( c +d) c*d = c * ( d) """ s = 0 for i in range(len(D) - 1): s += D[i] * sum(D[i + 1:]) return s n = int(input()) D = list(map(int, input().split())) print(actual(n, D))
1
168,193,554,039,648
null
292
292
x,y,z=map(int,raw_input().split());c=0 for i in range(x,y+1): if z%i==0: c+=1 print c
n = int(input()) a = list(map(int, input().split())) def nim(x): bx = [format(i,'030b') for i in x] bz = ''.join([str( sum([int(bx[xi][i]) for xi in range(len(x))]) % 2) for i in range(30)]) return int(bz, 2) nima = nim(a) ans = [ str(nim([nima,aa])) for aa in a ] print(' '.join(ans) )
0
null
6,554,832,935,028
44
123
n = int(input()) a =[' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0'] A_1 = a.copy() A_2 = a.copy() A_3 = a.copy() B_1 = a.copy() B_2 = a.copy() B_3 = a.copy() C_1 = a.copy() C_2 = a.copy() C_3 = a.copy() D_1 = a.copy() D_2 = a.copy() D_3 = a.copy() ren1 = [A_1,A_2,A_3] ren2 = [B_1,B_2,B_3] ren3 = [C_1,C_2,C_3] ren4 = [D_1,D_2,D_3] for i in range(n): b = input() c = b.split(' ') ren = int(c[0]) kai = int(c[1]) banme = int(c[2]) nin = int(c[3]) if nin < 0: if ren == 1: ren1[kai-1][banme-1] = ' %s'%(int(ren1[kai-1][banme-1])+nin) elif ren == 2: ren2[kai-1][banme-1] = ' %s'%(int(ren2[kai-1][banme-1])+nin) elif ren == 3: ren3[kai-1][banme-1] = ' %s'%(int(ren3[kai-1][banme-1])+nin) elif ren == 4: ren4[kai-1][banme-1] = ' %s'%(int(ren4[kai-1][banme-1])+nin) elif ren == 1: ren1[kai-1][banme-1] = ' %s'%(int(ren1[kai-1][banme-1])+nin) elif ren == 2: ren2[kai-1][banme-1] = ' %s'%(int(ren2[kai-1][banme-1])+nin) elif ren == 3: ren3[kai-1][banme-1] = ' %s'%(int(ren3[kai-1][banme-1])+nin) elif ren == 4: ren4[kai-1][banme-1] = ' %s'%(int(ren4[kai-1][banme-1])+nin) print(''.join(A_1)) print(''.join(A_2)) print(''.join(A_3)) print('####################') print(''.join(B_1)) print(''.join(B_2)) print(''.join(B_3)) print('####################') print(''.join(C_1)) print(''.join(C_2)) print(''.join(C_3)) print('####################') print(''.join(D_1)) print(''.join(D_2)) print(''.join(D_3))
Residents = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] n = int(input()) for l in range(n): b, f, r, v = list(map(int, input().split())) Residents[b-1][f-1][r-1] += v for k in range(4): for j in range(3): print(' '+' '.join(map(str, Residents[k][j]))) if k == 3: break print('####################')
1
1,103,566,911,828
null
55
55
n, k = map(int, input().split()) MOD = 10 ** 9 + 7 patterns = [0] * k total = 0 for i in range(k, 0, -1): # gcdがちょうどi ⇔ すべての要素がiの倍数 # かつ すべての要素が2i, 3i, ...の倍数でない tmp = pow(k // i, n, MOD) for j in range(2*i, k+1, i): tmp -= patterns[j-1] patterns[i-1] = tmp total += i * tmp total %= MOD print(total)
N, K = map(int, input().split()) ans = 0 lis = [0]*K mod = 10**9 + 7 def modpow(a, n, mod): ans = 1 while n > 0: if n&1: ans = ans * a % mod a = a * a % mod n = n >> 1 return ans for x in range(K,0, -1): a = int((K // x) % mod) b = modpow(a, N, mod) for i in range(2, K//x +1): b = (b - lis[x*i-1]) %mod if b < 0: b += mod lis[x-1] = b ans = (ans + b*x%mod) % mod print(int(ans))
1
36,630,391,239,708
null
176
176
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) mod = 10 ** 9 + 7 b = 1 ans = 0 for i in range(k - 1, n): ans += b * (a[i] - a[n - i - 1]) ans %= mod b = (i+1)*pow(i-k+2, mod - 2, mod) * b % mod print(ans)
s = input() print(s+'es') if s.endswith('s') else print(s+'s')
0
null
48,822,659,302,620
242
71
L=int(input()) answer=(round(L/3,10))**3 print(answer)
#! env/bin/local python3 # -*- coding: utf-8 -*- print((float(input()) / 3) ** 3)
1
47,072,987,026,688
null
191
191
a,b,c = (int(x) for x in input().split()) count = 0 while a <= b: if c % a == 0: count += 1 a += 1 print (str(count))
a,b,c = map(int, input().split()) p = 0 for j in range(a,b + 1): if c%j==0: p = p+1 print(p)
1
556,099,047,480
null
44
44
import sys import math def resolve(in_): a, b, n = map(int, next(in_).split()) x = min(b - 1, n) return math.floor(a * x / b) - a * math.floor(x / b) def main(): answer = resolve(sys.stdin.buffer) print(answer) if __name__ == '__main__': main()
#abc175b n=int(input()) l=list(map(int,input().split())) l.sort() cnt=0 for i in range(n): for j in range(i): for k in range(j): if l[k]!=l[j] and l[i]!=l[j] and l[k]+l[j]>l[i]: cnt+=1 print(cnt)
0
null
16,666,816,327,488
161
91
import sys a,b,c = map(int,sys.stdin.readline().split()) num = 0 for i in range(a,b+1): if c % i == 0: num += 1 print(num)
from math import gcd K=int(input()) result=0 for a in range(1,K+1): for b in range(1,K+1): for c in range(1,K+1): result+=gcd(gcd(a,b),c) print(result)
0
null
17,917,824,067,108
44
174
h,w,k = map(int,input().split()) g = [list(input()) for i in range(h)] ans = [[1]*w for i in range(h)] count = 1 path = False l = [] for i in range(h): if "#" in g[i]: path = True done = 0 for j in range(w): if g[i][j] == "#": done += 1 if done >= 2: count += 1 ans[i][j] = count count += 1 if l: for j in l: ans[j] = ans[i] l = [] else: if path: ans[i] = ans[i-1] else: l.append(i) for i in ans: print(*i)
import sys import numpy as np from math import ceil as C, floor as F, sqrt from collections import defaultdict as D, Counter as CNT from functools import reduce as R ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' alp = 'abcdefghijklmnopqrstuvwxyz' def _X(): return sys.stdin.readline().rstrip().split(' ') def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0] def S(): return _S(_X()) def Ss(): return list(S()) def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss) def I(): return _I(S()) def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss] def Is(): return _Is(I()) x = I() A = [] As = [] B = [] Bs = [] for i in range(250): n = i ** 5 A.append(i) As.append(n) B.append(i) Bs.append(n) B.append(-i) Bs.append(-n) xs = [a-x for a in As] for i, x in enumerate(xs): if x in Bs: print(A[i], B[Bs.index(x)]) break
0
null
84,746,425,289,540
277
156
N,K = map(int,input().split()) H = list(map(int,input().split())) H = sorted(H)[::-1] H = H[K:N] print(str(sum(H)))
number=list(map(int,input().split())) n,m=number[0],number[1] height=list(map(int,input().split())) load=[[] for i in range(n+1)] for i in range(m): tmp=list(map(int,input().split())) if tmp[1] not in load[tmp[0]]: load[tmp[0]].append(tmp[1]) if tmp[0] not in load[tmp[1]]: load[tmp[1]].append(tmp[0]) box=[] answer=0 for i in range(1,n+1): box=[] if len(load[i])==0: answer+=1 for j in range(len(load[i])): box.append(height[load[i][j]-1]) if box!=[]: if max(box)<height[i-1]: answer+=1 print(answer)
0
null
52,169,829,095,072
227
155
s = input() print(s.swapcase())
def main(): import sys input = sys.stdin.readline inf = 1 << 60 N, M, L = map(int, input().split()) dist = [[inf] * N for _ in range(N)] for _ in range(M): A, B, C = map(int, input().split()) A -= 1 B -= 1 dist[A][B] = dist[B][A] = C for k in range(N): for i in range(N): for j in range(N): dist[i][j] = min( dist[i][j], dist[i][k] + dist[k][j] ) g = [[inf] * N for _ in range(N)] # 到達に必要な補充回数 for A in range(N): for B in range(N): if dist[A][B] <= L: g[A][B] = 1 for k in range(N): for i in range(N): for j in range(N): g[i][j] = min( g[i][j], g[i][k] + g[k][j] ) Q = int(input()) for _ in range(Q): s, t = (int(x) - 1 for x in input().split()) d = g[s][t] if d == inf: print(-1) else: print(d - 1) if __name__ == '__main__': main()
0
null
87,172,504,928,640
61
295
N,M,*f = open(0).read().split() N = int(N) M = int(M) pS = [f[i*2:i*2+2] for i in range(M)] accepted = [0] * (N+1) wrong = [0] * (N+1) penalty = [0] * (N+1) for p,S in pS: i = int(p) if accepted[i] == 0: if S == 'AC': penalty[i] = wrong[i] accepted[i] = 1 else: wrong[i] += 1 print(sum(accepted),sum(penalty))
import copy from collections import deque n, st, sa = map(int,input().split()) st -= 1 sa -= 1 e = [[] for i in range(n)] for i in range(n-1): a, b = map(int, input().split()) a -= 1 b -= 1 e[a].append(b) e[b].append(a) visited = [False] * n visited[st] = True d = deque() d.append([st, 0]) tx = {} if len(e[st]) == 1: tx[st] = 0 cnt = 0 while d: f, cnt = d.popleft() flg = True for t in e[f]: if not visited[t]: flg = False d.append([t, cnt+1]) visited[t] = True if flg: tx[f] = cnt visited = [False] * n visited[sa] = True d = deque() d.append([sa, 0]) ax = {} if len(e[sa]) == 1: ax[sa] = 0 cnt = 0 while d: f, cnt = d.popleft() flg = True for t in e[f]: if not visited[t]: flg = False d.append([t, cnt+1]) visited[t] = True if flg: ax[f] = cnt ax = sorted(ax.items(), key=lambda x:x[1], reverse=True) for i in range(len(ax)): x, d = ax[i][0], ax[i][1] if d > tx[x]: ans = d - 1 break print(ans)
0
null
105,500,212,218,324
240
259
n=int(input()) s=input() ans="" for i in range(len(s)): num=ord(s[i])+n if num>90: num-=26 ans+=chr(num) print(ans)
def main(): import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline # 開催日数 D = int(input()) # 満足度の下がりやすさ C = list(map(int, input().split())) # 得られる満足度 S = [ list(map(int, input().split())) for _ in range(D) ] # 開催予定 T = [ int(input())-1 for _ in range(D) ] # 最後に開かれた日付 last = [0]*26 def cp(d, t): c = 0 for i in range(26): c += C[i] * (d - last[i]) return c score = 0 for i in range(D): score += S[i][T[i]] last[T[i]] = i+1 c = cp(i+1, T[i]) score -= c print(score) main()
0
null
72,246,449,329,212
271
114
N = input() if N.endswith('2') == True or N.endswith('4') == True or N.endswith('5') == True or N.endswith('7') == True or N.endswith('9') == True: print('hon') elif N.endswith('0') == True or N.endswith('1') == True or N.endswith('6') == True or N.endswith('8') == True: print('pon') else: print('bon')
H = int(input()) a = 1 i = 1 while a < H: a += 2 ** i i += 1 print(a)
0
null
49,811,165,661,140
142
228
a, b, c = map(int, input().split()) divisitor = [] for i in range(a, b+1): if a < 0 or b < 0 or c < 0: break elif a > 10001 or b > 10001 or c > 10001: break elif a > b: break elif c % i == 0: divisitor.append(int(c/i)) print((len(divisitor)))
a, b, c = [int(temp) for temp in input().split()] count = 0 for check in range(a, b + 1) : if c % check == 0 : count += 1 print(count)
1
559,265,159,492
null
44
44
D = int(input()) c = [*map(int, input().split())] s = [0] + [[*map(int, input().split())] for _ in range(D)] t = [0] + [int(input()) for _ in range(D)] v = 0 last = [0] * 26 for d in range(1, D+1): select = t[d] - 1 v += s[d][select] last[select] = d v -= sum(c[i] * (d - last[i]) for i in range(26)) print(v)
def main(): D = int(input()) C = [0] * 26 C = list(map(int,input().split())) S = [ list(map(int,input().split(" "))) for i in range(D)] score = 0 last = [0] * 26 for i in range(D): t = int(input()) for j in range(26): if j+1 == t: last[j] = 0 score += S[i][j] else: last[j] += 1 score -= last[j]*C[j] print(score) if __name__ == '__main__': main()
1
9,992,780,371,152
null
114
114
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()
n = input() s = input().split() q = input() t = input().split() ans = 0 for c1 in t: for c2 in s: if c1 == c2: ans += 1 break print(ans)
1
64,985,538,278
null
22
22
from sys import stdin f_i = stdin N, M = map(int, f_i.readline().split()) A = list(map(int, f_i.readline().split())) A.sort() from bisect import bisect_left def shake_count(power): return N ** 2 - sum(bisect_left(A, power - left_hand) for left_hand in A) lower = A[0] * 2 - 1 upper = A[-1] * 2 + 1 while lower + 1 < upper: mid = (lower + upper) // 2 if shake_count(mid) >= M: lower = mid else: upper = mid X = tuple(bisect_left(A, upper - left_hand) for left_hand in A) from itertools import accumulate acc = tuple(accumulate([0] + A)) s = acc[-1] ans = sum(s - acc[x] for x in X) + sum(a * (N - x) for a, x in zip(A, X)) rest_shake_count = M - (N ** 2 - sum(X)) ans += lower * rest_shake_count print(ans)
import sys read = sys.stdin.buffer.read input = sys.stdin.buffer.readline inputs = sys.stdin.buffer.readlines import bisect n,m=map(int,input().split()) A=list(map(int,input().split())) A.sort() def hand(x): cnt=0 for i in range(n): p=x-A[i] cnt+=n-bisect.bisect_left(A,p) return cnt def main(): l=0 h=2*10**5+1 mid=(l+h)//2 while l+1<h: mid=(l+h)//2 if hand(mid)<m: h=mid else: l=mid B=A[::-1] for i in range(n-1): B[i+1]+=B[i] B=B[::-1] ans=0 cnt=0 for i in range(n): y=l-A[i]+1 index=bisect.bisect_left(A,y) if n==index: continue else: ans+=(n-index)*A[i]+B[index] cnt+=(n-index) ans+=(m-cnt)*l print(ans) if __name__ == "__main__": main()
1
108,115,398,138,308
null
252
252
while (True): code=list(map(int,input().split())) if(code[0]==-1 and code[1]==-1 and code[2]==-1): break sum=code[0]+code[1] if(code[0]==-1 or code[1]==-1): print("F") elif(sum>=80): print("A") elif(sum>=65): print("B") elif(sum>=50): print("C") elif(sum<30): print("F") elif(sum>=30 and code[2]>=50): print("C") else: print("D")
while True: m,f,r = map(int,input().split()) score = "" if(m == -1 and f == -1 and r == -1): break if(m == -1 or f == -1): score = "F" elif(m+f >= 80): score = "A" elif(m+f >= 65): score = "B" elif(m+f >= 50): score = "C" elif(m+f >= 30): if(r >= 50): score = "C" else: score = "D" else: score = "F" print(score)
1
1,200,928,519,610
null
57
57
N = int(input()) X = list(map(int,input().split())) avg = sum(X)//N sums_1 = 0 sums_2 = 0 for i in X: sums_1 += (avg - i)**2 for j in X: sums_2 += (avg+1 - j)**2 print(min(sums_1,sums_2))
a,b,c = map(int, input().split()) print("Yes") if b * c >= a else print("No")
0
null
34,445,015,988,240
213
81
N = int(input()) L = list(map(int,input().split())) if N < 3: print(0) exit() count = 0 for i in range(N-2): for j in range(i+1,N-1): if L[i] == L[j]: continue else: for k in range(j+1,N): if L[i]==L[k] or L[j]==L[k]: continue elif abs(L[i]+L[j])>L[k]and abs(L[i]-L[j])<L[k]: count += 1 print(count)
import itertools N = int(input()) L = list(map(int,(input().split()))) Combination = list(itertools.permutations(L, 3)) count = 0 for i in Combination: # a+b>c かつ b+c>a かつ c+a>b a = int(i[0]) b = int(i[1]) c = int(i[2]) if((a+b)> c and (b+c) >a and (c+a) >b and a!=b and b!= c and a!= c and a<b and b<c): count+=1 print(count)
1
5,001,076,443,538
null
91
91
N = int(input()) count = {} max_count = 0 for _ in range(N): s = input() if s not in count: count[s] = 0 count[s] += 1 max_count = max(max_count, count[s]) longest = [] for s, c in count.items(): if c == max_count: longest.append(s) longest.sort() for s in longest: print(s)
def maximumProfit(A, N): minR = A[0] minP = A[1] - A[0] for i in range(1, N): R = A[i] - minR if R > minP: minP = R if A[i] < minR: minR = A[i] return minP if __name__ == "__main__": N = input() A = [] for i in range(N): A.append(input()) print maximumProfit(A, N)
0
null
34,860,573,719,510
218
13
def is_prime(num: int) -> bool: # 6k +- 1 <= √n if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i+2) == 0: return False i += 6 return True x = int(input()) for i in range(x,1000000): if is_prime(i): print(i) break
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools from collections import Counter def main(): x = int(input()) while True: if all( x%i != 0 for i in range(2,x)): print(x) exit() x += 1 if __name__=="__main__": main()
1
105,536,740,677,608
null
250
250
N = int(input()) A = list(map(int, input().split())) cnt = 0 idx = 1 for i, a in enumerate(A): if idx == a: idx += 1 else: cnt += 1 if cnt == N: print(-1) else: print(cnt)
n=int(input()) s=list(map(int,input().split())) ans=0 j=1 for i in s: if i!=j : ans+=1 else: j+=1 print(ans) if ans<n else print(-1)
1
114,966,823,205,190
null
257
257
x,n= map(int,input().split()) p = list(map(int,input().split())) ans,i = 0,0 while True: if x-i not in p: ans = x-i break if x+i not in p: ans = x+i break i = i+1 print(ans)
N,X,M = map(int,input().split()) i = X%M L = [i] S = set([i]) i = i**2 % M while not i in S: L.append(i) S.add(i) i = i**2 % M index = L.index(i) k = (N-index)//len(L[index:]) l = (N-index)%len(L[index:]) # これでうまくいくのたまたまだよ。本当はN<indexの場合分けがひつよう。なんで場合分けするよ if N<index: ans = sum(L[:N]) else: ans = sum(L[:index]) + (k*sum(L[index:])) + sum(L[index:index+l]) print(ans)
0
null
8,436,707,465,670
128
75
n,m = map(int, input().split()) height_list = list(map(int, input().split())) heightest_list = [0] * n for _ in range(m): a,b = map(int, input().split()) heightest_list[a-1] = max(heightest_list[a-1], height_list[b-1]) heightest_list[b-1] = max(heightest_list[b-1], height_list[a-1]) result = 0 for i in range(n): if height_list[i] > heightest_list[i]: result += 1 print(result)
n,m = map(int, input().split()) ans = 0 #辺を取り除くことはabのセットとなっている要素から取り除くことと等価。頂点を消すのではない。 h_list = list(map(int, input().split())) c = 0 max_list = [0]*(n+1) for i in range(m): a,b = map(int, input().split()) max_list[a] = max(max_list[a],h_list[b-1]) max_list[b] = max(max_list[b],h_list[a-1]) for i in range(1,n+1): if h_list[i-1] > max_list[i]: ans += 1 print(ans)
1
24,988,992,507,688
null
155
155
import bisect,collections,copy,heapq,itertools,math,string import numpy as np import sys from cmath import pi, rect sys.setrecursionlimit(10**7) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) A,B,H,M = LI() H += M / 60 H = H/12 * 2*pi M = M/60 * 2*pi # 余弦定理 l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(H-M) ) # 複素数座標 Aexp(iθ) zA = A * np.exp(H*1j) zB = B * np.exp(M*1j) l=abs(zA - zB) print(l)
D,T,S=map(int,input().split()) print("Yes" if D<=T*S else "No")
0
null
11,739,014,858,350
144
81
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n, m = map(int, input().split()) h = tuple(map(int, input().split())) edges = {e:[] for e in range(n)} for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(h[b]) edges[b].append(h[a]) r = 0 for i, he in enumerate(h): if not edges[i]: r += 1 else: r += he > max(edges[i]) print(r) if __name__ == '__main__': main()
N,M=map(int,input().split()) H=[0]+list(map(int,input().split())) check=[0]+[1]*N for _ in range(M): a,b=map(int,input().split()) if H[a]>=H[b]: check[b]=0 if H[b]>=H[a]: check[a]=0 print(sum(check))
1
24,919,549,368,182
null
155
155
def manhattan(n, x, y): x2 = [0] * n y2 = [0] * n for i in range(n): x2[i] = x[i] - y[i] y2[i] = x[i] + y[i] print(max(max(x2) - min(x2), max(y2) - min(y2))) n = int(input()) x = [0] * n y = [0] * n for i in range(n): x[i] , y[i] = map(int, input().split()) manhattan(n, x, y)
n=int(input()) a,b,c,d=-10**9,10**9,-10**9,10**9 for _ in range(n): x,y=map(int,input().split()) a=max(a,x+y) b=min(b,x+y) c=max(c,x-y) d=min(d,x-y) print(max(a-b,c-d))
1
3,414,731,626,368
null
80
80