├── hw.py.txt ├── factorial_recursion.py ├── factorial.py ├── EOEO ├── EOEO.py ├── A-Books ├── permutermIndex.py ├── elections.cpp ├── MUFFINS3.cpp ├── factorial_recursion(user_input).py ├── 26337736.py ├── FLOW009.cpp ├── palindrome.py ├── SMPAIR.cpp ├── TSORT.cpp ├── EVENM_Even Matrix.py ├── FLOW006.cpp ├── lapindrome.py ├── Factorial using recursion.cpp ├── Fibonacci.cpp ├── FLOW006.cpp ├── ATM.cpp ├── LAPIN.cpp ├── adaking.py ├── SALARY.cpp ├── armstrong.py ├── CHEFSTR1_Chef _and_Strings.py ├── PPSUM.cpp ├── SnackDown.kt ├── recognizer.py ├── MARM ├── error.cpp ├── CRDGAME3.CPP ├── DECREM_COOK123B.cpp ├── StrangeNumber.py ├── balanced_parenthesis.c ├── chef and typing.py ├── codechef1.cpp ├── PALL01.cpp ├── AMR15A.cpp ├── splitItOctoberCookOff2020.cpp ├── 26396667.py ├── CHFICRM ├── ISHVALA.cpp ├── iss52 ├── DYNAMO ├── HRDSEQ ├── SAKTAN ├── OCT19B └── CHEFINSQ ├── CDRGAME.py ├── Chef and Linear Chess.cpp ├── pathSumOctCookOff2020.cpp ├── Oct_cook_b.cpp ├── PTMSSNG_Missing_a_Point.py ├── Box_is_pull.cpp ├── CLLCM.c ├── unitGcd.cpp ├── fenwickTree.cpp ├── fibonacci.c ├── ENCJMAY6.cpp ├── SimpleCalculator.py ├── CVDRUN.cpp ├── create_the_contest.cpp ├── Levenshtein_Distance.py ├── ABBB.cpp ├── OR-thodox_Distinction.py ├── POSAND.CPP ├── 1235624892.java ├── fib_huge.cpp ├── QuickSort.c ├── Oct_Long_REPLESX.cpp ├── MinimizeDigitsum.cpp ├── ThreadPriority.java ├── Labyrinth.py ├── altaray.java ├── matrix_chain_order.py ├── CHFNSWPS.cpp ├── Score After Flipping Matrix.cpp ├── DisplayReverse.c ├── addsqure.cpp ├── C - Numbers on Whiteboard.cpp ├── CONVSTR.cpp ├── SOUNDEX.py ├── LFIVES.py ├── chandf-mayLongChallenge-2020.cpp ├── DrChef-JulyChallenge2020.cpp ├── Binary_Search_Tree.c ├── D - String Deletion.cpp ├── chefinaSwaps_julyLongChallenge2020.cpp ├── Binomialdistribution.py ├── 33227289.java └── TRPLSRT.cpp /hw.py.txt: -------------------------------------------------------------------------------- 1 | print("hello world") -------------------------------------------------------------------------------- /factorial_recursion.py: -------------------------------------------------------------------------------- 1 | def factorial(n): 2 | if(n<2): 3 | return 1 4 | 5 | return n * factorial(n-1) 6 | -------------------------------------------------------------------------------- /factorial.py: -------------------------------------------------------------------------------- 1 | #gs 2 | n=int(input("Enter the Number ")) 3 | f = 1 4 | for i in range(1,n+1): 5 | f=f*i 6 | print("Factorial is ", f) 7 | -------------------------------------------------------------------------------- /EOEO: -------------------------------------------------------------------------------- 1 | t=int(input()) 2 | while t>0: 3 | tom=int(input()) 4 | if tom%2!=0: 5 | print(tom//2) 6 | else: 7 | while(tom%2==0): 8 | tom//=2 9 | print(tom//2) 10 | t-=1 11 | -------------------------------------------------------------------------------- /EOEO.py: -------------------------------------------------------------------------------- 1 | 2 | t=int(input()) 3 | while t>0: 4 | tom=int(input()) 5 | if tom%2!=0: 6 | print(tom//2) 7 | else: 8 | while(tom%2==0): 9 | tom//=2 10 | print(tom//2) 11 | t-=1 12 | -------------------------------------------------------------------------------- /A-Books: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | for _ in range(int(input())): 3 | n=int(input()) 4 | l=list(map(int,input().split())) 5 | b=[] 6 | for i in range(n): 7 | ans=n-i-l[i:n].count(l[i]) 8 | b.append(ans) 9 | print(" " .join(str(a) for a in b)) 10 | -------------------------------------------------------------------------------- /permutermIndex.py: -------------------------------------------------------------------------------- 1 | #Entering the values that should permutate 2 | Term = input("Enter the term to rotate : ") 3 | print("Term to be permutate",Term) 4 | 5 | a = Term + '$' 6 | print(a) 7 | X = len(a) 8 | for i in range(X-1,0,-1): 9 | c = a[i:]+a[:i] 10 | print(c,Term) 11 | print(a,Term) 12 | -------------------------------------------------------------------------------- /elections.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | long long int n,i,m=0,s=0,a; 6 | cin>>n; 7 | for(i=0;i>a; 10 | m=max(m,a); 11 | s+=a; 12 | } 13 | cout< 4 | using namespace std; 5 | 6 | int main() { 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { int a,b; 11 | cin>>a; 12 | b=(a/2)+1; 13 | cout< 4 | using namespace std; 5 | int main() 6 | { 7 | long int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | double a,b,c=0.00000; 12 | cin>>a>>b; 13 | if(a>1000) 14 | c=(a*b)-((a*b)/10); 15 | else 16 | c=a*b; 17 | cout< 4 | using namespace std; 5 | int main() 6 | { 7 | long int n,t,add=0; 8 | cin>>t; 9 | while(t--) 10 | { 11 | cin>>n; 12 | long int a[n]; 13 | for(int i=0; i>a[i]; 15 | sort(a,a+n); 16 | add= a[0]+a[1]; 17 | cout< 4 | #include 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | int t; 10 | cin>>t; 11 | int a[t]; 12 | for(int i=0;i>a[i]; 15 | } 16 | sort(a,a+t); 17 | for(int i=0;i 4 | using namespace std; 5 | 6 | int main() { 7 | int a,b,t; 8 | cin>>t; 9 | while (t--) 10 | { 11 | int sum=0; 12 | cin>>a; 13 | while (a!=0){ 14 | b=a%10; 15 | sum=sum+b; 16 | a=a/10;} 17 | cout< 2 | using namespace std; 3 | 4 | int factorial(int n); 5 | 6 | int main() 7 | { 8 | int n; 9 | 10 | cout << "Enter a positive integer: "; 11 | cin >> n; 12 | 13 | cout << "Factorial of " << n << " = " << factorial(n); 14 | 15 | return 0; 16 | } 17 | 18 | int factorial(int n) 19 | { 20 | if(n > 1) 21 | return n * factorial(n - 1); 22 | else 23 | return 1; 24 | } 25 | -------------------------------------------------------------------------------- /Fibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int fib(int n) 5 | { 6 | int a = 0, b = 1, c, i; 7 | if( n == 0) 8 | return a; 9 | for(i = 2; i <= n; i++) 10 | { 11 | c = a + b; 12 | a = b; 13 | b = c; 14 | } 15 | return b; 16 | } 17 | 18 | // Driver code 19 | int main() 20 | { 21 | int n = 9; 22 | 23 | cout << fib(n); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- / FLOW006.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int x; 6 | cin>>x; 7 | string ar [x]; 8 | 9 | for(int i=0; i>ar[i]; 12 | } 13 | int z;int p; 14 | for(int i=0; i 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | float y;int x; 7 | 8 | cin>>x; // Total account balance 9 | 10 | cin>>y; // Amout to be withdrawn 11 | 12 | float z=y-0.5; 13 | if(x 4 | using namespace std; 5 | int main() 6 | { 7 | long int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | string s1,s2,s; 12 | cin>>s; 13 | int l=s.length(); 14 | s1=s.substr(0,l/2); 15 | s2=s.substr(l%2!=0? (l/2)+1:l/2,l); 16 | sort(s1.begin(),s1.end()); 17 | sort(s2.begin(),s2.end()); 18 | if(s1==s2) 19 | cout<<"YES"< 2 | using namespace std; 3 | 4 | #define For(i,a,b) for(int i=a;i<=b;++i) 5 | int a[1111]; 6 | 7 | int main() { 8 | ios::sync_with_stdio(false); 9 | cin.tie(0); 10 | int t; 11 | cin>>t; 12 | for(int tc=1;tc<=t;tc++) { 13 | 14 | 15 | int n;cin>>n; 16 | For(i,1,n)cin>>a[i]; 17 | sort(a+1,a+n+1); 18 | int ans=0; 19 | For(i,1,n)ans+=a[i]-a[1]; 20 | cout< 0: 12 | digit = temp % 10 13 | sum += digit ** 3 14 | temp //= 10 15 | 16 | # display the result 17 | if num == sum: 18 | print(num,"is an Armstrong number") 19 | else: 20 | print(num,"is not an Armstrong number") 21 | 22 | -------------------------------------------------------------------------------- /CHEFSTR1_Chef _and_Strings.py: -------------------------------------------------------------------------------- 1 | # Problem :: https://www.codechef.com/JULY20B/problems/CHEFSTR1 2 | 3 | #Python 4 | 5 | from sys import stdin,stdout # module to read/write o/p 6 | 7 | for _ in range(int(stdin.readline())): # TestCase Loop 8 | N = int(stdin.readline()) # Input 9 | Intergers = list(map(int,stdin.readline().split())) # List of inputs 10 | print(sum([abs(Intergers[n]-Intergers[n-1])-1 for n in range(1,len(Intergers))])) # total number of strings he has to skip 11 | 12 | 13 | -------------------------------------------------------------------------------- /PPSUM.cpp: -------------------------------------------------------------------------------- 1 | //https://www.codechef.com/submit/PPSUM 2 | 3 | #include 4 | using namespace std; 5 | 6 | int sum(int n){ 7 | return n*(n+1)/2; 8 | } 9 | 10 | int main() { 11 | int t; 12 | std::cin >> t; 13 | 14 | 15 | for (int i=0; i> D >> N; 19 | 20 | int ans =sum(N); 21 | 22 | for(int j=0; j){ 7 | val sc=Scanner(System.`in`) 8 | var t=sc.nextInt() 9 | while(t > 0){ 10 | val x=sc.nextInt() 11 | when(x){ 12 | 2010,2015,2016,2017,2019 -> println("HOSTED") 13 | else -> println("NOT HOSTED") 14 | } 15 | t-- 16 | } 17 | } -------------------------------------------------------------------------------- /recognizer.py: -------------------------------------------------------------------------------- 1 | from urllib.request import urlopen 2 | from urllib.error import HTTPError 3 | from urllib.error import URLError 4 | 5 | try: 6 | PageUrl = urlopen("https://www.google.in/") 7 | except HTTPError: 8 | print("HTTP error") 9 | except URLError: 10 | print("Page not found!") 11 | else: 12 | print("Page Found") 13 | 14 | try: 15 | PageUrl = urlopen("http://www.notfound.in/") 16 | except HTTPError: 17 | print("HTTP error") 18 | except URLError: 19 | print("Page not found!") 20 | else: 21 | print("Page Found") 22 | -------------------------------------------------------------------------------- /MARM: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | for _ in range(int(input())): 3 | n,k=map(int,input().split()) 4 | l=list(map(int,input().split())) 5 | i=0 6 | while(i<(k//n)%3): 7 | for j in range(0,n//2): 8 | a=j%n 9 | b=n-a-1 10 | l[a]=l[a]^l[b] 11 | l[b]=l[a]^l[b] 12 | i+=1 13 | if n%2!=0 and n//2 2 | using namespace std; 3 | void check(string s) 4 | { 5 | int see=0; 6 | for(int i=0;i>t; 20 | while(t--) 21 | { 22 | string s; 23 | cin>>s; 24 | check(s); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CRDGAME3.CPP: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int a, b; 9 | cin>>a>>b; 10 | int acnt=0, bcnt=0; 11 | if(a%9==0) 12 | acnt+=a/9; 13 | else 14 | acnt+=a/9+1; 15 | if(b%9==0) 16 | bcnt+=b/9; 17 | else 18 | bcnt+=b/9+1; 19 | 20 | if(acnt==bcnt) 21 | cout<<"1 "<bcnt) 23 | cout<<"1 "< 2 | #define ll long long 3 | #define ui unsigned int 4 | #define f(i,a,n) for(int i=a ;i>t; 17 | while(t--) 18 | { 19 | int l,r; 20 | cin>>l>>r; 21 | if(r>=2*l || l==1) 22 | { 23 | cout<<-1< 1: 16 | c +=1 17 | return c 18 | for i in range(int(stdin.readline())): 19 | X,K = map(int,stdin.readline().split()) 20 | L = primeFactors(X) 21 | if (K<=L): 22 | stdout.write('1'+'\n') 23 | else: 24 | stdout.write('0'+'\n') 25 | -------------------------------------------------------------------------------- /balanced_parenthesis.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int breakingRecords() 5 | { 6 | int n,i,ch=0,cl=0; 7 | scanf("%d",&n); 8 | int ar[n]; 9 | for(i=0;iar[i]) 21 | { 22 | min=ar[i]; 23 | cl++; 24 | } 25 | } 26 | printf("%d %d",ch,cl); 27 | return 1; 28 | } 29 | int main() 30 | { 31 | breakingRecords(); 32 | return 1; 33 | } 34 | -------------------------------------------------------------------------------- /chef and typing.py: -------------------------------------------------------------------------------- 1 | # cook your dish here 2 | for _ in range(int(input())): 3 | n=int(input()) 4 | l=[] 5 | sh1=['d','f'] 6 | sh2=['j','k'] 7 | time=0 8 | for __ in range(n): 9 | l.append(input()) 10 | s=list(set(l)) 11 | # print(s) 12 | for i in s: 13 | a=l.count(i) 14 | t=0.2 15 | for j in range(1,len(i)): 16 | if (i[j] in sh1 and i[j-1] in sh1) or (i[j] in sh2 and i[j-1] in sh2): 17 | t+=0.4 18 | else: 19 | t+=0.2 20 | time+=t+(t/2)*(a-1) 21 | print(round(time*10)) 22 | -------------------------------------------------------------------------------- /codechef1.cpp: -------------------------------------------------------------------------------- 1 | //https://www.codechef.com/problems/LUCKFOUR 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int T; 9 | cin>>T; 10 | int arr[T]; 11 | for(int i=0;i>arr[i]; 13 | } 14 | for(int i=0;i 4 | using namespace std; 5 | 6 | int main(){ 7 | int T; 8 | int arr[T]; 9 | cin>>T; 10 | for(int i=0;i>arr[i]; 12 | } 13 | for(int i=0;i 4 | using namespace std; 5 | 6 | int main() { 7 | int n,c1=0,c2=0; 8 | cin>>n; 9 | int a[n]; 10 | for(int i=0;i>a[i]; 13 | } 14 | for(int j=0;jc2) 26 | { 27 | cout<<"READY FOR BATTLE"< 3 | using namespace std; 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int len; 11 | cin>>len; 12 | char strr[100002]; 13 | cin>>strr; 14 | bool check=true; 15 | for (int i = 0; i < strlen(strr)-1; i++) 16 | { 17 | if (strr[i]==strr[len-1]) 18 | { 19 | check=false; 20 | } 21 | } 22 | if (!check) 23 | { 24 | cout<<"YES"<<"\n"; 25 | } 26 | else 27 | { 28 | cout<<"NO"<<"\n"; 29 | } 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /26396667.py: -------------------------------------------------------------------------------- 1 | """import math 2 | def pow2(n): 3 | p = int(math.log(n, 2)) 4 | return p""" 5 | t=int(input()) 6 | for i in range(t): 7 | n=int(input()) 8 | if n==1: 9 | print("0") 10 | else: 11 | c=0 12 | while n>=1: 13 | n=n//2 14 | c+=1 15 | #x=pow2(n) 16 | y=pow(2,c-1)%60 17 | if y==1: 18 | print("0") 19 | elif y==2: 20 | print("1") 21 | elif y==4: 22 | print("2") 23 | elif y==8: 24 | print("3") 25 | elif y==16: 26 | print("0") 27 | elif y==32: 28 | print("9") 29 | 30 | -------------------------------------------------------------------------------- /CHFICRM: -------------------------------------------------------------------------------- 1 | def money(a): 2 | coin=dict() 3 | coin[5]=0 4 | coin[10]=0 5 | for i in a: 6 | if i==5: 7 | coin[5]+=1 8 | elif i==10: 9 | coin[10]+=1 10 | if coin[5]==0: 11 | return("NO") 12 | else: 13 | coin[5]-=1 14 | else: 15 | if coin[10]!=0: 16 | coin[10]-=1 17 | elif coin[5]>=2: 18 | coin[5]-=2 19 | else: 20 | return ("NO") 21 | return ("YES") 22 | t=int(input()) 23 | while t>0: 24 | n=int(input()) 25 | arr=list(map(int,input().split())) 26 | print(money(arr)) 27 | t-=1 28 | -------------------------------------------------------------------------------- /ISHVALA.cpp: -------------------------------------------------------------------------------- 1 | //https://www.codechef.com/submit/ISHVALA 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int t; 8 | cin>>t; 9 | for(int i=0;i>N>>M>>X>>Y>>s; 12 | int prev_x=0,prev_y=0,sum_x=0,sum_y=0; 13 | for(int j=0;j>x; 15 | sum_x+=(x-prev_x-1)/s; 16 | prev_x=x; 17 | } 18 | sum_x+=(N-prev_x)/s; 19 | for(int j=0;j>y; 21 | sum_y+=(y-prev_y-1)/s; 22 | prev_y=y; 23 | } 24 | sum_y+=(M-prev_y)/s; 25 | 26 | cout< 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() { 7 | // your code goes here 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | long t; 11 | cin>>t; 12 | while(t--){ 13 | int n; 14 | cin>>n; 15 | long long a,b,c,d,e,s,x; 16 | cin>>a; 17 | x=pow(10,n); 18 | s=(2*x)+a; 19 | cout<>b; 21 | c=x-b; 22 | cout<>d; 24 | e=x-d; 25 | cout<>i; 29 | if(i==1){ 30 | continue; 31 | } 32 | else{ 33 | break; 34 | } 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /CDRGAME.py: -------------------------------------------------------------------------------- 1 | Problem ID :: https://www.codechef.com/JULY20B/problems/CRDGAME 2 | 3 | #Python Code :: 4 | 5 | 6 | from sys import stdin,stdout 7 | 8 | def sumdigits(n): 9 | return 0 if n==0 else (n%10) + sumdigits(n//10) 10 | 11 | for _ in range(int(stdin.readline())): 12 | C_W = 0 13 | M_W = 0 14 | for _ in range(int(stdin.readline())): 15 | C , M = map(int,stdin.readline().split()) 16 | C_S = sumdigits(C) 17 | M_S = sumdigits(M) 18 | if (C_S == M_S): 19 | C_W = C_W+1 20 | M_W = M_W+1 21 | elif(C_S > M_S): 22 | C_W = C_W+1 23 | else: 24 | M_W = M_W+1 25 | if (C_W == M_W): 26 | print("2",C_W) 27 | elif(C_W > M_W): 28 | print("0" , C_W) 29 | else: 30 | print("1",M_W) 31 | 32 | 33 | -------------------------------------------------------------------------------- /Chef and Linear Chess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n, k; 11 | cin>>n>>k; 12 | int a[n]; 13 | for(int i=0; i>a[i]; 15 | 16 | int m=INT_MAX; 17 | int res=-1; 18 | for(int i=0;i 3 | using namespace std; 4 | int arr[107]; 5 | vector adj[107]; 6 | void dfs(int s,int p,int y){ 7 | arr[s]=y; 8 | for(auto x:adj[s]){ 9 | if(p!=x){ 10 | if(y==1)dfs(x,s,2); 11 | else dfs(x,s,1); 12 | } 13 | } 14 | } 15 | int main() { 16 | int t; 17 | cin>>t; 18 | while(t--){ 19 | int n,i,a,b; 20 | cin>>n; 21 | for(i=1;i<=n;i++){ 22 | arr[i]=0; 23 | if(!adj[i].empty())adj[i].clear(); 24 | } 25 | for(i=0;i>a>>b; 27 | adj[a].push_back(b); 28 | adj[b].push_back(a); 29 | } 30 | dfs(1,-1,1); 31 | for(i=1;i<=n;i++)cout< 3 | 4 | #define FAST cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0) 5 | #define lli(n) long long n; cin>>n; 6 | #define li(n) long n; cin>>n; 7 | #define inti(n) int n;cin>>n; 8 | #define CC int test;\ 9 | cin>>test;\ 10 | while(test--) 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | FAST; 17 | CC 18 | { 19 | inti(l);inti(r); 20 | // if l<=r-l, mod function will give a value 21 | // less than the length of the segment 22 | // and the condition will neve be satisfied 23 | if(l<=r-l) 24 | cout<<"-1\n"; 25 | else{ 26 | // the answer always exist in this case and is always equal to r 27 | cout< 3 | #include 4 | #include 5 | #include 6 | # define mod 1000000007 7 | using namespace std; 8 | typedef long long int lli; 9 | 10 | void solve() 11 | { 12 | //write your code here 13 | lli x1,y1,x2,y2; 14 | cin >> x1 >> y1 >> x2 >> y2; 15 | int ans=abs(x2-x1)+abs(y2-y1); 16 | if(abs(x2-x1)!=0 && abs(y2-y1)!=0) 17 | ans+=2; 18 | cout << ans << "\n"; 19 | } 20 | 21 | 22 | int main() 23 | { 24 | #ifndef ONLINE_JUDGE 25 | freopen ("A:/c++/inputf.in", "r", stdin); 26 | freopen ("A:/c++/outputf.in", "w", stdout); 27 | #endif 28 | ios_base::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int t; 31 | cin >> t; 32 | while(t--) 33 | { 34 | solve(); 35 | } 36 | return 0; 37 | } 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /CLLCM.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define z 1000 3 | int main(void) { 4 | // FILE *fp; 5 | // // For getting input from input0.txt file 6 | // fp = freopen("input0.txt", "r", stdin); 7 | 8 | // Change the input0.txt according to the number of files 9 | // make sure to comment this out before submitting it to the online judge 10 | // Your code goes Here 11 | // your code goes here 12 | int t; 13 | long long int a[z]= {0},n,mul=1; 14 | scanf("%d",&t); 15 | while(t--) 16 | { 17 | scanf("%lld",&n); 18 | mul = 1; 19 | for (int i = 0; i < n;i++) 20 | { 21 | scanf("%lld", &a[i]); 22 | mul *= a[i]; 23 | } 24 | if (mul %2 == 0) 25 | { 26 | printf("NO\n"); 27 | } 28 | else{ 29 | printf("YES\n"); 30 | } 31 | 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /unitGcd.cpp: -------------------------------------------------------------------------------- 1 | ///Solution to Unit GCD problem of April Long Challenge 2020.. 2 | #include 3 | using namespace std; 4 | typedef long long int llt; 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | llt t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | llt n; 14 | cin>>n; 15 | if(n>=2) 16 | { 17 | cout<=3) 33 | { 34 | cout<<"3 "<<"1 "<<"2 "<<"3"<<"\n"; 35 | for(llt i=4;i<=n;i=i+2) 36 | { 37 | cout<<"2 "< bit; // binary indexed tree 4 | int n; 5 | 6 | FenwickTree(int n) { 7 | this->n = n; 8 | bit.assign(n, 0); 9 | } 10 | 11 | FenwickTree(vector a) : FenwickTree(a.size()) { 12 | for (size_t i = 0; i < a.size(); i++) 13 | add(i, a[i]); 14 | } 15 | 16 | int sum(int r) { 17 | int ret = 0; 18 | for (; r >= 0; r = (r & (r + 1)) - 1) 19 | ret += bit[r]; 20 | return ret; 21 | } 22 | 23 | int sum(int l, int r) { 24 | return sum(r) - sum(l - 1); 25 | } 26 | 27 | void add(int idx, int delta) { 28 | for (; idx < n; idx = idx | (idx + 1)) 29 | bit[idx] += delta; 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | clrscr(); 6 | void childprocess(unsigned long long int k) 7 | { 8 | int v; 9 | int a=0; 10 | int b=1; 11 | for (int j=0;j 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | // your code goes here 8 | int t; 9 | cin>>t; 10 | while(t-->0){ 11 | unordered_map count; 12 | unordered_map siz; 13 | int n, id; 14 | char a, b; 15 | cin >> n; 16 | vector ans; 17 | for(int i=0;i>id>>a>>b; 19 | siz[id]=a; 20 | count[b]++; 21 | } 22 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | int* hard(); 6 | 7 | int* hard(){ 8 | int* a=new int[129]; 9 | int pos,count=0,j; 10 | a[0]=0; 11 | a[1]=0; 12 | for(int i=2;i<128;i++){ 13 | int x=a[i-1]; 14 | count=0; 15 | for(int j=i-2;j>=0;j--){ 16 | if(a[j]==x){ 17 | pos=j; 18 | count++; 19 | break; 20 | } 21 | } 22 | if(count==0) 23 | a[i]=0; 24 | else{ 25 | a[i]=i-(pos+1); 26 | } 27 | } 28 | return a; 29 | } 30 | 31 | int main() { 32 | // your code goes here 33 | int* arr=hard(); 34 | 35 | 36 | 37 | int t; 38 | cin>>t; 39 | while(t--){ 40 | int n; 41 | cin>>n; 42 | int c=0; 43 | for(int k=0;k 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | long t; 10 | cin>>t; 11 | while(t--){ 12 | long n,m,q,reven=0,rodd=0,ceven=0,codd=0,count=0; 13 | cin>>n>>m>>q; 14 | long row[100001]={0},col[100001]={0}; 15 | while(q--){ 16 | long x,y; 17 | cin>>x>>y; 18 | row[x-1]=row[x-1]+1; 19 | col[y-1]=col[y-1]+1; 20 | } 21 | for(long i=0;i 3 | #include 4 | #include 5 | #include 6 | # define mod 1000000007 7 | using namespace std; 8 | typedef long long int lli; 9 | 10 | void solve() 11 | { 12 | //write your code here 13 | int n,k,x,y; 14 | cin >> n >> k >> x >> y; 15 | vectorcity; 16 | city.push_back(x); 17 | int val=(x+k)%n; 18 | while(val!=x) 19 | { 20 | city.push_back(val); 21 | val=(val+k)%n; 22 | } 23 | if(find(city.begin(),city.end(),y)!=city.end()) 24 | cout << "YES" << "\n"; 25 | else 26 | cout << "NO" << "\n"; 27 | } 28 | 29 | 30 | int main() 31 | { 32 | #ifndef ONLINE_JUDGE 33 | freopen ("A:/c++/inputf.in", "r", stdin); 34 | freopen ("A:/c++/outputf.in", "w", stdout); 35 | #endif 36 | ios_base::sync_with_stdio(false); 37 | cin.tie(NULL); 38 | int t; 39 | cin >> t; 40 | while(t--) 41 | { 42 | solve(); 43 | } 44 | return 0; 45 | } 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /iss52/OCT19B: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | int t; 10 | cin>>t; 11 | while(t--){ 12 | int n; 13 | cin>>n; 14 | int a[1000001],f[1000001]={0}; 15 | for(int i=0;i>a[i]; 18 | } 19 | int max=0; 20 | for(int i=0;i 3 | #include 4 | #include 5 | #include 6 | # define mod 1000000007 7 | using namespace std; 8 | typedef long long int lli; 9 | 10 | void solve() 11 | { 12 | //write your code here 13 | lli n; 14 | cin >> n; 15 | vectorarr(n); 16 | for(lli i=0;i> arr[i]; 18 | int count=1,val=arr[0],ma=-1; 19 | for(int i=1;i> t; 44 | // while(t--) 45 | // { 46 | solve(); 47 | // } 48 | return 0; 49 | } 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Levenshtein_Distance.py: -------------------------------------------------------------------------------- 1 | def Levenshtein_Distance(SOURCE, TERM): 2 | 3 | rows = len(SOURCE)+1 4 | cols = len(TERM)+1 5 | distance = [[0 for i in range(cols)] for i in range(rows)] 6 | print(distance) 7 | 8 | # source prefixes can be transformed into empty strings 9 | # by deletions: 10 | for X in range(1, len(SOURCE)+1): 11 | distance[X][0] = X 12 | # target prefixes can be created from an empty source string 13 | # by inserting the characters 14 | for Y in range(1, len(TERM)+1): 15 | distance[0][Y] = Y 16 | 17 | 18 | for col in range(1, cols): 19 | for row in range(1, rows): 20 | if SOURCE[row-1] == TERM[col-1]: 21 | cost = 0 22 | else: 23 | cost = 1 24 | distance[row][col] = min(distance[row-1][col] + 1, # deletion 25 | distance[row][col-1] + 1, # insertion 26 | distance[row-1][col-1] + cost) # substitution 27 | 28 | 29 | for R in range(rows): 30 | print(distance[R]) 31 | 32 | 33 | return distance[row][col] 34 | -------------------------------------------------------------------------------- /ABBB.cpp: -------------------------------------------------------------------------------- 1 | // Question Link: 2 | #include 3 | #include 4 | #include 5 | #include 6 | # define mod 1000000007 7 | using namespace std; 8 | typedef long long int lli; 9 | 10 | void solve() 11 | { 12 | //write your code here 13 | string s; 14 | cin >> s; 15 | stacksr; 16 | sr.push(s[0]); 17 | for(int i=1;i> t; 47 | while(t--) 48 | { 49 | solve(); 50 | } 51 | return 0; 52 | } 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /OR-thodox_Distinction.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Problem Link - https://www.codechef.com/COOK120B/problems/ORTHODOX 3 | ''' 4 | from sys import stdin,stdout 5 | from math import * 6 | from collections import * 7 | from functools import reduce 8 | from operator import ior 9 | 10 | mod = 1000000007 11 | 12 | def gcd(a,b): 13 | while b: 14 | a,b = b,a%b 15 | return a 16 | 17 | def lcm(a,b): return (a*b) // gcd(a,b) 18 | 19 | def set_bits(X): 20 | c = 0 21 | while X: 22 | X &= (X-1);c += 1 23 | return c 24 | 25 | def compute_MOD(N,M): return (N%M + M) % M 26 | 27 | def solve(arr): 28 | cur,ans = set(),set() 29 | for i in arr: 30 | cur = {i | b for b in cur} | {i} 31 | ans |= cur 32 | return len(ans) 33 | 34 | def get_array(): return list(map(int, stdin.readline().split())) 35 | 36 | def get_ints(): return map(int, stdin.readline().split()) 37 | 38 | def get_int(): return int(stdin.readline()) 39 | 40 | def get_input(): return stdin.readline().strip() 41 | 42 | def main(): 43 | tc = get_int() 44 | while(tc): 45 | N = get_int() 46 | arr = get_array() 47 | if solve(arr) == ((N*(N+1))//2): 48 | stdout.write('YES\n') 49 | else: 50 | stdout.write('NO\n') 51 | tc-=1 52 | 53 | if __name__ == "__main__": 54 | main() 55 | 56 | -------------------------------------------------------------------------------- /POSAND.CPP: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll int 5 | bool isPowerOfTwo(ll n) 6 | { 7 | return n!=0 && ((n&(n-1))==0); 8 | } 9 | 10 | int main() 11 | { 12 | ll t; 13 | cin >> t; 14 | while (t--) 15 | { 16 | ll n; 17 | cin >> n; 18 | set s; 19 | if (n == 1) 20 | { 21 | cout << 1 << endl; 22 | continue; 23 | } 24 | else if (isPowerOfTwo(n)) 25 | { 26 | cout << -1 << endl; 27 | } 28 | else 29 | { 30 | cout<<2<<" "<<3<<" "<<1; 31 | s.insert(2); 32 | s.insert(3); 33 | s.insert(1); 34 | for (ll i = 4; i <= n; i++) 35 | { 36 | if (isPowerOfTwo(i)) 37 | { 38 | cout << " " << i + 1 << " " << i; 39 | s.insert(i + 1); 40 | s.insert(i); 41 | } 42 | else 43 | { 44 | if (s.find(i) != s.end()) 45 | continue; 46 | else 47 | cout <<" "<< i; 48 | } 49 | } 50 | cout << endl; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /iss52/CHEFINSQ: -------------------------------------------------------------------------------- 1 | // Solution for problem code CHEFINSQ 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | void printNcR(int ,int); 8 | 9 | int main() { 10 | // your code goes here 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | int t; 14 | cin>>t; 15 | while(t--){ 16 | unsigned int n,k; 17 | cin>>n>>k; 18 | int a[52]; 19 | for(int i=0;i>a[i]; 21 | } 22 | sort(a,a+n); 23 | int c1=0,c2=0; 24 | for(int j=0;j 4 | 5 | using std::cin; 6 | using std::cout; 7 | 8 | long long get_fibonacci_huge_naive(long long n, long long m) { 9 | if (n <= 1) 10 | return n; 11 | 12 | long long previous = 0; 13 | long long current = 1; 14 | 15 | for (long long i = 0; i < n - 1; ++i) { 16 | long long tmp_previous = previous; 17 | previous = current; 18 | current = tmp_previous + current; 19 | } 20 | 21 | return current % m; 22 | } 23 | 24 | long long get_pisano_period_length(long long m) { 25 | long long F1 = 0, F2 = 1, F = F1 + F2; 26 | for (int i = 0; i < m * m; i++) { 27 | F = (F1 + F2) % m; 28 | F1 = F2; 29 | F2 = F; 30 | if (F1 == 0 && F2 == 1) return i + 1; 31 | } 32 | } 33 | 34 | long long get_fibonacci_huge_fast(long long n, long long m) { 35 | long long remainder = n % get_pisano_period_length(m); 36 | 37 | long long F1 = 0, F2 = 1, F = remainder; 38 | for (int i = 1; i < remainder; i++) { 39 | F = (F1 + F2) % m; 40 | F1 = F2; 41 | F2 = F; 42 | } 43 | return F % m; 44 | } 45 | 46 | int main() { 47 | long long n, m; 48 | 49 | std::cin >> n >> m; 50 | std::cout << get_fibonacci_huge_fast(n, m) << '\n'; 51 | } 52 | -------------------------------------------------------------------------------- /QuickSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void swap(int *a, int *b) 5 | { 6 | *a = *a ^ *b ^ (*b = *a); 7 | } 8 | 9 | int QSPartation(int array [], int start, int end) 10 | { 11 | int p = start, pivot = array[end]; 12 | 13 | for (int i=start; i 6 | 7 | #define FAST cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0) 8 | #define lli(n) long long n; cin>>n; 9 | #define li(n) long n; cin>>n; 10 | #define inti(n) int n;cin>>n; 11 | #define CC int test;\ 12 | cin>>test;\ 13 | while(test--) 14 | 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | FAST; 20 | CC 21 | { 22 | li(n);li(x);li(p);li(k); 23 | p--;k--; 24 | long a[n]; 25 | for(int i=0;i>a[i]; 27 | 28 | 29 | sort(a,a+n); 30 | if(a[p]==x) 31 | cout<<"0\n"; 32 | else if(p<=k && xx) 38 | { 39 | cx=i; 40 | break; 41 | } 42 | }cout<=k && x>a[p]) 45 | { 46 | int cx = n; 47 | for(int i=n-1;i>p;i--) 48 | { 49 | if(a[i]>=x && a[i-1] 2 | #include 3 | 4 | typedef unsigned long long int lld; 5 | 6 | struct node 7 | { 8 | struct node *left; 9 | unsigned long long int n; 10 | struct node *right; 11 | }node; 12 | 13 | void addnode(struct node **,lld ,lld ,lld); 14 | void search(struct node *,lld *,lld); 15 | 16 | lld sumdigits(lld no) 17 | { 18 | return no == 0 ? 0 : no%10 + sumdigits(no/10) ; 19 | } 20 | 21 | int main() 22 | { 23 | lld T,N,D,p[2]; 24 | scanf("%llu",&T); 25 | 26 | while(T--) 27 | { 28 | scanf ("%llu %llu",&N,&D); 29 | p[0]=N; 30 | p[1]=0; 31 | struct node *root=NULL; 32 | addnode (&root,N,D,0); 33 | search(root,p,0); 34 | printf ("%llu %llu\n",p[0],p[1]); 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | void addnode(struct node **pt,lld N,lld D,lld c) 41 | { 42 | 43 | if(c>20)//condition for recursion break 44 | return ; 45 | 46 | if((*pt)==NULL) 47 | { 48 | (*pt)=(struct node *)malloc(sizeof(node)); 49 | (*pt)->n=N; 50 | (*pt)->left=NULL; 51 | (*pt)->right=NULL; 52 | } 53 | 54 | addnode(&(*pt)->left,sumdigits(N),D,c+1); 55 | addnode(&(*pt)->right,(N+D),D,c+1); 56 | 57 | } 58 | 59 | void search(struct node *pt,lld *p,lld c) 60 | { 61 | if(pt!=NULL) 62 | { 63 | search(pt->left,p,c+1); 64 | if(pt->n < p[0]) 65 | { 66 | p[0]=pt->n; 67 | p[1]=c; 68 | } 69 | else if ((pt->n == p[0]) && (cright,p,c+1); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /ThreadPriority.java: -------------------------------------------------------------------------------- 1 | package com.shreyans; 2 | //t1.getName() is used to get the name 3 | //t1.setName() is used to set the name 4 | //Priority in the Range of 1 - 10 where 5 is the normal priority 5 | //t1.getPriority() is used to get the priority of the thread 6 | //t1.setPriority() is used to set the priority of the thread 7 | //Where 1 is the lowest priority or can use Thread.MIN_PRIORITY 8 | //Where 10 is the Highest priority or can use Thread.MAX_PRIORITY 9 | 10 | public class ThreadPriority{ 11 | 12 | public static void main(String[] args) throws Exception{ 13 | 14 | Thread t1 = new Thread(() -> 15 | { 16 | for (int i =0 ; i<=5;i++){ 17 | System.out.println("Hi"); 18 | try{ Thread.sleep(1000); } catch (Exception e){ } 19 | } 20 | },"Hi Thread");//You can set the name here also 21 | Thread t2 = new Thread(() -> 22 | { 23 | for (int i =0 ; i<=5;i++){ 24 | System.out.println("Hello"); 25 | try{ Thread.sleep(1000); } catch (Exception e){ } 26 | } 27 | },"Hello Thread" ); 28 | 29 | 30 | System.out.println(t1.getName()); 31 | System.out.println(t1.getName()); 32 | System.out.println(t1.getPriority()); 33 | System.out.println(t2.getPriority()); 34 | t1.start(); 35 | try { 36 | Thread.sleep(10); 37 | } catch (Exception e) { 38 | } 39 | t2.start(); 40 | 41 | t1.join(); 42 | t2.join(); 43 | System.out.println(t1.isAlive()); 44 | 45 | System.out.println("Bye"); 46 | } 47 | } -------------------------------------------------------------------------------- /Labyrinth.py: -------------------------------------------------------------------------------- 1 | #https://www.codechef.com/problems/L56LABY 2 | for _ in range(int(input())): 3 | n,m = list(map(int,input().split())) 4 | arr = [] 5 | ma = 0 6 | for i in range(n): 7 | arr.append(list(map(int,input().split()))) 8 | ma = max(max(arr[-1]),ma ) 9 | visited=[] 10 | for i in range(n): 11 | visited.append([0]*m) 12 | v=[] 13 | for i in range(ma+1): 14 | v.append([]) 15 | for i in range(n): 16 | for j in range(m): 17 | if arr[i][j] > 0: 18 | v[arr[i][j]].append((i,j)) 19 | for i in range(ma,0,-1): 20 | for cx,cy in v[i]: 21 | if visited[cx][cy] == 2: 22 | continue 23 | if cx+1 < n and arr[cx+1][cy]!=-1 and visited[cx+1][cy]==0: 24 | visited[cx+1][cy] = 1 25 | v[i-1].append((cx+1,cy)) 26 | if cx-1 > -1 and arr[cx-1][cy]!=-1 and visited[cx-1][cy]==0: 27 | visited[cx-1][cy] = 1 28 | v[i-1].append((cx-1,cy)) 29 | if cy+1 < m and arr[cx][cy+1]!=-1 and visited[cx][cy+1]==0: 30 | visited[cx][cy+1] = 1 31 | v[i-1].append((cx,cy+1)) 32 | if cy-1 > -1 and arr[cx][cy-1]!=-1 and visited[cx][cy-1]==0: 33 | visited[cx][cy-1] = 1 34 | v[i-1].append((cx,cy-1)) 35 | visited[cx][cy] = 2 36 | for i in range(n): 37 | st = '' 38 | for j in range(m): 39 | if arr[i][j] ==-1: 40 | st += 'B' 41 | elif visited[i][j]>0: 42 | st+='Y' 43 | else: 44 | st+='N' 45 | print(st) 46 | -------------------------------------------------------------------------------- /altaray.java: -------------------------------------------------------------------------------- 1 | /* package codechef; // don't place package name! 2 | * problem code-ALTARAY*/ 3 | 4 | import java.util.*; 5 | import java.lang.*; 6 | import java.io.*; 7 | 8 | /* Name of the class has to be "Main" only if the class is public. */ 9 | class Codechef 10 | { 11 | public static void main (String[] args) throws java.lang.Exception 12 | { 13 | Scanner sc=new Scanner(System.in); 14 | int t,n; 15 | t=sc.nextInt(); 16 | while(t-->0) 17 | { 18 | n=sc.nextInt(); 19 | int a[]=new int[n]; 20 | int b[]=new int[n]; 21 | for(int i=0;i=0;i--) 28 | { 29 | if(prev==Integer.MIN_VALUE) 30 | { 31 | b[i]=1; 32 | prev=a[i]; 33 | } 34 | else 35 | { 36 | if(prev>0&&a[i]>0||prev<0&&a[i]<0) 37 | { 38 | b[i]=1; 39 | prev=a[i]; 40 | } 41 | else 42 | { 43 | b[i]=b[i+1]+1; 44 | prev=a[i]; 45 | } 46 | } 47 | } 48 | for(int i=0;i 2 | using namespace std; 3 | #define ll long long 4 | #define tc ll te; cin>>te; while(te--) 5 | #define pa pair 6 | 7 | 8 | int main() 9 | { 10 | #ifndef ONLINE_JUDGE 11 | freopen("input.txt", "r", stdin); 12 | freopen("output.txt", "w", stdout); 13 | #endif 14 | ios_base::sync_with_stdio(0); cin.tie(0); 15 | tc 16 | { 17 | ll n, mini = INT_MAX, s = 0, ans = 0; 18 | vector v; 19 | map map1, map2; 20 | cin >> n; 21 | ll a[n], b[n]; 22 | for (int i = 0; i < n; i++) 23 | { 24 | cin >> a[i]; 25 | map1[a[i]]++; 26 | } 27 | for (int i = 0; i < n; i++) 28 | mini = min(mini, a[i]); 29 | for (int i = 0; i < n; i++) 30 | { 31 | cin >> b[i]; 32 | map2[b[i]]++; 33 | } 34 | for (int i = 0; i < n; i++) 35 | mini = min(mini, b[i]); 36 | for (int i = 0; i < n; i++) 37 | { 38 | if (map2[a[i]] > 0) 39 | { 40 | map2[a[i]]--; 41 | map1[a[i]]--; 42 | } 43 | } 44 | for (int i = 0; i < n; i++) 45 | { 46 | if (map1[a[i]] % 2) 47 | { 48 | s = 1; 49 | break; 50 | } 51 | if (map2[b[i]] % 2 ) 52 | { 53 | s = 1; 54 | break; 55 | } 56 | } 57 | for (int i = 0; i < n; i++) 58 | { 59 | if (map1[a[i]] > 0) 60 | { 61 | v.push_back(a[i]); 62 | map1[a[i]]--; 63 | } 64 | if (map2[b[i]] > 0) 65 | { 66 | v.push_back(b[i]); 67 | map2[b[i]]--; 68 | } 69 | } 70 | sort(v.begin(), v.end()); 71 | if (s == 1) 72 | cout << "-1" << endl; 73 | else 74 | { 75 | 76 | for (int i = 0; i < v.size() / 2; i += 2) 77 | { 78 | if (v[i] <= mini * 2) 79 | ans += v[i]; 80 | else 81 | ans += (mini * 2); 82 | } 83 | cout << ans << endl; 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Score After Flipping Matrix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int matrixScore(vector>& A) { 4 | int n = A.size(); 5 | int m = A[0].size(); 6 | int ans = 0,t=1; 7 | // int count=1; 8 | // int t=1; 9 | for(int i=1;in/2) 39 | { 40 | for(int j=0;j 2 | #include 3 | int size=0; 4 | struct location 5 | { 6 | int item; 7 | struct location *address; 8 | }; 9 | typedef struct location *location; 10 | 11 | location create() 12 | { 13 | location newnode; 14 | newnode=(location)malloc(sizeof(struct location)); 15 | return newnode; 16 | } 17 | 18 | location insertfront(location head,int cost) 19 | { 20 | location temp; 21 | temp=create(); 22 | temp->address=NULL; 23 | temp->item=cost; 24 | temp->address=head; 25 | head=temp; 26 | return head; 27 | } 28 | 29 | location deletefront(location head) 30 | { 31 | location cur; 32 | if(head == NULL) 33 | printf("Empty\n"); 34 | else 35 | { 36 | cur=head; 37 | head=head->address; 38 | free(cur); 39 | } 40 | return head; 41 | } 42 | 43 | void display(location head) 44 | { 45 | location cur; 46 | int pos=1; 47 | if(head==NULL) 48 | printf("Nothing is there\n"); 49 | else 50 | { 51 | cur=head; 52 | while(cur!=NULL) 53 | { 54 | printf("%d=[%d]\t",pos,cur->item); 55 | cur=cur->address; 56 | pos++; 57 | } 58 | printf("\n"); 59 | } 60 | } 61 | void displayrev(location head) 62 | { 63 | location cur; 64 | cur=head; 65 | if(cur!=NULL) 66 | { 67 | displayrev(cur->address); 68 | printf("[%d]\n",cur->item); 69 | 70 | } 71 | } 72 | void main() 73 | { 74 | location head=NULL; 75 | int choice,cost; 76 | for(;;) 77 | { 78 | printf("Enter your choice \n1.Insert Front \t2.Delete Front \t3.Display \t4.Display reverse\n(press any other key to exit)\n"); 79 | scanf("%d",&choice); 80 | switch (choice) 81 | { 82 | case 1:printf("Enter the cost\n"); 83 | scanf("%d",&cost); 84 | head=insertfront(head,cost); 85 | display(head); 86 | break; 87 | case 2:head=deletefront(head); 88 | display(head); 89 | break; 90 | case 3:display(head); 91 | break; 92 | case 4:displayrev(head); 93 | break; 94 | default:exit(0); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /addsqure.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // Function to count all the possible 6 | // squares with given lines parallel 7 | // to both the X and Y axis 8 | int numberOfSquares(int X[], int Y[], 9 | int N, int M) 10 | { 11 | // Stores the count of all possible 12 | // distances in X[] & Y[] respectively 13 | unordered_map m1, m2; 14 | int i, j, ans = 0; 15 | 16 | // Find distance between all 17 | // pairs in the array X[] 18 | for (i = 0; i < N; i++) { 19 | for (j = i + 1; j < N; j++) { 20 | 21 | int dist = abs(X[i] - X[j]); 22 | 23 | // Add the count to m1 24 | m1[dist]++; 25 | } 26 | } 27 | 28 | // Find distance between all 29 | // pairs in the array Y[] 30 | for (i = 0; i < M; i++) { 31 | for (j = i + 1; j < M; j++) { 32 | 33 | int dist = abs(Y[i] - Y[j]); 34 | 35 | // Add the count to m2 36 | m2[dist]++; 37 | } 38 | } 39 | 40 | // Find sum of m1[i] * m2[i] 41 | // for same distance 42 | for (auto i = m1.begin(); 43 | i != m1.end(); i++) { 44 | 45 | // Find current count in m2 46 | if (m2.find(i->first) 47 | != m2.end()) { 48 | 49 | // Add to the total count 50 | ans += 1; 51 | } 52 | } 53 | 54 | // Return the final count 55 | return ans; 56 | } 57 | 58 | bool found(int Y[],int i,int m){ 59 | int l=0,u=m-1,mid; 60 | while(l<=u){ 61 | mid=(l+u)/2; 62 | if(Y[mid]==i)return true; 63 | else if(Y[mid]>w>>h>>n>>m; 74 | vector A; 75 | int X[n]; 76 | for(int i=0;i>X[i]; 77 | int Y[m+1]; 78 | for(int j=0;j>Y[j]; 79 | sort(X,X+n);sort(Y,Y+m); 80 | int x=X[n-1]-X[0]; 81 | x+=Y[m-1]; 82 | A.push_back(numberOfSquares(X,Y,n,m+1)); 83 | for(int i=1;i<=h;i++){ 84 | if(!found(Y,i,m)) 85 | { 86 | Y[m]=i; 87 | A.push_back(numberOfSquares(X, Y, n, m+1)); 88 | } 89 | }cout<<*max_element(A.begin(), A.end()); 90 | return 0; 91 | } -------------------------------------------------------------------------------- /C - Numbers on Whiteboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | #define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); 8 | #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n" 9 | #define MAX 1000000 10 | #define mod 1000000007 11 | #define ll long long int 12 | #define ld long double 13 | #define ull unsigned long long 14 | #define li long int 15 | #define str string 16 | #define fr(i,n) for(ll i = 0; i=0; i--) 19 | #define all(x) x.begin(),x.end() 20 | #define debug(x) cout << #x << " " << x << endl; 21 | #define println(x) cout << x << "\n"; 22 | #define print(x) cout << x << " "; 23 | #define printCase(x) cout << "Case #" << x << ": "; 24 | #define umax(a, b) a=max(a,b); 25 | 26 | template void read(vector& v); 27 | template void read(T& x) { 28 | cin >> x; 29 | } 30 | void read(double& d) { 31 | string t; 32 | read(t); 33 | d=stod(t); 34 | } 35 | void read(long double& d) { 36 | string t; 37 | read(t); 38 | d=stold(t); 39 | } 40 | template void read(H& h, T&... t) { 41 | read(h); 42 | read(t...); 43 | } 44 | 45 | template void write(A x) { 46 | cout << to_string(x); 47 | } 48 | template void write(const H& h, const T&... t) { 49 | write(h); 50 | write(t...); 51 | } 52 | 53 | void solve() { 54 | 55 | ll n; 56 | read(n); 57 | 58 | int a = n, b = n-1; 59 | cout << 2 << endl; 60 | fr (i, n-1) { 61 | cout << a << " " << b <> t; 81 | 82 | frj(i, 1, t+1) { 83 | // printCase(i); 84 | solve(); 85 | } 86 | 87 | return 0; 88 | 89 | } 90 | -------------------------------------------------------------------------------- /CONVSTR.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/LTIME84B/problems/CONVSTR 2 | 3 | /* 4 | Only way to go is UP 5 | H1s3nb3rg's Here !! 6 | */ 7 | #define _USE_MATH_DEFINES 8 | #include 9 | #include 10 | using namespace std; 11 | #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 12 | #define rep(i,b,e) for(__typeof(e)i=(b)-((b)>(e));i!=(e)-((b)>(e));i+=1-2*((b)>(e))) 13 | #define repa(i,x) for(auto i:x) 14 | #define vin(x) for(auto &i:x){cin>>i;} 15 | #define vin1(x) for(ll i=1;i>x[i];} 16 | #define dbg(x) for(auto i:x){cout< vll; 22 | typedef long double ld; 23 | typedef pair pi; 24 | typedef uint64_t i64; 25 | #define ff first 26 | #define ss second 27 | typedef vector vi; 28 | typedef vector vpi; 29 | typedef vector> v2ll; 30 | #define sz(x) (int)x.size() 31 | const int MOD = 1e9+7; 32 | #define MP(a,b) make_pair(a,b) 33 | #define ff first 34 | #define ss second 35 | #define ret0 return 0; 36 | #define ret return; 37 | /*----------------------------*/ 38 | 39 | 40 | void solver(){ 41 | ll n; 42 | cin>>n; 43 | string a,b; 44 | cin>>a>>b; 45 | rep(i,0,n){ 46 | if(a[i]> mp; 52 | map,greater> mod; 53 | rep(i,0,n) 54 | mp[a[i]].push_back(i); 55 | rep(i,0,n){ 56 | if(a[i]!=b[i]){ 57 | mod[b[i]].push_back(i); 58 | } 59 | } 60 | v2ll ans; 61 | for(auto i:mod){ 62 | vll a; 63 | if(mp.find(i.ff)==mp.end()){ 64 | cout<<-1<>tc; 87 | while(tc--) 88 | solver(); 89 | ret0; 90 | } 91 | -------------------------------------------------------------------------------- /SOUNDEX.py: -------------------------------------------------------------------------------- 1 | def SOUNDEX(TERM: str): 2 | 3 | 4 | # Step 0: Covert the TERM to UpperCase 5 | TERM = TERM.upper() 6 | TERM_LETTERS = [char for char in TERM if char.isalpha()] 7 | 8 | #List the Remove occurrences of A, E, I, O, U, Y, H, W. 9 | Remove_List = ('A', 'E', 'I', 'O', 'U', 'Y', 'H', 'W') 10 | # Save the first letter 11 | first_letter = TERM_LETTERS[0] 12 | #Take the Other letters instead of First_Letter 13 | Characters = TERM_LETTERS[1:] 14 | #Remove items from Character using Remove_List 15 | Characters = [To_Characters for To_Characters in Characters if To_Characters not in Remove_List] 16 | 17 | #if len(Characters) == 0: 18 | # return first_letter + "000" 19 | 20 | #Replace all the Characters with Numeric Values (instead of the first letter) with digits according to Soundex Algorythem Ruels 21 | Replace_List = {('B', 'F', 'P', 'V'): 1, 22 | ('C', 'G', 'J', 'K', 'Q', 'S', 'X', 'Z'): 2, 23 | ('D', 'T'): 3, 24 | ('L'): 4, 25 | ('M', 'N'): 5, 26 | ('R'): 6} 27 | Characters = [value if char else char 28 | for char in Characters 29 | for group,value in Replace_List.items() 30 | if char in group] 31 | 32 | # Step 3: Replace all adjacent same number with one number 33 | Characters = [char for Letter_Count, char in enumerate(Characters) 34 | if (Letter_Count == len(Characters) - 1 or 35 | (Letter_Count+1 < len(Characters) and 36 | char != Characters[Letter_Count+1]))] 37 | 38 | #If the saved Characters’s Number is the same the resulting First Letter,keep the First Letter AND remove the Number 39 | if len(TERM_LETTERS)!=1: 40 | if first_letter == TERM_LETTERS[1]: 41 | Characters[0] = TERM[0] 42 | else: 43 | Characters.insert(0, first_letter) 44 | 45 | #If the Number of Characters are less than 4 insert 3 zeros to Characters 46 | # Remove all except first letter and 3 digits after it. 47 | #first_letter = Characters[0] 48 | #Characters = Characters[1:] 49 | 50 | #Characters = [char for char in Characters if isinstance(char, int)][0:3] 51 | while len(Characters) < 4: 52 | Characters.append(0) 53 | if len(Characters) > 4: 54 | Characters=Characters[0:4] 55 | 56 | INDEX = "".join([str(C) for C in Characters]) 57 | return INDEX 58 | -------------------------------------------------------------------------------- /LFIVES.py: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | typedef long double ld; 6 | typedef double db; 7 | 8 | typedef pair pii; 9 | typedef pair pil; 10 | typedef pair pli; 11 | typedef pair pll; 12 | typedef pair piipi; 13 | typedef pair pipii; 14 | typedef pair piipii; 15 | typedef pair plpii; 16 | typedef pair pdd; 17 | 18 | typedef vector vi; 19 | typedef vector vii; 20 | 21 | #define FOR(i, a, b) for(int i=(a);i<(b);++i) 22 | #define FOR2(i, a, b) for(int i=(a);i<=(b);++i) 23 | #define ROF(i, a, b) for(int i=(b)-1;i>=(a);--i) 24 | #define ROF2(i, a, b) for(int i=(b);i>=(a);--i) 25 | #define GO(i, x) for(auto &i : x) 26 | 27 | #define mp make_pair 28 | #define fi first 29 | #define se second 30 | #define sz(x) (int)x.size() 31 | #define all(x) (x).begin(), (x).end() 32 | #define eb emplace_back 33 | #define pf push_front 34 | #define pb push_back 35 | #define lb lower_bound 36 | #define up upper_bound 37 | 38 | const int mod = 1e9 + 7; 39 | // const int mod = 998244353 // ntt mod 40 | const int P1 = 999983, P2 = 999979; 41 | const ld PI = acos((ld)-1); 42 | const int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; 43 | const ll INF = 1e18; 44 | const int N = 2000; 45 | 46 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 47 | 48 | struct ft{ 49 | int ft[N+5]; 50 | void init(){ 51 | memset(ft, 0, sizeof(ft)); 52 | } 53 | void update(int i, int v){ 54 | for(;i<=N;i+=(i&-i)){ 55 | ft[i] += v; 56 | } 57 | } 58 | int query(int i){ 59 | int res = 0; 60 | for(;i>0;i-=(i&-i)) res+=ft[i]; 61 | return res; 62 | } 63 | }ft; 64 | 65 | ll dp1[2005][2005], dp2[2005][2005]; 66 | int a[2005]; 67 | int main(){ 68 | int n, q; 69 | scanf("%d%d", &n, &q); 70 | vector d; 71 | FOR(i, 1, n+1) scanf("%d", &a[i]), d.eb(a[i]); 72 | sort(all(d)); 73 | d.erase(unique(all(d)), d.end()); 74 | FOR(i, 1, n+1) a[i] = lb(all(d), a[i]) - d.begin() + 1; 75 | 76 | FOR(l, 1, n+1){ 77 | ft.init(); 78 | FOR(i, l+1, n+1){ 79 | dp1[l][i] = ft.query(a[i]-1); 80 | if(a[i] < a[l]) ft.update(a[i], 1); 81 | } 82 | } 83 | ROF(r, 1, n+1){ 84 | ft.init(); 85 | ROF(i, 1, r){ 86 | dp2[r][i] = ft.query(a[i]-1); 87 | if(a[i] < a[r]) ft.update(a[i], 1); 88 | } 89 | } 90 | FOR(i, 1, q+1){ 91 | int l, r; 92 | scanf("%d%d", &l, &r); 93 | ll ans = 0; 94 | FOR2(i, l, r) ans = (ans + dp1[l][i]*dp2[r][i]); 95 | printf("%lld\n", ans); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /chandf-mayLongChallenge-2020.cpp: -------------------------------------------------------------------------------- 1 | //May Long Challenge 2020 Solution for Problem Chef and Bitwise Product.. 2 | #include 3 | using namespace std; 4 | typedef long long int ll; 5 | ll x, y, l, r; 6 | 7 | ll con(int ind,bitset<64>&arr) 8 | { 9 | ll ans = 0; 10 | for(ll i=0;i& arr) 22 | { 23 | ll res = 0; 24 | int j = -2; 25 | for (ll i = ind; i >= -1; i--) 26 | { 27 | if(i > 0) 28 | if(arr[i] == 0) { 29 | continue; 30 | } 31 | ll ans1 = con(i,arr); 32 | ll ans = (y & ans1) * (x & ans1); 33 | if(ans > res) 34 | { 35 | res = ans; 36 | j = i; 37 | } 38 | } 39 | return j; 40 | } 41 | 42 | int main() 43 | { 44 | ios_base::sync_with_stdio(false); 45 | cin.tie(NULL); 46 | cout.tie(NULL); 47 | int Test; 48 | cin >> Test; 49 | while(Test--) 50 | { 51 | cin >> x >> y >> l >> r; 52 | bitset<64>a(l); 53 | bitset<64>b(r); 54 | bitset<64>c(x); 55 | bitset<64>e(y); 56 | bitset<64>arr(r); 57 | ll ind = -1; 58 | 59 | for(int i = 63; i >= 0; --i) 60 | { 61 | if(b[i] == 1 && a[i] == 0) 62 | { 63 | ind = i; 64 | break; 65 | } 66 | } 67 | if(ind == -1) 68 | { 69 | cout << l << endl; 70 | } 71 | else if(x == 0 || y == 0){ 72 | cout << l << endl; 73 | } 74 | else 75 | { 76 | int mx = chnge_of_index(ind,arr); 77 | if (mx == -2) 78 | { 79 | cout << l << endl; 80 | } 81 | else if(mx == -1) 82 | { 83 | cout << arr.to_ulong() << endl; 84 | } 85 | else 86 | { 87 | arr[mx] = 0; 88 | if (mx == ind) 89 | { 90 | bool flag = false; 91 | for ( int i = mx-1; i >= 0; --i) 92 | { 93 | if(c[i] == 1 || e[i] == 1) 94 | arr[i] = 1; 95 | else arr[i] = 0; 96 | if(flag) continue; 97 | if (arr[i] == 1 && a[i] == 0) flag = true; 98 | else arr[i] = a[i]; 99 | } 100 | } 101 | else 102 | { 103 | for (int i = mx-1; i >= 0; --i) 104 | { 105 | if(c[i] == 1 || e[i] == 1) arr[i] = 1; 106 | else arr[i] = 0; 107 | } 108 | } 109 | ll ans = con(-1,arr); 110 | cout << ans << endl; 111 | } 112 | } 113 | } 114 | return 0; 115 | } -------------------------------------------------------------------------------- /DrChef-JulyChallenge2020.cpp: -------------------------------------------------------------------------------- 1 | //Solution for July Long Challenge 2020 2 | #include 3 | using namespace std; 4 | #define pairii pair 5 | #define veci vector 6 | #define vecl vector 7 | #define mapii map 8 | #define umapll unordered_map 9 | #define pqb priority_queue 10 | #define pqs priority_queue> 11 | #define set unordered_set 12 | #define f first 13 | #define s second 14 | #define pb push_back 15 | #define mp make_pair 16 | #define setbits(x) __builtin_popcountll(x) 17 | #define leadzero(x) __builtin_clzll(x) 18 | #define trailzero(x) __builtin_ctzll(x) 19 | #define parity(x) _builtin_parityll(x) 20 | #define mod 1000000007 21 | #define inf 1e18 22 | #define bitscount 32 23 | #define pi 3.141592653589793 24 | #define gold 1.618033988749895 25 | #define maxInt INT_MAX 26 | #define minInt INT_MIN 27 | #define ps(x, y) fixed << setprecision(y) << x 28 | #define mkarr(arr, n, type) type *arr = new type[n]; 29 | #define pw(b, p) pow(b, p) + 0.1 30 | #define fastio \ 31 | ios_base::sync_with_stdio(NULL); \ 32 | cin.tie(NULL); \ 33 | cout.tie(NULL); 34 | #define t() \ 35 | int t; \ 36 | cin >> t; \ 37 | while (t--) 38 | #define read(x) scanf("%d", &x) 39 | #define write(x) printf("%d\n", x) 40 | #define loop(i, n) for (int i = 0; i < n; i++) 41 | #define looplong(i, n) for (ll i = 0; i < n; i++) 42 | #define loopab(i, a, b) for (int i = a; i < b; i++) 43 | #define looplongab(i, a, b) for (ll i = a; i < b; i++) 44 | #define looplongnminusone(i, n) for (ll i = 0; i < n - 1; i++) 45 | #define loopba(i, a, b) for (int i = a; i >= b; i--) 46 | #define looplongba(i, a, b) for (ll i = a; i >= b; i--) 47 | #define foreach(name) for (auto i = name.begin(); i != name.end(); i++) 48 | #define endln "\n" 49 | #define hcf(a, b) __gcd(a, b) 50 | #define lcm(a, b) ((a * b)) / (__gcd(a, b)) 51 | #define init(c, bytes) memset(c, 0, (bytes)) //c=container 52 | #define initc(c, bytes) memset(c, '0', (bytes)) 53 | #define max(a, b) (a) > (b) ? (a) : (b) 54 | #define min(a, b) (a) < (b) ? (a) : (b) 55 | #define mid(start, end) (((end) - (start)) >> 1) + (start) 56 | 57 | typedef long long ll; 58 | typedef unsigned long long ull; 59 | 60 | int32_t main() 61 | { 62 | fastio 63 | t() 64 | { 65 | ll n, x; 66 | cin >> n >> x; 67 | vecl anson; 68 | looplong(i,n) 69 | { 70 | ll x; 71 | cin >> x; 72 | anson.push_back(x); 73 | } 74 | sort(anson.begin(), anson.end()); 75 | ll flagt = 0; 76 | ll startIIndex; 77 | for (ll i = 0; i < n; i++) 78 | { 79 | if (anson[i] * 2 >= x) 80 | { 81 | startIIndex = i; 82 | break; 83 | } 84 | } 85 | for (ll i = startIIndex; i < n; i++) 86 | { 87 | while (x < anson[i]) 88 | { 89 | 90 | flagt++; 91 | x = x * 2; 92 | } 93 | if (x < anson[i]) 94 | { 95 | flagt += 2; 96 | x = anson[i] * 2; 97 | } 98 | else 99 | { 100 | flagt += 1; 101 | x = anson[i] * 2; 102 | } 103 | } 104 | cout << flagt + startIIndex < 2 | #include 3 | struct location 4 | { 5 | int data; 6 | struct location *left; 7 | struct location *right; 8 | }; 9 | typedef struct location *LOCATION; 10 | LOCATION cn(int item) 11 | { 12 | LOCATION temp=(LOCATION)malloc(sizeof(struct location)); 13 | temp->right=NULL; 14 | temp->left=NULL; 15 | temp->data=item; 16 | return temp; 17 | } 18 | LOCATION insert_without_recursion(LOCATION root, int item) 19 | { 20 | 21 | LOCATION temp,prv,cur; 22 | temp=cn(item); 23 | temp->data=item; 24 | if(root==NULL) 25 | root=temp; 26 | else 27 | { 28 | cur=root; 29 | while(cur!=NULL) 30 | { 31 | if(item>cur->data||item==cur->data) 32 | { 33 | prv=cur; 34 | cur=cur->right; 35 | } 36 | else 37 | { 38 | prv=cur; 39 | cur=cur->left; 40 | } 41 | } 42 | if(itemdata) 43 | prv->left=temp; 44 | else 45 | prv->right=temp; 46 | } 47 | return root; 48 | } 49 | LOCATION insert_with_recursion(LOCATION n,int item) 50 | { 51 | if(n==NULL) 52 | return cn(item); 53 | if(item>n->data||item==n->data) 54 | n->right=insert_with_recursion(n->right,item); 55 | else if(itemdata) 56 | n->left=insert_with_recursion(n->left,item); 57 | return n; 58 | } 59 | void inorder(LOCATION root) 60 | { 61 | if(root!=NULL) 62 | { 63 | inorder(root->left); 64 | printf("%d ",root->data); 65 | inorder(root->right); 66 | } 67 | } 68 | void preorder(LOCATION root) 69 | { 70 | if(root!=NULL) 71 | { 72 | printf("%d ",root->data); 73 | preorder(root->left); 74 | preorder(root->right); 75 | } 76 | } 77 | void postorder(LOCATION root) 78 | { 79 | if(root!=NULL) 80 | { 81 | postorder(root->left); 82 | postorder(root->right); 83 | printf("%d ",root->data); 84 | } 85 | } 86 | void main() 87 | { 88 | LOCATION root=NULL; 89 | int choice,item; 90 | for(;;) 91 | { 92 | printf("Enter the Chocie\n"); 93 | printf("1:Insert without recursion 2:Insert using recursion 3: inorder 4: preorder 5: postorder 6: Exit\n"); 94 | scanf("%d",&choice); 95 | switch(choice) 96 | { 97 | case 1: printf("Enter the item\n"); 98 | scanf("%d",&item); 99 | root=insert_without_recursion(root,item); 100 | printf("in-order:"); 101 | inorder(root); 102 | printf("\n"); 103 | printf("pre-order:"); 104 | preorder(root); 105 | printf("\n"); 106 | printf("post-order:"); 107 | postorder(root); 108 | printf("\n"); 109 | break; 110 | case 3: inorder(root); 111 | break; 112 | case 4: preorder(root); 113 | break; 114 | case 5: postorder(root); 115 | break; 116 | case 2: printf("Enter the item\n"); 117 | scanf("%d",&item); 118 | root=insert_with_recursion(root,item); 119 | printf("in-order:"); 120 | inorder(root); 121 | printf("\n"); 122 | printf("pre-order:"); 123 | preorder(root); 124 | printf("\n"); 125 | printf("post-order:"); 126 | postorder(root); 127 | printf("\n"); 128 | break; 129 | default: exit(0); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /D - String Deletion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | #define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); 8 | #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n" 9 | #define MAX 1000000 10 | #define mod 1000000007 11 | #define ll long long int 12 | #define ld long double 13 | #define ull unsigned long long 14 | #define li long int 15 | #define str string 16 | #define fr(i,n) for(ll i = 0; i=0; i--) 19 | #define all(x) x.begin(),x.end() 20 | #define debug(x) cout << #x << " " << x << endl; 21 | #define println(x) cout << x << "\n"; 22 | #define print(x) cout << x << " "; 23 | #define printCase(x) cout << "Case #" << x << ": "; 24 | #define umax(a, b) a=max(a,b); 25 | 26 | template void read(vector& v); 27 | template void read(T& x) { 28 | cin >> x; 29 | } 30 | void read(double& d) { 31 | string t; 32 | read(t); 33 | d=stod(t); 34 | } 35 | void read(long double& d) { 36 | string t; 37 | read(t); 38 | d=stold(t); 39 | } 40 | template void read(H& h, T&... t) { 41 | read(h); 42 | read(t...); 43 | } 44 | 45 | template void write(A x) { 46 | cout << to_string(x); 47 | } 48 | template void write(const H& h, const T&... t) { 49 | write(h); 50 | write(t...); 51 | } 52 | 53 | void solve() { 54 | 55 | ll n; 56 | read(n); 57 | 58 | string s; 59 | read(s); 60 | 61 | int c = 1, i = 1; 62 | ll ans = 0; 63 | vector count; 64 | while (i < n){ 65 | if (s[i] == s[i-1]) { 66 | c++; 67 | } 68 | else { 69 | count.push_back(c); 70 | c = 1; 71 | } 72 | ++i; 73 | } 74 | count.push_back(c); 75 | 76 | i = 0; 77 | int pos = -1; 78 | fr (i, count.size()) 79 | if (count[i] > 1){ 80 | pos = i; 81 | break; 82 | } 83 | if (pos == -1) { 84 | cout << ceil((float)n/2) << endl; 85 | // debug("yes\n+"); 86 | return; 87 | } 88 | 89 | ans = 0; 90 | // debug(pos); 91 | 92 | fr (j, count.size()) { 93 | 94 | count[pos]--; 95 | ans++; 96 | 97 | if (pos == j || count[pos] == 1) { 98 | 99 | while (pos < count.size()) { 100 | pos++; 101 | if (count[pos] > 1) 102 | break; 103 | } 104 | if(pos >= count.size()) { 105 | ans += ceil((float)(count.size()-j-1)/2); 106 | break; 107 | } 108 | 109 | } 110 | 111 | } 112 | 113 | 114 | cout << ans << endl; 115 | 116 | 117 | // fr (i, count.size()) 118 | // cout << count[i] << " "; 119 | // cout << endl; 120 | 121 | 122 | } 123 | 124 | int main() { 125 | 126 | fastio; 127 | 128 | //Skipped in presense of online judge. 129 | #ifndef ONLINE_JUDGE 130 | freopen("D:/Competitive/inputf.in","r",stdin); 131 | freopen("D:/Competitive/outputf.in","w",stdout); 132 | #endif 133 | 134 | int t(1); 135 | cin >> t; 136 | 137 | frj(i, 1, t+1) { 138 | // printCase(i); 139 | solve(); 140 | } 141 | 142 | return 0; 143 | 144 | } 145 | -------------------------------------------------------------------------------- /chefinaSwaps_julyLongChallenge2020.cpp: -------------------------------------------------------------------------------- 1 | // Chefina and swaps July Long challenge 2020. 2 | #include 3 | using namespace std; 4 | #define pairii pair 5 | #define veci vector 6 | #define vecl vector 7 | #define mapii map 8 | #define umapll unordered_map 9 | #define pqb priority_queue 10 | #define pqs priority_queue> 11 | #define set unordered_set 12 | #define f first 13 | #define s second 14 | #define pb push_back 15 | #define mp make_pair 16 | #define setbits(x) __builtin_popcountll(x) 17 | #define leadzero(x) __builtin_clzll(x) 18 | #define trailzero(x) __builtin_ctzll(x) 19 | #define parity(x) _builtin_parityll(x) 20 | #define mod 1000000007 21 | #define inf 1e18 22 | #define bitscount 32 23 | #define pi 3.141592653589793 24 | #define gold 1.618033988749895 25 | #define maxInt INT_MAX 26 | #define minInt INT_MIN 27 | #define ps(x, y) fixed << setprecision(y) << x 28 | #define mkarr(arr, n, type) type *arr = new type[n]; 29 | #define pw(b, p) pow(b, p) + 0.1 30 | #define fastio \ 31 | ios_base::sync_with_stdio(NULL); \ 32 | cin.tie(NULL); \ 33 | cout.tie(NULL); 34 | #define t() \ 35 | int t; \ 36 | cin >> t; \ 37 | while (t--) 38 | #define read(x) scanf("%d", &x) 39 | #define write(x) printf("%d\n", x) 40 | #define loop(i, n) for (int i = 0; i < n; i++) 41 | #define looplong(i, n) for (ll i = 0; i < n; i++) 42 | #define loopab(i, a, b) for (int i = a; i < b; i++) 43 | #define looplongab(i, a, b) for (ll i = a; i < b; i++) 44 | #define looplongnminusone(i, n) for (ll i = 0; i < n - 1; i++) 45 | #define loopba(i, a, b) for (int i = a; i >= b; i--) 46 | #define looplongba(i, a, b) for (ll i = a; i >= b; i--) 47 | #define foreach(name) for (auto i = name.begin(); i != name.end(); i++) 48 | #define endln "\n" 49 | #define hcf(a, b) __gcd(a, b) 50 | #define lcm(a, b) ((a * b)) / (__gcd(a, b)) 51 | #define init(c, bytes) memset(c, 0, (bytes)) //c=container 52 | #define initc(c, bytes) memset(c, '0', (bytes)) 53 | #define max(a, b) (a) > (b) ? (a) : (b) 54 | #define min(a, b) (a) < (b) ? (a) : (b) 55 | #define mid(start, end) (((end) - (start)) >> 1) + (start) 56 | #define pointloop for (ll i = 0; i < (4 * n) - 1; i++) 57 | typedef long long ll; 58 | typedef unsigned long long ull; 59 | 60 | int32_t main() 61 | { 62 | fastio 63 | t() 64 | { 65 | ll n; 66 | cin >> n; 67 | ll arr1[n], arr2[n]; 68 | umapll mp, map1, map2; 69 | ll minimum = LLONG_MAX; 70 | loop(i,n) 71 | { 72 | cin >> arr1[i]; 73 | minimum = min(arr1[i], minimum); 74 | mp[arr1[i]]++; 75 | } 76 | loop(i,n) 77 | { 78 | cin >> arr2[i]; 79 | minimum = min(arr2[i], minimum); 80 | mp[arr2[i]]++; 81 | } 82 | ll flag = 0; 83 | for (auto iteerator : mp) 84 | { 85 | if (iteerator.second % 2 == 1) 86 | { 87 | flag = 1; 88 | break; 89 | } 90 | else 91 | { 92 | map1[iteerator.first] = iteerator.second / 2; 93 | } 94 | } 95 | if (flag) 96 | { 97 | cout << "-1"<()); 128 | ll y = ans1.size(); 129 | if (y == 0) 130 | { 131 | cout << "0"< void mprintln(T ... ar){ 77 | for(T i: ar) out.print(i + " "); 78 | out.println(); 79 | } 80 | 81 | private static PrintWriter out;*/ 82 | 83 | static class Reader //fasest way to take input 84 | { //refer geeksforgeeks for more info 85 | final private int BUFFER_SIZE = 1 << 16; 86 | private DataInputStream din; 87 | private byte[] buffer; 88 | private int bufferPointer, bytesRead; 89 | 90 | public Reader() 91 | { 92 | din = new DataInputStream(System.in); 93 | buffer = new byte[BUFFER_SIZE]; 94 | bufferPointer = bytesRead = 0; 95 | } 96 | 97 | public Reader(String file_name) throws IOException 98 | { 99 | din = new DataInputStream(new FileInputStream(file_name)); 100 | buffer = new byte[BUFFER_SIZE]; 101 | bufferPointer = bytesRead = 0; 102 | } 103 | 104 | public String readLine() throws IOException 105 | { 106 | byte[] buf = new byte[(int)(Math.pow(10,5)+1)]; // line length 107 | int cnt = 0, c; 108 | while ((c = read()) != -1) 109 | { 110 | if (c == '\n') 111 | break; 112 | buf[cnt++] = (byte) c; 113 | } 114 | return new String(buf, 0, cnt); 115 | } 116 | 117 | public int nextInt() throws IOException 118 | { 119 | int ret = 0; 120 | byte c = read(); 121 | while (c <= ' ') 122 | c = read(); 123 | boolean neg = (c == '-'); 124 | if (neg) 125 | c = read(); 126 | do 127 | { 128 | ret = ret * 10 + c - '0'; 129 | } while ((c = read()) >= '0' && c <= '9'); 130 | 131 | if (neg) 132 | return -ret; 133 | return ret; 134 | } 135 | 136 | public long nextLong() throws IOException 137 | { 138 | long ret = 0; 139 | byte c = read(); 140 | while (c <= ' ') 141 | c = read(); 142 | boolean neg = (c == '-'); 143 | if (neg) 144 | c = read(); 145 | do { 146 | ret = ret * 10 + c - '0'; 147 | } 148 | while ((c = read()) >= '0' && c <= '9'); 149 | if (neg) 150 | return -ret; 151 | return ret; 152 | } 153 | 154 | public double nextDouble() throws IOException 155 | { 156 | double ret = 0, div = 1; 157 | byte c = read(); 158 | while (c <= ' ') 159 | c = read(); 160 | boolean neg = (c == '-'); 161 | if (neg) 162 | c = read(); 163 | 164 | do { 165 | ret = ret * 10 + c - '0'; 166 | } 167 | while ((c = read()) >= '0' && c <= '9'); 168 | 169 | if (c == '.') 170 | { 171 | while ((c = read()) >= '0' && c <= '9') 172 | { 173 | ret += (c - '0') / (div *= 10); 174 | } 175 | } 176 | 177 | if (neg) 178 | return -ret; 179 | return ret; 180 | } 181 | 182 | private void fillBuffer() throws IOException 183 | { 184 | bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 185 | if (bytesRead == -1) 186 | buffer[0] = -1; 187 | } 188 | 189 | private byte read() throws IOException 190 | { 191 | if (bufferPointer == bytesRead) 192 | fillBuffer(); 193 | return buffer[bufferPointer++]; 194 | } 195 | 196 | public void close() throws IOException 197 | { 198 | if (din == null) 199 | return; 200 | din.close(); 201 | } 202 | } 203 | public static void main (String[] args) throws java.lang.Exception 204 | { 205 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new 206 | FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 1024); 207 | Reader sc=new Reader(); 208 | //MyScanner sc = new MyScanner(); 209 | //out = new PrintWriter(new BufferedOutputStream(System.out)); 210 | int t=sc.nextInt(); 211 | while(t-->0) 212 | { 213 | int n=sc.nextInt(); 214 | int c=1; 215 | int x=sc.nextInt(); 216 | int y=0; 217 | int min =x; 218 | for(int i=1;iy){ 221 | min=y; 222 | } 223 | if(min>=y){ 224 | c++; 225 | } 226 | } 227 | out.write(c+"\n"); 228 | } 229 | out.flush(); 230 | //out.close(); 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /TRPLSRT.cpp: -------------------------------------------------------------------------------- 1 | // https://www.codechef.com/problems/TRPLSRT 2 | 3 | #include 4 | using namespace std; 5 | #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 6 | typedef long long ll; 7 | typedef unsigned long long ull; 8 | typedef uint64_t i64; 9 | #define ENDL "\n" 10 | #define VALL(a) a.begin(),a.end() 11 | typedef vector vll; 12 | typedef long double ld; 13 | typedef pair pi; 14 | typedef vector vi; 15 | typedef vector vpi; 16 | typedef vector> v2ll; 17 | #define sz(x) (int)x.size() 18 | #define MP(a,b) make_pair(a,b) 19 | const int MOD = 1e9+7; 20 | /*--------------------------------------*/ 21 | 22 | 23 | ll fc(vector &v,ll n) 24 | { 25 | if(v[n]<0) 26 | return n; 27 | return v[n]=fc(v,v[n]); 28 | } 29 | 30 | void uni(vector &v,ll a,ll b) 31 | { 32 | ll x=fc(v,a); 33 | ll y=fc(v,b); 34 | if(x==y) 35 | return; 36 | v[x]+=v[y]; 37 | v[y]=x; 38 | return; 39 | } 40 | 41 | void cycshift(ll *a,ll *b,ll *c){ 42 | ll tmp=*a; 43 | *a=*c; 44 | *c=*b; 45 | *b=tmp; 46 | } 47 | 48 | void solver(){ 49 | ll n,k; 50 | cin>>n>>k; 51 | vll dsu(n+1,-1); 52 | vll el(n+1,0); 53 | for(ll i=0;i>t; 56 | el[i+1]=t; 57 | uni(dsu,i+1,t); 58 | } 59 | ll od=0,ev=0; 60 | for(ll i=1;i<=n;i++){ 61 | if(dsu[i]<0 && abs(dsu[i])%2==0) 62 | ev++; 63 | else if(dsu[i]<0 && abs(dsu[i])%2!=0) 64 | od++; 65 | } 66 | if(ev%2!=0){ 67 | cout<<-1< oddcycle; 71 | vector evencycle; 72 | vector vis(n+1,0); 73 | // detect cycles 74 | for(ll i=1;i<=n;i++){ 75 | if(el[i] != i){ 76 | if(dsu[i]<0 && abs(dsu[i])%2!=0){ 77 | ll st=i; 78 | oddcycle.push_back(st); 79 | while(true){ 80 | if(vis[st]==1) 81 | break; 82 | vis[st]=1; 83 | st=el[st]; 84 | oddcycle.push_back(st); 85 | } 86 | oddcycle.pop_back(); 87 | } 88 | if(dsu[i]<0 && abs(dsu[i])%2==0){ 89 | ll st=i; 90 | evencycle.push_back(st); 91 | while(true){ 92 | if(vis[st]==1) 93 | break; 94 | vis[st]=1; 95 | st=el[st]; 96 | evencycle.push_back(st); 97 | } 98 | evencycle.pop_back(); 99 | } 100 | } 101 | } 102 | // solve 103 | vll anszz; 104 | while(oddcycle.size()!=3 && oddcycle.size()>3) 105 | { 106 | anszz.push_back(oddcycle[oddcycle.size()-3]); 107 | anszz.push_back(oddcycle[oddcycle.size()-2]); 108 | anszz.push_back(oddcycle[oddcycle.size()-1]); 109 | //cout<3) 136 | { 137 | anszz.push_back(evencycle[evencycle.size()-3]); 138 | anszz.push_back(evencycle[evencycle.size()-2]); 139 | anszz.push_back(evencycle[evencycle.size()-1]); 140 | //cout<>tc; 182 | while(tc--){ 183 | solver(); 184 | } 185 | return 0; 186 | } 187 | --------------------------------------------------------------------------------