dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int FindMaxS ( int X , int Y , int Z , int n , int [ ] A , int [ ] B , int [ ] C ) { if ( X < 0 Y < 0 Z < 0 ) return int . MinValue ; if ( n < 0 ) return 0 ; int ch = A [ n ] + FindMaxS ( X - 1 , Y , Z , n - 1 , A , B , C ) ; int ca = B [ n ] + FindMaxS ( X , Y - 1 , Z , n - 1 , A , B , C ) ; int co = C [ n ] + FindMaxS ( X , Y , Z - 1 , n - 1 , A , B , C ) ; int no = FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ; int maximum = Math . Max ( ch , Math . Max ( ca , Math . Max ( co , no ) ) ) ; return maximum ; } public static void Main ( String [ ] args ) { int X = 1 ; int Y = 1 ; int Z = 1 ; int [ ] A = { 10 , 0 , 5 } ; int [ ] B = { 5 , 10 , 0 } ; int [ ] C = { 0 , 5 , 10 } ; int n = B . Length ; Console . WriteLine ( FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ) ; } }

Index/key variables: n
Class/struct names: GFG
C# program:
using System ; class GFG { static void replace ( int [ ] arr ) { int n = arr . Length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] >= 0 && arr [ j ] >= 0 && arr [ i ] % 2 == 0 && arr [ j ] % 2 != 0 ) { int tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; arr [ j ] = - arr [ j ] ; break ; } else if ( arr [ i ] >= 0 && arr [ j ] >= 0 && arr [ i ] % 2 != 0 && arr [ j ] % 2 == 0 ) { int tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; arr [ j ] = - arr [ j ] ; break ; } } } for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = Math . Abs ( arr [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 2 , 4 } ; replace ( arr ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GfG { public class Node { public int data ; public Node left , right ; } static int gethalfCount ( Node root ) { if ( root == null ) return 0 ; int res = 0 ; if ( ( root . left == null && root . right != null ) || ( root . left != null && root . right == null ) ) res ++ ; res += ( gethalfCount ( root . left ) + gethalfCount ( root . right ) ) ; return res ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void Main ( ) { Node root = newNode ( 2 ) ; root . left = newNode ( 7 ) ; root . right = newNode ( 5 ) ; root . left . right = newNode ( 6 ) ; root . left . right . left = newNode ( 1 ) ; root . left . right . right = newNode ( 11 ) ; root . right . right = newNode ( 9 ) ; root . right . right . left = newNode ( 4 ) ; Console . WriteLine ( gethalfCount ( root ) ) ; } }

Accumulator variables: res
Class/struct names: GfG, Node
C# program:
using System ; class GFG { static int minimumCostToMergeK ( int [ ] arr , int K , int N ) { if ( ( N - 1 ) % ( K - 1 ) != 0 ) { return - 1 ; } int [ ] prefixSum = new int [ N + 1 ] ; for ( int i = 1 ; i < ( N + 1 ) ; i ++ ) { prefixSum [ i ] = ( prefixSum [ i - 1 ] + arr [ i - 1 ] ) ; } int [ , ] dp = new int [ N , N ] ; for ( int L = K ; L < ( N + 1 ) ; L ++ ) { for ( int i = 0 ; i < ( N - L + 1 ) ; i ++ ) { int j = i + L - 1 ; if ( L > K ) { int temp = int . MaxValue ; for ( int x = i ; x < j ; x += K - 1 ) { temp = Math . Min ( temp , dp [ i , x ] + dp [ x + 1 , j ] ) ; } dp [ i , j ] = temp ; } if ( ( L - 1 ) % ( K - 1 ) == 0 ) { dp [ i , j ] += ( prefixSum [ j + 1 ] - prefixSum [ i ] ) ; } } } return dp [ 0 , N - 1 ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 5 , 1 , 2 , 6 } ; int K = 3 ; int N = arr . Length ; Console . Write ( minimumCostToMergeK ( arr , K , N ) ) ; } }

Index/key variables: i
Accumulator variables: L, i, x
Iterator variables: L, i, x
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 8 ; static int check ( int [ , ] memo , int i , int j , int [ ] A ) { if ( i == N - 1 ) return 1 ; if ( memo [ i , j ] != - 1 ) return memo [ i , j ] ; int flag = 0 , k ; for ( k = i + 1 ; k < N ; k ++ ) { if ( A [ k ] - A [ i ] > j + 1 ) break ; if ( A [ k ] - A [ i ] >= j - 1 && A [ k ] - A [ i ] <= j + 1 ) flag = check ( memo , k , A [ k ] - A [ i ] , A ) ; if ( flag != 0 ) break ; } memo [ i , j ] = flag ; return memo [ i , j ] ; } static void checkEndReach ( int [ ] A , int K ) { int [ , ] memo = new int [ N , N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { memo [ i , j ] = - 1 ; } } int startIndex = 1 ; if ( check ( memo , startIndex , K , A ) != 0 ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( ) { int [ ] A = { 0 , 1 , 3 , 5 , 6 , 8 , 12 , 17 } ; int K = 1 ; checkEndReach ( A , K ) ; } }

Index/key variables: i, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int Max_Sum ( int [ ] arr , int K , int N ) { int [ ] dp = new int [ N + 1 ] ; Array . Fill ( dp , 0 ) ; int [ ] prefix = new int [ N + 1 ] ; prefix [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + arr [ i - 1 ] ; } dp [ 0 ] = 0 ; for ( int i = 1 ; i <= K - 1 ; i ++ ) { dp [ i ] = prefix [ i ] ; } for ( int i = K ; i <= N ; ++ i ) { for ( int j = i ; j >= ( i - K + 1 ) ; j -- ) { dp [ i ] = Math . Max ( dp [ i ] , dp [ j - 1 ] + prefix [ i ] - prefix [ j ] ) ; } } return dp [ N ] ; } static public void Main ( ) { int [ ] arr = { 4 , 12 , 22 , 18 , 34 , 12 , 25 } ; int N = arr . Length ; int K = 5 ; Console . WriteLine ( Max_Sum ( arr , K , N ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int binomialCoeff ( int n , int k ) { int [ , ] C = new int [ n + 1 , k + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . Min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i , j ] = 1 ; else C [ i , j ] = C [ i - 1 , j - 1 ] + C [ i - 1 , j ] ; } } return C [ n , k ] ; } static int waysToSplitN ( int k , int n , int P ) { int new_N = n - k * P ; return binomialCoeff ( new_N + k - 1 , new_N ) ; } public static void Main ( ) { int K = 3 , N = 8 , P = 2 ; Console . Write ( waysToSplitN ( K , N , P ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int solve ( int [ ] a ) { int n = a . Length ; int [ ] dp = new int [ n + 1 ] ; int [ ] val = new int [ n + 1 ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { int sum = a [ i ] ; int j = i ; while ( j + 1 < n && sum < val [ j + 1 ] ) { j ++ ; sum += a [ j ] ; } dp [ i ] = ( j - i ) + dp [ j + 1 ] ; val [ i ] = sum ; } return dp [ 0 ] ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 5 , 3 , 9 , 1 } ; Console . Write ( solve ( arr ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = null ; right = null ; } } public class BinaryTree { Node root ; int getfullCount ( ) { if ( root == null ) return 0 ; Queue < Node > queue = new Queue < Node > ( ) ; queue . Enqueue ( root ) ; int count = 0 ; while ( queue . Count != 0 ) { Node temp = queue . Dequeue ( ) ; if ( temp . left != null && temp . right != null ) count ++ ; if ( temp . left != null ) { queue . Enqueue ( temp . left ) ; } if ( temp . right != null ) { queue . Enqueue ( temp . right ) ; } } return count ; } public static void Main ( String [ ] args ) { BinaryTree tree_level = new BinaryTree ( ) ; tree_level . root = new Node ( 2 ) ; tree_level . root . left = new Node ( 7 ) ; tree_level . root . right = new Node ( 5 ) ; tree_level . root . left . right = new Node ( 6 ) ; tree_level . root . left . right . left = new Node ( 1 ) ; tree_level . root . left . right . right = new Node ( 11 ) ; tree_level . root . right . right = new Node ( 9 ) ; tree_level . root . right . right . left = new Node ( 4 ) ; Console . WriteLine ( tree_level . getfullCount ( ) ) ; } }

Accumulator variables: count
Class/struct names: BinaryTree, Node
C# program:
using System ; using System . Collections . Generic ; class GFG { static int distinctSimilarSubstrings ( string str ) { int n = str . Length ; if ( n <= 1 ) return 0 ; long [ , ] dp = new long [ n + 1 , n + 1 ] ; List < string > list = new List < string > ( ) ; for ( int j = n - 1 ; j >= 0 ; j -- ) { for ( int i = j - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == str [ j ] ) { dp [ i , j ] = dp [ i + 1 , j + 1 ] + 1 ; } else { dp [ i , j ] = 0 ; } if ( dp [ i , j ] >= j - i ) { list . Add ( str . Substring ( i , j - i ) ) ; } } } return list . Count ; } static void Main ( ) { string str = " geeksforgeeks " ; Console . WriteLine ( distinctSimilarSubstrings ( str ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static readonly int MAXN = 100 ; static int INF = ( int ) 1e7 ; static int [ , ] dis = new int [ MAXN , MAXN ] ; static int [ , ] Next = new int [ MAXN , MAXN ] ; static void initialise ( int V , int [ , ] graph ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { dis [ i , j ] = graph [ i , j ] ; if ( graph [ i , j ] == INF ) Next [ i , j ] = - 1 ; else Next [ i , j ] = j ; } } } static List < int > constructPath ( int u , int v ) { if ( Next [ u , v ] == - 1 ) return null ; List < int > path = new List < int > ( ) ; path . Add ( u ) ; while ( u != v ) { u = Next [ u , v ] ; path . Add ( u ) ; } return path ; } static void floydWarshall ( int V ) { for ( int k = 0 ; k < V ; k ++ ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { if ( dis [ i , k ] == INF dis [ k , j ] == INF ) continue ; if ( dis [ i , j ] > dis [ i , k ] + dis [ k , j ] ) { dis [ i , j ] = dis [ i , k ] + dis [ k , j ] ; Next [ i , j ] = Next [ i , k ] ; } } } } } static void printPath ( List < int > path ) { int n = path . Count ; for ( int i = 0 ; i < n - 1 ; i ++ ) Console . Write ( path [ i ] + " ▁ - > ▁ " ) ; Console . Write ( path [ n - 1 ] + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int V = 4 ; int [ , ] graph = { { 0 , 3 , INF , 7 } , { 8 , 0 , 2 , INF } , { 5 , INF , 0 , 1 } , { 2 , INF , INF , 0 } } ; initialise ( V , graph ) ; floydWarshall ( V ) ; List < int > path ; Console . Write ( " Shortest ▁ path ▁ from ▁ 1 ▁ to ▁ 3 : ▁ " ) ; path = constructPath ( 1 , 3 ) ; printPath ( path ) ; Console . Write ( " Shortest ▁ path ▁ from ▁ 0 ▁ to ▁ 2 : ▁ " ) ; path = constructPath ( 0 , 2 ) ; printPath ( path ) ; Console . Write ( " Shortest ▁ path ▁ from ▁ 3 ▁ to ▁ 2 : ▁ " ) ; path = constructPath ( 3 , 2 ) ; printPath ( path ) ; } }

Index/key variables: i
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < int > [ ] vp = new List < int > [ 2009 ] ; static void finding_factors ( int n ) { int i ; for ( i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i == n ) { vp [ n ] . Add ( i ) ; } else { vp [ n ] . Add ( i ) ; vp [ n ] . Add ( n / i ) ; } } } } static int countSeq ( int N , int K ) { int i , j , k ; int [ , ] dp = new int [ 109 , 109 ] ; for ( i = 1 ; i <= N ; i ++ ) { finding_factors ( i ) ; dp [ 0 , i ] = 0 ; dp [ 1 , i ] = 1 ; } for ( i = 2 ; i <= K ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { int sum = 0 ; for ( k = 0 ; k < vp [ j ] . Count ; k ++ ) { sum = ( sum + dp [ i - 1 , vp [ j ] [ k ] ] ) ; } dp [ i , j ] = sum ; } } int ans = 0 ; for ( j = 1 ; j <= N ; j ++ ) { ans = ( ans + dp [ K , j ] ) ; } return ans ; } public static void Main ( String [ ] args ) { int N , K ; N = 3 ; K = 2 ; for ( int i = 0 ; i < vp . Length ; i ++ ) vp [ i ] = new List < int > ( ) ; Console . Write ( countSeq ( N , K ) + " STRNEWLINE " ) ; } }

Index/key variables: i, j, k, n
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX_value ( int [ , ] arr ) { int row = arr . GetLength ( 0 ) ; int col = arr . GetLength ( 1 ) ; int [ , ] dp = new int [ row , col ] ; int i = 0 , j = 0 ; int c = arr [ 0 , 0 ] , p = 0 ; int d = row ; for ( i = 0 ; i < d ; i ++ ) { for ( j = 0 ; j < d ; j ++ ) { if ( c < arr [ i , j ] ) { c = arr [ i , j ] ; } if ( i == 0 j == 0 ) { dp [ i , j ] = 1 ; } else { if ( arr [ i - 1 , j - 1 ] == arr [ i , j ] && arr [ i - 1 , j ] == arr [ i , j ] && arr [ i , j - 1 ] == arr [ i , j ] ) { dp [ i , j ] = Math . Min ( dp [ i - 1 , j - 1 ] , Math . Min ( dp [ i - 1 , j ] , dp [ i , j - 1 ] ) ) + 1 ; } else { dp [ i , j ] = 1 ; } } } } for ( i = 0 ; i < d ; i ++ ) { for ( j = 0 ; j < d ; j ++ ) { if ( arr [ i , j ] == c ) { if ( p < dp [ i , j ] ) { p = dp [ i , j ] ; } } } } return p * p ; } public static void Main ( String [ ] args ) { int [ , ] arr = { { 9 , 9 , 3 , 3 , 4 , 4 } , { 9 , 9 , 7 , 7 , 7 , 4 } , { 1 , 2 , 7 , 7 , 7 , 4 } , { 4 , 4 , 7 , 7 , 7 , 4 } , { 5 , 5 , 1 , 1 , 2 , 7 } , { 2 , 7 , 1 , 1 , 4 , 4 } } ; Console . Write ( MAX_value ( arr ) + " STRNEWLINE " ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int smallestNum ( int n ) { for ( int i = 2 ; ; i *= 2 ) { int length = ( int ) ( Math . Log10 ( i ) ) + 1 ; if ( length == n ) return ( int ) ( Math . Log ( i ) / Math . Log ( 2 ) ) ; } } public static void Main ( ) { int n = 4 ; Console . Write ( smallestNum ( n ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int N = 100005 ; static int [ ] level = new int [ N ] ; static int LG = 20 ; static int [ , ] dp = new int [ LG , N ] ; static int [ , ] mx = new int [ LG , N ] ; static List < List < Tuple < int , int > > > v = new List < List < Tuple < int , int > > > ( ) ; static int n = 0 ; static void dfs_lca ( int a , int par , int lev ) { dp [ 0 , a ] = par ; level [ a ] = lev ; for ( int i = 0 ; i < v [ a ] . Count ; i ++ ) { if ( v [ a ] [ i ] . Item1 == par ) continue ; mx [ 0 , v [ a ] [ i ] . Item1 ] = v [ a ] [ i ] . Item2 ; dfs_lca ( v [ a ] [ i ] . Item1 , a , lev + 1 ) ; } } static void find_ancestor ( ) { for ( int i = 1 ; i < 16 ; i ++ ) { for ( int j = 1 ; j < n + 1 ; j ++ ) { dp [ i , j ] = dp [ i - 1 , dp [ i - 1 , j ] ] ; mx [ i , j ] = Math . Max ( mx [ i - 1 , j ] , mx [ i - 1 , dp [ i - 1 , j ] ] ) ; } } } static int getMax ( int a , int b ) { if ( level [ b ] < level [ a ] ) { int temp = a ; a = b ; b = temp ; } int ans = 0 ; int diff = level [ b ] - level [ a ] ; while ( diff > 0 ) { int log = ( int ) ( Math . Log ( diff ) / Math . Log ( 2 ) ) ; ans = Math . Max ( ans , mx [ log , b ] ) ; b = dp [ log , b ] ; diff -= ( 1 << log ) ; } while ( a != b ) { int i = ( int ) ( Math . Log ( level [ a ] ) / Math . Log ( 2 ) ) ; while ( i > 0 && dp [ i , a ] == dp [ i , b ] ) { i -= 1 ; } ans = Math . Max ( ans , mx [ i , a ] ) ; ans = Math . Max ( ans , mx [ i , b ] ) ; a = dp [ i , a ] ; b = dp [ i , b ] ; } return ans ; } static void compute_lca ( ) { dfs_lca ( 1 , 0 , 0 ) ; find_ancestor ( ) ; } static void Main ( ) { for ( int i = 0 ; i < LG ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { dp [ i , j ] = 0 ; mx [ i , j ] = 0 ; } } for ( int i = 0 ; i < N ; i ++ ) { v . Add ( new List < Tuple < int , int > > ( ) ) ; } v [ 1 ] . Add ( new Tuple < int , int > ( 2 , 2 ) ) ; v [ 2 ] . Add ( new Tuple < int , int > ( 1 , 2 ) ) ; v [ 1 ] . Add ( new Tuple < int , int > ( 3 , 5 ) ) ; v [ 3 ] . Add ( new Tuple < int , int > ( 1 , 5 ) ) ; v [ 3 ] . Add ( new Tuple < int , int > ( 4 , 3 ) ) ; v [ 4 ] . Add ( new Tuple < int , int > ( 3 , 4 ) ) ; v [ 3 ] . Add ( new Tuple < int , int > ( 5 , 1 ) ) ; v [ 5 ] . Add ( new Tuple < int , int > ( 3 , 1 ) ) ; compute_lca ( ) ; int [ , ] queries = { { 3 , 5 } , { 2 , 3 } , { 2 , 4 } } ; int q = 3 ; for ( int i = 0 ; i < q ; i ++ ) { int max_edge = getMax ( queries [ i , 0 ] , queries [ i , 1 ] ) ; Console . WriteLine ( max_edge ) ; } } }

Index/key variables: N, a, b, i
Accumulator variables: diff, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GfG { public class Node { public int data ; public Node left , right ; } static int getfullCount ( Node root ) { if ( root == null ) return 0 ; int res = 0 ; if ( root . left != null && root . right != null ) res ++ ; res += ( getfullCount ( root . left ) + getfullCount ( root . right ) ) ; return res ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void Main ( ) { Node root = newNode ( 2 ) ; root . left = newNode ( 7 ) ; root . right = newNode ( 5 ) ; root . left . right = newNode ( 6 ) ; root . left . right . left = newNode ( 1 ) ; root . left . right . right = newNode ( 11 ) ; root . right . right = newNode ( 9 ) ; root . right . right . left = newNode ( 4 ) ; Console . WriteLine ( getfullCount ( root ) ) ; } }

Accumulator variables: res
Class/struct names: GfG, Node
C# program:
using System ; class GFG { static int countDecodingDP ( String digits , int n ) { if ( digits [ 0 ] == '0' ) { return 0 ; } int count0 = 1 , count1 = 1 , count2 ; for ( int i = 2 ; i <= n ; i ++ ) { int dig1 = 0 , dig2 , dig3 = 0 ; if ( digits [ i - 1 ] != '0' ) { dig1 = 1 ; } if ( digits [ i - 2 ] == '1' ) { dig2 = 1 ; } else dig2 = 0 ; if ( digits [ i - 2 ] == '2' && digits [ i - 1 ] < '7' ) { dig3 = 1 ; } count2 = dig1 * count1 + dig2 + dig3 * count0 ; count0 = count1 ; count1 = count2 ; } return count1 ; } public static void Main ( String [ ] args ) { String digits = "1234" ; int n = digits . Length ; Console . Write ( countDecodingDP ( digits , n ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxDistance ( int [ , ] grid ) { if ( grid . GetLength ( 0 ) == 0 ) return - 1 ; int N = grid . GetLength ( 0 ) ; int INF = 1000000 ; grid [ 0 , 0 ] = grid [ 0 , 0 ] == 1 ? 0 : INF ; for ( int i = 1 ; i < N ; i ++ ) grid [ 0 , i ] = grid [ 0 , i ] == 1 ? 0 : grid [ 0 , i - 1 ] + 1 ; for ( int i = 1 ; i < N ; i ++ ) grid [ i , 0 ] = grid [ i , 0 ] == 1 ? 0 : grid [ i - 1 , 0 ] + 1 ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j < N ; j ++ ) { grid [ i , j ] = grid [ i , j ] == 1 ? 0 : Math . Min ( grid [ i - 1 , j ] , grid [ i , j - 1 ] ) + 1 ; } } if ( grid [ N - 1 , N - 1 ] >= INF ) return - 1 ; int maxi = grid [ N - 1 , N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) { grid [ N - 1 , i ] = Math . Min ( grid [ N - 1 , i ] , grid [ N - 1 , i + 1 ] + 1 ) ; maxi = Math . Max ( grid [ N - 1 , i ] , maxi ) ; } for ( int i = N - 2 ; i >= 0 ; i -- ) { grid [ i , N - 1 ] = Math . Min ( grid [ i , N - 1 ] , grid [ i + 1 , N - 1 ] + 1 ) ; maxi = Math . Max ( grid [ i , N - 1 ] , maxi ) ; } for ( int i = N - 2 ; i >= 0 ; i -- ) { for ( int j = N - 2 ; j >= 0 ; j -- ) { grid [ i , j ] = Math . Min ( grid [ i , j ] , Math . Min ( grid [ i + 1 , j ] + 1 , grid [ i , j + 1 ] + 1 ) ) ; maxi = Math . Max ( grid [ i , j ] , maxi ) ; } } return maxi == 0 ? - 1 : maxi ; } public static void Main ( ) { int [ , ] arr = { { 0 , 0 , 1 } , { 0 , 0 , 0 } , { 0 , 0 , 0 } } ; Console . WriteLine ( maxDistance ( arr ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int findCost ( int [ , ] cost_mat , int N , int M ) { int [ , ] dp = new int [ N , M ] ; for ( int i = 0 ; i < M ; i ++ ) dp [ 0 , i ] = cost_mat [ 0 , i ] ; for ( int row = 1 ; row < N ; row ++ ) { for ( int curr_col = 0 ; curr_col < M ; curr_col ++ ) { int val = 999999999 ; for ( int prev_col = 0 ; prev_col < M ; prev_col ++ ) { if ( curr_col != prev_col ) val = Math . Min ( val , dp [ row - 1 , prev_col ] ) ; } dp [ row , curr_col ] = val + cost_mat [ row , curr_col ] ; } } int ans = int . MaxValue ; for ( int i = 0 ; i < M ; i ++ ) ans = Math . Min ( ans , dp [ N - 1 , i ] ) ; return ans ; } public static void Main ( string [ ] args ) { int N = 4 ; int M = 4 ; int [ , ] cost_mat = { { 4 , 5 , 3 , 2 } , { 6 , 2 , 8 , 1 } , { 6 , 2 , 2 , 1 } , { 0 , 5 , 5 , 1 } } ; Console . WriteLine ( findCost ( cost_mat , N , M ) ) ; } }

Accumulator variables: curr_col, i, prev_col, row
Iterator variables: curr_col, i, prev_col, row
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void getPrimesFromSeive ( HashSet < String > primes ) { bool [ ] prime = new bool [ 1000001 ] ; for ( int i = 0 ; i < 1000001 ; i ++ ) prime [ i ] = true ; prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i * i <= 1000000 ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * i ; j <= 1000000 ; j += i ) prime [ j ] = false ; } } for ( int i = 2 ; i <= 1000000 ; i ++ ) { if ( prime [ i ] == true ) primes . Add ( String . Join ( " " , i ) ) ; } } static int splitIntoPrimes ( String number ) { int numLen = number . Length ; int [ ] splitDP = new int [ numLen + 1 ] ; for ( int i = 0 ; i < numLen + 1 ; i ++ ) splitDP [ i ] = - 1 ; HashSet < String > primes = new HashSet < String > ( ) ; getPrimesFromSeive ( primes ) ; for ( int i = 1 ; i <= numLen ; i ++ ) { if ( i <= 6 && ( primes . Contains ( number . Substring ( 0 , i ) ) ) ) splitDP [ i ] = 1 ; if ( splitDP [ i ] != - 1 ) { for ( int j = 1 ; j <= 6 && i + j <= numLen ; j ++ ) { if ( primes . Contains ( number . Substring ( i , j ) ) ) { if ( splitDP [ i + j ] == - 1 ) splitDP [ i + j ] = 1 + splitDP [ i ] ; else splitDP [ i + j ] = Math . Min ( splitDP [ i + j ] , 1 + splitDP [ i ] ) ; } } } } return splitDP [ numLen ] ; } public static void Main ( String [ ] args ) { Console . Write ( splitIntoPrimes ( "13499315" ) + " STRNEWLINE " ) ; Console . Write ( splitIntoPrimes ( "43" ) + " STRNEWLINE " ) ; } }

Index/key variables: i, j, numLen
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class Connect_node_same_level { class Node { public int data ; public Node left , right , nextRight ; public Node ( int data ) { this . data = data ; left = null ; right = null ; nextRight = null ; } } ; static void connect ( Node root ) { Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; q . Enqueue ( null ) ; while ( q . Count != 0 ) { Node p = q . Peek ( ) ; q . Dequeue ( ) ; if ( p != null ) { p . nextRight = q . Peek ( ) ; if ( p . left != null ) q . Enqueue ( p . left ) ; if ( p . right != null ) q . Enqueue ( p . right ) ; } else if ( q . Count != 0 ) q . Enqueue ( null ) ; } } public static void Main ( ) { Node root = new Node ( 10 ) ; root . left = new Node ( 8 ) ; root . right = new Node ( 2 ) ; root . left . left = new Node ( 3 ) ; root . right . right = new Node ( 90 ) ; connect ( root ) ; Console . WriteLine ( " Following ▁ are ▁ populated ▁ nextRight ▁ pointers ▁ in ▁ STRNEWLINE " + " the ▁ tree ▁ ( -1 ▁ is ▁ printed ▁ if ▁ there ▁ is ▁ no ▁ nextRight ) " ) ; Console . WriteLine ( " nextRight ▁ of ▁ " + root . data + " ▁ is ▁ " + ( ( root . nextRight != null ) ? root . nextRight . data : - 1 ) ) ; Console . WriteLine ( " nextRight ▁ of ▁ " + root . left . data + " ▁ is ▁ " + ( ( root . left . nextRight != null ) ? root . left . nextRight . data : - 1 ) ) ; Console . WriteLine ( " nextRight ▁ of ▁ " + root . right . data + " ▁ is ▁ " + ( ( root . right . nextRight != null ) ? root . right . nextRight . data : - 1 ) ) ; Console . WriteLine ( " nextRight ▁ of ▁ " + root . left . left . data + " ▁ is ▁ " + ( ( root . left . left . nextRight != null ) ? root . left . left . nextRight . data : - 1 ) ) ; Console . WriteLine ( " nextRight ▁ of ▁ " + root . right . right . data + " ▁ is ▁ " + ( ( root . right . right . nextRight != null ) ? root . right . right . nextRight . data : - 1 ) ) ; } }

Class/struct names: Connect_node_same_level, Node