codeparrot/xlcost-text-to-code huggingface dataset:
Count of Missing Numbers in a sorted array | C # program for the above approach ; Function that find the count of missing numbers in array a [ ] ; Calculate the count of missing numbers in the array ; Driver code
using System ; class GFG { public static void countMissingNum ( int [ ] a , int N ) { int count = a [ N - 1 ] - a [ 0 ] + 1 - N ; Console . Write ( count ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 5 , 10 , 20 , 40 } ; int N = arr . Length ; countMissingNum ( arr , N ) ; } }
Length of longest subsequence whose XOR value is odd | C # program for the above approach ; Function for find max XOR subsequence having odd value ; Initialize odd and even count ; Count the number of odd and even numbers in given array ; If all values are odd in given array ; If all values are even in given array ; If both odd and even are present in given array ; Driver Code ; Given array arr [ ] ; Function Call
using System ; class GFG { static int maxXORSubsequence ( int [ ] arr , int n ) { int i , odd = 0 , even = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; else even ++ ; } int maxlen ; if ( odd == n ) { if ( odd % 2 == 0 ) maxlen = n - 1 ; else maxlen = n ; } else if ( even == n ) { maxlen = 0 ; } else { if ( odd % 2 == 0 ) maxlen = even + odd - 1 ; else maxlen = even + odd ; } return maxlen ; } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 3 , 4 , 5 , 6 , 7 } ; int n = arr . Length ; Console . Write ( maxXORSubsequence ( arr , n ) ) ; } }
Count of pairs with sum N from first N natural numbers | C # program to count the number of pairs among the first N natural numbers with sum N ; Function to calculate the value of count ; If n is even ; Count of pairs ; Otherwise ; Driver code
using System ; class GFG { public static int numberOfPairs ( int n ) { if ( n % 2 == 0 ) return n / 2 - 1 ; else return n / 2 ; } public static void Main ( string [ ] args ) { int n = 8 ; Console . Write ( numberOfPairs ( n ) ) ; } }
Count pair of strings whose concatenation has every vowel | C # program for the above approach ; Function to return the count of all concatenated String with each vowel at least once ; Concatenating all possible pairs of String ; Creating an array which checks , the presence of each vowel ; Checking for each vowel by traversing the concatenated String ; Checking if all the elements are set in vowel [ ] ; Check if all vowels are present or not ; Return the readonly count ; Driver Code ; Given array of Strings ; Function call
using System ; class GFG { static int good_pair ( String [ ] str , int N ) { int countStr = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { String res = str [ i ] + str [ j ] ; int [ ] vowel = new int [ 5 ] ; for ( int k = 0 ; k < res . Length ; k ++ ) { if ( res [ k ] == ' a ' ) vowel [ 0 ] = 1 ; else if ( res [ k ] == ' e ' ) vowel [ 1 ] = 1 ; else if ( res [ k ] == ' i ' ) vowel [ 2 ] = 1 ; else if ( res [ k ] == ' o ' ) vowel [ 3 ] = 1 ; else if ( res [ k ] == ' u ' ) vowel [ 4 ] = 1 ; } int temp = 0 ; for ( int ind = 0 ; ind < 5 ; ind ++ ) { if ( vowel [ ind ] == 1 ) temp ++ ; } if ( temp == 5 ) countStr ++ ; } } return countStr ; } public static void Main ( String [ ] args ) { String [ ] arr = { " aaweiolkju " , " oxdfgujkmi " } ; int N = arr . Length ; Console . Write ( good_pair ( arr , N ) ) ; } }
Find sum of exponents of prime factors of numbers 1 to N | C # program for the above approach ; Function to implement sieve of erastosthenes ; Create a bool array and initialize all entries as false ; Initializing smallest factor equal to 2 for all the even numbers ; Iterate for odd numbers less then equal to n ; s ( i ) for a prime is the number itself ; For all multiples of current prime number ; i is the smallest prime factor for number " i * j " ; Function to generate prime factors and its power ; s [ i ] is going to store smallest prime factor of i ; Current prime factor of N ; Power of current prime factor ; Calculating prime factors and their powers sum ; Increment the count and continue the process ; Add count to the sum ; Reinitialize count ; Return the result ; Function to find the sum of all the power of prime factors of N ; Iterate for in [ 2 , N ] ; Driver Code ; Given number N ; Function call
using System ; class GFG { static void sieveOfEratosthenes ( int N , int [ ] s ) { bool [ ] prime = new bool [ N + 1 ] ; for ( int i = 2 ; i <= N ; i += 2 ) s [ i ] = 2 ; for ( int i = 3 ; i <= N ; i += 2 ) { if ( prime [ i ] == false ) { s [ i ] = i ; for ( int j = i ; j * i <= N ; j += 2 ) { if ( prime [ i * j ] == false ) { prime [ i * j ] = true ; s [ i * j ] = i ; } } } } } static int generatePrimeFactors ( int N ) { int [ ] s = new int [ N + 1 ] ; int sum = 0 ; sieveOfEratosthenes ( N , s ) ; int curr = s [ N ] ; int cnt = 1 ; while ( N > 1 ) { N /= s [ N ] ; if ( curr == s [ N ] ) { cnt ++ ; continue ; } sum = sum + cnt ; curr = s [ N ] ; cnt = 1 ; } return sum ; } static void findSum ( int N ) { int sum = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { sum += generatePrimeFactors ( i ) ; } Console . Write ( sum + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int N = 4 ; findSum ( N ) ; } }
Minimum LCM of all subarrays of length at least 2 | C # program for the above approach ; Function to find LCM pf two numbers ; Initialise lcm value ; Check for divisibility of a and b by the lcm ; Function to find the Minimum LCM of all subarrays of length greater than 1 ; Store the minimum LCM ; Traverse the array ; Find LCM of consecutive element ; Check if the calculated LCM is less than the minLCM then update it ; Print the minimum LCM ; Driver Code ; Given array [ ] arr ; Size of the array ; Function call
using System ; class GFG { static int LCM ( int a , int b ) { int lcm = a > b ? a : b ; while ( true ) { if ( lcm % a == 0 && lcm % b == 0 ) break ; else lcm ++ ; } return lcm ; } static void findMinLCM ( int [ ] arr , int n ) { int minLCM = int . MaxValue ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int val = LCM ( arr [ i ] , arr [ i + 1 ] ) ; if ( val < minLCM ) { minLCM = val ; } } Console . Write ( minLCM + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 8 , 12 , 16 , 20 , 24 } ; int n = arr . Length ; findMinLCM ( arr , n ) ; } }
Minimum integer with at most K bits set such that their bitwise AND with N is maximum | C # program for the above approach ; Function to find the integer with maximum bitwise with N ; Store answer in the bitset Initialized with 0 ; To maintain the count of set bits that should exceed k ; Start traversing from the Most significant if that bit is set in n then we will set in our answer i . e in X ; Checking if the ith bit is set in n or not ; Converting into integer ; Driver code ; Function Call
using System ; class GFG { static int find_max ( int n , int k ) { int [ ] X = new int [ 32 ] ; int cnt = 0 ; for ( int i = 31 ; i >= 0 && cnt != k ; i -- ) { if ( ( n & ( 1 << i ) ) != 0 ) { X [ i ] = 1 ; cnt ++ ; } } String s = " " ; for ( int i = 31 ; i >= 0 ; i -- ) s += X [ i ] == 0 ? '0' : '1' ; return Convert . ToInt32 ( s , 2 ) ; } public static void Main ( String [ ] args ) { int n = 10 , k = 2 ; Console . Write ( find_max ( n , k ) ) ; } }
Convert string to integer without using any in | C # program for the above approach ; Function to convert string to integer without using functions ; Initialize a variable ; Iterate till length of the string ; Subtract 48 from the current digit ; Print the answer ; Driver code ; Given string of number ; Function call
using System ; class GFG { public static void convert ( string s ) { int num = 0 ; int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) num = num * 10 + ( ( int ) s [ i ] - 48 ) ; Console . Write ( num ) ; } public static void Main ( string [ ] args ) { string s = "123" ; convert ( s ) ; } }
Permutation of Array such that sum of adjacent elements are not divisible by 3 | C # implementation to find the permutation of the array such that sum of adjacent elements is not divisible by 3 ; Function to segregate numbers based on their remainder when divided by three ; Loop to iterate over the elements of the given array ; Condition to check the remainder of the number ; Function to find the permutation of the array such that sum of adjacent elements is not divisible by 3 ; Condition to check when it 's impossible to arrange ; Condition to check when there are no zeros , and only ones or only twos ; Array to store the permutation ; Place the ones on alternate places in the answer array , leaving spaces for zeros remainder elements in the array ; Adding a zero to connect it with a two ; Place the twos on alternate places in the answer array , leaving spaces for zeros ; Fill the zeros finally , between the ones and the twos ; Print the arrangement of the array ; Function to solve the problem ; As there can be only 3 remainders ; Function Call ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static readonly int hell = 1000000007 ; static readonly int N = 100005 ; static int c_0 , c_1 , c_2 ; static void count_k ( int [ ] arr , Stack < int > ones , Stack < int > twos , Stack < int > zeros ) { for ( int i = 0 ; i < arr . Length ; i ++ ) { if ( arr [ i ] % 3 == 0 ) { c_0 ++ ; zeros . Push ( arr [ i ] ) ; } else if ( arr [ i ] % 3 == 1 ) { c_1 ++ ; ones . Push ( arr [ i ] ) ; } else { c_2 ++ ; twos . Push ( arr [ i ] ) ; } } return ; } static void printArrangement ( int [ ] arr , Stack < int > ones , Stack < int > twos , Stack < int > zeros ) { if ( ( c_0 == 0 && c_1 != 0 && c_2 != 0 ) c_0 > c_1 + c_2 + 1 ) { Console . Write ( " - 1" ) ; return ; } int i ; if ( c_0 == 0 ) { for ( i = 0 ; i < arr . Length ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } return ; } int j ; int [ ] ans = new int [ N ] ; for ( i = 0 ; i < ans . Length ; i ++ ) ans [ i ] = - 1 ; for ( i = 1 , j = 0 ; j < c_1 ; i += 2 , j ++ ) { ans [ i ] = ones . Peek ( ) ; ones . Pop ( ) ; } ans [ i - 1 ] = zeros . Peek ( ) ; zeros . Pop ( ) ; c_0 -- ; for ( j = 0 ; j < c_2 ; j ++ , i += 2 ) { ans [ i ] = twos . Peek ( ) ; twos . Pop ( ) ; } for ( int k = 0 ; c_0 > 0 ; k += 2 ) { if ( ans [ k ] == - 1 ) { ans [ k ] = zeros . Peek ( ) ; c_0 -- ; } } for ( int i1 = 0 ; i1 < N ; i1 ++ ) { if ( ans [ i1 ] != - 1 ) Console . Write ( ans [ i1 ] + " ▁ " ) ; } return ; } static void solve ( int n , int [ ] arr ) { Stack < int > ones = new Stack < int > ( ) ; Stack < int > zeros = new Stack < int > ( ) ; Stack < int > twos = new Stack < int > ( ) ; c_0 = 0 ; c_1 = 0 ; c_2 = 0 ; count_k ( arr , ones , twos , zeros ) ; printArrangement ( arr , ones , twos , zeros ) ; } public static void Main ( String [ ] args ) { int n = 5 ; int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; solve ( n , arr ) ; } }
Count of unique digits in a given number N | C # program for the above approach ; Function that returns the count of unique digits of number N ; Initialize a variable to store count of unique digits ; Initialize cnt array to store digit count ; Iterate through digits of N ; Retrieve the last digit of N ; Increase the count of the last digit ; Remove the last digit of N ; Iterate through the cnt array ; If frequency of digit is 1 ; Increment the count of unique digits ; Return the count of unique digit ; Driver Code ; Given Number N ; Function Call
using System ; class GFG { public static void countUniqueDigits ( int N ) { int res = 0 ; int [ ] cnt = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; while ( N > 0 ) { int rem = N % 10 ; cnt [ rem ] ++ ; N = N / 10 ; } for ( int i = 0 ; i < cnt . Length ; i ++ ) { if ( cnt [ i ] == 1 ) { res ++ ; } } Console . WriteLine ( res ) ; } public static void Main ( String [ ] args ) { int N = 2234262 ; countUniqueDigits ( N ) ; } }
Check if frequency of each element in given array is unique or not | C # code for the above approach ; Function to check whether the frequency of elements in array is unique or not . ; Freq map will store the frequency of each element of the array ; Store the frequency of each element from the array ; Check whether frequency of any two or more elements are same or not . If yes , return false ; Return true if each frequency is unique ; Driver Code ; Given array [ ] arr ; Function call ; Print the result
using System ; using System . Collections . Generic ; class GFG { static bool checkUniqueFrequency ( int [ ] arr , int n ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . ContainsKey ( arr [ i ] ) ) { freq [ arr [ i ] ] = freq [ arr [ i ] ] + 1 ; } else { freq . Add ( arr [ i ] , 1 ) ; } } HashSet < int > uniqueFreq = new HashSet < int > ( ) ; foreach ( KeyValuePair < int , int > i in freq ) { if ( uniqueFreq . Contains ( i . Value ) ) return false ; else uniqueFreq . Add ( i . Value ) ; } return true ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 2 , 5 , 5 } ; int n = arr . Length ; bool res = checkUniqueFrequency ( arr , n ) ; if ( res ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else Console . Write ( " No " + " STRNEWLINE " ) ; } }
Sum of first N natural numbers with all powers of 2 added twice | C # program to implement the above approach ; Function to raise N to the power P and return the value ; Function to calculate the log base 2 of an integer ; Calculate log2 ( N ) indirectly using log ( ) method ; Function to calculate and return the required sum ; Sum of first N natural numbers ; Sum of all powers of 2 up to N ; Driver Code
using System ; class GFG { static double power ( int N , int P ) { return Math . Pow ( N , P ) ; } public static int log2 ( int N ) { int result = ( int ) ( Math . Log ( N ) / Math . Log ( 2 ) ) ; return result ; } static double specialSum ( int n ) { double sum = ( double ) ( n ) * ( n + 1 ) / 2 ; int a = log2 ( n ) ; sum = ( sum ) + power ( 2 , a + 1 ) - 1 ; return sum ; } public static void Main ( string [ ] args ) { int n = 4 ; Console . Write ( specialSum ( n ) ) ; } }
Rearrange an array such that product of every two consecutive elements is a multiple of 4 | C # program to rearray array elements such that the product of every two consecutive elements is a multiple of ; Function to rearrange array elements such that the every two consecutive elements is a multiple of 4 ; If element is odd ; Odd ; If element is divisible by 4 ; Divisible by 4 ; If element is not divisible by 4 ; Even but not divisible by 4 ; Condition for rearrangement to be possible ; Print ODD [ i ] and FOUR [ i ] consecutively ; Print the remaining FOUR [ i ] , if any ; Condition for rearrangement to be possible ; Print ODD [ i ] and FOUR [ i ] consecutively ; Print the remaining FOUR [ i ] , if any ; Print the NON_FOUR [ i ] elements at the end ; No possible configuration ; Driver Code
using System ; using System . Collections . Generic ; class GFG { public static void Permute ( List < int > arr , int n ) { int odd = 0 , four = 0 ; int non_four = 0 ; List < int > ODD = new List < int > ( ) ; List < int > FOUR = new List < int > ( n ) ; List < int > NON_FOUR = new List < int > ( n ) ; foreach ( int x in arr ) { if ( x % 2 != 0 ) { odd ++ ; ODD . Add ( x ) ; } else if ( x % 4 == 0 ) { four ++ ; FOUR . Add ( x ) ; } else { non_four ++ ; NON_FOUR . Add ( x ) ; } } if ( non_four == 0 && four >= odd - 1 ) { int x = ODD . Count ; int y = FOUR . Count ; int i ; for ( i = 0 ; i < x ; i ++ ) { Console . Write ( ODD [ i ] + " ▁ " ) ; if ( i < y ) Console . Write ( FOUR [ i ] + " ▁ " ) ; } while ( i < y ) Console . Write ( FOUR [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } else if ( non_four > 0 && four >= odd ) { int x = ODD . Count ; int y = FOUR . Count ; int i ; for ( i = 0 ; i < x ; i ++ ) { Console . Write ( ODD [ i ] + " ▁ " ) ; if ( i < y ) Console . Write ( FOUR [ i ] + " ▁ " ) ; } while ( i < y ) Console . Write ( FOUR [ i ] + " ▁ " ) ; for ( int j = 0 ; j < ( int ) NON_FOUR . Count ; j ++ ) Console . Write ( NON_FOUR [ j ] + " ▁ " ) ; Console . WriteLine ( ) ; } else Console . WriteLine ( " Not ▁ Possible " ) ; } public static void Main ( String [ ] args ) { List < int > arr = new List < int > ( ) ; arr . Add ( 2 ) ; arr . Add ( 7 ) ; arr . Add ( 1 ) ; arr . Add ( 8 ) ; arr . Add ( 2 ) ; arr . Add ( 8 ) ; Permute ( arr , arr . Count ) ; } }
Construct the smallest possible Array with given Sum and XOR | C # program implementation of the approach ; Function to find array ; Array not possible ; Array possible with exactly 1 or no element ; Checking array with two elements possible or not . ; Driver code ; Given sum and value of Bitwise XOR ; Function call
using System ; class GFG { static void findArray ( int sum , int xorr ) { if ( xorr > sum sum % 2 != xorr % 2 ) { Console . WriteLine ( " No ▁ Array ▁ Possible " ) ; return ; } if ( sum == xorr ) { if ( sum == 0 ) Console . WriteLine ( " Array ▁ is ▁ empty ▁ " + " with ▁ size ▁ 0" ) ; else Console . WriteLine ( " Array ▁ size ▁ is ▁ " + 1 ) ; Console . WriteLine ( " Array ▁ is ▁ " + sum ) ; return ; } int mid = ( sum - xorr ) / 2 ; if ( xorr == 1 && mid == 1 ) { Console . WriteLine ( " Array ▁ size ▁ is ▁ " + 3 ) ; Console . WriteLine ( " Array ▁ is ▁ " + xorr + " ▁ " + mid + " ▁ " + mid ) ; } else { Console . WriteLine ( " Array ▁ size ▁ is ▁ " + 2 ) ; Console . WriteLine ( " Array ▁ is ▁ " + ( xorr + mid ) + " ▁ " + mid ) ; } } public static void Main ( ) { int sum = 4 , xorr = 2 ; findArray ( sum , xorr ) ; } }
Smallest number greater than X which is K | C # program to find the smallest K periodic integer greater than X ; Function to find the smallest K periodic integer greater than X ; Stores the number in a temporary String ; Set X [ i ] = X [ i - k ] for i > k ; Start from the current index ; Loop upto N change X [ j ] to X [ i ] ; Return X if current Value is greater than original value ; Find the first digit not equal to 9 ; Increment X [ i ] ; Set POS to current index ; Change X [ i ] to 0 for all indices from POS + 1 to K ; Set X [ i ] = X [ i - k ] for i > k ; Loop upto N change X [ j ] to X [ i ] ; Return the readonly String ; Driver Code
using System ; class GFG { static String Kperiodicinteger ( char [ ] X , int N , int K ) { String temp = String . Join ( " " , X ) ; for ( int i = 0 ; i < K ; i ++ ) { int j = i ; while ( j < N ) { X [ j ] = X [ i ] ; j += K ; } } if ( String . Join ( " " , X ) . CompareTo ( temp ) >= 0 ) { return String . Join ( " " , X ) ; } int POS = 0 ; for ( int i = K - 1 ; i >= 0 ; i -- ) { if ( X [ i ] != '9' ) { X [ i ] ++ ; POS = i ; break ; } } for ( int i = POS + 1 ; i < K ; i ++ ) { X [ i ] = '0' ; } for ( int i = 0 ; i < K ; i ++ ) { int j = i ; while ( j < N ) { X [ j ] = X [ i ] ; j += K ; } } return String . Join ( " " , X ) ; } public static void Main ( String [ ] args ) { int N = 4 , K = 2 ; String X = "1215" ; Console . Write ( Kperiodicinteger ( X . ToCharArray ( ) , N , K ) ) ; } }
Maximum cost path in an Undirected Graph such that no edge is visited twice in a row | C # program for the above approach ; To store the resulting sum of the cost ; To store largest cost leaf vertex ; DFS Traversal to find the update the maximum cost of from any node to leaf ; Mark vertex as visited ; Store vertex initial cost ; Initially assuming edge not to be traversed ; Back edge found so , edge can be part of traversal ; New vertex is found ; Bitwise AND the current check with the returned check by the previous DFS Call ; Adds parent and its children cost ; Updates total cost of parent including child nodes ; Edge is part of the cycle ; Add cost of vertex to the answer ; Updates the largest cost leaf vertex ; Function to find the maximum cost from source vertex such that no two edges is traversed twice ; DFS call ; Print the maximum cost ; Driver Code ; Cost Array ; Given Graph ; Given Source Node ; Function call
using System ; using System . Collections . Generic ; class GFG { static int N = 100000 ; static int canTake ; static int best ; static int [ ] dp = new int [ N ] ; static bool [ ] vis = new bool [ N ] ; static bool dfs ( List < int > [ ] g , int [ ] cost , int u , int pre ) { vis [ u ] = true ; dp [ u ] = cost [ u ] ; bool check = true ; int cur = cost [ u ] ; foreach ( int x in g [ u ] ) { if ( vis [ x ] && x != pre ) { check = false ; } else if ( ! vis [ x ] ) { check = dfs ( g , cost , x , u ) ? false : true ; cur = Math . Max ( cur , cost [ u ] + dp [ x ] ) ; } } dp [ u ] = cur ; if ( ! check ) { canTake += cost [ u ] ; } else { best = Math . Max ( best , dp [ u ] ) ; } return check ; } static void FindMaxCost ( List < int > [ ] g , int [ ] cost , int source ) { dfs ( g , cost , source , - 1 ) ; Console . Write ( canTake + best ) ; } public static void Main ( String [ ] args ) { int n = 5 , m = 5 ; int [ ] cost = { 2 , 2 , 8 , 6 , 9 } ; List < int > [ ] g = new List < int > [ n ] ; for ( int i = 0 ; i < g . Length ; i ++ ) g [ i ] = new List < int > ( ) ; g [ 0 ] . Add ( 1 ) ; g [ 1 ] . Add ( 0 ) ; g [ 0 ] . Add ( 2 ) ; g [ 2 ] . Add ( 0 ) ; g [ 0 ] . Add ( 3 ) ; g [ 3 ] . Add ( 0 ) ; g [ 1 ] . Add ( 2 ) ; g [ 2 ] . Add ( 1 ) ; g [ 1 ] . Add ( 4 ) ; g [ 4 ] . Add ( 1 ) ; int source = 1 ; FindMaxCost ( g , cost , source ) ; } }
Reverse a subarray of the given array to minimize the sum of elements at even position | C # implementation to reverse a subarray of the given array to minimize the sum of elements at even position ; Function that will give the max negative value ; Check for count greater than 0 as we require only negative solution ; Function to print the minimum sum ; Taking sum of only even index elements ; Initialize two vectors v1 , v2 ; v1 will keep account for change if 1 th index element goes to 0 ; v2 will keep account for change if 1 th index element goes to 2 ; Get the max negative value ; Driver code
using System ; using System . Collections . Generic ; class GFG { static readonly int N = 5 ; static int after_rev ( List < int > v ) { int mini = 0 , count = 0 ; for ( int i = 0 ; i < v . Count ; i ++ ) { count += v [ i ] ; if ( count > 0 ) count = 0 ; if ( mini > count ) mini = count ; } return mini ; } static void print ( int [ ] arr ) { int sum = 0 ; for ( int i = 0 ; i < N ; i += 2 ) sum += arr [ i ] ; List < int > v1 , v2 ; v1 = new List < int > ( ) ; v2 = new List < int > ( ) ; for ( int i = 0 ; i + 1 < N ; i += 2 ) v1 . Add ( arr [ i + 1 ] - arr [ i ] ) ; for ( int i = 1 ; i + 1 < N ; i += 2 ) v2 . Add ( arr [ i ] - arr [ i + 1 ] ) ; int change = Math . Min ( after_rev ( v1 ) , after_rev ( v2 ) ) ; if ( change < 0 ) sum += change ; Console . Write ( sum + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 0 , 1 , 4 , 3 , 0 } ; print ( arr ) ; } }