code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
from collections import defaultdict def main(): N = int(input()) dd = defaultdict(int) for _ in range(N): si = input() dd[si] += 1 maxv = max(dd.items(), key = lambda item: item[1])[-1] strings = [key for key, val in dd.items() if val == maxv] strings = sorted(strings) for string in strings: print(string) if __name__ == '__main__': main()
n=int(input()) d={} m=1 for i in range(n): s=input() if s in d: d[s]+=1 m=max(m,d[s]) else: d[s]=1 se=set() for i in d: if d[i]==m: se.add(i) se=list(se) se.sort() print(*se)
1
69,899,624,881,060
null
218
218
k = int(input()) a, b = map(int, input().split()) if a <= k <= b or k <= b/2: print('OK') else: print('NG')
ini = lambda : int(input()) inm = lambda : map(int,input().split()) inl = lambda : list(map(int,input().split())) gcd = lambda x,y : gcd(y,x%y) if x%y else y 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 def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors #maincode------------------------------------------------- k = ini() a,b = inm() ans = 'NG' for i in range(1000): if a <= i * k <= b: ans = 'OK' print(ans)
1
26,400,622,864,528
null
158
158
n,m=map(int,input().split()) a=list(map(int,input().split())) import math def lcm(x, y): return (x * y) // math.gcd(x, y) x=1 for i in range(n): x=lcm(x,a[i]//2) power=[0]*n for i in range(n): while a[i]%2==0: a[i]//=2 power[i]+=1 if power.count(power[0])==n: print((m+x)//(2*x)) else: print(0)
from math import atan2, degrees a,b,x = map(int, input().split()) s = x/a if x >= a**2*b/2: print(degrees(atan2(2*(a*b-s)/a, a))) else: print(degrees(atan2(b, 2*s/b)))
0
null
132,142,520,130,180
247
289
from functools import reduce from operator import xor # via https://drken1215.hatenablog.com/entry/2020/06/22/122500 N, *A = map(int, open(0).read().split()) B = reduce(xor, A) print(*map(lambda a: B^a, A))
x,y,a,b,c = map(int,input().split()) p=[int(x) for x in input().rstrip().split()] q=[int(x) for x in input().rstrip().split()] r=[int(x) for x in input().rstrip().split()] p.sort(reverse=True) q.sort(reverse=True) r.sort(reverse=True) p=p[:x] q=q[:y] pq=p+q pqr=pq+r pqr.sort(reverse=True) print(sum(pqr[:x+y]))
0
null
28,676,577,648,988
123
188
import sys def input(): return sys.stdin.readline().strip() def resolve(): x,y=map(int, input().split()) ans=0 if x==3: ans+=100000 elif x==2: ans+=200000 elif x==1: ans+=300000 if y==3: ans+=100000 elif y==2: ans+=200000 elif y==1: ans+=300000 if x==1 and y==1: ans+=400000 print(ans) resolve()
def award(x): return max(0, 4*(10**5) - x*(10**5)) x,y = map(int,input().split()) ans = award(x) ans += award(y) if x == 1 and y == 1: ans += 4*(10**5) print(ans)
1
140,062,752,420,956
null
275
275
while True: H,W = map(int, input().split()) if H==0 and W==0: break for y in range(0,H): for x in range(0,W): if y%2==1: if x%2==1: print("#",end="") else: print(".",end="") else: if x%2==1: print(".",end="") else: print("#",end="") print() print()
import sys while True: h, w = [ int( val ) for val in sys.stdin.readline().split( " " ) ] if 0 ==h and 0 == w: break pa = [ "#", "." ] ouput = [] for i in range( h ): for j in range( w ): ouput.append( pa[(i+j)%2] ) ouput.append( "\n" ) print( "".join( ouput ) )
1
878,872,993,490
null
51
51
il = [int(k) for k in input().split()] H = il[0] W = il[1] # H : 縦 # W : 横 import math a = math.ceil(W/2) b = math.floor(W/2) c = math.ceil(H/2) d = math.floor(H/2) if H == 1 or W == 1: print("1") else: print(a*c + b*d)
H, W = map(int, input().split()) total = H*W if H == 1 or W == 1: ans = 1 elif total % 2 == 0: ans = total//2 else: total += 1 ans = total//2 print(ans)
1
50,650,962,838,936
null
196
196
a,b,c,d = map(int,input().split()) ans1 = a * c ans2 = a * d ans3 = b * c ans4 = b * d print(max(ans1,ans2,ans3,ans4))
a,b,c,d = map(int,input().split()) s = max(max(a*c,a*d),max(b*c,b*d)) print(s)
1
3,034,001,233,920
null
77
77
def main(): H = int(input()) W = int(input()) N = int(input()) print((N-1)//max(H,W) + 1) if __name__ == '__main__': main()
n = int(input()) x = 100000 for i in range(n): x = x*1.05 if x % 1000 == 0: pass else: x = x//1000 x = x+1 x = x*1000 print('{:.0f}'.format(x))
0
null
44,114,662,565,728
236
6
num_list=[] while True: num = input() if num == 0: break num_list.append(num) for num in num_list: print sum(map(int,list(str(num))))
N = int(input()) G = [[-1] * N for i in range(N)] ans = 0 for i in range(N): A = int(input()) for j in range(A): x, y = map(int, input().split()) G[i][x-1] = y for bit in range(2**N): honests = [] for i in range(N): if bit & (1<<i): honests.append(i) flag = True for j in honests: for k in range(N): if (k in honests) and G[j][k] == 0: flag = False elif(k not in honests) and G[j][k] == 1: flag = False if flag: ans = max(ans, len(honests)) print(ans)
0
null
61,365,950,637,072
62
262
H = int(input()) W = int(input()) N = int(input()) answer = 0 if H >= W: answer = N // H if N % H != 0: answer += 1 else: answer = N // W if N % W != 0: answer += 1 print(answer)
n = int(input()) s = input() count = 1 for i in range(n-1): if s[i+1] != s[i]: count = count + 1 print(count)
0
null
129,641,227,390,052
236
293
# -*- coding:utf-8 -*- def main(): List=[] for i in range(10): a=int(input()) List.append(a) List.sort(reverse=True) print(List[0]) print(List[1]) print(List[2]) if __name__ == '__main__': main()
def merge(a, left, mid, right): L = a[left:mid] + [INF] R = a[mid:right] + [INF] i = 0 j = 0 for k in range(left, right): global idx idx += 1 if( L[i] <= R[j] ): a[k] = L[i] i += 1 else: a[k] = R[j] j += 1 def merge_sort(a, left, right): if( left + 1 < right ): mid = (left + right) // 2 merge_sort(a, left, mid) merge_sort(a, mid, right) merge(a, left, mid, right) INF = 1000000000 idx = 0 n = int(input()) a = [int(i) for i in input().split()] merge_sort(a,0,len(a)) print(*a) print(idx)
0
null
59,418,191,508
2
26
n=int(input()) a=list(map(int,input().split())) ans=10**20 p=sum(a) q=0 for i in range(n-1): q+=a[i] ans=min(ans,abs(p-q-q)) print(ans)
n = int(input()) A = list(map(int, input().split())) for i in range(n - 1): A[i + 1] += A[i] minv = float('inf') for a in A[:-1]: minv = min(minv, abs(A[-1]/2 - a)) print(int(minv * 2))
1
142,245,947,724,272
null
276
276
from collections import defaultdict def main(): n = int(input()) a = list(map(int, input().split())) d = defaultdict(lambda : 0) ans = 0 for i, ai in enumerate(a, 1): num = str(ai+i) d[num] += 1 ans += d[str(i-ai)] print(ans) if __name__ == "__main__": main()
A,B = map(int,input().split()) Flag = True i = max(A,B) s = max(A,B) while Flag == True and i <= A*B: if i%A ==0 and i%B == 0: Flag = False i += s print(i-s)
0
null
69,421,233,249,576
157
256
import sys def solve(): input = sys.stdin.readline N = int(input()) A = [int(a) for a in input().split()] if N == 0 and A[0] > 1: print(-1) return 0 low, high = A[N], A[N] maxN = [0] * (N + 1) maxN[N] = A[N] Limit = [2 ** 50] * (N + 1) Limit[N] = A[N] for i in reversed(range(N)): leaf = A[i] Limit[i] = min(Limit[i], Limit[i+1] + leaf) if i <= 50: Limit[i] = min(pow(2, i), Limit[i]) low = (low + 1) // 2 + leaf high += leaf if low > Limit[i]: print(-1) break else: maxN[i] = min(high, Limit[i]) else: for i in range(N): if (maxN[i] - A[i]) * 2 <= maxN[i+1]: maxN[i + 1] = (maxN[i] - A[i]) * 2 print(sum(maxN)) return 0 if __name__ == "__main__": solve()
N = int(input()) A = list(map(int, input().split())) if N == 0 and A[0] == 1: print(1) exit() if A[0] != 0: print(-1) exit() sum_leaf = sum(A) ans = 1 before_top = 1 for i in range(1, len(A)): if A[i] <= before_top*2: ans += min(sum_leaf, before_top*2) before_top = min(sum_leaf, before_top*2) - A[i] sum_leaf -= A[i] else: print(-1) exit() print(ans)
1
19,011,799,948,388
null
141
141
import sys r=sys.stdin.readline N,M=map(int,r().split()) city=[[] for _ in range(N+1)] for _ in range(M): a,b=map(int,r().split()) city[a].append(b) city[b].append(a) check=[True]+[False]*(N) def dfs(v): stack=[v] while stack: cur=stack.pop() check[cur]=True for v in city[cur]: if not check[v]: stack.append(v) cnt=0 for i in range(1,N+1): if not check[i]: dfs(i) cnt+=1 print(cnt-1)
import networkx as nx n, m = map(int, input().split()) nodes = [0 for i in range(n)] L = [] for i in range(m): a, b = map(int, input().split()) L.append((a,b)) nodes[a-1] += 1 nodes[b-1] += 1 num = 0 for node in nodes: if node == 0: num += 1 graph = nx.from_edgelist(L) num += len(list(nx.connected_components(graph))) print(num-1)
1
2,293,817,887,340
null
70
70
import sys s = input() if len(s)%2 == 1: print('No') sys.exit() for i in range(len(s)//2): if s[2*i:2*i+2] != 'hi': print('No') sys.exit() print('Yes')
import string n = int(input()) s = '' lowCase = string.ascii_lowercase while n > 0: n -= 1 s += lowCase[int(n % 26)] n //= 26 print(s[::-1])
0
null
32,333,072,784,572
199
121
import math x, y = map(int, input().split()) MOD = 10**9+7 def combination(n, r, mod): r = min(r, n-r) num = 1 d = 1 for i in range(1, r+1): num = num * (n+1-i) % mod d = d * i % mod return num * pow(d, mod-2, mod) % mod if (x+y)%3 != 0: print (0) exit() n = (x+y)/3 yy = (2*x-y)/3 xx = (2*y-x)/3 if yy < 0: print (0) exit() if xx < 0: print (0) exit() if xx.is_integer() and yy.is_integer(): print (combination(int(xx+yy),int(xx),MOD)) else: print (0)
X, Y = map(int, input().split()) n = (2 * X - Y) // 3 m = (-X + 2 * Y) // 3 if n < 0 or m < 0 or (2 * X - Y) % 3 != 0 or (-X + 2 * Y) % 3 != 0: print(0) else: # (n+m)Cn 通り fac = [1, 1] finv = [1, 1] inv = [1, 1] MOD = 10 ** 9 + 7 for i in range(2, n + m + 1): fac.append(fac[i - 1] * i % MOD) inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD) finv.append(finv[i - 1] * inv[i] % MOD) print(fac[n+m] * (finv[n] * finv[m] % MOD) % MOD)
1
149,700,022,061,968
null
281
281
n = int(input()) ans = "" while n: n -= 1 ans += chr(ord('a') + (n % 26)) n //= 26 print(ans[::-1])
# 171 A X = input() print('a') if X.islower() else print('A')
0
null
11,515,041,537,190
121
119
from sys import exit import math import collections ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) x = ii() while 1: cnt = 0 for i in range(2,math.ceil(x**(1/2)),1): if x % i == 0: cnt = 1 break if cnt == 0: print(x) exit() x += 1
n=int(input()) r=int(n**0.5+1) ans=0 for i in range(2,r): e=0 while n%i==0: n//=i e+=1 k=1 while e>=k: e-=k ans+=1 k+=1 if n!=1: ans+=1 print(ans)
0
null
61,022,880,723,938
250
136
import math n = int(input()) x = list(map(int,input().split())) y = list(map(int,input().split())) p1 = p2 = p3 = p = 0 for x,y in zip(x,y): d = abs(x-y) p1 += d p2 += d**2 p3 += d**3 if d>p: p = d print('{0:.5f}\n{1:.5f}\n{2:.5f}\n{3:.5f}'.format(p1,math.sqrt(p2),math.pow(p3,1/3),p))
# -*- coding: utf-8 -*- def merge(A, left, mid, right): global cnt n1 = mid - left n2 = right - mid L = A[left:left+n1] R = A[mid:mid+n2] L.append(float('inf')) R.append(float('inf')) i = 0 j = 0 for k in range(left, right): cnt += 1 if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) // 2 mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) if __name__ == '__main__': n = int(input()) S = [int(s) for s in input().split(" ")] cnt = 0 mergeSort(S, 0, n) print(" ".join(map(str, S))) print(cnt)
0
null
161,742,085,778
32
26
N,M,K = map(int,input().split()) mod = 998244353 n = 200050 frac = [1]*(n+1) finv = [1]*(n+1) for i in range(n): frac[i+1] = (i+1)*frac[i]%mod finv[-1] = pow(frac[-1],mod-2,mod) for i in range(1,n+1): finv[n-i] = finv[n-i+1]*(n-i+1)%mod def nCr(n,r): if n<0 or r<0 or n<r: return 0 r = min(r,n-r) return frac[n]*finv[n-r]*finv[r]%mod # M* n-1Ck*1^k*(M-1)^(N-1-k) ans = 0 for i in range(K+1): tmp=(M*nCr(N-1,i))%mod tmp*=pow(M-1,N-1-i,mod) ans += tmp%mod print(ans%mod)
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 998244353 ############# # Main Code # ############# # N:ブロック # M:色(バリエーション) # K:隣合う組み # N, M, K = 6, 2, 3のとき # K = 0 のとき # 121212, 212121 # K = 1のとき, # 12121 のどこかに同じ数字を挟み込めば # 112121, 122121という風にできる # K = 2のとき # 1212 のどこかに同じ数字を挟む を2回行う # 112212, 112122もできるし # 111212, 122212もできる N, M, K = getNM() # 重複組み合わせのため # 繰り返し使うのでこのタイプ Y = N + K + 1 fact =[1] #階乗 for i in range(1, Y + 1): fact.append(fact[i - 1] * i % mod) facv = [0] * (Y + 1) #階乗の逆元 facv[-1] = pow(fact[-1], mod - 2 , mod) for i in range(Y - 1, -1, -1): facv[i] = facv[i + 1] * (i + 1) % mod def cmb(n, r): if n < r: return 0 return fact[n] * facv[r] * facv[n - r] % mod ans = 0 for i in range(K + 1): opt = M * pow(M - 1, N - i - 1, mod) * cmb(N - i + i - 1, i) ans += opt % mod print(ans % mod)
1
23,212,326,118,458
null
151
151
tp = hp = 0 for i in range(int(input())): taro, hana = map(list, input().split()) short = min(len(taro), len(hana)) result = 0 for k in range(short): if ord(taro[k]) != ord(hana[k]): result = ord(taro[k]) - ord(hana[k]) break if not result: if len(taro) < len(hana): result = -1 elif len(taro) > len(hana): result = 1 if result > 0: tp += 3 elif result < 0: hp += 3 else: tp += 1 hp += 1 print(tp, hp)
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入 import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(input()) NUM = [0] * 500000 for x in range(1,101): for y in range(1,101): for z in range(1,101): nya = x**2 + y**2 + z**2 + x*y + y*z + z*x NUM[nya] += 1 n = I() for i in range(1,n+1): print(NUM[i])
0
null
4,971,694,711,622
67
106
N,K = map(int, input().split()) A = list(map(int, input().split())) k = K.bit_length() dv = [[0]*N for _ in range(k)] dv[0] = [a-1 for a in A] for turn in range(1,k): for town in range(N): dv[turn][town] = dv[turn-1][dv[turn-1][town]] a = 0 for i in range(k): if (K>>i)&1: a = dv[i][a] print(a+1)
N=int(input()) cnt=0 ans="No" for i in range(N): x,y=input().split() if x==y: cnt=cnt+1 else: cnt=0 if cnt>=3: ans="Yes" print(ans)
0
null
12,571,544,412,640
150
72
N = int(input()) A = list(map(int,input().split())) Q = int(input()) cnt_dict = {} s = sum(A) ans = 0 for item in A: if item not in cnt_dict: cnt_dict[item] = 0 cnt_dict[item] += 1 for _ in range(Q): X,Y = map(int,input().split()) if X not in cnt_dict: cnt_dict[X] = 0 if Y not in cnt_dict: cnt_dict[Y] = 0 s -= cnt_dict[X] * X s += cnt_dict[X] * Y cnt_dict[Y] += cnt_dict[X] cnt_dict[X] = 0 print(s) ''' #初期案 遅すぎ N = int(input()) A = list(map(int,input().split())) Q = int(input()) for i in range(Q): X,Y = map(int,input().split()) ans = 0 for j in range(N): if A[j] == X: ans += Y A[j] = Y else: ans += A[j] print(ans) '''
N=int(input()) A=list(map(int,input().split())) cnt=[0 for _ in range(100001)] for i in range(N): cnt[A[i]]+=1 ans=sum(A) Q=int(input()) for _ in range(Q): B,C=map(int,input().split()) cnt[C]+=cnt[B] ans+=(C-B)*cnt[B] cnt[B]=0 print(ans)
1
12,094,968,423,102
null
122
122
n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() mod=10**9+7 ans=1 i=0 j=-1 k_1=k while k_1>1: if a[i]*a[i+1]>a[j]*a[j-1]: ans=ans*a[i]*a[i+1]%mod i+=2 k_1-=2 else: ans=ans*a[j]%mod j-=1 k_1-=1 if k_1==1: ans=ans*a[j]%mod if a[-1]<0 and k%2==1: ans=1 for i in a[n-k:]: ans=ans*i%mod print(ans)
n = int(input()) if (n%2 == 1): n = n + 1 print(int(n/2))
0
null
34,442,703,564,230
112
206
s = list(input()) b = 0 if len(s)%2==1: for a in range(int((len(s)-1)/2)): if s[a]!=s[len(s)-a-1] and b==0: b = 1 else: b = 1 if b == 0: for c in range(int((len(s)-1)/4+1)): if s[c]==s[int((len(s)-1)/2-c-1)]==s[int((len(s)+1)/2+c)]==s[len(s)-c-1] and b==0: b = 0 else: b = 1 if b == 0: print("Yes") elif b == 1: print("No")
S = input() N = len(S) S1 = S[0:(N-1)//2] S2 = S[(N+3)//2-1:] print('Yes' if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1] else 'No')
1
46,471,595,133,628
null
190
190
# coding: utf-8 import sys from operator import itemgetter sysread = sys.stdin.readline read = sys.stdin.read from heapq import heappop, heappush #from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import combinations, product #import bisect# lower_bound etc #import numpy as np #import queue# queue,get(), queue.put() def run(): N = int(input()) current = 0 ways = [] dic = {'(': 1, ')': -1} SS = read().split() for S in SS: path = [0] for s in S: path.append(path[-1]+ dic[s]) ways.append((path[-1], min(path))) ways_pos = sorted([(a,b) for a,b in ways if a >= 0], key = lambda x:x[0], reverse=True) ways_neg = sorted([(a,b) for a,b in ways if a < 0], key = lambda x:(x[0] - x[1]), reverse=True) tmp = [] for go, max_depth in ways_pos: if current + max_depth >= 0: current += go else: tmp.append((go, max_depth)) for go, max_depth in tmp: if current + max_depth >= 0: current += go else: print('No') return None tmp =[] for go, max_depth in ways_neg: if current + max_depth >= 0: current += go else: tmp.append((go, max_depth)) for go, max_depth in tmp: if current + max_depth >= 0: current += go else: print('No') return None if current == 0: print('Yes') else: print('No') if __name__ == "__main__": run()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # 998244353 input=lambda:sys.stdin.readline().rstrip() from bisect import bisect_left def resolve(): n, m = map(int,input().split()) A = list(map(int,input().split())) A.sort() def count(x): # the number of (i, j)s s.t. A[i] + A[j] >= x res = 0 for a in A: idx = bisect_left(A, x - a) res += n - idx return res left = 0 right = 200001 while right - left > 1: mid = (left + right) // 2 if count(mid) < m: right = mid else: left = mid x = right res = 0 for a in A: idx = bisect_left(A, x - a) res += 2 * a * (n - idx) res += (x - 1) * (m - count(x)) print(res) resolve()
0
null
65,638,706,595,964
152
252
import sys def solve(): input = sys.stdin.readline N = int(input()) P = [input().strip("\n").split() for _ in range(N)] X = input().strip("\n") sec = 0 lastId = 0 for i in range(N): if P[i][0] == X: lastId = i break for i in range(lastId + 1, N): sec += int(P[i][1]) print(sec) return 0 if __name__ == "__main__": solve()
n=int(input()) a=[] for i in range(n): s,t=input().split() a.append([s,int(t)]) x=input() sum1=0 for j in range(n): if a[j][0]!=x: sum1+=a[j][1] else: sum1+=a[j][1] break sum2=0 for i in range(n): sum2+=a[i][1] print(sum2-sum1)
1
97,274,400,821,880
null
243
243
n = int(input()) s = input() res = "No" if n%2 == 0 and s[:n//2] *2 ==s:res ="Yes" print(res)
n = int(input()) s = list(input()) m = n//2 if n%2 != 0: ans = "No" else: for i in range(m): if s[i] != s[m+i]: ans = "No" break ans = "Yes" print(ans)
1
146,983,253,395,942
null
279
279
def stringconcant(S,T): a=S b=T c=a+b return c S,T = input().split() a = stringconcant(T,S) print(a)
S, T = input().split(' ') print(T + S)
1
103,053,898,280,002
null
248
248
X,Y = map(int,input().split()) ans='No' for i in range(0,X+1): #print(i) if i * 2 + (X - i) * 4 == Y and X>=i: ans = 'Yes' break print(ans)
x,y=map(int,input().split()) if (x*2) <= y <= (x*4) and y%2 ==0: print('Yes') else: print('No')
1
13,740,868,787,848
null
127
127
n = int(input()) a = list(map(int, input().split())) last = 0 count = 0 flag = True while flag: flag = False for i in range( n-1, last, -1 ): if a[i] < a[i-1]: t = a[i] a[i] = a[i-1] a[i-1] = t count += 1 flag = True last += 1 print(*a) print(count)
n = int(input()) numbers = [int(i) for i in input().split(" ")] flag = 1 cnt = 0 while flag: flag = 0 for j in range(n - 1, 0, -1): if numbers[j] < numbers[j - 1]: numbers[j], numbers[j - 1] = numbers[j - 1], numbers[j] flag = 1 cnt += 1 numbers = map(str, numbers) print(" ".join(numbers)) print(cnt)
1
16,686,079,410
null
14
14
s = int(input()) print((1000-s%1000)%1000)
import math def abc173a_payment(): n = int(input()) print(math.ceil(n/1000)*1000 - n) abc173a_payment()
1
8,507,019,706,720
null
108
108
X = int(input()) happy = 0 happy += (X // 500) * 1000 X %= 500 happy += (X // 5) * 5 print(happy)
from collections import deque def bfs(i, j): dist = [[0] * w for _ in range(h)] q = deque() q.append((i, j)) dist[i][j] = 1 while q: nx, ny = q.pop() for dx, dy in D: X, Y = nx + dx, ny + dy if X < 0 or Y < 0 or X >= h or Y >= w: continue if m[X][Y] == "#": continue if dist[X][Y] != 0: continue q.appendleft((X, Y)) dist[X][Y] = 1 + dist[nx][ny] mx = 0 for i in dist: mx = max(mx, max(i)) return mx h, w = map(int, input().split()) m = [input() for _ in range(h)] D = [(-1, 0), (0, -1), (1, 0), (0, 1)] ans = 0 for i in range(h): for j in range(w): if m[i][j] == ".": ans = max(ans, bfs(i, j)) print(ans - 1)
0
null
68,785,598,482,470
185
241
def main(): s = input() p = input() if p in s*2: print("Yes") else: print("No") if __name__ == '__main__': main()
H, W, M = list(map(int, input().split())) h = [0] * H w = [0] * W hw = {} for _ in range(M): a, b = list(map(int, input().split())) h[a - 1] += 1 w[b - 1] += 1 temp = "x" + str(a - 1) + "y" + str(b - 1) hw[temp] = 1 hm = max(h) wm = max(w) hp = [i for i, v in enumerate(h) if v == hm] wp = [i for i, v in enumerate(w) if v == wm] for x in hp: for y in wp: temp = "x" + str(x) + "y" + str(y) if temp not in hw: print(hm + wm) exit() else: print(hm + wm - 1)
0
null
3,235,203,577,218
64
89
import math a,b,c = [float(s) for s in input().split()] r = c * math.pi / 180 h = math.sin(r) * b s = a * h / 2 x1 = a y1 = 0 if c == 90: x2 = 0 else: x2 = math.cos(r) * b y2 = h d = math.sqrt((math.fabs(x1 - x2) ** 2) + (math.fabs(y1 - y2) ** 2)) l = a + b + d print(s) print(l) print(h)
#!/usr/bin/python3 # -*- coding: utf-8 -*- import sys import math a, b, c = map(float, sys.stdin.readline().split()) degree = abs(180-abs(c))*math.pi / 180 height = abs(b * math.sin(degree)) pos_x = b * math.cos(degree) + a edge_x = (height**2 + pos_x**2) ** 0.5 print(round(a * height / 2, 6)) print(round(a + b + edge_x, 6)) print(round(height, 6))
1
176,183,185,112
null
30
30
import math n=int(input()) def koch(d,p1,p2): if d==0: return s=[0,0] t=[0,0] u=[0,0] s[0]=2/3*p1[0]+1/3*p2[0] s[1]=2/3*p1[1]+1/3*p2[1] t[0]=1/3*p1[0]+2/3*p2[0] t[1]=1/3*p1[1]+2/3*p2[1] u[0]=s[0]+(t[0]-s[0])*math.cos(math.pi/3)-(t[1]-s[1])*math.sin(math.pi/3) u[1]=s[1]+(t[0]-s[0])*math.sin(math.pi/3)+(t[1]-s[1])*math.cos(math.pi/3) koch(d-1,p1,s) print(*s) koch(d-1,s,u) print(*u) koch(d-1,u,t) print(*t) koch(d-1,t,p2) print(0,0) koch(n,[0,0],[100,0]) print(100,0)
S = input() N = len(S) if S == S[::-1]: if S[:(N-1)//2] == S [(N+1)//2:]: print("Yes") else: print("No") else: print("No")
0
null
23,050,054,483,102
27
190
import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10**9) INF = 10**9 mod = 10**9+7 N = i() table = [[0]*9 for _ in range(9)] for i in range(N): s = str(i+1) a,b = int(s[0]),int(s[-1]) if b == 0: continue table[a-1][b-1] += 1 ans = 0 for i in range(9): for j in range(9): ans += table[i][j]*table[j][i] print(ans)
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp #?????????????????? #?????????????´?????¢????????????£????????????????????????????????¨???????¢?????????¨ #?????°??¢??°???????¨???????????¢???????????????? def bubble_sort(target_list): list_length = len(target_list) flag = True change_count = 0 top_index = 1 while flag: flag = False for i in range(top_index, list_length)[::-1]: if target_list[i] < target_list[i - 1]: tmp = target_list[i] target_list[i] = target_list[i - 1] target_list[i - 1] = tmp change_count += 1 flag = True top_index += 1 return change_count def main(): n_list = int(input()) target_list = [int(n) for n in input().split()] cc = bubble_sort(target_list) print(*target_list) print(cc) if __name__ == "__main__": main()
0
null
43,343,898,214,240
234
14
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) INF = float("inf") import bisect def count(s): a = 0 aa = 0 b = 0 bb = 0 for i in range(len(s)): if s[i] == ")": if aa == 0: a = a + 1 else: aa = aa - 1 if s[i] == "(": aa = aa + 1 if s[len(s)-1-i] == "(": if bb == 0: b = b + 1 else: bb = bb - 1 if s[len(s)-1-i] == ")": bb = bb + 1 return [a, b] N = int(input()) c = [] d = [] for i in range(N): s = input() e = count(s) if e[1] - e[0] >= 0: c.append(e) if e[0] - e[1] > 0: d.append(e) c.sort(key=lambda x: x[0]) d.sort(key=lambda x: x[1], reverse=True) c = c + d # print(c) f = 0 for cc in c: f = f - cc[0] if f < 0: print("No") sys.exit() f = f + cc[1] if f == 0: print("Yes") else: print("No")
import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] IN=lambda : map(int, input().split()) LIN=lambda : list(IN()) mod=1000000007 #+++++ def main(): #a = int(input()) h,w,k = IN() ss=0 ret=[] kv=1 for i in range(h): wd = input() if ss >= 0 and wd == '.'*w: ss+=1 elif wd == '.'*w: al=ret[-1][:] ret.append(al) else: al=[] stf=True for c in wd: if stf and c == '#': stf = False elif c == '#': kv+=1 al.append(kv) else: kv+=1 if ss >= 0: for i in range(ss+1): ret.append(al) ss=-1 else: ret.append(al) for l in ret: print(*l) #+++++ isTest=False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform =='ios': if input_method==input_methods[0]: ic=input_clipboard() input = lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else: pass isTest=True else: pass #input = sys.stdin.readline ret = main() if ret is not None: print(ret)
0
null
83,969,408,353,198
152
277
n=int(input()) A=list(map(int,input().split())) r = [-1]*n for i,a in enumerate(A): r[a-1]=i+1 for r2 in r: print(r2)
import sys input = sys.stdin.readline a, b = input()[:-1].split() print(min(''.join(a for i in range(int(b))), ''.join(b for i in range(int(a)))))
0
null
132,364,369,315,682
299
232
n = int(input()) buf = list(map(int,input().split())) a = [] for i in range(n): a.append([buf[i],i]) a = sorted(a,reverse=True) dp = [[0]*(n+1) for i in range(n+1)] for i in range(n): for j in range(n-i): cur = i+j temp1 = dp[i][j]+a[cur][0]*abs(n-1-a[cur][1]-j) temp2 = dp[i][j]+a[cur][0]*abs(a[cur][1]-i) dp[i+1][j] = max(dp[i+1][j],temp2) dp[i][j+1] = max(dp[i][j+1],temp1) print(max([max(i) for i in dp]))
N = int(input()) A = list(map(int, input().split())) A = sorted([(a, p) for p, a in enumerate(A)], reverse=True) dp = [[0]*(i+1) for i in range(N+1)] for z in range(N): for y in range(z+1): dp[z+1][y] = max(A[z][0]*(A[z][1]-(z-y))+dp[z][y],dp[z+1][y]) dp[z+1][y+1]= A[z][0]*((N-y-1)-A[z][1])+dp[z][y] print(max(dp[-1]))
1
33,611,504,685,320
null
171
171
def aaaa(): n=int(input()) a=list(map(int, input().split())) ans=0 if a[0]>0: if a[0]==1 and n==0: return 1 else: return -1 return -1 nezen=1 hazen=0 line=[] liha=[] line.append(nezen) liha.append(hazen) su=0 su=sum(a[x] for x in range(len(a))) for x in range(1,n+1): if nezen<=0: return -1 ha=a[x] su-=ha ne=min(nezen*2-ha,su) nezen=ne line.append(ne) liha.append(ha) if line[n]<0: return -1 line[n]=0 for x in range(len(line)): ans+=line[x]+liha[x] return ans print(aaaa())
n,*l=map(int,open(0).read().split()) e=[1] for i in range(n): e+=[(e[-1]-l[i])*2] a=t=0 for i in range(n,-1,-1): if l[i]>e[i]: print(-1); break t=min(l[i]+t,e[i]); a+=t else: print(a)
1
18,837,700,057,098
null
141
141
#abc149-d n,k=map(int,input().split()) s,p,r=map(int,input().split()) f={'s':s,'p':p,'r':r} t=str(input()) ans=0 for i in range(k): a=i+k last=t[i] ans+=f[last] while a<n-k: if t[a]==last: if t[a+k]==last: if last=='s': last='r' else: last='s' else: if last=='s': if t[a+k]=='r': last='p' else: last='r' elif last=='r': if t[a+k]=='s': last='p' else: last='s' else: if t[a+k]=='r': last='s' else: last='r' else: last=t[a] ans+=f[last] a+=k if a<n: if t[a]!=last: ans+=f[t[a]] print(ans)
import sys input = sys.stdin.readline (n, k), (r, s, p), t = map(int, input().split()), map(int, input().split()), input()[:-1] d, res = {'r': p, 's': r, 'p': s}, 0 for i in range(k): b = False for j in range(i, n, k): if i == j: res += d[t[j]]; b = False; continue if (t[j] != t[j-k]) | b: res += d[t[j]]; b = False else: b = True print(res)
1
107,165,268,111,200
null
251
251
import numpy as np import numpy.linalg as linalg X, Y = map(int, input().split()) if Y%2 == 1: print('No') else: A = np.array([[1, 1], [2, 4]]) A_inv = linalg.inv(A) B = np.array([X , Y]) C = np.dot(A_inv, B) if C[0] >= 0 and C[1] >= 0 : print('Yes') else: print('No')
N = int(input()) A = list(map(int, input().split())) x = 0 ans = list() for ai in A: x = x ^ ai for ai in A: ans.append(x ^ ai) print(*ans)
0
null
13,135,912,018,320
127
123
def main(): X = int(input()) v = 100 ans = 0 while v < X: ans += 1 v = int(v * 101 // 100) print(ans) if __name__ == '__main__': main()
x = int(input()) i = 0 ganpon = 100 while True: if x > ganpon: ganpon += int(ganpon//100) i += 1 else: print(i) break
1
27,042,774,033,818
null
159
159
l = [x+' '+y for x in['S','H','C','D']for y in[str(i+1)for i in range(13)]] for n in range(int(input())): l.remove(input()) for i in l: print(i)
n = input() #a,b = map(str,raw_input().split()) a = [raw_input() for i in range(n)] j=0 for i in range(1,14): for j in range(n): if a[j] == 'S %s' % i: break elif j==n-1: print 'S %s' % i for i in range(1,14): for j in range(n): if a[j] == 'H %s' % i: break elif j==n-1: print 'H %s' % i for i in range(1,14): for j in range(n): if a[j] == 'C %s' % i: break elif j==n-1: print 'C %s' % i for i in range(1,14): for j in range(n): if a[j] == 'D %s' % i: break elif j==n-1: print 'D %s' % i
1
1,046,657,707,208
null
54
54
import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) input = sys.stdin.readline mod = 10**9+7 Max = sys.maxsize def l(): #intのlist return list(map(int,input().split())) def m(): #複数文字 return map(int,input().split()) def onem(): #Nとかの取得 return int(input()) def s(x): #圧縮 a = [] if len(x) == 0: return [] aa = x[0] su = 1 for i in range(len(x)-1): if aa != x[i+1]: a.append([aa,su]) aa = x[i+1] su = 1 else: su += 1 a.append([aa,su]) return a def jo(x): #listをスペースごとに分ける return " ".join(map(str,x)) def max2(x): #他のときもどうように作成可能 return max(map(max,x)) def In(x,a): #aがリスト(sorted) k = bs.bisect_left(a,x) if k != len(a) and a[k] == x: return True else: return False def pow_k(x, n): ans = 1 while n: if n % 2: ans *= x x *= x n >>= 1 return ans def nibu(x,n,r): ll = 1 rr = r while True: mid = (ll+rr)//2 if rr == mid: return ll if cou(x,mid) <= n: rr = mid else: ll = mid+1 def cou(x,le): co = 0 for i in range(len(x)): if le != 0: co += -(-x[i]//le) - 1 return co n,k = m() a = l() left = 0 right = 10**9 aaa = nibu(a,k,right) print(aaa)
while True: N=input() if N=="0": break else: print(sum([int(x) for x in list(N)]))
0
null
3,991,833,479,288
99
62
k, n = [int(i) for i in input().split()] A = [int(i) for i in input().split()] max_len = 0 for i in range(len(A) - 1): if max_len < A[i + 1] - A[i]: max_len = A[i + 1] - A[i] # A[n] -> A[0] l = (k - A[-1]) + A[0] if max_len < l: max_len = l print(k - max_len)
def count(word, text): """Count the word in text. Counting is done case-insensitively. >>> count('a', 'A b c a') 2 >>> count('computer', 'Nurtures computer scientists' \ + ' and highly-skilled computer engineers' \ + ' who will create and exploit "knowledge"' \ + ' for the new era. Provides an outstanding' \ + ' computer environment.') 3 """ return (text .lower() .split() .count(word.lower())) def run(): word = input() text = "" line = input() while line != "END_OF_TEXT": text += line + "\n" line = input() print(count(word, text)) if __name__ == "__main__": run()
0
null
22,624,312,296,988
186
65
#!/usr/bin/env python3 import math x = int(input()) ans = 360//math.gcd(360, x) print(ans)
import sys x = int(input()) ans = 2 while(True): if x*ans % 360 == 0: print(ans) sys.exit() ans +=1
1
13,128,199,217,600
null
125
125
from collections import deque import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def bfs(field, sx, sy, seen): queue = deque([(sx, sy)]) seen[sx][sy] += 1 while queue: x, y = queue.popleft() for dx, dy in [(-1, 0), (0, 1), (1, 0), (0, -1)]: nx = x + dx ny = y + dy if seen[nx][ny] == -1 and field[nx][ny] != "#": seen[nx][ny] = seen[x][y] + 1 queue.append((nx, ny)) return seen[x][y] def main(): H,W = map(int, readline().split()) c = ["#" * (W + 2)] for _ in range(H): c.append("#" + readline().strip() + "#") c.append("#" * (W + 2)) ans = 0 for sx in range(1,H+1): for sy in range(1,W+1): if c[sx][sy] == ".": seen = [[-1] * (W + 2) for i in range(H+2)] dist = bfs(c, sx, sy, seen) ans = max(ans, dist) print(ans) if __name__ == "__main__": main()
from collections import Counter N = int(input()) d = list(map(int, input().split())) MOD = 998244353 dn = Counter(d) ans = 1 if dn[0] != 1 or d[0] != 0: ans = 0 else: for i in range(1, max(d)+1): ans *= (dn[i-1]**dn[i]) ans %= MOD print(ans)
0
null
124,141,000,032,962
241
284
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() P=LI() Q=LI() import itertools cnt=0 p=0 q=0 for ite in itertools.permutations(range(1,N+1)): if P==list(ite): p=cnt if Q==list(ite): q=cnt cnt+=1 print(abs(p-q)) main()
S = input() if S[1:2] == "R": print("ABC") else: print("ARC")
0
null
62,426,053,159,360
246
153
import sys official_house = {} for b in range(1, 5): for f in range(1, 4): for r in range(1, 11): official_house[(b, f, r)] = 0 n = int(sys.stdin.readline()) for line in sys.stdin: (b, f, r, v) = [int(i) for i in line.split()] official_house[(b, f, r)] += v for b in range(1, 5): if b != 1: print("####################") for f in range(1, 4): for r in range(1, 11): print(" %d" % official_house[(b, f, r)], end="") print()
''' Created on 2020/08/20 @author: harurun ''' def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write N=int(pin()) print((N-1)//2) return main()
0
null
77,336,899,168,212
55
283
h=int(input()) w=int(input()) n=int(input()) print(-(-n//max(h,w)))
from itertools import product n = int(input()) test = [] for i in range(n): a = int(input()) test.append([list(map(int, input().split())) for i in range(a)]) ans = 0 for i in product(range(2), repeat=n): flag = True for j in range(n): if i[j] == 1: for s in test[j]: if i[s[0]-1] != s[1]: flag = False break if flag == True: cnt = i.count(1) if cnt > ans: ans = cnt print(ans)
0
null
104,918,579,495,938
236
262
#submit 16999743 a, b = input().split() a = int(a) b1, b2 = b.split('.') ans = a * (int(b1) * 100 + int(b2)) // 100 print(ans)
a,b=map(int,input().split()) dic={1:3*10**5,2:2*10**5,3:1*10**5} c=0 if a in dic and b in dic: if a==1 and b==1: c+=dic[a]+dic[b]+4*10**5 print(c) else: c+=dic[a]+dic[b] print(c) elif a in dic and b not in dic: c+=dic[a] print(c) elif b in dic and a not in dic: c+=dic[b] print(c) else: print(c)
0
null
78,405,325,331,252
135
275
x = int(input()) A = str() for i in range(x): A = A + 'ACL' i += 1 print(A)
s = raw_input() n1, n2 = s.split() n1 = int(n1) n2 = int(n2) flag = True if n1 < 0 or n1 > 9: flag = False if n2 < 0 or n2 > 9: flag = False if flag: print n1 * n2 else: print -1
0
null
80,541,408,024,452
69
286
n = int(input()) l = list(map(int, input().split())) ans = 1000000 for p in range(1,101): d = 0 for x in l: d += (x-p)**2 ans = min(d,ans) print(ans)
X, K, D = map(int, input().split()) X = abs(X) a = K*D if X >= a: result = X-a else: b = X//D c = (X-b*D) d = abs(X-(b+1)*D) if c < d: if b%2==K%2: result = c else: result = d else: if (b+1)%2==K%2: result=d else: result=c print(result)
0
null
35,021,140,094,240
213
92
from collections import deque x = deque() for i in range(int(input())): com = input() if com == "deleteFirst": x.popleft() elif com == "deleteLast": x.pop() else: com,n = com.split() if com == "insert": x.appendleft(n) elif com == "delete": try: x.remove(n) except: pass print(*x)
from math import sqrt x1, y1, x2, y2 = map(float, input().split()) X = abs(x1 - x2) Y = abs(y1 - y2) print(sqrt(X**2 + Y**2))
0
null
105,284,205,640
20
29
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, K = map(int, read().split()) X = list(map(int, str(N))) L = len(X) dp1 = [[0] * (K + 1) for _ in range(L + 1)] dp2 = [[0] * (K + 1) for _ in range(L + 1)] dp1[0][0] = 1 for i, x in enumerate(X): for j in range(K + 1): if x != 0: if j > 0: dp1[i + 1][j] = dp1[i][j - 1] else: dp1[i + 1][j] = dp1[i][j] if j > 0: dp2[i + 1][j] = dp2[i][j - 1] * 9 if x != 0: dp2[i + 1][j] += dp1[i][j - 1] * (x - 1) dp2[i + 1][j] += dp2[i][j] if x != 0: dp2[i + 1][j] += dp1[i][j] print(dp1[L][K] + dp2[L][K]) return if __name__ == '__main__': main()
N = int(input()) A = [0]*(N) for i in input().split(): A[int(i)-1] = A[int(i)-1]+1 for i in A: print(i)
0
null
54,464,306,050,718
224
169
from collections import Counter n = int(input()) a = list(map(int, input().split())) s = set(a) c = Counter(a) t = [0] * (10**6 + 1) for i in s: for j in range(i, 10**6+1, i): t[j] += 1 ans = len([1 for i in s if t[i] == 1 and c[i] == 1]) print(ans)
#!/usr/bin/env python3 import sys input = sys.stdin.readline def INT(): return int(input()) def MAP(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def main(): N = INT() A = LI() RGB = [0,0,0] answer = 1 MOD = 10**9+7 for i in range(N): if RGB.count(A[i]) == 0: print(0) return answer *= RGB.count(A[i]) answer %= MOD for j in range(3): if RGB[j] == A[i]: RGB[j] += 1 break print(answer) return if __name__ == '__main__': main()
0
null
72,119,591,251,372
129
268
input_value = input() value = int(input_value) print(value**3)
import sys while(1): H,W = map(int, raw_input().split()) if H==0 and W==0: break for i in range(H): for j in range(W): sys.stdout.write("#") print "" print ""
0
null
522,462,871,348
35
49
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() class SWAG(object): def __init__(self,dot): self.__front=[] self.__back=[] self.__dot=dot def __bool__(self): return True if(self.__front or self.__back) else False def __len__(self): return len(self.__front)+len(self.__back) def append(self,x): back=self.__back if(not back): back.append((x,x)) else: back.append((x,self.__dot(back[-1][1],x))) def popleft(self): assert(self) front=self.__front; back=self.__back if(not front): front.append((back[-1][0],back[-1][0])) back.pop() while(back): front.append((back[-1][0],self.__dot(back[-1][0],front[-1][1]))) back.pop() front.pop() def sum(self): assert(self) front=self.__front; back=self.__back if(not front): return back[-1][1] elif(not back): return front[-1][1] else: return self.__dot(front[-1][1],back[-1][1]) def resolve(): n,m=map(int,input().split()) S=list(map(int,input())) swag=SWAG(min) dp=[INF]*(n+1) dp[n]=0 for i in range(n-1,-1,-1): if(i+1+m<=n): swag.popleft() swag.append(dp[i+1]) if(S[i]==1): continue dp[i]=swag.sum()+1 if(dp[0]==INF): print(-1) return ans=[] now=0 next=0 while(now!=n): next+=1 if(dp[next]!=INF and dp[now]!=dp[next]): ans.append(next-now) now=next print(*ans) resolve()
x=int(input()) if 29>x>(-40): print('No') elif x>=30: print('Yes') elif x<-40: print('No') else: print('No')
0
null
72,041,589,653,440
274
95
a=input() print a+a**2+a**3
a = int(input()) print(a*(1+a*(1+a)))
1
10,231,214,785,848
null
115
115
s, S = divmod(input(), 60) H, M = divmod(s, 60) print '%d:%d:%d' %(H,M,S)
from math import ceil, floor def resolve(): N = int(input()) tax = 0.08 if floor(ceil(N/(1+tax))*(1+tax)) == N: print(ceil(N/(1+tax))) else: print(":(") if __name__ == "__main__": resolve()
0
null
63,147,781,501,840
37
265
def main(): x,y = list(map(int,input().split())) ans=0 for i in range(0,x+1): if 2*i+4*(x-i)==y: ans=1 if ans==1: print("Yes") else: print("No") main()
X, Y = map(int, input().split()) if Y % 2 == 0 and 0 <= (4 * X - Y) / 2 <= X: print("Yes") else: print("No")
1
13,829,914,794,930
null
127
127
n=list(map(int,input().split())) a=list(map(int,input().split())) count=0 for i in range(0,len(a)): if n[1]<=a[i]: count+=1 print(count)
n,k=[int(s) for s in input().split()] h=[int(j) for j in input().split()] r=0 for i in range(n): if k<=h[i]: r=r+1 print(r)
1
179,103,324,812,438
null
298
298
import math x1,y1,x2,y2=map(float,input().split()) a=(x2-x1)**2+(y2-y1)**2 l=math.sqrt(a) print(f'{l:.8f}')
x1, y1, x2, y2 = map(float, input().split()) x = abs(x2 - x1) y = abs(y2 - y1) dis = (x ** 2 + y ** 2) ** (1 / 2) dis = round(dis, 8) print("{}" .format(dis))
1
160,744,503,528
null
29
29
N,K = map(int,input().split()) if N % K >= abs(N % K - K): print(abs(N % K - K)) else: print(N % K)
import math import sys readline = sys.stdin.readline def main(): h1, m1, h2, m2, k = map(int, readline().rstrip().split()) print((max(0, (h2 - h1) * 60 + (m2 - m1) - k))) if __name__ == '__main__': main()
0
null
28,557,437,727,700
180
139
H, W = list(map(int, input().split())) while H != 0 or W != 0 : print('#' * W) for i in range(H-2) : print('#', end = '') print('.' * (W - 2), end = '') print('#') print('#' * W) print() H, W = list(map(int, input().split()))
from sys import stdin,stdout def fn(pos,res,k): if pos==n:return (k==0) ans=0 if (pos,res,k) in dp:return dp[pos,res,k] cur=ord(s[pos])-48 if res: for d in range(cur+1): if d==0:ans+=fn(pos+1,d==cur,k) elif d!=0 and k>0:ans+=fn(pos+1,d==cur,k-1) else: for d in range(10): if d == 0:ans += fn(pos + 1,0, k) elif d != 0 and k > 0:ans += fn(pos + 1,0, k - 1) dp[pos,res,k]=ans return ans #a,b=map(int,stdin.readline().split()) s=input() n=len(s) k1=int(stdin.readline()) dp={} ans=0 for d in range(10): if d+48<=ord(s[0]): ans+=fn(1,(d==ord(s[0])-48),(k1-(d!=0))) print(ans)
0
null
38,251,866,630,208
50
224
# ABC158 C - Tax Increase a,b = map(int,input().split()) import math c=10000 for i in range(1200): if math.floor(i*0.08)==a and math.floor(i*0.10)==b: c = min(c,i) if c==10000: print(-1) exit() print(c)
import numpy as np k,n = map(int, input().split()) a = np.array(list(map(int, input().split()))) a.sort() dif = np.diff(a, n=1) maximum = max(dif.max(), a[0]+(k-a[-1])) print(k-maximum)
0
null
49,913,261,424,140
203
186
from math import gcd def readinput(): n,m=map(int,input().split()) a=list(map(int,input().split())) return n,m,a def lcm(a,b): return a*b//gcd(a,b) def main(n,m,a): #s=set(a) #print(s) x=a[0]//2 for i in range(1,n): x=lcm(x,a[i]//2) #print(x) gusubai=False kisubai=False for i in range(n): if x%a[i]!=0: gusubai=True else: kisubai=True y=m//x #print(y,x,m) if gusubai and not kisubai: ans=y//2+y%2 elif gusubai and kisubai: ans=0 else: ans=y return ans if __name__=='__main__': n,m,a=readinput() ans=main(n,m,a) print(ans)
n,m=map(int, input().split()) a=[int(x) for x in input().split()] kaisuu=0 for i in a: zantei=0 while True: if i%2==0: zantei+=1 i//=2 else: break if kaisuu==0: kaisuu=zantei else: if kaisuu!=zantei: print(0) exit() sks=a[0]//2 import math for i in range(1,len(a)): sks=sks*(a[i]//2)//(math.gcd(sks,a[i]//2)) ans=int(m/(2*sks)+(1/2)) print(ans)
1
101,759,324,384,630
null
247
247
while 1: h,w=map(int,input().split()) if h==0 and w==0: break for y in range(h): print(('#.'*w)[y % 2:][:w]) print('')
def print_it(l, n): print(''.join([l[x % 2] for x in range(n)])) matrix = [] while True: values = input() if '0 0' == values: break matrix.append([int(x) for x in values.split()]) sc = ['#', '.'] cs = ['.', '#'] for height, width in matrix: if 1 == height and 1 == width: print('#') print() continue for i in range(height): if 0 == i % 2: print_it(sc, width) else: print_it(cs, width) print()
1
873,113,658,884
null
51
51
s, t = input().split() a, b = map(int, input().split()) u = input() bnum = {s: a, t: b} bnum[u] -= 1 print('{} {}'.format(bnum[s], bnum[t]))
def ABC_154_A(): S,T = map(str, input().split()) A,B = map(int, input().split()) U = input() if U == S: print(str(A-1)+' '+str(B)) else: print(str(A)+' '+str(B-1)) if __name__ == '__main__': ABC_154_A()
1
72,096,388,203,940
null
220
220
while True: try: m,f,r = map(int,raw_input().split()) if all(k == -1 for k in [m,f,r]): break except EOFError: break if m == -1 or f == -1: print 'F' elif m + f >= 80: print 'A' elif 65 <= m + f <80: print 'B' elif 50 <= m + f < 65: print 'C' elif 30 <= m + f < 50: if r >= 50: print 'C' else: print 'D' elif m + f < 30: print 'F'
while True: m, f, r = [int(i) for i in input().split()] if m == f == r == -1: break elif m == -1 or f == -1: print("F") elif m + f >= 80: print("A") elif 65 <= m + f < 80: print("B") elif 50 <= m + f < 65: print("C") elif 30 <= m + f < 50: if r >= 50: print("C") else: print("D") elif m + f < 30: print("F") elif m + f < 30: print("F")
1
1,211,445,540,028
null
57
57
k = int(input()) a,b = map(int, input().split()) if (int(b/k)*k >= a): print("OK") else: print("NG")
# 5 import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return input() def LS(): return input().split() INF = float('inf') n = I() s = S() ciphers = [f'{i:03}' for i in range(1000)] ans = 0 for v in ciphers: j = 0 for i in range(n): if s[i] == v[j]: j += 1 if j == 3: ans += 1 break print(ans)
0
null
77,500,905,163,610
158
267
n,k = map(int,input().split()) MOD = 10**9+7 FAC = [1] INV = [1] for i in range(1,2*n+1): FAC.append((FAC[i-1]*i) % MOD) INV.append(pow(FAC[-1],MOD-2,MOD)) def nCr(n,r): return FAC[n]*INV[n-r]*INV[r] ans = 0 for i in range(min(n-1,k)+1): ans += nCr(n,i)*nCr(n-1,n-i-1) ans %= MOD print(ans)
n,m = [int(x) for x in input().split()] h = [int(x) for x in input().split()] a,b = [],[] for i in range(m): a1,b1 = [int(x) for x in input().split()] a.append(a1-1) b.append(b1-1) ans = [1] * n for i in range(m): if h[a[i]] < h[b[i]]: ans[a[i]] = 0 elif h[a[i]] > h[b[i]]: ans[b[i]] = 0 else: ans[a[i]] = 0 ans[b[i]] = 0 c = 0 for i in range(n): if ans[i] == 1: c += 1 #print(ans) print(c)
0
null
46,063,951,948,970
215
155
from itertools import combinations n = int(input()) state = [None] + [[set(),set()] for _ in range(n)] for i in range(1,n+1): a = int(input()) for _ in range(a): x,y = map(int,input().split()) if y == 0: state[i][0].add(x) if y == 1: state[i][1].add(x) ans = 0 #正直者の人数を仮定 for i in range(1,n+1): #正直者の選び方を仮定 for j in combinations(list(range(1,n+1)), i): assum = set(j) state_lst = [] #正直者の証言抽出 for each_state in j: state_lst.append(state[each_state]) #証言の矛盾を確認 for each_state in state_lst: crr0 = assum.isdisjoint(each_state[0]) crr1 = assum >= each_state[1] crr = crr0 and crr1 if not crr: break else: ans = i print(ans)
N = int(input()) x = [[0] * (N-1) for _ in range(N)] y = [[0] * (N-1) for _ in range(N)] A = [0] * N for i in range(N): A[i] = int(input()) for j in range(A[i]): x[i][j], y[i][j] = list(map(int, input().split())) n = 2 ** N Flag = 0 ans = 0 while(n < 2 ** (N+1)): Flag = 0 for i in range(N): if(int(bin(n)[i + 3]) == 1): for j in range(A[i]): if(y[i][j] != int(bin(n)[x[i][j] + 2])): Flag = 1 break if(Flag == 1): break else: ans = max(ans, sum(list(map(int,bin(n)[3:])))) n += 1 print(ans)
1
121,847,230,089,650
null
262
262
while 1: h,w = map(int, raw_input().split()) if h==w==0: break for i in range(0,h/2): print ("#." * (w/2) + "#" * (w%2)) print (".#" * (w/2) + "." * (w%2)) if h % 2 == 1: print ("#." * (w/2) + "#" * (w%2)) print ""
input() print('APPROVED' if all(map(lambda x: x % 3 == 0 or x % 5 == 0, filter(lambda x: x % 2 == 0, map(int, input().split())))) else 'DENIED')
0
null
35,120,207,632,718
51
217
n, m = map(int, input().split()) a, b = n, 1 V = [False for d in range(1, n + 1)] for i in range(m): d = min(a - b, n - (a - b)) if 2 * d == n or V[d]: a -= 1 print(a, b) d = min(a - b, n - (a - b)) V[d] = True a -= 1 b += 1
n,m = map(int,input().split()) a = 0 for i in range(m): if n % 2 == 0 and n % 4 != 0 and n-4*i-2 == 0: a = 1 elif n % 4 == 0 and i == (n//2-1) // 2 + 1: a = 1 print('{} {}'.format(i+1, n-i-a))
1
28,615,036,923,266
null
162
162
while True: [n, x] = map(int, input().split()) if n==0 and x==0: break ans = 0 for a in range(1,n-1): for b in range(a+1,n): for c in range(b+1,n+1): if a+b+c==x: ans += 1 print(ans)
K,N = map(int,input().split()) A = list(map(int,input().split())) tmin = 2*K for i in range(1,N): tmin = min(tmin,K-(A[i]-A[i-1])) tmin = min(tmin,A[N-1]-A[0]) print(tmin)
0
null
22,202,101,484,500
58
186
import sys input = sys.stdin.readline S = input() print(S[:3])
total_people, min_height = map(int, input().split()) height = map(int, input().split()) rideable_people = 0 for i in height: if i >= min_height: rideable_people += 1 print(rideable_people)
0
null
97,057,030,107,618
130
298
n, p = [int(_) for _ in input().split()] s = input() if p == 2 or p == 5: ans = 0 for i in range(n): if int(s[i]) % p == 0: ans += i+1 print(ans) exit() t = [0 for i in range(n+1)] P = [0 for i in range(p)] P[0] += 1 d = 1 for i in range(1, n+1): t[i] = (t[i-1]+int(s[n-i])*d) % p P[t[i]] += 1 d = d*10 % p ans = 0 for c in P: ans += c*(c-1)//2 # print(t) print(ans)
N=int(input()) A=list(map(int,input().split())) ans=20202020200 sum_A=0 sum_B=sum(A) for i in range(N): sum_A+=A[i] sum_B-=A[i] tmp=abs(sum_A-sum_B) if tmp<ans: ans=tmp print(ans)
0
null
99,950,389,061,260
205
276
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) from bisect import bisect_left from itertools import product def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def LI_(): return list(map(lambda x: int(x)-1, input().split())) def LF(): return list(map(float, input().split())) def LC(): return [c for c in input().split()] def LLI(n): return [LI() for _ in range(n)] def NSTR(n): return [input() for _ in range(n)] def array2d(N, M, initial=0): return [[initial]*M for _ in range(N)] def copy2d(orig, N, M): ret = array2d(N, M) for i in range(N): for j in range(M): ret[i][j] = orig[i][j] return ret INF = float("inf") MOD = 10**9 + 7 def main(): X, K, D = MAP() # 到達候補は0に近い正と負の二つの数 d, m = divmod(X, D) cand = (m, m-D) if X >= 0: if K <= d: print(X-K*D) return else: rest = (K-d) if rest % 2 == 0: print(cand[0]) return else: print(-cand[1]) return else: if K <= -d-1: print(abs(X+K*D)) return else: rest = K-(-d-1) if rest % 2 == 0: print(-cand[1]) return else: print(cand[0]) return return if __name__ == '__main__': main()
class Dice: def __init__(self, usr_input, command): self.eyes = list(map(int, usr_input.split())) self.pos = {label:eye for label, eye in zip(range(1, 7), self.eyes)} self.com = list(command) def roll(self): for c in self.com: self.eyes = [n for n in self.pos.values()] if c == 'E': self.pos[1] = self.eyes[3] self.pos[3] = self.eyes[0] self.pos[4] = self.eyes[5] self.pos[6] = self.eyes[2] elif c == 'N': self.pos[1] = self.eyes[1] self.pos[2] = self.eyes[5] self.pos[5] = self.eyes[0] self.pos[6] = self.eyes[4] elif c == 'S': self.pos[1] = self.eyes[4] self.pos[2] = self.eyes[0] self.pos[5] = self.eyes[5] self.pos[6] = self.eyes[1] elif c == 'W': self.pos[1] = self.eyes[2] self.pos[3] = self.eyes[5] self.pos[4] = self.eyes[0] self.pos[6] = self.eyes[3] def top_print(self): print(self.pos.get(1)) if __name__ == '__main__': dice1 = Dice(input(), input()) dice1.roll() dice1.top_print()
0
null
2,759,642,315,908
92
33
ma = lambda :map(int,input().split()) n,u,v = ma() u,v = u-1,v-1 tree = [[] for i in range(n)] import collections for i in range(n-1): a,b = ma() tree[a-1].append(b-1) tree[b-1].append(a-1) que = collections.deque([(v,0)]) vis = [False]*n dist_v = [0]*n while que: now,c = que.popleft() vis[now] = True dist_v[now] = c for node in tree[now]: if not vis[node]: que.append((node,c+1)) que = collections.deque([(u,0)]) vis = [False]*n dist_u = [0]*n while que: now,c = que.popleft() vis[now] = True dist_u[now] = c for node in tree[now]: if not vis[node]: que.append((node,c+1)) ans = 0 for i in range(n): if dist_u[i] < dist_v[i]: ans = max(ans,dist_v[i]) print(ans-1)
A, B, C, K = map(int, input().split()) ans = 0 if A > K: ans += 1*K else: ans += 1*A K = K - A if B > K: ans += 0*K else: ans += 0*B K = K - B if C > K: ans += -1*K else: ans += -1*C print(ans)
0
null
69,930,801,409,948
259
148
A = int(input()) B = int(input()) if A == 1 and B == 2: print(3) elif A == 2 and B == 1: print(3) elif A == 1 and B == 3: print(2) elif A == 3 and B == 1: print(2) elif A == 2 and A == 3: print(1) else: print(1)
import sys input = lambda: sys.stdin.readline().rstrip() def solve(): N = int(input()) if N % 2 == 1 or N < 10: print(0) exit() ans = 0 div = 10 while div <= N: ans += N // div div *= 5 print(ans) if __name__ == '__main__': solve()
0
null
113,493,624,275,178
254
258
n,x,y=map(int,input().split()) x-=1;y-=1 fl=[0 for i in range(n-1)] for i in range(n): for j in range(i+1,n): fl[min(abs(j-i),abs(j-x)+1+abs(y-i),abs(i-x)+1+abs(y-j))]+=1 print(*fl[1:],sep="\n") print(0)
import sys # import re # import math # import collections # import decimal # import bisect # import itertools # import fractions # import functools # import copy # import heapq # import decimal # import statistics # import queue sys.setrecursionlimit(10000001) INF = 10 ** 10 MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): n = ni() mat = [[0 for _ in range(10)] for _ in range(10)] for i in range(1, n + 1): s = str(i) ss = int(s[0]) st = int(s[-1]) mat[ss][st] += 1 ans=0 for i in range(1,10): for j in range(1,10): ans += mat[i][j]*mat[j][i] print(ans) if __name__ == '__main__': main()
0
null
65,595,537,052,320
187
234
while True: H, W = map(int, raw_input().split()) if (H + W) == 0: break printW = ['#'] * W if W != 0: for h in range(H): print ''.join(printW) print ""
#!/usr/bin/env python3 import sys def solve(S: str, T: str): min_change = 100000000 S = [s for s in S] T = [t for t in T] for i, s in enumerate(S): for j, t in enumerate(T): if j == 0: c = 0 if len(S) <= i + j: break if S[i+j] != t: c += 1 if len(T) == j + 1: min_change = min(min_change, c) print(min_change) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str T = next(tokens) # type: str solve(S, T) if __name__ == '__main__': main()
0
null
2,258,320,786,570
49
82
def main(): line = input() s1 = [] s2 = [] sum = 0 for i, s in enumerate(line): if s == "\\": # 谷の位置をスタックに積む s1.append(i) elif s == "/" and len(s1) > 0: # 山で対応する谷があるなら、面積に追加 j = s1.pop() sum += i - j # 谷から山の距離を水たまりの面積に追加 # jより前に位置する水たまりの面積を追加 a = i - j while len(s2) > 0 and s2[-1][0] > j: a += s2.pop()[1] # (水たまりの左端の位置, 水たまりの面積)のタプルをスタックに積む s2.append((j, a)) print(sum) print(len(s2), end="") for x in s2: print(f" {x[1]}", end="") print() if __name__ == "__main__": main()
n,k = map(int, input().split()) alist=list(map(int, input().split())) def is_ok(arg): cnt=0 for i in alist: cnt+=(i-1)//arg return cnt<=k def nibun(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok print(nibun(0 , 10**9 + 1))
0
null
3,267,361,717,060
21
99
import sys N = int(input()) S = list(input()) if len(S)%2 != 0: print("No") sys.exit(0) else: i = int(len(S)/2) T = S[0:i] if T*2 == S: print("Yes") else: print("No")
N = int(input()) S = str(input()) flag = False half = (N+1) // 2 if S[:half] == S[half:N]: flag = True if flag: print("Yes") else: print("No")
1
146,846,513,332,596
null
279
279
K, N= map(int, input().split()) A = list(map(int, input().split())) max=K-(A[N-1]-A[0]) for i in range(N-1): a=A[i+1]-A[i] if max<a: max=a print(K-max)
k, n = map(int, input().split()) cnt = [0] * (n + 1) cmb = 0 a = list(map(int, input().split())) ans = 10 ** 6 + 1 for i in range(n): r_idx = ((i+1)%n) r_ans = a[i]+(k-a[r_idx]) if a[i] < a[r_idx] else abs(a[r_idx]-a[i]) l_idx = (i-1+n)%n l_ans = (k-a[i])+a[l_idx] if a[i] > a[l_idx] else a[l_idx]-a[i] ans = min([ans, r_ans, l_ans]) print(ans)
1
43,451,887,935,158
null
186
186
def main(): H, W, M = map(int, input().split()) # H, W, M = (3 * 10 ** 5, 3 * 10 ** 5, 3 * 10 ** 5) row = [0] * (H + 1) row_set = [set() for _ in range(H+1)] column = [0] * (W + 1) column_set = [set() for _ in range(W+1)] # import random ms = [] positions = set() for m in range(M): h, w = map(int, input().split()) positions.add((h, w)) # h, w = (random.randrange(3*10**5), random.randrange(3*10**5)) row[h] += 1 row_set[h].add(w) column[w] += 1 column_set[w].add(h) max_rows = set() maxR = -1 for i, v in enumerate(row[1:]): if v > maxR: max_rows = set() max_rows.add(i+1) maxR = v elif v == maxR: max_rows.add(i+1) max_cols = set() maxC = -1 for i, v in enumerate(column[1:]): if v > maxC: max_cols = set() max_cols.add(i+1) maxC = v elif v == maxC: max_cols.add(i + 1) for y in max_rows: for x in max_cols: if not (y, x) in positions: print(maxR + maxC) exit() print(maxR + maxC - 1) main()
s = str(input()) p = str(input()) connect = s + s if p in connect: print('Yes') else: print('No')
0
null
3,186,933,883,376
89
64
x = int(input()) ans = x // 500 * 1000 x = x % 500 ans += x // 5 * 5 print(ans)
x = int(input()) money1 = x // 500 x %= 500 money2 = x // 5 ans = money1 * 1000 + money2 * 5 print(ans)
1
42,699,494,313,170
null
185
185
n = int(input()) s = input() x = [int(i) for i in s] pc = s.count('1') def popcnt(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f def f(x): if x == 0: return 0 return f(x % popcnt(x)) + 1 ans = [0]*n for a in range(2): npc = pc if a == 0: npc += 1 else: npc -= 1 if npc <= 0: continue r0 = 0 for i in range(n): r0 = (r0*2) % npc r0 += x[i] k = 1 for i in range(n-1, -1, -1): if x[i] == a: r = r0 if a == 0: r = (r+k) % npc else: r = (r-k+npc) % npc ans[i] = f(r) + 1 k = (k*2) % npc for i in ans: print(i)
import math a,b,C = map(float,input().split()) C = math.pi* C / 180 area = (a * b * math.sin(C) / 2) print(area) print(a + b + math.sqrt(a**2 + b**2 - 2 * a * b* math.cos(C))) print(area * 2 / a)
0
null
4,207,620,879,480
107
30
#N E S W def move_func(dice_list, dir): new_dice = [] if dir=="N": new_dice.append(dice_list[1]) new_dice.append(dice_list[5]) new_dice.append(dice_list[2]) new_dice.append(dice_list[3]) new_dice.append(dice_list[0]) new_dice.append(dice_list[4]) elif dir=="E": new_dice.append(dice_list[3]) new_dice.append(dice_list[1]) new_dice.append(dice_list[0]) new_dice.append(dice_list[5]) new_dice.append(dice_list[4]) new_dice.append(dice_list[2]) elif dir=="S": new_dice.append(dice_list[4]) new_dice.append(dice_list[0]) new_dice.append(dice_list[2]) new_dice.append(dice_list[3]) new_dice.append(dice_list[5]) new_dice.append(dice_list[1]) elif dir=="W": new_dice.append(dice_list[2]) new_dice.append(dice_list[1]) new_dice.append(dice_list[5]) new_dice.append(dice_list[0]) new_dice.append(dice_list[4]) new_dice.append(dice_list[3]) return new_dice try: while True: dice_list = input().split(" ") move_cmd = input() for cmd in move_cmd: dice_list = move_func(dice_list, cmd) print(dice_list[0]) except EOFError: pass
# -*-coding:utf-8 class Dice: def __init__(self, diceList): self.d1, self.d2, self.d3, self.d4, self.d5, self.d6 = diceList def diceRoll(self, r): if(r == 'N'): self.d1, self.d2, self.d5, self.d6 = self.d2, self.d6, self.d1, self.d5 elif(r == 'E'): self.d1, self.d3, self.d4, self.d6 = self.d4, self.d1, self.d6, self.d3 elif(r == 'W'): self.d1, self.d3, self.d4, self.d6 = self.d3, self.d6, self.d1, self.d4 elif(r == 'S'): self.d1, self.d2, self.d5, self.d6 = self.d5, self.d1, self.d6, self.d2 def main(): inputDiceList = list(map(int, input().split())) rollList = list(input()) d = Dice(inputDiceList) for i in rollList: d.diceRoll(i) print(d.d1) if __name__ == '__main__': main()
1
231,930,616,504
null
33
33
A = input() if A[2]==A[3] and A[4]==A[5]: print('Yes') else: print('No')
K = int(input()) k = K - 1 numbers = { 0: 1 } while k > 0: k -= 1 for i in range(len(numbers)): n = numbers[i] if n == 9: continue if abs(numbers.get(i - 1, n) - (n + 1)) <= 1 and abs(numbers.get(i + 1, n) - (n + 1)) <= 1: numbers[i] += 1 j = i - 1 while j >= 0: numbers[j] = max(numbers[j + 1] - 1, 0) j -= 1 break else: for key in numbers.keys(): numbers[key] = 0 numbers[len(numbers)] = 1 print(''.join([str(numbers[i]) for i in range(len(numbers))])[::-1])
0
null
40,730,018,340,206
184
181
class BIT: def __init__(self,n): self.s = [0]*(n+1) self.n = n def add(self,val,idx): while idx < self.n+1: self.s[idx] = self.s[idx] + val idx += idx&(-idx) return def get(self,idx): res = 0 while idx > 0: res = res + self.s[idx] idx -= idx&(-idx) return res import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline n = int(input()) S = [ord(s) - ord('a') for s in input()[:-1]] bits = [BIT(n) for i in range(26)] for i,s in enumerate(S): bits[s].add(1,i+1) Q = int(input()) ans = [] for _ in range(Q): flag,x,y = input().split() if flag == "1": i = int(x) c = ord(y) - ord('a') bits[S[i-1]].add(-1,i) bits[c].add(1,i) S[i-1] = c else: l = int(x) r = int(y) res = 0 for i in range(26): res += (bits[i].get(r) > bits[i].get(l-1)) ans.append(str(res)) print("\n".join(ans))
class SegmentTree(): """一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。 built(array) := arrayを初期値とするセグメント木を構築する O(N)。 update(i, val) := i番目の要素をvalに変更する。 get_val(l, r) := 区間[l, r)に対する二項演算の畳み込みの結果を返す。 """ def __init__(self, n, op, e): """要素数、二項演算、単位元を引数として渡す 例) 区間最小値 SegmentTree(n, min, 10 ** 18) 区間和 SegmentTree(n, lambda a, b : a + b, 0) """ self.n = n self.op = op self.e = e self.size = 2 ** ((n - 1).bit_length()) self.node = [self.e] * (2 * self.size) def build(self, array): """arrayを初期値とするセグメント木を構築する""" for i in range(self.n): self.node[self.size + i] = array[i] for i in range(self.size - 1, 0, -1): self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1]) def update(self, i, val): """i番目の要素をvalに変更する""" i += self.size self.node[i] = val while i > 1: i >>= 1 self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1]) def get_val(self, l, r): """[l, r)の畳み込みの結果を返す""" l, r = l + self.size, r + self.size res_l, res_r = self.e, self.e while l < r: if l & 1: res_l = self.op(res_l, self.node[l]) l += 1 if r & 1: r -= 1 res_r = self.op(self.node[r], res_r) l, r = l >> 1, r >> 1 return self.op(res_l, res_r) ALPH = "abcdefghijklmnopqrstuvwxyz" to_int = {char: i for i, char in enumerate(ALPH)} n = int(input()) s = input() q = int(input()) query = [list(input().split()) for i in range(q)] init = [0] * n for i, char in enumerate(s): init[i] = 1 << to_int[char] op = lambda a, b: a | b st = SegmentTree(n, op, 0) st.build(init) for i in range(q): if query[i][0] == "1": _, ind, char = query[i] ind = int(ind) - 1 st.update(ind, 1 << to_int[char]) else: _, l, r = query[i] l, r = int(l) - 1, int(r) print(bin(st.get_val(l, r)).count("1"))
1
62,747,214,048,008
null
210
210
x, y = map(int, input().split()) if x <= y: print(1) elif x % y == 0: print(x//y) else: print(x//y+1)
N, K = map(int, input().split()) AAA = [] for _ in range(K): d = int(input()) A = list(map(int, input().split())) AAA = AAA + A AAA = list(set(AAA)) AA = [] for i in range(N): AA = AA + [i + 1] a = AAA + AA ANS = len([i for i in list(set(a)) if a.count(i) == 1]) print(ANS)
0
null
50,549,506,862,468
225
154
a,b,m = map(int, input().split()) aprice = list(map(int, input().split())) bprice = list(map(int, input().split())) c = sorted(aprice) d = sorted(bprice) e = c[0]+d[0] f =0 for i in range(m): x,y,k = map(int, input().split()) f =aprice[x-1]+bprice[y-1]-k if(e>f): e = f print(e)
A, B, M = map(int, input().split()) As = list(map(int, input().split())) Bs = list(map(int, input().split())) coupons = [] for _ in range(M): x, y, c = map(int, input().split()) coupons.append((x, y, c)) price_min = min(As) + min(Bs) coupon_min = min([As[x - 1] + Bs[y - 1] - c for (x, y, c) in coupons]) print(min((price_min, coupon_min)))
1
54,097,280,184,768
null
200
200
def aizu004(): xs = map(int,raw_input().split()) W = xs[0] H = xs[1] x = xs[2] y = xs[3] r = xs[4] if (r <= x <= W-r) and (r <= y <= H-r): print "Yes" else: print "No" aizu004()
n =int(input()) S = list(map(int, input().split(' '))) q = int(input()) T = list(map(int, input().split(' '))) count = 0 for t in T: if t in S: count += 1 print(count)
0
null
258,184,011,838
41
22
import sys input = sys.stdin.readline def main(): N = int(input()) a = list(map(int, input().split())) s = 0 for i in a: s ^= i for i in a: ans = s ^ i print(ans, sep=' ', end=' ') main()
from collections import deque N, M, K = map(int, input().split()) F = [[] for _ in range(N)] B = [[] for _ in range(N)] # フレンドの隣接リスト for _ in range(M): a, b = map(int, input().split()) a, b = a - 1, b - 1 F[a].append(b) F[b].append(a) # ブロックの隣接リスト for _ in range(K): c, d = map(int, input().split()) c, d = c - 1, d - 1 B[c].append(d) B[d].append(c) # 交友関係グループ(辞書型) D = {} # グループの親 parent = [-1] * N # 訪問管理 visited = [False] * N for root in range(N): cnt = 0 if visited[root]: continue # D[root] = set([root]) # 訪問先のスタック stack = [root] # 訪問先が無くなるまで while stack: # 訪問者をポップアップ n = stack.pop() # 訪問者を訪問済み if visited[n]: continue visited[n] = True cnt +=1 # 訪問者のグループの親を設定 parent[n] = root # root のフレンドをグループと訪問先に追加 for to in F[n]: if visited[to]: continue # D[root].add(to) stack.append(to) if cnt!=0: D[root]=cnt # print(D) ans = [0]*N for iam in range(N): # group = gro[parent[iam]] tmp_ans = D[parent[iam]] tmp_ans -=1 tmp_ans -= len(F[iam]) for block in B[iam]: if parent[block]==parent[iam] : tmp_ans -=1 ans[iam]=tmp_ans print(*ans, sep=' ')
0
null
37,030,200,243,428
123
209