text: Number of Subsequences with Even and Odd Sum | C # program to get minimum cost to sort strings by reversal operation ; Returns the count of odd and even subsequences ; Variables to store the count of even subsequences and odd subsequences ; Initialising count_even and count_odd to 0 since as there is no subsequence before the iteration with even or odd count . ; Find sum of all subsequences with even count and odd count and storing them as we iterate . ; if the number is even ; if the number is odd ; Driver code ; Calling the function
code: using System ; class GFG { public class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static pair countSum ( int [ ] arr , int n ) { int count_odd , count_even ; count_odd = 0 ; count_even = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( arr [ i - 1 ] % 2 == 0 ) { count_even = count_even + count_even + 1 ; count_odd = count_odd + count_odd ; } else { int temp = count_even ; count_even = count_even + count_odd ; count_odd = count_odd + temp + 1 ; } } return new pair ( count_even , count_odd ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 2 , 3 } ; int n = arr . Length ; pair ans = countSum ( arr , n ) ; Console . Write ( " EvenSum ▁ = ▁ " + ans . first ) ; Console . Write ( " ▁ OddSum ▁ = ▁ " + ans . second ) ; } }