├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── README.md ├── c_plus_plus ├── .DS_Store ├── 4yush933 │ ├── 4yush933_BuildingTeams.cpp │ ├── 4yush933_CountingRooms.cpp │ ├── 4yush933_CourseSchedule.cpp │ ├── 4yush933_MessageRoute.cpp │ └── 4yush933_RangeUpdate.cpp ├── ASVKVINAYAK │ ├── ASVKVINAYAK_WeirdAlgorithm.cpp │ ├── ASVKVINAYAK_bitstrings.cpp │ ├── ASVKVINAYAK_missingnumber.cpp │ ├── ASVKVINAYAK_repetation.cpp │ └── ASVKVINAYAK_twoknights.cpp ├── AbHiSHekAB01 │ ├── AbHiSHekAB01IncreasingArray.cpp │ ├── AbHiSHekAB01TrailingZeros.cpp │ ├── AbHiSHekAB01_DistinctNumbers.cpp │ ├── AbHiSHekAB01_MissingNumber.cpp │ └── AbHiSHekAB01_WeirdAlgorithm.cpp ├── AkhileshMattam │ └── triling_zeros.cpp ├── Ayushkumarsahoo │ ├── Ayushkumarsahoo_Increasing_Array.cpp │ ├── Ayushkumarsahoo_MissingNumber.cpp │ ├── Ayushkumarsahoo_Repetitions.cpp │ ├── Ayushkumarsahoo_Weird_Algorithm.cpp │ └── Ayushkumarsahoo_permutations.cpp ├── Devansh_Singh │ ├── Increasing Array.cpp │ ├── Missing Number.cpp │ ├── Number Spiral.cpp │ ├── Permutations.cpp │ ├── Repetitions.cpp │ └── Weird Algorithm.cpp ├── MartyMiniac │ ├── MartyMiniac_apple_division.cpp │ ├── MartyMiniac_bit_strings.cpp │ ├── MartyMiniac_missing_number.cpp │ ├── MartyMiniac_repetitions.cpp │ └── MartyMiniac_weird_algorithm.cpp ├── NasarTarique │ ├── NasarTarique_Range_Minimum_Queries_I.cpp │ ├── NasarTarique_Range_Minimum_Queries_II.cpp │ ├── NasarTarique_Range_Sum_Queries_I.cpp │ ├── NasarTarique_Range_Sum_Queries_II.cpp │ └── NasarTarique_Tree_Traversals.cpp ├── Pranjal81 │ └── Pranjal81_Round_Trip.cpp ├── PratikSonal │ ├── PratikSonal_increasing_array.cpp │ ├── PratikSonal_missing_number.cpp │ ├── PratikSonal_permutations.cpp │ ├── PratikSonal_repetitions.cpp │ └── PratikSonal_weird_algorithm.cpp ├── Raman │ └── Graph │ │ ├── .cph │ │ ├── .Building_Roads.cpp_7e433b79cd927b9dba1a6a4298f53e3d.prob │ │ ├── .Building_Teams.cpp_92e4fa58d42efc981141d3cb07c9a894.prob │ │ ├── .Counting_Rooms.cpp_ae7f61321e7c7e80dfedd5c2b3aa88a2.prob │ │ ├── .Labyrinth.cpp_f8635e9a69fb9d7315154109f3317af4.prob │ │ └── .Message_Route.cpp_71d5c75dbdb56d6c744588c775d202f5.prob │ │ ├── .vscode │ │ └── settings.json │ │ ├── Raman_Building_Roads.cpp │ │ ├── Raman_Building_Teams.cpp │ │ ├── Raman_Counting_Rooms.cpp │ │ ├── Raman_Labyrinth.cpp │ │ └── Raman_Message_Route.cpp ├── SiddhantJaiswal-0125 │ └── SiddhantJaiswal-0125_NearestSmallerValues.cpp ├── SouravReal │ ├── SouravReal_Increasing_Array.cpp │ └── SouravReal_Two_Knights.cpp ├── Sudeep25022000 │ ├── Sudeep25022000_distinctnumber.cpp │ ├── Sudeep25022000_permutation.cpp │ ├── Sudeep25022000_repeatation.cpp │ ├── Sudeep25022000_weirdalgorithm.cpp │ └── sudeep25022000_appledivision.cpp ├── akbar1214 │ ├── akbar1214_BitStrings.cpp │ ├── akbar1214_IncreasingArray.cpp │ ├── akbar1214_MissingNumber.cpp │ ├── akbar1214_TrailingZeroes.cpp │ ├── akbar1214_TwoKnights.cpp │ ├── akbar1214_TwoSets.cpp │ ├── akbar1214_WeirdAlgorithm.cpp │ └── akbar1214_permutations.cpp ├── c++.md ├── goel28priyanshu │ └── goel28priyanshu_trailing_zeros.cpp ├── jineshparakh │ ├── .DS_Store │ ├── jineshparakh_Building_Roads.cpp │ ├── jineshparakh_Counting_Rooms.cpp │ ├── jineshparakh_Edit_Distance.cpp │ ├── jineshparakh_Range_Xor_Queries.cpp │ └── jineshparakh_Tree_Distances_I.cpp ├── pawank0411 │ ├── pawank0411_Number_Spiral.cpp │ └── pawank0411_Permutation.cpp ├── psib0t │ ├── psib0t_Appartments.cpp │ ├── psib0t_CoinCombinations1.cpp │ ├── psib0t_CoinCombinations2.cpp │ ├── psib0t_MovieFestival.cpp │ └── psib0t_RemovingDigits.cpp ├── saurabhNikam │ ├── saurabh-nikam-Increasing_Array.cpp │ ├── saurabh-nikam_Bit_String.cpp │ ├── saurabh-nikam_Number_Spiral.cpp │ ├── saurabh-nikam_Permitation.cpp │ └── saurabh-nikam_Repetitions.cpp ├── siddhantmohanty2001 │ ├── siddhantmohanty2001_bitStrings.cpp │ ├── siddhantmohanty2001_coinPiles.cpp │ ├── siddhantmohanty2001_palindromeReorder.cpp │ ├── siddhantmohanty2001_trailingZeroes.cpp │ ├── siddhantmohanty2001_twoKnights.cpp │ └── siddhantmohanty2001_twoSets.cpp ├── stevenbudinata │ ├── steven_budinata_repetitions.cpp │ ├── stevenbudinata_counting_rooms.cpp │ ├── stevenbudinata_distinct_numbers.cpp │ ├── stevenbudinata_missing_number.cpp │ └── stevenbudinata_weird_algorithm.cpp └── subhamsagar524 │ ├── subhamsagar524_distinct_numbers.cpp │ ├── subhamsagar524_ferris_wheel.cpp │ ├── subhamsagar524_missing_number.cpp │ ├── subhamsagar524_trailing_zeros.cpp │ └── subhamsagar524_weird_algorithm.cpp ├── java ├── AbhinandanRoul │ ├── AbhinandanRoul_MissingNumber.java │ ├── AbhinandanRoul_Repetitions.java │ ├── AbhinandanRoul_StringMatching.java │ ├── AbhinandanRoul_TrailingZeros.java │ └── AbhinandanRoul_WeirdAlgorithm.java ├── Abhishek417374 │ ├── Abhishek417374_distinct_number.java │ ├── Abhishek417374_missing_number.java │ ├── Abhishek417374_repetition.java │ ├── Abhishek417374_trailing_zeros.java │ └── Abhishek417374_weird_algorithm.java ├── JainStuti25 │ ├── JainStuti25_IncreasingArr.java │ ├── JainStuti25_MissingNum.java │ ├── JainStuti25_Permutation.java │ ├── JainStuti25_Repetition.java │ └── JainStuti25_WeirdAlgo.java ├── KejariwalAyush │ ├── kejariwalAyush_TrailingZerors.java │ ├── kejariwalAyush_bitString.java │ ├── kejariwalAyush_increasingArrays.java │ ├── kejariwalAyush_repetitions.java │ └── kejariwalAyush_wierdAlgorithm.java ├── LoopGlitch26 │ ├── LoopGlitch26_MissingNumber.java │ ├── LoopGlitch26_Repetitions.java │ └── LoopGlitch26_WeirdAlgorithm.java ├── Palak Srivastava │ ├── Palak-Srivastava_DistinctNumbers.java │ ├── Palak-Srivastava_IncreasingArray.java │ ├── Palak-Srivastava_MissingNumber.java │ ├── Palak-Srivastava_RepetitionString.java │ └── Palak-Srivastava_weirdAlgorithm.java ├── Prakashpathak984 │ ├── Prakashpathak984_BitStrings.java │ ├── Prakashpathak984_MissingNumber.java │ ├── Prakashpathak984_Repetitions.java │ ├── Prakashpathak984_WeirdAlgorithm.java │ ├── Prakashpathak984_increasingArray.java │ └── Prakashpathak984_removingDigits.java ├── RIJULDAS │ ├── RIJULDAS_increasing_array.java │ ├── RIJULDAS_missing_number.java │ ├── RIJULDAS_repetitions.java │ ├── RIJULDAS_trailing_zeros.java │ └── RIJULDAS_weird_algorithm.java ├── RaviKumarPrasad │ ├── Raviruler_Increasing_Array.java │ ├── Raviruler_Missing_Number.java │ ├── Raviruler_Repetition.java │ ├── Raviruler_Trailing_Zero.java │ └── Raviruler_Weird_Algorithm.java ├── Rishika6 │ ├── Rishika6_DistinctNumbers.java │ ├── Rishika6_IncreasingArray.java │ ├── Rishika6_NearestSmallerValue.java │ ├── Rishika6_Repeatitions.java │ ├── Rishika6_SumOfTwoValues.java │ └── Rishika6_missingNumber.java ├── SatyapragyanDas │ ├── SatyapragyanDas_IncreasingArray.java │ ├── SatyapragyanDas_Permutations.java │ ├── SatyapragyanDas_Repetitions.java │ ├── SatyapragyanDas_WeirdAlgorithm.java │ └── Satyapragyan_MissingNumber.java ├── Shivangibose │ ├── Shivangibose_Missing_number.java │ ├── Shivangibose_Removing_Digits.java │ ├── Shivangibose_Repetitions.java │ ├── Shivangibose_Weird_Algorithm.java │ └── Shivangibose_increasing_array.java ├── ShrutiMallick │ ├── ShrutiMallick_BookShop.java │ ├── ShrutiMallick_DiceCombination.java │ ├── ShrutiMallick_FerrisWheel.java │ ├── ShrutiMallick_SmallestNumber.java │ └── ShrutiMallick_subarraydivisibilty.java ├── SiddhantJaiswal-0125 │ ├── SiddhantJaiswal-0125_DistinctNumbers.java │ ├── SiddhantJaiswal-0125_MinimizingCoins.java │ ├── SiddhantJaiswal-0125_ReadingBooks.java │ └── SiddhantJaiswal-0125_SumofTwoValues.java ├── SouravReal │ ├── SouravReal_Missing_Number.java │ ├── SouravReal_Repetitions.java │ └── SouravReal_Weird_Algorithm.java ├── SumanMore │ ├── SumanMore_Distinct_Numbers.java │ ├── SumanMore_Missing_Number.java │ ├── SumanMore_Repititions.java │ ├── SumanMore_Trailing_zeros.java │ └── SumanMore_weird_algorithm.java ├── Suvamrx │ ├── Suvamrx_increasingarray.java │ ├── Suvamrx_playlist.java │ ├── Suvamrx_repetition.java │ ├── Suvamrx_sumofdivisors.java │ └── Suvamrx_twoknights.java ├── TapasSahu │ ├── TapasSahu_DistinctNumbers.java │ ├── TapasSahu_MissingNumber.java │ ├── TapasSahu_TrailingZeros.java │ ├── TapasSahu_WeirdAlgorithm.java │ └── TapasSahu_bitString.java ├── UtkarshShankar │ ├── UtkarshShankar_Increasing_Array.java │ ├── UtkarshShankar_Missing_number.java │ ├── UtkarshShankar_Repetitions.java │ ├── UtkarshShankar_TrailingZeors.java │ └── UtkarshShankar_Weird.java ├── ZeoShark │ ├── ZeoShark_Weird_Algorithm.java │ ├── Zeoshark_DistinctIntegers.java │ ├── Zeoshark_IncreasingArray.java │ ├── Zeoshark_MissingNumber.java │ ├── Zeoshark_Permutation.java │ ├── Zeoshark_Repetition.java │ └── Zeoshark_TrailingZeroes.java ├── aadityamittal │ ├── aadityamittal_BitStrings.java │ ├── aadityamittal_IncreasingArray.java │ ├── aadityamittal_MissingNumber.java │ ├── aadityamittal_Repetitions.java │ ├── aadityamittal_TrailingZeros.java │ ├── aadityamittal_TwoKnights.java │ └── aadityamittal_WeirdAlgorithm.java ├── adarsh1405 │ └── adarsh1405_weird_algorithm.java ├── agarwalsahil0210 │ ├── agarwalsahil0210_increasing_array.java │ ├── agarwalsahil0210_missing_number.java │ ├── agarwalsahil0210_permutations.java │ ├── agarwalsahil0210_repetitions.java │ └── agarwalsahil0210_weird_number.java.java ├── amohapatra123 │ ├── amohapatra123_distinct_numbers.java │ ├── amohapatra123_increasing_array.java │ ├── amohapatra123_maximum_subarray_sum.java │ ├── amohapatra123_missing_number.java │ └── amohapatra123_weird_algorithm.java ├── ankitsaebby │ ├── ankitsaebbyMissingNumber.java │ ├── ankitsaebbyTrailingZeros.java │ ├── ankitsaebbyWeirdAlgorithm.java │ ├── ankitsaebby_repetion.java │ └── ankitsaebby_two_knights.java ├── ash0202 │ ├── Ashish_DistinctNumbers.java │ ├── Ashish_MissingNumber.java │ ├── Ashish_WeirdAlgorithm.java │ ├── ash0202_BitString.java │ └── ash0202_TrailingZeros.java ├── debashishsamantara │ ├── debashishsamantara_BitStrings.java │ ├── debashishsamantara_CoinPiles.java │ ├── debashishsamantara_CreatingStringsI.java │ ├── debashishsamantara_DistinctNumbers.java │ ├── debashishsamantara_TrailingZeros.java │ ├── debashishsamantara_TwoKnights.java │ ├── debashishsamantara_WeirdAlgorithm.java │ ├── debashishsamantara_permutation.java │ └── debashishsamantara_repetitions.java ├── itsjohnty │ ├── Bookshop.java │ ├── Repetition.java │ ├── SmallestNumber.java │ ├── Trailingzeros.java │ ├── increasing_array.java │ ├── sumofdivisors.java │ └── weird_number.java ├── java.md ├── jigyasa-samal │ ├── jigyasa-samal_DistinctNumber.java │ ├── jigyasa-samal_MissingNumber.java │ ├── jigyasa-samal_SmallestNumber │ ├── jigyasa-samal_SumOfTwoValues.java │ └── jigyasa-samal_WeirdAlgorithm.java ├── kshitizranjan15 │ ├── kshitizranjan15_MissingNumber.java │ ├── kshitizranjan15_Repetitions.java │ ├── kshitizranjan15_TwoKnight.java │ ├── kshitizranjan15_weirdalgorithm.java │ └── kshitizranjn15_IncreasingArray.java ├── lipsamishra1609 │ ├── lipsamishra1609_distinctNumber.java │ ├── lipsamishra1609_increasingArray.java │ ├── lipsamishra1609_missingNumber.java │ ├── lipsamishra1609_repetitions.java │ └── lipsamishra1609_weirdAlgorithm.java ├── rahulkumarjha21 │ ├── rahulkumarjha21_Missing_Number.java │ ├── rahulkumarjha21_coin_piles.java │ ├── rahulkumarjha21_distinct_number.java │ ├── rahulkumarjha21_increasing_array.java │ ├── rahulkumarjha21_repetitions.java │ └── rahulkumarjha21_weird_algorithm.java ├── rituraj-iter │ ├── rituraj-iter_bit_string.java.java │ ├── rituraj-iter_distinct_number.java.java │ ├── rituraj-iter_increasing_array.java │ ├── rituraj-iter_missing_number.java │ ├── rituraj-iter_repetitions.java │ ├── rituraj-iter_sum_of_divisors.java.java │ ├── rituraj-iter_trailing_zeros.java.java │ ├── rituraj-iter_two_knights.java.java │ └── rituraj-iter_weird_algorithm.java ├── shobhnanayak99 │ └── shobhnanayak99_WeirdAlgorithm.java └── swetamukherjee │ ├── swetamukherjee_IncreasingArray.java │ ├── swetamukherjee_MissingNumber.java │ ├── swetamukherjee_Repetitions.java │ ├── swetamukherjee_TrailingZeros.java │ └── swetamukherjee_WeirdAlgorithm.java ├── nodejs ├── itspiyush01 │ ├── itsPiyush01_IncreasingArray.js │ ├── itsPiyush01_MissingNumber.js │ ├── itsPiyush01_Repetitions.js │ ├── itsPiyush01_TrailingZeros.js │ ├── itsPiyush01_TwoKnights.js │ └── itsPiyush01_WeirdAlgorithm.js └── js.md └── python ├── AkhileshMattam ├── AkhileshMattam_Distinct_Numbers.py ├── AkhileshMattam_Increasing_Array.py ├── AkhileshMattam_Missing_Number.py └── AkhileshMattam_Weird_Algorithm.py ├── Ashis-007 ├── Ashis-007_increasing_array.py ├── Ashis-007_missing_number.py ├── Ashis-007_permutations.py ├── Ashis-007_repetitions.py └── Ashis-007_weird_algorithm.py ├── DE-L-TA ├── de-l-ta__increasing_array.py ├── de-l-ta_missing_num.py ├── de-l-ta_repetation.py └── de-l-ta_two_num_sum.py ├── LoopGlitch26 ├── LoopGlitch26_DistinctNumbers.py └── LoopGlitch26_ReadingBooks.py ├── Prerna2001 ├── Prerna2001_bitStrings.py ├── Prerna2001_missingNumber.py ├── Prerna2001_repetations.py ├── Prerna2001_sumOfTwoValues.py └── Prerna2001_weirdAlgorithm.py ├── SandipNayak ├── SandipNayak_IncreasingArray.py ├── SandipNayak_MissingNumber.py ├── SandipNayak_Permutations.py ├── SandipNayak_Repetitions.py └── SandipNayak_WeirdAlgorithm.py ├── SanketKN ├── SanketKN_increasing_array.py ├── SanketKN_missing_number.py ├── SanketKN_repetitions.py ├── SanketKN_trailing_zeros.py └── SanketKN_weird_algorithm.py ├── Sharma_chanism ├── Sharma-chanism__Bit_Strings.py ├── Sharma-chanism__Missing_Number.py ├── Sharma-chanism__Reading_Books.py ├── Sharma_chanism__trailing_zeros.py └── Sharma_chanism__wierd_algorithm.py ├── SoumyaKB96 ├── SoumyaKB96_Bit_Strings.py ├── SoumyaKB96_SubArray_sum2.py ├── SoumyaKB96_Subarray_Divisibility.py ├── SoumyaKB96_missing_number.py └── SoumyaKB96_subarray_sum1.py ├── TheSpeedX ├── TheSpeedX_increasing_array.py ├── TheSpeedX_missing_number.py ├── TheSpeedX_permutation.py ├── TheSpeedX_repetitions.py └── TheSpeedX_wierd_number.py ├── ankita-04 ├── ankita-04_bitStrings.py ├── ankita-04_creatingStrings.py ├── ankita-04_maxSubarraySum.py ├── ankita-04_missingNumber.py ├── ankita-04_repetitions.py └── ankita-04_weirdAlgorithm.py ├── belikesayantan ├── belikesayantan_Distinct_Numbers.py ├── belikesayantan_maximum_subarray_sum.py ├── belikesayantan_stick_lengths.py ├── belikesayantan_subarray_sum.py └── belikesayantan_sum_of_two_values.py ├── bikash1317 ├── bikash1317_Bit_Strings.py ├── bikash1317_Distinct_Numbers.py ├── bikash1317_Sum_of_Divisors.py ├── bikash1317_Trailing_Zeros.py └── bikash1317_Weird_Algorithm.py ├── dishak331 ├── dishak331_bit_strings.py ├── dishak331_missing_number.py ├── dishak331_repetitions.py ├── dishak331_trailing_zeros.py └── dishak331_weird_algorithm.py ├── iamAbhishekkumar ├── iamAbhishekkumar_Permutations.py ├── iamAbhishekkumar_bit strings.py ├── iamAbhishekkumar_distinct_numbers.py ├── iamAbhishekkumar_repetitions.py └── iamAbhishekkumar_stick_lengths.py ├── nisargsheth ├── nisargsheth_Bit_Strings.py ├── nisargsheth_Creating_Strings_I.py ├── nisargsheth_Number_Spiral.py ├── nisargsheth_Trailing_Zeros.py └── nisargsheth_Two_Sets.py ├── nishantc7 ├── nishantc7_apartments.py ├── nishantc7_max_subarray_sum.py ├── nishantc7_playlists.py ├── nishantc7_reading_books.py └── nishantc7_restaurant_customers.py ├── obli99 ├── obli99_BitStrings.py ├── obli99_increasingArray.py ├── obli99_missingNumber.py ├── obli99_repetitions.py └── obli99_weirdAlgorithm.py ├── pritam047 ├── pritam047_bit_strings.py ├── pritam047_counting_divisors.py ├── pritam047_creating_strings_1.py ├── pritam047_missing_number.py ├── pritam047_trailing_zeros.py └── pritam047_weird_algorithm.py ├── python.md ├── saniya3 ├── saniya3_distinct_numbers.py ├── saniya3_increasing_array.py ├── saniya3_maximum_subarray_sum.py ├── saniya3_missing_number.py ├── saniya3_repetitions.py └── saniya3_weird_algorithm.py └── swetasahoo29 ├── swetasahoo29_Appartments ├── swetasahoo29_De_Bruijn_Sequence.py ├── swetasahoo29_distinct_no ├── swetasahoo29_readingbooks └── swetasahoo29_towers /README.md: -------------------------------------------------------------------------------- 1 | # CSES-Problems 2 | 3 | Here we will have collection of solution of cses.fi 4 | 5 | ## Info: 6 | 7 | - It will help you in Hacktoberfest 2020 8 | 9 | - Learning about Open source contributions 10 | 11 | ```You can star and fork this repository on GitHub by navigating at the top of this repository.``` 12 | 13 | ### CONTRIBUTE 14 | - Head over to [CONTRIBUTING.md](https://github.com/Hackodex-ITER/CSES-Problems/blob/master/CONTRIBUTING.md) to make Contributions 15 | 16 | ## Official Banner 17 | 18 | ![Banner](https://github.com/Hackodex-ITER/Hackodex-ITER/blob/master/Hacktober.png?raw=true) 19 | -------------------------------------------------------------------------------- /c_plus_plus/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/c_plus_plus/.DS_Store -------------------------------------------------------------------------------- /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< 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 | #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 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 -------------------------------------------------------------------------------- /c_plus_plus/AbHiSHekAB01/AbHiSHekAB01_DistinctNumbers.cpp: -------------------------------------------------------------------------------- 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 | //author:AbHiSHekAB01 4 | 5 | #include 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< 7 | using namespace std; 8 | int main() 9 | { 10 | long x; 11 | cin>>x; 12 | cout< 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< 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;i 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 | { 15 | long long n; 16 | cin>>n; 17 | while(n!=1) 18 | { 19 | cout< 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 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 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 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/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 | -------------------------------------------------------------------------------- /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/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<>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<>inp; 13 | 14 | std::cout<> 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<> 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<>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/ -------------------------------------------------------------------------------- /c_plus_plus/PratikSonal/PratikSonal_repetitions.cpp: -------------------------------------------------------------------------------- 1 | //Question 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 | //https://cses.fi/problemset/task/1069/ 4 | 5 | #include "iostream" 6 | 7 | int main(){ 8 | std::string dna; 9 | std::cin >> 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 | 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 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< 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 | } -------------------------------------------------------------------------------- /c_plus_plus/akbar1214/akbar1214_MissingNumber.cpp: -------------------------------------------------------------------------------- 1 | #include 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/akbar1214/akbar1214_TwoKnights.cpp: -------------------------------------------------------------------------------- 1 | #include 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 | } -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /c_plus_plus/akbar1214/akbar1214_permutations.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 | 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 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /c_plus_plus/goel28priyanshu/goel28priyanshu_trailing_zeros.cpp: -------------------------------------------------------------------------------- 1 | //Problem 2 | 3 | // Task is to calculate the number of trailing zeros in the factorial n!. 4 | 5 | //Link: https://cses.fi/problemset/task/1618/ 6 | 7 | 8 | #include 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 | -------------------------------------------------------------------------------- /c_plus_plus/jineshparakh/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/c_plus_plus/jineshparakh/.DS_Store -------------------------------------------------------------------------------- /c_plus_plus/pawank0411/pawank0411_Permutation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | A permutation of integers 1,2,…,n is called beautiful if there are no adjacent elements whose difference is 1. 3 | 4 | Given n, construct a beautiful permutation if such a permutation exists. 5 | 6 | Question Link : https://cses.fi/problemset/task/1070/ 7 | Profile Link : https://cses.fi/user/32415 8 | author : pawank0411 9 | */ 10 | 11 | #include 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/psib0t/psib0t_CoinCombinations1.cpp: -------------------------------------------------------------------------------- 1 | #include 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 | } -------------------------------------------------------------------------------- /c_plus_plus/psib0t/psib0t_CoinCombinations2.cpp: -------------------------------------------------------------------------------- 1 | #include 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 | } -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /c_plus_plus/saurabhNikam/saurabh-nikam_Bit_String.cpp: -------------------------------------------------------------------------------- 1 | // problem:Bit_Stirng 2 | // link: https://cses.fi/problemset/task/1617 3 | // author: saurabh_nikam 4 | // profile: https://cses.fi/user/32649 5 | 6 | 7 | #include 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 -------------------------------------------------------------------------------- /c_plus_plus/saurabhNikam/saurabh-nikam_Repetitions.cpp: -------------------------------------------------------------------------------- 1 | // problem:Repatations 2 | // link: https://cses.fi/problemset/task/1069 3 | // author: saurabh_nikam 4 | // profile: https://cses.fi/user/32649 5 | 6 | #include 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 -------------------------------------------------------------------------------- /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 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"< 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< 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 | #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< 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/ -------------------------------------------------------------------------------- /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 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 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 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 | -------------------------------------------------------------------------------- /c_plus_plus/subhamsagar524/subhamsagar524_trailing_zeros.cpp: -------------------------------------------------------------------------------- 1 | // Trailing Zeros 2 | // https://cses.fi/problemset/task/1618 3 | 4 | /* Given n as input, 5 | task: calculate the number of trailing zeros in the factorial n!. 6 | */ 7 | 8 | // submission: https://cses.fi/paste/e33826e28687e039109f77/ 9 | 10 | #include 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/Abhishek417374/Abhishek417374_distinct_number.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 | //https://cses.fi/problemset/task/1621 4 | 5 | //Author:Abhiserk417374 6 | 7 | import java.util.Arrays; 8 | import java.util.Scanner; 9 | public class Abhishek417374_distinct_number{ 10 | 11 | public static void main(String[] args) { 12 | Scanner s=new Scanner(System.in); 13 | int n=s.nextInt(); 14 | int a[]=new int[n]; 15 | 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/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/KejariwalAyush/kejariwalAyush_wierdAlgorithm.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 | // //author: KejariwalAyush 8 | 9 | import java.util.Scanner; 10 | 11 | public class kejariwalAyush_wierdAlgorithm { 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | long n = sc.nextInt(); 15 | sc.close(); 16 | 17 | System.out.print(n + " "); 18 | while (n > 1) { 19 | n = n % 2 == 0 ? n / 2 : n * 3 + 1; 20 | System.out.print(n + " "); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /java/LoopGlitch26/LoopGlitch26_MissingNumber.java: -------------------------------------------------------------------------------- 1 | // AUTHOR 2 | // Bravish ghosh 3 | // USER ID 4 | // https://cses.fi/user/34034 5 | // PROBLEM NUMBER 6 | // https://cses.fi/problemset/task/1083/ 7 | // QUESTION 8 | // You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 9 | 10 | import java.io.*; 11 | import java.util.*; 12 | 13 | public class MissingNumber { 14 | public static void main(String[] args) throws IOException { 15 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 16 | int n = Integer.parseInt(br.readLine()); 17 | boolean[] used = new boolean[n + 1]; 18 | StringTokenizer st = new StringTokenizer(br.readLine()); 19 | for (int i = 1; i < n; i++) { 20 | int a = Integer.parseInt(st.nextToken()); 21 | used[a] = true; 22 | } 23 | for (int a = 1; a <= n; a++) 24 | if (!used[a]) { 25 | System.out.println(a); 26 | return; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java/LoopGlitch26/LoopGlitch26_Repetitions.java: -------------------------------------------------------------------------------- 1 | // AUTHOR 2 | // Bravish ghosh 3 | // USER ID 4 | // https://cses.fi/user/34034 5 | // PROBLEM NUMBER 6 | // https://cses.fi/problemset/task/1069 7 | // QUESTION 8 | // 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. 9 | 10 | import java.io.*; 11 | 12 | public class LoopGlitch26_Repetitions { 13 | public static void main(String[] args) throws IOException { 14 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 15 | char[] ch = br.readLine().toCharArray(); 16 | int n = ch.length, ans = 1, p = 1; 17 | for (int i = 1; i < n; i++) { 18 | if (ch[i] == ch[i - 1]) 19 | p++; 20 | else 21 | p = 1; 22 | if (ans < p) 23 | ans = p; 24 | } 25 | System.out.println(ans); 26 | } 27 | } -------------------------------------------------------------------------------- /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;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_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=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/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/ -------------------------------------------------------------------------------- /java/RaviKumarPrasad/Raviruler_Missing_Number.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/java/RaviKumarPrasad/Raviruler_Missing_Number.java -------------------------------------------------------------------------------- /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= 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/RaviKumarPrasad/Raviruler_Weird_Algorithm.java: -------------------------------------------------------------------------------- 1 | /*Consider an algorithm that takes as input a positive integer n. 2 | If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 3 | The algorithm repeats this, until n is one. 4 | 5 | link : https://cses.fi/problemset/task/1068 6 | */ 7 | 8 | import java.util.*; 9 | public class Raviruler_Weird_Algorithm { 10 | public static void main(String[] args) { 11 | Scanner sc=new Scanner(System.in); 12 | long n =sc.nextInt(); 13 | while(n!=1) { 14 | System.out.print(n + " "); 15 | if (n % 2 == 0) n=(n / 2); 16 | else n=(3*n + 1); 17 | } 18 | System.out.print(n); 19 | } 20 | 21 | } 22 | //Author: Ravi Kumar Prasad 23 | //Git_hub Id: Raviruler 24 | //cses : https://cses.fi/user/32356/ -------------------------------------------------------------------------------- /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/Rishika6/Rishika6_missingNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/java/Rishika6/Rishika6_missingNumber.java -------------------------------------------------------------------------------- /java/SatyapragyanDas/SatyapragyanDas_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 | // Question Link: https://cses.fi/problemset/task/1069 3 | 4 | 5 | import java.util.Scanner; 6 | public class Repetitions { 7 | 8 | public static void main(String[] args) { 9 | // TODO Auto-generated method stub 10 | Scanner s1=new Scanner(System.in); 11 | String input=s1.nextLine(); 12 | s1.close(); 13 | int count=1, max=1; 14 | 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/SatyapragyanDas/Satyapragyan_MissingNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/java/SatyapragyanDas/Satyapragyan_MissingNumber.java -------------------------------------------------------------------------------- /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;x1) 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/Shivangibose/Shivangibose_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.On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 2 | //LINK:-https://cses.fi/problemset/task/1094 3 | import java.util.*; 4 | public class Shivangibose_increasing_array 5 | { 6 | 7 | public static void main(String[] args) 8 | { 9 | Scanner sc=new Scanner(System.in); 10 | long c=0; 11 | long z; 12 | int n=sc.nextInt(); 13 | int a[]=new int[n]; 14 | for(int x=0;x=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/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/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=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/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 | -------------------------------------------------------------------------------- /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/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;i1) 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/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 -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /java/ZeoShark/ZeoShark_Weird_Algorithm.java: -------------------------------------------------------------------------------- 1 | 2 | // Weird Algorithm 3 | //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: 4 | // 3→10→5→16→8→4→2→1 5 | 6 | //Problem link: https://cses.fi/problemset/task/1068 7 | 8 | //UserID: https://cses.fi/user/32264 9 | 10 | //Author:souravbera 11 | 12 | //Result: https://cses.fi/problemset/result/1065843/ 13 | import java.util.*; 14 | public class ZeoShark_Weird_Algorithm{ 15 | 16 | public static void main(String args[]){ 17 | Scanner in = new Scanner(System.in); 18 | long n= in.nextInt(); 19 | while(n!=1) 20 | { 21 | System.out.print(n+" "); 22 | if(n%2==0) 23 | n=n/2; 24 | else 25 | n=(n*3)+ 1; 26 | } 27 | System.out.println("1"); 28 | in.close(); 29 | } 30 | } -------------------------------------------------------------------------------- /java/ZeoShark/Zeoshark_DistinctIntegers.java: -------------------------------------------------------------------------------- 1 | //Distinct Integers 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 | //Problem Link: https://cses.fi/problemset/task/1621 5 | // Solution: https://cses.fi/problemset/result/1072944/ 6 | //Author: souravbera 7 | import java.util.*; 8 | public class Zeoshark_DistinctIntegers { 9 | public static void main(String args[]) 10 | { 11 | int m; 12 | Scanner in= new Scanner(System.in); 13 | int n=in.nextInt(); 14 | int a[]= new int[n]; 15 | int pos=1,f=0; 16 | a[0]= in.nextInt(); 17 | for(int i=1;i=1;i*=5) 21 | { 22 | count += n / i; 23 | } 24 | System.out.println(count); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /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/aadityamittal/aadityamittal_MissingNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 4 | 5 | https://cses.fi/problemset/task/1083 6 | */ 7 | public class MissingNo { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | long n = sc.nextLong(); 12 | long sum = n*(n+1)/2; 13 | long total = 0l; 14 | for(long i = 0l;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_TwoKnights.java: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 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 4 | they do not attack each other. 5 | 6 | 7 | 8 | https://cses.fi/problemset/task/1072/ 9 | 10 | */ 11 | 12 | 13 | 14 | 15 | import java.util.*; 16 | 17 | public class TwoKnights 18 | { 19 | public static void main(String[] args) 20 | { 21 | Scanner sc = new Scanner(System.in); 22 | long n = sc.nextLong(); 23 | for(long i=1; i<=n; i++){ 24 | System.out.println(TwoKnights(i)); 25 | } 26 | } 27 | static long TwoKnights(long n){ 28 | long th = 4*(n-1)*(n-2); 29 | 30 | long pos = (n*n*(n*n-1))/2; 31 | 32 | return pos-th; 33 | } 34 | } 35 | 36 | 37 | 38 | /*author:aadityamittal 39 | https://cses.fi/user/32817 40 | */ 41 | 42 | -------------------------------------------------------------------------------- /java/aadityamittal/aadityamittal_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:aadityamittal 35 | https://cses.fi/user/32817 36 | */ -------------------------------------------------------------------------------- /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/agarwalsahil0210/agarwalsahil0210_missing_number.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/java/agarwalsahil0210/agarwalsahil0210_missing_number.java -------------------------------------------------------------------------------- /java/agarwalsahil0210/agarwalsahil0210_permutations.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/java/agarwalsahil0210/agarwalsahil0210_permutations.java -------------------------------------------------------------------------------- /java/agarwalsahil0210/agarwalsahil0210_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 | // Question Link: https://cses.fi/problemset/task/1069 3 | 4 | 5 | import java.util.*; 6 | public class repititions { 7 | 8 | public static void main(String[] args) { 9 | 10 | Scanner in=new Scanner(System.in); 11 | String str=in.nextLine(); 12 | 13 | int count=1, max=1; 14 | for (int i=1;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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /java/ankitsaebby/ankitsaebby_two_knights.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | //Your task is to count for k=1,2,…,n the number of ways two knights can be placed on a 5 | //k×k chessboard so that they do not attack each other 6 | 7 | //author:ankitsaebby 8 | 9 | import java.util.*; 10 | public class ankitsaebby_two_knights { 11 | 12 | public static void main(String[] args) { 13 | Scanner s=new Scanner(System.in); 14 | System.out.println("enter your number"); 15 | int n =s.nextInt(); 16 | for(int i=1;i<=n;i++) { 17 | int w=ways(i); 18 | System.out.println(w); 19 | } 20 | 21 | } 22 | public static int ways(int n) { 23 | int s1=n*n*(n*n-1)/2; 24 | int s2=4*(n-1)*(n-2); 25 | return s1-s2; 26 | } 27 | 28 | } 29 | 30 | // cses id- https://cses.fi/user/32538 31 | -------------------------------------------------------------------------------- /java/ash0202/ash0202_BitString.java: -------------------------------------------------------------------------------- 1 | /* 2 | profile-https://cses.fi/user/32749 3 | link-https://cses.fi/problemset/task/1617/ 4 | 5 | Your task is to calculate the number of bit strings of length n. 6 | 7 | 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. 8 | 9 | Input 10 | 11 | The only input line has an integer n. 12 | 13 | Output 14 | 15 | Print the result modulo 109+7. 16 | 17 | Constraints 18 | 1≤n≤106 19 | Example 20 | 21 | Input: 22 | 3 23 | 24 | Output: 25 | 8 26 | 27 | */ 28 | import java.math.BigInteger; 29 | import java.util.Scanner; 30 | 31 | public class Ashish_BitString { 32 | static Scanner sc =new Scanner(System.in); 33 | public static void main(String[] args) 34 | { 35 | 36 | int s = sc.nextInt(); 37 | BigInteger two = new BigInteger("2"); 38 | BigInteger res = two.pow(s); 39 | System.out.println(res.mod(new BigInteger("1000000007"))); 40 | 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/debashishsamantara/debashishsamantara_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 | //Author : debashishsamantara 3 | //Profile : https://cses.fi/user/32389 4 | //Ques. link : https://cses.fi/problemset/task/1621/ 5 | 6 | import java.util.*; 7 | public class debashishsamantara_DistinctNumbers { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int x = sc.nextInt(); 11 | int a[] = new int[x]; 12 | for(int i=0; i=1; i*=5) 16 | { 17 | c+=x/i; 18 | } 19 | System.out.println(c); 20 | sc.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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=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/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/itsjohnty/weird_number.java: -------------------------------------------------------------------------------- 1 | //Consider an algorithm that takes as input a positive integer n. 2 | //If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. 3 | //https://cses.fi/problemset/task/1068/ 4 | 5 | import java.util.*; 6 | class weird_number 7 | { 8 | public static void main(String args[]) 9 | { 10 | Scanner in =new Scanner(System.in); 11 | long n=in.nextLong(); 12 | System.out.print(n);//1st number 13 | while(n!=1) 14 | { 15 | if(n%2==0) 16 | n=n/2; 17 | else 18 | n=n*3+1; 19 | System.out.print(" "+n); 20 | } 21 | } 22 | } 23 | 24 | //author: itsjohnty 25 | //https://cses.fi/problemset/result/1065804/ 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /java/jigyasa-samal/jigyasa-samal_MissingNumber.java: -------------------------------------------------------------------------------- 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 | */ 5 | 6 | import java.util.*; 7 | public class MissingNumber { 8 | public static void main(String args[]) { 9 | Scanner sc = new Scanner(System.in); 10 | long n = sc.nextInt(); 11 | long ele = 0, i, op, sum = 0; 12 | for (i = 1; i < n; i++) { 13 | ele = sc.nextInt(); 14 | sum = sum + ele; 15 | } 16 | op = (n * (n + 1) / 2) - sum; 17 | System.out.println(op); 18 | 19 | } 20 | } 21 | 22 | /* 23 | author : jigyasa-samal 24 | profile : https://cses.fi/user/32531 25 | */ 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /java/kshitizranjan15/kshitizranjan15_MissingNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/java/kshitizranjan15/kshitizranjan15_MissingNumber.java -------------------------------------------------------------------------------- /java/kshitizranjan15/kshitizranjan15_Repetitions.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | /* 3 | You are given a DNA sequence: a string consisting of characters A, C, G, and T. 4 | Your task is to find the longest repetition in the sequence. 5 | This is a maximum-length substring containing only one type of character. 6 | //https://cses.fi/problemset/task/1069/ 7 | */ 8 | public class Repetitions { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | String s = sc.nextLine(); 13 | int x = s.length(); 14 | long c = 1l,ans = 1l; 15 | for(int i = 1; i < x; i++) 16 | { 17 | if(s.charAt(i)==s.charAt(i-1)) 18 | { 19 | c++; 20 | } 21 | else{ 22 | ans = Math.max(c,ans); 23 | c = 1l; 24 | } 25 | }ans = Math.max(c,ans); 26 | System.out.println(ans); 27 | } 28 | } 29 | //author:- kshitizranjan15 30 | // https://cses.fi/user/32865 31 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /java/kshitizranjan15/kshitizranjn15_IncreasingArray.java: -------------------------------------------------------------------------------- 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 | //https://cses.fi/problemset/task/1094 6 | */ 7 | import java.util.Scanner; 8 | 9 | public class IncreasingArray 10 | { 11 | public static void main(String[] args) 12 | { 13 | Scanner sc = new Scanner(System.in); 14 | int x = sc.nextInt(); 15 | long[] array = new long[x]; 16 | for(int i = 0; i < x; i++){ 17 | array[i] = sc.nextLong(); 18 | } 19 | long tot = 0l; 20 | long b= array[0]; 21 | for (int i = 1; i < x; i++) 22 | { 23 | tot += Math.max(0L, b - array[i]); 24 | b = Math.max(b, array[i]); 25 | } 26 | System.out.println(tot); 27 | 28 | 29 | } 30 | } 31 | // author:- kshitizranjan15 32 | //https://cses.fi/user/32865 -------------------------------------------------------------------------------- /java/lipsamishra1609/lipsamishra1609_distinctNumber.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/java/lipsamishra1609/lipsamishra1609_distinctNumber.java -------------------------------------------------------------------------------- /java/lipsamishra1609/lipsamishra1609_increasingArray.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hacktoberfest-ITER/CSES-Problems/c290be786233a56857d704213e04813b1a08bac1/java/lipsamishra1609/lipsamishra1609_increasingArray.java -------------------------------------------------------------------------------- /java/rahulkumarjha21/rahulkumarjha21_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 | import java.io.*; 4 | public class Repetitions 5 | { 6 | public static void main(String args[])throws IOException 7 | { 8 | BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); 9 | String s=in.readLine(); 10 | int c=1,max=1; 11 | for(int i=1;imax) 18 | max=c; 19 | } 20 | System.out.println(max); 21 | } 22 | } 23 | // author: rahulkumarjha21 24 | // profile: https://cses.fi/user/32483 -------------------------------------------------------------------------------- /java/rituraj-iter/rituraj-iter_bit_string.java.java: -------------------------------------------------------------------------------- 1 | // Your task is to calculate the number of bit strings of length n. 2 | // https://cses.fi/problemset/task/1617/ 3 | import java.util.Scanner; 4 | public class Test8 { 5 | public static void main(String[] args) { 6 | final int m_mod=1000000007; 7 | Scanner sc=new Scanner(System.in); 8 | int i=1; 9 | int n=sc.nextInt(); 10 | while(n-->0){ 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 -------------------------------------------------------------------------------- /java/rituraj-iter/rituraj-iter_distinct_number.java.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 | import java.util.*; 4 | public class Test2 { 5 | public static void main(String[] args){ 6 | Scanner sc=new Scanner(System.in); 7 | int n=sc.nextInt(); 8 | int arr[]=new int[n]; 9 | for (int i = 0; i < n; i++) 10 | arr[i] =sc.nextInt(); 11 | Arrays.sort(arr); 12 | int c = 1; 13 | for (int i = 1; i < n; i++) 14 | if ((int) arr[i]!=arr[i - 1]) 15 | c++; 16 | System.out.println(c); 17 | } 18 | } 19 | // author: rituraj-iter 20 | // profile: https://cses.fi/user/32401 -------------------------------------------------------------------------------- /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=5){ 11 | c+=(n/=5); 12 | } 13 | System.out.println(c); 14 | } 15 | } 16 | // author: rituraj-iter 17 | // profile: https://cses.fi/user/32401 -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /java/swetamukherjee/swetamukherjee_MissingNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 4 | 5 | https://cses.fi/problemset/task/1083 6 | */ 7 | public class MissingNo { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | long n = sc.nextLong(); 12 | long sum = n*(n+1)/2; 13 | long total = 0l; 14 | for(long i = 0l;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 | */ -------------------------------------------------------------------------------- /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 | */ -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /nodejs/itspiyush01/itsPiyush01_TrailingZeros.js: -------------------------------------------------------------------------------- 1 | /* 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 | Link : https://cses.fi/problemset/task/1618 6 | Author : Piyush Ranjan 7 | GitHub_Id : itsPiyush01 8 | Profile : https://cses.fi/user/32379 9 | */ 10 | 11 | const readline = require("readline").createInterface({ 12 | input: process.stdin, 13 | output: process.stdout, 14 | }); 15 | 16 | let n; 17 | readline.question("", (X) => { 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 | -------------------------------------------------------------------------------- /nodejs/itspiyush01/itsPiyush01_TwoKnights.js: -------------------------------------------------------------------------------- 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 | 4 | Link : https://cses.fi/problemset/task/1072/ 5 | Author : Piyush Ranjan 6 | GitHub_Id : itsPiyush01 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 | let n; 16 | 17 | function TwoKnights(n) { 18 | th = 4 * (n - 1) * (n - 2); 19 | pos = (n * n * (n * n - 1)) / 2; 20 | return pos - th; 21 | } 22 | 23 | readline.question("", (X) => { 24 | n = parseInt(X); 25 | 26 | for (let i = 1; i <= n; i++) { 27 | console.log(TwoKnights(i)); 28 | } 29 | readline.close(); 30 | }); 31 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/AkhileshMattam/AkhileshMattam_Distinct_Numbers.py: -------------------------------------------------------------------------------- 1 | #You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 2 | # program link:https://cses.fi/problemset/task/1621 3 | # author:AkhileshMattam 4 | # profile link:https://cses.fi/user/3234 5 | n = int(input()) 6 | l1 = input().split()[:n] 7 | new = len(set(l1)) 8 | print(new) 9 | 10 | 11 | -------------------------------------------------------------------------------- /python/AkhileshMattam/AkhileshMattam_Increasing_Array.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 | # program link:https://cses.fi/problemset/task/1094 4 | # author:AkhileshMattam 5 | # profile link:https://cses.fi/user/32346 6 | n = int(input()) 7 | l1 = list(map(int,input().split()))[:n] 8 | t = 0 9 | for i in range(1,n): 10 | if l1[i-1]>l1[i]: 11 | t+=(l1[i-1]-l1[i]) 12 | l1[i]=l1[i-1] 13 | print(t) 14 | -------------------------------------------------------------------------------- /python/AkhileshMattam/AkhileshMattam_Missing_Number.py: -------------------------------------------------------------------------------- 1 | # Time limit: 1.00 s Memory limit: 512 MB 2 | # You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 3 | # program link:https://cses.fi/problemset/task/1083/ 4 | # Author:AkhileshMattam 5 | # profile link:https://cses.fi/user/32346 6 | n = int(input()) 7 | l = list(map(int,input().split()))[:n-1] 8 | t = 0 9 | for j in range(n-1): 10 | t+=l[j] 11 | for i in range(1,(n+1)): 12 | t-=i 13 | print(abs(t)) 14 | 15 | -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /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/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/Ashis-007/Ashis-007_permutations.py: -------------------------------------------------------------------------------- 1 | # Question 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 | 5 | # Link 6 | # https://cses.fi/problemset/task/1070/ 7 | 8 | n= int(input()) 9 | 10 | if (n==2 or n==3): 11 | print("NO SOLUTION") 12 | elif (n==4): 13 | print("3 1 4 2") 14 | else: 15 | perm=[str(i) for i in range (1,n+1,2)] 16 | perm+=[str(i) for i in range (2,n+1,2)] 17 | print(" ".join(perm)) 18 | 19 | # author: Ashis-007 20 | # profile: https://cses.fi/user/32353 21 | # Solution: https://cses.fi/problemset/result/1135658/ -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/DE-L-TA/de-l-ta__increasing_array.py: -------------------------------------------------------------------------------- 1 | #link-problem:https://cses.fi/problemset/task/1094 2 | #Author-Mayank Sahu 3 | #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. 4 | #On each turn, you may increase the value of any element by one. What is the minimum number of turns required? 5 | 6 | i=input 7 | t=i() 8 | n,c,d=0,1,1 9 | 10 | 11 | for i in i().split(): 12 | i=int(i) 13 | d+=1 14 | if c>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 | -------------------------------------------------------------------------------- /python/DE-L-TA/de-l-ta_missing_num.py: -------------------------------------------------------------------------------- 1 | #Author-Mayank Sahu 2 | #You are given an array of n integers, and your task is to find two values (at distinct positions) whose sum is x. 3 | #link-question:https://cses.fi/problemset/task/1640 4 | 5 | 6 | i=input 7 | t,s=int(i()),0 8 | 9 | for i in i().split(): 10 | s+=int(i) 11 | print(t*(t+1)//2-s) -------------------------------------------------------------------------------- /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/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/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() -------------------------------------------------------------------------------- /python/LoopGlitch26/LoopGlitch26_ReadingBooks.py: -------------------------------------------------------------------------------- 1 | # AUTHOR 2 | # Bravish Ghosh 3 | # USER ID 4 | # https://cses.fi/user/34034 5 | # PROBLEM NUMBER 6 | # https://cses.fi/problemset/task/1631 7 | # QUESTION 8 | # 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. 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 | 10 | n,j=int(input()),list(map(int,input().split())) 11 | print(sum(j) if sum(j)-max(j)>=max(j) else max(j)*2) 12 | -------------------------------------------------------------------------------- /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/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/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/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 -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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/SandipNayak/SandipNayak_MissingNumber.py: -------------------------------------------------------------------------------- 1 | # Author: Sandip Nayak 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 | #userId: https://cses.fi/user/34086 5 | 6 | num = int(input()) 7 | array=map(int,input().split()) 8 | print(int(((num*(num+1))/2)-sum(array))) 9 | -------------------------------------------------------------------------------- /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/SandipNayak/SandipNayak_Repetitions.py: -------------------------------------------------------------------------------- 1 | # Author: Sandip Nayak 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 | # userId: https://cses.fi/user/34086 6 | 7 | num = input() 8 | def count(num): 9 | b=c=0 10 | for i in range(0,len(num)): 11 | if num[i]==num[i-1]: 12 | c+=1 13 | b=max(b,c) 14 | else: 15 | c=1 16 | b=max(b,c) 17 | print(b) 18 | 19 | count(num) 20 | 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /python/SanketKN/SanketKN_missing_number.py: -------------------------------------------------------------------------------- 1 | #Missing Number 2 | #You are given all numbers between 1,2,…,n except one. 3 | #Your task is to find the missing number. 4 | #problem link: https://cses.fi/problemset/task/1083 5 | #user id: SanketKN 6 | #cses user link: https://cses.fi/user/33432 7 | 8 | x = int(input()) 9 | n = list(map(int,input().split()))[:x-1] 10 | y = (x*(x+1)//2)-sum(n) 11 | print(y) 12 | -------------------------------------------------------------------------------- /python/SanketKN/SanketKN_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. 4 | #problem link: https://cses.fi/problemset/task/1069 5 | #user id: SanketKN 6 | #cses user link: https://cses.fi/user/33432 7 | 8 | x = input() 9 | k = f = 1 10 | for i in range(0,len(x)-1): 11 | if x[i] == x[i+1]: 12 | f+=1 13 | k = max(f,k) 14 | else: 15 | f = 1 16 | print(k) 17 | -------------------------------------------------------------------------------- /python/SanketKN/SanketKN_trailing_zeros.py: -------------------------------------------------------------------------------- 1 | #Trailing Zeros 2 | #Your task is to calculate the number of trailing zeros in the factorial n!. 3 | #problem link: https://cses.fi/problemset/task/1618 4 | #user id: SanketKN 5 | #cses user link: https://cses.fi/user/33432 6 | 7 | x = int(input()) 8 | k = 0 9 | while(x>4): 10 | x//=5 11 | k+=x 12 | print(k) 13 | -------------------------------------------------------------------------------- /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/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/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/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/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/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 | -------------------------------------------------------------------------------- /python/SoumyaKB96/SoumyaKB96_Bit_Strings.py: -------------------------------------------------------------------------------- 1 | #Q. Your task is to calculate the number of bit strings of length n. 2 | #Qn Link - https://cses.fi/problemset/task/1617/ 3 | 4 | a=int(input()) 5 | 6 | print((2**a)%(10**9 + 7)) 7 | 8 | 9 | 10 | 11 | 12 | # Author : SoumyaKB96 13 | # profile : https://cses.fi/user/32322 14 | -------------------------------------------------------------------------------- /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_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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /python/TheSpeedX/TheSpeedX_increasing_array.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 | 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 | 6 | n = int(input()) 7 | arr = list(map(int,input().strip().split())) 8 | total=0 9 | m=arr[0] 10 | for i in arr: 11 | total+=max(0,m-i) 12 | m=max(m,i) 13 | print(total) 14 | 15 | # author: deadcoder 16 | # https://cses.fi/user/32336 -------------------------------------------------------------------------------- /python/TheSpeedX/TheSpeedX_missing_number.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 | n= int(input()) 5 | numlist=list(map(int,input().strip().split())) 6 | print(n*(n+1)//2-sum(numlist)) 7 | 8 | # author: deadcoder 9 | # https://cses.fi/user/32336 -------------------------------------------------------------------------------- /python/TheSpeedX/TheSpeedX_permutation.py: -------------------------------------------------------------------------------- 1 | # A permutation of integers 1,2,…,n is called beautiful if there are no adjacent elements whose difference is 1. 2 | 3 | # Given n, construct a beautiful permutation if such a permutation exists. 4 | # https://cses.fi/problemset/task/1070/ 5 | 6 | n= int(input()) 7 | if (n==2 or n==3): 8 | print("NO SOLUTION") 9 | elif (n==4): 10 | print("3 1 4 2") 11 | else: 12 | perm=[str(i) for i in range (1,n+1,2)] 13 | perm+=[str(i) for i in range (2,n+1,2)] 14 | print(" ".join(perm)) 15 | 16 | # author: deadcoder 17 | # https://cses.fi/user/32336 -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /python/TheSpeedX/TheSpeedX_wierd_number.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 | # https://cses.fi/problemset/task/1068/ 6 | 7 | n=int(input()) 8 | print(n,end=" ") 9 | while (n!=1): 10 | n = n//2 if n%2==0 else n*3+1 11 | print(n,end=" ") 12 | 13 | # author: deadcoder 14 | # solution: https://cses.fi/problemset/result/1065540/ -------------------------------------------------------------------------------- /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_creatingStrings.py: -------------------------------------------------------------------------------- 1 | # Author: Ankita Satapathy 2 | # generate all different strings that can be created using its characters. 3 | # https://cses.fi/problemset/task/1622/ 4 | # userId: https://cses.fi/user/32881 5 | 6 | from itertools import permutations 7 | n = input() 8 | p = permutations(n) 9 | arraylist = [] 10 | for x in list(p): 11 | arraylist.append(''.join(i)) 12 | alist = sorted(list(set(arraylist))) 13 | print(len(alist)) 14 | 15 | for y in alist: 16 | print(j) 17 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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()])) -------------------------------------------------------------------------------- /python/belikesayantan/belikesayantan_maximum_subarray_sum.py: -------------------------------------------------------------------------------- 1 | # author: https://cses.fi/user/32392 2 | # @belikesayantan 3 | 4 | '''Sorting and Searching - Maximum Subarray Sum''' 5 | n = int(input()) 6 | arr = [int(x) for x in input().split()] 7 | 8 | curr, best = arr[0], arr[0] 9 | for i in range(1, len(arr)): 10 | curr = max(curr + arr[i], arr[i]) 11 | best = max(best, curr) 12 | 13 | print(best) -------------------------------------------------------------------------------- /python/belikesayantan/belikesayantan_stick_lengths.py: -------------------------------------------------------------------------------- 1 | # author: https://cses.fi/user/32392 2 | # @belikesayantan 3 | 4 | ''' Stick Lengths - https://cses.fi/problemset/task/1074 5 | There are n sticks with some lengths. Your task is to modify the sticks so that each stick has the same length. 6 | 7 | You can either lengthen and shorten each stick. Both operations cost x where x is the difference between the new and original length. 8 | 9 | What is the minimum total cost? 10 | ''' 11 | from typing import List 12 | 13 | 14 | def sticklengths(n: int, arr: List[int]) -> 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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /python/bikash1317/bikash1317_Bit_Strings.py: -------------------------------------------------------------------------------- 1 | # User ID : https://cses.fi/user/32480 2 | 3 | # Problem Number: https://cses.fi/problemset/task/1617/ 4 | 5 | # Aurthor: bikash1317 6 | 7 | # Question: 8 | # Time limit: 1.00 s Memory limit: 512 MB 9 | # Your task is to calculate the number of bit strings of length n. 10 | 11 | # 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. 12 | 13 | 14 | mod = 1000000007 15 | number = int (input('')) 16 | i = 1 17 | while (number > 0): 18 | i = (i*2)%mod 19 | number = number -1 20 | print (int(i)) -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /python/bikash1317/bikash1317_Sum_of_Divisors.py: -------------------------------------------------------------------------------- 1 | # User ID : https://cses.fi/user/32480 2 | 3 | # Problem Number: https://cses.fi/problemset/result/1133272/ 4 | 5 | # Aurthor: bikash1317 6 | 7 | # Question: 8 | # Let σ(n) denote the sum of divisors of an integer n. For example, σ(12)=1+2+3+4+6+12=28. 9 | 10 | # Your task is to calculate the sum ∑ni=1σ(i) modulo 109+7. 11 | 12 | # Input 13 | 14 | # The only input line has an integer n. 15 | 16 | def sumOfDivisors(n): 17 | ans=0 18 | i=1 19 | while(i<=n): 20 | r=n//(n//i) 21 | ans+=(n//i)*((r*(r+1))//2-i*(i-1)//2) 22 | i=r+1 23 | return ans%(10**9+7) 24 | n=int(input()) 25 | print(sumOfDivisors(n)) -------------------------------------------------------------------------------- /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/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)) -------------------------------------------------------------------------------- /python/dishak331/dishak331_bit_strings.py: -------------------------------------------------------------------------------- 1 | # Print your Name 2 | # cses.fi/printName 3 | print('Disha Kapoor') 4 | # author: dishak331 5 | # solution: https://cses.fi/problemset/result/1068272/ 6 | 7 | mod = 1000000007 8 | 9 | 10 | def power(x, y, p): 11 | res = 1 12 | 13 | x = x % p 14 | 15 | while (y > 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 | -------------------------------------------------------------------------------- /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/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 maxx=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/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/iamAbhishekkumar/iamAbhishekkumar_Permutations.py: -------------------------------------------------------------------------------- 1 | # user id : 2 | # https://cses.fi/user/32366 3 | 4 | # A permutation of integers 1,2,…,n is called beautiful if there are no adjacent elements whose difference is 1. 5 | # Given n, construct a beautiful permutation if such a permutation exists. 6 | # https://cses.fi/problemset/task/1070/ 7 | # author : iamAbhishekkumar 8 | 9 | n = int(input()) 10 | if n == 1: 11 | print(1) 12 | elif n < 4: 13 | print("NO SOLUTION") 14 | elif n == 4: 15 | print("3 1 4 2") 16 | else: 17 | for i in range(1, n+1, 2): 18 | print(i, end=" ") 19 | for i in range(2, n+1, 2): 20 | print(i, end=" ") 21 | -------------------------------------------------------------------------------- /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/iamAbhishekkumar/iamAbhishekkumar_distinct_numbers.py: -------------------------------------------------------------------------------- 1 | # user id : 2 | # https://cses.fi/user/32366 3 | 4 | # You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 5 | # https://cses.fi/problemset/task/1621/ 6 | # author : iamAbhishekkumar 7 | 8 | n = input() 9 | m = list(input().split()) 10 | print(len(set(m))) 11 | -------------------------------------------------------------------------------- /python/iamAbhishekkumar/iamAbhishekkumar_repetitions.py: -------------------------------------------------------------------------------- 1 | # user id : 2 | # https://cses.fi/user/32366 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 5 | # repetition in the sequence. This is a maximum-length substring containing only one type of character. 6 | # https://cses.fi/problemset/task/1069/ 7 | # author : iamAbhishekkumar 8 | 9 | s = input() 10 | count = 1 11 | lis = [] 12 | for i in range(len(s) - 1): 13 | if s[i] == s[i + 1]: 14 | count += 1 15 | else: 16 | lis.append(count) 17 | count = 1 18 | lis.append(count) 19 | print(max(lis)) 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/nisargsheth/nisargsheth_Creating_Strings_I.py: -------------------------------------------------------------------------------- 1 | # Question 2 | # Given a string, your task is to generate all different strings that can be created using its characters. 3 | 4 | 5 | # Link 6 | # https://cses.fi/problemset/task/1622 7 | 8 | from itertools import permutations 9 | def main(): 10 | string = input() 11 | permList = permutations(string) 12 | permList = sorted(set(permList)) 13 | print(len(permList)) 14 | for perm in permList: 15 | print(''.join(perm)) 16 | main() 17 | 18 | # author: nisargsheth 19 | # profile: https://cses.fi/user/9669 20 | # solution: https://cses.fi/problemset/result/384136/ 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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 -------------------------------------------------------------------------------- /python/nishantc7/nishantc7_restaurant_customers.py: -------------------------------------------------------------------------------- 1 | # Restaurant Customers : You are given the arrival and leaving times of n customers in a restaurant. What was the maximum number of customers? 2 | # https://cses.fi/problemset/task/1619/ 3 | 4 | 5 | import sys 6 | def max_people(times): 7 | count, max_count = 0, 0 8 | 9 | for time in times: 10 | count = count + time[1] 11 | 12 | if count > 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 -------------------------------------------------------------------------------- /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)) -------------------------------------------------------------------------------- /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) -------------------------------------------------------------------------------- /python/obli99/obli99_missingNumber.py: -------------------------------------------------------------------------------- 1 | # You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 2 | # Question Link: https://cses.fi/problemset/task/1083/ 3 | # Author : jyotij 4 | # profile : https://cses.fi/user/32333 5 | # solution : https://cses.fi/problemset/result/1134619/ 6 | n = int(input()) 7 | array=map(int,input().split()) 8 | print(int(((n*(n+1))/2)-sum(array))) 9 | -------------------------------------------------------------------------------- /python/obli99/obli99_repetitions.py: -------------------------------------------------------------------------------- 1 | # Question: 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 | # author: jyotij 4 | # profile: https://cses.fi/user/32333 5 | # solution: https://cses.fi/problemset/result/1138905/ 6 | 7 | st = input() 8 | def count(st): 9 | x = 0 10 | y = 0 11 | for i in range(0,len(st)): 12 | if st[i]==st[i-1]: 13 | y=y+1 14 | x=max(x,y) 15 | else: 16 | y=1 17 | x=max(x,y) 18 | print(x) 19 | 20 | count(st) -------------------------------------------------------------------------------- /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=" ") -------------------------------------------------------------------------------- /python/pritam047/pritam047_bit_strings.py: -------------------------------------------------------------------------------- 1 | # USER ID 2 | # https://cses.fi/user/32269 3 | # PROBLEM NUMBER 4 | # https://cses.fi/problemset/task/1617/ 5 | # Your task is to calculate the number of bit strings of length n. 6 | # QUESTION 7 | # 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. 8 | n= int(input()) 9 | print((2**n) % ((10**9)+7)) -------------------------------------------------------------------------------- /python/pritam047/pritam047_counting_divisors.py: -------------------------------------------------------------------------------- 1 | # USER ID 2 | # https://cses.fi/user/32269 3 | # PROBLEM NUMBER 4 | # https://cses.fi/problemset/task/1713/ 5 | # QUESTION 6 | # Given n integers, your task is to report for each integer the number of its divisors. 7 | # For example, if x=18, the correct answer is 6 because its divisors are 1,2,3,6,9,18. 8 | # ------------------------------------------------------------------------------------------------- 9 | import math 10 | n= int(input()) 11 | # for x in range() 12 | # numarray=map(int,input().split()) 13 | arrlist = [] 14 | for x in range(0,n): 15 | arrlist.append(int(input())) 16 | # print(numarray) 17 | def countDivisors(n): 18 | count = 0 19 | for i in range(1,(int)(math.sqrt(n))+1) : 20 | if (n % i == 0) : 21 | if (n / i == i): 22 | count = count + 1 23 | else: 24 | count = count + 2 25 | 26 | print(count) 27 | 28 | for y in arrlist: 29 | countDivisors(y) 30 | 31 | # countDivisors(n) -------------------------------------------------------------------------------- /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/pritam047/pritam047_missing_number.py: -------------------------------------------------------------------------------- 1 | # USER ID 2 | # https://cses.fi/user/32269 3 | # PROBLEM NUMBER 4 | # https://cses.fi/problemset/task/1083/ 5 | # QUESTION 6 | # You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 7 | n = int(input()) 8 | n1array=map(int,input().split()) 9 | print(int(((n*(n+1))/2)-sum(n1array))) -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/saniya3/saniya3_maximum_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 | array = [int(x) for x in input().split()] 6 | Sub=array[0] 7 | Sum=0 8 | for i in array: 9 | if Sum<0 : 10 | Sum=0 11 | Sum+=i 12 | Sub=max(Sum,Sub) 13 | print(Sub) 14 | 15 | # author: saniya3 16 | # https://cses.fi/user/32262 -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /python/swetasahoo29/swetasahoo29_Appartments: -------------------------------------------------------------------------------- 1 | # PROBLEM NUMBER 2 | # https:https://cses.fi/problemset/task/1084/ 3 | # Sweta Snigdha Sahoo 4 | # author : swetasahoo29 5 | # QUESTION 6 | # 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. 7 | 8 | # Each applicant has a desired apartment size, and they will accept any apartment whose size is close enough to the desired size. 9 | 10 | def t():return map(int,input().split()) 11 | x,y,k=t() 12 | a,b,c,j,i=sorted(t()),sorted(t()),0,0,0 13 | while ib[j]: 17 | j+=1 18 | else: 19 | c+=1 20 | j+=1 21 | i+=1 22 | print(c) 23 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /python/swetasahoo29/swetasahoo29_towers: -------------------------------------------------------------------------------- 1 | # PROBLEM NUMBER 2 | # https://cses.fi/problemset/task/1073 3 | # Sweta Snigdha Sahoo 4 | # author : swetasahoo29 5 | # QUESTION 6 | # You are given n cubes in a certain order, and your task is to build towers using them. Whenever two cubes are one on top of the other, the upper cube must be smaller than the lower cube. 7 | 8 | # You must process the cubes in the given order. You can always either place the cube on top of an existing tower, or begin a new tower. What is the minimum possible number of towers? 9 | from bisect import bisect_right 10 | l,t,n,x=[],0,int(input()),[int(i)for i in input().split()] 11 | for i in x: 12 | b=bisect_right(l,i) 13 | if b>=t: 14 | l+=[i] 15 | t+=1 16 | else: 17 | l[b]=i 18 | print(t) 19 | --------------------------------------------------------------------------------