├── c_plus_plus ├── .DS_Store ├── Raman │ └── Graph │ │ ├── .vscode │ │ └── settings.json │ │ ├── .cph │ │ ├── .Building_Roads.cpp_7e433b79cd927b9dba1a6a4298f53e3d.prob │ │ ├── .Building_Teams.cpp_92e4fa58d42efc981141d3cb07c9a894.prob │ │ ├── .Message_Route.cpp_71d5c75dbdb56d6c744588c775d202f5.prob │ │ ├── .Labyrinth.cpp_f8635e9a69fb9d7315154109f3317af4.prob │ │ └── .Counting_Rooms.cpp_ae7f61321e7c7e80dfedd5c2b3aa88a2.prob │ │ └── Raman_Building_Roads.cpp ├── jineshparakh │ └── .DS_Store ├── ASVKVINAYAK │ ├── ASVKVINAYAK_twoknights.cpp │ ├── ASVKVINAYAK_missingnumber.cpp │ ├── ASVKVINAYAK_bitstrings.cpp │ └── ASVKVINAYAK_repetation.cpp ├── c++.md ├── Ayushkumarsahoo │ ├── Ayushkumarsahoo_permutations.cpp │ ├── Ayushkumarsahoo_MissingNumber.cpp │ ├── Ayushkumarsahoo_Weird_Algorithm.cpp │ ├── Ayushkumarsahoo_Repetitions.cpp │ └── Ayushkumarsahoo_Increasing_Array.cpp ├── siddhantmohanty2001 │ ├── siddhantmohanty2001_bitStrings.cpp │ ├── siddhantmohanty2001_trailingZeroes.cpp │ ├── siddhantmohanty2001_twoKnights.cpp │ ├── siddhantmohanty2001_coinPiles.cpp │ └── siddhantmohanty2001_twoSets.cpp ├── Devansh_Singh │ ├── Weird Algorithm.cpp │ ├── Missing Number.cpp │ ├── Repetitions.cpp │ ├── Increasing Array.cpp │ ├── Permutations.cpp │ └── Number Spiral.cpp ├── akbar1214 │ ├── akbar1214_WeirdAlgorithm.cpp │ ├── akbar1214_MissingNumber.cpp │ ├── akbar1214_TwoKnights.cpp │ ├── akbar1214_IncreasingArray.cpp │ └── akbar1214_permutations.cpp ├── AkhileshMattam │ └── triling_zeros.cpp ├── AbHiSHekAB01 │ ├── AbHiSHekAB01TrailingZeros.cpp │ ├── AbHiSHekAB01_DistinctNumbers.cpp │ ├── AbHiSHekAB01_WeirdAlgorithm.cpp │ └── AbHiSHekAB01IncreasingArray.cpp ├── MartyMiniac │ ├── MartyMiniac_missing_number.cpp │ ├── MartyMiniac_bit_strings.cpp │ └── MartyMiniac_weird_algorithm.cpp ├── subhamsagar524 │ ├── subhamsagar524_trailing_zeros.cpp │ └── subhamsagar524_distinct_numbers.cpp ├── PratikSonal │ ├── PratikSonal_missing_number.cpp │ ├── PratikSonal_permutations.cpp │ ├── PratikSonal_repetitions.cpp │ └── PratikSonal_increasing_array.cpp ├── goel28priyanshu │ └── goel28priyanshu_trailing_zeros.cpp ├── SouravReal │ └── SouravReal_Two_Knights.cpp ├── stevenbudinata │ ├── stevenbudinata_distinct_numbers.cpp │ ├── stevenbudinata_missing_number.cpp │ ├── steven_budinata_repetitions.cpp │ └── stevenbudinata_weird_algorithm.cpp ├── saurabhNikam │ ├── saurabh-nikam_Bit_String.cpp │ └── saurabh-nikam_Repetitions.cpp ├── psib0t │ ├── psib0t_RemovingDigits.cpp │ ├── psib0t_CoinCombinations1.cpp │ └── psib0t_CoinCombinations2.cpp └── pawank0411 │ └── pawank0411_Permutation.cpp ├── java ├── RIJULDAS │ ├── RIJULDAS_missing_number.java │ ├── RIJULDAS_trailing_zeros.java │ └── RIJULDAS_repetitions.java ├── Rishika6 │ ├── Rishika6_missingNumber.java │ └── Rishika6_Repeatitions.java ├── SouravReal │ └── SouravReal_Missing_Number.java ├── RaviKumarPrasad │ ├── Raviruler_Missing_Number.java │ ├── Raviruler_Trailing_Zero.java │ ├── Raviruler_Weird_Algorithm.java │ ├── Raviruler_Repetition.java │ └── Raviruler_Increasing_Array.java ├── SatyapragyanDas │ ├── Satyapragyan_MissingNumber.java │ ├── SatyapragyanDas_Repetitions.java │ └── SatyapragyanDas_WeirdAlgorithm.java ├── java.md ├── UtkarshShankar │ ├── UtkarshShankar_Missing_number.java │ ├── UtkarshShankar_TrailingZeors.java │ ├── UtkarshShankar_Weird.java │ ├── UtkarshShankar_Repetitions.java │ └── UtkarshShankar_Increasing_Array.java ├── kshitizranjan15 │ ├── kshitizranjan15_MissingNumber.java │ ├── kshitizranjan15_TwoKnight.java │ ├── kshitizranjan15_Repetitions.java │ └── kshitizranjn15_IncreasingArray.java ├── agarwalsahil0210 │ ├── agarwalsahil0210_permutations.java │ ├── agarwalsahil0210_missing_number.java │ ├── agarwalsahil0210_weird_number.java.java │ └── agarwalsahil0210_repetitions.java ├── lipsamishra1609 │ ├── lipsamishra1609_distinctNumber.java │ └── lipsamishra1609_increasingArray.java ├── rituraj-iter │ ├── rituraj-iter_bit_string.java.java │ ├── rituraj-iter_trailing_zeros.java.java │ ├── rituraj-iter_two_knights.java.java │ ├── rituraj-iter_missing_number.java │ ├── rituraj-iter_distinct_number.java.java │ ├── rituraj-iter_increasing_array.java │ ├── rituraj-iter_repetitions.java │ └── rituraj-iter_sum_of_divisors.java.java ├── Abhishek417374 │ ├── Abhishek417374_trailing_zeros.java │ ├── Abhishek417374_missing_number.java │ ├── Abhishek417374_distinct_number.java │ ├── Abhishek417374_repetition.java │ └── Abhishek417374_weird_algorithm.java ├── ankitsaebby │ ├── ankitsaebbyMissingNumber.java │ ├── ankitsaebby_two_knights.java │ ├── ankitsaebbyTrailingZeros.java │ ├── ankitsaebbyWeirdAlgorithm.java │ └── ankitsaebby_repetion.java ├── swetamukherjee │ ├── swetamukherjee_MissingNumber.java │ ├── swetamukherjee_TrailingZeros.java │ ├── swetamukherjee_Repetitions.java │ └── swetamukherjee_WeirdAlgorithm.java ├── aadityamittal │ ├── aadityamittal_MissingNumber.java │ ├── aadityamittal_TrailingZeros.java │ ├── aadityamittal_BitStrings.java │ ├── aadityamittal_TwoKnights.java │ ├── aadityamittal_Repetitions.java │ └── aadityamittal_WeirdAlgorithm.java ├── Shivangibose │ ├── Shivangibose_Missing_number.java │ ├── Shivangibose_Weird_Algorithm.java │ ├── Shivangibose_Removing_Digits.java │ └── Shivangibose_increasing_array.java ├── JainStuti25 │ ├── JainStuti25_MissingNum.java │ └── JainStuti25_IncreasingArr.java ├── KejariwalAyush │ ├── kejariwalAyush_TrailingZerors.java │ ├── kejariwalAyush_bitString.java │ ├── kejariwalAyush_repetitions.java │ ├── kejariwalAyush_wierdAlgorithm.java │ └── kejariwalAyush_increasingArrays.java ├── SumanMore │ ├── SumanMore_Trailing_zeros.java │ ├── SumanMore_Missing_Number.java │ ├── SumanMore_weird_algorithm.java │ └── SumanMore_Distinct_Numbers.java ├── itsjohnty │ ├── Trailingzeros.java │ ├── Repetition.java │ ├── weird_number.java │ └── SmallestNumber.java ├── adarsh1405 │ └── adarsh1405_weird_algorithm.java ├── debashishsamantara │ ├── debashishsamantara_TrailingZeros.java │ ├── debashishsamantara_BitStrings.java │ ├── debashishsamantara_TwoKnights.java │ ├── debashishsamantara_DistinctNumbers.java │ └── debashishsamantara_repetitions.java ├── amohapatra123 │ ├── amohapatra123_missing_number.java │ └── amohapatra123_weird_algorithm.java ├── jigyasa-samal │ ├── jigyasa-samal_MissingNumber.java │ ├── jigyasa-samal_DistinctNumber.java │ └── jigyasa-samal_SmallestNumber ├── Palak Srivastava │ ├── Palak-Srivastava_MissingNumber.java │ ├── Palak-Srivastava_DistinctNumbers.java │ ├── Palak-Srivastava_RepetitionString.java │ ├── Palak-Srivastava_IncreasingArray.java │ └── Palak-Srivastava_weirdAlgorithm.java ├── Prakashpathak984 │ ├── Prakashpathak984_BitStrings.java │ ├── Prakashpathak984_MissingNumber.java │ ├── Prakashpathak984_WeirdAlgorithm.java │ ├── Prakashpathak984_Repetitions.java │ └── Prakashpathak984_removingDigits.java ├── ZeoShark │ ├── Zeoshark_TrailingZeroes.java │ ├── Zeoshark_DistinctIntegers.java │ ├── Zeoshark_MissingNumber.java │ └── ZeoShark_Weird_Algorithm.java ├── ShrutiMallick │ ├── ShrutiMallick_DiceCombination.java │ ├── ShrutiMallick_subarraydivisibilty.java │ └── ShrutiMallick_SmallestNumber.java ├── rahulkumarjha21 │ └── rahulkumarjha21_repetitions.java ├── ash0202 │ ├── ash0202_TrailingZeros.java │ └── ash0202_BitString.java ├── LoopGlitch26 │ ├── LoopGlitch26_Repetitions.java │ └── LoopGlitch26_MissingNumber.java └── TapasSahu │ └── TapasSahu_DistinctNumbers.java ├── nodejs ├── js.md └── itspiyush01 │ ├── itsPiyush01_TrailingZeros.js │ ├── itsPiyush01_TwoKnights.js │ ├── itsPiyush01_WeirdAlgorithm.js │ ├── itsPiyush01_MissingNumber.js │ └── itsPiyush01_Repetitions.js ├── python ├── python.md ├── ankita-04 │ ├── ankita-04_bitStrings.py │ ├── ankita-04_missingNumber.py │ ├── ankita-04_maxSubarraySum.py │ ├── ankita-04_repetitions.py │ ├── ankita-04_creatingStrings.py │ └── ankita-04_weirdAlgorithm.py ├── SoumyaKB96 │ ├── SoumyaKB96_Bit_Strings.py │ ├── SoumyaKB96_missing_number.py │ ├── SoumyaKB96_Subarray_Divisibility.py │ ├── SoumyaKB96_SubArray_sum2.py │ └── SoumyaKB96_subarray_sum1.py ├── TheSpeedX │ ├── TheSpeedX_missing_number.py │ ├── TheSpeedX_wierd_number.py │ ├── TheSpeedX_permutation.py │ ├── TheSpeedX_increasing_array.py │ └── TheSpeedX_repetitions.py ├── DE-L-TA │ ├── de-l-ta_missing_num.py │ ├── de-l-ta_two_num_sum.py │ ├── de-l-ta_repetation.py │ └── de-l-ta__increasing_array.py ├── SandipNayak │ ├── SandipNayak_MissingNumber.py │ ├── SandipNayak_WeirdAlgorithm.py │ ├── SandipNayak_Permutations.py │ ├── SandipNayak_IncreasingArray.py │ └── SandipNayak_Repetitions.py ├── pritam047 │ ├── pritam047_missing_number.py │ ├── pritam047_bit_strings.py │ ├── pritam047_trailing_zeros.py │ ├── pritam047_creating_strings_1.py │ ├── pritam047_weird_algorithm.py │ └── pritam047_counting_divisors.py ├── SanketKN │ ├── SanketKN_trailing_zeros.py │ ├── SanketKN_missing_number.py │ ├── SanketKN_repetitions.py │ ├── SanketKN_increasing_array.py │ └── SanketKN_weird_algorithm.py ├── saniya3 │ ├── saniya3_distinct_numbers.py │ ├── saniya3_missing_number.py │ ├── saniya3_maximum_subarray_sum.py │ ├── saniya3_increasing_array.py │ ├── saniya3_weird_algorithm.py │ └── saniya3_repetitions.py ├── iamAbhishekkumar │ ├── iamAbhishekkumar_distinct_numbers.py │ ├── iamAbhishekkumar_bit strings.py │ ├── iamAbhishekkumar_repetitions.py │ ├── iamAbhishekkumar_Permutations.py │ └── iamAbhishekkumar_stick_lengths.py ├── AkhileshMattam │ ├── AkhileshMattam_Distinct_Numbers.py │ ├── AkhileshMattam_Missing_Number.py │ ├── AkhileshMattam_Increasing_Array.py │ └── AkhileshMattam_Weird_Algorithm.py ├── belikesayantan │ ├── belikesayantan_maximum_subarray_sum.py │ ├── belikesayantan_subarray_sum.py │ ├── belikesayantan_stick_lengths.py │ ├── belikesayantan_Distinct_Numbers.py │ └── belikesayantan_sum_of_two_values.py ├── obli99 │ ├── obli99_missingNumber.py │ ├── obli99_BitStrings.py │ ├── obli99_weirdAlgorithm.py │ ├── obli99_repetitions.py │ └── obli99_increasingArray.py ├── dishak331 │ ├── dishak331_trailing_zeros.py │ ├── dishak331_missing_number.py │ ├── dishak331_repetitions.py │ ├── dishak331_weird_algorithm.py │ └── dishak331_bit_strings.py ├── swetasahoo29 │ ├── swetasahoo29_distinct_no │ ├── swetasahoo29_readingbooks │ ├── swetasahoo29_Appartments │ └── swetasahoo29_towers ├── Prerna2001 │ ├── Prerna2001_bitStrings.py │ ├── Prerna2001_missingNumber.py │ ├── Prerna2001_repetations.py │ ├── Prerna2001_sumOfTwoValues.py │ └── Prerna2001_weirdAlgorithm.py ├── nishantc7 │ ├── nishantc7_reading_books.py │ ├── nishantc7_max_subarray_sum.py │ ├── nishantc7_playlists.py │ ├── nishantc7_apartments.py │ └── nishantc7_restaurant_customers.py ├── Sharma_chanism │ ├── Sharma-chanism__Bit_Strings.py │ ├── Sharma-chanism__Missing_Number.py │ ├── Sharma_chanism__trailing_zeros.py │ ├── Sharma-chanism__Reading_Books.py │ └── Sharma_chanism__wierd_algorithm.py ├── LoopGlitch26 │ ├── LoopGlitch26_DistinctNumbers.py │ └── LoopGlitch26_ReadingBooks.py ├── bikash1317 │ ├── bikash1317_Trailing_Zeros.py │ ├── bikash1317_Bit_Strings.py │ ├── bikash1317_Sum_of_Divisors.py │ ├── bikash1317_Distinct_Numbers.py │ └── bikash1317_Weird_Algorithm.py ├── nisargsheth │ ├── nisargsheth_Bit_Strings.py │ ├── nisargsheth_Trailing_Zeros.py │ ├── nisargsheth_Creating_Strings_I.py │ └── nisargsheth_Number_Spiral.py └── Ashis-007 │ ├── Ashis-007_missing_number.py │ ├── Ashis-007_weird_algorithm.py │ ├── Ashis-007_permutations.py │ ├── Ashis-007_repetitions.py │ └── Ashis-007_increasing_array.py └── README.md /c_plus_plus/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/c_plus_plus/.DS_Store -------------------------------------------------------------------------------- /c_plus_plus/Raman/Graph/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "iostream": "cpp" 4 | } 5 | } -------------------------------------------------------------------------------- /c_plus_plus/jineshparakh/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/c_plus_plus/jineshparakh/.DS_Store -------------------------------------------------------------------------------- /java/RIJULDAS/RIJULDAS_missing_number.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/RIJULDAS/RIJULDAS_missing_number.java -------------------------------------------------------------------------------- /java/Rishika6/Rishika6_missingNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/Rishika6/Rishika6_missingNumber.java -------------------------------------------------------------------------------- /java/SouravReal/SouravReal_Missing_Number.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/SouravReal/SouravReal_Missing_Number.java -------------------------------------------------------------------------------- /c_plus_plus/ASVKVINAYAK/ASVKVINAYAK_twoknights.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/c_plus_plus/ASVKVINAYAK/ASVKVINAYAK_twoknights.cpp -------------------------------------------------------------------------------- /java/RaviKumarPrasad/Raviruler_Missing_Number.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/RaviKumarPrasad/Raviruler_Missing_Number.java -------------------------------------------------------------------------------- /java/SatyapragyanDas/Satyapragyan_MissingNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/SatyapragyanDas/Satyapragyan_MissingNumber.java -------------------------------------------------------------------------------- /java/java.md: -------------------------------------------------------------------------------- 1 | ## Java lang Repo 2 | 3 | - Add a folder of your name (if dosent exist) 4 | - Add your file in it with name mentioned in main readme 5 | - Commit and Push 6 | -------------------------------------------------------------------------------- /c_plus_plus/ASVKVINAYAK/ASVKVINAYAK_missingnumber.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/c_plus_plus/ASVKVINAYAK/ASVKVINAYAK_missingnumber.cpp -------------------------------------------------------------------------------- /c_plus_plus/c++.md: -------------------------------------------------------------------------------- 1 | ## C++ lang Repo 2 | 3 | - Add a folder of your name (if dosent exist) 4 | - Add your file in it with name mentioned in main readme 5 | - Commit and Push 6 | -------------------------------------------------------------------------------- /java/UtkarshShankar/UtkarshShankar_Missing_number.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/UtkarshShankar/UtkarshShankar_Missing_number.java -------------------------------------------------------------------------------- /java/kshitizranjan15/kshitizranjan15_MissingNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/kshitizranjan15/kshitizranjan15_MissingNumber.java -------------------------------------------------------------------------------- /nodejs/js.md: -------------------------------------------------------------------------------- 1 | ## node.js lang Repo 2 | 3 | - Add a folder of your name (if dosent exist) 4 | - Add your file in it with name mentioned in main readme 5 | - Commit and Push 6 | -------------------------------------------------------------------------------- /python/python.md: -------------------------------------------------------------------------------- 1 | ## Python lang Repo 2 | 3 | - Add a folder of your name (if dosent exist) 4 | - Add your file in it with name mentioned in main readme 5 | - Commit and Push 6 | -------------------------------------------------------------------------------- /java/agarwalsahil0210/agarwalsahil0210_permutations.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/agarwalsahil0210/agarwalsahil0210_permutations.java -------------------------------------------------------------------------------- /java/lipsamishra1609/lipsamishra1609_distinctNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/lipsamishra1609/lipsamishra1609_distinctNumber.java -------------------------------------------------------------------------------- /java/lipsamishra1609/lipsamishra1609_increasingArray.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/lipsamishra1609/lipsamishra1609_increasingArray.java -------------------------------------------------------------------------------- /c_plus_plus/Ayushkumarsahoo/Ayushkumarsahoo_permutations.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/c_plus_plus/Ayushkumarsahoo/Ayushkumarsahoo_permutations.cpp -------------------------------------------------------------------------------- /java/agarwalsahil0210/agarwalsahil0210_missing_number.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/java/agarwalsahil0210/agarwalsahil0210_missing_number.java -------------------------------------------------------------------------------- /c_plus_plus/Ayushkumarsahoo/Ayushkumarsahoo_MissingNumber.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/HEAD/c_plus_plus/Ayushkumarsahoo/Ayushkumarsahoo_MissingNumber.cpp -------------------------------------------------------------------------------- /python/ankita-04/ankita-04_bitStrings.py: -------------------------------------------------------------------------------- 1 | # Author: Ankita Satapathy 2 | # Calculate the number of bit strings of length n. 3 | # https://cses.fi/problemset/task/1617/ 4 | # userId: https://cses.fi/user/32881 5 | 6 | n= int(input()) 7 | print((2**n) % ((10**9)+7)) 8 | -------------------------------------------------------------------------------- /python/ankita-04/ankita-04_missingNumber.py: -------------------------------------------------------------------------------- 1 | # Author: Ankita Satapathy 2 | # find the missing number. 3 | # https://cses.fi/problemset/task/1083/ 4 | # userId: https://cses.fi/user/32881 5 | 6 | n = int(input()) 7 | array=map(int,input().split()) 8 | print(int(((n*(n+1))/2)-sum(array))) 9 | -------------------------------------------------------------------------------- /c_plus_plus/siddhantmohanty2001/siddhantmohanty2001_bitStrings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long long int n,i=1,ans=1,M=1000000007; 8 | cin>>n; 9 | for(i=1;i<=n;i++) 10 | ans=(ans*2)%M; 11 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long long int n,i=5,ans=0; 8 | cin>>n; 9 | for(i=5;i<=n;i*=5) 10 | { 11 | ans=ans+n/i; 12 | } 13 | cout<4): 10 | x//=5 11 | k+=x 12 | print(k) 13 | -------------------------------------------------------------------------------- /python/saniya3/saniya3_distinct_numbers.py: -------------------------------------------------------------------------------- 1 | # Distinct Numbers: 2 | # You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 3 | # https://cses.fi/problemset/task/1621/ 4 | 5 | n = input() 6 | m = list(input().split()) 7 | print(len(set(m))) 8 | 9 | # author: saniya3 10 | # https://cses.fi/user/32262 11 | 12 | -------------------------------------------------------------------------------- /c_plus_plus/Devansh_Singh/Weird Algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | long long int n; 6 | cin >> n; 7 | cout << n << " "; 8 | while (n!=1){ 9 | if (n%2==0){ 10 | n=n/2; 11 | cout << n; 12 | }else{ 13 | n=(n*3)+1; 14 | cout << n; 15 | } 16 | cout << " "; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /c_plus_plus/siddhantmohanty2001/siddhantmohanty2001_twoKnights.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long long int n,i,s,k; 8 | cin>>n; 9 | cout<<0< 2 | using namespace std; 3 | 4 | int main(){ 5 | long long int n; 6 | scanf("%lld",&n); 7 | long long int arr[n-1]; 8 | long long int sum=0; 9 | for (int i=0;i=1: 12 | c+= n//i 13 | i = i*5 14 | return c 15 | 16 | 17 | n = int(input()) 18 | print(trailing_zero(n)) 19 | -------------------------------------------------------------------------------- /python/iamAbhishekkumar/iamAbhishekkumar_bit strings.py: -------------------------------------------------------------------------------- 1 | # user id : 2 | # https://cses.fi/user/32366 3 | # Your task is to calculate the number of bit strings of length n. For example, if n=3, the correct answer is 8, 4 | # because the possible bit strings are 000, 001, 010, 011, 100, 101, 110, and 111. 5 | # https://cses.fi/problemset/task/1617/ 6 | # author : iamAbhishekkumar 7 | 8 | print(2 ** int(input()) % 1000000007) 9 | -------------------------------------------------------------------------------- /python/swetasahoo29/swetasahoo29_distinct_no: -------------------------------------------------------------------------------- 1 | 2 | # PROBLEM NUMBER 3 | # https://cses.fi/problemset/task/1621 4 | # Sweta Snigdha Sahoo 5 | # author : swetasahoo29 6 | # QUESTION 7 | # You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 8 | def main(): 9 | input() 10 | l = [x for x in input().split()] 11 | print(len(set(l))) 12 | 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /python/Prerna2001/Prerna2001_bitStrings.py: -------------------------------------------------------------------------------- 1 | # Your task is to calculate the number of bit strings of length n. 2 | # For example, if n=3, the correct answer is 8, because the possible bit strings are 000, 001, 010, 011, 100, 101, 110, and 111. 3 | # https://cses.fi/problemset/task/1617/ 4 | 5 | n = (int)(input()) 6 | x = pow(2, n, 1000000007) 7 | print(x) 8 | 9 | # author : PrernaBabber 10 | # https://cses.fi/user/32267 -------------------------------------------------------------------------------- /python/nishantc7/nishantc7_reading_books.py: -------------------------------------------------------------------------------- 1 | # Reading Books : There are n books, and Kotivalo and Justiina are going to read them all. For each book, you know the time it takes to read it. 2 | # https://cses.fi/problemset/task/1631/ 3 | 4 | n = int(input()) 5 | books = list(map(int,input().split())) 6 | books = sorted(books) 7 | print(max(sum(books),2*books[-1])) 8 | 9 | # author : nishantc7 10 | # profile : https://cses.fi/user/32680 -------------------------------------------------------------------------------- /c_plus_plus/Devansh_Singh/Repetitions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long int ll; 5 | 6 | int main(){ 7 | string s; 8 | cin >> s; 9 | int c=1; 10 | for (int i=0;ic){ 17 | c=sum; 18 | } 19 | } 20 | cout << c << endl; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /python/Sharma_chanism/Sharma-chanism__Bit_Strings.py: -------------------------------------------------------------------------------- 1 | # Your task is to calculate the number of bit strings of length n. For example, if n=3, the correct answer is 8, 2 | # because the possible bit strings are 000, 001, 010, 011, 100, 101, 110, and 111. 3 | # Problem Link: https://cses.fi/problemset/task/1617 4 | n = int(input()) 5 | print((2 ** n) % ((10 ** 9) + 7)) 6 | # Author: Sharma-chanism 7 | # User ID - https://cses.fi/user/33304 8 | -------------------------------------------------------------------------------- /python/dishak331/dishak331_missing_number.py: -------------------------------------------------------------------------------- 1 | # Print your Name 2 | # cses.fi/printName 3 | print('Disha Kapoor') 4 | # author: dishak331 5 | # solution: https://cses.fi/problemset/result/1065831/ 6 | 7 | def missing_num(n): 8 | n=sorted(n) 9 | n.append(0) 10 | for i in range(1,len(n)+1): 11 | if i!=n[i-1]: 12 | return i 13 | 14 | input() 15 | n = list(map(int, input().split(" "))) 16 | print(missing_num(n)) -------------------------------------------------------------------------------- /python/LoopGlitch26/LoopGlitch26_DistinctNumbers.py: -------------------------------------------------------------------------------- 1 | # AUTHOR 2 | # Bravish ghosh 3 | # USER ID 4 | # https://cses.fi/user/34034 5 | # PROBLEM NUMBER 6 | # https://cses.fi/problemset/task/1621 7 | # QUESTION 8 | # You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 9 | 10 | def main(): 11 | input() 12 | j = [i for i in input().split()] 13 | print(len(set(j))) 14 | 15 | 16 | main() -------------------------------------------------------------------------------- /c_plus_plus/akbar1214/akbar1214_WeirdAlgorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | long long n; 9 | cin >> n; 10 | 11 | while (n != 1) 12 | { 13 | cout << n << " "; 14 | if (n & 1) 15 | { 16 | n = n * 3 + 1; 17 | } 18 | else 19 | { 20 | n /= 2; 21 | } 22 | } 23 | cout << 1 << endl; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /python/saniya3/saniya3_missing_number.py: -------------------------------------------------------------------------------- 1 | # Missing number: 2 | # You are given all numbers between 1,2,…,n except one.Your task is to find the missing number. 3 | # https://cses.fi/problemset/task/1083/ 4 | 5 | n=int(input()) 6 | y=[int(i) for i in input().split()] 7 | 8 | def missing(seq,num): 9 | n=len(seq)+1 10 | total=n*(n+1)/2 11 | print(int(total-sum(seq))) 12 | 13 | missing(y,n) 14 | 15 | # author: saniya3 16 | # https://cses.fi/user/32262 17 | -------------------------------------------------------------------------------- /python/Sharma_chanism/Sharma-chanism__Missing_Number.py: -------------------------------------------------------------------------------- 1 | # You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 2 | # Problem link : https://cses.fi/problemset/task/1083 3 | 4 | a = int(input()) 5 | b = list(map(int, input().split())) 6 | s = 0 7 | for i in range(a - 1): 8 | s = s + b[i] 9 | c = ((a * (a + 1)) / 2) - s 10 | print(int(c)) 11 | 12 | # Author: Sharma-chanism 13 | # Result: https://cses.fi/user/33304 14 | -------------------------------------------------------------------------------- /python/ankita-04/ankita-04_maxSubarraySum.py: -------------------------------------------------------------------------------- 1 | # Author: Ankita Satapathy 2 | # find the maximum sum of values in a contiguous, nonempty subarray. 3 | # https://cses.fi/problemset/task/1643/ 4 | # userId: https://cses.fi/user/32881 5 | 6 | n = int(input()) 7 | array = [int(x) for x in input().split()] 8 | curr, maxSum = array[0], array[0] 9 | for i in range(1, len(array)): 10 | curr = max(curr + array[i], array[i]) 11 | maxSum= max(maxSum, curr) 12 | print(maxSum) 13 | -------------------------------------------------------------------------------- /python/DE-L-TA/de-l-ta_two_num_sum.py: -------------------------------------------------------------------------------- 1 | #You are given an array of n integers, and your task is to find two values (at distinct positions) whose sum is x. 2 | # https://cses.fi/problemset/task/1640 3 | # author:Mayank sahu 4 | 5 | 6 | g=lambda:map(int,input().split()) 7 | a,b=g() 8 | l=list(g()) 9 | s={} 10 | for i in range(a): 11 | n=b-l[i] 12 | if n in s: 13 | print(s[n]+1,i+1) 14 | exit() 15 | s[l[i]]=i 16 | else: 17 | print("IMPOSSIBLE") -------------------------------------------------------------------------------- /python/Prerna2001/Prerna2001_missingNumber.py: -------------------------------------------------------------------------------- 1 | # You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 2 | # https://cses.fi/problemset/task/1083 3 | 4 | def getMissing(ar,n): 5 | s_n = n*(n+1) / 2 6 | s_a = sum(ar) 7 | return int(s_n - s_a) 8 | 9 | n = int(input()) 10 | lst = [int(s) for s in input().strip().split()] 11 | print(getMissing(lst, n)) 12 | 13 | # author : PrernaBabber 14 | # https://cses.fi/user/32267 -------------------------------------------------------------------------------- /python/Sharma_chanism/Sharma_chanism__trailing_zeros.py: -------------------------------------------------------------------------------- 1 | # Problem link: https://cses.fi/problemset/task/1618 2 | # Your task is to calculate the number of trailing zeros in the factorial n!. 3 | # For example, 20!=2432902008176640000 and it has 4 trailing zeros. 4 | 5 | a = int(input()) 6 | b = 5 7 | c = 0 8 | while a / b >= 1: 9 | c = c + int(a / b) 10 | b = b * 5 11 | print(c) 12 | 13 | # Author: Sharma-chanism 14 | # User ID : https://cses.fi/user/33304 15 | -------------------------------------------------------------------------------- /python/SoumyaKB96/SoumyaKB96_missing_number.py: -------------------------------------------------------------------------------- 1 | # 2 | # Q.You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 3 | # Link - https://cses.fi/problemset/task/1083/ 4 | 5 | 6 | n=int(input()) 7 | arr=[] 8 | arr = list(map(int,input().strip().split()))[:n-1] 9 | 10 | 11 | print(int(n*(n+1)/2)-sum(arr)) 12 | 13 | 14 | 15 | 16 | 17 | #Author :SoumyaKB 18 | # Profile : https://cses.fi/user/32322 19 | -------------------------------------------------------------------------------- /python/ankita-04/ankita-04_repetitions.py: -------------------------------------------------------------------------------- 1 | # Author: Ankita Satapathy 2 | # find the longest repetition in the sequence. 3 | # https://cses.fi/problemset/task/1069/ 4 | # userId: https://cses.fi/user/32881 5 | 6 | a = input() 7 | def count(n): 8 | x=y=0 9 | for i in range(0,len(a)): 10 | if a[i]==a[i-1]: 11 | y=y+1 12 | x=max(x,y) 13 | else: 14 | y=1 15 | x=max(x,y) 16 | print(x) 17 | 18 | count(a) 19 | -------------------------------------------------------------------------------- /c_plus_plus/Devansh_Singh/Increasing Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long int ll; 5 | 6 | int main(){ 7 | ll n; 8 | scanf("%lld",&n); 9 | ll arr[n]; 10 | for (ll i=0;i 7 | using namespace std; 8 | int main() 9 | { 10 | int n,c=0; 11 | cin>>n; 12 | for(int i=5;n/i>=1;i=i*5) 13 | c=c+n/i; 14 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | 8 | int n; 9 | cin >> n; 10 | vector v(n - 1); 11 | for (int &x : v) 12 | cin >> x; 13 | 14 | sort(v.begin(), v.end()); 15 | for (int i = 0; i < n - 1; i++) 16 | { 17 | if (v[i] != i + 1) 18 | { 19 | cout << i + 1 << endl; 20 | return 0; 21 | } 22 | } 23 | cout << n << endl; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /c_plus_plus/Raman/Graph/.cph/.Building_Roads.cpp_7e433b79cd927b9dba1a6a4298f53e3d.prob: -------------------------------------------------------------------------------- 1 | {"name":"Building Roads","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1666","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601085870725,"input":"4 2\n1 2\n3 4\n","output":"1\n2 3\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BuildingRoads"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Building_Roads.cpp"} -------------------------------------------------------------------------------- /c_plus_plus/Raman/Graph/.cph/.Building_Teams.cpp_92e4fa58d42efc981141d3cb07c9a894.prob: -------------------------------------------------------------------------------- 1 | {"name":"Building Teams","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1668","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601357601408,"input":"5 3\n1 2\n1 3\n4 5\n","output":"1 2 2 1 2\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BuildingTeams"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Building_Teams.cpp"} -------------------------------------------------------------------------------- /python/obli99/obli99_BitStrings.py: -------------------------------------------------------------------------------- 1 | # Question: Your task is to calculate the number of bit strings of length n. For example, if n=3, the correct answer is 8, because the possible bit strings are 000, 001, 010, 011, 100, 101, 110, and 111. 2 | # Link: https://cses.fi/problemset/task/1617/ 3 | # author: jyotij 4 | # profile: https://cses.fi/user/32333 5 | # solution: https://cses.fi/problemset/result/1138609/ 6 | 7 | m = 1000000007 8 | n = int (input('')) 9 | i = 1 10 | while (n > 0): 11 | i = (i*2)%m 12 | n = n - 1 13 | print (int(i)) -------------------------------------------------------------------------------- /c_plus_plus/Raman/Graph/.cph/.Message_Route.cpp_71d5c75dbdb56d6c744588c775d202f5.prob: -------------------------------------------------------------------------------- 1 | {"name":"Message Route","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1667","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601106441000,"input":"5 5\n1 2\n1 3\n1 4\n2 3\n5 4\n","output":"3\n1 4 5\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"MessageRoute"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Message_Route.cpp"} -------------------------------------------------------------------------------- /python/nishantc7/nishantc7_max_subarray_sum.py: -------------------------------------------------------------------------------- 1 | # Maximum Subarray Sum : Given an array of n integers, your task is to find the maximum sum of values in a contiguous, nonempty subarray. 2 | # https://cses.fi/problemset/task/1643/ 3 | 4 | n = int(input()) 5 | arr = [int(x) for x in input().split()] 6 | maxSub = arr[0] 7 | curSum = 0 8 | for n in arr: 9 | if curSum < 0 : 10 | curSum = 0 11 | curSum +=n 12 | maxSub = max(curSum,maxSub) 13 | print(maxSub) 14 | 15 | # author : nishantc7 16 | # profile : https://cses.fi/user/32680 -------------------------------------------------------------------------------- /python/bikash1317/bikash1317_Trailing_Zeros.py: -------------------------------------------------------------------------------- 1 | # User ID : https://cses.fi/user/32480 2 | # Problem Number ID : https://cses.fi/problemset/task/1618 3 | 4 | # Aurthor : bikash1317 5 | 6 | # Question: 7 | # Your task is to calculate the number of trailing zeros in the factorial n!. 8 | 9 | # For example, 20!=2432902008176640000 and it has 4 trailing zeros. 10 | 11 | 12 | number = int(input ('')) 13 | i=5 14 | countZeros = 0 15 | while(number >= i): 16 | countZeros = countZeros + int((number/i)) 17 | i = i * 5 18 | print (countZeros) 19 | -------------------------------------------------------------------------------- /python/pritam047/pritam047_trailing_zeros.py: -------------------------------------------------------------------------------- 1 | # USER ID 2 | # https://cses.fi/user/32269 3 | # PROBLEM NUMBER 4 | # https://cses.fi/problemset/task/1622/ 5 | # QUESTION 6 | # Your task is to calculate the number of trailing zeros in the factorial n!. 7 | # For example, 20!=2432902008176640000 and it has 4 trailing zeros. 8 | def trailingZeros(n): 9 | count = 0 10 | i=5 11 | while (n/i>=1): 12 | count += int(n/i) 13 | i *= 5 14 | 15 | return int(count) 16 | 17 | 18 | n = int(input()) 19 | print(trailingZeros(n)) -------------------------------------------------------------------------------- /python/nisargsheth/nisargsheth_Bit_Strings.py: -------------------------------------------------------------------------------- 1 | # Question 2 | # Your task is to calculate the number of bit strings of length n. 3 | # For example, if n=3, the correct answer is 8, because the possible bit strings are 000, 001, 010, 011, 100, 101, 110, and 111. 4 | 5 | 6 | # Link 7 | # https://cses.fi/problemset/task/1617 8 | 9 | def main(): 10 | 11 | n = int(input()) 12 | print((2**n)%1000000007) 13 | main() 14 | 15 | # author: nisargsheth 16 | # profile: https://cses.fi/user/9669 17 | # solution: https://cses.fi/problemset/result/383637/ 18 | -------------------------------------------------------------------------------- /python/swetasahoo29/swetasahoo29_readingbooks: -------------------------------------------------------------------------------- 1 | # PROBLEM NUMBER 2 | # https://cses.fi/problemset/task/1631 3 | # Sweta Snigdha Sahoo 4 | # author : swetasahoo29 5 | # QUESTION 6 | # There are n books, and Kotivalo and Justiina are going to read them all. For each book, you know the time it takes to read it. 7 | 8 | # They both read each book from beginning to end, and they cannot read a book at the same time. What is the minimum total time required? 9 | n,i=int(input()),list(map(int,input().split())) 10 | print(sum(i) if sum(i)-max(i)>=max(i) else max(i)*2) 11 | -------------------------------------------------------------------------------- /c_plus_plus/Devansh_Singh/Permutations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long int ll; 5 | 6 | int main(){ 7 | ll n; 8 | scanf("%lld",&n); 9 | if (n==1){ 10 | printf("1\n"); 11 | }else if(n<4){ 12 | printf("NO SOLUTION\n"); 13 | }else if (n==4){ 14 | printf("3 1 4 2\n"); 15 | }else{ 16 | for (ll i=1;i<=n;i+=2){ 17 | printf("%d",i); 18 | printf(" "); 19 | } 20 | for (ll j=2;j<=n;j+=2){ 21 | printf("%d",j); 22 | printf(" "); 23 | } 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /c_plus_plus/Raman/Graph/.cph/.Labyrinth.cpp_f8635e9a69fb9d7315154109f3317af4.prob: -------------------------------------------------------------------------------- 1 | {"name":"Labyrinth","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1193","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601085858617,"input":"5 8\n########\n#.A#...#\n#.##.#B#\n#......#\n########\n","output":"YES\n9\nLDDRRRRRU\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"Labyrinth"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Labyrinth.cpp"} -------------------------------------------------------------------------------- /python/SanketKN/SanketKN_increasing_array.py: -------------------------------------------------------------------------------- 1 | #increasing array 2 | #https://cses.fi/problemset/task/1094/ 3 | #You are given an array of n integers. You want to modify the array so that it is increasing, 4 | #i.e., every element is at least as large as the previous element. 5 | #author : SanketKN 6 | #csis id:https://cses.fi/user/33432 7 | 8 | x = int(input()) 9 | n = list(map(int,input().split()))[:(x-1)] 10 | k = 0 11 | 12 | for i in range(0, x-1): 13 | if n[i] > n[i+1]: 14 | k += (n[i]-n[i+1]) 15 | n[i+1] = n[i] 16 | print(k) 17 | -------------------------------------------------------------------------------- /c_plus_plus/Raman/Graph/.cph/.Counting_Rooms.cpp_ae7f61321e7c7e80dfedd5c2b3aa88a2.prob: -------------------------------------------------------------------------------- 1 | {"name":"Counting Rooms","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1192","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601085822567,"input":"5 8\n########\n#..#...#\n####.#.#\n#..#...#\n########\n","output":"3\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CountingRooms"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Counting_Rooms.cpp"} -------------------------------------------------------------------------------- /python/nisargsheth/nisargsheth_Trailing_Zeros.py: -------------------------------------------------------------------------------- 1 | # Question 2 | # Your task is to calculate the number of trailing zeros in the factorial n!. 3 | # For example, 20!=2432902008176640000 and it has 4 trailing zeros. 4 | 5 | 6 | # Link 7 | # https://cses.fi/problemset/task/1618 8 | def main(): 9 | 10 | n = int(input()) 11 | cnt = 0 12 | while(n!=0): 13 | n//=5 14 | cnt+=n 15 | print(cnt) 16 | main() 17 | 18 | # author: nisargsheth 19 | # profile: https://cses.fi/user/9669 20 | # solution: https://cses.fi/problemset/result/383640/ 21 | -------------------------------------------------------------------------------- /python/pritam047/pritam047_creating_strings_1.py: -------------------------------------------------------------------------------- 1 | # USER ID 2 | # https://cses.fi/user/32269 3 | # PROBLEM NUMBER 4 | # https://cses.fi/problemset/task/1622/ 5 | # QUESTION 6 | # Given a string, your task is to generate all different strings that can be created using its characters. 7 | from itertools import permutations 8 | n = input() 9 | p = permutations(n) 10 | 11 | arlist = [] 12 | for i in list(p): 13 | arlist.append(''.join(i)) 14 | 15 | nlist = sorted(list(set(arlist))) 16 | print(len(nlist)) 17 | 18 | for j in nlist: 19 | print(j) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /python/SandipNayak/SandipNayak_WeirdAlgorithm.py: -------------------------------------------------------------------------------- 1 | # Author: Sandip Nayak 2 | #Consider an algorithm that takes as input a positive integer n. 3 | # If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 4 | # The algorithm repeats this, until n is one. 5 | # https://cses.fi/problemset/task/1068 6 | #userId: https://cses.fi/user/34086 7 | 8 | n = int(input()) 9 | print(n, end=" ") 10 | while(n!= 1): 11 | if(n % 2 == 0): 12 | n = n//2 13 | else: 14 | n = n*3+1 15 | print(n,end=" ") 16 | -------------------------------------------------------------------------------- /c_plus_plus/siddhantmohanty2001/siddhantmohanty2001_coinPiles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | long long int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | long long int a,b,mini,maxi; 12 | cin>>a>>b; 13 | mini=min(a,b); 14 | maxi=max(a,b); 15 | if(a==0&&b==0) 16 | cout<<"YES"<=1&&b>=1) 18 | cout<<"YES"<=max(j) else max(j)*2) 12 | -------------------------------------------------------------------------------- /python/saniya3/saniya3_increasing_array.py: -------------------------------------------------------------------------------- 1 | # Icreasing Array:You are given an array of n integers.You want to modify the array so that it is increasing. 2 | # On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 3 | # https://cses.fi/problemset/task/1094/ 4 | 5 | n = int(input()) 6 | l = list(map(int,input().split(' '))) 7 | c=0 8 | for i in range(1,n): 9 | if l[i-1]>l[i]: 10 | c+=(l[i-1]-l[i]) 11 | l[i]=l[i-1] 12 | print(c) 13 | 14 | # author: saniya3 15 | # https://cses.fi/user/32262 16 | 17 | -------------------------------------------------------------------------------- /python/Ashis-007/Ashis-007_missing_number.py: -------------------------------------------------------------------------------- 1 | # Question 2 | # You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 3 | 4 | # Link 5 | # https://cses.fi/problemset/task/1083/ 6 | n = int(input()) 7 | numbers = input().split() 8 | numbers = list(map(int, numbers)) 9 | missing_sum = 0 10 | 11 | for i in numbers: 12 | missing_sum += i 13 | 14 | original_sum = n * (n + 1) // 2 15 | print(original_sum - missing_sum) 16 | 17 | # author: Ashis-007 18 | # profile: https://cses.fi/user/32353 19 | # solution: https://cses.fi/problemset/result/1066259/ -------------------------------------------------------------------------------- /python/DE-L-TA/de-l-ta_repetation.py: -------------------------------------------------------------------------------- 1 | #question link : https://cses.fi/problemset/task/1069 2 | #author Mayank Sahu 3 | #You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find 4 | #the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 5 | 6 | d=input() 7 | g,c,e=d[0],1,1 8 | for i in range(1,len(d)): 9 | if g==d[i]: 10 | c+=1 11 | if e < c: 12 | e=c 13 | 14 | 15 | else: 16 | g=d[i] 17 | c=1 18 | print(e) -------------------------------------------------------------------------------- /python/SanketKN/SanketKN_weird_algorithm.py: -------------------------------------------------------------------------------- 1 | #weird algorithm 2 | #https://cses.fi/problemset/task/1068/ 3 | #Consider an algorithm that takes as input a positive integer n. 4 | #If n is even, the algorithm divides it by two, and if n is odd, 5 | #the algorithm multiplies it by three and adds one. The algorithm 6 | #repeats this, until n is one. 7 | x = int(input()) 8 | print(x, end=' ') 9 | while x!=1: 10 | if x%2 != 0: 11 | x = (x*3)+1 12 | else: 13 | x//=2 14 | print(x, end=' ') 15 | 16 | #auther: SanketKN 17 | #cses id : https://cses.fi/user/33432 18 | -------------------------------------------------------------------------------- /python/obli99/obli99_weirdAlgorithm.py: -------------------------------------------------------------------------------- 1 | # Question: Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 2 | # Link: https://cses.fi/problemset/task/1068/ 3 | # author: jyotij 4 | # profile: https://cses.fi/user/32333 5 | # solution: https://cses.fi/problemset/result/1133081/ 6 | 7 | n = int((input())) 8 | print(n, end=" ") 9 | while n != 1: 10 | if n % 2 == 0: 11 | n //= 2 12 | elif n%2!=0: 13 | n = n * 3 + 1 14 | 15 | print(n, end=" ") -------------------------------------------------------------------------------- /c_plus_plus/AbHiSHekAB01/AbHiSHekAB01TrailingZeros.cpp: -------------------------------------------------------------------------------- 1 | 2 | //Your task is to calculate the number of trailing zeros in the factorial n!. 3 | 4 | //For example, 20!=2432902008176640000 and it has 4 trailing zeros. 5 | 6 | //author:AbHiSHekAB01; 7 | 8 | 9 | #include 10 | 11 | int main() { 12 | std::cout ; 13 | int k; 14 | std::cin >> k; 15 | int t = 0; 16 | for (int i = 5; k / i >= 1; i *= 5) 17 | { 18 | t += k / i; 19 | } 20 | std::cout << t; 21 | return 0;} 22 | 23 | 24 | //cses user id:- https://cses.fi/user/32825 -------------------------------------------------------------------------------- /python/ankita-04/ankita-04_weirdAlgorithm.py: -------------------------------------------------------------------------------- 1 | # Author: Ankita Satapathy 2 | #Consider an algorithm that takes as input a positive integer n. 3 | # If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 4 | # The algorithm repeats this, until n is one. 5 | # https://cses.fi/problemset/task/1068/ 6 | #userId: https://cses.fi/user/32881 7 | 8 | num = int(input()) 9 | print(num, end=" ") 10 | while(num != 1): 11 | if(num % 2 == 0): 12 | num = num//2 13 | else: 14 | num = num*3+1 15 | print(num,end=" ") 16 | -------------------------------------------------------------------------------- /python/dishak331/dishak331_repetitions.py: -------------------------------------------------------------------------------- 1 | # Print your Name 2 | # cses.fi/printName 3 | print('Disha Kapoor') 4 | # author: dishak331 5 | # solution: https://cses.fi/problemset/result/1065973/ 6 | 7 | def repeat_counts(n): 8 | if len(n)==1: 9 | return 1 10 | maxx=c=0 11 | for i in range(1,len(n)): 12 | if n[i-1]==n[i]: 13 | c+=1 14 | if n[i-1]!=n[i] or i==len(n)-1: 15 | c+=1 16 | if maxx0){ 11 | i=(i*2)%m_mod; 12 | } 13 | System.out.println(i); 14 | } 15 | } 16 | // author: rituraj-iter 17 | // profile: https://cses.fi/user/32401 -------------------------------------------------------------------------------- /python/TheSpeedX/TheSpeedX_repetitions.py: -------------------------------------------------------------------------------- 1 | # You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 2 | # https://cses.fi/problemset/task/1069/ 3 | 4 | dna= input()+" " 5 | count=1 6 | maxcount=1 7 | for i in range(len(dna)-1): 8 | if dna[i]==dna[i+1]: 9 | count+=1 10 | else: 11 | if count>maxcount: 12 | maxcount=count 13 | count=1 14 | print(maxcount) 15 | 16 | # author: deadcoder 17 | # https://cses.fi/user/32336 -------------------------------------------------------------------------------- /c_plus_plus/Devansh_Singh/Number Spiral.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long int ll; 5 | 6 | int main(){ 7 | ll t; 8 | scanf("%lld",&t); 9 | while (t>0){ 10 | ll x,y; 11 | scanf("%lld %lld",&x,&y); 12 | if (x 0): 18 | i = (i*2)%mod 19 | number = number -1 20 | print (int(i)) -------------------------------------------------------------------------------- /python/Prerna2001/Prerna2001_repetations.py: -------------------------------------------------------------------------------- 1 | # You are given a DNA sequence: a string consisting of characters A, C, G, and T. 2 | # Your task is to find the longest repetition in the sequence. 3 | # This is a maximum-length substring containing only one type of character. 4 | # https://cses.fi/problemset/task/1069/ 5 | 6 | string= input()+" " 7 | c=1 8 | max=1 9 | for i in range(len(string)-1): 10 | if string[i]==string[i+1]: 11 | c+=1 12 | else: 13 | if c>max: 14 | max=c 15 | c=1 16 | print(max) 17 | 18 | # author : PrernaBabber 19 | # https://cses.fi/user/32267 -------------------------------------------------------------------------------- /python/SandipNayak/SandipNayak_Permutations.py: -------------------------------------------------------------------------------- 1 | # Author: Sandip Nayak 2 | # A permutation of integers 1,2,…,n is called beautiful if there are no adjacent elements whose difference is 1. 3 | # Given n, construct a beautiful permutation if such a permutation exists. 4 | # https://cses.fi/problemset/task/1070 5 | # userId: https://cses.fi/user/34086 6 | 7 | num= int(input()) 8 | 9 | if (num==2 or num==3): 10 | print("NO SOLUTION") 11 | elif (num==4): 12 | print("3 1 4 2") 13 | else: 14 | perm=[str(i) for i in range (1,num+1,2)] 15 | perm+=[str(i) for i in range (2,num+1,2)] 16 | print(" ".join(perm)) 17 | -------------------------------------------------------------------------------- /python/Ashis-007/Ashis-007_weird_algorithm.py: -------------------------------------------------------------------------------- 1 | # Question 2 | # Consider an algorithm that takes as input a positive integer n. 3 | # If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 4 | 5 | # Link 6 | # https://cses.fi/problemset/task/1068/ 7 | 8 | n = int((input())) 9 | print(n, end=" ") 10 | 11 | while n != 1: 12 | if n % 2 == 0: 13 | n //= 2 14 | else: 15 | n = n * 3 + 1 16 | 17 | print(n, end=" ") 18 | 19 | # author: Ashis-007 20 | # profile: https://cses.fi/user/32353 21 | # solution: https://cses.fi/problemset/result/1066093/ -------------------------------------------------------------------------------- /python/SandipNayak/SandipNayak_IncreasingArray.py: -------------------------------------------------------------------------------- 1 | # Author: Sandip Nayak 2 | # You are given an array of n integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 3 | # On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 4 | # https://cses.fi/problemset/task/1094 5 | # userId: https://cses.fi/user/34086 6 | 7 | num = int(input()) 8 | arr = list(map(int,input().strip().split())) 9 | total=0 10 | m=arr[0] 11 | for i in arr: 12 | total+=max(0,m-i) 13 | m=max(m,i) 14 | print(total) 15 | 16 | -------------------------------------------------------------------------------- /python/dishak331/dishak331_weird_algorithm.py: -------------------------------------------------------------------------------- 1 | # Print your Name 2 | # cses.fi/printName 3 | print('Disha Kapoor') 4 | # author: dishak331 5 | # solution: https://cses.fi/problemset/result/1066160/ 6 | 7 | def weird_algo(algo): 8 | if algo[-1]==1: 9 | return algo 10 | if algo[-1]%2==0: 11 | algo.append(algo[-1]//2) 12 | return weird_algo(algo) 13 | else: 14 | algo.append(algo[-1]*3+1) 15 | return weird_algo(algo) 16 | 17 | 18 | n = int(input()) 19 | if n==1: 20 | print(n) 21 | else: 22 | algo = [n] 23 | s = list(map(str, weird_algo(algo))) 24 | print(" ".join(s)) -------------------------------------------------------------------------------- /python/saniya3/saniya3_weird_algorithm.py: -------------------------------------------------------------------------------- 1 | # Weird algorithm: 2 | #Consider an algorithm that takes as input a positive integer n. 3 | # If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 4 | # The algorithm repeats this, until n is one. 5 | # https://cses.fi/problemset/task/1068/ 6 | 7 | x=int(input()) 8 | def alg(n): 9 | while n != 1: 10 | print(n, end = ' ') 11 | if n & 1: 12 | n=3*n+1 13 | else: 14 | n=n//2 15 | print(n) 16 | alg(x) 17 | 18 | # author: saniya3 19 | # https://cses.fi/user/32262 20 | -------------------------------------------------------------------------------- /java/Abhishek417374/Abhishek417374_trailing_zeros.java: -------------------------------------------------------------------------------- 1 | //Your task is to calculate the number of trailing zeros in the factorial n!.For example, 20!=2432902008176640000 and it has 4 trailing zeros. 2 | 3 | ///https://cses.fi/problemset/task/1618 4 | 5 | //Author:Abhishek417374 6 | 7 | import java.util.Scanner; 8 | public class Abhishek417374_trailing_zeros{ 9 | 10 | public static void main(String[] args) { 11 | Scanner s=new Scanner(System.in); 12 | int n=s.nextInt(); 13 | int count=0; 14 | for (int i = 5; i <= n; i *= 5) 15 | count += n / i; 16 | System.out.println(count); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /c_plus_plus/MartyMiniac/MartyMiniac_missing_number.cpp: -------------------------------------------------------------------------------- 1 | //Question 2 | //You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 3 | 4 | //https://cses.fi/problemset/task/1083/ 5 | 6 | #include "iostream" 7 | 8 | int main() 9 | { 10 | double size; 11 | std::cin>>size; 12 | double t=0; 13 | t=size*(size+1)*0.5; 14 | for(int i=0; i>tmp; 18 | t-=tmp; 19 | } 20 | std::cout<l1[i]: 11 | t+=(l1[i-1]-l1[i]) 12 | l1[i]=l1[i-1] 13 | print(t) 14 | -------------------------------------------------------------------------------- /python/Sharma_chanism/Sharma-chanism__Reading_Books.py: -------------------------------------------------------------------------------- 1 | # Problem link: https://cses.fi/problemset/task/1631 2 | # There are n books, and Kotivalo and Justiina are going to read them all. 3 | # For each book, you know the time it takes to read it. 4 | # They both read each book from beginning to end, and they cannot read a book at the same time. 5 | # What is the minimum total time required? 6 | 7 | 8 | a = int(input()) 9 | b = list(map(int, input().split())) 10 | s = sum(b) 11 | c = max(b) 12 | if s-c >= c: 13 | print(s) 14 | else: 15 | print(c*2) 16 | 17 | # Author: Sharma-chanism 18 | # User ID : https://cses.fi/user/33304 19 | -------------------------------------------------------------------------------- /python/saniya3/saniya3_repetitions.py: -------------------------------------------------------------------------------- 1 | # Repetitions: 2 | # You are given a DNA sequence: a string consisting of characters A, C, G, and T. 3 | # Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 4 | # https://cses.fi/problemset/task/1069/ 5 | 6 | n = input() 7 | def count(n): 8 | b=c=0 9 | for i in range(0,len(n)): 10 | if n[i]==n[i-1]: 11 | c+=1 12 | b=max(b,c) 13 | else: 14 | c=1 15 | b=max(b,c) 16 | print(b) 17 | 18 | count(n) 19 | 20 | # author: saniya3 21 | # https://cses.fi/user/32262 22 | -------------------------------------------------------------------------------- /java/rituraj-iter/rituraj-iter_trailing_zeros.java.java: -------------------------------------------------------------------------------- 1 | /*Your task is to calculate the number of trailing zeros in the factorial n!. 2 | For example, 20!=2432902008176640000 and it has 4 trailing zeros.*/ 3 | // https://cses.fi/problemset/task/1618/ 4 | import java.util.Scanner; 5 | public class Trailing_Zeros { 6 | public static void main(String[] args) { 7 | Scanner sc=new Scanner(System.in); 8 | int n=sc.nextInt(); 9 | int c=0; 10 | while(n>=5){ 11 | c+=(n/=5); 12 | } 13 | System.out.println(c); 14 | } 15 | } 16 | // author: rituraj-iter 17 | // profile: https://cses.fi/user/32401 -------------------------------------------------------------------------------- /c_plus_plus/MartyMiniac/MartyMiniac_bit_strings.cpp: -------------------------------------------------------------------------------- 1 | //Question 2 | /*Your task is to calculate the number of bit strings of length n. 3 | For example, if n=3, the correct answer is 8, because the possible 4 | bit strings are 000, 001, 010, 011, 100, 101, 110, and 111.*/ 5 | 6 | //https://cses.fi/problemset/task/1617 7 | 8 | #include "iostream" 9 | 10 | int main() 11 | { 12 | int n; 13 | std::cin>>n; 14 | int outp = 1; 15 | for(int i=n; i>0; i--) 16 | { 17 | outp = (outp*2)%1000000007; 18 | } 19 | std::cout< 11 | using namespace std; 12 | 13 | int main() 14 | { 15 | long long num; 16 | cin >> num; 17 | 18 | int res = 0; 19 | 20 | for(long long i = 5; num/i >= 1; i *= 5) 21 | res += num/i; 22 | 23 | cout << res << endl; 24 | 25 | return 0; 26 | } 27 | 28 | // author: Subham Sagar Paira 29 | // profile: https://cses.fi/user/32482 30 | -------------------------------------------------------------------------------- /java/rituraj-iter/rituraj-iter_two_knights.java.java: -------------------------------------------------------------------------------- 1 | // Your task is to count for k=1,2,…,n the number of ways two knights can be placed on a k×k chessboard so that they do not attack each other. 2 | // https://cses.fi/problemset/task/1072 3 | import java.util.Scanner; 4 | public class Test13 { 5 | public static void main(String[] args) { 6 | Scanner sc=new Scanner(System.in); 7 | int n=sc.nextInt(); 8 | for (int i=1;i<=n;i++) { 9 | int k =i*i; 10 | System.out.println((long)k*(k-1)/2-(i-1)*(i-2)*4); 11 | } 12 | } 13 | } 14 | // author: rituraj-iter 15 | // profile: https://cses.fi/user/32401 -------------------------------------------------------------------------------- /python/obli99/obli99_increasingArray.py: -------------------------------------------------------------------------------- 1 | # You are given an array of n integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 2 | #On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 3 | # Question link : https://cses.fi/problemset/task/1094 4 | # Author : jyotij 5 | # profile : https://cses.fi/user/32333 6 | # solution : https://cses.fi/problemset/result/1137543/ 7 | 8 | n = int(input()) 9 | a = list(map(int,input().strip().split())) 10 | total=0 11 | m=a[0] 12 | for i in a: 13 | total+=max(0,m-i) 14 | m=max(m,i) 15 | print(total) -------------------------------------------------------------------------------- /c_plus_plus/PratikSonal/PratikSonal_missing_number.cpp: -------------------------------------------------------------------------------- 1 | //Question 2 | //You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 3 | //https://cses.fi/problemset/task/1083/ 4 | 5 | #include "iostream" 6 | 7 | int main(){ 8 | double num; 9 | std::cin >> num; 10 | double count = num * (num+ 1) * 0.5; 11 | for(int i = 0; i < num - 1; i++){ 12 | int temp; 13 | std::cin>>temp; 14 | count -= temp; 15 | } 16 | std::cout<i: 15 | n+=c-i 16 | else: 17 | c=i 18 | if d==int(t): 19 | print(n) 20 | else: 21 | exit(0) 22 | 23 | 24 | -------------------------------------------------------------------------------- /java/kshitizranjan15/kshitizranjan15_TwoKnight.java: -------------------------------------------------------------------------------- 1 | /* 2 | Your task is to count for k=1,2,…,n the number of ways two knights can be placed on a k×k chessboard so that they do not attack each other. 3 | //https://cses.fi/problemset/task/1072 4 | */ 5 | import java.util.Scanner; 6 | 7 | public class TwoKnight 8 | { 9 | public static void main(String[] args) { 10 | Scanner sc=new Scanner(System.in); 11 | long n=sc.nextInt(); 12 | for (long i=1;i<=n;i++) { 13 | long k =i*i; 14 | System.out.println(k*(k-1)/2-(i-1)*(i-2)*4); 15 | } 16 | } 17 | } 18 | //author:- kshitizranjan15 19 | // https://cses.fi/user/32865 -------------------------------------------------------------------------------- /python/Sharma_chanism/Sharma_chanism__wierd_algorithm.py: -------------------------------------------------------------------------------- 1 | # Problem Link : https://cses.fi/problemset/task/1068 2 | # Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, 3 | # and if n is odd, the algorithm multiplies it by three and adds one 4 | # The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows: 5 | # 3→10→5→16→8→4→2→1 6 | 7 | a = int(input()) 8 | while a > 1: 9 | print(int(a)) 10 | if a % 2 == 0: 11 | a = a / 2 12 | else: 13 | a = (a * 3) + 1 14 | print(1) 15 | # author : Sharma-chanism 16 | # Result Link : https://cses.fi/user/33304 17 | -------------------------------------------------------------------------------- /java/Shivangibose/Shivangibose_Missing_number.java: -------------------------------------------------------------------------------- 1 | //You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 2 | //LINK:-https://cses.fi/problemset/task/1083 3 | 4 | import java.util.*; 5 | public class Shivangibose_Missing_number 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc=new Scanner(System.in); 10 | long n=sc.nextInt(); 11 | long a,s=0; 12 | s=(n)*(n+1)/2; 13 | for(int x=1;x 2 | #define sc(x) scanf("%d", &x) 3 | #define ll unsigned long long 4 | #define FOR(i, a, b) for (int i = a; i < b; i++) 5 | #define FORd(i, a, b) for (int i = a; i > b; i--) 6 | #define ff first 7 | #define ss second 8 | #define reset(x) memset(x, 0, sizeof x) 9 | #define sz(x) x.size() 10 | #define pb push_back 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | 17 | ll x; 18 | cin >> x; 19 | FOR(i, 1, x + 1) 20 | { 21 | ll n = i; 22 | ll cr = ((n * n) * (n * n - 1)) / 2; 23 | cr -= 4 * (n - 1) * (n - 2); 24 | cout << cr << endl; 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /java/rituraj-iter/rituraj-iter_missing_number.java: -------------------------------------------------------------------------------- 1 | // You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 2 | // https://cses.fi/problemset/task/1083/ 3 | import java.util.Scanner; 4 | public class missingnumber { 5 | public static void main(String[] args) { 6 | Scanner sc=new Scanner(System.in); 7 | long n=sc.nextLong(); 8 | long b=0,d; 9 | for(long i=1;i 0): 16 | 17 | 18 | if (y & 1): 19 | res = (res * x) % p 20 | 21 | y = y >> 1 22 | x = (x * x) % p 23 | 24 | return res 25 | 26 | 27 | def findCount(N): 28 | count = power(2, N, mod) 29 | return count 30 | 31 | if __name__ == '__main__': 32 | N = int(input()) 33 | print(findCount(N)) 34 | -------------------------------------------------------------------------------- /java/SumanMore/SumanMore_Trailing_zeros.java: -------------------------------------------------------------------------------- 1 | //Your task is to calculate the number of trailing zeros in the factorial n!. 2 | //https://cses.fi/problemset/task/1618 3 | 4 | 5 | import java.util.*; 6 | public class trailingzeroes { 7 | public static void main(String args[]) 8 | { 9 | int cnt=0,i,n; 10 | Scanner sc = new Scanner(System.in); 11 | n = sc.nextInt(); 12 | for( i=5; n/i>=1; i*=5) 13 | { 14 | cnt=cnt+(n/i); 15 | } 16 | 17 | System.out.println(cnt); 18 | } 19 | } 20 | 21 | 22 | //Author:SumanMore/ 23 | // User id: https://cses.fi/user/32360 24 | //Solution:https://cses.fi/problemset/result/1076224/ -------------------------------------------------------------------------------- /java/UtkarshShankar/UtkarshShankar_TrailingZeors.java: -------------------------------------------------------------------------------- 1 | //Your task is to calculate the number of trailing zeros in the factorial n!. 2 | // 3 | //For example, 20!=2432902008176640000 and it has 4 trailing zeros. 4 | //https://cses.fi/problemset/task/1618 5 | import java.util.Scanner; 6 | public class UtkarshShankar_TrailingZeors { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | long n = in.nextLong(); 10 | int c = 0,i=0; 11 | for (i=5;n/i>=1; i*= 5) { 12 | c+=n/i; 13 | } 14 | System.out.println(c); 15 | } 16 | 17 | } 18 | 19 | //author : Utkarsh Shankar 20 | //profile: https://cses.fi/user/32339 -------------------------------------------------------------------------------- /python/iamAbhishekkumar/iamAbhishekkumar_stick_lengths.py: -------------------------------------------------------------------------------- 1 | # user id : 2 | # https://cses.fi/user/32366 3 | # There are n sticks with some lengths. Your task is to modify the sticks so that each stick has the same length. 4 | # You can either lengthen and shorten each stick. Both operations cost x where x is the difference between the new 5 | # and original length. 6 | # What is the minimum total cost? 7 | 8 | # https://cses.fi/problemset/task/1074/ 9 | # author : iamAbhishekkumar 10 | 11 | from statistics import median 12 | 13 | n = int(input()) 14 | l = list(map(int, input().split())) 15 | median = int(median(l)) 16 | cost = 0 17 | for i in l: 18 | cost += abs(median - i) 19 | print(cost) 20 | -------------------------------------------------------------------------------- /java/Abhishek417374/Abhishek417374_missing_number.java: -------------------------------------------------------------------------------- 1 | 2 | //You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 3 | 4 | //https://cses.fi/problemset/task/1083 5 | 6 | //Author:Abhishek417374 7 | 8 | 9 | import java.util.Arrays; 10 | import java.util.Scanner; 11 | public class Abhishek417374_missing_number{ 12 | 13 | public static void main(String[] args) { 14 | Scanner s=new Scanner(System.in); 15 | int i,n=s.nextInt(); 16 | int a[]=new int[n-1]; 17 | for(i=0;i<(n-1);i++) { 18 | a[i]=s.nextInt(); 19 | } 20 | int find=1; 21 | for(int j=2;j<=n;j++) 22 | find+=j-a[j-2]; 23 | System.out.println(find); 24 | 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /python/AkhileshMattam/AkhileshMattam_Weird_Algorithm.py: -------------------------------------------------------------------------------- 1 | #Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows: 2 | # 3→10→5→16→8→4→2→1 3 | #program link :https://cses.fi/problemset/task/1068 4 | #Author : AkhileshMattam 5 | #result link :https://cses.fi/user/32346 6 | n = int(input()) 7 | l1 = [n,] 8 | while n>1: 9 | if n%2==0: 10 | n=int(n/2) 11 | l1.append(n) 12 | else: 13 | n=int((n*3)+1) 14 | l1.append(n) 15 | new = " ".join(map(str,l1)) 16 | print(new) -------------------------------------------------------------------------------- /java/itsjohnty/Trailingzeros.java: -------------------------------------------------------------------------------- 1 | //Your task is to calculate the number of trailing zeros in the factorial n!. 2 | // 3 | // For example, 20!=2432902008176640000 and it has 4 trailing zeros. 4 | //Problem Link:https://cses.fi/problemset/task/1618 5 | 6 | //Result: https://cses.fi/problemset/result/1072673/ 7 | //Author: itsjohnty 8 | import java.util.*; 9 | public class TrailingZeroes { 10 | public static void main(String[] args) { 11 | 12 | Scanner in= new Scanner(System.in); 13 | int n=in.nextInt(); 14 | int count=0; 15 | // Dividing n by powers of 5 16 | for(int i=5;n/i>=1;i*=5) 17 | { 18 | count += n / i; 19 | } 20 | System.out.println(count); 21 | } 22 | } -------------------------------------------------------------------------------- /java/RaviKumarPrasad/Raviruler_Trailing_Zero.java: -------------------------------------------------------------------------------- 1 | /*Your task is to calculate the number of trailing zeros in the factorial n!. 2 | 3 | For example, 20!=2432902008176640000 and it has 4 trailing zeros. 4 | 5 | link : https://cses.fi/problemset/task/1618/ 6 | */ 7 | import java.util.Scanner; 8 | public class Raviruler_Trailing_Zero { 9 | public static void main(String[] args) { 10 | Scanner scan=new Scanner(System.in); 11 | int n,zeroes=0,b; 12 | int count=0; 13 | n=scan.nextInt(); 14 | for (int i = 5; n / i >= 1; i *= 5) { 15 | count += n / i; 16 | } 17 | System.out.print(count); 18 | } 19 | 20 | } 21 | //Author: Ravi Kumar Prasad 22 | //Git_hub Id: Raviruler 23 | //cses : https://cses.fi/user/32356/ -------------------------------------------------------------------------------- /java/UtkarshShankar/UtkarshShankar_Weird.java: -------------------------------------------------------------------------------- 1 | /* 2 | Consider an algorithm that takes as input a positive integer n. 3 | If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 4 | */ 5 | //cses.fi/problemset/task/1068 6 | 7 | import java.util.*; 8 | public class UtkarshShankar_Weird { 9 | 10 | public static void main(String[] args) { 11 | Scanner in =new Scanner (System.in); 12 | long n=in.nextLong(); 13 | System.out.print(n + " "); 14 | while (n!=1) 15 | { 16 | if(n%2==0) 17 | n/=2; 18 | else 19 | n=(n*3)+1; 20 | System.out.print(n + " "); 21 | } 22 | } 23 | 24 | } 25 | //author : Utkarsh Shankar 26 | //profile: https://cses.fi/user/32339 -------------------------------------------------------------------------------- /c_plus_plus/ASVKVINAYAK/ASVKVINAYAK_bitstrings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Bit Strings 3 | 4 | Your task is to calculate the number of bit strings of length n. 5 | 6 | For example, if n=3, the correct answer is 8, because the possible bit strings are 000, 001, 010, 011, 100, 101, 110, and 111. 7 | 8 | Question link : https://cses.fi/problemset/task/1617 9 | Profile Link :https://cses.fi/user/32376 10 | Author: ASVKVINAYAK 11 | 12 | */ 13 | 14 | 15 | #include 16 | #include 17 | using namespace std; 18 | int main() 19 | { 20 | long long int n,s=1,i; 21 | cin>>n; 22 | for(i=1;i<=n;++i) 23 | { 24 | s= (s*2)%1000000007; 25 | } 26 | cout< 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | int trailingZero(long long n) 14 | { 15 | int x = 5, zero = 0; 16 | while (n / x != 0) 17 | { 18 | zero += n / x; 19 | x *= 5; 20 | } 21 | return zero; 22 | } 23 | 24 | int main() 25 | { 26 | long long n; 27 | cin >> n; 28 | cout << trailingZero(n); 29 | 30 | return 0; 31 | } 32 | 33 | //author: goel5 34 | //Solution: https://cses.fi/problemset/result/1066999/ 35 | -------------------------------------------------------------------------------- /python/pritam047/pritam047_weird_algorithm.py: -------------------------------------------------------------------------------- 1 | # USER ID 2 | # https://cses.fi/user/32269 3 | # PROBLEM NUMBER 4 | # https://cses.fi/problemset/task/1068/ 5 | # QUESTION 6 | #Consider an algorithm that takes as input a positive integer n. 7 | # If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 8 | # The algorithm repeats this, until n is one. 9 | # For example, the sequence for n=3 is as follows: 10 | # 3→10→5→16→8→4→2→1 11 | 12 | # Your task is to simulate the execution of the algorithm for a given value of n. 13 | n= int(input()) 14 | print(n,end=" ") 15 | while(n!=1): 16 | if(n%2==0): 17 | n=n//2 18 | else: 19 | n=n*3+1 20 | print(n,end=" ") 21 | -------------------------------------------------------------------------------- /java/aadityamittal/aadityamittal_TrailingZeros.java: -------------------------------------------------------------------------------- 1 | /* 2 | Your task is to calculate the number of trailing zeros in the factorial n!. 3 | 4 | For example, 20!=2432902008176640000 and it has 4 trailing zeros. 5 | 6 | https://cses.fi/problemset/task/1618/ 7 | */ 8 | 9 | 10 | 11 | import java.util.*; 12 | 13 | public class TrailingZeros 14 | { 15 | public static void main(String[] args) 16 | { 17 | Scanner sc = new Scanner(System.in); 18 | int n = sc.nextInt(); 19 | int total = 0; 20 | for (int i = 5; n / i >= 1; i *= 5) 21 | { 22 | total += n / i; 23 | } 24 | System.out.println(total); 25 | } 26 | } 27 | 28 | 29 | /*author:aadityamittal 30 | https://cses.fi/user/32817 31 | */ -------------------------------------------------------------------------------- /java/aadityamittal/aadityamittal_BitStrings.java: -------------------------------------------------------------------------------- 1 | /* 2 | Your task is to calculate the number of bit strings of length n. 3 | 4 | For example, if n=3, the correct answer is 8, because the possible bit strings are 5 | 000, 001, 010, 011, 100, 101, 110, and 111. 6 | 7 | https://cses.fi/problemset/task/1617/ 8 | 9 | */ 10 | 11 | import java.util.Scanner; 12 | class BitStrings{ 13 | public static void main(String[] args) 14 | { 15 | int mod = (int)Math.pow(10,9)+7; 16 | Scanner sc = new Scanner(System.in); 17 | int n = sc.nextInt(); 18 | int p = 1; 19 | while(n-->0){ 20 | p=(p*2)%mod; 21 | } 22 | System.out.println(p); 23 | 24 | }} 25 | 26 | /* 27 | author:aadityamittal 28 | https://cses.fi/user/32817 29 | */ -------------------------------------------------------------------------------- /java/adarsh1405/adarsh1405_weird_algorithm.java: -------------------------------------------------------------------------------- 1 | 2 | // Question 3 | // Consider an algorithm that takes as input a positive integer n. 4 | // If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 5 | 6 | 7 | // link :- https://cses.fi/problemset/task/1068 8 | 9 | // author : Adarsh Padhi 10 | 11 | import java.util.*; 12 | public class adarsh1405_weird_algorithm 13 | { 14 | public static void main(String[] args) { 15 | Scanner sc= new Scanner(System.in); 16 | long n = sc.nextLong(); 17 | System.out.print(n+" "); 18 | while(n!=1){ 19 | if(n%2==0) 20 | n/=2; 21 | else 22 | n=(n*3)+1; 23 | System.out.print(n+" "); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/swetamukherjee/swetamukherjee_TrailingZeros.java: -------------------------------------------------------------------------------- 1 | /* 2 | Your task is to calculate the number of trailing zeros in the factorial n!. 3 | 4 | For example, 20!=2432902008176640000 and it has 4 trailing zeros. 5 | 6 | https://cses.fi/problemset/task/1618/ 7 | */ 8 | 9 | 10 | 11 | import java.util.*; 12 | 13 | public class TrailingZeros 14 | { 15 | public static void main(String[] args) 16 | { 17 | Scanner sc = new Scanner(System.in); 18 | int n = sc.nextInt(); 19 | int total = 0; 20 | for (int i = 5; n / i >= 1; i *= 5) 21 | { 22 | total += n / i; 23 | } 24 | System.out.println(total); 25 | } 26 | } 27 | 28 | 29 | /*author: swetamukherjee 30 | https://cses.fi/user/32972 31 | */ -------------------------------------------------------------------------------- /python/nishantc7/nishantc7_playlists.py: -------------------------------------------------------------------------------- 1 | # Playlist : You are given a playlist of a radio station since its establishment. The playlist has a total of n songs. 2 | # https://cses.fi/problemset/task/1141/ 3 | 4 | 5 | from collections import defaultdict 6 | n = int(input()) 7 | a = [int(x) for x in input().split()] 8 | index = defaultdict(lambda : 0) 9 | ans = 0 10 | j = 0 11 | 12 | for i in range(n): 13 | 14 | # Update j based on previous 15 | # occurrence of a[i] 16 | j = max(index[a[i]], j) 17 | # Update ans to store maximum 18 | # length of subarray 19 | ans = max(ans, i - j + 1) 20 | index[a[i]] = i + 1 21 | i += 1 22 | 23 | # Return final ans 24 | print(ans) 25 | 26 | # author : nishantc7 27 | # profile : https://cses.fi/user/32680 -------------------------------------------------------------------------------- /python/belikesayantan/belikesayantan_subarray_sum.py: -------------------------------------------------------------------------------- 1 | # author: https://cses.fi/user/32392 2 | # @belikesayantan 3 | 4 | 5 | ''' 6 | Subarray Sums I : https://cses.fi/problemset/task/1660/ 7 | Problem: 8 | Given an array of n positive integers, your task is to count the number of subarrays having sum x. 9 | ''' 10 | from collections import defaultdict 11 | 12 | _, x = (int(x) for x in input().split()) 13 | arr = [int(x) for x in input().split()] 14 | 15 | count, curr_sum = 0, 0 16 | sums_count = defaultdict(int) 17 | 18 | for i in arr: 19 | curr_sum += i 20 | if curr_sum == x: 21 | count += 1 22 | if curr_sum - x in sums_count: 23 | count += sums_count[curr_sum - x] 24 | sums_count[curr_sum] += 1 25 | 26 | print(count) 27 | -------------------------------------------------------------------------------- /java/debashishsamantara/debashishsamantara_TrailingZeros.java: -------------------------------------------------------------------------------- 1 | //Your task is to calculate the number of trailing zeros in the factorial n!. 2 | //For example, 20!=2432902008176640000 and it has 4 trailing zeros. 3 | 4 | //Author : debashishsamantara 5 | //Profile : https://cses.fi/user/32389 6 | //Ques. link : https://cses.fi/problemset/task/1618 7 | 8 | 9 | import java.util.Scanner; 10 | public class debashishsamantara_TrailingZeros { 11 | public static void main(String[] args) { 12 | int c=0; 13 | Scanner sc = new Scanner(System.in); 14 | int x = sc.nextInt(); 15 | for(int i=5; x/i>=1; i*=5) 16 | { 17 | c+=x/i; 18 | } 19 | System.out.println(c); 20 | sc.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /c_plus_plus/SouravReal/SouravReal_Two_Knights.cpp: -------------------------------------------------------------------------------- 1 | //Question - Your task is to count for k=1,2,…,n the number of ways two knights can be placed on a k×k chessboard so that they do not attack each other. 2 | //link - https://cses.fi/problemset/task/1072 3 | 4 | 5 | 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | long long n; 13 | cin>>n; 14 | for(long long i = 1;i<=n;i++) 15 | { 16 | long long total = (i*i)*(i*i-1)/2 ; 17 | long long attack = 4*(i-1)*(i-2) ; 18 | cout<=5) 14 | { 15 | n=n/5; 16 | l=l+n; 17 | } 18 | System.out.println(l); 19 | sc.close(); 20 | } 21 | } 22 | 23 | 24 | //author: RijulDas 25 | //result link:https://cses.fi/problemset/result/1082987/ 26 | //user id: https://cses.fi/user/32349 27 | -------------------------------------------------------------------------------- /java/amohapatra123/amohapatra123_missing_number.java: -------------------------------------------------------------------------------- 1 | /*You are given all numbers between 1,2,…,n except one. 2 | Your task is to find the missing number. 3 | */ 4 | //https://cses.fi/problemset/task/1083/ 5 | 6 | 7 | //author:amohapatra123 8 | 9 | import java.util.Scanner; 10 | public class amohapatra123_missing_number{ 11 | public static void main(String args[]){ 12 | Scanner y= new Scanner(System.in); 13 | int n=y.nextInt(); 14 | int arr[]= new int[n-1]; 15 | for(int i=0;ib[j]: 17 | j+=1 18 | else: 19 | c+=1 20 | j+=1 21 | i+=1 22 | print(c) 23 | -------------------------------------------------------------------------------- /java/Palak Srivastava/Palak-Srivastava_MissingNumber.java: -------------------------------------------------------------------------------- 1 | /* You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 2 | Link: https://cses.fi/problemset/task/1083/ 3 | */ 4 | 5 | import java.util.*; 6 | public class MissingNumber { 7 | 8 | public static void main(String[] args) { 9 | Scanner in=new Scanner(System.in); 10 | int n,i,s=0,s1=0; 11 | n=in.nextInt(); 12 | int a[]=new int[n]; 13 | for(i=0;i int: 15 | mid = n // 2 16 | return sum(arr[mid + n % 2:]) - sum(arr[: mid]) 17 | 18 | 19 | if __name__ == "__main__": 20 | print(sticklengths(int(input()), sorted([int(x) for x in input().split()]))) -------------------------------------------------------------------------------- /python/Ashis-007/Ashis-007_repetitions.py: -------------------------------------------------------------------------------- 1 | # Question 2 | # You are given a DNA sequence: a string consisting of characters A, C, G, and T. 3 | # Your task is to find the longest repetition in the sequence. 4 | # This is a maximum-length substring containing only one type of character. 5 | 6 | # Link 7 | # https://cses.fi/problemset/task/1069 8 | 9 | strings = list(input()) 10 | best = 0 11 | curr = 0 12 | 13 | for i in range(len(strings)): 14 | if strings[i] != strings[i-1]: 15 | best = best if best > curr else curr 16 | curr = 0 17 | curr += 1 18 | 19 | best = best if best > curr else curr 20 | print(best) 21 | 22 | # author: Ashis-007 23 | # profile: https://cses.fi/user/32353 24 | # solution: https://cses.fi/problemset/result/1066368/ 25 | 26 | 27 | -------------------------------------------------------------------------------- /c_plus_plus/akbar1214/akbar1214_IncreasingArray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define sc(x) scanf("%d", &x) 3 | #define ll long long 4 | #define FOR(i, a, b) for (int i = a; i < b; i++) 5 | #define FORd(i, a, b) for (int i = a; i > b; i--) 6 | #define ff first 7 | #define ss second 8 | #define reset(x) memset(x, 0, sizeof x) 9 | #define sz(x) x.size() 10 | #define pb push_back 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | 17 | int n; 18 | cin >> n; 19 | std::vector v(n); 20 | for (int &x : v) 21 | cin >> x; 22 | ll ans = 0; 23 | FOR(i, 1, n) 24 | { 25 | if (v[i] < v[i - 1]) 26 | { 27 | ans += (v[i - 1] - v[i]); 28 | v[i] = v[i - 1]; 29 | } 30 | } 31 | cout << ans << endl; 32 | } -------------------------------------------------------------------------------- /python/belikesayantan/belikesayantan_Distinct_Numbers.py: -------------------------------------------------------------------------------- 1 | # author: https://cses.fi/user/32392 2 | # @belikesayantan 3 | 4 | ''' Distinct Numbers - https://cses.fi/problemset/task/1621 5 | You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 6 | ''' 7 | from typing import List 8 | from collections import Counter 9 | 10 | def distinct(n: int, arr: List[int]): 11 | """Distinct Numbers in a List 12 | Input: 13 | n: length of the array 14 | arr: List of integers 15 | Output: 16 | unique: Number of unique values in the list 17 | """ 18 | unique = len(Counter(arr).keys()) 19 | return unique 20 | 21 | if __name__ == "__main__": 22 | print(distinct(int(input()), [int(x) for x in input().split()])) -------------------------------------------------------------------------------- /c_plus_plus/stevenbudinata/stevenbudinata_distinct_numbers.cpp: -------------------------------------------------------------------------------- 1 | // Question: 2 | /* 3 | You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 4 | */ 5 | 6 | // link: https://cses.fi/problemset/task/1621/ 7 | 8 | #include 9 | using namespace std; 10 | 11 | int main() { 12 | int n; 13 | map dictionary; 14 | 15 | int ans = 0; 16 | scanf("%d", &n); 17 | 18 | for(int i=0; i=t: 14 | l+=[i] 15 | t+=1 16 | else: 17 | l[b]=i 18 | print(t) 19 | -------------------------------------------------------------------------------- /java/Abhishek417374/Abhishek417374_repetition.java: -------------------------------------------------------------------------------- 1 | 2 | /*You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 3 | import java.util.Scanner;*/ 4 | //https://cses.fi/problemset/task/1069 5 | //Author:Abhishek417374 6 | public class Abhishek417374_repetition{ 7 | 8 | public static void main(String[] args) { 9 | Scanner S=new Scanner(System.in); 10 | String s=S.next().toUpperCase(); 11 | int count=1,max=1; 12 | for(int i=1;i { 18 | n = parseInt(X); 19 | readline.close(); 20 | }); 21 | 22 | readline.on("close", () => { 23 | let count = 0; 24 | for (let i = 5; n / i >= 1; i = i * 5) { 25 | count = count + Math.floor(n / i); 26 | } 27 | console.log(count); 28 | }); 29 | -------------------------------------------------------------------------------- /python/belikesayantan/belikesayantan_sum_of_two_values.py: -------------------------------------------------------------------------------- 1 | # author: https://cses.fi/user/32392 2 | # @belikesayantan 3 | 4 | ''' Sum of Two Values - https://cses.fi/problemset/task/1640 5 | You are given an array of n integers, and your task is to find two values (at distinct positions) whose sum is x. 6 | ''' 7 | 8 | def TwoSum(n: 'int length of the array', x: 'int target', arr: 'list of integers') -> str: 9 | temp = dict() 10 | for i in range(n): 11 | curr = arr[i] 12 | if x - curr in temp: 13 | return "{} {}".format(i + 1, temp[x - curr] + 1) 14 | else: 15 | temp[curr] = i 16 | return "IMPOSSIBLE" 17 | 18 | 19 | 20 | if __name__ == "__main__": 21 | print(TwoSum(*(int(x) for x in input().split()), [int(x) for x in input().split()])) 22 | -------------------------------------------------------------------------------- /java/itsjohnty/Repetition.java: -------------------------------------------------------------------------------- 1 | /*You are given a DNA sequence: a string consisting of characters A, C, G, and T. 2 | Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character.*/ 3 | /*Example 4 | Input: 5 | ATTCGGGA 6 | Output: 7 | 3 8 | link: https://cses.fi/problemset/task/1069 9 | */ 10 | import java.util.Scanner; 11 | public class repetition{ 12 | public static void main(String[] args) { 13 | Scanner scan=new Scanner(System.in); 14 | String s=scan.nextLine().toLowerCase(); 15 | int a=s.length(),b=1,c=1; 16 | for (int i=1;i 8 | #include 9 | using namespace std; 10 | #define ios ios::sync_with_stdio(false);cin.tie(NULL) 11 | #define endl "\n" 12 | #define ll long long 13 | const long Mod=1e9+7; 14 | 15 | void solve() 16 | { 17 | ll n; 18 | cin>>n; 19 | ll ans=1; 20 | for(int i=0;i>tt; 29 | while(tt--) 30 | { 31 | solve(); 32 | } 33 | return 0; 34 | } 35 | 36 | 37 | //author:saurabh_nikam -------------------------------------------------------------------------------- /java/Prakashpathak984/Prakashpathak984_MissingNumber.java: -------------------------------------------------------------------------------- 1 | // You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 2 | // Link : https://cses.fi/problemset/task/1083 3 | 4 | import java.util.Scanner; 5 | public class Prakashpathak984_MissingNumber 6 | { 7 | public static void main(String args[]) 8 | { 9 | Scanner sc=new Scanner(System.in); 10 | int n=sc.nextInt(); 11 | int a[]=new int[n]; 12 | for(int i=0;i 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int n,c,count=1; 13 | vector a; 14 | cin>>n; 15 | for(int x=0;x>c; 18 | a.push_back(c); 19 | } 20 | sort(a.begin(),a.end()); 21 | vector::iterator it; 22 | for(it=a.begin();it!=a.end()-1;++it) 23 | { 24 | if(n==1) 25 | {cout<<"1"; 26 | break;} 27 | else 28 | if(*it!=*(it+1)) 29 | count+=1; 30 | } 31 | cout< 11 | using namespace std; 12 | 13 | int main() 14 | { 15 | long long n; 16 | cin>>n; 17 | while(n!=1) 18 | { 19 | cout< 2 | #define sc(x) scanf("%d", &x) 3 | #define ll long long 4 | #define FOR(i, a, b) for (int i = a; i < b; i++) 5 | #define FORd(i, a, b) for (int i = a; i > b; i--) 6 | #define ff first 7 | #define ss second 8 | #define reset(x) memset(x, 0, sizeof x) 9 | #define sz(x) x.size() 10 | #define pb push_back 11 | 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | 17 | int n; 18 | cin >> n; 19 | if (n == 2 || n == 3) 20 | { 21 | cout << "NO SOLUTION" << endl; 22 | return 0; 23 | } 24 | 25 | for (int i = 2; i <= n; i += 2) 26 | { 27 | cout << i << " "; 28 | } 29 | for (int i = 1; i <= n; i += 2) 30 | { 31 | cout << i << " "; 32 | } 33 | cout << endl; 34 | return 0; 35 | } -------------------------------------------------------------------------------- /python/bikash1317/bikash1317_Distinct_Numbers.py: -------------------------------------------------------------------------------- 1 | # User ID : https://cses.fi/user/32480 2 | 3 | # Problem Number : https://cses.fi/problemset/task/1621/ 4 | 5 | # Author : bikash1317 6 | 7 | # Questions : 8 | # You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 9 | 10 | # Input 11 | 12 | # The first input line has an integer n: the number of values. 13 | 14 | # The second line has n integers x1,x2,…,xn. 15 | 16 | 17 | 18 | n = int(input()) 19 | 20 | ele = input() 21 | e = ele.split() 22 | 23 | for i in range(0, len(e)): 24 | e[i] = int(e[i]) 25 | 26 | 27 | e.sort() 28 | count = 0 29 | flag = 0 30 | for i in range(n): 31 | if(i < n-1 and e[i] == e[i+1]): 32 | i = i + 1 33 | else: 34 | count = count + 1 35 | 36 | print(count) 37 | -------------------------------------------------------------------------------- /java/ZeoShark/Zeoshark_TrailingZeroes.java: -------------------------------------------------------------------------------- 1 | //Trailing Zeroes 2 | //Your task is to calculate the number of trailing zeros in the factorial n!. 3 | // 4 | // For example, 20!=2432902008176640000 and it has 4 trailing zeros. 5 | //Problem Link:https://cses.fi/problemset/task/1618 6 | 7 | //Result: https://cses.fi/problemset/result/1072678/ 8 | //Author: souravbera 9 | import java.util.*; 10 | public class Zeoshark_TrailingZeroes { 11 | public static void main(String[] args) { 12 | 13 | Scanner in= new Scanner(System.in); 14 | int n=in.nextInt(); 15 | //Initialising count 16 | //trailing Zeroes 17 | int count=0; 18 | 19 | // Keep dividing n by powers of 5 20 | for(int i=5;n/i>=1;i*=5) 21 | { 22 | count += n / i; 23 | } 24 | System.out.println(count); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /java/rituraj-iter/rituraj-iter_increasing_array.java: -------------------------------------------------------------------------------- 1 | // You are given an array of n integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 2 | // On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 3 | // https://cses.fi/problemset/task/1094/ 4 | import java.util.Scanner; 5 | public class Increasing_Array { 6 | public static void main(String[] args){ 7 | Scanner sc=new Scanner(System.in); 8 | int n=sc.nextInt(); 9 | int a=sc.nextInt(); 10 | long c=0; 11 | for(int i=1;i { 24 | n = parseInt(X); 25 | 26 | for (let i = 1; i <= n; i++) { 27 | console.log(TwoKnights(i)); 28 | } 29 | readline.close(); 30 | }); 31 | -------------------------------------------------------------------------------- /python/Prerna2001/Prerna2001_sumOfTwoValues.py: -------------------------------------------------------------------------------- 1 | # You are given an array of n integers, and your task is to find two values (at distinct positions) whose sum is x. 2 | #https://cses.fi/problemset/task/1640 3 | 4 | def sumOfTwo(array, targetSum): 5 | nums = {} 6 | for num in array: 7 | if targetSum - num in nums: 8 | return [(array.index(targetSum - num))+1, (array.index(num))+1] 9 | else: 10 | nums[num] = True 11 | 12 | size, target_sum = input().split() 13 | l = input() 14 | array = list(map(int, l.split(' '))) 15 | 16 | lst = sumOfTwo(array, int(target_sum)) 17 | 18 | if len(lst) == 0: 19 | print("IMPOSSIBLE") 20 | else: 21 | for i in range(len(lst)): 22 | print(lst[i], end=" ") 23 | 24 | # author : PrernaBabber 25 | # https://cses.fi/user/32267 -------------------------------------------------------------------------------- /java/Palak Srivastava/Palak-Srivastava_DistinctNumbers.java: -------------------------------------------------------------------------------- 1 | //You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 2 | //https://cses.fi/problemset/task/1621 3 | 4 | 5 | import java.util.*; 6 | public class DistinctNumbers { 7 | 8 | public static void main(String[] args) { 9 | Scanner in=new Scanner(System.in); 10 | int n,i; 11 | n=in.nextInt(); 12 | int a[]=new int[n]; 13 | for(i=0;i1) 11 | { 12 | System.out.print(n+" "); 13 | n=n%2==0?n/2:n*3+1; 14 | } 15 | System.out.print(n); 16 | } 17 | } 18 | 19 | 20 | //AUTHOR-Sh161101 21 | //cses profile-https://cses.fi/user/32657 -------------------------------------------------------------------------------- /java/ShrutiMallick/ShrutiMallick_DiceCombination.java: -------------------------------------------------------------------------------- 1 | /*Your task is to count the number of ways to construct sum n by throwing a dice one or more times. 2 | Each throw produces an outcome between 1 and 6. 3 | link: https://cses.fi/problemset/task/1633/ 4 | */ 5 | import java.util.*; 6 | public class DiceCombination { 7 | static final int MD=1000000007; 8 | public static void main(String[] args) { 9 | // TODO Auto-generated method stub 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(); 12 | int []a=new int[n+1]; 13 | a[0]=1; 14 | for(int i=1;i<=n;i++) { 15 | long x=0; 16 | for(int j=i-1;j>=i-6 && j>=0;j--) { 17 | x+=a[j]; 18 | }a[i]=(int)(x % MD); 19 | } 20 | System.out.println(a[n]); 21 | } 22 | } 23 | 24 | //author:Shruti 25 | //profile link:https://cses.fi/user/32358 -------------------------------------------------------------------------------- /java/ankitsaebby/ankitsaebbyTrailingZeros.java: -------------------------------------------------------------------------------- 1 | //Your task is to calculate the number of trailing zeros in the factorial n!. 2 | // 3 | //For example, 20!=2432902008176640000 and it has 4 trailing zeros. 4 | 5 | //author:ankitsaebby 6 | 7 | import java.util.*; 8 | 9 | public class ankitsaebbyTrailingZeros { 10 | 11 | public static void main (String[] args) 12 | { 13 | Scanner s=new Scanner(System.in); 14 | int n = s.nextInt(); 15 | System.out.println( findTrailingZeros(n)); 16 | } 17 | public static int findTrailingZeros(int n) 18 | { 19 | 20 | int count = 0; 21 | for (int i = 5; n / i >= 1; i *= 5) 22 | count += n / i; 23 | 24 | return count; 25 | } 26 | } 27 | 28 | 29 | 30 | //cses id- https://cses.fi/user/32538 31 | -------------------------------------------------------------------------------- /python/nishantc7/nishantc7_apartments.py: -------------------------------------------------------------------------------- 1 | # Apartments : There are n applicants and m free apartments. Your task is to distribute the apartments so that as many applicants as possible will get an apartment. 2 | #https://cses.fi/problemset/task/1084 3 | 4 | 5 | m, n, k = map(int,input().split()) 6 | desired_size = list(map(int,input().split())) 7 | avail_size = list(map(int,input().split())) 8 | count = 0 9 | desired_size.sort() 10 | avail_size.sort() 11 | i, j = 0, 0 12 | while(i < n and j < m): 13 | if (abs(avail_size[i] - desired_size[j]) <= k): 14 | count += 1 15 | i += 1 16 | j += 1 17 | 18 | elif (avail_size[i] < desired_size[j]): 19 | i += 1 20 | 21 | else: 22 | j += 1 23 | 24 | print(count) 25 | 26 | # author : nishantc7 27 | # profile : https://cses.fi/user/32680 28 | -------------------------------------------------------------------------------- /python/Ashis-007/Ashis-007_increasing_array.py: -------------------------------------------------------------------------------- 1 | # Question 2 | # You are given an array of n integers. 3 | # You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 4 | # On each turn, you may increase the value of any element by one. 5 | # What is the minimum number of turns required? 6 | 7 | # Link: https://cses.fi/problemset/task/1094 8 | 9 | n = int(input()) 10 | numbers = input().split() 11 | numbers = list(map(int, numbers)) 12 | 13 | total = 0 14 | m = numbers[0] 15 | 16 | for i in range(n-1): 17 | if numbers[i] > numbers[i+1]: 18 | total += abs(numbers[i] - numbers[i+1]) 19 | numbers[i+1] = numbers[i] 20 | 21 | print(total) 22 | 23 | # author: Ashis-007 24 | # profile: https://cses.fi/user/32353 25 | # Solution: https://cses.fi/problemset/result/1067119/ -------------------------------------------------------------------------------- /python/bikash1317/bikash1317_Weird_Algorithm.py: -------------------------------------------------------------------------------- 1 | # User ID : https://cses.fi/user/32480 2 | # Problem Number : https://cses.fi/problemset/task/1068/ 3 | 4 | # Author : bikash1317 5 | 6 | # Question: 7 | # Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows: 8 | # 3→10→5→16→8→4→2→1 9 | 10 | # Your task is to simulate the execution of the algorithm for a given value of n. 11 | 12 | 13 | number = int (input()) 14 | print (int (number)) 15 | while(number != 1 and number > 0): 16 | if(number % 2 == 0): 17 | number = number/2 18 | else: 19 | number = (number*3) + 1 20 | 21 | print (int (number)) -------------------------------------------------------------------------------- /java/Prakashpathak984/Prakashpathak984_WeirdAlgorithm.java: -------------------------------------------------------------------------------- 1 | // Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. 2 | // Link : https://cses.fi/problemset/task/1068 3 | 4 | import java.util.Scanner; 5 | public class Prakashpathak984_WeirdAlgorithm 6 | { 7 | public static void main(String args[]) 8 | { 9 | Scanner sc=new Scanner(System.in); 10 | long n=sc.nextLong(); 11 | sc.close(); 12 | System.out.print(n+" "); 13 | while(n!=1) 14 | { 15 | if(n%2==0) 16 | n/=2; 17 | else 18 | n=(n*3)+1; 19 | System.out.print(n+" "); 20 | } 21 | } 22 | } 23 | 24 | // Author : Prakashpathak984 25 | // CSES Profile Link : https://cses.fi/user/32961 -------------------------------------------------------------------------------- /java/debashishsamantara/debashishsamantara_BitStrings.java: -------------------------------------------------------------------------------- 1 | //Author : debashishsamantara 2 | //Profile : https://cses.fi/user/32389 3 | //Your task is to calculate the number of bit strings of length n.For example, if n=3, the correct answer is 8, because the possible bit strings are 000, 001, 010, 011, 100, 101, 110, and 111. 4 | //Ques .link : https://cses.fi/problemset/task/1617 5 | 6 | 7 | import java.util.Scanner; 8 | public class debashishsamantara_BitStrings { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int mod = 1000000007; 12 | int k = 1; 13 | int n = sc.nextInt(); 14 | for(int i=n; i>0; i--) 15 | { 16 | k = (k*2)%mod; 17 | } 18 | System.out.println(k); 19 | sc.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /java/jigyasa-samal/jigyasa-samal_DistinctNumber.java: -------------------------------------------------------------------------------- 1 | /* 2 | You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 3 | 4 | */ 5 | 6 | import java.util.*; 7 | public class DistinctNumber { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | 11 | int count = 1; 12 | int n = sc.nextInt(); 13 | int arr[] = new int[n]; 14 | for (int i = 0; i < n; i++) 15 | arr[i] = sc.nextInt(); 16 | Arrays.sort(arr); 17 | 18 | for (int j = 0; j < n - 1; j++) { 19 | if (arr[j] != arr[j + 1]) 20 | count++; 21 | 22 | } 23 | System.out.println(count); 24 | 25 | } 26 | } 27 | 28 | /* 29 | author : Jigyasa-Samal 30 | profile : https://cses.fi/user/32531 31 | */ 32 | -------------------------------------------------------------------------------- /c_plus_plus/psib0t/psib0t_RemovingDigits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | // #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | int main(){ 9 | int n, temp; 10 | cin >> n; 11 | vector minStepsVec; 12 | if (n >= 1 && n <= 9) { 13 | cout << 1 << endl; 14 | return 0; 15 | } 16 | for(int i = 0; i <= 9; i++) 17 | minStepsVec.push_back(1); 18 | for (int i = 10; i <= n; i++){ 19 | temp = i; 20 | minStepsVec.push_back(INT_MAX - 8); 21 | while (temp){ 22 | minStepsVec[i] = min(minStepsVec[i], minStepsVec[i - temp % 10] + 1); 23 | temp /= 10; 24 | } 25 | 26 | } 27 | 28 | cout << minStepsVec[n] << endl; 29 | // Author: psib0t 30 | // Profile: https://cses.fi/user/26439 31 | } -------------------------------------------------------------------------------- /java/debashishsamantara/debashishsamantara_TwoKnights.java: -------------------------------------------------------------------------------- 1 | // Your task is to count for k=1,2,…,n the number of ways two knights can be placed on a k×k chessboard so that they do not attack each other. 2 | // https : //cses.fi/problemset/task/1072 3 | // Author : debashishsamantara 4 | // Profile : https://cses.fi/user/32389 5 | 6 | 7 | import java.util.*; 8 | public class debashishsamantara_TwoKnights{ 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | long n = sc.nextLong(); 12 | for(long i=1; i<=n; i++){ 13 | System.out.println(TwoKnights(i)); 14 | sc.close(); 15 | } 16 | } 17 | static long TwoKnights(long n) 18 | { 19 | long th = 4*(n-1)*(n-2); 20 | long pos = (n*n*(n*n-1))/2; 21 | return pos-th; 22 | } 23 | } -------------------------------------------------------------------------------- /c_plus_plus/ASVKVINAYAK/ASVKVINAYAK_repetation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Repetitions 3 | 4 | You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 5 | 6 | Question link : https://cses.fi/problemset/task/1069 7 | Profile Link :https://cses.fi/user/32376 8 | Author: ASVKVINAYAK 9 | 10 | */ 11 | 12 | #include 13 | using namespace std; 14 | int main() 15 | { 16 | string ss; 17 | cin >> ss; 18 | long long int c=1,i,s=0; 19 | for ( i=0;ic) 29 | { 30 | c=s; 31 | } 32 | } 33 | cout < 9 | using namespace std; 10 | 11 | int main() { 12 | int n; 13 | map dictionary; 14 | 15 | int ans = 0; 16 | scanf("%d", &n); 17 | 18 | for(int i=0; i 7 | using namespace std; 8 | int main() 9 | { 10 | long x; 11 | cin>>x; 12 | cout<max) 18 | max=c; 19 | } 20 | System.out.println(max); 21 | } 22 | } 23 | // author: rahulkumarjha21 24 | // profile: https://cses.fi/user/32483 -------------------------------------------------------------------------------- /nodejs/itspiyush01/itsPiyush01_WeirdAlgorithm.js: -------------------------------------------------------------------------------- 1 | /* 2 | Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. 3 | 4 | link : https://cses.fi/problemset/task/1068 5 | 6 | author : Piyush Ranjan 7 | Profile: https://cses.fi/user/32379 8 | */ 9 | 10 | const readline = require("readline").createInterface({ 11 | input: process.stdin, 12 | output: process.stdout, 13 | }); 14 | 15 | readline.question("", (n) => { 16 | console.log(n); 17 | 18 | while (n !== 1 && n>1) { 19 | if (n % 2 === 0) { 20 | n /= 2; 21 | console.log(n); 22 | } else { 23 | n *= 3; 24 | n += 1; 25 | 26 | console.log(n); 27 | } 28 | } 29 | 30 | readline.close(); 31 | }); 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /c_plus_plus/subhamsagar524/subhamsagar524_distinct_numbers.cpp: -------------------------------------------------------------------------------- 1 | // Distinct Numbers 2 | // https://cses.fi/problemset/task/1621 3 | 4 | /* Input n and n numbers list, 5 | task: calculate the number of distinct values in the list. 6 | */ 7 | 8 | // submission: https://cses.fi/paste/8fa7d3f03fa9e89a10bf5b/ 9 | 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | int n, res = 0; 17 | cin >> n; 18 | 19 | long long arr[n]; 20 | for(int i = 0; i < n; i++) 21 | cin >> arr[i]; 22 | 23 | sort(arr, arr+n); 24 | 25 | for(int i = 0; i < n; i++) 26 | { 27 | while (i < n - 1 && arr[i+1] == arr[i]) 28 | i++; 29 | res++; 30 | } 31 | 32 | cout << res << endl; 33 | 34 | return 0; 35 | } 36 | 37 | // author: Subham Sagar Paira 38 | // profile: https://cses.fi/user/32482 39 | -------------------------------------------------------------------------------- /nodejs/itspiyush01/itsPiyush01_MissingNumber.js: -------------------------------------------------------------------------------- 1 | /* 2 | You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 3 | Link : https://cses.fi/problemset/task/1083 4 | Author : Piyush Ranjan 5 | GitHub_Id : itsPiyush01 6 | Profile : https://cses.fi/user/32379 7 | */ 8 | 9 | const readline = require("readline"); 10 | const rl = readline.createInterface({ 11 | input: process.stdin, 12 | output: process.stdout, 13 | }); 14 | let arr = []; 15 | var n; 16 | rl.question("", (X) => { 17 | n = X; 18 | rl.on("line", (numbs) => { 19 | arr.push(numbs.split(" ")); 20 | rl.close(); 21 | }); 22 | }); 23 | 24 | rl.on("close", () => { 25 | arr = arr.join().split(","); 26 | let xor = 0; 27 | for (let i = 0; i < n - 1; i++) { 28 | xor ^= arr[i]; 29 | xor = xor ^ (i + 1); 30 | } 31 | xor = xor ^ n; 32 | console.log(xor); 33 | }); 34 | -------------------------------------------------------------------------------- /java/ShrutiMallick/ShrutiMallick_subarraydivisibilty.java: -------------------------------------------------------------------------------- 1 | /*Given an array of n integers, your task is to count 2 | * the number of subarrays where the sum of values is divisible by n. 3 | link:https://cses.fi/problemset/task/1662 4 | */ 5 | import java.util.*; 6 | public class Subarray { 7 | 8 | public static void main(String[] args) { 9 | // TODO Auto-generated method stub 10 | Scanner sc=new Scanner(System.in); 11 | int n=sc.nextInt(); 12 | int []a=new int[n]; 13 | a[0]=1; 14 | for(int i=0,s=0;i>n; 12 | if (n==1){ 13 | printf("1"); 14 | }else if(n<4){ 15 | printf("NO SOLUTION"); 16 | }else if (n==4){ 17 | printf("3 1 4 2"); 18 | }else{ 19 | for (long j = n - 1 ; j > 0; j -= 2){ 20 | printf("%d" , j); 21 | printf(" "); 22 | } 23 | for (long i = n; i > 0; i -= 2){ 24 | printf("%d" , i); 25 | printf(" "); 26 | } 27 | } 28 | return 0; 29 | } 30 | 31 | //author : Pratik Sonal 32 | //CSES profile : https://cses.fi/user/34290 33 | //solution : https://cses.fi/problemset/result/1141621/ -------------------------------------------------------------------------------- /python/SoumyaKB96/SoumyaKB96_Subarray_Divisibility.py: -------------------------------------------------------------------------------- 1 | #QN. Given an array of n integers, your task is to count the number of 2 | # subarrays where the sum of values is divisible by n 3 | 4 | # Link - https://cses.fi/problemset/task/1662/ 5 | 6 | def subCount(arr, n): 7 | 8 | mod = [] 9 | for i in range(n + 1): 10 | mod.append(0) 11 | 12 | 13 | csum = 0 14 | for i in range(n): 15 | csum = csum + arr[i] 16 | 17 | mod[((csum % n)+n) % n] = mod[((csum % n)+n) % n] + 1 18 | 19 | r= 0 20 | 21 | for i in range(n): 22 | 23 | 24 | if (mod[i] > 1): 25 | r= r + (mod[i]*(mod[i]-1))//2 26 | 27 | 28 | r = r + mod[0] 29 | 30 | return r 31 | 32 | 33 | 34 | 35 | n=int(input()) 36 | arr = list(map(int, input().strip().split()))[:n] 37 | print(subCount(arr, n)) 38 | 39 | 40 | #Author - SoumyaKB96 41 | #Profile - https://cses.fi/user/32322 42 | -------------------------------------------------------------------------------- /java/jigyasa-samal/jigyasa-samal_SmallestNumber: -------------------------------------------------------------------------------- 1 | /* 2 | Given an array of n integers, your task is to find for each array position the nearest position to its left having a smaller value. 3 | link : https://cses.fi/problemset/task/1645/ 4 | */ 5 | 6 | import java.util.*; 7 | import java.io.*; 8 | public class SmallestNumber { 9 | 10 | public static void main(String[] args) { 11 | Scanner sc=new Scanner(System.in); 12 | int n=sc.nextInt(); 13 | int []a=new int[n+1]; 14 | for(int i=1;i<=n;i++) { 15 | a[i]=sc.nextInt(); 16 | } 17 | int arr[]=new int[n+1]; 18 | int count=0; 19 | arr[count++]=0; 20 | for(int i=1;i<=n;i++) { 21 | int h=0; 22 | while(a[h=arr[count-1]]>=a[i]) { 23 | count--; 24 | } 25 | System.out.print(h+" "); 26 | arr[count++]=i; 27 | } 28 | } 29 | 30 | } 31 | 32 | /* 33 | author : jigyasa-samal 34 | profile : https://cses.fi/user/32531 35 | */ 36 | -------------------------------------------------------------------------------- /python/nisargsheth/nisargsheth_Number_Spiral.py: -------------------------------------------------------------------------------- 1 | # Question 2 | # A number spiral is an infinite grid whose upper-left square has number 1. Here are the first five layers of the spiral: 3 | 4 | # Your task is to find out the number in row y and column x. 5 | 6 | 7 | # Link 8 | # https://cses.fi/problemset/task/1071 9 | def main(): 10 | t = int(input()) 11 | for t_itr in range(0,t): 12 | y,x = map(int,input().split()) 13 | if(x>y): 14 | if(x%2==1): 15 | print(x*x - y + 1) 16 | else: 17 | x-=1 18 | print(x*x+y) 19 | else: 20 | if(y%2==0): 21 | print(y*y-x+1) 22 | else: 23 | y-=1 24 | print(y*y+x) 25 | main() 26 | 27 | # author: nisargsheth 28 | # profile: https://cses.fi/user/9669 29 | # solution: https://cses.fi/problemset/result/382948/ 30 | -------------------------------------------------------------------------------- /nodejs/itspiyush01/itsPiyush01_Repetitions.js: -------------------------------------------------------------------------------- 1 | /* 2 | You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 3 | * Link :https://cses.fi/problemset/task/1069/ 4 | * Author : Piyush Ranjan 5 | * Profile: https://cses.fi/user/32379 6 | * GitHub_Id: itsPiyush01 7 | */ 8 | 9 | const readline = require("readline").createInterface({ 10 | input: process.stdin, 11 | output: process.stdout, 12 | }); 13 | 14 | readline.question("", (str) => { 15 | let count = 1; 16 | let s = 0; 17 | for (let i = 1; i < str.length; i++) { 18 | if (str[i - 1] == str[i]) { 19 | count++; 20 | } else { 21 | s = Math.max(s, count); 22 | count = 1; 23 | } 24 | } 25 | s = Math.max(s, count); 26 | console.log(s); 27 | 28 | readline.close(); 29 | }); 30 | -------------------------------------------------------------------------------- /python/Prerna2001/Prerna2001_weirdAlgorithm.py: -------------------------------------------------------------------------------- 1 | # Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows: 2 | # 3→10→5→16→8→4→2→1 3 | # Your task is to simulate the execution of the algorithm for a given value of n. 4 | # https://cses.fi/problemset/task/1068 5 | 6 | def weird(num): 7 | while num > 0 : 8 | if num == 1: 9 | print(num) 10 | exit() 11 | if num % 2 ==0: 12 | print(num, end=" ") 13 | num = (int)(num/2) 14 | else: 15 | print(num, end=" " ) 16 | num = (int)(num * 3) + 1 17 | 18 | 19 | num = int(input()) 20 | weird(num) 21 | 22 | # author : PrernaBabber 23 | # https://cses.fi/user/32267 -------------------------------------------------------------------------------- /java/RaviKumarPrasad/Raviruler_Repetition.java: -------------------------------------------------------------------------------- 1 | /*You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character.*/ 2 | /*Example 3 | 4 | Input: 5 | ATTCGGGA 6 | 7 | Output: 8 | 3 9 | 10 | link: https://cses.fi/problemset/task/1069 11 | */ 12 | import java.util.Scanner; 13 | public class Raviruler_Repetition { 14 | public static void main(String[] args) { 15 | Scanner scan=new Scanner(System.in); 16 | String s=scan.nextLine().toLowerCase(); 17 | int a=s.length(),b=1,c=1; 18 | for (int i=1;i max_count: 13 | max_count = count 14 | 15 | return max_count 16 | 17 | 18 | def main(): 19 | n = int(sys.stdin.readline()) 20 | times = [] 21 | 22 | for _ in range(n): 23 | a, b = map(int,sys.stdin.readline().split()) 24 | times.append((int(a), 1)) 25 | times.append((int(b), -1)) 26 | times.sort() 27 | print(max_people(times)) 28 | 29 | if __name__ == "__main__": 30 | main() 31 | 32 | # author : nishantc7 33 | # profile : https://cses.fi/user/32680 -------------------------------------------------------------------------------- /java/KejariwalAyush/kejariwalAyush_repetitions.java: -------------------------------------------------------------------------------- 1 | // You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 2 | // https://cses.fi/problemset/task/1069/ 3 | 4 | //author: KejariwalAyush 5 | 6 | import java.util.Scanner; 7 | 8 | public class kejariwalAyush_repetitions { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | String s = sc.nextLine().toUpperCase(); 12 | int cnt = 1, max = 1; 13 | for (int i = 1; i < s.length(); i++) { 14 | if (s.charAt(i) == s.charAt(i - 1)) { 15 | cnt++; 16 | max = Math.max(max, cnt); 17 | } else 18 | cnt = 1; 19 | } 20 | System.out.println(max); 21 | sc.close(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /java/Abhishek417374/Abhishek417374_weird_algorithm.java: -------------------------------------------------------------------------------- 1 | /*Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows: 2 | 3→10→5→16→8→4→2→1 3 | 4 | Your task is to simulate the execution of the algorithm for a given value of n. */ 5 | 6 | //https://cses.fi/problemset/task/1068 7 | 8 | //author:Abhishek417374 9 | 10 | 11 | import java.util.Scanner; 12 | 13 | public class Abhishek417374_weird_algorithm{ 14 | 15 | public static void main(String[] args) { 16 | Scanner s=new Scanner(System.in); 17 | long n=s.nextLong(); 18 | while(n!=1) { 19 | System.out.println(n); 20 | if(n%2==0) 21 | n=n/2; 22 | else 23 | n=n*3+1; 24 | } 25 | System.out.println(1); 26 | 27 | } 28 | 29 | 30 | 31 | 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /java/SumanMore/SumanMore_weird_algorithm.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Consider an algorithm that takes as input a positive integer n. 4 | If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 5 | */ 6 | //https://cses.fi/problemset/task/1068 7 | 8 | 9 | import java.util.*; 10 | public class weird { 11 | public static void main(String args[]) 12 | { 13 | Scanner sc=new Scanner(System.in); 14 | long n=sc.nextInt(); 15 | System.out.print(n+" "); 16 | while(n!=1) 17 | { 18 | 19 | if(n%2==0) 20 | n/=2; 21 | else 22 | n=(n*3)+1; 23 | 24 | System.out.print(n+" "); 25 | } 26 | } 27 | } 28 | // AUTHOR:SumanMore 29 | // User id: https://cses.fi/user/32360 30 | //solution:https://cses.fi/problemset/result/1073408/ 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /c_plus_plus/AbHiSHekAB01/AbHiSHekAB01IncreasingArray.cpp: -------------------------------------------------------------------------------- 1 | 2 | //You are given an array of n integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 3 | 4 | //On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 5 | 6 | //author:AbHiSHekAB01; 7 | 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | 15 | int n; 16 | cin>>n; 17 | long long arr[n]; 18 | long long x=0; 19 | for(int i=0;i>arr[i]; 22 | } 23 | for(int i=1;i> dna; 10 | char track = dna[0]; 11 | int count = 0; 12 | int check = 0; 13 | for(char c : dna){ 14 | if(track == c){ 15 | count++; 16 | }else{ 17 | track = c; 18 | count = 1; 19 | } 20 | if(check < count){ 21 | check = count; 22 | } 23 | } 24 | std::cout< 2 | // #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | int main(){ 8 | 9 | int n, x, temp; 10 | cin >> n >> x; 11 | vector coins; 12 | vector sum; 13 | for(int i = 0; i < n; i++){ 14 | cin >> temp; 15 | coins.push_back(temp); 16 | } 17 | sort(coins.begin(), coins.end()); 18 | 19 | cout << endl; 20 | sum.push_back(1); 21 | for(int i = 1; i <= x; i++){ 22 | sum.push_back(0); 23 | for(int j = 0; j < n; j++){ 24 | if(coins.at(j) > i) 25 | break; 26 | sum.at(i) = (sum.at(i) + sum.at(i - coins[j])) % 1000000007; 27 | } 28 | //cout << "i is " << i << endl; 29 | } 30 | cout << sum[x] << endl; 31 | // ifs.close(); 32 | 33 | // Author: psib0t 34 | // Profile: https://cses.fi/user/26439 35 | } -------------------------------------------------------------------------------- /java/amohapatra123/amohapatra123_weird_algorithm.java: -------------------------------------------------------------------------------- 1 | /* Consider an algorithm that takes as input a positive integer n. If n is even, 2 | the algorithm divides it by two, and if n is odd, the algorithm multiplies 3 | it by three and adds one. The algorithm repeats this, until n is one. 4 | For example, the sequence for n=3 is as follows: 5 | 3→10→5→16→8→4→2→1 6 | */ 7 | 8 | //https://cses.fi/problemset/task/1068/ 9 | 10 | //author:amohapatra123 11 | 12 | 13 | import java.util.Scanner; 14 | public class amohapatra123_weird_algorithm{ 15 | 16 | public static void main(String args[]){ 17 | Scanner y= new Scanner(System.in); 18 | long n=y.nextLong(); 19 | System.out.print(n+" "); 20 | while(n!=1){ 21 | if(n%2==0){ 22 | n=n/2; 23 | }else if(n%2==1){ 24 | n=(n*3)+1; 25 | } 26 | System.out.print(n+" "); 27 | } 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /java/Rishika6/Rishika6_Repeatitions.java: -------------------------------------------------------------------------------- 1 | /*Q-->You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 2 | Link-->https://cses.fi/problemset/task/1069*/ 3 | import java.util.Scanner; 4 | 5 | public class Repeatitions { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | String s = sc.nextLine().toUpperCase(); 11 | int cnt = 1, max = 1; 12 | for (int i = 1; i < s.length(); i++) { 13 | if (s.charAt(i) == s.charAt(i - 1)) { 14 | cnt++; 15 | max = Math.max(max, cnt); 16 | } else 17 | cnt = 1; 18 | } 19 | System.out.println(max); 20 | sc.close(); 21 | } 22 | 23 | } 24 | 25 | //author:Rishika 26 | //https://cses.fi/user/32327 -------------------------------------------------------------------------------- /java/SumanMore/SumanMore_Distinct_Numbers.java: -------------------------------------------------------------------------------- 1 | 2 | //You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 3 | //https://cses.fi/problemset/task/1621 4 | 5 | import java.util.*; 6 | public class distinctnumbers 7 | { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc=new Scanner(System.in); 11 | int n,i,j , cnt = 1; 12 | n=sc.nextInt(); 13 | int ar[]=new int[n]; 14 | for ( i = 0; i < n; i++) 15 | ar[i] =sc.nextInt(); 16 | Arrays.sort(ar); 17 | 18 | for( j=0;j 11 | #include 12 | using namespace std; 13 | 14 | int main() 15 | { 16 | 17 | string in; 18 | cin>>in; 19 | long long max=1; 20 | long long c=1; 21 | for(int i=1;i 11 | using namespace std; 12 | 13 | int main() { 14 | string input; 15 | cin>>input; 16 | 17 | int ans = 1; 18 | int tempChain = 1; 19 | 20 | for (int i=1; i ans ? tempChain : ans; 24 | } else { 25 | tempChain = 1; 26 | } 27 | } 28 | 29 | printf("%d\n", ans); 30 | 31 | return 0; 32 | } 33 | 34 | // author: stevenbudinata 35 | // solution: https://cses.fi/problemset/result/1065652/ -------------------------------------------------------------------------------- /java/Palak Srivastava/Palak-Srivastava_RepetitionString.java: -------------------------------------------------------------------------------- 1 | /* You are given a DNA sequence: a string consisting of characters A, C, G, and T. 2 | Your task is to find the longest repetition in the sequence. 3 | This is a maximum-length substring containing only one type of character. 4 | 5 | Link: https://cses.fi/problemset/task/1069/ 6 | */ 7 | 8 | 9 | 10 | import java.util.*; 11 | public class repetitionString { 12 | 13 | public static void main(String[] args) 14 | { 15 | Scanner in=new Scanner(System.in); 16 | String s=""; 17 | int c=1,max=1; 18 | s=in.nextLine().toUpperCase(); 19 | for(int i=1;i 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | long long int n,s=0,q,r,i; 7 | cin>>n; 8 | s=(n*(n+1))/2; 9 | if(s%2==0) 10 | { 11 | cout<<"YES"<0) 24 | cout< 12 | 13 | using namespace std; 14 | 15 | 16 | int main() 17 | { 18 | 19 | int n; 20 | cin >> n; 21 | 22 | if(n == 1) cout << 1 << endl; 23 | else if (n < 4) cout << "NO SOLUTION" << endl; 24 | else if (n == 4) cout << "2 4 1 3\n"; 25 | else { 26 | for (int i = 1; i <= n; i += 2) cout << i << " "; 27 | for (int i = 2; i <= n; i += 2) { 28 | cout << i; 29 | if (i + 2 <= n) cout << " "; 30 | else cout << endl; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /c_plus_plus/stevenbudinata/stevenbudinata_weird_algorithm.cpp: -------------------------------------------------------------------------------- 1 | // Question: 2 | /* 3 | Consider an algorithm that takes as input a positive integer n. 4 | If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 5 | The algorithm repeats this, until n is one 6 | */ 7 | 8 | // link: https://cses.fi/problemset/task/1068 9 | 10 | #include 11 | using namespace std; 12 | 13 | int main() { 14 | long long int n; 15 | cin>>n; 16 | 17 | vector ans; 18 | while (n >= 1) { 19 | ans.push_back(n); 20 | 21 | if(n==1) break; 22 | if (n % 2 == 0) { 23 | n /= 2; 24 | continue; 25 | } 26 | n = n*3 + 1; 27 | } 28 | 29 | for (int i=0; i 1) { 19 | n = n % 2 == 0 ? n / 2 : n * 3 + 1; 20 | System.out.print(n + " "); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /java/ankitsaebby/ankitsaebbyWeirdAlgorithm.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | //Consider an algorithm that takes as input a positive integer n. 5 | //If n is even, the algorithm divides it by two, and if n is odd, 6 | //the algorithm multiplies it by three and adds one. 7 | //The algorithm repeats this, until n is one. 8 | //For example, the sequence for n=3 is as follows: 9 | 10 | //author:ankitsaebby 11 | 12 | import java.util.Scanner; 13 | 14 | public class ankitsaebbyWeirdAlgorithm { 15 | public static void main(String[] args) { 16 | 17 | //System.out.println("Input your number"); 18 | Scanner sc= new Scanner(System.in); 19 | long n= sc.nextLong(); 20 | System.out.print(n); 21 | while(n>1) { 22 | if(n%2==0) { 23 | n=n/2; 24 | System.out.print(" "+n); 25 | } 26 | else { 27 | n=(n*3)+1; 28 | System.out.print(" "+n); 29 | } 30 | } 31 | 32 | } 33 | 34 | } 35 | //cses id - https://cses.fi/user/32538 36 | -------------------------------------------------------------------------------- /python/SoumyaKB96/SoumyaKB96_SubArray_sum2.py: -------------------------------------------------------------------------------- 1 | #Qn. Given an array of n integers, 2 | # your task is to count the number of subarrays having sum x. 3 | 4 | # Link - https://cses.fi/problemset/task/1661/ 5 | 6 | from collections import defaultdict 7 | def SubSum(arr, n, Sum): 8 | 9 | psum = defaultdict(lambda: 0) 10 | 11 | res = 0 12 | csum = 0 13 | 14 | for i in range(0, n): 15 | csum += arr[i] 16 | 17 | if csum == Sum: 18 | res += 1 19 | 20 | 21 | if (csum - Sum) in psum: 22 | res += psum[csum - Sum] 23 | 24 | 25 | psum[csum] += 1 26 | 27 | return res 28 | 29 | 30 | if __name__ == "__main__": 31 | 32 | n,x= input().split() 33 | n=int(n) 34 | x=int(x) 35 | arr = list(map(int, input().strip().split()))[:n] 36 | print(SubSum(arr, n, x)) 37 | 38 | #Author - SoumyaKB96 39 | # Profile - https://cses.fi/user/32322 40 | -------------------------------------------------------------------------------- /python/SoumyaKB96/SoumyaKB96_subarray_sum1.py: -------------------------------------------------------------------------------- 1 | #Qn. Given an array of n positive integers, your task is to count the number of subarrays having sum x 2 | # Q LInk - https://cses.fi/problemset/task/1660/ 3 | 4 | from collections import defaultdict 5 | def SubarraySum(arr, n, Sum): 6 | 7 | psum = defaultdict(lambda: 0) 8 | res = 0 9 | cursum = 0 10 | 11 | for i in range(0, n): 12 | cursum += arr[i] 13 | 14 | 15 | if cursum == Sum: 16 | res += 1 17 | 18 | 19 | if (cursum - Sum) in psum: 20 | res += psum[cursum - Sum] 21 | 22 | 23 | psum[cursum] += 1 24 | 25 | return res 26 | 27 | 28 | n, x = input().split() 29 | n = int(n) 30 | x = int(x) 31 | arr = [] 32 | arr = list(map(int, input().strip().split()))[:n] 33 | 34 | print(SubarraySum(arr, n, x)) 35 | 36 | #Author : SoumyaKB96 37 | # Profile : https://cses.fi/user/32322 38 | 39 | 40 | -------------------------------------------------------------------------------- /c_plus_plus/MartyMiniac/MartyMiniac_weird_algorithm.cpp: -------------------------------------------------------------------------------- 1 | //Question 2 | //Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows: 3 | //3→10→5→16→8→4→2→1 4 | //Your task is to simulate the execution of the algorithm for a given value of n. 5 | //https://cses.fi/problemset/task/1068/ 6 | 7 | #include "iostream" 8 | 9 | int main() 10 | { 11 | unsigned long int inp; 12 | std::cin>>inp; 13 | 14 | std::cout< 1) 20 | { 21 | if(a%2 == 0) 22 | { 23 | a = a/2; 24 | System.out.print(a+" "); 25 | } 26 | else 27 | { 28 | a = (a*3)+1; 29 | System.out.print(a+" "); 30 | } 31 | } 32 | } 33 | } 34 | /*author:aadityamittal 35 | https://cses.fi/user/32817 36 | */ -------------------------------------------------------------------------------- /java/swetamukherjee/swetamukherjee_Repetitions.java: -------------------------------------------------------------------------------- 1 | /*You are given a DNA sequence: a string consisting of characters A, C, G, and T. 2 | Your task is to find the longest repetition in the sequence. 3 | This is a maximum-length substring containing only one type of character. 4 | 5 | 6 | https://cses.fi/problemset/task/1069 7 | 8 | */ 9 | 10 | import java.util.*; 11 | 12 | public class Repetitions 13 | { 14 | public static void main(String[] args) 15 | { 16 | Scanner sc = new Scanner(System.in); 17 | String x = sc.nextLine(); 18 | int n = x.length(); 19 | long t = 1l,ans = 1l; 20 | for(int i = 1; i < n; i++) 21 | { 22 | if(x.charAt(i)==x.charAt(i-1)) 23 | { 24 | t++; 25 | } 26 | else{ 27 | ans = Math.max(t,ans); 28 | t = 1l; 29 | } 30 | }ans = Math.max(t,ans); 31 | System.out.println(ans); 32 | } 33 | } 34 | 35 | /*author:swetamukherjee 36 | https://cses.fi/user/32972 37 | */ 38 | 39 | 40 | -------------------------------------------------------------------------------- /java/swetamukherjee/swetamukherjee_WeirdAlgorithm.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | Consider an algorithm that takes as input a positive integer n. 4 | If n is even, the algorithm divides it by two, and if n is odd, 5 | the algorithm multiplies it by three and adds one. 6 | The algorithm repeats this, until n is one. 7 | For example, the sequence for n=3 is as follows: 8 | 3→10→5→16→8→4→2→1 9 | 10 | 11 | https://cses.fi/problemset/task/1068 12 | */ 13 | public class WeirdAlgo { 14 | public static void main(String[] args) 15 | { 16 | Scanner sc = new Scanner(System.in); 17 | long a = sc.nextLong(); 18 | System.out.print(a+" "); 19 | while(a > 1) 20 | { 21 | if(a%2 == 0) 22 | { 23 | a = a/2; 24 | System.out.print(a+" "); 25 | } 26 | else 27 | { 28 | a = (a*3)+1; 29 | System.out.print(a+" "); 30 | } 31 | } 32 | } 33 | } 34 | /*author:swetamukherjee 35 | https://cses.fi/user/32972 36 | */ -------------------------------------------------------------------------------- /java/ankitsaebby/ankitsaebby_repetion.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | //You are given a DNA sequence: a string consisting of characters A, C, G, and T. 5 | //Your task is to find the longest repetition in the sequence. 6 | //This is a maximum-length substring containing only one type of character. 7 | 8 | //author: ankitsaebby 9 | 10 | 11 | import java.util.Scanner; 12 | public class ankitsaebby_repetion { 13 | 14 | public static void main(String[] args) { 15 | System.out.println("input your string"); 16 | Scanner s=new Scanner(System.in); 17 | String str= s.next().toUpperCase(); 18 | int m=calMax(str); 19 | System.out.println(m); 20 | } 21 | public static int calMax(String str) { 22 | int max=0,count=0; 23 | for(int i=0;imax) 28 | max=count; 29 | count=0; 30 | } 31 | return max; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /c_plus_plus/PratikSonal/PratikSonal_increasing_array.cpp: -------------------------------------------------------------------------------- 1 | //Question 2 | //You are given an array of n integers. You want to modify the array so that it is increasing, 3 | //i.e., every element is at least as large as the previous element. 4 | //On each turn, you may increase the value of any element by one. 5 | //What is the minimum number of turns required? 6 | //https://cses.fi/problemset/task/1094 7 | 8 | #include "iostream" 9 | 10 | int main(){ 11 | int size; 12 | std::cin >> size; 13 | long count = 0; 14 | long track = 0; 15 | std::cin>>track; 16 | for(int i = 1; i < size; i++){ 17 | long temp = 0; 18 | std::cin>>temp; 19 | if(track > temp){ 20 | count += (track - temp); 21 | }else{ 22 | track = temp; 23 | } 24 | } 25 | std::cout<1) 16 | {for(int i=0;i<(s.length()-1);i++) 17 | { 18 | ch1=s.charAt(i); 19 | ch2=s.charAt(i+1); 20 | if(ch1==ch2) 21 | { c++; 22 | k=Math.max(c, k); 23 | } 24 | else 25 | c=1; 26 | 27 | } 28 | System.out.println(k); 29 | } 30 | else 31 | System.out.println("1"); 32 | } 33 | } 34 | //author : Utkarsh Shankar 35 | //profile: https://cses.fi/user/32339 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /java/itsjohnty/SmallestNumber.java: -------------------------------------------------------------------------------- 1 | /*Given an array of n integers, 2 | Your task is to find for each array position the nearest position to its left having a smaller value. 3 | link:https://cses.fi/problemset/task/1645 4 | */ 5 | import java.util.*; 6 | 7 | import java.io.*; 8 | 9 | public class SmallestNumber { 10 | 11 | public static void main(String[] args) { 12 | 13 | // TODO Auto-generated method stub 14 | Scanner sc=new Scanner(System.in); 15 | PrintWriter pw=new PrintWriter(System.out); 16 | int n=sc.nextInt(); 17 | 18 | int []a=new int[n+1]; 19 | 20 | for(int i=1;i<=n;i++) {//input 21 | a[i]=sc.nextInt(); 22 | } 23 | int stack[]=new int[n+1]; 24 | int count=0; 25 | stack[count++]=0; 26 | for(int i=1;i<=n;i++) {//stack 27 | int h=0; 28 | while(a[h=stack[count-1]]>=a[i]) { 29 | count--; 30 | } 31 | pw.print(h+" "); 32 | stack[count++]=i; 33 | } 34 | pw.println(); 35 | pw.close(); 36 | } 37 | 38 | } 39 | 40 | //author:itsjohnty 41 | -------------------------------------------------------------------------------- /java/ash0202/ash0202_TrailingZeros.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Your task is to calculate the number of trailing zeros in the factorial n!. 4 | 5 | For example, 20!=2432902008176640000 and it has 4 trailing zeros. 6 | 7 | Input 8 | 9 | The only input line has an integer n. 10 | 11 | Output 12 | 13 | Print the number of trailing zeros in n!. 14 | 15 | Constraints 16 | 1≤n≤109 17 | Example 18 | 19 | Input: 20 | 20 21 | 22 | Output: 23 | 4 24 | author:Ashish Senapati 25 | profile:https://cses.fi/user/32749 26 | link-https://cses.fi/problemset/task/1618/ 27 | */ 28 | import java.util.Scanner; 29 | public class ash0202_TrailingZeros 30 | { 31 | static Scanner sc=new Scanner(System.in); 32 | public static void main(String[] args) 33 | { 34 | 35 | long n=sc.nextLong(); 36 | int c=0; 37 | for(int i=5;(n/i!=0);i*=5) 38 | { 39 | c=c+(int)(n/i); 40 | } 41 | System.out.println(c); 42 | 43 | 44 | 45 | 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /c_plus_plus/Raman/Graph/Raman_Building_Roads.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void DFS_util(int node,vector>&mat,vector&visited) 4 | { 5 | visited[node]=true; 6 | for(auto v:mat[node]) 7 | { 8 | if(!visited[v]) 9 | DFS_util(v,mat,visited); 10 | } 11 | } 12 | int main() 13 | { 14 | ios_base::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n,m; 17 | cin>>n>>m; 18 | vector>g(n); 19 | for(int i=0;i>u>>v; 23 | g[u-1].push_back(v-1); 24 | g[v-1].push_back(u-1); 25 | } 26 | vectorvisited(n,false); 27 | vectorcities; 28 | int comp=0; 29 | for(int i=0;i 2 | // #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | int main(){ 8 | int n, x, temp; 9 | cin >> n >> x; 10 | vector coins; 11 | vector> sum; 12 | for(int i = 0; i < n; i++){ 13 | cin >> temp; 14 | coins.push_back(temp); 15 | } 16 | sort(coins.begin(), coins.end()); 17 | for (auto k: coins){ 18 | sum.emplace_back(x + 1, 0); 19 | sum.back().at(0) = 1; 20 | } 21 | for (int i = coins[0]; i <= x; i += coins[0]) 22 | sum[0][i] = 1; 23 | for(int i = 1; i < coins.size(); i++){ 24 | for(int j = 1; j <= x; j++){ 25 | sum[i][j] = sum[i-1][j]; 26 | if (coins[i] <= j) 27 | sum[i][j] = (sum[i][j] + sum[i][j - coins[i]]) % 1000000007; 28 | } 29 | } 30 | cout << sum.back().back() << endl; 31 | // Author: psib0t 32 | // Profile: https://cses.fi/user/26439 33 | } -------------------------------------------------------------------------------- /java/Palak Srivastava/Palak-Srivastava_IncreasingArray.java: -------------------------------------------------------------------------------- 1 | //You are given an array of n integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 2 | 3 | //On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 4 | //Link: https://cses.fi/problemset/task/1094/ 5 | 6 | 7 | 8 | import java.util.*; 9 | public class IncreasingArray { 10 | 11 | public static void main(String[] args) { 12 | Scanner sc=new Scanner(System.in); 13 | int n,i; 14 | long turn=0; 15 | n=sc.nextInt(); 16 | int a[]=new int[n]; 17 | for(i=0;ia[i]) 24 | { 25 | turn=turn+ Math.abs(a[i-1]-a[i]); 26 | a[i]=a[i-1]; 27 | } 28 | } 29 | 30 | System.out.println(turn); 31 | 32 | } 33 | 34 | } 35 | 36 | //Author: Palak Srivastava 37 | //https://cses.fi/user/32824 38 | -------------------------------------------------------------------------------- /java/Palak Srivastava/Palak-Srivastava_weirdAlgorithm.java: -------------------------------------------------------------------------------- 1 | //Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, 2 | // the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows: 3 | //3→10→5→16→8→4→2→1 4 | //Your task is to simulate the execution of the algorithm for a given value of n. 5 | //Link : https://cses.fi/problemset/task/1068 6 | 7 | import java.util.*; 8 | public class weirdAlgo { 9 | 10 | public static void main(String[] args) { 11 | Scanner in=new Scanner(System.in); 12 | long n=in.nextLong(); 13 | StringBuilder s=new StringBuilder(); 14 | while(n!=1) { 15 | s.append(n+" "); 16 | if(n%2==0) { 17 | n/=2; 18 | } 19 | else 20 | n=n*3+1; 21 | } 22 | s.append(1); 23 | System.out.println(s); 24 | 25 | } 26 | 27 | } 28 | 29 | //Author Palak Srivastava 30 | //profile link: https://cses.fi/user/32824 -------------------------------------------------------------------------------- /java/UtkarshShankar/UtkarshShankar_Increasing_Array.java: -------------------------------------------------------------------------------- 1 | //You are given an array of n integers. You want to modify the array so that it is increasing, i.e. 2 | //, every element is at least as large as the previous element. 3 | // 4 | //On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 5 | //https://cses.fi/problemset/task/1094/ 6 | 7 | import java.util.*; 8 | public class UtkarshShankar_Increasing_Array 9 | { 10 | public static void main(String args[]) 11 | { 12 | Scanner in=new Scanner(System.in); 13 | int n=in.nextInt(); 14 | int a[]=new int[n]; 15 | for(int i=0;i 7 | #include 8 | using namespace std; 9 | #define ios ios::sync_with_stdio(false);cin.tie(NULL) 10 | #define endl "\n" 11 | #define ll long long 12 | 13 | void solve() 14 | { 15 | string s; 16 | cin>>s; 17 | int ans=0; 18 | int count=1; 19 | for(int i=0;i>tt; 41 | 42 | while(tt--) 43 | { 44 | solve(); 45 | } 46 | return 0; 47 | } 48 | 49 | //author:saurbhnikam -------------------------------------------------------------------------------- /java/RaviKumarPrasad/Raviruler_Increasing_Array.java: -------------------------------------------------------------------------------- 1 | /* 2 | You are given an array of n integers. 3 | You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 4 | 5 | On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 6 | 7 | link:https://cses.fi/problemset/task/1094/ 8 | 9 | Input: 10 | 5 11 | 3 2 5 1 7 12 | 13 | Output: 14 | 5 15 | 16 | */ 17 | import java.util.Scanner; 18 | public class Raviruler_Increasing_Array { 19 | public static void main(String[] args) { 20 | Scanner scan=new Scanner(System.in); 21 | long minturn=0; 22 | int n=scan.nextInt(); 23 | int a[]=new int [n]; 24 | a[0]=scan.nextInt(); 25 | for(int i=1;ia[i]) 28 | { 29 | minturn+=(a[i-1]-a[i]); 30 | a[i]=a[i-1]; 31 | } 32 | } 33 | System.out.print(minturn); 34 | } 35 | } 36 | //Author: Ravi Kumar Prasad 37 | //Git_hub Id: Raviruler 38 | //cses : https://cses.fi/user/32356/ -------------------------------------------------------------------------------- /c_plus_plus/Ayushkumarsahoo/Ayushkumarsahoo_Increasing_Array.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | You are given an array of n integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 3 | 4 | On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 5 | 6 | */ 7 | // link : https://cses.fi/problemset/task/1094 8 | 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | int main() 14 | { 15 | 16 | int n; 17 | cin>>n; 18 | long long arr[n]; 19 | long long c=0; 20 | for(int i=0;i>num; 24 | arr[i]=num; 25 | } 26 | for(int i=1;i1){ 19 | if(n%2==0){ 20 | n/=2; 21 | System.out.println(n); 22 | } 23 | else{ 24 | n=n*3+1; 25 | System.out.println(n); 26 | } 27 | } 28 | } 29 | } 30 | 31 | //author: SatyapragyanDas 32 | //profile: https://cses.fi/user/32452 33 | -------------------------------------------------------------------------------- /java/ShrutiMallick/ShrutiMallick_SmallestNumber.java: -------------------------------------------------------------------------------- 1 | /*Given an array of n integers, 2 | * your task is to find for each array position the nearest position to its left having a smaller value. 3 | * 4 | * link:https://cses.fi/problemset/task/1645 5 | */ 6 | import java.util.*; 7 | import java.io.*; 8 | public class SmallestNumber { 9 | 10 | public static void main(String[] args) { 11 | // TODO Auto-generated method stub 12 | Scanner sc=new Scanner(System.in); 13 | PrintWriter pw=new PrintWriter(System.out); 14 | int n=sc.nextInt(); 15 | int []a=new int[n+1]; 16 | for(int i=1;i<=n;i++) { 17 | a[i]=sc.nextInt(); 18 | } 19 | int stack[]=new int[n+1]; 20 | int count=0; 21 | stack[count++]=0; 22 | for(int i=1;i<=n;i++) { 23 | int h=0; 24 | while(a[h=stack[count-1]]>=a[i]) { 25 | count--; 26 | } 27 | pw.print(h+" "); 28 | stack[count++]=i; 29 | } 30 | pw.println(); 31 | pw.close(); 32 | } 33 | 34 | } 35 | //author:Shruti 36 | //profile link:https://cses.fi/user/32358 37 | -------------------------------------------------------------------------------- /java/TapasSahu/TapasSahu_DistinctNumbers.java: -------------------------------------------------------------------------------- 1 | /*You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 2 | 3 | Input 4 | 5 | The first input line has an integer n: the number of values. 6 | 7 | The second line has n integers x1,x2,…,xn. 8 | 9 | Output 10 | 11 | Print one integers: the number of distinct values. 12 | 13 | Constraints 14 | 1≤n≤2⋅105 15 | 1≤xi≤109 16 | Example 17 | 18 | Input: 19 | 5 20 | 2 3 2 2 3 21 | 22 | Output: 23 | 2 24 | link:https://cses.fi/problemset/task/1621*/ 25 | import java.math.BigInteger; 26 | import java.util.*; 27 | public class TapasSahu_DistinctNumbers{ 28 | static Scanner sc=new Scanner(System.in); 29 | public static void main(String[] args) 30 | { 31 | BigInteger n=new BigInteger(sc.nextLine()); 32 | String x=sc.nextLine(); 33 | String arr[]=x.split(" "); 34 | HashSet set=new HashSet(Arrays.asList(arr)); 35 | System.out.println(set.size()); 36 | } 37 | 38 | } 39 | //author:Tapas Sahu 40 | //Profile: https://cses.fi/problemset/task/1621 -------------------------------------------------------------------------------- /java/JainStuti25/JainStuti25_IncreasingArr.java: -------------------------------------------------------------------------------- 1 | // AUTHOR 2 | // Stuti Jain 3 | // USER ID 4 | // https://cses.fi/user/25504 5 | // PROBLEM NUMBER 6 | // https://cses.fi/problemset/task/1094 7 | // You are given an array of n integers. You want to modify the array so that it is increasing, i.e., every element is at least as large as the previous element. 8 | //On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 9 | 10 | public class JainStuti25_IncreasingArr { 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | int n = sc.nextInt(); 14 | long ans=0; 15 | int[] arr=new int[n]; 16 | for(int i=0;i a[i]) { 22 | min += (a[i - 1] - a[i]); 23 | a[i] = a[i - 1]; 24 | } 25 | } 26 | System.out.println(min); 27 | sc.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java/debashishsamantara/debashishsamantara_repetitions.java: -------------------------------------------------------------------------------- 1 | //You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 2 | 3 | //Author : debashishsamantara 4 | //Profile : https://cses.fi/user/32389 5 | //Ques. link : https://cses.fi/problemset/task/1069/ 6 | 7 | 8 | import java.util.Scanner; 9 | public class debashishsamantara_repetitions { 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | String s = sc.nextLine().toUpperCase(); 13 | int c=1, z=1; 14 | for(int i=0; i