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
def ABC_147_A(): A1,A2,A3 = map(int, input().split()) if A1+A2+A3>=22: print('bust') else: print('win') if __name__ == '__main__': ABC_147_A()
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce, lru_cache import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def MAP1() : return map(lambda x:int(x)-1,input().split()) def LIST() : return list(MAP()) def LIST1() : return list(MAP1()) n = INT() a = LIST() c = [0]*(10**6+1) for x in a: c[x] += 1 k = max(sum(c[i::i]) for i in range(2, 10**6+1)) if k <= 1: print("pairwise coprime") elif k < n: print("setwise coprime") else: print("not coprime")
0
null
61,520,300,542,858
260
85
N = int(input()) S = input() l = [S[i:i+3] for i in range(0, len(S)-2)] print(l.count('ABC'))
def resolve(): N = int(input()) S = str(input()) print(S.count('ABC')) return resolve()
1
99,432,639,585,292
null
245
245
S = input() T = input() if T.startswith(S): if len(T)-len(S)==1: print("Yes") else: print("No") else: print("No")
from operator import itemgetter from itertools import chain N = int(input()) L = [] R = [] for i in range(N): S = input() low = 0 var = 0 for s in S: if s == '(': var += 1 else: var -= 1 low = min(low, var) if var >= 0: L.append((low, var)) else: R.append((low, var)) L.sort(key=itemgetter(0), reverse=True) R.sort(key=lambda x: x[0] - x[1]) pos = 0 for i, (low, var) in enumerate(chain(L, R)): if pos + low < 0: ans = 'No' break pos += var else: ans = 'Yes' if pos == 0 else 'No' print(ans)
0
null
22,422,575,072,700
147
152
i = list(map(int, input().split())) a = i[0] b = i[1] print('{0} {1} {2:.5f}'.format(a // b, a % b, float(a / b)))
values = input() a, b = [int(x) for x in values.split()] print('{0} {1} {2:.5f}'.format(a // b, a % b, a / b))
1
595,238,977,716
null
45
45
N, M =map(int, input().split()) H=list(map(int, input().split())) A=[True]*N for i in range(M): a, b = map(int, input().split()) if H[a-1]>H[b-1]: A[b-1]=False elif H[a-1]==H[b-1]: A[a-1]=False A[b-1]=False elif H[a-1]<H[b-1]: A[a-1]=False print(sum(A))
def main(): n, m = map(int, input().split()) h_lst = list(map(int, input().split())) ab_dict = dict() # 展望台i : [展望台iに隣接する展望台の標高] for _ in range(m): a, b = map(int, input().split()) if a not in ab_dict: ab_dict[a] = [h_lst[b - 1]] else: ab_dict[a].append(h_lst[b - 1]) if b not in ab_dict: ab_dict[b] = [h_lst[a - 1]] else: ab_dict[b].append(h_lst[a - 1]) cnt = 0 ab_dict_keys = ab_dict.keys() for i in range(1, n + 1): if i not in ab_dict_keys: cnt += 1 continue if h_lst[i - 1] > max(ab_dict[i]): cnt += 1 print(cnt) if __name__ == "__main__": main()
1
25,158,968,483,818
null
155
155
alpha=input() if(alpha.isupper()==True): ans='A' else: ans='a' print(ans)
#coding:utf-8 N = int(input()) buff = [y for x in range(N) for y in [input().split()]] data = [(x[0], int(x[1])) for x in buff] S = [x for x in data if x[0]=="S"] H = [x for x in data if x[0]=="H"] D = [x for x in data if x[0]=="D"] C = [x for x in data if x[0]=="C"] ansS = [("S", x) for x in range(1,14) if ("S", x) not in S] ansH = [("H", x) for x in range(1,14) if ("H", x) not in H] ansD = [("D", x) for x in range(1,14) if ("D", x) not in D] ansC = [("C", x) for x in range(1,14) if ("C", x) not in C] ans = ansS + ansH + ansC + ansD [print(str(x[0]) + " " + str(x[1])) for x in ans]
0
null
6,148,525,815,680
119
54
import sys stdin = sys.stdin def main(): N = int(stdin.readline().rstrip()) A = list(map(int,stdin.readline().split())) mod = 10**9+7 ans = 0 for i in range(61): bits = 0 for x in A: if (x>>i)&1: bits += 1 ans += ((bits*(N-bits))* 2**i) %mod ans %= mod print(ans) main()
X=sorted(map(int,input().split()));print(X[0],X[1],X[2])
0
null
61,359,171,793,190
263
40
inp = input() print(inp.swapcase())
from itertools import starmap print("".join(starmap(lambda c: c.lower() if 'A' <= c <= 'Z' else c.upper(), input())))
1
1,529,111,105,856
null
61
61
N = int(input()) A = set(map(int, input().split())) if len(A) == N: print('YES') else: print('NO')
import collections N = int(input()) lsA = list(map(int,input().split())) cout = collections.Counter(lsA) ans = 'YES' for i in cout.values(): if i > 1: ans = 'NO' break print(ans)
1
73,805,616,148,082
null
222
222
n = int(input()) ascii_letters = 'abcdefghijklmnopqrstuvwxyz' for i in range(1,15): if n<=26**i: order=i n-=1 break n-=26**i for i in range(order): print(ascii_letters[n//(26**(order-i-1))],end='') n%=(26**(order-i-1)) print()
n = int(input()) p = list("zabcdefghijklmnopqrstuvwxy") num = "" while n > 26: a = p[n % 26] num += a if n % 26 == 0: n = n // 26 - 1 else: n = n // 26 num += p[n%26] new_num = num[::-1] print(new_num)
1
11,850,799,697,488
null
121
121
T = input() r = T.replace("?", "D") print(r)
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) H1, M1, H2, M2, K = mapint() if M2>=M1: minutes = (H2-H1)*60 minutes += M2-M1 else: minutes = (H2-H1-1)*60 minutes += M2-M1+60 print(max(0, minutes-K))
0
null
18,428,717,099,420
140
139
N = int(input()) c = 0 for _ in range(N): D1, D2 = map(int, input().split()) if D1 == D2: c += 1 if c == 3: print('Yes') exit() else: c = 0 print('No')
n = int(input()) answer = 0 for i in range(n): x, y = input().split() if x == y: answer = answer + 1 else: answer = 0 if answer == 3: print('Yes') exit(0) else: print('No')
1
2,453,208,240,572
null
72
72
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect #from operator import itemgetter #from heapq import heappush, heappop #import numpy as np #from scipy.sparse.csgraph import breadth_first_order, depth_first_order, shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson #from scipy.sparse import csr_matrix #from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN import sys sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 stdin = sys.stdin ni = lambda: int(ns()) nf = lambda: float(ns()) na = lambda: list(map(int, stdin.readline().split())) nb = lambda: list(map(float, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces max_ = 10 ** 18 N = ni() A = na() A.sort() ans = 1 for i in range(N): ans *= A[i] if ans > max_: ans = -1 break print(ans)
n = int(input()) a = list(map(int, input().split())) try: idx = a.index(0) print(0) except ValueError: ans = a[0] for i in range(1, len(a)): ans *= a[i] if ans > 10**18: print('-1') exit() print(ans)
1
16,222,168,807,192
null
134
134
N=int(input()) c=input() countR=c.count('R') print(c[:countR].count('W'))
H = int(input()) cnt = 0 ans = 0 while(H > 0): H = int(H / 2) cnt += 1 for i in range(cnt): ans += 2 ** i print(ans)
0
null
42,936,481,530,400
98
228
import sys x = sys.stdin.readline() a_list = x.split(" ") if int(a_list[0]) < int(a_list[1]) and int(a_list[1]) < int(a_list[2]): print "Yes" else: print "No"
A, B, C = map(int, input().split()) K = int(input()) while B <= A and K: B *= 2 K -= 1 while C <= B and K: C *= 2 K -= 1 print('Yes' if A < B < C else 'No')
0
null
3,600,009,566,088
39
101
n = int(input()) c = list(input()) x = c.count("R") ans = 0 for i in range(x): if c[i] == "W": ans += 1 print(ans)
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)
1
6,221,080,103,320
null
98
98
while 1: n, x = map(int, raw_input().split()) if n == 0 and x == 0: break count = 0 for i in xrange(1, n-1): for j in xrange(i+1, n): for k in xrange(j+1, n+1): if i+j+k > x: break if i+j+k == x: count += 1 print count
n = int(input()) graph = [[0] * 9 for i in range(9)] for i in range(1, n + 1): if i % 10 != 0: i = str(i) sentou = int(i[0]) matubi = int(i[-1]) graph[sentou - 1][matubi - 1] += 1 import numpy as np graph = np.array(graph) print(np.trace(np.dot(graph, graph)))
0
null
44,160,472,381,062
58
234
A,B,C = list(map(int,input().split(" "))) print(C,A,B)
X, Y, Z = map(int, input().split()) print("%d %d %d"%(Z, X, Y))
1
37,818,723,397,530
null
178
178
import sys, io, os, re from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right from pprint import pprint from math import sin, cos, pi, radians, sqrt, floor, ceil from copy import copy, deepcopy from collections import deque, defaultdict from fractions import gcd from functools import reduce from itertools import groupby, combinations from heapq import heapify, heappush, heappop # sys.setrecursionlimit(5000) n1 = lambda: int(sys.stdin.readline().strip()) nn = lambda: list(map(int, sys.stdin.readline().strip().split())) f1 = lambda: float(sys.stdin.readline().strip()) fn = lambda: list(map(float, sys.stdin.readline().strip().split())) s1 = lambda: sys.stdin.readline().strip() sn = lambda: list(sys.stdin.readline().strip().split()) nl = lambda n: [n1() for _ in range(n)] fl = lambda n: [f1() for _ in range(n)] sl = lambda n: [s1() for _ in range(n)] nm = lambda n: [nn() for _ in range(n)] fm = lambda n: [fn() for _ in range(n)] sm = lambda n: [sn() for _ in range(n)] def array1(n, d=0): return [d] * n def array2(n, m, d=0): return [[d] * m for x in range(n)] def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)] def linc(A, d=1): return list(map(lambda x: x + d, A)) def ldec(A, d=1): return list(map(lambda x: x - d, A)) N = n1() A = nn() #MAX = 10**6 MAX = max(A) dp = defaultdict(list) p = 2 while p <= MAX: i = p while i <= MAX: dp[i].append(p) i += p p += 1 while len(dp[p]) >= 1: p += 1 if max(A) == 1: print("pairwise coprime") exit(0) dic = defaultdict(list) for ai in A: fact = dp[ai] for x in fact: dic[x].append(ai) maxlen = 0 for k, v in dic.items(): maxlen = max(len(v), maxlen) if maxlen == 1: print("pairwise coprime") elif maxlen == N: print("not coprime") else: print("setwise coprime")
N, M = map(int, input().split()) Alst = list(map(int, input().split())) k = sum(Alst) ans = N - k if ans >= 0: print(ans) else: print(-1)
0
null
18,084,105,581,112
85
168
def aizu001 (): xs = map(int,raw_input().split()) a = xs[0] b = xs[1] if a > b: print "a > b" elif a < b: print "a < b" else : print "a == b" aizu001()
import sys import math char = "abcdefghijklmnopqrstuvwxyz" cnt = {} for S in sys.stdin: for x in S: x = x.lower() if x not in cnt: cnt[x] = 0 cnt[x] += 1 for c in char: sys.stdout.write(c + " : ") if c not in cnt: print 0 else: print cnt[c]
0
null
992,901,013,410
38
63
H, W, K = map(int, input().split()) c = [input() for _ in range(H)] r = [[0]*W for _ in range(H)] S = 0 for i in range(2**H): for j in range(2**W): cnt = 0 for k in range(H): for l in range(W): if (i >> k) & 1: if (j >> l) & 1: if c[k][l] == "#": cnt += 1 if cnt == K: S += 1 print(S)
n = int(input()) s, t = input().split() combination_of_letters = '' for i in range(n): combination_of_letters += s[i] + t[i] print(combination_of_letters)
0
null
60,394,584,426,850
110
255
n, x, t = map(int,input().split(' ')) r = int(n / x) + (1 if n % x > 0 else 0) print(r * t)
import math def solve(n,x,t): if n%x != 0: return (math.ceil(n/x))*t else: return (n//x)*t n,x,t = map(int, input().strip().split()) print(solve(n,x,t))
1
4,261,301,769,440
null
86
86
import numpy as np a,b=map(int,input().split()) print(max(a-2*b,0))
import sys input = sys.stdin.readline X, Y, A, B, C = map(int, input().split()) P = sorted(list(map(int, input().split())), reverse=True) Q = sorted(list(map(int, input().split())), reverse=True) R = sorted(list(map(int, input().split())), reverse=True) ans = sum(P[:X]) + sum(Q[:Y]) x = X-1 y = Y-1 for z in range(C): if x < 0: if R[z] > Q[y]: ans += R[z] - Q[y] y -= 1 elif y < 0: if R[z] > P[x]: ans += R[z] - P[x] x -= 1 else: if R[z] > P[x] >= Q[y]: ans += R[z] - Q[y] y -= 1 elif R[z] > Q[y] > P[x]: ans += R[z] - P[x] x -= 1 elif P[x] >= R[z] > Q[y]: ans += R[z] - Q[y] y -= 1 elif Q[y] >= R[z] > P[x]: ans += R[z] - P[x] x -= 1 print(ans)
0
null
106,174,502,031,388
291
188
while True: a, b, c = input().split() a = int(a) c = int(c) if b == "+": print(a + c) elif b == "-": print(a - c) elif b == '*': print(a * c) elif b == '/': print(a // c) else: break
ans = [] while True: cin = raw_input().split() a = int(cin[0]) b = int(cin[2]) if cin[1] == "+": ans.append(a + b) elif cin[1] == "-": ans.append(a - b) elif cin[1] == "*": ans.append(a * b) elif cin[1] == "/": ans.append(a // b) elif cin[1] == "?": break for i in range(len(ans)): print(ans[i])
1
676,495,839,810
null
47
47
arr = input().split() print("Yes" if len(set(arr)) == 2 else "No")
from decimal import Decimal A, B = input().split() A = Decimal(A) B = Decimal(B) ans = int(A * B) print(ans)
0
null
42,219,552,564,702
216
135
import math import itertools import sys class Dice: numbers = [] faces = { 'top': None, 'back': None, 'right': None, 'left': None, 'front': None, 'bottom': None, } def __init__(self, int_array): self.numbers = int_array self.faces['top'] = self.numbers[0] self.faces['back'] = self.numbers[1] self.faces['right'] = self.numbers[2] self.faces['left'] = self.numbers[3] self.faces['front'] = self.numbers[4] self.faces['bottom'] = self.numbers[5] def getNum(self, n): return self.numbers[n-1] def getFace(self, f): return self.faces[f] def getRightFace(self, t, b): top = self.faces['top'] back = self.faces['back'] right = self.faces['right'] left = self.faces['left'] front = self.faces['front'] bottom = self.faces['bottom'] if t == self.getNum(2): self.rotate('N') elif t == self.getNum(4): self.rotate('E') elif t == self.getNum(5): self.rotate('S') elif t == self.getNum(3): self.rotate('W') elif t == self.getNum(6): for _ in range(2): self.rotate('N') while self.getFace('back') != b: self.rotate('R') result = self.getFace('right') self.faces['top'] = top self.faces['back'] = back self.faces['right'] = right self.faces['left'] = left self.faces['front'] = front self.faces['bottom'] = bottom return result def rotate(self, direction): if direction == 'N': # 前回り top = self.getFace('top') #一時保存 self.faces['top'] = self.faces['back'] self.faces['back'] = self.faces['bottom'] self.faces['bottom'] = self.faces['front'] self.faces['front'] = top elif direction == 'E': # 右回り top = self.faces['top'] #一時保存 self.faces['top'] = self.faces['left'] self.faces['left'] = self.faces['bottom'] self.faces['bottom'] = self.faces['right'] self.faces['right'] = top elif direction == 'S': # 後ろ回り top = self.faces['top'] #一時保存 self.faces['top'] = self.faces['front'] self.faces['front'] = self.faces['bottom'] self.faces['bottom'] = self.faces['back'] self.faces['back'] = top elif direction == 'W': # 左回り top = self.faces['top'] #一時保存 self.faces['top'] = self.faces['right'] self.faces['right'] = self.faces['bottom'] self.faces['bottom'] = self.faces['left'] self.faces['left'] = top elif direction == 'R': # その場右回り back = self.faces['back'] #一時保存 self.faces['back'] = self.faces['left'] self.faces['left'] = self.faces['front'] self.faces['front'] = self.faces['right'] self.faces['right'] = back else: # その場左回り back = self.faces['back'] #一時保存 self.faces['back'] = self.faces['right'] self.faces['right'] = self.faces['front'] self.faces['front'] = self.faces['left'] self.faces['left'] = back def main(): number = list(map(int, input().split())) q = int(input()) dice = Dice(number) for _ in range(q): t, b = map(int, input().split()) print(dice.getRightFace(t,b)) if __name__ == '__main__': main()
import math if __name__ == "__main__": deg = int(input()) print(360//math.gcd(deg, 360))
0
null
6,746,075,691,232
34
125
import sys import math import itertools import collections import heapq import re import numpy as np from functools import reduce rr = lambda: sys.stdin.readline().rstrip() rs = lambda: sys.stdin.readline().split() ri = lambda: int(sys.stdin.readline()) rm = lambda: map(int, sys.stdin.readline().split()) rf = lambda: map(float, sys.stdin.readline().split()) rl = lambda: list(map(int, sys.stdin.readline().split())) inf = float('inf') mod = 10**9 + 7 a = [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] print(a[ri()-1])
from sys import stdin import sys, math n,m,x = [int(x) for x in stdin.readline().rstrip().split()] c = [] for i in range(n): c.append([int(x) for x in stdin.readline().rstrip().split()]) money = [] for i in range(2**n): b = bin(i) d = [0 for i in range(m + 1)] for j in range(n): if b[-1] == "1": d = [p+q for (p,q) in zip(d,c[j])] b = str(bin(int(b, 2) // 2)) if min(d[1:]) >= x: money.append(d[0]) if len(money) == 0: print(-1) else: print(min(money))
0
null
36,016,557,214,670
195
149
import numpy as np a= input() K = [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] print(K[int(a)-1])
hp, count_skills = map(int, input().split()) a = map(int, input().split()) skills_list = list(a) for skill in skills_list: hp -= skill if hp <= 0: print('Yes') break if hp >= 1: print('No')
0
null
63,836,191,605,912
195
226
# coding: utf-8 # Your code here! import numpy as np import copy D = int(input()) C = list(map(int,input().split())) contest = [list(map(int,input().split())) for i in range(D)] inputs = [int(input()) for i in range(D)] # print(contest) # print(inputs) lists = np.array([0 for i in range(26)]) Y = 0 for i,j in zip(contest,inputs): lists += 1 lists[j-1] = 0 X = C * lists.T # print(X) # print(sum(X)) # x = sum(C[:j-1])+sum(C[j:]) # y = i[j-1]-x+solve Y = i[j-1]-sum(X)+Y print(Y) Y = copy.deepcopy(Y)
D = int(input()) C = [int(T) for T in input().split()] S = [[] for TD in range(0,D)] for TD in range(0,D): S[TD] = [int(T) for T in input().split()] Type = 26 Last = [0]*Type Sats = 0 for TD in range(0,D): Test = int(input())-1 Last[Test] = TD+1 Sats += S[TD][Test] for TC in range(0,Type): Sats -= C[TC]*(TD+1-Last[TC]) print(Sats)
1
10,064,596,636,082
null
114
114
n,p = map(int,input().split()) s = list(map(int, list(input()))) # 数値のリストにしておく def solve(): if p in [2,5]: # 例外的な処理 ret = 0 for i in range(n): # 文字位置: i: 左から, n-1-i:右から (0 基準) lsd = s[n-1-i] # 最下位桁 if lsd % p == 0: ret += n - i # LSD が割り切れたら LSD から右の桁数分加算 return ret ten = 1 # S[l,r) のときの 10^r, init r=0 -> 10^0 = 1 cnt = [0]*p # 余りで仕分けして個数を集計 r = 0 # 左からの文字数 0 のときの余り cnt[r] += 1 # 余りが同じものをカウント for i in range(n): # 文字位置: i: 左から, n-1-i:右から (0 基準) msd = s[n-1-i] # 最上位桁 r = (msd * ten + r) % p # r: 今回の余り ten = ten * 10 % p # N≦2*10^5 桁 なので剰余計算忘れずに! cnt[r] += 1 # 余りが同じものをカウント ret = 0 for r in range(p): # 余り r の個数から組み合わせを計算 ret += cnt[r] * (cnt[r] - 1) // 2 # nCr(n=i,r=2)= n(n-1)/2 return ret print(solve())
N,P=map(int,input().split()) S=str(input()) ans=0 if 10%P==0: for i in range(N): if int(S[i])%P==0: ans+=i+1 else: rem = [0]*P mod = 0 ten = 1 rem[mod]=1 for i in range(N): mod=(mod+int(S[N-i-1])*ten)%P ten=ten*10%P rem[mod]+=1 for j in rem: ans+=(j*(j-1))//2 print(ans)
1
58,481,777,264,368
null
205
205
INFTY = 1000000001 def merge(A, left, mid, right): global cnt L = A[left:mid] R = A[mid:right] L.append(INFTY) R.append(INFTY) i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 cnt += 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) n = int(input()) S = list(map(int, input().split())) cnt = 0 merge_sort(S, 0, len(S)) print(*S) print(cnt)
import sys n = int(input()) SENTINEL = 10000000000 COMPAR = 0 A = list(map(int, sys.stdin.readline().split())) def merge(A, left, mid, right): global COMPAR n1 = mid - left n2 = right - mid L = A[left:mid] R = A[mid:right] L.append(SENTINEL) R.append(SENTINEL) j = 0 i = 0 for k in range(left, right): COMPAR += 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) merge_sort(A, 0, n) print(' '.join(map(str, A))) print(COMPAR)
1
115,564,946,240
null
26
26
N,K = map(int,input().split()) # from scipy.special import comb # a = comb(n, r) MOD = 10**9 + 7 ans = 0 for k in range(K,N+2): # print(k) right = (N+N-k+1)*k // 2 left = (k-1)*k // 2 ans += right - left + 1 ans %= MOD # print(ans) # ans += comb(N+1, k, exact=True) # print(ans) print(ans)
n,k = map(int,input().split()) ans = 1 y = sum(list(range(n-k+2,n+1))) j = n - k + 1 for i in range(k,n+1): x = (1+(i-1))*(i-1)//2 y += j j -= 1 ans += y - x + 1 ans %= 10 ** 9 + 7 print(ans)
1
33,125,989,013,908
null
170
170
def main(): n,k = map(int, input().split()) MOD = 10**9+7 # 0人部屋が0~k個の時の場合の数の和 # Σ(i=[0,k]){comb(n,i)*pow((n-i),i)} を求めれば良い # しかし上式ではpowの計算量がデカすぎるので、捉え方を変えて下式まで変形 # Σ(i=[0,k]){comb(n,i)*comb((n-1),i)} を求めれば良い # 注:i=0のとき、つまり0人部屋がない、つまり全部屋に1人ずつ、のケースは1通り # comb(n,i+1) = comb(n,i) * (n-i)/(i+1) であることを利用する ans = 0 k1 = 1 k2 = 1 for i in range(min(k+1,n)): ans += k1*k2 ans %= MOD k1 *= (n-i)*pow(i+1,MOD-2,MOD) k1 %= MOD k2 *= (n-1-i)*pow(i+1,MOD-2,MOD) k2 %= MOD print(int(ans)) main()
n, p = map(int, input().split()) s = input() if 10%p==0: ans = 0 for r in range(n): if int(s[r])%p == 0: ans += r+1 print(ans) exit() d = [0]*(n+1) ten = 1 for i in range(n-1, -1, -1): a = int(s[i])*ten%p d[i] = (d[i+1]+a)%p ten *= 10 ten %= p cnt = [0]*p ans = 0 for i in range(n, -1, -1): ans += cnt[d[i]] cnt[d[i]] += 1 print(ans)
0
null
62,985,294,162,980
215
205
import sys sys.setrecursionlimit(10 ** 7) rl = sys.stdin.readline def solve(): n, r = map(int,input().split()) if 10 > n: print(r + (100 * (10 - n))) else: print(r) if __name__ == '__main__': solve()
import sys input = sys.stdin.readline n, k = map(int, input().split()) print(min(n % k, k - (n % k)))
0
null
51,660,989,167,104
211
180
from decimal import * getcontext().prec = 29 a,b=map(Decimal,input().split()) print(int(a*b))
a,b,c,d=map(int,input().split()) ans=[] ans.append(a*c) ans.append(a*d) ans.append(b*c) ans.append(b*d) print(max(ans))
0
null
9,758,173,002,288
135
77
a = input() k = int(a.split()[0]) x = int(a.split()[1]) if k * 500 >= x: print('Yes') else: print('No')
H,N = map(int,input().split());INF = float("inf") A=[];B=[] for i in range(N): a,b = map(int,input().split()) A.append(a);B.append(b) #print(A,B) dp = [INF for _ in range(H+1)] #dp[i] HPがi残っているときの、魔力の消費最小 dp[H] = 0 for i in reversed(range(H+1)): #print(i) #print(dp) for j in range(N): if i - A[j] >= 0: dp[i-A[j]] = min(dp[i-A[j]], dp[i] + B[j]) else: dp[0] = min(dp[0], dp[i] + B[j]) ans = dp[0] print(ans)
0
null
89,900,118,278,090
244
229
import math a, b = map(int,input().split()) ans = -1 for i in range(1, 1011): if math.floor(i*0.08) == a and math.floor(i * 0.1) == b: print(i) exit() print(ans)
#!/usr/bin/env python3 from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def sum_of_arithmetic_progression(s, d, n): return n * (2 * s + (n - 1) * d) // 2 def gcd(a, b): if b == 0: return a return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return a / g * b def solve(): A, B = map(int, input().split()) for i in range(0, 100000): if int(i * 0.08) == A and int(i * 0.1) == B: print(i) return print(-1) def main(): solve() if __name__ == '__main__': main()
1
56,614,206,006,952
null
203
203
G = [] cnt = 0 def insertionSort(A, n, g): for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: global cnt cnt += 1 A[j+g] = A[j] j -= g A[j+g] = v def shellSort(n, A): m = 1 while m <= n / 9: m = m * 3 + 1 while 0 < m: global G G.append(m) insertionSort(A, n, m) m = int(m / 3) A = [] n = int(input()) for i in range(n): A.append(int(input())) shellSort(n, A) print(len(G)) print(*G) print(cnt) for i in range(n): print(A[i])
n, k = map(int, input().split()) h = list(map(int,input().split())) ans = 0 h = sorted(h,reverse=True) for i in range(k,n): ans += h[i] print(ans)
0
null
39,685,925,271,748
17
227
h1, m1, h2, m2, k = map(int, input().split()) s = h1*60+m1 t = h2*60+m2 ans = t-s-k print (max(ans,0))
h1,m1,h2,m2,k=map(int,raw_input().split()) print max(h2*60+m2-h1*60-m1-k,0)
1
17,993,950,060,984
null
139
139
#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 # (string,3) 3回 #from collections import deque #from collections import defaultdict #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(input()) H,W,K = readInts() cake = [input() for _ in range(H)] ans = [] no = 0 cnt = 0 for h in range(H): if cake[h] == "."*W: no += 1 continue else: cnt += 1 same = [] arrived = False for w in range(W): if cake[h][w] == "#": if not arrived: arrived = True else: cnt += 1 same.append(cnt) for _ in range(no+1): ans.append(same) no = 0 for _ in range(no): ans.append(ans[-1]) for a in ans: print(*a,sep=" ")
number_list=[int(i) for i in input().split()] counter=0 for r in range(number_list[0],number_list[1]+1): if number_list[2]%r==0: counter+=1 print(counter)
0
null
71,884,552,912,118
277
44
a, b, c, d = map(int,input().split(" ")) Ns = [a*c, a*d, b*c, b*d] print(sorted(Ns)[-1])
# -*- coding: utf-8 -*- A, B, C, D = map(int, input().split()) i = 0 while A > 0 and C > 0: i += 1 if i % 2 == 1: # 高橋くんの攻撃 C -= B else: # 青木くんの攻撃 A -= D if C <= 0: print("Yes") else: print("No")
0
null
16,427,480,702,290
77
164
#!/usr/bin/env python3 import collections as cl import sys def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = II() S = LI() if len(set(S)) == N: print("YES") else: print("NO") main()
#k = int(input()) #s = input() #a, b = map(int, input().split()) #l = list(map(int, input().split())) l = list(map(int, input().split())) if (l[0] == l[1] != l[2]): print("Yes") elif (l[0] == l[2] != l[1]): print("Yes") elif (l[0] != l[1] == l[2]): print("Yes") else: print("No")
0
null
71,033,126,041,310
222
216
N = int(input()) g = 0 for n in range(1, N + 1): if n % 2 == 0: g += 1 ANS = (N - g) / N print(ANS)
n = int(input()) ans = (n // 2 + n % 2) / n print(ans)
1
177,492,830,924,530
null
297
297
n = raw_input() l = map(int, raw_input().split()) n = raw_input() sum = 0 for i in map(int, raw_input().split()): if i in l: sum += 1 print sum
N, A, B = map(int, input().split()) q = N // (A + B) r = N % (A + B) if r <= A: print(q * A + r) else: print(q * A + A)
0
null
27,682,709,346,292
22
202
#!/usr/bin/env python3 k, n = map(int, input().split()) a = list(map(int, input().split())) cnt = 0 maxku = 0 for i in range(n-1): ku = a[i + 1] - a[i] maxku = max(ku, maxku) cnt += ku ku = a[0] + (k - a[-1]) maxku = max(ku, maxku) cnt += ku print(cnt - maxku)
K,N = map(int,input().split()) A = list(map(int,input().split())) max_range = 0 for i in range(N): if i == N-1: if max_range < K-A[i]+A[0]: max_range = K-A[i]+A[0] else: if max_range < A[i+1]-A[i]: max_range = A[i+1]-A[i] ans = K - max_range print(ans)
1
43,290,721,493,156
null
186
186
n = int(input()) s = list(input().split()) q = int(input()) t = list(input().split()) ans = 0 for num in t: if num in s: ans += 1 print(ans)
n = input() S = list(map(int,input().split())) n = input() T = list(map(int,input().split())) count = 0 for i in T: if i in S: count+= 1 print(count)
1
67,511,001,922
null
22
22
X = int(input()) x1 = X // 100 x2 = X % 100 if x2 <= x1 * 5: print(1) else: print(0)
x = int(input()) price = [100, 101, 102, 103, 104, 105] dp = [False for _ in range(x + 1)] dp[0] = True for i in range(1, x + 1): for j in range(6): if i - price[j] >= 0: if dp[i - price[j]]: dp[i] = True break else: dp[i] = False if dp[x]: print(1) else: print(0)
1
127,109,285,963,758
null
266
266
s = raw_input().rstrip().split(" ") W = int(s[0]) H = int(s[1]) x = int(s[2]) y = int(s[3]) r = int(s[4]) if (x-r)>=0 and (x+r)<=W and (y-r)>=0 and (y+r)<=H:print "Yes" else:print "No"
W,H,x,y,r=map(int,input().split()) a = x-r b = x+r c = y-r d = y+r if a>=0 and b<=W and c>=0 and d<=H: print("Yes") else: print("No")
1
453,874,955,070
null
41
41
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools as fts import itertools as its import math import sys INF = float('inf') def solve(S: str): return sum([S == "RRR", "RR" in S, "R" in S]) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str print(f'{solve(S)}') if __name__ == '__main__': main()
import copy H, W, K = map(int, input().split()) tiles = [list(input()) for _ in range(H)] count = 0 for num in range(2**(H+W)): copied_tiles = copy.deepcopy(tiles) for i in range(H+W): if num>>i&1: if i < H: for j in range(W): copied_tiles[i][j] = 'R' else: for j in range(H): copied_tiles[j][i-H] = 'R' black_c = 0 for i in range(H): for j in range(W): if copied_tiles[i][j] == '#': black_c += 1 if black_c == K: count += 1 print(count)
0
null
6,966,998,838,200
90
110
a = input() print(a.swapcase())
x = int(input()) a = x // 500 b = (x - (a * 500)) // 5 c = (a * 1000) + (b * 5) print(c)
0
null
22,234,553,320,410
61
185
import itertools n,m,q=map(int,input().split()) d=[list(map(int,input().split())) for i in range(q)] ans=0 for i in list(itertools.combinations_with_replacement(list(range(1,m+1)), n)): a=list(i) hantei=0 for j in range(q): if (a[d[j][1]-1]-a[d[j][0]-1])==d[j][2]: hantei+=d[j][3] ans=max(ans,hantei) print(ans)
import itertools N, M, Q = map(int, input().split()) a = [0] * Q b = [0] * Q c = [0] * Q d = [0] * Q for i in range(Q): a[i], b[i], c[i], d[i] = map(int, input().split()) cc = [i for i in range(1, M+1)] ans = 0 for A in itertools.combinations_with_replacement(cc, N): A = list(A) t = 0 for i in range(Q): if A[b[i]-1] - A[a[i]-1] == c[i]: t += d[i] ans = max(ans, t) print(ans)
1
27,739,691,299,990
null
160
160
n = int(input()) d = [list(map(int, input().split())) for _i in range(n)] c = 0 for i, j in d: if i==j: c += 1 if c == 3: print('Yes') import sys sys.exit() else: c = 0 print('No')
(W,H,x,y,r)=map(int,raw_input().split()) if r<=x and r<=y and x<=W-r and y<=H-r : print "Yes" else : print "No"
0
null
1,446,620,610,340
72
41
def main(): labels = list(map(int, input().split(' '))) n = int(input()) for i in range(n): dice = Dice(labels) t, f = map(int, input().split(' ')) for j in range(8): if j%4 == 0: dice.toE() if f == dice.front: break dice.toN() for j in range(4): if t == dice.top: break dice.toE() print(dice.right) class Dice: def __init__(self, labels): self.labels = labels self._tb = (0, 5) self._fb = (1, 4) self._lr = (3, 2) def toN(self): tb = self._tb self._tb = self._fb self._fb = tuple(reversed(tb)) return self def toS(self): tb = self._tb self._tb = tuple(reversed(self._fb)) self._fb = tb return self def toW(self): tb = self._tb self._tb = tuple(reversed(self._lr)) self._lr = tb return self def toE(self): tb = self._tb self._tb = self._lr self._lr = tuple(reversed(tb)) return self def get_top(self): return self.labels[self._tb[0]] def get_front(self): return self.labels[self._fb[0]] def get_right(self): return self.labels[self._lr[1]] top = property(get_top) front = property(get_front) right = property(get_right) if __name__ == '__main__': main()
#!/usr/bin/env python # -*- coding: utf-8 -*- POSITIONS = ["top", "south", "east", "west", "north", "bottom"] class Dice(object): def __init__(self, initial_faces): self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)} self.store_previous_faces() def store_previous_faces(self): self.previous_faces = self.faces.copy() def change_face(self, after, before): self.faces[after] = self.previous_faces[before] def change_faces(self, rotation): self.change_face(rotation[0], rotation[1]) self.change_face(rotation[1], rotation[2]) self.change_face(rotation[2], rotation[3]) self.change_face(rotation[3], rotation[0]) def roll(self, direction): self.store_previous_faces() if direction == "E": self.change_faces(["top", "west", "bottom", "east"]) elif direction == "N": self.change_faces(["top", "south", "bottom", "north"]) elif direction == "S": self.change_faces(["top", "north", "bottom", "south"]) elif direction == "W": self.change_faces(["top", "east", "bottom", "west"]) def rolls(self, directions): for d in directions: self.roll(d) def main(): dice = Dice(input().split()) q = int(input()) for x in range(q): [qtop, qsouth] = input().split() if qsouth == dice.faces["west"]: dice.roll("E") elif qsouth == dice.faces["east"]: dice.roll("W") while qsouth != dice.faces["south"]: dice.roll("N") while qtop != dice.faces["top"]: dice.roll("W") print(dice.faces["east"]) if __name__ == "__main__": main()
1
254,966,327,488
null
34
34
#-*-coding:utf-8-*- import sys input=sys.stdin.readline import itertools def main(): n = int(input()) P=tuple(map(int,input().split())) Q=tuple(map(int,input().split())) permutations = list(itertools.permutations(range(1,n+1))) a = permutations.index(P) b = permutations.index(Q) print(abs(a-b)) if __name__=="__main__": main()
import itertools n=[x for x in range(1,int(input())+1)] P=list(map(int, input().split())) Q=list(map(int, input().split())) for i, a in enumerate(itertools.permutations(n), start=1): if list(a)==P: p=i if list(a)==Q: q=i print(abs(p-q))
1
100,553,183,604,512
null
246
246
A,B = map(int, input().split()) print(int((A*(A-1)+B*(B-1))/2))
r, c = map(int, input().split()) lis = [[] for a in range(r+1)] for x in range(r): lis[x] = list(map(int, input().split())) lis[x].append(sum(lis[x])) lis[r] = [0 for a in range(c+1)] for y in range(c+1): for z in range(r): lis[r][y] += lis[z][y] for x in lis: for z,y in enumerate(x): if z == c: print(y) else: print(y, end = " ")
0
null
23,600,079,248,576
189
59
A, B = [int(x) for x in input().split(" ")] if A > B*2: print(A-B*2) else: print(0)
# coding:utf-8 import sys import math import time #import numpy as np import collections from collections import deque from collections import Counter import queue import copy import bisect import heapq import itertools sys.setrecursionlimit(10**7) #N, Q = map(int, input().split()) #G = [list(input()) for i in range(H)] #INF = V * 10001 #A = [int(i) for i in input().split()] #AB = [list(map(int, input().split())) for _ in range(K)] A, B = map(int,input().split()) ans = 0 if(A<=2*B): print(0) else: print(A-2*B)
1
166,547,225,773,880
null
291
291
(n, k), p, c = [[*map(int, i.split())] for i in open(0)] def solve(x, t): visit = [0] * n visit[x] = 1 loop = [0] * n count = 0 ans = c[p[x] - 1] l = True sub = 0 while True: x = p[x] - 1 if l: if visit[x]: if loop[x]: ln = sum(loop) if t > ln: sub += (t//ln -1)*count*(count>0) t %= ln t += ln l = False count += c[x] loop[x] = 1 visit[x] = 1 sub += c[x] t -= 1 ans = max(sub, ans) if t < 1: return ans print(max(solve(i, k) for i in range(n)))
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) ans = -float('inf') for i in range(n): s = [] j = p[i]-1 s.append(c[j]) while j != i: j = p[j]-1 s.append(s[-1]+c[j]) l = len(s) if k <= l: a = max(s[:k]) elif s[-1] <= 0: a = max(s) else: w, r = divmod(k, l) a1 = s[-1]*(w-1) + max(s) a2 = s[-1]*w if r != 0: a2 += max(0, max(s[:r])) a = max(a1, a2) ans = max(ans, a) print(ans)
1
5,373,027,171,712
null
93
93
def gcd(a, b): if b == 0: return a else: return gcd(b, a%b) def lcm(a, b): return a*b/gcd(a, b) try : while True : (a,b) = map(int, raw_input().split()) print gcd(a,b), lcm(a,b) except EOFError : pass
import sys def gcd(a, b): if b == 0: return a return gcd(b, a%b) for line in sys.stdin: a, b= map(int, line.split()) if a < b: a, b = b, a g = gcd(a,b) print g, a*b/g
1
559,794,860
null
5
5
name=input() len_n=len(name) name2=input() len_n2=len(name2) if name==name2[:-1] and len_n+1==len_n2: print("Yes") else: print("No")
h, w, k = map(int, input().split()) s = [list(map(int, list(input()))) for _ in range(h)] result = [] if h*w<=k: result.append(0) else: for i in range(2**(h-1)): checker, num, p = 0, i ,[0] for _ in range(h): p.append(p[-1]+num%2) checker += num%2 num >>= 1 x = 0 c = [0 for _ in range(checker+1)] for j in range(w): num = i nex = [0 for _ in range(checker+1)] for m in range(h): nex[p[m]] += s[m][j] if max(nex) > k: x = float('inf') break if all(nex[m]+c[m] <= k for m in range(checker+1)): c = [c[I]+nex[I] for I in range(checker+1)] else: x += 1 c = nex result.append(checker+x) print(min(result))
0
null
34,947,912,109,530
147
193
def insertion_sort(a, n, g, cnt): for i in range(g,n,1): v = a[i] j = i - g #initial value while j>=0 and a[j]>v: a[j+g]=a[j] j -= g cnt += 1 a[j+g] = v return a, cnt def shell_sort(a,n,m,g): cnt = 0 for i in range(m): sorted_list, cnt = insertion_sort(a,n,g[i],cnt) return sorted_list, cnt def seqforshell(n): seq = [1] next_num = 3*seq[0] + 1 while next_num<n: seq.insert(0, next_num) next_num = 3*next_num + 1 return seq if __name__ == "__main__": a = [] n = int(input()) for i in range(n): a.append(int(input())) g = seqforshell(n) m = len(g) res, cnt = shell_sort(a,n,m,g) print(m) print(*g) print(cnt) for i in range(n): print(res[i])
def resolve(): a = int(input()) print(a+a*a+a*a*a) if '__main__' == __name__: resolve()
0
null
5,185,988,777,872
17
115
def solve(k): v = "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" v = list(map(int, v.split(","))) return v[k-1] k = int(input()) print(solve(k))
mlist = list([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]) b = int(input()) print(mlist[b-1])
1
50,227,717,815,240
null
195
195
n, m = list(map(int, input().split())) print(int((n * (n-1) + m * (m-1)) / 2))
a, b = list(map(int, input().split())) my_result = a * (a - 1) + b * (b - 1) print(int(my_result / 2))
1
45,551,787,521,888
null
189
189
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from functools import reduce from bisect import bisect_left, insort_left from heapq import heapify, heappush, heappop INPUT = lambda: sys.stdin.readline().rstrip() INT = lambda: int(INPUT()) MAP = lambda: map(int, INPUT().split()) S_MAP = lambda: map(str, INPUT().split()) LIST = lambda: list(map(int, INPUT().split())) S_LIST = lambda: list(map(str, INPUT().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 def main(): N = INT() A = LIST() C = Counter(A) X = 0 for v in C.values(): X += v * (v - 1) // 2 for i in range(N): print(X - C[A[i]] + 1) if __name__ == '__main__': main()
def select(S): for i in range(0, n): minj = i for j in range(i, n): if int(S[j][1]) < int(S[minj][1]): minj = j (S[i], S[minj]) = (S[minj], S[i]) return S def bubble(B): flag = True while flag: flag = False for j in reversed(range(1, n)): if int(B[j][1]) < int(B[j-1][1]): (B[j-1], B[j]) = (B[j], B[j-1]) flag = True return B def isStable(inA, out): for i in range(0, n): for j in range(i+1, n): for a in range(0, n): for b in range(a+1, n): if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]: return "Not stable" return "Stable" n = int(input()) A = input().split(' ') B = bubble(A[:]) print(" ".join(B)) print(isStable(A, B)) S = select(A[:]) print(" ".join(S)) print(isStable(A, S))
0
null
23,922,282,899,228
192
16
import os, sys, re, math N = int(input()) S = input() if S[:N // 2] == S[N // 2:]: print('Yes') else: print('No')
n = int(input()) s = input() if n%2==0 and s[0:(n+1)//2] == s[(n+1)//2:]: print('Yes') else: print('No')
1
147,584,088,269,632
null
279
279
from collections import defaultdict p = 10 ** 9 + 7 n = int(input()) a = [int(x) for x in input().split()] num = defaultdict(int) num[-1] = 3 col = [None] * n for i in range(n): col[i] = num[a[i] - 1] num[a[i]] += 1 num[a[i] - 1] -= 1 ans = 1 for i in range(n): ans = ans * col[i] % p print(ans)
N = int(input()) def resolve(): a = 7 for i in range(1,N+1): if a % N == 0: return i a = (a * 10 + 7) % N return -1 ans = resolve() print(ans)
0
null
68,060,230,741,668
268
97
import itertools N = int(input()) L = list(map(int,(input().split()))) L.sort() Combi = list(itertools.combinations(L, 3)) count = 0 for i in Combi: a = int(i[0]) b = int(i[1]) c = int(i[2]) if((a+b)> c and a!=b != c and a<b <c ): count+=1 print(count)
N = int(input()) L = list(map(int, input().split())) L.sort() ans = 0 if N >= 3 : for i in range(0, N - 1) : for j in range(1, N - 1 - i) : for k in range(2, N - i): if L[i] < L[i+j] < L[i+k] and L[i] + L[i+j] > L[i+k]: ans += 1 print(ans)
1
5,009,368,905,298
null
91
91
n,*d = map(int,open(0).read().split()) print(sum((sum(d)-i)*i for i in d)//2)
n,k=map(int,input().split()) cnt=[0]*(k+1) mod=10**9+7 for i in range(1,k+1): cnt[i]=pow(k//i,n,mod) #print(cnt) for i in range(k): baisu=k//(k-i) for j in range(2,baisu+1): cnt[k-i]=(cnt[k-i]-cnt[(k-i)*j]+mod)%mod ans=0 for i in range(1,k+1): ans+=i*cnt[i] ans%=mod print(ans)
0
null
102,279,961,736,120
292
176
from collections import defaultdict, deque N, K = map(int, input().split()) A = list(map(int, input().split())) cumA = [0] * (N + 1) for i in range(1, N + 1): cumA[i] = cumA[i - 1] + A[i - 1] cnt = defaultdict(int) que = deque([]) ans = 0 for i, c in enumerate(cumA): while que and que[0][0] <= i - K: cnt[que.popleft()[1]] -= 1 diff = (i - c) % K ans += cnt[diff] cnt[diff] += 1 que.append((i, diff)) print(ans)
N=input() ans=0 for i in range(1,int(N)+1): if i%15==0: pass elif i%5==0: pass elif i%3==0: pass else: ans=ans+i print(ans)
0
null
86,560,601,199,410
273
173
N = int(input()) xs, ys = [], [] for _ in range(N): x, y = map(int, input().split()) xs.append(x) ys.append(y) A = [x + y for x, y in zip(xs, ys)] B = [x - y for x, y in zip(xs, ys)] ans = max([max(A) - min(A), max(B) - min(B)]) print(ans)
import math , sys N , M = list(map( int, input().split() )) cor = 0 pen = 0 F = [False]*N C = [0]*N for i in range(M): A , B = list( input().split() ) A = int(A)-1 if B == "WA" and not F[A]: C[A]+=1 #print(C) if B == "AC" and not F[A]: F[A] = True cor += 1 pen +=C[A] print(cor,pen)
0
null
48,223,909,671,028
80
240
def main(): n = int(input()) numbers = list(map(int, input().split())) ans1 = min(numbers) ans2 = max(numbers) ans3 = sum(numbers) print(ans1, ans2, ans3) if __name__=="__main__": main()
n,m = input().split() n = int(n) m = int(m) print(int(n*(n-1)/2+m*(m-1)/2))
0
null
23,323,141,068,612
48
189
n = int(input()) L = [list(map(int,input().split())) for _ in range(n)] L.sort(key=lambda x:x[0]+x[1]) seen=-10**10 cnt=0 for i in range(n): if seen<=L[i][0]-L[i][1]: seen=L[i][0]+L[i][1] cnt+=1 print(cnt)
import heapq n=int(input()) rb = [] heapq.heapify(rb) for i in range(n): x,l= map(int,input().split()) heapq.heappush(rb,(x+l,x-l)) ans=0 mostr=-1 while len(rb)>0: c=heapq.heappop(rb) if ans==0: ans+=1 mostr=c[0] else: if mostr<=c[1]: ans+=1 mostr=c[0] print(ans)
1
90,338,739,184,304
null
237
237
N_str=list(reversed(input())) N=int(N_str[0]) if N==2 or N==4 or N==5 or N==7 or N==9: print("hon") elif N==0 or N==1 or N==6 or N==8: print("pon") elif N==3: print("bon")
n, k = map(int, input().split()) a = list(map(int, input().split())) d = [[-1] * n for _ in range(70)] for i in range(n): d[0][i] = a[i] - 1 for i in range(1, 70): for j in range(n): d[i][j] = d[i - 1][d[i - 1][j]] dst = 0 while k: i = 70 while pow(2, i) & k <= 0: i -= 1 dst = d[i][dst] k -= pow(2, i) print(dst + 1)
0
null
21,021,857,079,400
142
150
b = input() a = input() print(int(a[-2:]==' 1'))
h,n=map(int,input().split()) ab = [list(map(int,input().split())) for i in range(n)] dp=[float('inf')]*(h+1) dp[0]=0 for i in range(h): for j in range(n): next=i+ab[j][0] if i+ab[j][0]<=h else h dp[next]=min(dp[next],dp[i]+ab[j][1]) print(dp[-1])
0
null
102,570,496,115,102
264
229
X = int(input()) x1 = X // 100 x2 = X % 100 if x2 <= x1 * 5: print(1) else: print(0)
n=int(input()) b=input().split() s=b[:] for i in range(n): for j in range(n-1,i,-1): if b[j][1]<b[j-1][1]:b[j],b[j-1]=b[j-1],b[j] m=i for j in range(i,n): if s[m][1]>s[j][1]:m=j s[m],s[i]=s[i],s[m] print(*b) print('Stable') print(*s) print(['Not stable','Stable'][b==s])
0
null
63,533,176,594,060
266
16
while True: n,x=map(int,input().split()) a=0 if n==0 and x==0:break for i in range(1,n+1): for j in range(1,i): for k in range(1,j): if i+j+k==x:a+=1 print(a)
m = 0 while m == 0: n, x = map(int,raw_input().split()) count = 0 if n == 0 and x == 0: break for i in xrange(1,n+1): for j in xrange(1,n+1): for k in xrange(1,n+1): ans = i + j + k if ans == x and i != j and j != k and k != i: count = count + 1 print count / 6
1
1,286,376,894,400
null
58
58
n = int(input()) a = list(map(int,input().split())) M = max(a)+1 if M == 2: print("pairwise coprime") exit() count = [0]*(M) prime = [2,3,5,7,11,13] for i in range(14,int(M**0.5)+2): check = True for j in prime: if i%j == 0: check = False break if check: prime.append(i) for i in a: for j in prime: if i < j: break if i%j==0: while i%j == 0: i //= j count[j] += 1 if i > 1: count[i] += 1 ans = max(count) if ans == 1: print("pairwise coprime") elif ans == n: print("not coprime") else: print("setwise coprime")
N = int(input()) A = list(map(int, input().split())) B = [0 for i in range(max(A)+1)] for i in range(2, len(B)): if B[i] != 0: continue for j in range(i, len(B), i): B[j] = i def func(X): buf = set() while X>1: x = B[X] buf.add(x) while X%x==0: X = X//x #print(buf) return buf set1 = func(A[0]) set2 = func(A[0]) totallen = len(set1) for a in A[1:]: set3 = func(a) totallen += len(set3) #print(a, set1, set2) set1 |= set3 set2 &= set3 #print(set1, set2, set3) #print(totallen, set1, set2) if len(set2)!=0: print("not coprime") elif len(set1)==totallen: print("pairwise coprime") else: print("setwise coprime")
1
4,110,356,864,640
null
85
85
import time as ti class MyQueue(object): """ My Queue class Attributes: queue: queue head tail """ def __init__(self): """Constructor """ self.length = 50010 self.queue = [] counter = 0 while counter < self.length: self.queue.append(Process()) counter += 1 self.head = 0 self.tail = 0 def enqueue(self, name, time): """enqueue method Args: name: enqueued process name time: enqueued process time Returns: None """ self.queue[self.tail].name = name self.queue[self.tail].time = time self.tail = (self.tail + 1) % self.length def dequeue(self): """dequeue method Returns: None """ self.queue[self.head].name = "" self.queue[self.head].time = 0 self.head = (self.head + 1) % self.length def is_empty(self): """check queue is empty or not Returns: Bool """ if self.head == self.tail: return True else: return False def is_full(self): """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue): return True else: return False class Process(object): """process class """ def __init__(self, name="", time=0): """constructor Args: name: name time: time """ self.name = name self.time = time def forward_time(self, time): """time forward method Args: time: forward time interval Returns: remain time """ self.time -= time return self.time def time_forward(my_queue, interval, current_time, end_time_list): """ Args: my_queue: queue interval: time step interval current_time: current time """ value = my_queue.queue[my_queue.head].forward_time(interval) if value <= 0: current_time += (interval + value) end_time_list.append([my_queue.queue[my_queue.head].name, current_time]) # print my_queue.queue[my_queue.head].name, current_time my_queue.dequeue() elif value > 0: current_time += interval name, time = my_queue.queue[my_queue.head].name, \ my_queue.queue[my_queue.head].time my_queue.dequeue() my_queue.enqueue(name, time) return current_time my_queue = MyQueue() n, q = [int(x) for x in raw_input().split()] counter = 0 while counter < n: name, time = raw_input().split() my_queue.enqueue(name, int(time)) counter += 1 end_time_list = [] current_time = 0 while not my_queue.is_empty(): current_time = time_forward(my_queue, q, current_time, end_time_list) for data in end_time_list: print data[0], data[1]
class Queue: def __init__(self, n): self.values = [None]*n self.n = n self.s = 0 self.t = 0 def next(self, p): ret = p+1 if ret >= self.n: ret = 0 return ret def enqueue(self, x): if self.next(self.s) == self.t: raise Exception("Overflow") self.values[self.s] = x self.s = self.next(self.s) def dequeue(self): if self.s == self.t: raise Exception("Underflow") ret = self.values[self.t] self.t = self.next(self.t) return ret n, q = map(int, raw_input().split(' ')) queue = Queue(n+1) for _ in range(n): name, time = raw_input().split(' ') time = int(time) queue.enqueue((name, time)) completed = [] cur = 0 while len(completed) < n: name, time = queue.dequeue() res = time-q if res <= 0: cur += time completed.append((name, cur)) else: cur += q queue.enqueue((name, res)) for name, time in completed: print name, time
1
43,407,940,220
null
19
19
import itertools N = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) l = [i+1 for i in range(N)] for i, tpl in enumerate(itertools.permutations(l, N)): if tpl == P: a = i if tpl == Q: b = i print(abs(a-b))
n = int( input() ) p = tuple( map( int, input().split() ) ) q = tuple( map( int, input().split() ) ) import itertools permutations = list( itertools.permutations( range( 1, n + 1 ) ) ) p_order = permutations.index( p ) q_order = permutations.index( q ) print( abs( p_order - q_order ) )
1
100,511,385,729,468
null
246
246
a,b,c = map(int, raw_input().split()) count = 0 while 1: if c % a == 0: count += 1 if a == b: break a += 1 print count
import math n, x, t = [int(x) for x in input().split()] print(math.ceil(n/x)*t)
0
null
2,434,045,812,640
44
86
import math N, X, T = map(int, input().split()) m = math.ceil(N/X) print(m*T)
N, M = map(int, input().split()) ans = [-1 for _ in range(N)] if N ==1: ans = 0 clis = [] for _ in range(M): s, c = map(int, input().split()) clis.append(c) if len(set(clis)) == 1: print(clis[0]) exit() elif len(set(clis)) == 0: print(0) exit() else: print(-1) exit() else: for _ in range(M): s, c = map(int, input().split()) if s == 1 and c == 0: print(-1) exit() if ans[s-1] == c or ans[s-1] == -1: ans[s-1] = c else: print(-1) exit() ans[0] = max(1, ans[0]) answer = '' for k in range(N): if ans[k] == -1: answer += '0' else: answer += str(ans[k]) print(answer)
0
null
32,697,715,155,852
86
208
n, k = map(int, input().split()) ww = [int(input()) for _ in range(n)] def chk(p): c = 1 s = 0 for w in ww: if w > p: return False if s + w <= p: s += w else: c += 1 s = w if c > k: return False return True def search(l, r): if r - l < 10: for i in range(l, r): if chk(i): return i m = (l + r) // 2 if chk(m): return search(l, m + 1) else: return search(m, r) print(search(0, 2 ** 30))
import math p_max = 1000000 * 1000000 n, k = map(int, input().split()) w = [int(input()) for i in range(n)] def check(p): i = 0 for j in range(k): s = 0 while (s + w[i] <= p): s += w[i] i += 1 if i == n: return n return i if __name__ == "__main__": right = p_max left = 0 mid = 0 while (right - left > 1): mid = math.floor((right + left) / 2) v = check(mid) if v >= n: right = mid else: left = mid print (right)
1
91,310,303,260
null
24
24
n = input() hon = [2, 4, 5, 7, 9] pon = [0, 1, 6, 8] if int(n[-1]) in hon: print("hon") elif int(n[-1]) in pon: print("pon") else: print("bon")
N = list(input()) l = len(N) if N[l-1] == '2' or N[l-1] == '4' or N[l-1] == '5' or N[l-1] == '7' or N[l-1] == '9': print('hon') elif N[l-1] == '0' or N[l-1] == '1' or N[l-1] == '6' or N[l-1] == '8': print('pon') elif N[l-1] == '3': print('bon')
1
19,263,390,846,266
null
142
142
h,w,y=map(int,input().split()) c=[input() for _ in range(h)] black=0 for i in range(h): for j in range(w): if c[i][j]=="#": black+=1 if black<y: print("0") exit() hb=[] wb=[] for i in range(h): hb.append(c[i].count("#")) for i in range(w): count=0 for j in range(h): if c[j][i]=="#": count+=1 wb.append(count) bit=[] for i in range(2**(h+w)): #行:[:h]、列:[h+1:] bit.append(bin(i)[2:].zfill(h+w)) ans=0 for i in bit: x=black for j in range(h): if i[j]=="1": for k in range(w): if i[h+k]=="1" and c[j][k]=="#": x+=1 for j in range(h): if i[j]=="1": x-=hb[j] for j in range(w): if i[h+j]=="1": x-=wb[j] if x==y: ans+=1 print(ans)
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) n,m=nii() print('Yes' if n==m else 'No')
0
null
46,039,195,773,152
110
231
# -*- coding: utf-8 -*- # 入力を整数に変換して受け取る def input_int(): return int(input()) # マイナス1した値を返却 def int1(x): return int(x) - 1 # 半角スペース区切り入力をIntに変換してMapで受け取る def input_to_int_map(): return map(int, input().split()) # 半角スペース区切り入力をIntに変換して受け取る def input_to_int_tuple(): return tuple(map(int, input().split())) # 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る def input_to_int_tuple_minus1(): return tuple(map(int1, input().split())) def main(): n = input_int() cnt = [[0] * 10 for i in range(10)] for n in range(1, n + 1): cnt[int(str(n)[0])][int(str(n)[-1])] += 1 ret = 0 for i in range(10): for j in range(10): ret += cnt[i][j] * cnt[j][i] return ret if __name__ == "__main__": print(main())
ii = lambda : int(input()) mi = lambda : map(int,input().split()) li = lambda : list(map(int,input().split())) n = ii() def get_head(x): while x: b = x%10 x //= 10 return b dp = [[0] * 10 for i in range(10)] for i in range(1,n+1): h = get_head(i) t = i%10 dp[h][t] += 1 for i in range(10): dp[0][i] = 0 dp[i][0] = 0 ans = 0 for i in range(1,n+1): h = get_head(i) t = i%10 ans += dp[t][h] print(ans)
1
86,631,328,652,700
null
234
234
import sys n = sys.stdin.readline() s = sys.stdin.readline().split() q = sys.stdin.readline() t = sys.stdin.readline().split() cnt = 0 for i in t: if i in s: cnt += 1 print(cnt)
n = int(input()) S = list(map(int,input().split())) q = int(input()) T = list(map(int,input().split())) S.append(-1) sum = 0 for i in T: count = 0 while True: if i != S[count]: count += 1 else: sum += 1 break if S[count] == -1: break print(sum)
1
64,346,591,078
null
22
22
N,A,B=map(int,input().split()) if (A+B)%2==0: P=(B-A)//2 else: P=float("inf") if (A+B)%2==1: Q=A Q+=(B-Q-(B-Q+1)//2) else: Q=float("inf") if (A+B)%2==1: R=N-B+1 B=N A+=R R+=B-(A+B)//2 else: R=float("inf") print(min(P,Q,R))
N,M = (int(a) for a in input().split()) x = N*(N-1)/2 y = M*(M-1)/2 print(int(x+y))
0
null
77,727,849,318,976
253
189
N = input() l = len(N) for i in range(l): if N[i] =="7": print("Yes") exit() print("No")
N=input() if N.count("7"): print("Yes") else: print("No")
1
34,161,779,478,618
null
172
172
inData = int(input()) inSeries = [int(i) for i in input().split()] outData =[0]*inData for i in range(inData): outData[i] = inSeries[inData-1-i] print(" ".join(map(str,outData)))
k=int(input()) s=list(input()) num_list=[] if k<len(s): for x in range(k): num_list+=s[x] x+=1 t=''.join(num_list)+'...' else: t=''.join(s) print(t)
0
null
10,316,373,491,112
53
143
import sys import string s = sys.stdin.read().lower() for a in string.ascii_lowercase: print('{0} : {1}'.format(a, s.count(a)))
import collections import sys S = "".join([line for line in sys.stdin]) count = collections.Counter(S.lower()) for char in "abcdefghijklmnopqrstuvwxyz": print("{0:s} : {1:d}".format(char, count[char]))
1
1,681,662,906,068
null
63
63
i = int(input()) print(i^1)
# ['表面', '南面', '東面', '西面', '北面', '裏面'] dice = input().split() com = [c for c in input()] rolling = { 'E': [3, 1, 0, 5, 4, 2], 'W': [2, 1, 5, 0, 4, 3], 'S': [4, 0, 2, 3, 5, 1], 'N': [1, 5, 2, 3, 0, 4] } for c in com: dice = [dice[i] for i in rolling[c]] print(dice[0])
0
null
1,565,826,595,230
76
33
num_list = [] while True: values = [int(x) for x in input().split()] if 0 == values[0] and 0 == values[1]: break num_list.append(values) for n, t in num_list: ret = ' '.join(str(x + y + z) for x in range(1, n + 1) for y in range(x + 1, n + 1) for z in range(y + 1, n + 1)) cnt = 0 for x in ret.split(): if str(t) == x: cnt += 1 print(cnt)
while True: [n, m] = [int(x) for x in raw_input().split()] if [n, m] == [0, 0]: break data = [] for x in range(n, 2, -1): if 3 * x - 2 < m: break for y in range(x - 1, 1, -1): for z in range(y - 1, 0, -1): s = x + y + z if s < m: break if s == m: data.append(s) print(len(data))
1
1,284,168,927,518
null
58
58
s=input() t=input() for i in range(len(s)): if s[i]!=t[i]: print("No") exit() if len(t)==len(s)+1: print("Yes")
s = str(input()) t = str(input()) flag = 0 for i in range(len(s)): if s[i] == t[i]: continue else: print('No') flag = 1 break if flag == 0: print('Yes')
1
21,395,032,684,832
null
147
147
if __name__ == '__main__': from sys import stdin from itertools import combinations while True: n, x = (int(n) for n in stdin.readline().rstrip().split()) if n == x == 0: break a = range(1, n + 1) l = tuple(filter(lambda _: sum(_) == x, combinations(a, 3))) print(len(l))
S = str(input()) s = list(map(str,S)) if s[2] == s[3] and s[4] == s[5]: print('Yes') else: print('No')
0
null
21,540,116,224,320
58
184
print input()**2
r = int(input()) if 1 <= r <= 100: print(int(r*r))
1
145,352,500,452,600
null
278
278
import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int, input().split()) sys.setrecursionlimit(10**9) X = int(input()) dp = [0]*(X+1) dp[0] = 1 for i in range(1, X+1): for yen in range(100, 106): if yen<=i: if dp[i-yen]==1: dp[i] = 1 if dp[X]: print(1) else: print(0)
a=int(input()) x=(a-2)/2 if int(x) ==x: print(int(x)) else: print(int(x+1))
0
null
140,940,020,227,952
266
283
A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) v=V-W l=abs(A-B) if l<=v*T: print("YES") else: print("NO")
A, V = map(int, input().split()) B, W = map(int, input().split()) T = int(input()) print("YES" if (V-W)*T >= abs(B-A) else "NO")
1
15,082,312,362,080
null
131
131
from math import sqrt while True: input_data =[] # ????´?????????? alpha = 0 # ?????? num = int(input()) if num == 0: break input_data = [float(i) for i in input().split()] m = sum(input_data) / float(num) for i in range(num): alpha += (input_data[i] - m)**2 print(sqrt(alpha/num))
# -*- coding: utf-8 -*- # E import sys from collections import defaultdict, deque from heapq import heappush, heappop import math import bisect input = sys.stdin.readline # 再起回数上限変更 # sys.setrecursionlimit(1000000) n = int(input()) d1 = [] * n d2 = [] * n for i in range(n): x, y = map(int, input().split()) d1.append(x+y) d2.append(x-y) print(max(max(d1) - min(d1), max(d2)-min(d2)))
0
null
1,790,320,656,724
31
80
import queue def main(): h, w = map(int, input().split()) st = [[1]*(w+2) for _ in range(h+2)] for i in range(h): s = input() for j in range(w): if s[j] == ".": st[i+1][j+1] = 0 ans = 0 for i in range(1, h+2): for j in range(1, w+2): if st[i][j] == 0: fs = [[float("inf")]*(w+2) for _ in range(h+2)] q = queue.Queue() fs[i][j] = 0 q.put([i, j]) while not q.empty(): y, x = q.get() if st[y-1][x] == 0 and fs[y-1][x] > fs[y][x] + 1: fs[y-1][x] = fs[y][x] + 1 q.put([y-1, x]) if st[y+1][x] == 0 and fs[y+1][x] > fs[y][x] + 1: fs[y+1][x] = fs[y][x] + 1 q.put([y+1, x]) if st[y][x-1] == 0 and fs[y][x-1] > fs[y][x] + 1: fs[y][x-1] = fs[y][x] + 1 q.put([y, x-1]) if st[y][x+1] == 0 and fs[y][x+1] > fs[y][x] + 1: fs[y][x+1] = fs[y][x] + 1 q.put([y, x+1]) if ans < fs[y][x]: ans = fs[y][x] print(ans) if __name__ == "__main__": main()
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)
1
94,397,225,136,910
null
241
241
a,b=(map(int,input().split())) c=0 if a<=b: print(0) elif a>b: c=a-b*2 if c>0: print(c) elif c<=0: print(0)
def resolve(): a,b = map(int,input().split()) print(0 if a<b*2 else a-b*2) resolve()
1
166,775,175,361,390
null
291
291
n = input() list = [] list = map(str, raw_input().split()) list.reverse() print " ".join(list)
# -*- coding: utf-8 -*- """ Created on Sun Jun 18 10:01:05 2017 @author: syaga """ if __name__ == "__main__": N = int(input()) C = list(input().split()) D = C[:] # Bunbble Sort for i in range(0, N): for j in range(N-1, i, -1): if int(C[j][1]) < int(C[j-1][1]): temp = C[j] C[j] = C[j-1] C[j-1] = temp print(" ".join(C)) print("Stable") # Selection Sort for i in range(0, N): minj = i for j in range(i, N): if int(D[j][1]) < int(D[minj][1]): minj = j temp = D[i] D[i] = D[minj] D[minj] = temp print(" ".join(D)) flag = 0 for (i, j) in zip(C, D): if i != j: flag = 1 break if flag == 1: print("Not stable") else: print("Stable")
0
null
499,675,181,628
53
16