forked from GDSC-JSCOE/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeginner.txt
1524 lines (1277 loc) · 31.7 KB
/
Beginner.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Example :
Solution :
# Python
age=input(int("Age : "))
print(age);
Maintainer : Gaurav-2803
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
1. Write a program that asks the user for their name and greets (Hi!, Hey!, Hello!, etc) them with their name.
Example : (Hi!, Gaurav)
Solution :
#include <iostream>
using namespace std;
int main(){
string name;
cout<<" Enter Name : ";
cin>>name;
cout<<"Hi "+name;
return 0;
}
#Solved Q no 1 using python
#python
name=input("Enter your name: ")
print("Hello!,",name)
# rust
use std::io::{self, Write};
fn main() {
let mut name = String::new();
print!("Enter you name: ");
io::stdout().flush().unwrap();
io::stdin()
.read_line(&mut name)
.expect("Failed to read name");
println!("Hello, {}", name);
}
# Java
import java.util.Scanner;
public class Greet {
static Scanner scanner = new Scanner(System.in);
public static void greet(String name){
System.out.println("Hello, "+name);
}
public static void main(String[] args) {
System.out.print("Enter your name : ");
String name = scanner.next();
greet(name);
}
}
2. Modify the previous program (i.e. Q.1) such that only the users Alice and Bob are greeted with their names.
Solution :
#include<iostream>
using namespace std;
int main(){
string name;
cout<<" Enter Name : ";
cin>>name;
if(name=="Alice" || name=="bob")
{
cout<<"Hi "+name;
}else{
cout<<"Hi";
}
return 0;
}
#solved Q no 2 using python
# Python
name = input("Enter name: ")
if(name=="Alice" or name=="Bob"):
print("Hi!, "+name);
3. Write a program that asks the user for a number n and prints the sum of the numbers 1 to n
Solution :
//include <iostream>
using namespace std;
int main()
{
int n, a;
a = 0;
cin >> n;
n++;
while (n--)
{
a = a + n;
}
cout << a;
return 0;
}
//another method
include <iostream>
using namespace std;
int main()
{
int n, a;
a = 0;
cin>>n;
cout << (n*(n+1))/2;
return 0;
}
#solved Q no 3 using python
#python
num = int(input("Enter numer n: "))
if num < 0:
print("Enter a positive number")
else:
sum = 0
while(num > 0):
sum += num
num -= 1
print("The sum is", sum)
# Java
import java.util.Scanner;
public class Sum {
public static int sum(int n){
if(n == 0){
return 0;
}
else if (n == 1){
return 1;
}
else {
return sum(n-1)+(n);
}
}
public static void main(String [] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number : ");
int n = scanner.nextInt();
System.out.println(sum(n));
}
}
4. Modify the previous program (i.e. Q.3) such that only multiples of three or five are considered in the sum, e.g. 3, 5, 6, 9, 10, 12, 15 for n=17
Solution :
#include <iostream>
using namespace std;
int main()
{
int n, ans;
ans = 0;
cin >> n;
n++;
while (n--)
{
if (n % 3 == 0 || n % 5 == 0)
{
ans = ans + n;
}
}
cout << ans;
return 0;
}
5. Write a program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,…,n.
Solution :
x=int(input('Enter a number :'))
y=input('Compute the sum or Compute the product(s/m) ? :')
sum=0
multi=1
for i in range(1,x+1):
if y=='s':
sum=sum+i
if y=='m':
multi=multi*i
if y=='s':
print('Sum :',sum)
if y=='m':
print('Product :',multi)
======= In C++ ==========
#include <iostream>
using namespace std;
int main() {
int n, a, b;
a = 0;
b = 1;
cin >> n;
n++;
while (n--) {
a = a + n;
b = b * n;
}
cout << "Sum or Product (s/p) : ";
char c;
cin >> c;
if (c == 's')
cout << "Sum : " << a << endl;
else if (c == 'p')
cout << "Product : " << b << endl;
else
cout << "Invalid Input";
return 0;
}
==========================
6. Write a program that prints a multiplication table for numbers up to 12.
Solution :
#include <iostream>
using namespace std;
int main()
{
int a;
for(int j=1; j<=12; j++)
{
for (int i = 1; i <= 10; i++)
{
a = j * i;
cout << a << endl;
}
}
return 0;
}
# Java
public class Multiplication {
public static void table(int n){
for (int i = 1; i < 11; i++) {
System.out.print(i*n+" ");
}
System.out.println();
}
public static void main(String[] args) {
for (int i = 1; i < 13 ; i++){
table(i);
}
}
}
7. Write a program that prints all prime numbers between 2 numbers.
Solution :
//cpp
class Solution {
public:
bool isprime(int n){
if(n<=1)
return false;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0)
return false;
}
return true;
}
void primeRange(int M, int N) {
vector<int>ans;
for(M;M<=N;M++){
if(isprime(M))
ans.push_back(M);
}
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
}
};
print('Enter two numbers :')
x=int(input())
y=int(input())
print('Prime numbers : ',end=' ')
for i in range(x,y+1):
cnt=0
for j in range(1,i+1):
if i%j==0:
cnt+=1
if cnt==2:
print(i,end=' ')
8. Write a program that prints the next 20 leap years.
Solution :
Code:
#include<stdio.h>
int nr_leap_years(int y){
return( y/4 - y/100 + y/400 );
}
int is_leap_year(int y)
{
return(nr_leap_years(y) - nr_leap_years(y-1));
}
int main(void){
int nr,i;
nr = 0;
i = 2021;
while(nr<20){
if (is_leap_year(i)){
printf(“\n %d”, i);
nr++;
}
i++;
}
return(0);
}
---------------JAVA-----------------------
import java.util.*;
class LeapYear {
public static void main (String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the year to check for leap year.");
int year = sc.nextInt();
System.out.println("The next 20 leap years from the given year " + year+ " are: ");
int count =0;
while(count != 20){
year = year+4;
if((year%400==0) || (year%4==0 && year%100 != 0)){
System.out.println(year);
}
count++;
}
]
]
9. Write a function that returns the largest element in a array.
Solution :
class Main{
public static void main(String[] args){
int[] arr={1,2,3,4,5};
Arrays.sort(arr);
System.out.println(arr[arr.length-1]);
}
}
--------------------c++--------------------
#include<bits/stdc++.h>
using namespace std;
int largest(int arr[], int n){
int max=arr[0];
for(int i=1;i<n;i++){
if(arr[i]>max)
max=arr[i];
}
return max;
}
int main(){
int n;
cin >> n;
int arr[n];
for(int i=0;i<n;i++)
cin >> arr[i];
cout<<largest(arr,n);
return 0;
}
-------------------------------------------
10. Write a function that checks whether an element occurs in a array.
Solution :
#include <iostream>
using namespace std;
int main() {
int i, n;
float arr[100];
cout << "Enter total number of elements(1 to 100): ";
cin >> n;
cout << endl;
// Store number entered by the user
for(i = 0; i < n; ++i) {
cout << "Enter Number " << i + 1 << " : ";
cin >> arr[i];
}
// Loop to store largest number to arr[0]
for(i = 1;i < n; ++i) {
// Change < to > if you want to find the smallest element
if(arr[0] < arr[i])
arr[0] = arr[i];
}
cout << endl << "Largest element = " << arr[0];
return 0;
}
11. Write a function that returns the elements on odd positions in a list.
Solution :
# Python code to return the elements on odd positions in a list.
a = [41, 19, 74, 107, 12309, -82, 64, 39, 501, 124, 70, 1111]
length_of_a = len(a)
for i in range(1, length_of_a, 2):
print(a[i], end=" ")
=========c++=========
vector<int> oddPosition(vector<int> arr, int n) {
vector<int> oddPos(n/2);
for(int i = 1; i < n; i += 2) {
oddPos.push_back(arr[i]);
}
return oddPos;
}
12. Write three functions that compute the sum of the numbers in a array: using a for-loop, a while-loop and recursion.
Solution :
class code{
public static void main(String[] args){
int[] arr={1,2,3,4,5};
int ans1=usingfor(arr);
int ans2=usingwhile(arr);
int ans3=using rec(arr);
}
public int usingfor(int[] arr){
int ans=0;
for(int i=0; i<arr.lengthl i++){
ans=ans+arr[i];
}
return ans;
}
public int usingwhile(int[] arr){
int ans=0;
int i=0;
while(i<arr.length){
ans=ans+arr[i];
i++;
}
return ans;
}
public int usingrec(int[] arr, int i){
if(i=>arr.length){
return 0;
}
return arr[i]+usingrec(arr,i+1);
}
}
13. Write a function that concatenates two arrays. [a,b,c], [1,2,3] → [a,b,c,1,2,3]
Solution :
public class Concat {
public static void main(String[] args) {
int[] array1 = {1, 2, 3};
int[] array2 = {4, 5, 6};
int aLen = array1.length;
int bLen = array2.length;
int[] result = new int[aLen + bLen];
System.arraycopy(array1, 0, result, 0, aLen);
System.arraycopy(array2, 0, result, aLen, bLen);
System.out.println(Arrays.toString(result));
}
}
14. Write a function that merges two sorted into a new sorted list. [1,4,6],[2,3,5] → [1,2,3,4,5,6]. You can do this quicker than concatenating them followed by a sort.
Solution :
def merge(list1,list2):
print(sorted(list1 + list2))
list1 = [1,2,3,4,5]
list2= [10,20,30,40,50,60]
merge(list1,list2)
15. Write a function that computes the list of the first n Fibonacci numbers. The first two Fibonacci numbers are 1 and 1. The first few are therefore 1, 1, 1+1=2, 1+2=3, 2+3=5, 3+5=8.
Solution :
class Main {
public static int fibonacci_numbers(int n)
{
if(n == 0){
return 0;
}
else if(n == 1){
return 1;
}
else{
return fibonacci_numbers(n-2) + fibonacci_numbers(n-1);
}
}
public static void main (String[] args) {
int n = 7;
for(int i = 0; i < n; i++){
System.out.print(fibonacci_numbers(i)+ " ");
}
}
}
16. Write a function that return the Factorial of given number n.
Solution :
# Python
def factorial(n):
if n==0:
return 1
else:
return n*factorial(n-1)
17. Print the following pattern without using print in-built function.
i. ii. iii.
*** 123 321
*** 123 321
*** 123 321
Solution :
//cpp
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cout<<"*";
}
}
for(int i=0;i<3;i++){
for(int j=1;j<=3;j++){
cout<<"j";
}
}
for(int i=0;i<3;i++){
for(int j=3;j>=0;j++){
cout<<"j";
}
}
18. Convert i. Minutes -> Seconds
ii. Fahrenheit -> Celsius -> Kelvin
Solution : #include<stdio.h>
#include<conio.h>
int main()
{
float celsius, fahr, kelvin;
clrscr();
printf("Enter temperature in celsius: ");
scanf("%f", &celsius);
fahr = 1.8 * celsius + 32.0;
kelvin = 273.15 + celsius;
printf("%0.2f Celsius = %0.2f Fahrenheit\n", celsius, fahr);
printf("%0.2f Celsius = %0.2f Kelvin",celsius, kelvin);
getch();
return(0);
}
19. Design a quiz game which take answer as input to given question (atleast 5) and print final result(Total marks & percentage). +2 for Correct answer, -0.5 for Incorrect.
Solution :
def new_game():
guesses = []
correct_guesses = 0
question_num = 1
for key in questions:
print("-------------------------")
print(key)
for i in options[question_num-1]:
print(i)
guess = input("Enter (A, B, C, or D): ")
guess = guess.upper()
guesses.append(guess)
correct_guesses += check_answer(questions.get(key), guess)
question_num += 1
display_score(correct_guesses, guesses)
# -------------------------
def check_answer(answer, guess):
if answer == guess:
print("CORRECT!")
return 1
else:
print("WRONG!")
return 0
# -------------------------
def display_score(correct_guesses, guesses):
print("-------------------------")
print("RESULTS")
print("-------------------------")
print("Answers: ", end="")
for i in questions:
print(questions.get(i), end=" ")
print()
print("Guesses: ", end="")
for i in guesses:
print(i, end=" ")
print()
score = int((correct_guesses/len(questions))*100)
print("Your score is: "+str(score)+"%")
# -------------------------
def play_again():
response = input("Do you want to play again? (yes or no): ")
response = response.upper()
if response == "YES":
return True
else:
return False
# -------------------------
questions = {
"Who created Python?: ": "A",
"What year was Python created?: ": "B",
"Python is tributed to which comedy group?: ": "C",
"Is the Earth round?: ": "A",
"Value of pi?: ": "C",
}
options = [["A. Guido van Rossum", "B. Elon Musk", "C. Bill Gates", "D. Mark Zuckerburg"],
["A. 1989", "B. 1991", "C. 2000", "D. 2016"],
["A. Lonely Island", "B. Smosh", "C. Monty Python", "D. SNL"],
["A. True","B. False", "C. sometimes", "D. What's Earth?"],
['1.24','2.34','3.14','3.68']]
new_game()
while play_again():
new_game()
print("Byeeeeee!")
20. Design a tool which find area & perimeter of different shapes.
Solution :
# define a function for calculating
# the area of a shapes
def calculate_area(name):\
# converting all characters
# into lower cases
name = name.lower()
# check for the conditions
if name == "rectangle":
l = int(input("Enter rectangle's length: "))
b = int(input("Enter rectangle's breadth: "))
# calculate area of rectangle
rect_area = l * b
print(f"The area of rectangle is {rect_area}.")
elif name == "square":
s = int(input("Enter square's side length: "))
# calculate area of square
sqt_area = s * s
print(f"The area of square is {sqt_area}.")
elif name == "triangle":
h = int(input("Enter triangle's height length: "))
b = int(input("Enter triangle's breadth length: "))
# calculate area of triangle
tri_area = 0.5 * b * h
print(f"The area of triangle is {tri_area}.")
elif name == "circle":
r = int(input("Enter circle's radius length: "))
pi = 3.14
# calculate area of circle
circ_area = pi * r * r
print(f"The area of circle is {circ_area}.")
elif name == 'parallelogram':
b = int(input("Enter parallelogram's base length: "))
h = int(input("Enter parallelogram's height length: "))
# calculate area of parallelogram
para_area = b * h
print(f"The area of parallelogram is
{para_area}.")
else:
print("Sorry! This shape is not available")
# driver code
if __name__ == "__main__" :
print("Calculate Shape Area")
shape_name = input("Enter the name of shape whose area you want to find: ")
# function calling
calculate_area(shape_name)
21. Return first, middle & last element of array.
Solution :
#python
def func():
arr = [1,2,3,4,5]
ans = []
middle = 5//2
ans.append(arr[0])
ans.append(arr[middle])
ans.append(arr[-1])
return ans
answer = func()
print(answer)
22. Largest subarray with 0 sum
Solution :
class GfG
{
int maxLen(int arr[], int n)
{
// Your code here
HashMap<Integer,Integer>a=new HashMap<>();
int s=0;
int count=0;
a.put(0,-1);
for(int i=0;i<n;i++)
{
s=s+arr[i];
if(s==0 || a.containsKey(s))
{
count=Math.max(count,i-a.get(s));
}
else
{
a.put(s,i);
}
}
return count;
}
}
23.Find duplicates in an array
Solution :
class Solution {
public static ArrayList<Integer> duplicates(int arr[], int n) {
// code here
int a[]= new int [n];
int c=0;
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
a[arr[i]]=a[arr[i]]+1;
}
for(int j=0;j<n;j++)
{
if(a[j]>1){
list.add(j);
c++;
}
else
continue;
}
if(c==0)
{
list.add(-1);
return list;
}
else
return list;
}
}
=======
#python
a = []
n=int(input("enter total number of elements to be added in array:"))
for i in range(0,n):
x=input("Enter element to add in array:")
a.append(x)
print("Array: ", a)
mid=(0+arr.length-1)/2;
print("first element is" ,a[0])
print("last element is", a[-1])
print("middle element is",a[mid])
=======
#Java
static int[] printArray(int[] arr){
int mid=(0+arr.length-1)/2;
int[] nums=new int[3];
//Storing values in new array
nums[0]=arr[0];
nums[1]=arr[mid];
nums[2]=arr[arr.length-1];
System.out.println("First,middle,last element of array is");
return nums;
}
24.Write a program to find the gcd of 2 numbers
Solution :
#C++
int gcd(int a,int b)
{
if(b==0)return a;
return gcd(b,a%b);
}
int main()
{
int a,b;
cin>>a>>b;
cout<<gcd(a,b)<<endl;
//Time Complexity:O(log(min(a,b)))
}
25.Conversion of Binary number to its decimal
#C
Solution:
#include<stdio.h>
int main()
{
int T,N,K,i,j,A,B;
char s[100][100];
scanf("%d",&T);
for(i=0;i<T;i++)
{
scanf("%d %d %d",&N,&A,&B);
scanf("%s",s[j]);
K=0;
for(j=0;j<N;j++)
{
if(s[i][j]=='0')
K=K+A;
if(s[i][j]=='1')
K=K+B;
}
printf("%d\n",K);
}
return 0;
}
26.Split the array into equal sum subarrays.
Solution:
sample = [2, 4, 5, 1, 2, 3]
sum = 0
sum_left=[]
for val in sample:
sum += val
sum_left.append(sum)
sum_right=[]
for val in sample:
sum_right.append(sum)
sum -= val
for i in range(len(sum_left)):
if sum_left[i] == sum_right[i]:
print(f"Matching index is {i}.")
break
}
27 the minimum numbers of operations required by Chef to make parity of all the elements same.
Solution:
#include <iostream>
using namespace std;
#define ll long long
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
ll arr[n];
ll even=0,odd=0;
for(int i=0;i<n;i++)
{
cin>>arr[i];
if(arr[i]%2==1)
{
odd++;
}
}
if(odd==n || odd== 0)
{
cout<<"0"<<endl;
}
else
{
cout<<n-odd<<endl;
}
}
return 0;
28. Equilibrium index of an array
Solution:
int findEquilibrium(int A[], int n)
{
//Your code here
double s=0;
for(int i=0;i<n;i++){
s=s+A[i];
}
double s1=0;
for(int i=0;i<n;i++){
s1=s1+A[i];
if(((s-A[i+1])/2)==s1){
return i+1;
}
}
return -1;
}
29. Polynomials
Solution:
import numpy as np
poly = [float(x) for x in input().split()]
x = float(input())
print(np.polyval(poly, x))
30. Implement Tower of Hanoi.
Solution:
def hanoi(disks, source, auxiliary, target):
if disks == 1:
print('Move disk 1 from peg {} to peg {}.'.format(source, target))
return
hanoi(disks - 1, source, target, auxiliary)
print('Move disk {} from peg {} to peg {}.'.format(disks, source, target))
hanoi(disks - 1, auxiliary, source, target)
disks = int(input('Enter number of disks: '))
hanoi(disks, 'A', 'B', 'C')
31. Kadane's Algorithm (largest contiguous array sum)
Solution:
#include <bits/stdc++.h>
using namespace std;
int maxSubArraySum(int a[], int size)
{
int max_so_far = INT_MIN, max_ending_here = 0;
for (int i = 0; i < size; i++) {
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
}
int main()
{