├── .vscode └── header.code-snippets ├── bai1.py ├── bai2.py ├── bai3.py ├── bai4.py ├── bai5.py ├── baitoandem.py ├── baitoantohop.py ├── bangxephang.py ├── baucu.py ├── biendoidayso.py ├── biendoinguyento.py ├── biendoive1.py ├── biendoivedaybangnhau.py ├── biendoivematranvuong.py ├── bobanguyentocungnhau.py ├── capnghichthe.py ├── cauhoitheochude1.py ├── chanle.py ├── chanlenguyento.py ├── chendauphay.py ├── chenxau.py ├── chiaducho42.py ├── chiahetchok.py ├── chucmungnammoi.py ├── chuhoachuthuong.py ├── chusonguyento.py ├── chuyendoinhiphan.py ├── chuyenthanhchuhoa.py ├── consoduyenno.py ├── cunghoangdao.py ├── datten.py ├── daucuoi.py ├── daucuoinguyento.py ├── dayconchungcubadayso.py ├── daysonhiphan.py ├── daysophuhop.py ├── demcacsocohaichuso.py ├── demcapdongxu.py ├── demsotrongxau.py ├── diachiip.py ├── dienso.py ├── doancuoinguyento.py ├── doichocacchuso.py ├── doicoso.py ├── dothihinhsao.py ├── emirpnumber.py ├── giaima.py ├── guithongbao.py ├── hecoso8.py ├── hello.py ├── hieusonguyenlon.py ├── hoanvikytu.py ├── hoanvinguoc.py ├── khoangcachnguyento.py ├── khoiphucdayso.py ├── kiemtrachanle.py ├── kiemtrachiahetcho7.py ├── kiemtrahecoso3.py ├── kiemtranguyento.py ├── kiemtranguyento2.py ├── kiemtrasodep.py ├── laisuatnganhang.py ├── lamtronso.py ├── lietkecacsocohaichusotangdan.py ├── lietkecacsocohaichusotheothutuxuathien.py ├── lietkecapsonguyentocungnhau.py ├── lietkesonguyentotrongday.py ├── lietsofibonacci.py ├── lonnhatvanhonhat.py ├── lopphanso1.py ├── lopphanso2.py ├── loppoint.py ├── loprectangle.py ├── lopthisinh1.py ├── mahoa1.py ├── mahoa2.py ├── mahoa3.py ├── main.py ├── nguongtoithieu.py ├── nguyento.py ├── nguyentocungnhau.py ├── nguyentocungnhau2.py ├── perfectprime.py ├── phanchianguyento.py ├── phantichthuasonguyento.py ├── phepcong.py ├── primetriplet.py ├── pythonfile.py ├── sapdatlaixaukytu.py ├── sapxepchanle.py ├── sapxepdayso.py ├── sapxepnguyento.py ├── sapxeptheotichchuso.py ├── sapxeptheotongchuso.py ├── sochiahetcho3.py ├── sodaonguyentocungnhau.py ├── sodeptrongmatran.py ├── sokhonggiam.py ├── sokrish.py ├── solocphatdep.py ├── somayman1.py ├── somayman2.py ├── somaymantrongmatran.py ├── songuyenlon.py ├── songuyentolonnhattrongmatran.py ├── songuyentotrongmatran.py ├── sonhonhatconthieu.py ├── sophatloc.py ├── sotanggiam.py ├── sothuannghich.py ├── sothuannghichchan.py ├── sothuannghichlonnhattrongmatran.py ├── sothuannghichtrongmatran.py ├── soxenke.py ├── tachdoivatinhtong.py ├── tachsovasapxep.py ├── tachtu.py ├── tansuatle.py ├── taphopsobangnhau.py ├── taphopsonguyen.py ├── thongkedichte.py ├── thongketukhacnhau.py ├── thongketukhacnhaukhongchuachuso.py ├── thongketukhacnhautheonguongk.py ├── thuphixeoto.py ├── tichchuso.py ├── tichchusotongchuso.py ├── tichlonnhat.py ├── timsolonnhat.py ├── timsonhonhat.py ├── tinhcandoicuamatran1.py ├── tinhcandoicuamatran2.py ├── tinhdiemthiielts.py ├── tinhdiemtrungbinh.py ├── tinhtongcacchuso.py ├── tinhtongphanthuc.py ├── tongchuso.py ├── tongchusonguyento.py ├── tongchusothuannghich.py ├── tongchusotichchuso.py ├── tongsonguyenlon.py ├── trungthuong.py ├── uocsochungnguyento.py ├── uocsocuagiaithua.py ├── uuthenguyento.py ├── vitringuyento.py ├── welcometopython.py ├── xacdinhtheloaitho.py ├── xaupalindrome.py ├── xauthangbang.py ├── xoaymang.py ├── xuathiennhieulannhat.py ├── xulyvanban.py └── xulyxaukytu.py /.vscode/header.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | // Place your Python workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 3 | // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 4 | // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 5 | // used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 6 | // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 7 | // Placeholders with the same ids are connected. 8 | // Example: 9 | // "Print to console": { 10 | // "scope": "javascript,typescript", 11 | // "prefix": "log", 12 | // "body": [ 13 | // "console.log('$1');", 14 | // "$2" 15 | // ], 16 | // "description": "Log output to console" 17 | // } 18 | "": { 19 | "prefix": "cnew", 20 | "body": [ 21 | "\"\"\"", 22 | "Author: Tris1702", 23 | "Github: https://github.com/Tris1702", 24 | "Gmail: phuonghoand2001@gmail.com", 25 | "Thank you so much!", 26 | "\"\"\"", 27 | "" 28 | ], 29 | "description": "" 30 | } 31 | } -------------------------------------------------------------------------------- /bai1.py: -------------------------------------------------------------------------------- 1 | def bai1(): 2 | a = list(int(i) for i in input().split()) 3 | # xoa phan tu cuoi 4 | a.pop() 5 | print(a) 6 | # Chen 7 | a.insert(3, 10) 8 | print(a) 9 | # Doi gia tri 10 | a[0] = 'Python' 11 | print(a) 12 | 13 | def bai2(): 14 | a = list(int(i) for i in input().split()) 15 | # swap 16 | t = a[0] 17 | a[0] = a[-1] 18 | a[-1] = t 19 | print(a) 20 | 21 | def bai3(): 22 | a = list(int(i) for i in input().split()) 23 | b = list(i for i in a if i%2 != 0) 24 | # b =[] 25 | # for i in a: 26 | # if i %2 != 0: b.append(i) 27 | print(b) 28 | 29 | def bai4(): 30 | a = input().split() 31 | sum = 0 32 | sl = 0 33 | for i in a: 34 | if i.isnumeric(): 35 | sum += int(i) 36 | sl += 1 37 | print(sum, sum//sl) 38 | 39 | def bai5(): 40 | a = [4, 2, 3, 1, 4, 6, 4] 41 | for i in range(0, len(a)): 42 | a[i] *= a[i] 43 | print(sorted(a, reverse= True)) 44 | def bai6(): 45 | a = [1, 'a', 34, 'a', 'b', 1, 'c'] 46 | b = [] 47 | for i in a: 48 | if i not in b: 49 | b.append(i) 50 | print(len(b)) 51 | 52 | bai5() 53 | bai6() -------------------------------------------------------------------------------- /bai2.py: -------------------------------------------------------------------------------- 1 | fav_number = 27 2 | print('''My favourite number has 2 digits 3 | The first one is the first prime 4 | and the second one is the 4th prime 5 | ------------- 6 | Answer: ''', fav_number) -------------------------------------------------------------------------------- /bai3.py: -------------------------------------------------------------------------------- 1 | c1 = 5 + 1.3j 2 | c2 = 6 + 1.5j 3 | print(c2+c1) 4 | print(c2-c1) -------------------------------------------------------------------------------- /bai4.py: -------------------------------------------------------------------------------- 1 | s = '''Hello 2 | Xin chao 3 | Hola 4 | Konichiwa''' 5 | s1 = s.split('\n') 6 | 7 | max = s1[0] 8 | min = s1[0] 9 | for i in s1: 10 | if len(max) < len(i): 11 | max = i 12 | if len(min) > len(i): 13 | min = i 14 | print(max, min) 15 | -------------------------------------------------------------------------------- /bai5.py: -------------------------------------------------------------------------------- 1 | s1 = "Chao PTIT" 2 | s2 = " mung den voi" 3 | s3 = s1[:len(s1)//2] + s2 + s1[len(s1)//2:] 4 | print(s3) -------------------------------------------------------------------------------- /baitoandem.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | a = [] 10 | while True: 11 | a.extend(list(int(x) for x in input().split())) 12 | # print(len(a)) 13 | if len(a) == n: break 14 | a.sort() 15 | check = 0 16 | for i in range(1, max(a)): 17 | if i not in a: 18 | print(i) 19 | check = 1 20 | 21 | if check == 0: 22 | print('Excellent!') -------------------------------------------------------------------------------- /baitoantohop.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | from itertools import combinations 8 | 9 | n,k = map(int, input().split()) 10 | l = list(set(int(x) for x in input().split())) 11 | l.sort() 12 | res = combinations(l,k) 13 | for i in res: 14 | print(*i) -------------------------------------------------------------------------------- /bangxephang.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | -------------------------------------------------------------------------------- /baucu.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n, m = map(int, input().split()) 9 | a = list(int(i) for i in input().split()) 10 | result = {} 11 | for i in a: 12 | if i not in result: 13 | result[i] = 1 14 | else: result[i] += 1 15 | result = sorted(result.items(), key = lambda x : (x[1], -x[0]), reverse=True) 16 | if result[0][1] == result[-1][1]: print("NONE") 17 | else: 18 | it = 1 19 | while (result[it][1] == result[0][1]): it += 1 20 | print(result[it][0]) -------------------------------------------------------------------------------- /biendoidayso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def allEqual(a): 9 | return a[0] == a[1] and a[1] == a[2] and a[2] == a[3] 10 | 11 | while True: 12 | arr = list(int(i) for i in input().split()) 13 | if arr[0] == 0 and allEqual(arr): 14 | break 15 | count = 0 16 | while allEqual(arr) == False: 17 | count = count + 1 18 | tmp = arr[0] 19 | arr[0] = abs(arr[0] - arr[1]) 20 | arr[1] = abs(arr[1] - arr[2]) 21 | arr[2] = abs(arr[2] - arr[3]) 22 | arr[3] = abs(arr[3] - tmp) 23 | # print(arr) 24 | print(count) -------------------------------------------------------------------------------- /biendoinguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | prime = [] 10 | 11 | def isPrime(x): 12 | for i in range(2, int(math.sqrt(x))+1): 13 | if x % i == 0: return False 14 | return x > 1 15 | 16 | def genPrime(): 17 | for i in range(10**5): 18 | if isPrime(i): 19 | prime.append(i) 20 | def BS(l, r, x): 21 | res = r 22 | while l <= r: 23 | mid = (l+r)//2 24 | if prime[mid] == x: return mid 25 | if prime[mid] < x: 26 | l = mid+1 27 | else: 28 | res = mid 29 | r = mid - 1 30 | return res 31 | 32 | 33 | genPrime() 34 | n = int(input()) 35 | a = list(int(i) for i in input().split()) 36 | a = set(a) 37 | inc = [0] 38 | dec = [0] 39 | tmp = [] 40 | 41 | for i in a: 42 | if isPrime(i): 43 | continue 44 | else: 45 | it1 = BS(0, len(prime)-1, i) 46 | it2 = it1 - 1 47 | # print (i, end = ' ') 48 | if it2 < 0: 49 | # print(prime[it1], end=' ') 50 | inc.append(prime[it1]-i) 51 | else: 52 | if abs(prime[it1] - i) < abs(prime[it2] - i): 53 | # print(prime[it1], end=' ') 54 | inc.append(prime[it1] - i) 55 | elif abs(prime[it1] - i) > abs(prime[it2] - i): 56 | # print(prime[it2], end=' ') 57 | dec.append(prime[it2]-i) 58 | else: 59 | tmp.append(i) 60 | maxx = max(max(inc), max(dec)) 61 | for i in tmp: 62 | it1 = BS(0, len(prime)-1, i) 63 | if prime[it1]-i > maxx: inc.append(prime[it1]-i) 64 | inc = set(inc) 65 | dec = set(dec) 66 | num1 = max(dec) 67 | num2 = max(inc) 68 | print(num1+num2) 69 | 70 | -------------------------------------------------------------------------------- /biendoive1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | while True: 8 | N = int(input()) 9 | if N == 0: 10 | break 11 | count = {N: 1} 12 | while N != 1: 13 | if N%2 == 0: 14 | N = int(N/2) 15 | else: 16 | N = N*3 + 1 17 | if N not in count: 18 | count[N] = 1 19 | print(len(count)) -------------------------------------------------------------------------------- /biendoivedaybangnhau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | a = list(int(i) for i in input().split()) 10 | minn = 10**9 11 | res = 0 12 | for i in a: 13 | count = 0 14 | for j in a: 15 | count += abs(j-i) 16 | if count < minn: 17 | minn = count 18 | res = i 19 | print(minn, res) 20 | -------------------------------------------------------------------------------- /biendoivematranvuong.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | n,m = map(int, input().split()) 8 | a = [] 9 | for i in range(n): 10 | a.append(list(int(i) for i in input().split())) 11 | 12 | hbo = [] 13 | cbo = [] 14 | nn = n 15 | mm = m 16 | if n > m: 17 | for i in range(0, n, 2): 18 | hbo.append(i) 19 | n-= 1 20 | if n == m: break 21 | if n < m: 22 | for i in range(1, m, 2): 23 | cbo.append(i) 24 | m-=1 25 | if n == m: break 26 | for i in range(nn): 27 | if i in hbo: continue 28 | for j in range(mm): 29 | if j in cbo: continue 30 | print(a[i][j], end =' ') 31 | print() 32 | -------------------------------------------------------------------------------- /bobanguyentocungnhau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def gcd(a, b): 10 | while (a > 0): 11 | if a < b: 12 | a, b = b, a 13 | a %= b 14 | return b 15 | 16 | a, b = map(int,input().split()) 17 | l = [] 18 | for i in range(a, b-1): 19 | for j in range (i+1, b): 20 | if gcd(i, j) == 1: 21 | l.append([i, j]) 22 | for coup in l: 23 | for i in range(coup[1]+1, b+1): 24 | if (gcd(i, coup[0])==1) and (gcd(i, coup[1]) == 1): 25 | print('(' + str(coup[0]) + ', ' + str(coup[1])+', ' + str(i) + ')') -------------------------------------------------------------------------------- /capnghichthe.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | arr = list(int(i) for i in input().split()) 10 | count = 0 11 | for i in range(0, len(arr)): 12 | for j in range(i+1, len(arr)): 13 | if arr[j] < arr[i]: 14 | count = count + 1 15 | 16 | print(count) -------------------------------------------------------------------------------- /cauhoitheochude1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | N = int(input()) 9 | dem = 0 10 | 11 | while dem < N: 12 | topic = input() 13 | res = 0 14 | dem += 1 15 | s = '#' 16 | while len(s) > 0 and dem < N: 17 | s = input() 18 | if len(s)>0: 19 | res += 1 20 | dem += 1 21 | print(topic+': '+str(res)) -------------------------------------------------------------------------------- /chanle.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def checkSumOfDigits(x): 9 | sum = 0 10 | for i in x: 11 | sum = sum + int(i) 12 | return sum % 10 == 0 13 | 14 | def checkDifferenceBetweenTwoDigits(x): 15 | for i in range(1, len(x)): 16 | if abs(int(x[i])- int(x[i-1])) != 2: 17 | return False 18 | return True 19 | 20 | T = int(input()) 21 | for t in range(T): 22 | x = input() 23 | if checkDifferenceBetweenTwoDigits(x) and checkSumOfDigits(x): 24 | print('YES') 25 | else: 26 | print('NO') -------------------------------------------------------------------------------- /chanlenguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def isPrime(x): 10 | for i in range(2, int(math.sqrt(x))+1): 11 | if x % i == 0: 12 | return False 13 | return x > 1 14 | 15 | T = int(input()) 16 | evenDigit = ['0', '2', '4', '6', '8'] 17 | for t in range(T): 18 | s = input() 19 | sum = 0 20 | check = True 21 | for i in range(0, len(s)): 22 | sum += int(s[i]) 23 | if i % 2 == 0: 24 | if s[i] not in evenDigit: 25 | check = False 26 | break 27 | else: 28 | if s[i] in evenDigit: 29 | check = False 30 | break 31 | if check and isPrime(sum): 32 | print('YES') 33 | else: 34 | print('NO') -------------------------------------------------------------------------------- /chendauphay.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | s = input()[::-1] 8 | res ='' 9 | for i in range(0, len(s)): 10 | res = s[i] + res 11 | if i % 3 == 2: 12 | res = ',' + res 13 | 14 | print(res.lstrip(',')) -------------------------------------------------------------------------------- /chenxau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | s1 = input() 9 | s2 = input() 10 | vt = int(input()) - 1 11 | check = True 12 | for i in range(0, len(s1)): 13 | if (i == vt): 14 | print(s2, end = '') 15 | check = False 16 | print(s1[i], end = '') 17 | if check: print(s2) -------------------------------------------------------------------------------- /chiaducho42.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | r = [] 8 | count = 0 9 | while (input()): 10 | for i in input().split(): 11 | so = int(i) % 42 12 | if (so in r) == False: 13 | r.append(so) 14 | print(len(r)) -------------------------------------------------------------------------------- /chiahetchok.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | count = 0 9 | a, k, n = map(int, input().split()) 10 | 11 | st = (int(a/k) + 1) * k 12 | 13 | for i in range(st, n+1, k): 14 | print(i-a, end = ' ') 15 | count = count + 1 16 | if count == 0: 17 | print(-1) 18 | else: 19 | print() 20 | 21 | -------------------------------------------------------------------------------- /chucmungnammoi.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | l=[] 9 | dem = 0 10 | n = int(input()) 11 | for i in range(n): 12 | x = input() 13 | if x not in l: 14 | l.append(x) 15 | dem += 1 16 | print(dem) -------------------------------------------------------------------------------- /chuhoachuthuong.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | s = input() 8 | dem = 0 9 | for i in s: 10 | if i.islower(): 11 | dem = dem+1 12 | if dem >= len(s)-dem: 13 | print(s.lower()) 14 | else: 15 | print(s.upper()) 16 | -------------------------------------------------------------------------------- /chusonguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x%i==0: return False 11 | return x > 1 12 | 13 | def check(s): 14 | dem = 0 15 | if isPrime(len(s)) == False: return False 16 | for i in s: 17 | if isPrime(int(i)): dem+=1 18 | return dem*2 > len(s) 19 | 20 | n = int(input()) 21 | 22 | for i in range(n): 23 | if check(input()): 24 | print('YES') 25 | else: print('NO') 26 | 27 | -------------------------------------------------------------------------------- /chuyendoinhiphan.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def w(so): 9 | if so < 10: return str(so) 10 | if so == 10: return 'A' 11 | if so == 11: return 'B' 12 | if so == 12: return 'C' 13 | if so == 13: return 'D' 14 | if so == 14: return 'E' 15 | if so == 15: return 'F' 16 | 17 | 18 | def doi(s, sl): 19 | while len(s) % sl != 0: s = '0'+s 20 | res = '' 21 | for i in range(len(s)-1, 0, -sl): 22 | x = 1 23 | so = 0 24 | for j in range(i, i-sl, -1): 25 | if j >= 0: 26 | so += x*int(s[j]) 27 | x *= 2 28 | res = res + w(so) 29 | return res[::-1] 30 | 31 | T = int(input().strip()) 32 | for t in range(T): 33 | N = int(input().strip()) 34 | s = input().strip() 35 | if N == 2: 36 | print(s) 37 | elif N == 4: 38 | print(doi(s, 2)) 39 | elif N == 8: 40 | print(doi(s, 3)) 41 | else: print(doi(s, 4)) -------------------------------------------------------------------------------- /chuyenthanhchuhoa.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | s = input() 8 | print(s.upper()) -------------------------------------------------------------------------------- /consoduyenno.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | x = input() 11 | print('YES' if x[0] == x[-1] else 'NO') -------------------------------------------------------------------------------- /cunghoangdao.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | for i in range(n): 10 | dd, mm = map(int, input().split()) 11 | 12 | if mm == 1: 13 | if dd >= 20: print('Bao Binh') 14 | else: print('Ma Ket') 15 | 16 | if mm == 2: 17 | if dd >= 19: print('Song Ngu') 18 | else: print('Bao Binh') 19 | 20 | if mm == 3: 21 | if dd >= 21: print('Bach Duong') 22 | else: print('Song Ngu') 23 | 24 | if mm == 4: 25 | if dd >=20: print('Kim Nguu') 26 | else: print('Bach Duong') 27 | 28 | if mm == 5: 29 | if dd >=21: print('Song Tu') 30 | else: print('Kim Nguu') 31 | if mm == 6: 32 | if dd >=21: print('Cu Giai') 33 | else: print('Song Tu') 34 | 35 | if mm == 7: 36 | if dd >=23: print('Su Tu') 37 | else: print('Cu Giai') 38 | 39 | if mm == 8: 40 | if dd >=23: print('Xu Nu') 41 | else: print('Su Tu') 42 | 43 | if mm == 9: 44 | if dd >=23: print('Thien Binh') 45 | else: print('Xu Nu') 46 | 47 | if mm == 10: 48 | if dd >=23: print('Thien Yet') 49 | else: print('Thien Binh') 50 | 51 | if mm == 11: 52 | if dd >=23: print('Nhan Ma') 53 | else: print('Thien Yet') 54 | 55 | if mm == 12: 56 | if dd >=22: print('Ma Ket') 57 | else: print('Nhan Ma') 58 | -------------------------------------------------------------------------------- /datten.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | # WA? :) what? 9 | l = [] 10 | res = [] 11 | def genToHop(l, n, k, vt, s, pre): 12 | # print(s) 13 | if vt == n: return 14 | if len(s.split()) == k: 15 | res.append(s) 16 | for i in range(pre+1, n): 17 | genToHop(l, n, k, vt+1, s+" "+ str(l[i]), i) 18 | n,k = map(int, input().split()) 19 | l = list(set(input().split())) 20 | genToHop(sorted(l, key= lambda x: x[0]), len(l), k, 0, '', -1) 21 | for i in res: 22 | print(i[1:]) -------------------------------------------------------------------------------- /daucuoi.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | T = int(input()) 8 | for t in range(T): 9 | so = input() 10 | length = len(so) 11 | if length >=4 and so[0] == so[length-2] and so[1] == so[length-1]: 12 | print('YES') 13 | else: 14 | print('NO') -------------------------------------------------------------------------------- /daucuoinguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def isPrime(x): 10 | for i in range(2, int(math.sqrt(x))+1): 11 | if x % i == 0: 12 | return False 13 | return x > 1 14 | 15 | T = int(input()) 16 | for t in range(T): 17 | s = input() 18 | num1 = s[:3] 19 | num2 = s[len(s)-3:] 20 | if isPrime(int(num1)) and isPrime(int(num2)): 21 | print('YES') 22 | else: print('NO') -------------------------------------------------------------------------------- /dayconchungcubadayso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def solve(): 9 | n1, n2, n3 = map(int, input().split()) 10 | a = list(int(x) for x in input().split()) 11 | b = list(int(x) for x in input().split()) 12 | c = list(int(x) for x in input().split()) 13 | i = 0 14 | j = 0 15 | k = 0 16 | check = True 17 | while i < n1 and j < n2 and k < n3: 18 | if a[i] == b[j] and b[j] == c[k]: 19 | print(a[i], end = ' ') 20 | check = False 21 | i = i + 1 22 | j = j + 1 23 | k = k + 1 24 | continue 25 | if a[i] < b[j] or a[i] < c[k]: 26 | i = i + 1 27 | continue 28 | if b[j] < c[k] or b[j] arr2[i]: 18 | check = 'NO' 19 | break 20 | print(check) -------------------------------------------------------------------------------- /demcacsocohaichuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | s = input() 9 | a = {} 10 | for i in range(1, len(s), 2): 11 | so = int(s[i-1])*10+int(s[i]) 12 | if so not in a: 13 | a[so] = 1 14 | else: a[so] += 1 15 | for i in a.keys(): 16 | print(str(i) + " " + str(a[i])) -------------------------------------------------------------------------------- /demcapdongxu.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | arr = [] 10 | for i in range(n): 11 | s = input() 12 | tmp = [] 13 | for j in s: 14 | tmp.append(j) 15 | arr.append(tmp) 16 | res = 0 17 | for i in range(n): 18 | sl = 0 19 | for j in range(n): 20 | if arr[i][j] == 'C': 21 | res = res + sl 22 | sl = sl+1 23 | 24 | for j in range(n): 25 | sl = 0 26 | for i in range(n): 27 | if arr[i][j] == 'C': 28 | res = res + sl 29 | sl = sl +1 30 | print(res) -------------------------------------------------------------------------------- /demsotrongxau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | s = input() 11 | so = input() 12 | print(s.count(so)) -------------------------------------------------------------------------------- /diachiip.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def isIPAddress(x): 9 | if len(x) != 4: return False 10 | for i in x: 11 | if i.isdecimal(): 12 | if int(i) < 0 or int(i) > 255: return False 13 | else: return False 14 | return True 15 | T = int(input()) 16 | 17 | for t in range(T): 18 | if isIPAddress(input().split('.')): print('YES') 19 | else: print('NO') 20 | -------------------------------------------------------------------------------- /dienso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | 10 | for t in range(T): 11 | n = int(input()) 12 | l = list(set(int(x) for x in input().split())) 13 | res = 0 14 | for i in range(1,len(l)): 15 | if l[i] > l[i-1]+1: 16 | res += l[i] - l[i-1] - 1 17 | print(res) -------------------------------------------------------------------------------- /doancuoinguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def isPrime(x): 10 | for i in range(2, int(math.sqrt(x))+1): 11 | if x % i == 0: 12 | return False 13 | return x > 1 14 | 15 | T = int(input()) 16 | for t in range(T): 17 | s = input() 18 | num = s[len(s)-4:] 19 | if isPrime(int(num)): 20 | print('YES') 21 | else: print('NO') -------------------------------------------------------------------------------- /doichocacchuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | s = list(str(i) for i in input()) 11 | if len(s) == 1: 12 | print(-1) 13 | continue 14 | i = len(s)-2 15 | while i >= 0 and s[i] <= s[i+1]: 16 | i = i - 1 17 | if (i < 0): 18 | print(-1) 19 | else: 20 | max = i+1 21 | for j in range(i+1, len(s)): 22 | if s[j] < s[i] and s[j] > s[max]: 23 | max = j 24 | s[max], s[i] = s[i], s[max] 25 | if s[0] == '0': 26 | print(-1) 27 | else: 28 | for j in s: 29 | print(j,end='') 30 | print() 31 | -------------------------------------------------------------------------------- /doicoso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | xchange = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 9 | 10 | def change(x, k): 11 | res = '' 12 | while (x > 0): 13 | r = x % k 14 | res = xchange[r] + res 15 | x = int(x/k) 16 | return res 17 | T = int(input()) 18 | for t in range(T): 19 | x, k = map(int,input().split()) 20 | print(change(x, k)) -------------------------------------------------------------------------------- /dothihinhsao.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | d ={} 10 | for i in range(n-1): 11 | a, b = map(int, input().split()) 12 | if a not in d: 13 | d[a] = 1 14 | else: d[a] += 1 15 | if b not in d: 16 | d[b] = 1 17 | else: d[b] += 1 18 | 19 | dem1 = 0 20 | dem2 = 0 21 | for i in d.keys(): 22 | if d[i] == 1: dem1 += 1 23 | if d[i] == n-1: dem2 += 1 24 | print('Yes' if (dem1 == n-1 and dem2 == 1) else 'No') -------------------------------------------------------------------------------- /emirpnumber.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x%i == 0: return False 11 | return x > 1 12 | 13 | 14 | 15 | T = int(input()) 16 | for t in range(T): 17 | n = int(input()) 18 | dd = {} 19 | for i in range(10, n): 20 | x1 = str(i)[::-1] 21 | x2 = str(i) 22 | if x1 != x2: 23 | j = int(x1) 24 | if j >= n: continue 25 | if i not in dd: 26 | dd[j] = 1 27 | if isPrime(i) and isPrime(j): 28 | print(i, j, end = ' ') 29 | print() 30 | -------------------------------------------------------------------------------- /giaima.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | T = int(input()) 8 | for t in range (0, T): 9 | s = input() 10 | for i in range (1, len(s), 2): 11 | for j in range(0, int(s[i])): 12 | print(s[i-1], end='') 13 | print() 14 | -------------------------------------------------------------------------------- /guithongbao.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | s = input() 11 | nt = s[:min(len(s), 100)] 12 | if len(nt) == 100: 13 | x = nt.split() 14 | xx = s.split() 15 | if x[-1] != xx[len(x)-1]: 16 | while nt[-1]!= ' ': nt = nt[:-1] 17 | print(nt) -------------------------------------------------------------------------------- /hecoso8.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def decToOct(x): 8 | switcher = { 9 | '000': '0', 10 | '001': '1', 11 | '010': '2', 12 | '011': '3', 13 | '100': '4', 14 | '101': '5', 15 | '110': '6', 16 | '111': '7' 17 | } 18 | return switcher.get(x, '') 19 | 20 | s = input() 21 | while len(s) % 3: 22 | s = '0'+s 23 | res = '' 24 | for i in range(0, len(s), 3): 25 | tmp = s[i] + s[i+1] + s[i+2] 26 | res = res + decToOct(tmp) 27 | print(res) -------------------------------------------------------------------------------- /hello.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | s = input() 8 | print("Hello "+s+"!") -------------------------------------------------------------------------------- /hieusonguyenlon.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | a = int(input()) 9 | b = int(input()) 10 | print(a - b) -------------------------------------------------------------------------------- /hoanvikytu.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | from itertools import permutations 8 | s = input() 9 | res = permutations(s) 10 | for i in res: 11 | print(*i, sep ='') -------------------------------------------------------------------------------- /hoanvinguoc.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | from itertools import permutations 8 | import math 9 | 10 | T = int(input()) 11 | for t in range(T): 12 | n = int(input()) 13 | s = '' 14 | for i in range(1, n+1): s = str(i)+s 15 | res = permutations(s) 16 | print(math.factorial(n)) 17 | for i in res: 18 | print(**i, sep ='', end = ' ') 19 | -------------------------------------------------------------------------------- /khoangcachnguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x%i == 0: 11 | return False 12 | return x > 1 13 | 14 | noPrime = [2] 15 | so = 2 16 | while (len(noPrime) < 1000): 17 | so = so + 1 18 | if (isPrime(so)): 19 | noPrime.append(so) 20 | 21 | N, X = map(int, input().split()) 22 | for i in range(0, N): 23 | print(X, end = ' ') 24 | X = X + noPrime[i] 25 | print(X) -------------------------------------------------------------------------------- /khoiphucdayso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | arr = [] 10 | for i in range(n): 11 | arr.append(list(int(i) for i in input().split())) 12 | 13 | if (n == 2): 14 | print(n//2, n//2) 15 | else: 16 | # find the first number 17 | sum1 = 0 18 | for i in range(n): 19 | if i == n-1: 20 | sum1 = sum1 + arr[i][0] 21 | else: sum1 = sum1 + arr[i][i+1] 22 | sum2 = 0 23 | for i in range(1, n): 24 | if i == n-1: 25 | sum2 = sum2 + arr[i][1] 26 | else: sum2 = sum2 + arr[i][i+1] 27 | res = [(sum1-sum2)//2] 28 | # find the other 29 | for i in range(1, n): 30 | res.append(arr[i-1][i] - res[len(res)-1]) 31 | for i in res: 32 | print(i, end = ' ') -------------------------------------------------------------------------------- /kiemtrachanle.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | a = int (input()) 8 | if a%2 == 0: 9 | print('CHAN') 10 | else: 11 | print('LE') -------------------------------------------------------------------------------- /kiemtrachiahetcho7.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | a = input() 11 | if int(a) % 7 != 0: 12 | for i in range(1000): 13 | rev_a = a[::-1] 14 | a = str(int(a)+int(rev_a)) 15 | if int(a) % 7 == 0: break 16 | if int(a) % 7 == 0: print(a) 17 | else: print(-1) 18 | -------------------------------------------------------------------------------- /kiemtrahecoso3.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def check(s): 9 | for i in s: 10 | if i != '0' and i != '1' and i != '2': return False 11 | return True 12 | 13 | n = int(input()) 14 | for i in range(n): 15 | if check(input()): print('YES') 16 | else: print('NO') 17 | -------------------------------------------------------------------------------- /kiemtranguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x%i == 0: 11 | return False 12 | return x > 1 13 | 14 | N, M = map(int, input().split()) 15 | res = [] 16 | for i in range(N): 17 | tmp = [] 18 | for item in (input().split()): 19 | so = int(item) 20 | if (isPrime(so)): 21 | tmp.append(1) 22 | else: 23 | tmp.append(0) 24 | res.append(tmp) 25 | 26 | for i in range(0, N): 27 | for j in range(0, M): 28 | print(res[i][j], end = ' ') 29 | print() -------------------------------------------------------------------------------- /kiemtranguyento2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def isPrime(x): 10 | for i in range(2, int(math.sqrt(x))+1): 11 | if x%i == 0: 12 | return False 13 | return x > 1 14 | 15 | T = int(input()) 16 | for t in range(T): 17 | x = input() 18 | if isPrime(int(x[-4:])): print('YES') 19 | else: print('NO') -------------------------------------------------------------------------------- /kiemtrasodep.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def isPretty(a): 9 | for i in range(2, len(a), 2): 10 | if (a[i] != a[0]): return False 11 | for i in range(3, len(a), 2): 12 | if (a[i] != a[1]): return False 13 | return True 14 | T = int(input()) 15 | for t in range(T): 16 | if isPretty(input()): print('YES') 17 | else: print('NO') -------------------------------------------------------------------------------- /laisuatnganhang.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | N, X, M = input().split() 11 | N, X, M = float(N), float(X), float(M) 12 | days = 0 13 | while (N < M): 14 | days = days + 1 15 | N = N + N*(X/100.0) 16 | print(days) -------------------------------------------------------------------------------- /lamtronso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | s = list(int(i) for i in input()) 11 | for i in range(len(s)-1, 0, -1): 12 | if s[i] >= 5: 13 | s[i-1] = s[i-1] + 1 14 | s[i] = 0 15 | if s[0] == 10: 16 | s[0] = 0 17 | print(1, end='') 18 | for i in s: 19 | print(i, end = '') 20 | print() -------------------------------------------------------------------------------- /lietkecacsocohaichusotangdan.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | s = input() 9 | a = set() 10 | for i in range(1, len(s), 2): 11 | a.add(int(s[i-1])*10+int(s[i])) 12 | a = sorted(a) 13 | for i in a: 14 | print(i, end = ' ') -------------------------------------------------------------------------------- /lietkecacsocohaichusotheothutuxuathien.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | s = input() 9 | a = {} 10 | for i in range(1, len(s), 2): 11 | a[int(s[i-1])*10+int(s[i])] = 1 12 | for i in a.keys(): 13 | print(i, end = ' ') -------------------------------------------------------------------------------- /lietkecapsonguyentocungnhau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | n = int(input()) 9 | l = sorted(list(int(x) for x in input().split())) 10 | 11 | for i in range(len(l)): 12 | for j in range(i+1, len(l)): 13 | if math.gcd(l[i], l[j]) == 1: 14 | print(l[i], l[j]) -------------------------------------------------------------------------------- /lietkesonguyentotrongday.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x % i == 0: 11 | return False 12 | return x > 1 13 | 14 | N = int(input()) 15 | arr = input().split() 16 | dict = {} 17 | for i in arr: 18 | if isPrime(int(i)): 19 | if i in dict: 20 | dict[i] = dict[i] + 1 21 | else: 22 | dict[i] = 1 23 | for key, val in dict.items(): 24 | print(str(key) + ' ' + str(val)) -------------------------------------------------------------------------------- /lietsofibonacci.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def genFibo(): 9 | listfibo = [] 10 | f1 = 0 11 | f2 = 1 12 | for i in range(1, 95): 13 | listfibo.append(f1) 14 | tmp = f1 15 | f1 = f2 16 | f2 = f1 + tmp 17 | return listfibo 18 | listfibo = genFibo() 19 | T = int(input()) 20 | for t in range(T): 21 | a, b = map(int,input().split()) 22 | for i in range(a, b+1): 23 | print(listfibo[i], end = ' ') 24 | print() -------------------------------------------------------------------------------- /lonnhatvanhonhat.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def greater(x, y): 8 | if len(x) > len(y): 9 | return True 10 | elif len(x) < len(y): 11 | return False 12 | else: 13 | return x > y 14 | 15 | while True: 16 | N = int(input()) 17 | if N == 0: 18 | break 19 | resMax = '0' 20 | resMin = '' 21 | for i in range(N): 22 | x = input() 23 | while x[0] == '0': 24 | x = x.lstrip('0') 25 | if (greater(x, resMax)): 26 | resMax = x 27 | if (len(resMin) == 0) or (greater(resMin, x)): 28 | resMin = x 29 | if (resMax == resMin): 30 | print('BANG NHAU') 31 | else: 32 | print(resMin + ' ' + resMax) -------------------------------------------------------------------------------- /lopphanso1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | import math 9 | 10 | def rutgon(a, b): 11 | return (a//math.gcd(a,b), b//math.gcd(a,b)) 12 | 13 | a, b= map(int, input().split()) 14 | res = rutgon(a,b) 15 | print(str(res[0]) + '/' + str(res[1])) -------------------------------------------------------------------------------- /lopphanso2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | import math 9 | 10 | a,b,c,d = map(int, input().split()) 11 | 12 | x = a*d + b*c 13 | y = b*d 14 | 15 | print(str(x//math.gcd(x,y)) + '/'+str(y//math.gcd(x,y))) -------------------------------------------------------------------------------- /loppoint.py: -------------------------------------------------------------------------------- 1 | import math 2 | from decimal import Decimal 3 | class Point: 4 | def __init__(self, x, y): 5 | self.x = x 6 | self.y = y 7 | def distance(self, p): 8 | res = math.sqrt((self.x - p.x)**2 + (self.y - p.y)**2) 9 | return format(res, ".4f") 10 | 11 | if __name__ == '__main__': 12 | t = int(input()) 13 | while t > 0: 14 | arr = input().split() 15 | p1 = Point(Decimal(arr[0]), Decimal(arr[1])) 16 | p2 = Point(Decimal(arr[2]), Decimal(arr[3])) 17 | print(p1.distance(p2)) 18 | t -= 1 -------------------------------------------------------------------------------- /loprectangle.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | class Rectangle: 9 | def __init__(self, h, w, c): 10 | self.h = h 11 | self.w = w 12 | self.c = c 13 | def perimeter(self): 14 | return 2*(self.h+self.w) 15 | def area(self): 16 | return self.h * self.w 17 | def color(self): 18 | return self.c.title() 19 | def isvalid(self): 20 | return self.h > 0 and self.w > 0 21 | 22 | arr = input().strip().split() 23 | r = Rectangle(int(arr[0]), int(arr[1]), arr[2]) 24 | if r.isvalid(): 25 | print(r.perimeter(), r.area(), r.color()) 26 | else: print('INVALID') -------------------------------------------------------------------------------- /lopthisinh1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | class Student: 9 | def __init__(self, name, dob, score1, score2, score3): 10 | self.name = name 11 | self.dob = dob 12 | self.score1 = score1 13 | self.score2 = score2 14 | self.score3 = score3 15 | def show(self): 16 | print(self.name, self.dob, format((self.score1+self.score2+self.score3),'.1f')) 17 | 18 | st = Student(input(), input(), float(input()), float(input()), float(input())) 19 | st.show() -------------------------------------------------------------------------------- /mahoa1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | s = input() 11 | s = s + '#' 12 | count = 1 13 | res = '' 14 | for i in range(1, len(s)): 15 | if (s[i] == s[i-1]): 16 | count = count + 1 17 | else: 18 | res = res + str(count) + s[i-1] 19 | count = 1 20 | print(res) -------------------------------------------------------------------------------- /mahoa2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | p = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_.' 9 | while True: 10 | s = input().split() 11 | k = int(s[0]) 12 | if k == 0: 13 | break 14 | s = s[1] 15 | res = '' 16 | for i in s: 17 | pos = p.find(i) 18 | res = p[(pos + k) % 28] + res 19 | print(res) -------------------------------------------------------------------------------- /mahoa3.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | sample = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 9 | def rotate(s): 10 | res = '' 11 | offset = 0 12 | for i in s: 13 | offset = offset + (ord(i) - ord('A')) 14 | offset = offset % 26 15 | for i in range (0, len(s)): 16 | tmp =(offset + (ord(s[i]) - ord('A'))) % 26 17 | res = res + sample[int(tmp)] 18 | return res 19 | 20 | T = int(input()) 21 | for t in range(T): 22 | s = input() 23 | # Devide 24 | 25 | s1 = s[0:len(s)//2] 26 | s2 = s[len(s)//2:len(s)] 27 | 28 | # Rotate 29 | 30 | s1 = rotate(s1) 31 | s2 = rotate(s2) 32 | 33 | # Merge 34 | 35 | for i in range(0, len(s1)): 36 | vt = ord(s1[i])-ord('A') 37 | offset = (vt + (ord(s2[i]) - ord('A'))) % 26 38 | print(sample[offset], end ='') 39 | print() 40 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | first_name = "Hoa" 2 | last_name = "Co Thi Phuong" 3 | 4 | print(f"My name is {last_name} {first_name}") -------------------------------------------------------------------------------- /nguongtoithieu.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | s = input() 9 | k = int(input()) 10 | a = {} 11 | for i in range(1, len(s), 2): 12 | so = int(s[i-1])*10+int(s[i]) 13 | if so not in a: 14 | a[so] = 1 15 | else: 16 | a[so] += 1 17 | res = sorted(a.items(), key = lambda x: x[0]) 18 | check = 0 19 | for i in res: 20 | if i[1] >= k: 21 | check = 1 22 | print(i[0], i[1]) 23 | if check == 0: 24 | print('NOT FOUND') -------------------------------------------------------------------------------- /nguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | import math 9 | def gcd(a, b): 10 | while (a > 0): 11 | if (a < b): 12 | a, b = b, a 13 | a = a % b 14 | return b 15 | 16 | def isPrime(x): 17 | for i in range(2, int(math.sqrt(x))+1): 18 | if x % i == 0: 19 | return False 20 | return x > 1 21 | 22 | T = int(input()) 23 | for t in range(T): 24 | k = 1 25 | N = int(input()) 26 | for i in range(2, N): 27 | if gcd(i, N) == 1: 28 | k = k + 1 29 | if isPrime(k): 30 | print('YES') 31 | else: print('NO') -------------------------------------------------------------------------------- /nguyentocungnhau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def gcd(a, b): 8 | while (a > 0): 9 | if a < b: 10 | a, b = b, a 11 | a = int(a % b) 12 | return b 13 | 14 | N = int(input()) 15 | arr = list(int(i) for i in input().split()) 16 | arr.sort() 17 | for i in range(0, len(arr)): 18 | for j in range(i+1, len(arr)): 19 | a = arr[i] 20 | b = arr[j] 21 | if gcd(a, b) == 1: 22 | print(a, b) -------------------------------------------------------------------------------- /nguyentocungnhau2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def gcd(a, b): 10 | while (a > 0): 11 | if a < b: 12 | a, b = b, a 13 | a %= b 14 | return b 15 | 16 | num, cs = map(int,input().split()) 17 | dem = 0 18 | for i in range(10**(cs-1), 10**cs): 19 | if gcd(i, num) == 1: 20 | if (dem == 10): 21 | dem = 0 22 | print() 23 | print(i, end = ' ') 24 | dem += 1 25 | -------------------------------------------------------------------------------- /perfectprime.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | import math 9 | def isPrime(x): 10 | for i in range(2, int(math.sqrt(x))+1): 11 | if x%i == 0: return False 12 | return x > 1 13 | 14 | def sum(x): 15 | sum = 0 16 | for i in x: 17 | sum += int(i) 18 | return sum 19 | 20 | def chr(x): 21 | for i in x: 22 | if i not in ['2','3','5','7']: return False 23 | return True 24 | 25 | T = int(input()) 26 | for t in range(T): 27 | inp = input() 28 | n = int(inp) 29 | if (isPrime(n) and isPrime(int(inp[::-1])) and isPrime(sum(inp)) and chr(inp)): 30 | print('Yes') 31 | else: print('No') -------------------------------------------------------------------------------- /phanchianguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x % i == 0: return False 11 | return x > 1 12 | 13 | n = int(input()) 14 | a = list(int(i) for i in input().split()) 15 | dd = {} 16 | b = [] 17 | for i in a: 18 | if i not in dd: 19 | dd[i] = 1 20 | if len(b) == 0: b.append(i) 21 | else: b.append(i+b[-1]) 22 | res = -1 23 | for i in range(0,len(b)): 24 | if isPrime(b[i]) and isPrime(b[-1]-b[i]): 25 | res = i 26 | break 27 | if res == -1: print("NOT FOUND") 28 | else: print(res) -------------------------------------------------------------------------------- /phantichthuasonguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | T = int(input()) 9 | 10 | for t in range(T): 11 | x = int(input()) 12 | print('1 ', end = '') 13 | for i in range(2, int(math.sqrt(x))+1): 14 | count = 0 15 | while x % i == 0: 16 | x = x/i 17 | count = count + 1 18 | if count > 0: 19 | print('* '+str(i)+'^'+str(count)+' ', end = '') 20 | if x > 1: 21 | print('* '+str(int(x))+'^1'+' ', end = '') 22 | print() 23 | -------------------------------------------------------------------------------- /phepcong.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | s = input() 8 | if int(s[0]) + int(s[4]) == int(s[8]): 9 | print('YES') 10 | else: 11 | print('NO') -------------------------------------------------------------------------------- /primetriplet.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x%i == 0: return False 11 | return x > 1 12 | 13 | T = int(input()) 14 | for t in range(T): 15 | n = int(input()) 16 | dem = 0 17 | for i in range(n-6): 18 | if (isPrime(i) and isPrime(i+2) and isPrime(i+6)) or (isPrime(i) and isPrime(i+4) and isPrime(i+6)): 19 | dem += 1 20 | print(dem) -------------------------------------------------------------------------------- /pythonfile.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | s = input().split('.') 9 | if s[-1].lower() == 'py': print('yes') 10 | else: print('no') -------------------------------------------------------------------------------- /sapdatlaixaukytu.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | T = int(input()) 8 | for t in range(1, T+1): 9 | s1 = input() 10 | s2 = input() 11 | print('Test '+str(t)+': ', end = '') 12 | if (len(s1) != len(s2)): 13 | print('NO') 14 | continue 15 | s1 = sorted(s1) 16 | s2 = sorted(s2) 17 | if s1 == s2: 18 | print('YES') 19 | else: 20 | print('NO') -------------------------------------------------------------------------------- /sapxepchanle.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | N = int(input()) 9 | le = [] 10 | chan = [] 11 | sl = 0 12 | arr = [] 13 | while sl < N: 14 | arrtmp = list(int(i) for i in input().split()) 15 | for so in arrtmp: 16 | sl = sl + 1 17 | if so % 2 != 0: 18 | le.append(so) 19 | else: 20 | chan.append(so) 21 | arr.extend(arrtmp) 22 | le.sort(reverse=True) 23 | chan.sort() 24 | i = 0 25 | j = 0 26 | for x in arr: 27 | if x % 2 != 0: 28 | print(le[i], end = ' ') 29 | i = i + 1 30 | else: 31 | print(chan[j], end =' ') 32 | j = j + 1 33 | print() -------------------------------------------------------------------------------- /sapxepdayso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | la = [] 11 | n, k = map(int, input().split()) 12 | l = list(int(x) for x in input().split()) 13 | maxx = 0 14 | for i in range(1, n): 15 | if l[i] > l[maxx]: maxx = i 16 | 17 | l.insert(maxx, k) 18 | for i in l: 19 | if i < 0: 20 | la.append(i) 21 | for i in la: print(i, end = ' ') 22 | for i in l: 23 | if i >= 0: 24 | print(i, end = ' ') 25 | print() -------------------------------------------------------------------------------- /sapxepnguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def isPrime(x): 10 | for i in range(2, int(math.sqrt(x))+1): 11 | if x % i == 0: 12 | return False 13 | return x > 1 14 | 15 | n = int(input()) 16 | x = [] 17 | a = list(int(i) for i in input().split()) 18 | for i in a: 19 | if isPrime(i): x.append(i) 20 | x.sort() 21 | it = 0 22 | for i in a: 23 | if isPrime(i): 24 | print(x[it], end = ' ') 25 | it += 1 26 | else: print(i, end = ' ') -------------------------------------------------------------------------------- /sapxeptheotichchuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def productOfDigits(x): 8 | pro = 1 9 | for i in x: 10 | pro = pro * int(i) 11 | return pro 12 | 13 | T = int(input()) 14 | for t in range(T): 15 | N = int(input()) 16 | arr = input().split() 17 | dict = {} 18 | for x in arr: 19 | i = int(x) 20 | dict[i] = productOfDigits(x) 21 | sorted_dict = sorted(dict.items(), key = lambda x: (x[1], x[0])) #x : x[1] theo value, x : x[0] theo key 22 | 23 | for i in sorted_dict: 24 | print(i[0], end = ' ') 25 | print() -------------------------------------------------------------------------------- /sapxeptheotongchuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def sumOfDigits(x): 8 | sum = 0 9 | for i in x: 10 | sum = sum + int(i) 11 | return sum 12 | 13 | T = int(input()) 14 | for t in range(T): 15 | N = int(input()) 16 | arr = input().split() 17 | dict = {} 18 | for x in arr: 19 | i = int(x) 20 | dict[i] = sumOfDigits(x) 21 | sorted_dict = sorted(dict.items(), key = lambda x: (x[1], x[0])) #x : x[1] theo value, x : x[0] theo key 22 | 23 | for i in sorted_dict: 24 | print(i[0], end = ' ') 25 | print() -------------------------------------------------------------------------------- /sochiahetcho3.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | s = input() 11 | num = 0 12 | for i in s: 13 | num += int(i) 14 | if num % 3 == 0: 15 | print('YES') 16 | else: print('NO') -------------------------------------------------------------------------------- /sodaonguyentocungnhau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def gcd(a, b): 10 | while (a > 0): 11 | if a < b: 12 | a, b = b, a 13 | a %= b 14 | return b 15 | 16 | T = int(input()) 17 | for t in range(T): 18 | s = input() 19 | num1 = int(s) 20 | num2 = int(s[::-1]) 21 | if gcd(num1, num2) == 1: 22 | print('YES') 23 | else: 24 | print('NO') -------------------------------------------------------------------------------- /sodeptrongmatran.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n,m = map(int, input().split()) 9 | 10 | maxx = 0 11 | minn = 10001 12 | x = [] 13 | for i in range(n): 14 | l = list(int(x) for x in input().split()) 15 | maxx = max(maxx, max(l)) 16 | minn = min(minn, min(l)) 17 | x.append(l) 18 | dep = maxx - minn 19 | res = [] 20 | for i in range(n): 21 | for j in range(m): 22 | if x[i][j] == dep: 23 | res.append([i,j]) 24 | 25 | if len(res) == 0: print('NOT FOUND') 26 | else: 27 | print(dep) 28 | for tmp in res: 29 | print('Vi tri ['+str(tmp[0])+']['+str(tmp[1])+']') 30 | -------------------------------------------------------------------------------- /sokhonggiam.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | T = int(input()) 8 | for t in range (0, T): 9 | a = input() 10 | check = False 11 | for i in range (1, len(a)): 12 | if int(a[i-1]) > int(a[i]): 13 | print('NO') 14 | check = True 15 | break 16 | if check == False: 17 | print('YES') -------------------------------------------------------------------------------- /sokrish.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def gt(x): 9 | s = 1 10 | for i in range(2, x+1): 11 | s *= i 12 | return s 13 | 14 | T = int(input()) 15 | for t in range(T): 16 | n = input() 17 | sum = 0 18 | for i in n: 19 | sum += gt(int(i)) 20 | print('Yes' if sum == int(n) else 'No') -------------------------------------------------------------------------------- /solocphatdep.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def check(s): 9 | if ('888' in s) or (s[0] == '8'): 10 | return 'NO' 11 | for i in s: 12 | if i != '6' and i != '8': 13 | return 'NO' 14 | return 'YES' 15 | 16 | s = input() 17 | print(check(s)) -------------------------------------------------------------------------------- /somayman1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | so = input() 8 | dem = 0 9 | for i in so: 10 | if i == '4' or i == '7': 11 | dem = dem + 1 12 | if dem == 4 or dem == 7: 13 | print('YES') 14 | else: 15 | print('NO') -------------------------------------------------------------------------------- /somayman2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def isLuckyNumber(s): 9 | for i in s: 10 | if i != '4' and i != '7': 11 | return 'NO' 12 | return 'YES' 13 | 14 | T = int(input()) 15 | for t in range(T): 16 | print(isLuckyNumber(s=input())) 17 | -------------------------------------------------------------------------------- /somaymantrongmatran.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n,m = map(int, input().split()) 9 | a = [] 10 | for i in range(n): 11 | a.append(list(int(i) for i in input().split())) 12 | l = a[0][0] 13 | r = a[0][0] 14 | for i in range(n): 15 | for j in range(m): 16 | l = min(l, a[i][j]) 17 | r = max(r, a[i][j]) 18 | 19 | check = 0 20 | for i in range(n): 21 | for j in range(m): 22 | if a[i][j] == r-l: 23 | if check == 0: print(a[i][j]) 24 | print("Vi tri ["+str(i)+"]["+str(j)+"]") 25 | check = 1 26 | if check == 0: 27 | print("NOT FOUND") -------------------------------------------------------------------------------- /songuyenlon.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | t = int(input()) 9 | for i in range(t): 10 | a = int(input()) 11 | b = int(input()) 12 | while a > 0: 13 | if a < b: 14 | a, b = b, a 15 | a = a % b 16 | print(b) -------------------------------------------------------------------------------- /songuyentolonnhattrongmatran.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x%i == 0: 11 | return False 12 | return x > 1 13 | 14 | n,m = map(int, input().split()) 15 | a = [] 16 | for i in range(n): 17 | a.append(list(int(i) for i in input().split())) 18 | maxx = 0 19 | for i in range(n): 20 | for j in range(m): 21 | if isPrime(a[i][j]): 22 | maxx = max(a[i][j], maxx) 23 | if maxx == 0: 24 | print("NOT FOUND") 25 | else: 26 | print(maxx) 27 | for i in range(n): 28 | for j in range(m): 29 | if isPrime(a[i][j]) and a[i][j] == maxx: 30 | print("Vi tri ["+str(i)+"]["+str(j)+"]") 31 | 32 | -------------------------------------------------------------------------------- /songuyentotrongmatran.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def isprime(x): 10 | for i in range(2, int(math.sqrt(x))+1): 11 | if x%i == 0: return False 12 | return x > 1 13 | 14 | n,m = map(int, input().split()) 15 | 16 | maxx = 0 17 | x = [] 18 | for i in range(n): 19 | l = list(int(x) for x in input().split()) 20 | for j in l: 21 | if isprime(j): 22 | maxx = max(maxx, j) 23 | x.append(l) 24 | res = [] 25 | for i in range(n): 26 | for j in range(m): 27 | if x[i][j] == maxx: 28 | res.append([i,j]) 29 | 30 | if len(res) == 0: print('NOT FOUND') 31 | else: 32 | print(maxx) 33 | for tmp in res: 34 | print('Vi tri ['+str(tmp[0])+']['+str(tmp[1])+']') 35 | -------------------------------------------------------------------------------- /sonhonhatconthieu.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | N = int(input()) 9 | arr = [0] 10 | for i in input().split(): 11 | arr.append(int(i)) 12 | arr.append(300000) 13 | arr.sort() 14 | for i in range(1, len(arr)): 15 | if arr[i] == arr[i-1]: 16 | continue 17 | if arr[i] != arr[i-1]+1: 18 | print(arr[i-1]+1) 19 | break -------------------------------------------------------------------------------- /sophatloc.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | T = int(input()) 8 | for t in range(0, T): 9 | s = input() 10 | sl = len(s) 11 | if sl >=2 and s[sl-2] == '8' and s[sl-1] =='6': 12 | print('YES') 13 | else: 14 | print('NO') -------------------------------------------------------------------------------- /sotanggiam.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def inc(a): 9 | for i in range(1, len(a)): 10 | if int(a[i]) <= int(a[i-1]): return i-1 11 | return len(a)-1 12 | 13 | def dec(a, vt): 14 | if vt == 0 or vt == len(a)-1: return False 15 | for i in range(vt+1, len(a)): 16 | if a[i] >= a[i-1]: return False 17 | return True 18 | 19 | T = int(input()) 20 | for t in range(T): 21 | a = input() 22 | if len(a) < 3: print('NO') 23 | else: 24 | vt = inc(a) 25 | if dec(a, vt): print('YES') 26 | else: print('NO') -------------------------------------------------------------------------------- /sothuannghich.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | palindrome = [0] 9 | 10 | def calculate(s): 11 | sum = 0 12 | so = 1 13 | s = s[::-1] 14 | for i in s: 15 | if i == '1': 16 | sum = sum + so 17 | so = so * 2 18 | return sum 19 | 20 | def prepare(s): 21 | if len(s)>21: 22 | return 23 | if len(s) > 0 and s[0] != '0': 24 | palindrome.append(calculate(s)) 25 | prepare('0'+s+'0') 26 | prepare('1'+s+'1') 27 | 28 | def BS(l, r, x): #BS return index of element >= x 29 | while l <= r: 30 | mid = (l+r)//2 31 | if palindrome[mid] == x: return mid 32 | if palindrome[mid] < x: 33 | l = mid+1 34 | else: 35 | res = mid 36 | r = mid - 1 37 | return res 38 | 39 | l, r, n = input().split() 40 | l = int(l) 41 | r = int(r) 42 | n = int(n) 43 | 44 | if n==3: 45 | res = 0 46 | if l == 0: res = res + 1 47 | if l <= 1 and 1 <= r: 48 | res = res + 1 49 | if (l<=6643 and 6643<=r): 50 | res = res + 1 51 | if l <= 1422773 and 1422773 <= r: 52 | res = res + 1 53 | print(res) 54 | if n>3: 55 | res = 0 56 | if l == 0: 57 | res= res+1 58 | if l<= 1 and 1<= r: 59 | res = res + 1 60 | print(res) 61 | if n == 2: 62 | dem = 0 63 | prepare('') 64 | prepare('1') 65 | prepare('0') 66 | palindrome.sort() 67 | it1 = BS(0, len(palindrome)-1, l) 68 | it2 = BS(0, len(palindrome)-1, r) 69 | if palindrome[it2]!=r: it2 -= 1 70 | print(it2 - it1 + 1) -------------------------------------------------------------------------------- /sothuannghichchan.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def fullOfEven(x): 8 | for i in x: 9 | if int(i) % 2: 10 | return False 11 | return True 12 | def mirror(i): 13 | i = str(i) 14 | return i+i[::-1] 15 | 16 | T = int(input()) 17 | for t in range(T): 18 | N = int(input()) 19 | x = 1 20 | while True: 21 | if fullOfEven(str(x)): 22 | i = mirror(x) 23 | if int(i) >= N: break 24 | print(i, end=' ') 25 | x+=1 26 | print() -------------------------------------------------------------------------------- /sothuannghichlonnhattrongmatran.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def isPalindrome(x): 9 | s = str(x) 10 | return x > 10 and s == s[::-1] 11 | 12 | n,m = map(int, input().split()) 13 | a = [] 14 | for i in range(n): 15 | a.append(list(int(i) for i in input().split())) 16 | maxx = 0 17 | for i in range(n): 18 | for j in range(m): 19 | if isPalindrome(a[i][j]): 20 | maxx = max(a[i][j], maxx) 21 | if maxx == 0: 22 | print("NOT FOUND") 23 | else: 24 | print(maxx) 25 | for i in range(n): 26 | for j in range(m): 27 | if isPalindrome(a[i][j]) and a[i][j] == maxx: 28 | print("Vi tri ["+str(i)+"]["+str(j)+"]") 29 | 30 | -------------------------------------------------------------------------------- /sothuannghichtrongmatran.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def ispalindrome(x): 8 | return len(x) >1 and x == x[::-1] 9 | 10 | n,m = map(int, input().split()) 11 | 12 | maxx = -1 13 | x = [] 14 | for i in range(n): 15 | l = list(int(x) for x in input().split()) 16 | for j in l: 17 | if ispalindrome(str(j)): 18 | maxx = max(maxx, j) 19 | x.append(l) 20 | res = [] 21 | for i in range(n): 22 | for j in range(m): 23 | if x[i][j] == maxx: 24 | res.append([i,j]) 25 | 26 | if len(res) == 0: print('NOT FOUND') 27 | else: 28 | print(maxx) 29 | for tmp in res: 30 | print('Vi tri ['+str(tmp[0])+']['+str(tmp[1])+']') 31 | -------------------------------------------------------------------------------- /soxenke.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def ktr(s): 8 | if len(s) % 2 == 0 or s[0] == s[1]: return 'NO' 9 | for i in range(0, len(s), 2): 10 | if s[i] != s[0]: return 'NO' 11 | return 'YES' 12 | T = int(input()) 13 | for t in range(T): 14 | s = input() 15 | print(ktr(s)) -------------------------------------------------------------------------------- /tachdoivatinhtong.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def compress(s): 9 | s1 = '' 10 | s2 = '' 11 | for i in range(0, len(s)//2): 12 | s1 = s1 + s[i] 13 | for i in range(len(s)//2, len(s)): 14 | s2 = s2 + s[i] 15 | return str(int(s1) + int(s2)) 16 | s = input() 17 | while len(s) > 1: 18 | s = compress(s) 19 | print(s) -------------------------------------------------------------------------------- /tachsovasapxep.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | N = int(input()) 9 | list_num = [] 10 | for n in range(N): 11 | s = input() 12 | s = s+'#' 13 | num = -1 14 | for i in s: 15 | if i.isnumeric(): 16 | if num == -1: 17 | num = 0 18 | num = num * 10 + int(i) 19 | else: 20 | if num != -1: 21 | list_num.append(num) 22 | num = -1 23 | list_num = sorted(list_num) 24 | for i in list_num: 25 | print(i) -------------------------------------------------------------------------------- /tachtu.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | s = input().split() 8 | for i in range(0, len(s)): 9 | print(s[i]) -------------------------------------------------------------------------------- /tansuatle.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | N = int(input()) 11 | arr = list(int(i) for i in input().split()) 12 | dict = {} 13 | for i in arr: 14 | if i in dict: 15 | dict[i] = dict[i] + 1 16 | else: 17 | dict[i] = 1 18 | 19 | for i in dict.items(): 20 | if i[1] % 2: 21 | print(i[0]) 22 | break -------------------------------------------------------------------------------- /taphopsobangnhau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | N, M = map(int, input().split()) 8 | a = list(int(i) for i in input().split()) 9 | b = list(int(i) for i in input().split()) 10 | 11 | A = {} 12 | B = {} 13 | for i in a: 14 | if i not in A: 15 | A[i] = 1 16 | for i in b: 17 | if i not in B: 18 | B[i] = 1 19 | A = sorted(A.keys()) 20 | B = sorted(B.keys()) 21 | 22 | if A == B: 23 | print('YES') 24 | else: 25 | print('NO') -------------------------------------------------------------------------------- /taphopsonguyen.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def diff(x): 8 | res = {} 9 | for i in x: 10 | if i not in res: 11 | res[i] = 1 12 | return sorted(res.keys()) 13 | 14 | N, M = map(int, input().split()) 15 | 16 | a = list(int(i) for i in input().split()) 17 | b = list(int(i) for i in input().split()) 18 | 19 | a = diff(a) 20 | b = diff(b) 21 | res1 = [] 22 | res2 = [] 23 | res3 = [] 24 | for i in a: 25 | if i in b: 26 | res1.append(i) 27 | for i in a: 28 | if i not in res1: 29 | res2.append(i) 30 | for i in b: 31 | if i not in res1: 32 | res3.append(i) 33 | for i in res1: 34 | print(i, end=' ') 35 | print() 36 | for i in res2: 37 | print(i, end=' ') 38 | print() 39 | for i in res3: 40 | print(i, end=' ') 41 | print() -------------------------------------------------------------------------------- /thongkedichte.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | l =[] 8 | q = [] 9 | b = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]] 10 | n, m = map(int, input().split()) 11 | for i in range(n): 12 | l.append(list(int(x) for x in input().split())) 13 | for j in range(m): 14 | if l[i][j] == -1: 15 | q.append([i,j]) 16 | dem = 0 17 | while len(q) > 0: 18 | u = q[0] 19 | q.pop(0) 20 | for i in b: 21 | ii, jj = i[0]+u[0], i[1]+u[1] 22 | if ii >= 0 and ii < n and jj >= 0 and jj < m: 23 | if l[ii][jj] != 0: 24 | dem += l[ii][jj] 25 | l[ii][jj] = 0 26 | print(dem) -------------------------------------------------------------------------------- /thongketukhacnhau.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import re 8 | T = int(input()) 9 | word = [] 10 | for t in range(T): 11 | s = input() 12 | word.extend(re.findall(r'\w+', s)) 13 | dict = {} 14 | for i in word: 15 | if len(i) == 0: continue 16 | if i.lower() not in dict: 17 | dict[i.lower()] = -1 18 | else: dict[i.lower()]-=1 19 | res = sorted(dict.items(), key = lambda x: (x[1], x[0])) 20 | for i in res: 21 | print(i[0] +" "+str(0-int(i[1]))) -------------------------------------------------------------------------------- /thongketukhacnhaukhongchuachuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import re 8 | T = int(input()) 9 | 10 | word = [] 11 | for t in range(T): 12 | s = input() 13 | word.extend(re.findall(r'[a-zA-Z]+', s)) 14 | dict = {} 15 | for i in word: 16 | if len(i) == 0: continue 17 | if i.lower() not in dict: 18 | dict[i.lower()] = -1 19 | else: dict[i.lower()]-=1 20 | res = sorted(dict.items(), key = lambda x: (x[1], x[0])) 21 | for i in res: 22 | print(i[0] +" "+str(0-int(i[1]))) -------------------------------------------------------------------------------- /thongketukhacnhautheonguongk.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import re 8 | T, k = map(int, input().split()) 9 | 10 | word = [] 11 | for t in range(T): 12 | s = input() 13 | word.extend(re.findall(r'\w+', s)) 14 | dict = {} 15 | for i in word: 16 | if len(i) == 0: continue 17 | if i.lower() not in dict: 18 | dict[i.lower()] = -1 19 | else: dict[i.lower()]-=1 20 | res = sorted(dict.items(), key = lambda x: (x[1], x[0])) 21 | for i in res: 22 | if i[1] <= (0-k): 23 | print(i[0] +" "+str(0-int(i[1]))) -------------------------------------------------------------------------------- /thuphixeoto.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def gia(loai, sl): 9 | if loai == 'Xe_con': 10 | if sl == '5': return 10000 11 | else: return 15000 12 | if loai == 'Xe_tai': return 20000 13 | if loai == 'Xe_khach': 14 | if sl == '29': return 50000 15 | else: return 70000 16 | 17 | n = int(input()) 18 | ngay = {} 19 | for i in range(n): 20 | xe = input().split() 21 | if xe[3] == 'IN': 22 | if xe[4] not in ngay: 23 | ngay[xe[4]] = gia(xe[1], xe[2]) 24 | else: 25 | ngay[xe[4]] += gia(xe[1], xe[2]) 26 | d = sorted(ngay.items(), key=lambda x: x[0]) 27 | for i in d: 28 | print(str(i[0])+':',i[1]) -------------------------------------------------------------------------------- /tichchuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | s = input() 11 | num = 1 12 | for i in s: 13 | if i != '0': 14 | num *= int(i) 15 | print(num) -------------------------------------------------------------------------------- /tichchusotongchuso.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | Author: Tris1702 4 | Github: https://github.com/Tris1702 5 | Gmail: phuonghoand2001@gmail.com 6 | Thank you so much! 7 | """ 8 | 9 | T = int(input()) 10 | 11 | for t in range(T): 12 | s = input() 13 | sum = 0 14 | pro = 1 15 | for i in range(0, len(s)): 16 | if i % 2: 17 | sum += int(s[i]) 18 | else: 19 | if s[i] != '0': 20 | pro *= int(s[i]) 21 | print(pro, sum) -------------------------------------------------------------------------------- /tichlonnhat.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | l = list(int(x) for x in input().split()) 10 | l.sort() 11 | 12 | x1 = l[0] * l[1] 13 | x2 = l[0] * l[1] * l[-1] 14 | x3 = l[-1]* l[-2] 15 | x4 = l[-1] * l[-2] * l[-3] 16 | 17 | print(max([x1,x2,x3,x4])) -------------------------------------------------------------------------------- /timsolonnhat.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import re 8 | N = int(input()) 9 | for i in range(N): 10 | l = list(int(x) for x in re.findall('\d+',input())) 11 | print(sorted(l)[-1]) -------------------------------------------------------------------------------- /timsonhonhat.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import re 8 | N = int(input()) 9 | for i in range(N): 10 | l = list(int(x) for x in re.findall('\d+',input())) 11 | print(sorted(l)[0]) -------------------------------------------------------------------------------- /tinhcandoicuamatran1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | a = [] 10 | for i in range(n): 11 | a.append(list(int(i) for i in input().split())) 12 | k = int(input()) 13 | sum1 = 0 14 | sum2 = 0 15 | for i in range(n): 16 | for j in range(n): 17 | if j > i: sum1 += a[i][j] 18 | if j < i: sum2 += a[i][j] 19 | if abs(sum1-sum2) <= k: print('YES') 20 | else: print('NO') 21 | print(abs(sum1-sum2)) 22 | -------------------------------------------------------------------------------- /tinhcandoicuamatran2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | a = [] 10 | for i in range(n): 11 | a.append(list(int(i) for i in input().split())) 12 | k = int(input()) 13 | sum1 = 0 14 | sum2 = 0 15 | for i in range(n): 16 | for j in range(n): 17 | if j < n-i-1: sum1 += a[i][j] 18 | if j > n-i-1: sum2 += a[i][j] 19 | if abs(sum1-sum2) <= k: print('YES') 20 | else: print('NO') 21 | print(abs(sum1-sum2)) 22 | -------------------------------------------------------------------------------- /tinhdiemthiielts.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def doi(x): 8 | if x >=3 and x <=4: return 2.5 9 | if x >=5 and x <=6: return 3.0 10 | if x >=7 and x <=9: return 3.5 11 | if x >=10 and x <=12: return 4.0 12 | if x >=13 and x <=15: return 4.5 13 | if x >=16 and x <=19: return 5.0 14 | if x >=20 and x <=22: return 5.5 15 | if x >=23 and x <=26: return 6.0 16 | if x >=27 and x <=29: return 6.5 17 | if x >=30 and x <=32: return 7.0 18 | if x >=33 and x <=34: return 7.5 19 | if x >=35 and x <=36: return 8.0 20 | if x >=37 and x <=38: return 8.5 21 | if x >=39 and x <=40: return 9.0 22 | 23 | 24 | T = int(input()) 25 | for t in range(T): 26 | ss = input().split() 27 | r = int(ss[0]) 28 | l = int(ss[1]) 29 | s = float(ss[2]) 30 | w = float(ss[3]) 31 | 32 | score = (doi(r)+doi(l)+s + w)/4.0 33 | if score - int(score) >= 0.75: print(float(int(score))+1.0) 34 | elif score - int(score) >= 0.25: print(float(int(score)+0.5)) 35 | else: print(float(int(score))) -------------------------------------------------------------------------------- /tinhdiemtrungbinh.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | n = int(input()) 9 | a = list(float(i) for i in input().split()) 10 | a.sort() 11 | i = 1 12 | j = len(a)-2 13 | while a[i-1] == a[i]: i += 1 14 | while a[j+1] == a[j]: j -= 1 15 | 16 | sum = 0 17 | for k in range(i, j+1): sum += a[k] 18 | print('{:.2f}'.format(sum/(j-i+1))) 19 | 20 | -------------------------------------------------------------------------------- /tinhtongcacchuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | s = input() 11 | res = '' 12 | count = 0 13 | for i in s: 14 | if i.isnumeric(): 15 | count = count + int(i) 16 | else: 17 | res = res + i 18 | res = ''.join(sorted(res)) 19 | print(res+str(count)) -------------------------------------------------------------------------------- /tinhtongphanthuc.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | n = int(input()) 11 | sum = 0.0 12 | for i in range(2 - n%2, n+1, 2): 13 | sum += 1.0/i 14 | print('{:.6f}'.format(sum)) -------------------------------------------------------------------------------- /tongchuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | T = int(input()) 10 | 11 | for t in range(T): 12 | res = 0 13 | n = int(input()) 14 | n = n * 2 15 | for i in range(2, int(math.sqrt(n))+1): 16 | if n % i != 0: 17 | continue 18 | j = n // i 19 | if (i+j-1) % 2 == 0: 20 | cuoi = (i+j-1)//2 21 | dau = j - cuoi 22 | if (dau != cuoi): 23 | res += 1 24 | print(res) 25 | -------------------------------------------------------------------------------- /tongchusonguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | def isPrime(x): 9 | for i in range(2, int(math.sqrt(x))+1): 10 | if x % i == 0: 11 | return 'NO' 12 | if x > 1: return 'YES' 13 | else: return 'NO' 14 | T = int(input()) 15 | for t in range(T): 16 | s = input() 17 | num = 0 18 | for i in s: 19 | num += int(i) 20 | print(isPrime(num)) -------------------------------------------------------------------------------- /tongchusothuannghich.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | def isPalindrome(x): 9 | s = str(x) 10 | if len(s) > 1 and s == s[::-1]: 11 | return 'YES' 12 | else: 13 | return 'NO' 14 | 15 | T = int(input()) 16 | for t in range(T): 17 | s = input() 18 | num = 0 19 | for i in s: 20 | num += int(i) 21 | print(isPalindrome(num)) -------------------------------------------------------------------------------- /tongchusotichchuso.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | 10 | for t in range(T): 11 | s = input() 12 | sum = 0 13 | pro = 1 14 | count0 = 0 15 | for i in range(0, len(s)): 16 | if i % 2 == 0: 17 | sum += int(s[i]) 18 | else: 19 | if s[i] != '0': 20 | pro *= int(s[i]) 21 | else: count0 += 1 22 | if count0 == len(s)//2: 23 | pro = 0 24 | print(sum, pro) -------------------------------------------------------------------------------- /tongsonguyenlon.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | a = int(input()) 8 | b = int(input()) 9 | print(a + b) -------------------------------------------------------------------------------- /trungthuong.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | T = int(input()) 8 | for t in range(T): 9 | n = int(input()) 10 | count = {} 11 | for i in range(n): 12 | x = int(input()) 13 | if x in count: 14 | count[x] = count[x] - 1 15 | else: 16 | count[x] = -1 17 | sorted_count = sorted(count.items(), key = lambda x : (x[1], x[0])) 18 | print(sorted_count[0][0]) 19 | -------------------------------------------------------------------------------- /uocsochungnguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def gcd(a, b): 10 | while a > 0: 11 | if a < b: 12 | a, b = b, a 13 | a = a % b 14 | return b 15 | 16 | def isPrime(x): 17 | for i in range(2, int(math.sqrt(x))+1): 18 | if x % i == 0: 19 | return False 20 | return x > 1 21 | 22 | def sumOfDigits(x): 23 | sum = 0 24 | for i in str(x): 25 | sum = sum + int(i) 26 | return sum 27 | 28 | T = int(input()) 29 | for t in range(T): 30 | a, b = input().split() 31 | a = int(a) 32 | b = int(b) 33 | if isPrime(sumOfDigits(gcd(a,b))): 34 | print('YES') 35 | else: 36 | print('NO') 37 | -------------------------------------------------------------------------------- /uocsocuagiaithua.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for i in range(T): 10 | n, p = map(int, input().split()) 11 | x = 0 12 | for i in range(p, n, p): 13 | while (i % p == 0): 14 | x = x + 1 15 | i = i // p 16 | print(x) -------------------------------------------------------------------------------- /uuthenguyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | 9 | def isPrime(x): 10 | for i in range(2, int(math.sqrt(x))+1): 11 | if x % i == 0: 12 | return False 13 | return x > 1 14 | 15 | T = int(input()) 16 | for t in range(T): 17 | s = input() 18 | if isPrime(len(s)): 19 | count_nt = 0 20 | for i in s: 21 | if i in ('2', '3', '5', '7', '9'): 22 | count_nt += 1 23 | if count_nt > (len(s) - count_nt): 24 | print('YES') 25 | else: 26 | print('NO') 27 | else: 28 | print('NO') -------------------------------------------------------------------------------- /vitringuyento.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import math 8 | primeDigits = ['2', '3', '5', '7'] 9 | 10 | def isPrime(x): 11 | for i in range(2, int(math.sqrt(x))+1): 12 | if x%i == 0: 13 | return False 14 | return x > 1 15 | 16 | T = int(input()) 17 | 18 | for t in range(T): 19 | s = input() 20 | check = True 21 | for i in range(0, len(s)): 22 | if isPrime(i): 23 | if s[i] not in primeDigits: 24 | check = False 25 | break 26 | else: 27 | if s[i] in primeDigits: 28 | check = False 29 | break 30 | if check: print('YES') 31 | else: print('NO') -------------------------------------------------------------------------------- /welcometopython.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | print("Welcome to python.") -------------------------------------------------------------------------------- /xacdinhtheloaitho.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | N = int(input()) 9 | i = 0 10 | tl = -1 11 | res =[] 12 | dem = 0 13 | while i < N: 14 | line = input().split() 15 | if len(line) == 7 and (dem == 4 or tl != 2): 16 | if dem == 4: dem = 0 17 | tl = 2 18 | res.append(tl) 19 | elif (len(line) == 6 or len(line) == 8) and tl != 1: 20 | tl = 1 21 | dem = 0 22 | res.append(tl) 23 | if tl == 2: dem+=1 24 | i += 1 25 | print(len(res)) 26 | for i in res: 27 | print(i) 28 | -------------------------------------------------------------------------------- /xaupalindrome.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | s = input() 9 | if len(s) > 1: print(len(s)-1) 10 | else: print(0) -------------------------------------------------------------------------------- /xauthangbang.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | def check(s1, s2): 8 | for i in range(1, len(s1)): 9 | if abs(ord(s1[i])-ord(s1[i-1])) != abs(ord(s2[i])-ord(s2[i-1])): 10 | return 'NO' 11 | return 'YES' 12 | 13 | T = int(input()) 14 | for t in range(T): 15 | s = input() 16 | print(check(s, s[::-1])) 17 | -------------------------------------------------------------------------------- /xoaymang.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | n, d = map(int, input().split()) 11 | l = input().split() 12 | vt = d%n 13 | for i in range(vt, n): 14 | print(l[i], end = ' ') 15 | for i in range(d): 16 | print(l[i], end = ' ') 17 | print() -------------------------------------------------------------------------------- /xuathiennhieulannhat.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | T = int(input()) 9 | for t in range(T): 10 | N = int(input()) 11 | arr = [int(i) for i in input().split()] 12 | dict = {} 13 | for i in arr: 14 | if i in dict: 15 | dict[i] = dict[i] + 1 16 | else: 17 | dict[i] = 1 18 | 19 | maxx = 0 20 | res = 0 21 | for key, val in dict.items(): 22 | if val > maxx: 23 | maxx = val 24 | res = key 25 | # print(int(N/2)) 26 | if (maxx > int(N/2)): 27 | print(res) 28 | else: 29 | print('NO') 30 | -------------------------------------------------------------------------------- /xulyvanban.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | import re 8 | str = '' 9 | while True: 10 | try: 11 | str += input() 12 | except EOFError: 13 | break 14 | str = re.split('[.?!]', str) 15 | for i in str: 16 | if len(i) > 0: 17 | x = re.sub('\s+',' ',i.strip()) 18 | print(x[0].upper()+x[1:].lower()) -------------------------------------------------------------------------------- /xulyxaukytu.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Tris1702 3 | Github: https://github.com/Tris1702 4 | Gmail: phuonghoand2001@gmail.com 5 | Thank you so much! 6 | """ 7 | 8 | s1 = set(input().lower().split()) 9 | s2 = set(input().lower().split()) 10 | 11 | res1 = s1|s2 12 | res2 = s1&s2 13 | 14 | res1 = sorted(res1) 15 | res2 = sorted(res2) 16 | 17 | for i in res1: 18 | print(i, end = ' ') 19 | print() 20 | 21 | for i in res2: 22 | print(i, end = ' ') 23 | print() --------------------------------------------------------------------------------