      SUBROUTINE ccsdt_lambda3(d_f1,d_i0,d_t1,d_t2,d_v2,d_y1,d_y2,d_y3,k
     &_f1_offset,k_i0_offset,k_t1_offset,k_t2_offset,k_v2_offset,k_y1_of
     &fset,k_y2_offset,k_y3_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = 1 * P( 9 ) * y ( h4 p1 )_y * v ( h5 h6 p2 p3 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yf + = 1 * P( 9 ) * y ( h4 h5 p1 p2 )_y * i1 ( h6 p3 )_f
C         i1 ( h4 p1 )_f + = 1 * f ( h4 p1 )_f
C         i1 ( h4 p1 )_vt + = 1 * Sum ( h8 p7 ) * t ( p7 h8 )_t * v ( h4 h8 p1 p7 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( h9 ) * y ( h4 h9 p1 p2 )_y * i1 ( h5 h6 h9 p3 )_v
C         i1 ( h4 h5 h9 p1 )_v + = 1 * v ( h4 h5 h9 p1 )_v
C         i1 ( h4 h5 h9 p1 )_vt + = -1 * Sum ( p7 ) * t ( p7 h9 )_t * v ( h4 h5 p1 p7 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( p7 ) * y ( h4 h5 p1 p7 )_y * v ( h6 p7 p2 p3 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yf + = -1 * P( 3 ) * Sum ( h11 ) * y ( h4 h5 h11 p1 p2 p3 )_y * i1 ( h6 h11 )_f
C         i1 ( h4 h11 )_f + = 1 * f ( h4 h11 )_f
C         i1 ( h4 h11 )_ft + = 1 * Sum ( p7 ) * t ( p7 h11 )_t * i2 ( h4 p7 )_f
C             i2 ( h4 p7 )_f + = 1 * f ( h4 p7 )_f
C             i2 ( h4 p7 )_vt + = 1 * Sum ( h10 p9 ) * t ( p9 h10 )_t * v ( h4 h10 p7 p9 )_v
C         i1 ( h4 h11 )_vt + = 1 * Sum ( h8 p7 ) * t ( p7 h8 )_t * v ( h4 h8 h11 p7 )_v
C         i1 ( h4 h11 )_vt + = -1/2 * Sum ( h10 p7 p8 ) * t ( p7 p8 h10 h11 )_t * v ( h4 h10 p7 p8 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yf + = 1 * P( 3 ) * Sum ( p12 ) * y ( h4 h5 h6 p1 p2 p12 )_y * i1 ( p12 p3 )_f
C         i1 ( p12 p1 )_f + = 1 * f ( p12 p1 )_f
C         i1 ( p12 p1 )_vt + = -1 * Sum ( h8 p7 ) * t ( p7 h8 )_t * v ( h8 p12 p1 p7 )_v
C         i1 ( p12 p1 )_vt + = 1/2 * Sum ( h9 h10 p8 ) * t ( p8 p12 h9 h10 )_t * v ( h9 h10 p1 p8 )_v
C         i1 ( p12 p1 )_vtt + = -1 * Sum ( h8 ) * t ( p12 h8 )_t * i2 ( h8 p1 )_vt
C             i2 ( h8 p1 )_vt + = 1 * Sum ( h10 p9 ) * t ( p9 h10 )_t * v ( h8 h10 p1 p9 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = 1/2 * P( 3 ) * Sum ( h12 h11 ) * y ( h4 h11 h12 p1 p2 p3 )_y * i1 ( h5 h6 h11 h12 )_v
C         i1 ( h4 h5 h11 h12 )_v + = 1 * v ( h4 h5 h11 h12 )_v
C         i1 ( h4 h5 h11 h12 )_vt + = -2 * Sum ( p7 ) * t ( p7 h11 )_t * i2 ( h4 h5 h12 p7 )_v
C             i2 ( h4 h5 h12 p7 )_v + = 1 * v ( h4 h5 h12 p7 )_v
C             i2 ( h4 h5 h12 p7 )_vt + = -1/2 * Sum ( p9 ) * t ( p9 h12 )_t * v ( h4 h5 p7 p9 )_v
C         i1 ( h4 h5 h11 h12 )_vt + = 1/2 * Sum ( p7 p8 ) * t ( p7 p8 h11 h12 )_t * v ( h4 h5 p7 p8 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( h12 p9 ) * y ( h4 h5 h12 p1 p2 p9 )_y * i1 ( h6 p9 h12 p3 )_v
C         i1 ( h4 p9 h12 p1 )_v + = 1 * v ( h4 p9 h12 p1 )_v
C         i1 ( h4 p9 h12 p1 )_vt + = -1 * Sum ( p7 ) * t ( p7 h12 )_t * v ( h4 p9 p1 p7 )_v
C         i1 ( h4 p9 h12 p1 )_vt + = -1 * Sum ( h10 p8 ) * t ( p8 p9 h10 h12 )_t * v ( h4 h10 p1 p8 )_v
C         i1 ( h4 p9 h12 p1 )_vtt + = 1 * Sum ( h10 ) * t ( p9 h10 )_t * i2 ( h4 h10 h12 p1 )_vt
C             i2 ( h4 h10 h12 p1 )_vt + = 1 * Sum ( p7 ) * t ( p7 h12 )_t * v ( h4 h10 p1 p7 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = 1/2 * P( 3 ) * Sum ( p8 p7 ) * y ( h4 h5 h6 p1 p7 p8 )_y * v ( p7 p8 p2 p3 )_v
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = -1 * P( 9 ) * Sum ( h11 ) * i1 ( h4 h5 h11 p1 )_yt * v ( h6 h11 p2 p3 )_v
C         i1 ( h4 h5 h11 p1 )_yt + = -1 * Sum ( p7 ) * t ( p7 h11 )_t * y ( h4 h5 p1 p7 )_y
C         i1 ( h4 h5 h11 p1 )_yt + = 1/2 * Sum ( h9 p8 p7 ) * t ( p7 p8 h9 h11 )_t * y ( h4 h5 h9 p1 p7 p8 )_y
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytf + = -1 * P( 3 ) * Sum ( h7 ) * i1 ( h4 h5 h6 h7 p1 p2 )_yt * f ( h7 p3 )_f
C         i1 ( h4 h5 h6 h7 p1 p2 )_yt + = 1 * Sum ( p8 ) * t ( p8 h7 )_t * y ( h4 h5 h6 p1 p2 p8 )_y
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = 1 * P( 9 ) * Sum ( h9 h8 ) * i1 ( h4 h5 h9 h8 p1 p2 )_yt * v ( h6 h8 h9 p3 )_v
C         i1 ( h4 h5 h9 h8 p1 p2 )_yt + = 1 * Sum ( p7 ) * t ( p7 h8 )_t * y ( h4 h5 h9 p1 p2 p7 )_y
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = 1 * P( 3 ) * Sum ( h8 p9 ) * i1 ( h4 h5 h6 h8 p1 p9 )_yt * v ( h8 p9 p2 p3 )_v
C         i1 ( h4 h5 h6 h8 p1 p9 )_yt + = -1 * Sum ( p7 ) * t ( p7 h8 )_t * y ( h4 h5 h6 p1 p7 p9 )_y
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = 1/2 * P( 9 ) * Sum ( p8 ) * i1 ( h4 p8 p1 p2 )_yt * v ( h5 h6 p3 p8 )_v
C         i1 ( h4 p8 p1 p2 )_yt + = -1 * Sum ( h10 h9 p7 ) * t ( p7 p8 h9 h10 )_t * y ( h4 h9 h10 p1 p2 p7 )_y
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = 1/4 * P( 3 ) * Sum ( h11 h10 ) * i1 ( h4 h5 h6 h10 h11 p1 )_yt * v ( h10 h11 p2 p3 )_v
C         i1 ( h4 h5 h6 h10 h11 p1 )_yt + = 1 * Sum ( p8 p7 ) * t ( p7 p8 h10 h11 )_t * y ( h4 h5 h6 p1 p7 p8 )_y
C         i1 ( h4 h5 h6 h10 h11 p1 )_ytt + = 2 * Sum ( p7 ) * t ( p7 h11 )_t * i2 ( h4 h5 h6 h10 p1 p7 )_yt
C             i2 ( h4 h5 h6 h10 p1 p7 )_yt + = -1 * Sum ( p9 ) * t ( p9 h10 )_t * y ( h4 h5 h6 p1 p7 p9 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "util.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_i0
      INTEGER k_i0_offset
      INTEGER d_y1
      INTEGER k_y1_offset
      INTEGER d_v2
      INTEGER k_v2_offset
      INTEGER d_y2
      INTEGER k_y2_offset
      INTEGER d_i1
      INTEGER k_i1_offset
      INTEGER d_y3
      INTEGER k_y3_offset
      INTEGER d_f1
      INTEGER k_f1_offset
      INTEGER l_i1_offset
      INTEGER size_i1
      INTEGER d_t1
      INTEGER k_t1_offset
      INTEGER d_i2
      INTEGER k_i2_offset
      INTEGER d_t2
      INTEGER k_t2_offset
      INTEGER l_i2_offset
      INTEGER size_i2
      CHARACTER*255 filename
      CALL ccsdt_lambda3_1(d_y1,k_y1_offset,d_v2,k_v2_offset,d_i0,k_i0_o
     &ffset)
      CALL OFFSET_ccsdt_lambda3_2_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_2_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_2_1(d_f1,k_f1_offset,d_i1,k_i1_offset)
      CALL ccsdt_lambda3_2_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_2(d_y2,k_y2_offset,d_i1,k_i1_offset,d_i0,k_i0_o
     &ffset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_3_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_3_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_3_1(d_v2,k_v2_offset,d_i1,k_i1_offset)
      CALL ccsdt_lambda3_3_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_3(d_y2,k_y2_offset,d_i1,k_i1_offset,d_i0,k_i0_o
     &ffset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL ccsdt_lambda3_4(d_y2,k_y2_offset,d_v2,k_v2_offset,d_i0,k_i0_o
     &ffset)
      CALL OFFSET_ccsdt_lambda3_5_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_5_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_5_1(d_f1,k_f1_offset,d_i1,k_i1_offset)
      CALL OFFSET_ccsdt_lambda3_5_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsdt_lambda3_5_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsdt_lambda3_5_2_1(d_f1,k_f1_offset,d_i2,k_i2_offset)
      CALL ccsdt_lambda3_5_2_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2,k_
     &i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsdt_lambda3_5_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1
     &_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL ccsdt_lambda3_5_3(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL ccsdt_lambda3_5_4(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_5(d_y3,k_y3_offset,d_i1,k_i1_offset,d_i0,k_i0_o
     &ffset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_6_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_6_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_6_1(d_f1,k_f1_offset,d_i1,k_i1_offset)
      CALL ccsdt_lambda3_6_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL ccsdt_lambda3_6_3(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL OFFSET_ccsdt_lambda3_6_4_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsdt_lambda3_6_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsdt_lambda3_6_4_1(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2,k_
     &i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsdt_lambda3_6_4(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1
     &_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_6(d_y3,k_y3_offset,d_i1,k_i1_offset,d_i0,k_i0_o
     &ffset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_7_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_7_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_7_1(d_v2,k_v2_offset,d_i1,k_i1_offset)
      CALL OFFSET_ccsdt_lambda3_7_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsdt_lambda3_7_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsdt_lambda3_7_2_1(d_v2,k_v2_offset,d_i2,k_i2_offset)
      CALL ccsdt_lambda3_7_2_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2,k_
     &i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsdt_lambda3_7_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1
     &_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL ccsdt_lambda3_7_3(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_7(d_y3,k_y3_offset,d_i1,k_i1_offset,d_i0,k_i0_o
     &ffset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_8_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_8_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_8_1(d_v2,k_v2_offset,d_i1,k_i1_offset)
      CALL ccsdt_lambda3_8_2(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL ccsdt_lambda3_8_3(d_t2,k_t2_offset,d_v2,k_v2_offset,d_i1,k_i1
     &_offset)
      CALL OFFSET_ccsdt_lambda3_8_4_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsdt_lambda3_8_4_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsdt_lambda3_8_4_1(d_t1,k_t1_offset,d_v2,k_v2_offset,d_i2,k_
     &i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsdt_lambda3_8_4(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i1
     &_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_8(d_y3,k_y3_offset,d_i1,k_i1_offset,d_i0,k_i0_o
     &ffset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL ccsdt_lambda3_9(d_y3,k_y3_offset,d_v2,k_v2_offset,d_i0,k_i0_o
     &ffset)
      CALL OFFSET_ccsdt_lambda3_10_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_10_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_10_1(d_t1,k_t1_offset,d_y2,k_y2_offset,d_i1,k_i
     &1_offset)
      CALL ccsdt_lambda3_10_2(d_t2,k_t2_offset,d_y3,k_y3_offset,d_i1,k_i
     &1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_10(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_
     &offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_11_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_11_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_11_1(d_t1,k_t1_offset,d_y3,k_y3_offset,d_i1,k_i
     &1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_11(d_i1,k_i1_offset,d_f1,k_f1_offset,d_i0,k_i0_
     &offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_12_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_12_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_12_1(d_t1,k_t1_offset,d_y3,k_y3_offset,d_i1,k_i
     &1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_12(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_
     &offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_13_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_13_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_13_1(d_t1,k_t1_offset,d_y3,k_y3_offset,d_i1,k_i
     &1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_13(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_
     &offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_14_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_14_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_14_1(d_t2,k_t2_offset,d_y3,k_y3_offset,d_i1,k_i
     &1_offset)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_14(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_
     &offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL OFFSET_ccsdt_lambda3_15_1(l_i1_offset,k_i1_offset,size_i1)
      CALL TCE_FILENAME('ccsdt_lambda3_15_1_i1',filename)
      CALL CREATEFILE(filename,d_i1,size_i1)
      CALL ccsdt_lambda3_15_1(d_t2,k_t2_offset,d_y3,k_y3_offset,d_i1,k_i
     &1_offset)
      CALL OFFSET_ccsdt_lambda3_15_2_1(l_i2_offset,k_i2_offset,size_i2)
      CALL TCE_FILENAME('ccsdt_lambda3_15_2_1_i2',filename)
      CALL CREATEFILE(filename,d_i2,size_i2)
      CALL ccsdt_lambda3_15_2_1(d_t1,k_t1_offset,d_y3,k_y3_offset,d_i2,k
     &_i2_offset)
      CALL RECONCILEFILE(d_i2,size_i2)
      CALL ccsdt_lambda3_15_2(d_t1,k_t1_offset,d_i2,k_i2_offset,d_i1,k_i
     &1_offset)
      CALL DELETEFILE(d_i2)
      IF (.not.MA_POP_STACK(l_i2_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      CALL RECONCILEFILE(d_i1,size_i1)
      CALL ccsdt_lambda3_15(d_i1,k_i1_offset,d_v2,k_v2_offset,d_i0,k_i0_
     &offset)
      CALL DELETEFILE(d_i1)
      IF (.not.MA_POP_STACK(l_i1_offset)) CALL ERRQUIT('ccsdt_lambda3',-
     &1,MA_ERR)
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = 1 * P( 9 ) * y ( h4 p1 )_y * v ( h5 h6 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b_1
      INTEGER p1b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h4b = 1,noab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = noab+1,noab+nvab
      DO p3b = p2b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. irrep_y) TH
     &EN
      CALL TCE_RESTRICTED_2(h4b,p1b,h4b_1,p1b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p2b,p3b,h5b_2,h6b_2,p2b_2,p3b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p2b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (h4b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_1',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_1',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_1',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_1',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_1',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_1',9,MA_ERR)
      IF ((h4b .le. h5b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,4,3,5,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h5b) .and. (p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,4,3,2,5,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h5b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,4,3,2,1,5,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,6,3,5,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p2b .le. p1b) .and.
     & (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,6,3,2,5,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,6,3,2,1,5,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,3,6,5,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,3,6,2,5,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),4,3,6,2,1,5,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_1',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_1',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs,1)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yf + = 1 * P( 9 ) * y ( h4 h5 p1 p2 )_y * i1 ( h6 p3 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs,1)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_f)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,p2b,h4b_1,h5b_1,p1b_1,p2b_1)
      CALL TCE_RESTRICTED_2(h6b,p3b,h6b_2,p3b_2)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h5b_1 - 1 + noab 
     &* (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_2',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (h6b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_2',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_2',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_2',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_2',9,MA_ERR)
      IF ((h5b .le. h6b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,4,3,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,1,4,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,4,1,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,4,3,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,1,4,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,4,1,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,4,3,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,1,4,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p1b .le. p3b) .and.
     & (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,4,1,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_2',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_2',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs,1)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_2_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p1 )_f + = 1 * f ( h4 p1 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p1b
      INTEGER dimc
      INTEGER h4b_1
      INTEGER p1b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      CALL TCE_RESTRICTED_2(h4b,p1b,h4b_1,p1b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_2_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - 1 + (noab+nvab) * (h4b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_2_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_2_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h4b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_2_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_2_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p1 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER p1b
      length = 0
      DO h4b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p1b - noab - 1 + nvab * (h4b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p1 )_vt + = 1 * Sum ( h8 p7 ) * t ( p7 h8 )_t * v ( h4 h8 p1 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h8b
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER h4b_2
      INTEGER h8b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h8b,p7b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h4b,h8b,p1b,p7b,h4b_2,h8b_2,p1b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h8b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_2_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_2_2',5,MA_ERR)
      IF ((h8b .lt. h4b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,1.0d0)
      END IF
      IF ((h8b .lt. h4b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .le. h8b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1)
     &,4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .le. h8b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1)
     &,3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_2_2',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_2_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_2_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_2_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h4b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_2_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_2_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( h9 ) * y ( h4 h9 p1 p2 )_y * i1 ( h5 h6 h9 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h9b
      INTEGER h4b_1
      INTEGER h9b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER h9b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h9b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h4b,h9b,p1b,p2b,h4b_1,h9b_1,p1b_1,p2b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p3b,h9b,h5b_2,h6b_2,p3b_2,h9b_2)
      dim_common = int_mb(k_range+h9b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1) * int_mb
     &(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_3',2,MA_ERR)
      IF ((h9b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h4b_1 - 1 + noab 
     &* (h9b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1)
     &,4,3,2,1,-1.0d0)
      END IF
      IF ((h4b .le. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h9b_1 - 1 + noab 
     &* (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1)
     &,4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_3',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h9b_2
     & - 1 + noab * (p3b_2 - noab - 1 + nvab * (h6b_2 - 1 + noab * (h5b_
     &2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p3b-1),int_mb(k_range+h9b-1)
     &,3,2,1,4,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_3',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_3',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_3',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_3',9,MA_ERR)
      IF ((h4b .le. h5b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,5,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h5b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,1,5,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h5b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,5,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,5,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,1,5,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p1b .le. p3b) .and.
     & (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,5,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,5,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,1,5,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,5,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_3',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_3',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_3_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h9 p1 )_v + = 1 * v ( h4 h5 h9 p1 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER p1b
      INTEGER h9b
      INTEGER dimc
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER p1b_1
      INTEGER h9b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h9b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h9b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h9b-1)
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,h9b,h4b_1,h5b_1,p1b_1,h9b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_3_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_3_1',1,MA_ERR)
      IF ((h9b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - 1 + (noab+nvab) * (h9b_1 - 1 + (noab+nvab) * (h5b_1 - 1 + (noab
     &+nvab) * (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h9b-1),int_mb(k_range+p1b-1)
     &,3,4,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_3_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_3_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h9b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h5b-1),int_mb(k_range+h4b-1)
     &,4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p1b - noab - 1 + nvab * (h5b - 1 + noab * (h4b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_3_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_3_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_3_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h9 p1 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER p1b
      INTEGER h9b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p1b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_3_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+p1b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h9b - 1 + noab * (p1b - noab - 1 + nvab 
     &* (h5b - 1 + noab * (h4b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+p1b-1) * int_mb(k_range+h9b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_3_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h9 p1 )_vt + = -1 * Sum ( p7 ) * t ( p7 h9 )_t * v ( h4 h5 p1 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER p1b
      INTEGER h9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h9b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h9b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h9b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h9b-1)))) .eq. ieor(irrep_v,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_3_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h9b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h9b,p7b_1,h9b_1)
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,p7b,h4b_2,h5b_2,p1b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_3_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_3_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h9b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_3_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_3_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_3_2',5,MA_ERR)
      IF ((p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_3_2',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_3_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_3_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_3_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),int_mb(k_range+h9b-1)
     &,3,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h9b -
     & 1 + noab * (p1b - noab - 1 + nvab * (h5b - 1 + noab * (h4b - 1)))
     &))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_3_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_3_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( p7 ) * y ( h4 h5 p1 p7 )_y * v ( h6 p7 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER p1b_1
      INTEGER p7b_1
      INTEGER h6b_2
      INTEGER p7b_2
      INTEGER p2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = noab+1,noab+nvab
      DO p3b = p2b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p7b-1)))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,p7b,h4b_1,h5b_1,p1b_1,p7b_1)
      CALL TCE_RESTRICTED_4(h6b,p7b,p2b,p3b,h6b_2,p7b_2,p2b_2,p3b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p2b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_4',2,MA_ERR)
      IF ((p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (p7b_1 - noab - 1 + nvab * (h5b_1 - 1 + noab 
     &* (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p7b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (h5b_1 - 1 + noab 
     &* (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_4',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_4',5,MA_ERR)
      IF ((h6b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (p7b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1)
     &,4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_4',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_4',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_4',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_4',9,MA_ERR)
      IF ((h5b .le. h6b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p2b .le. p1b) .and.
     & (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,2,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_4',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_4',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_5(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yf + = -1 * P( 3 ) * Sum ( h11 ) * y ( h4 h5 h11 p1 p2 p3 )_y * i1 ( h6 h11 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h11b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h11b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER p3b_1
      INTEGER h6b_2
      INTEGER h11b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = p2b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_f)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h11b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h11b-1
     &) .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b
     &-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h11b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),in
     &t_mb(k_sym+p3b-1)))))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_6(h4b,h5b,h11b,p1b,p2b,p3b,h4b_1,h5b_1,h11b_1,
     &p1b_1,p2b_1,p3b_1)
      CALL TCE_RESTRICTED_2(h6b,h11b,h6b_2,h11b_2)
      dim_common = int_mb(k_range+h11b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_mb(k_range+p3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_5',2,MA_ERR)
      IF ((h11b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h5b_1 - 1 + noab * (h4b_1 - 1 + noab * (h11b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,3,2,1,1.0d0)
      END IF
      IF ((h4b .le. h11b) .and. (h11b .lt. h5b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h5b_1 - 1 + noab * (h11b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h11b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,3,1,2,-1.0d0)
      END IF
      IF ((h5b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h11b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h11b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,2,1,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_5',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_5',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h11b_
     &2 - 1 + noab * (h6b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h11b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_5',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_5',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_5',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_5',9,MA_ERR)
      IF ((h5b .le. h6b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,1,4,3,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h6b .le. h4b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),1,6,5,4,3,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p3b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,1,5,4,3,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_5',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_5',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_5_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h11 )_f + = 1 * f ( h4 h11 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h11b
      INTEGER dimc
      INTEGER h4b_1
      INTEGER h11b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h11b-1)) .eq. irrep_f) T
     &HEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      CALL TCE_RESTRICTED_2(h4b,h11b,h4b_1,h11b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_5_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + (noab+nvab) * (h4b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_5_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_5_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h4b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_5_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_5_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_5_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h11 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h11b
      length = 0
      DO h4b = 1,noab
      DO h11b = 1,noab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h11b-1)) .eq. irrep_f) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-
     &1).ne.4)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_5_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h11b = 1,noab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h11b-1)) .eq. irrep_f) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h11b - 1 + noab * (h4b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_5_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h11 )_ft + = 1 * Sum ( p7 ) * t ( p7 h11 )_t * i2 ( h4 p7 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_1
      INTEGER h4b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h11b-1)) .eq. ieor(irrep
     &_f,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h11b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_2(h4b,p7b,h4b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_5_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_5_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_5_2',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (h4b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p7b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_5_2',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_5_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_5_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_5_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h11b-1),1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_5_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_5_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_5_2_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 p7 )_f + = 1 * f ( h4 p7 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p7b
      INTEGER dimc
      INTEGER h4b_1
      INTEGER p7b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p7b-1)
      CALL TCE_RESTRICTED_2(h4b,p7b,h4b_1,p7b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p7b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_5_2_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p7b_1
     & - 1 + (noab+nvab) * (h4b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_5_2_1',2,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_5_2_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h4b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_5_2_1',4,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_5_2_1
     &',5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_5_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 p7 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER p7b
      length = 0
      DO h4b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_5_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p7b-1)) .eq. irrep_f) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p7b - noab - 1 + nvab * (h4b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+p7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_5_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k
     &_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 p7 )_vt + = 1 * Sum ( h10 p9 ) * t ( p9 h10 )_t * v ( h4 h10 p7 p9 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER h10b
      INTEGER p9b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER h10b_2
      INTEGER p7b_2
      INTEGER p9b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p7b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+p7b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p9b,h10b,p9b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h4b,h10b,p7b,p9b,h4b_2,h10b_2,p7b_2,p9b_2)
      dim_common = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p7b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_5_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_5_2_2',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_5_2_2',5,MA_ERR)
      IF ((h10b .lt. h4b) .and. (p9b .lt. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+p9b-1),int_mb(k_range+p7b-1
     &),4,2,1,3,1.0d0)
      END IF
      IF ((h10b .lt. h4b) .and. (p7b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p9b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .le. h10b) .and. (p9b .lt. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p9b-1),int_mb(k_range+p7b-1
     &),4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .le. h10b) .and. (p7b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p7b-1),int_mb(k_range+p9b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_5_2_2',6,M
     &A_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_5_2_2
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_5_2_2
     &',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_5_2_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h4b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_5_2_2',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_5_2_2
     &',11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_5_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h11 )_vt + = 1 * Sum ( h8 p7 ) * t ( p7 h8 )_t * v ( h4 h8 h11 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h8b
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER h4b_2
      INTEGER h8b_2
      INTEGER h11b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h11b-1)) .eq. ieor(irrep
     &_v,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h8b,p7b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h4b,h8b,h11b,p7b,h4b_2,h8b_2,h11b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h8b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_5_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_5_3',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_5_3',5,MA_ERR)
      IF ((h8b .lt. h4b) .and. (h11b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (h11b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noa
     &b+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h11b-1),int_mb(k_range+p7b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .le. h8b) .and. (h11b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (h11b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+h11b-1),int_mb(k_range+p7b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_5_3',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_5_3',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_5_3',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_5_3',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h11b-1
     &),int_mb(k_range+h4b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_5_3',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_5_3',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_5_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h11 )_vt + = -1/2 * Sum ( h10 p7 p8 ) * t ( p7 p8 h10 h11 )_t * v ( h4 h10 p7 p8 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p8b
      INTEGER h10b
      INTEGER p7b_1
      INTEGER p8b_1
      INTEGER h11b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER h10b_2
      INTEGER p7b_2
      INTEGER p8b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+h4b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),int_mb(k_sym+h11b-1)) .eq. ieor(irrep
     &_v,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO p8b = p7b,noab+nvab
      DO h10b = 1,noab
      IF (int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h10b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p7b,p8b,h11b,h10b,p7b_1,p8b_1,h11b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h4b,h10b,p7b,p8b,h4b_2,h10b_2,p7b_2,p8b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1) * int_m
     &b(k_range+h10b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_5_4',2,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p7
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      END IF
      IF ((h11b .lt. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h11b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p7
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h11b-1),int_mb(k_range+h10b-
     &1),3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_5_4',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_5_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_5_4',5,MA_ERR)
      IF ((h10b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p8b-1
     &),2,1,4,3,-1.0d0)
      END IF
      IF ((h4b .le. h10b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p7b-1),int_mb(k_range+p8b-1
     &),1,2,4,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_5_4',6,MA_
     &ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p7b .eq. p8b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_5_4',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_5_4',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_5_4',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h11b-1),1,2,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h4b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_5_4',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_5_4',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_6(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yf + = 1 * P( 3 ) * Sum ( p12 ) * y ( h4 h5 h6 p1 p2 p12 )_y * i1 ( p12 p3 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p12b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER p12b_1
      INTEGER p12b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_f)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p12b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p12b
     &-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p12b-1)))))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,p2b,p12b,h4b_1,h5b_1,h6b_1,p
     &1b_1,p2b_1,p12b_1)
      CALL TCE_RESTRICTED_2(p12b,p3b,p12b_2,p3b_2)
      dim_common = int_mb(k_range+p12b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_6',2,MA_ERR)
      IF ((p12b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (p12b_1 - noab - 1
     & + nvab * (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p12b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,3,2,1,4,1.0d0)
      END IF
      IF ((p1b .le. p12b) .and. (p12b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p12b_1 - noab - 1 + nvab * (p1b_1 - noab - 1
     & + nvab * (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p12b-1),int_mb(k_range+p2b-1),6,4,3,2,1,5,-1.0d0)
      END IF
      IF ((p2b .le. p12b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p12b_
     &1 - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1
     & + nvab * (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p12b-1),5,4,3,2,1,6,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_6',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_6',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - noab - 1 + nvab * (p12b_2 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_6',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_6',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_6',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_6',9,MA_ERR)
      IF ((p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,1,3,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,3,1,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_6',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_6',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_6_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( p12 p1 )_f + = 1 * f ( p12 p1 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p12b
      INTEGER p1b
      INTEGER dimc
      INTEGER p12b_1
      INTEGER p1b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO p12b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+p1b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) T
     &HEN
      dimc = int_mb(k_range+p12b-1) * int_mb(k_range+p1b-1)
      CALL TCE_RESTRICTED_2(p12b,p1b,p12b_1,p1b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+p12b-1) * int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_6_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - 1 + (noab+nvab) * (p12b_1 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_6_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_6_1',3,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p12b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p12b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_6_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_6_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_6_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( p12 p1 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER p12b
      INTEGER p1b
      length = 0
      DO p12b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+p1b-
     &1).ne.4)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_6_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO p12b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+p1b-1)) .eq. irrep_f) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+p1b-
     &1).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p1b - noab - 1 + nvab * (p12b - noab - 1
     &)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+p12b-1) * int_mb(k_range+p1b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_6_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( p12 p1 )_vt + = -1 * Sum ( h8 p7 ) * t ( p7 h8 )_t * v ( h8 p12 p1 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p12b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h8b
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER p12b_2
      INTEGER h8b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO p12b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+p1b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep
     &_v,irrep_t)) THEN
      dimc = int_mb(k_range+p12b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h8b,p7b_1,h8b_1)
      CALL TCE_RESTRICTED_4(p12b,h8b,p1b,p7b,p12b_2,h8b_2,p1b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h8b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p12b-1) * int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_6_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_6_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_6_2',5,MA_ERR)
      IF ((h8b .le. p12b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (p12b_2 - 1 + (noa
     &b+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+p12b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1
     &),4,2,1,3,-1.0d0)
      END IF
      IF ((h8b .le. p12b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p12b_2 - 1 + (noa
     &b+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+p12b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_6_2',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_6_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_6_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_6_2',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p12b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p12b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_6_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_6_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_6_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( p12 p1 )_vt + = 1/2 * Sum ( h9 h10 p8 ) * t ( p8 p12 h9 h10 )_t * v ( h9 h10 p1 p8 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p12b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h9b
      INTEGER h10b
      INTEGER p12b_1
      INTEGER p8b_1
      INTEGER h9b_1
      INTEGER h10b_1
      INTEGER h9b_2
      INTEGER h10b_2
      INTEGER p1b_2
      INTEGER p8b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO p12b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+p1b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep
     &_v,irrep_t)) THEN
      dimc = int_mb(k_range+p12b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      DO h9b = 1,noab
      DO h10b = h9b,noab
      IF (int_mb(k_spin+p12b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+
     &h9b-1)+int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb
     &(k_sym+h9b-1),int_mb(k_sym+h10b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p12b,p8b,h9b,h10b,p12b_1,p8b_1,h9b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h9b,h10b,p1b,p8b,h9b_2,h10b_2,p1b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1) * int_mb(k_range+h9b-1) * int_m
     &b(k_range+h10b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_6_3',2,MA_ERR)
      IF ((p8b .le. p12b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h9b_1 - 1 + noab * (p12b_1 - noab - 1 + nvab * (p8
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p12b-1),int_mb(k_range+h9b-1),int_mb(k_range+h10b-
     &1),2,4,3,1,1.0d0)
      END IF
      IF ((p12b .lt. p8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h9b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p12
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+p8b-1),int_mb(k_range+h9b-1),int_mb(k_range+h10b-
     &1),1,4,3,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_6_3',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_6_3',5,MA_ERR)
      IF ((p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p8b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h9b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p8b-1),int_mb(k_range+p1b-1
     &),4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h9b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p1b-1),int_mb(k_range+p8b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_6_3',6,MA_
     &ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h9b .eq. h10b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubh(1))/FACTORIAL(nsubh(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_6_3',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_6_3',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_6_3',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p12b-1),2,1,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p12b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_6_3',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_6_3',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_6_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( p12 p1 )_vtt + = -1 * Sum ( h8 ) * t ( p12 h8 )_t * i2 ( h8 p1 )_vt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER p12b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p12b_1
      INTEGER h8b_1
      INTEGER h8b_2
      INTEGER p1b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO p12b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+p12b-1)+int_mb(k_spin+p1b-
     &1).ne.4)) THEN
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep
     &_v,ieor(irrep_t,irrep_t))) THEN
      dimc = int_mb(k_range+p12b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      IF (int_mb(k_spin+p12b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p12b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p12b,h8b,p12b_1,h8b_1)
      CALL TCE_RESTRICTED_2(h8b,p1b,h8b_2,p1b_2)
      dim_common = int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+p12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_6_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p12b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p12b-1
     &),int_mb(k_range+h8b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_6_4',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_6_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (h8b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+p1b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_6_4',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_6_4',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_6_4',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_6_4',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p12b-1),2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p12b - noab - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_6_4',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_6_4',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_6_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k
     &_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h8 p1 )_vt + = 1 * Sum ( h10 p9 ) * t ( p9 h10 )_t * v ( h8 h10 p1 p9 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h8b
      INTEGER p1b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER h10b
      INTEGER p9b_1
      INTEGER h10b_1
      INTEGER h8b_2
      INTEGER h10b_2
      INTEGER p1b_2
      INTEGER p9b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h8b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      dimc = int_mb(k_range+h8b-1) * int_mb(k_range+p1b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p9b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p9b,h10b,p9b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h8b,h10b,p1b,p9b,h8b_2,h10b_2,p1b_2,p9b_2)
      dim_common = int_mb(k_range+p9b-1) * int_mb(k_range+h10b-1)
      dima_sort = 1
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h8b-1) * int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_6_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_6_4_1',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_6_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_6_4_1',5,MA_ERR)
      IF ((h10b .lt. h8b) .and. (p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+p9b-1),int_mb(k_range+p1b-1
     &),4,2,1,3,1.0d0)
      END IF
      IF ((h10b .lt. h8b) .and. (p1b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h8b-1),int_mb(k_range+p1b-1),int_mb(k_range+p9b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h8b .le. h10b) .and. (p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p9b-1),int_mb(k_range+p1b-1
     &),4,1,2,3,-1.0d0)
      END IF
      IF ((h8b .le. h10b) .and. (p1b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p1b-1),int_mb(k_range+p9b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_6_4_1',6,M
     &A_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_6_4_1
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_6_4_1
     &',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_6_4_1',9,MA_ERR)
      CALL TCE_SORT_2(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (h8b - 1)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_6_4_1',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_6_4_1
     &',11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_6_4_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h8 p1 )_vt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h8b
      INTEGER p1b
      length = 0
      DO h8b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_6_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h8b = 1,noab
      DO p1b = noab+1,noab+nvab
      IF (int_mb(k_spin+h8b-1) .eq. int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h8b-1),int_mb(k_sym+p1b-1)) .eq. ieor(irrep_
     &v,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1
     &).ne.4)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p1b - noab - 1 + nvab * (h8b - 1)
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h8b-1) * int_mb(k_range+p1b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_7(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = 1/2 * P( 3 ) * Sum ( h12 h11 ) * y ( h4 h11 h12 p1 p2 p3 )_y * i1 ( h5 h6 h11 h12 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h11b
      INTEGER h12b
      INTEGER h4b_1
      INTEGER h11b_1
      INTEGER h12b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER p3b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER h11b_2
      INTEGER h12b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsuperh(2)
      INTEGER isuperh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = p2b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-
     &1) .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3
     &b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h11b-1),ieor(int_mb
     &(k_sym+h12b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),i
     &nt_mb(k_sym+p3b-1)))))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_6(h4b,h11b,h12b,p1b,p2b,p3b,h4b_1,h11b_1,h12b_
     &1,p1b_1,p2b_1,p3b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,h11b,h12b,h5b_2,h6b_2,h11b_2,h12b_2)
      dim_common = int_mb(k_range+h11b-1) * int_mb(k_range+h12b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1) * int_mb
     &(k_range+p2b-1) * int_mb(k_range+p3b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_7',2,MA_ERR)
      IF ((h12b .lt. h4b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h4b_1 - 1 + noab * (h12b_1 - 1 + noab * (h11b_1 - 1)))))
     &))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+h12b-1),int_mb(k_range+h4b-1),int_mb(k_range+p1b-
     &1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,3,2,1,1.0d0)
      END IF
      IF ((h11b .lt. h4b) .and. (h4b .le. h12b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h12b_1 - 1 + noab * (h4b_1 - 1 + noab * (h11b_1 - 1)))))
     &))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h12b-1),int_mb(k_range+p1b-
     &1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,2,3,1,-1.0d0)
      END IF
      IF ((h4b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p3b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h12b_1 - 1 + noab * (h11b_1 - 1 + noab * (h4b_1 - 1)))))
     &))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h11b-1),int_mb(k_range+h12b-1),int_mb(k_range+p1b-
     &1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1),6,5,4,1,3,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_7',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_7',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h12b_
     &2 - 1 + noab * (h11b_2 - 1 + noab * (h6b_2 - 1 + noab * (h5b_2 - 1
     &)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_7',6,MA_ER
     &R)
      nsuperh(1) = 1
      nsuperh(2) = 1
      isuperh = 1
      IF (h11b .eq. h12b) THEN
      nsuperh(isuperh) = nsuperh(isuperh) + 1
      ELSE
      isuperh = isuperh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperh(1))/FACTORIAL(nsuperh(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_7',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_7',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_7',9,MA_ERR)
      IF ((h4b .le. h5b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,2,1,5,4,3,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),2,6,1,5,4,3,-1.0d0/2.
     &0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p3b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),2,1,6,5,4,3,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_7',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_7',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_7_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h11 h12 )_v + = 1 * v ( h4 h5 h11 h12 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h11b_1
      INTEGER h12b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      CALL TCE_RESTRICTED_4(h4b,h5b,h11b,h12b,h4b_1,h5b_1,h11b_1,h12b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h11b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_7_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + (noab+nvab) * (h11b_1 - 1 + (noab+nvab) * (h5b_1 - 1 + (no
     &ab+nvab) * (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_7_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_7_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h11b-1),int_mb(k_range+h5b-1),int_mb(k_range+h4b-
     &1),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_7_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_7_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_7_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h11 h12 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER h11b
      INTEGER h12b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_7_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (h11b - 1 + noab * (h5
     &b - 1 + noab * (h4b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+h11b-1) * int_mb(k_range+h12b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_7_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h11 h12 )_vt + = -2 * Sum ( p7 ) * t ( p7 h11 )_t * i2 ( h4 h5 h12 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER h12b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h11b = 1,noab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h11b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h4b,h5b,h12b,p7b,h4b_2,h5b_2,h12b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h12b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_7_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_7_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_7_2',5,MA_ERR)
      IF ((h12b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (h12b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b
     &_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h12b-1),int_mb(k_range+p7b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_7_2',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_7_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_7_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_7_2',9,MA_ERR)
      IF ((h11b .le. h12b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),int_mb(k_range+h11b-
     &1),3,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))
      END IF
      IF ((h12b .le. h11b)) THEN
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),int_mb(k_range+h11b-
     &1),3,2,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h12b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_7_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_7_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_7_2_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 h5 h12 p7 )_v + = 1 * v ( h4 h5 h12 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h12b
      INTEGER p7b
      INTEGER dimc
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h12b_1
      INTEGER p7b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h12b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p7b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h12b-1) * int_mb(k_range+p7b-1)
      CALL TCE_RESTRICTED_4(h4b,h5b,h12b,p7b,h4b_1,h5b_1,h12b_1,p7b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h12b-1) * int_mb(k_range+p7b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_2_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_7_2_1',1,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p7b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (h5b_1 - 1 + (noa
     &b+nvab) * (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h12b-1),int_mb(k_range+p7b-1
     &),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_7_2_1',2,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_7_2_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h5b-1),int_mb(k_range+h4b-1
     &),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h12b - 1 + noab * (h5b - 1 + noab * (h4b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_7_2_1',4,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_7_2_1
     &',5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_7_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 h5 h12 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER h12b
      INTEGER p7b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h12b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p7b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_7_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h12b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p7b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p7b - noab - 1 + nvab * (h12b - 1 + noab
     & * (h5b - 1 + noab * (h4b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+h12b-1) * int_mb(k_range+p7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_7_2_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k
     &_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 h5 h12 p7 )_vt + = -1/2 * Sum ( p9 ) * t ( p9 h12 )_t * v ( h4 h5 p7 p9 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h12b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER p9b_1
      INTEGER h12b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER p7b_2
      INTEGER p9b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h12b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p7b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p7b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p7b-1)))) .eq. ieor(irrep_v,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h12b-1) * int_mb(k_range+p7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_2_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p9b,h12b,p9b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h4b,h5b,p7b,p9b,h4b_2,h5b_2,p7b_2,p9b_2)
      dim_common = int_mb(k_range+p9b-1)
      dima_sort = int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p7b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_2_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_7_2_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_7_2_2',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_2_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_7_2_2',5,MA_ERR)
      IF ((p9b .lt. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p9b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p9b-1),int_mb(k_range+p7b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p7b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p9b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_7_2_2',6,M
     &A_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_7_2_2
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_7_2_2
     &',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_7_2_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),int_mb(k_range+h12b-1
     &),3,2,4,1,-1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h12b - 1 + noab * (h5b - 1 + noab * (h4b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_7_2_2',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_7_2_2
     &',11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_7_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h11 h12 )_vt + = 1/2 * Sum ( p7 p8 ) * t ( p7 p8 h11 h12 )_t * v ( h4 h5 p7 p8 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h11b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p8b
      INTEGER p7b_1
      INTEGER p8b_1
      INTEGER h11b_1
      INTEGER h12b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER p7b_2
      INTEGER p8b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h11b = 1,noab
      DO h12b = h11b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h11b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO p8b = p7b,noab+nvab
      IF (int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p7b,p8b,h11b,h12b,p7b_1,p8b_1,h11b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h4b,h5b,p7b,p8b,h4b_2,h5b_2,p7b_2,p8b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1)
      dima_sort = int_mb(k_range+h11b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_7_3',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h11b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p7
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h11b-1),int_mb(k_range+h12b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_7_3',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_7_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_7_3',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h5b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p8b-1)
     &,2,1,4,3,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_7_3',6,MA_
     &ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p7b .eq. p8b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_7_3',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_7_3',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_7_3',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h12b-1),int_mb(k_range+h11b-
     &1),2,1,4,3,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (h11b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_7_3',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_7_3',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_8(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = -1 * P( 9 ) * Sum ( h12 p9 ) * y ( h4 h5 h12 p1 p2 p9 )_y * i1 ( h6 p9 h12 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h12b
      INTEGER p9b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h12b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER p9b_1
      INTEGER h6b_2
      INTEGER p9b_2
      INTEGER p3b_2
      INTEGER h12b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h12b = 1,noab
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h12b-1
     &) .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p9b
     &-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h12b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),in
     &t_mb(k_sym+p9b-1)))))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_6(h4b,h5b,h12b,p1b,p2b,p9b,h4b_1,h5b_1,h12b_1,
     &p1b_1,p2b_1,p9b_1)
      CALL TCE_RESTRICTED_4(h6b,p9b,p3b,h12b,h6b_2,p9b_2,p3b_2,h12b_2)
      dim_common = int_mb(k_range+h12b-1) * int_mb(k_range+p9b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_8',2,MA_ERR)
      IF ((h12b .lt. h4b) .and. (p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (p9b_1 - noab - 1 
     &+ nvab * (h5b_1 - 1 + noab * (h4b_1 - 1 + noab * (h12b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p9b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,3,2,4,1,1.0d0)
      END IF
      IF ((h12b .lt. h4b) .and. (p1b .le. p9b) .and. (p9b .lt. p2b)) THE
     &N
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p9b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h5b_1 - 1 + noab * (h4b_1 - 1 + noab * (h12b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p9b-1),int_mb(k_range+p2b-1),6,4,3,2,5,1,-1.0d0)
      END IF
      IF ((h12b .lt. h4b) .and. (p2b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p9b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h5b_1 - 1 + noab * (h4b_1 - 1 + noab * (h12b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h12b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p9b-1),5,4,3,2,6,1,1.0d0)
      END IF
      IF ((h4b .le. h12b) .and. (h12b .lt. h5b) .and. (p9b .lt. p1b)) TH
     &EN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (p9b_1 - noab - 1 
     &+ nvab * (h5b_1 - 1 + noab * (h12b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h5b-1),int_mb(k_range+p9b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,3,1,4,2,-1.0d0)
      END IF
      IF ((h4b .le. h12b) .and. (h12b .lt. h5b) .and. (p1b .le. p9b) .an
     &d. (p9b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p9b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h5b_1 - 1 + noab * (h12b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p9b-1),int_mb(k_range+p2b-1),6,4,3,1,5,2,1.0d0)
      END IF
      IF ((h4b .le. h12b) .and. (h12b .lt. h5b) .and. (p2b .le. p9b)) TH
     &EN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p9b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h5b_1 - 1 + noab * (h12b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h12b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p9b-1),5,4,3,1,6,2,-1.0d0)
      END IF
      IF ((h5b .le. h12b) .and. (p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (p9b_1 - noab - 1 
     &+ nvab * (h12b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h12b-1),int_mb(k_range+p9b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,2,1,4,3,1.0d0)
      END IF
      IF ((h5b .le. h12b) .and. (p1b .le. p9b) .and. (p9b .lt. p2b)) THE
     &N
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p9b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h12b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h12b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p9b-1),int_mb(k_range+p2b-1),6,4,2,1,5,3,-1.0d0)
      END IF
      IF ((h5b .le. h12b) .and. (p2b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p9b_1
     & - noab - 1 + nvab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h12b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h12b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p9b-1),5,4,2,1,6,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_8',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_8',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h12b_
     &2 - 1 + noab * (p3b_2 - noab - 1 + nvab * (p9b_2 - noab - 1 + nvab
     & * (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p3b-1),int_mb(k_range+h12b-1
     &),3,1,2,4,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_8',6,MA_ER
     &R)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_8',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_8',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_8',9,MA_ERR)
      IF ((h5b .le. h6b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,4,3,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,1,4,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,4,1,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,4,3,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,1,4,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,4,1,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,4,3,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,1,4,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p1b .le. p3b) .and.
     & (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,4,1,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_8',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_8',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_8_1(d_a,k_a_offset,d_c,k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p9 h12 p1 )_v + = 1 * v ( h4 p9 h12 p1 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p9b
      INTEGER p1b
      INTEGER h12b
      INTEGER dimc
      INTEGER h4b_1
      INTEGER p9b_1
      INTEGER p1b_1
      INTEGER h12b_1
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h12b-1)))) .eq. irrep_v) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h12b-1)
      CALL TCE_RESTRICTED_4(h4b,p9b,p1b,h12b,h4b_1,p9b_1,p1b_1,h12b_1)
      dim_common = 1
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p9b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      IF (dima .gt. 0) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_1',0,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_8_1',1,MA_ERR)
      IF ((h4b .le. p9b) .and. (h12b .le. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - 1 + (noab+nvab) * (h12b_1 - 1 + (noab+nvab) * (p9b_1 - 1 + (noa
     &b+nvab) * (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h12b-1),int_mb(k_range+p1b-1
     &),3,4,2,1,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_8_1',2,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_8_1',3,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_a_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+p9b-1),int_mb(k_range+h4b-1
     &),4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (p9b - noab - 1 + nvab * (h4
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_8_1',4,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_8_1',
     &5,MA_ERR)
      END IF
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_8_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p9 h12 p1 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER p9b
      INTEGER p1b
      INTEGER h12b
      length = 0
      DO h4b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p1b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_8_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+p1b-1)))) .eq. irrep_v) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (p1b - noab - 1 + nvab
     & * (p9b - noab - 1 + nvab * (h4b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+p9b-1) * int_
     &mb(k_range+p1b-1) * int_mb(k_range+h12b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_8_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p9 h12 p1 )_vt + = -1 * Sum ( p7 ) * t ( p7 h12 )_t * v ( h4 p9 p1 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p9b
      INTEGER p1b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h12b_1
      INTEGER h4b_2
      INTEGER p9b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h12b,p7b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h4b,p9b,p1b,p7b,h4b_2,p9b_2,p1b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p9b-1) * int_mb
     &(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_8_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_8_2',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_8_2',5,MA_ERR)
      IF ((h4b .le. p9b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .le. p9b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_8_2',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_8_2',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_8_2',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_8_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h4b-1),int_mb(k_range+h12b-1
     &),3,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (p9b - noab - 1 + nvab * (h4
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_8_2',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_8_2',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_8_3(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p9 h12 p1 )_vt + = -1 * Sum ( h10 p8 ) * t ( p8 p9 h10 h12 )_t * v ( h4 h10 p1 p8 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p9b
      INTEGER p1b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h10b
      INTEGER p9b_1
      INTEGER p8b_1
      INTEGER h12b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER h10b_2
      INTEGER p1b_2
      INTEGER p8b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_3',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      DO h10b = 1,noab
      IF (int_mb(k_spin+p9b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &12b-1)+int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h12b-1),int_mb(k_sym+h10b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p9b,p8b,h12b,h10b,p9b_1,p8b_1,h12b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h4b,h10b,p1b,p8b,h4b_2,h10b_2,p1b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1) * int_mb(k_range+h10b-1)
      dima_sort = int_mb(k_range+p9b-1) * int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_3',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_8_3',2,MA_ERR)
      IF ((p8b .le. p9b) .and. (h10b .le. h12b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p8
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h10b-1),int_mb(k_range+h12b-
     &1),4,2,3,1,1.0d0)
      END IF
      IF ((p8b .le. p9b) .and. (h12b .lt. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h12b_1 - 1 + noab * (p9b_1 - noab - 1 + nvab * (p8
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+h12b-1),int_mb(k_range+h10b-
     &1),3,2,4,1,-1.0d0)
      END IF
      IF ((p9b .lt. p8b) .and. (h10b .le. h12b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p9
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h10b-1),int_mb(k_range+h12b-
     &1),4,1,3,2,-1.0d0)
      END IF
      IF ((p9b .lt. p8b) .and. (h12b .lt. h10b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h12b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p9
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h12b-1),int_mb(k_range+h10b-
     &1),3,1,4,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_8_3',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_3',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_8_3',5,MA_ERR)
      IF ((h10b .lt. h4b) .and. (p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p8b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+p8b-1),int_mb(k_range+p1b-1
     &),4,2,1,3,1.0d0)
      END IF
      IF ((h10b .lt. h4b) .and. (p1b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p8b-1
     &),3,2,1,4,-1.0d0)
      END IF
      IF ((h4b .le. h10b) .and. (p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p8b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p8b-1),int_mb(k_range+p1b-1
     &),4,1,2,3,-1.0d0)
      END IF
      IF ((h4b .le. h10b) .and. (p1b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p1b-1),int_mb(k_range+p8b-1
     &),3,1,2,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_8_3',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_8_3',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_8_3',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_8_3',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h12b-1),int_mb(k_range+p9b-1
     &),2,4,1,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (p9b - noab - 1 + nvab * (h4
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_8_3',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_8_3',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_8_4(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c
     &_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p9 h12 p1 )_vtt + = 1 * Sum ( h10 ) * t ( p9 h10 )_t * i2 ( h4 h10 h12 p1 )_vt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p9b
      INTEGER p1b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h10b
      INTEGER p9b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER h10b_2
      INTEGER p1b_2
      INTEGER h12b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p9b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p9b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,ieor(irrep_
     &t,irrep_t))) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p9b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_4',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h10b = 1,noab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p9b,h10b,p9b_1,h10b_1)
      CALL TCE_RESTRICTED_4(h4b,h10b,p1b,h12b,h4b_2,h10b_2,p1b_2,h12b_2)
      dim_common = int_mb(k_range+h10b-1)
      dima_sort = int_mb(k_range+p9b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1) * int_mb
     &(k_range+h12b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_4',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_8_4',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h10b-1),1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_8_4',3,MA_
     &ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_4',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_8_4',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(h12b_
     &2 - 1 + noab * (p1b_2 - noab - 1 + nvab * (h10b_2 - 1 + noab * (h4
     &b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p1b-1),int_mb(k_range+h12b-
     &1),4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_8_4',6,MA_
     &ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_8_4',
     &7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_8_4',
     &8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_8_4',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h12b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),int_mb(k_range+p9b-1
     &),3,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (p9b - noab - 1 + nvab * (h4
     &b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_8_4',10,MA
     &_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_8_4',
     &11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_8_4_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k
     &_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 h10 h12 p1 )_vt + = 1 * Sum ( p7 ) * t ( p7 h12 )_t * v ( h4 h10 p1 p7 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h10b
      INTEGER p1b
      INTEGER h12b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h12b_1
      INTEGER h4b_2
      INTEGER h10b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h10b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h12b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &p1b-1)+int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+p1b-1),int_mb(k_sym+h12b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h10b-1) * int_mb(k_r
     &ange+p1b-1) * int_mb(k_range+h12b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_4_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h12b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h12b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h12b,p7b_1,h12b_1)
      CALL TCE_RESTRICTED_4(h4b,h10b,p1b,p7b,h4b_2,h10b_2,p1b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h12b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h10b-1) * int_m
     &b(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_4_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_8_4_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h12b_
     &1 - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h12b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_8_4_1',3,M
     &A_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_8_4_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_8_4_1',5,MA_ERR)
      IF ((h10b .lt. h4b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1
     &),4,1,2,3,1.0d0)
      END IF
      IF ((h10b .lt. h4b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h4b_2 - 1 + (noab
     &+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1
     &),3,1,2,4,-1.0d0)
      END IF
      IF ((h4b .le. h10b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - 1 + (noab+nvab) * (p7b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1
     &),4,2,1,3,-1.0d0)
      END IF
      IF ((h4b .le. h10b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - 1 + (noab+nvab) * (p1b_2 - 1 + (noab+nvab) * (h10b_2 - 1 + (noa
     &b+nvab) * (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1
     &),3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_8_4_1',6,M
     &A_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_8_4_1
     &',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_8_4_1
     &',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_8_4_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h4b-1),int_mb(k_range+h12b-
     &1),3,2,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h12b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (h10b - 1 + noab * (h4b - 1)
     &))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_8_4_1',10,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_8_4_1
     &',11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_8_4_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 h10 h12 p1 )_vt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h10b
      INTEGER p1b
      INTEGER h12b
      length = 0
      DO h4b = 1,noab
      DO h10b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h12b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h12b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_8_4_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h10b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO h12b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-1) .eq. int_mb(k_spin+
     &h12b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb
     &(k_sym+h12b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_v,irrep_t)) 
     &THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h10b-
     &1)+int_mb(k_spin+h12b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h12b - 1 + noab * (p1b - noab - 1 + nvab
     & * (h10b - 1 + noab * (h4b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h10b-1) * int
     &_mb(k_range+p1b-1) * int_mb(k_range+h12b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_9(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_o
     &ffset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_yv + = 1/2 * P( 3 ) * Sum ( p8 p7 ) * y ( h4 h5 h6 p1 p7 p8 )_y * v ( p7 p8 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p8b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER p1b_1
      INTEGER p7b_1
      INTEGER p8b_1
      INTEGER p7b_2
      INTEGER p8b_2
      INTEGER p2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsubp(2)
      INTEGER isubp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = noab+1,noab+nvab
      DO p3b = p2b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,irrep_v)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_9',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO p8b = p7b,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p7b-1),int
     &_mb(k_sym+p8b-1)))))) .eq. irrep_y) THEN
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,p7b,p8b,h4b_1,h5b_1,h6b_1,p1
     &b_1,p7b_1,p8b_1)
      CALL TCE_RESTRICTED_4(p7b,p8b,p2b,p3b,p7b_2,p8b_2,p2b_2,p3b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p2b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_9',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_9',2,MA_ERR)
      IF ((p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p1b_1
     & - noab - 1 + nvab * (p8b_1 - noab - 1 + nvab * (p7b_1 - noab - 1 
     &+ nvab * (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),6,3,2,1,5,4,1.0d0)
      END IF
      IF ((p7b .lt. p1b) .and. (p1b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p8b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (p7b_1 - noab - 1 
     &+ nvab * (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p8b-1),5,3,2,1,6,4,-1.0d0)
      END IF
      IF ((p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p8b_1
     & - noab - 1 + nvab * (p7b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 
     &+ nvab * (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p8b-1),4,3,2,1,6,5,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_9',3,MA_ER
     &R)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_9',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_9',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (p8b_2 - 1 + (noab
     &+nvab) * (p7b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_9',6,MA_ER
     &R)
      nsubp(1) = 1
      nsubp(2) = 1
      isubp = 1
      IF (p7b .eq. p8b) THEN
      nsubp(isubp) = nsubp(isubp) + 1
      ELSE
      isubp = isubp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubp(1))/FACTORIAL(nsubp(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_9',7,
     &MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_9',8,
     &MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_9',9,MA_ERR)
      IF ((p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,3,2,1,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,2,3,1,-1.0d0/2.
     &0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,2,1,3,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_9',10,MA_E
     &RR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_9',11
     &,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_10(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = -1 * P( 9 ) * Sum ( h11 ) * i1 ( h4 h5 h11 p1 )_yt * v ( h6 h11 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h11b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER p1b_1
      INTEGER h11b_1
      INTEGER h6b_2
      INTEGER h11b_2
      INTEGER p2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = noab+1,noab+nvab
      DO p3b = p2b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,ieor(irrep_t,irrep_v))) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h11b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,h11b,h4b_1,h5b_1,p1b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h6b,h11b,p2b,p3b,h6b_2,h11b_2,p2b_2,p3b_2)
      dim_common = int_mb(k_range+h11b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p2b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_10',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p1b_1 - noab - 1 + nvab * (h5b_1 - 1 + noab * (h4b
     &_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+h11b-1
     &),3,2,1,4,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_10',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_10',5,MA_ERR)
      IF ((h11b .lt. h6b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h11b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h11b-1
     &),int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1
     &),4,3,2,1,-1.0d0)
      END IF
      IF ((h6b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (h11b_2 - 1 + (noa
     &b+nvab) * (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h11b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1
     &),4,3,1,2,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_10',6,MA_E
     &RR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_10',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_10',8
     &,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_10',9,MA_ERR)
      IF ((h5b .le. h6b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,3,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,2,4,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),3,6,5,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,4,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p2b .le. p1b) .and.
     & (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,2,4,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,3,5,2,1,4,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_10',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_10',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_10_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h11 p1 )_yt + = -1 * Sum ( p7 ) * t ( p7 h11 )_t * y ( h4 h5 p1 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER p1b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h11b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h4b,h5b,p1b,p7b,h4b_2,h5b_2,p1b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_10_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_10_1',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_10_1',5,MA_ERR)
      IF ((p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (h5b_2 - 1 + noab 
     &* (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p7b-1),int_mb(k_range+p1b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (h5b_2 - 1 + noab 
     &* (h4b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+p1b-1),int_mb(k_range+p7b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_10_1',6,MA
     &_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_10_1'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_10_1'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_10_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),int_mb(k_range+h11b-1
     &),3,2,1,4,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (h5b - 1 + noab * (h4b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_10_1',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_10_1'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_10_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h11 p1 )_yt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER p1b
      INTEGER h11b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_10_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+p1b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+p1b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h11b - 1 + noab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+p1b-1) * int_mb(k_range+h11b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_10_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h11 p1 )_yt + = 1/2 * Sum ( h9 p8 p7 ) * t ( p7 p8 h9 h11 )_t * y ( h4 h5 h9 p1 p7 p8 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER p1b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p8b
      INTEGER h9b
      INTEGER p7b_1
      INTEGER p8b_1
      INTEGER h11b_1
      INTEGER h9b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER h9b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER p8b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h11b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+h11b-1)))) .eq. ieor(irrep_y,irrep_t)) T
     &HEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO p8b = p7b,noab+nvab
      DO h9b = 1,noab
      IF (int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &11b-1)+int_mb(k_spin+h9b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h11b-1),int_mb(k_sym+h9b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p7b,p8b,h11b,h9b,p7b_1,p8b_1,h11b_1,h9b_1)
      CALL TCE_RESTRICTED_6(h4b,h5b,h9b,p1b,p7b,p8b,h4b_2,h5b_2,h9b_2,p1
     &b_2,p7b_2,p8b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1) * int_m
     &b(k_range+h9b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_10_2',2,MA_ERR)
      IF ((h9b .le. h11b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h9b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p7b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h9b-1),int_mb(k_range+h11b-1
     &),4,3,2,1,1.0d0)
      END IF
      IF ((h11b .lt. h9b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h9b_1
     & - 1 + noab * (h11b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p7b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h11b-1),int_mb(k_range+h9b-1
     &),3,4,2,1,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_10_2',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_10_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_10_2',5,MA_ERR)
      IF ((h9b .lt. h4b) .and. (p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p8b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),6,3,2,1,5,4,1.0d0)
      END IF
      IF ((h9b .lt. h4b) .and. (p7b .lt. p1b) .and. (p1b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p8b-1),5,3,2,1,6,4,-1.0d0)
      END IF
      IF ((h9b .lt. h4b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p8b-1),4,3,2,1,6,5,1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (h9b .lt. h5b) .and. (p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p8b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h5b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),6,3,1,2,5,4,-1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (h9b .lt. h5b) .and. (p7b .lt. p1b) .and.
     & (p1b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h5b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p8b-1),5,3,1,2,6,4,1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (h9b .lt. h5b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p8b-1),4,3,1,2,6,5,-1.0d0)
      END IF
      IF ((h5b .le. h9b) .and. (p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p8b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h9b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h9b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),6,2,1,3,5,4,1.0d0)
      END IF
      IF ((h5b .le. h9b) .and. (p7b .lt. p1b) .and. (p1b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h9b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h9b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p8b-1),5,2,1,3,6,4,-1.0d0)
      END IF
      IF ((h5b .le. h9b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h9b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h9b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p8b-1),4,2,1,3,6,5,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_10_2',6,MA
     &_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p7b .eq. p8b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_10_2'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_10_2'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_10_2',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),int_mb(k_range+h11b-1
     &),3,2,1,4,1.0d0/2.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (p1b - noab - 1 + nvab * (h5b - 1 + noab * (h4b - 1))
     &)))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_10_2',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_10_2'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_11(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytf + = -1 * P( 3 ) * Sum ( h7 ) * i1 ( h4 h5 h6 h7 p1 p2 )_yt * f ( h7 p3 )_f
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h7b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER h7b_1
      INTEGER h7b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,ieor(irrep_t,irrep_f))) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_11',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h7b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+h7b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+h7b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,p2b,h7b,h4b_1,h5b_1,h6b_1,p1
     &b_1,p2b_1,h7b_1)
      CALL TCE_RESTRICTED_2(h7b,p3b,h7b_2,p3b_2)
      dim_common = int_mb(k_range+h7b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_11',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_11',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab 
     &* (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h7b-1),5,4,3,2,1,6,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_11',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_11',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_11',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (h7b_2 - 1)))
      CALL TCE_SORT_2(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h7b-1)
     &,int_mb(k_range+p3b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_11',6,MA_E
     &RR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_11',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_11',8
     &,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_11',9,MA_ERR)
      IF ((p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,3,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,1,3,2,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,3,1,2,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_11',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_11',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_11_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h6 h7 p1 p2 )_yt + = 1 * Sum ( p8 ) * t ( p8 h7 )_t * y ( h4 h5 h6 p1 p2 p8 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER h7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER p8b_1
      INTEGER h7b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p1b_2
      INTEGER p2b_2
      INTEGER p8b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO h7b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+h7b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+h7b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+h7b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+h7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_11_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h7b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),int_mb(k_sym+h7b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p8b,h7b,p8b_1,h7b_1)
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,p2b,p8b,h4b_2,h5b_2,h6b_2,p1
     &b_2,p2b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1)
      dima_sort = int_mb(k_range+h7b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_11_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_11_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h7b_1
     & - 1 + noab * (p8b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+h7b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_11_1',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_11_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_11_1',5,MA_ERR)
      IF ((p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p8b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,3,2,1,4,1.0d0)
      END IF
      IF ((p1b .le. p8b) .and. (p8b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p8b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p2b-1),6,4,3,2,1,5,-1.0d0)
      END IF
      IF ((p2b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p2b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p8b-1),5,4,3,2,1,6,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_11_1',6,MA
     &_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_11_1'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_11_1'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_11_1',9,MA_ERR)
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h7b-1),5,4,3,2,1,6,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h7b -
     & 1 + noab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab * (h6b
     & - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_11_1',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_11_1'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_11_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h6 h7 p1 p2 )_yt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER h7b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+h7b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+p1b-1),int
     &_mb(k_sym+p2b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p2b-1).ne.12)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_11_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO h7b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+h7b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+h7b-1),ieor(int_mb(k_sym+p1b-1),int
     &_mb(k_sym+p2b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h7b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p2b-1).ne.12)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h7b - 1 + noab * (p2b - noab - 1 + nvab 
     &* (p1b - noab - 1 + nvab * (h6b - 1 + noab * (h5b - 1 + noab * (h4
     &b - 1)))))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) 
     &* int_mb(k_range+h7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_12(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = 1 * P( 9 ) * Sum ( h9 h8 ) * i1 ( h4 h5 h9 h8 p1 p2 )_yt * v ( h6 h8 h9 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h9b
      INTEGER h8b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h9b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER h8b_1
      INTEGER h6b_2
      INTEGER h8b_2
      INTEGER p3b_2
      INTEGER h9b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,ieor(irrep_t,irrep_v))) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_12',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h9b = 1,noab
      DO h8b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h9b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+h8b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h9b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+h8b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      CALL TCE_RESTRICTED_6(h4b,h5b,h9b,p1b,p2b,h8b,h4b_1,h5b_1,h9b_1,p1
     &b_1,p2b_1,h8b_1)
      CALL TCE_RESTRICTED_4(h6b,h8b,p3b,h9b,h6b_2,h8b_2,p3b_2,h9b_2)
      dim_common = int_mb(k_range+h9b-1) * int_mb(k_range+h8b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h6b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_12',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_12',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p2b_1 - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab 
     &* (h9b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h9b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+h8b-1),5,4,2,1,6,3,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_12',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_12',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_12',5,MA_ERR)
      IF ((h8b .lt. h6b) .and. (h9b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (h9b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h9b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((h6b .le. h8b) .and. (h9b .le. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (h9b_2 - 1 + (noab+nvab) * (h8b_2 - 1 + (noab
     &+nvab) * (h6b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+h9b-1),int_mb(k_range+p3b-1)
     &,4,1,2,3,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_12',6,MA_E
     &RR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_12',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_12',8
     &,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_12',9,MA_ERR)
      IF ((h5b .le. h6b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,4,3,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,1,4,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h6b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,2,4,1,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,4,3,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,1,4,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),2,6,5,4,1,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h4b - 1 + noab * (h6b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,4,3,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,1,4,3,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h6b) .and. (h6b .le. h5b) .and. (p1b .le. p3b) .and.
     & (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p2b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,2,5,4,1,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h5b - 1 + noab * (h6b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_12',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_12',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_12_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h9 h8 p1 p2 )_yt + = 1 * Sum ( p7 ) * t ( p7 h8 )_t * y ( h4 h5 h9 p1 p2 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h9b
      INTEGER p1b
      INTEGER p2b
      INTEGER h8b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER h9b_2
      INTEGER p1b_2
      INTEGER p2b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h9b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO h8b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+h8b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h9b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+h8b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h9b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+h8b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h9b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+h8b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_12_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h8b,p7b_1,h8b_1)
      CALL TCE_RESTRICTED_6(h4b,h5b,h9b,p1b,p2b,p7b,h4b_2,h5b_2,h9b_2,p1
     &b_2,p2b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h9b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_12_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_12_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_12_1',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_12_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_12_1',5,MA_ERR)
      IF ((h9b .lt. h4b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,1,3,2,4,1.0d0)
      END IF
      IF ((h9b .lt. h4b) .and. (p1b .le. p7b) .and. (p7b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p2b-1),6,4,1,3,2,5,-1.0d0)
      END IF
      IF ((h9b .lt. h4b) .and. (p2b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p2b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p7b-1),5,4,1,3,2,6,1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (h9b .lt. h5b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h5b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,2,3,1,4,-1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (h9b .lt. h5b) .and. (p1b .le. p7b) .and.
     & (p7b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p2b-1),6,4,2,3,1,5,1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (h9b .lt. h5b) .and. (p2b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p2b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h5b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h5b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p7b-1),5,4,2,3,1,6,-1.0d0)
      END IF
      IF ((h5b .le. h9b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h9b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h9b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,3,2,1,4,1.0d0)
      END IF
      IF ((h5b .le. h9b) .and. (p1b .le. p7b) .and. (p7b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h9b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h9b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p2b-1),6,4,3,2,1,5,-1.0d0)
      END IF
      IF ((h5b .le. h9b) .and. (p2b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p2b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h9b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h9b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p7b-1),5,4,3,2,1,6,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_12_1',6,MA
     &_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_12_1'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_12_1'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_12_1',9,MA_ERR)
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h9b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h8b-1),5,4,3,2,1,6,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h8b -
     & 1 + noab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab * (h9b
     & - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_12_1',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_12_1'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_12_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h9 h8 p1 p2 )_yt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER h9b
      INTEGER p1b
      INTEGER p2b
      INTEGER h8b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h9b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h9b-1)
     & .eq. int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h9b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p1b-1),int
     &_mb(k_sym+p2b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p2b-1).ne.12)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_12_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h9b = 1,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO h8b = 1,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h9b-1)
     & .eq. int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h9b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p1b-1),int
     &_mb(k_sym+p2b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h9b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p2b-1).ne.12)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h8b - 1 + noab * (p2b - noab - 1 + nvab 
     &* (p1b - noab - 1 + nvab * (h9b - 1 + noab * (h5b - 1 + noab * (h4
     &b - 1)))))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+h9b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) 
     &* int_mb(k_range+h8b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_13(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = 1 * P( 3 ) * Sum ( h8 p9 ) * i1 ( h4 h5 h6 h8 p1 p9 )_yt * v ( h8 p9 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h8b
      INTEGER p9b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER p1b_1
      INTEGER h8b_1
      INTEGER p9b_1
      INTEGER h8b_2
      INTEGER p9b_2
      INTEGER p2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = noab+1,noab+nvab
      DO p3b = p2b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,ieor(irrep_t,irrep_v))) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_13',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h8b = 1,noab
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p9b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+h8b-1),int
     &_mb(k_sym+p9b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,h8b,p9b,h4b_1,h5b_1,h6b_1,p1
     &b_1,h8b_1,p9b_1)
      CALL TCE_RESTRICTED_4(h8b,p9b,p2b,p3b,h8b_2,p9b_2,p2b_2,p3b_2)
      dim_common = int_mb(k_range+h8b-1) * int_mb(k_range+p9b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p2b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_13',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_13',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p9b_1
     & - noab - 1 + nvab * (h8b_1 - 1 + noab * (p1b_1 - noab - 1 + nvab 
     &* (h6b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h8b-1),int_mb(k_range+p9b-1),4,3,2,1,6,5,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_13',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_13',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_13',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (p9b_2 - 1 + (noab
     &+nvab) * (h8b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h8b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-1)
     &,4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_13',6,MA_E
     &RR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_13',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_13',8
     &,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_13',9,MA_ERR)
      IF ((p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,3,2,1,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,2,3,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,2,1,3,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_13',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_13',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_13_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h6 h8 p1 p9 )_yt + = -1 * Sum ( p7 ) * t ( p7 h8 )_t * y ( h4 h5 h6 p1 p7 p9 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h8b
      INTEGER p9b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h8b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p1b_2
      INTEGER p9b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h8b = 1,noab
      DO p9b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h8b-1)+i
     &nt_mb(k_spin+p9b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p9b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+h8b-1),int
     &_mb(k_sym+p9b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+h8b-1) * int_m
     &b(k_range+p9b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_13_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h8b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h8b-1)) .eq. irrep_t) TH
     &EN
      CALL TCE_RESTRICTED_2(p7b,h8b,p7b_1,h8b_1)
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,p9b,p7b,h4b_2,h5b_2,h6b_2,p1
     &b_2,p9b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p9b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_13_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_13_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h8b_1
     & - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h8b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_13_1',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_13_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_13_1',5,MA_ERR)
      IF ((p7b .le. p9b) .and. (p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p9b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p1b-1),5,6,3,2,1,4,1.0d0)
      END IF
      IF ((p9b .lt. p7b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p9b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p1b-1),4,6,3,2,1,5,-1.0d0)
      END IF
      IF ((p9b .lt. p1b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p9b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p7b-1),4,5,3,2,1,6,1.0d0)
      END IF
      IF ((p7b .lt. p1b) .and. (p1b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p9b-1),6,5,3,2,1,4,-1.0d0)
      END IF
      IF ((p1b .le. p7b) .and. (p7b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p9b-1),6,4,3,2,1,5,1.0d0)
      END IF
      IF ((p1b .le. p9b) .and. (p9b .lt. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p9b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p7b-1),5,4,3,2,1,6,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_13_1',6,MA
     &_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_13_1'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_13_1'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_13_1',9,MA_ERR)
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h8b-1),5,4,3,2,6,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p9b -
     & noab - 1 + nvab * (h8b - 1 + noab * (p1b - noab - 1 + nvab * (h6b
     & - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_13_1',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_13_1'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_13_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h6 h8 p1 p9 )_yt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h8b
      INTEGER p9b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h8b = 1,noab
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p9b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p1b-1),int
     &_mb(k_sym+p9b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p9b-1).ne.12)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_13_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h8b = 1,noab
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p9b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+h8b-1),ieor(int_mb(k_sym+p1b-1),int
     &_mb(k_sym+p9b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h8b-1)+int_mb(k_spin+p1b-1)+i
     &nt_mb(k_spin+p9b-1).ne.12)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p9b - noab - 1 + nvab * (h8b - 1 + noab 
     &* (p1b - noab - 1 + nvab * (h6b - 1 + noab * (h5b - 1 + noab * (h4
     &b - 1)))))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+h8b-1) 
     &* int_mb(k_range+p9b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_14(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = 1/2 * P( 9 ) * Sum ( p8 ) * i1 ( h4 p8 p1 p2 )_yt * v ( h5 h6 p3 p8 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p8b
      INTEGER h4b_1
      INTEGER p8b_1
      INTEGER p1b_1
      INTEGER p2b_1
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p3b_2
      INTEGER p8b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = 1,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      DO p3b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,ieor(irrep_t,irrep_v))) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_14',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p8b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      CALL TCE_RESTRICTED_4(h4b,p8b,p1b,p2b,h4b_1,p8b_1,p1b_1,p2b_1)
      CALL TCE_RESTRICTED_4(h5b,h6b,p3b,p8b,h5b_2,h6b_2,p3b_2,p8b_2)
      dim_common = int_mb(k_range+p8b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1) * int_mb
     &(k_range+p2b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h5b-1) * int_mb(k_range+h6b-1) * int_mb
     &(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_14',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_14',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(p2b_1
     & - noab - 1 + nvab * (p1b_1 - noab - 1 + nvab * (p8b_1 - noab - 1 
     &+ nvab * (h4b_1 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1)
     &,4,3,1,2,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_14',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_14',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_14',5,MA_ERR)
      IF ((p8b .lt. p3b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p8b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p8b-1),int_mb(k_range+p3b-1)
     &,4,2,1,3,-1.0d0)
      END IF
      IF ((p3b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - 1 + (noab+nvab) * (p3b_2 - 1 + (noab+nvab) * (h6b_2 - 1 + (noab
     &+nvab) * (h5b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+p3b-1),int_mb(k_range+p8b-1)
     &,3,2,1,4,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_14',6,MA_E
     &RR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_14',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_14',8
     &,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_14',9,MA_ERR)
      IF ((h4b .le. h5b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,5,4,1,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h5b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,1,5,4,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h4b .le. h5b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),6,3,2,5,1,4,-1.0d0/2.
     &0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,5,4,1,-1.0d0/2.
     &0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,1,5,4,-1.0d0/2.
     &0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h5b .le. h4b) .and. (h4b .le. h6b) .and. (p1b .le. p3b) .and.
     & (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,6,2,5,1,4,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h4b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p2b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,5,4,1,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,1,5,4,1.0d0/2.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p3b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF ((h6b .le. h4b) .and. (p1b .le. p3b) .and. (p3b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),3,2,6,5,1,4,-1.0d0/2.
     &0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h4b - 1 + noab * (h6b - 1 + noab * (h5b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_14',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_14',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_14_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p8 p1 p2 )_yt + = -1 * Sum ( h10 h9 p7 ) * t ( p7 p8 h9 h10 )_t * y ( h4 h9 h10 p1 p2 p7 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER p8b
      INTEGER p1b
      INTEGER p2b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER h9b
      INTEGER h10b
      INTEGER p8b_1
      INTEGER p7b_1
      INTEGER h9b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER h9b_2
      INTEGER h10b_2
      INTEGER p1b_2
      INTEGER p2b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO p8b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1).ne.8)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+p8b-1) * int_mb(k_ra
     &nge+p1b-1) * int_mb(k_range+p2b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_14_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO h9b = 1,noab
      DO h10b = h9b,noab
      IF (int_mb(k_spin+p8b-1)+int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h
     &9b-1)+int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p8b-1),ieor(int_mb(k_sym+p7b-1),ieor(int_mb(
     &k_sym+h9b-1),int_mb(k_sym+h10b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p8b,p7b,h9b,h10b,p8b_1,p7b_1,h9b_1,h10b_1)
      CALL TCE_RESTRICTED_6(h4b,h9b,h10b,p1b,p2b,p7b,h4b_2,h9b_2,h10b_2,
     &p1b_2,p2b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+h9b-1) * int_m
     &b(k_range+h10b-1)
      dima_sort = int_mb(k_range+p8b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+p1b-1) * int_mb
     &(k_range+p2b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_14_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_14_1',2,MA_ERR)
      IF ((p7b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h9b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p7b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h9b-1),int_mb(k_range+h10b-1
     &),2,4,3,1,1.0d0)
      END IF
      IF ((p8b .lt. p7b)) THEN
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (h9b_1 - 1 + noab * (p7b_1 - noab - 1 + nvab * (p8b
     &_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p8b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+h9b-1),int_mb(k_range+h10b-1
     &),1,4,3,2,-1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_14_1',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_14_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_14_1',5,MA_ERR)
      IF ((h10b .lt. h4b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h4b_2 - 1 + noab * (h10b_2 - 1 + noab * (h9b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h4b-1),int_mb(k_range+p7b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,3,2,1,4,1.0d0)
      END IF
      IF ((h10b .lt. h4b) .and. (p1b .le. p7b) .and. (p7b .lt. p2b)) THE
     &N
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h4b_2 - 1 + noab * (h10b_2 - 1 + noab * (h9b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h4b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p7b-1),int_mb(k_range+p2b-1),6,4,3,2,1,5,-1.0d0)
      END IF
      IF ((h10b .lt. h4b) .and. (p2b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p2b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h4b_2 - 1 + noab * (h10b_2 - 1 + noab * (h9b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h4b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p7b-1),5,4,3,2,1,6,1.0d0)
      END IF
      IF ((h9b .lt. h4b) .and. (h4b .le. h10b) .and. (p7b .lt. p1b)) THE
     &N
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h10b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h10b-1),int_mb(k_range+p7b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,2,3,1,4,-1.0d0)
      END IF
      IF ((h9b .lt. h4b) .and. (h4b .le. h10b) .and. (p1b .le. p7b) .and
     &. (p7b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h10b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h10b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p7b-1),int_mb(k_range+p2b-1),6,4,2,3,1,5,1.0d0)
      END IF
      IF ((h9b .lt. h4b) .and. (h4b .le. h10b) .and. (p2b .le. p7b)) THE
     &N
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p2b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h10b_2 - 1 + noab * (h4b_2 - 1 + noab * (h9b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h9b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h10b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p7b-1),5,4,2,3,1,6,-1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h10b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h10b-1),int_mb(k_range+p7b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+p2b-1),6,5,1,3,2,4,1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (p1b .le. p7b) .and. (p7b .lt. p2b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p2b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h10b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h10b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p7b-1),int_mb(k_range+p2b-1),6,4,1,3,2,5,-1.0d0)
      END IF
      IF ((h4b .le. h9b) .and. (p2b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p2b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h10b_2 - 1 + noab * (h9b_2 - 1 + noab * (h4b_2 - 1))))))
     &)
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h9b-1),int_mb(k_range+h10b-1),int_mb(k_range+p1b-1
     &),int_mb(k_range+p2b-1),int_mb(k_range+p7b-1),5,4,1,3,2,6,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_14_1',6,MA
     &_ERR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h9b .eq. h10b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubh(1))/FACTORIAL(nsubh(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_14_1'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_14_1'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_14_1',9,MA_ERR)
      CALL TCE_SORT_4(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p2b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h4b-1),int_mb(k_range+p8b-1)
     &,3,4,2,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p2b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p8b - noab - 1 + nvab
     & * (h4b - 1)))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_14_1',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_14_1'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_14_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 p8 p1 p2 )_yt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER p8b
      INTEGER p1b
      INTEGER p2b
      length = 0
      DO h4b = 1,noab
      DO p8b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1).ne.8)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_14_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO p8b = noab+1,noab+nvab
      DO p1b = noab+1,noab+nvab
      DO p2b = p1b,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+p
     &1b-1)+int_mb(k_spin+p2b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+p1b-1),int_mb(k_sym+p2b-1)))) .eq. ieor(irrep_y,irrep_t)) TH
     &EN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+p8b-1
     &)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1).ne.8)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p2b - noab - 1 + nvab * (p1b - noab - 1 
     &+ nvab * (p8b - noab - 1 + nvab * (h4b - 1)))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+p8b-1) * int_
     &mb(k_range+p1b-1) * int_mb(k_range+p2b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_15(d_a,k_a_offset,d_b,k_b_offset,d_c,k_c_
     &offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i0 ( h4 h5 h6 p1 p2 p3 )_ytv + = 1/4 * P( 3 ) * Sum ( h11 h10 ) * i1 ( h4 h5 h6 h10 h11 p1 )_yt * v ( h10 h11 p2 p3 )_v
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER p2b
      INTEGER p3b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER h10b
      INTEGER h11b
      INTEGER h4b_1
      INTEGER h5b_1
      INTEGER h6b_1
      INTEGER p1b_1
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER h10b_2
      INTEGER h11b_2
      INTEGER p2b_2
      INTEGER p3b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsubh(2)
      INTEGER isubh
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO p2b = noab+1,noab+nvab
      DO p3b = p2b,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+i
     &nt_mb(k_spin+p3b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+p2b-1)+int_mb(k_spin+p3b-
     &1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+p2b-1),int
     &_mb(k_sym+p3b-1)))))) .eq. ieor(irrep_y,ieor(irrep_t,irrep_v))) TH
     &EN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p2b-1) * int_m
     &b(k_range+p3b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11
     &b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+h10b-1),in
     &t_mb(k_sym+h11b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,h10b,h11b,h4b_1,h5b_1,h6b_1,
     &p1b_1,h10b_1,h11b_1)
      CALL TCE_RESTRICTED_4(h10b,h11b,p2b,p3b,h10b_2,h11b_2,p2b_2,p3b_2)
      dim_common = int_mb(k_range+h10b-1) * int_mb(k_range+h11b-1)
      dima_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+p2b-1) * int_mb(k_range+p3b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_15',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p1b_1 - noab - 1 + nvab * (h6
     &b_1 - 1 + noab * (h5b_1 - 1 + noab * (h4b_1 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+h11b-1),4,3,2,1,6,5,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_15',3,MA_E
     &RR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_15',5,MA_ERR)
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p3b_2
     & - 1 + (noab+nvab) * (p2b_2 - 1 + (noab+nvab) * (h11b_2 - 1 + (noa
     &b+nvab) * (h10b_2 - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h10b-1
     &),int_mb(k_range+h11b-1),int_mb(k_range+p2b-1),int_mb(k_range+p3b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_15',6,MA_E
     &RR)
      nsubh(1) = 1
      nsubh(2) = 1
      isubh = 1
      IF (h10b .eq. h11b) THEN
      nsubh(isubh) = nsubh(isubh) + 1
      ELSE
      isubh = isubh + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsubh(1))/FACTORIAL(nsubh(2)),dbl_mb(k_a_sort),dim_common,dbl_mb(k
     &_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_15',7
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_15',8
     &,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_15',9,MA_ERR)
      IF ((p1b .le. p2b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,3,2,1,1.0d0/4.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p2b - noab - 1 + nvab * (p1b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p2b .le. p1b) .and. (p1b .le. p3b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,2,3,1,-1.0d0/4.
     &0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p3b -
     & noab - 1 + nvab * (p1b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((p3b .le. p1b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p3b-1)
     &,int_mb(k_range+p2b-1),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h4b-1),6,5,4,2,1,3,1.0d0/4.0
     &d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p1b -
     & noab - 1 + nvab * (p3b - noab - 1 + nvab * (p2b - noab - 1 + nvab
     & * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_15',10,MA_
     &ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_15',1
     &1,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_15_1(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h6 h10 h11 p1 )_yt + = 1 * Sum ( p8 p7 ) * t ( p7 p8 h10 h11 )_t * y ( h4 h5 h6 p1 p7 p8 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h10b
      INTEGER h11b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p8b
      INTEGER p7b_1
      INTEGER p8b_1
      INTEGER h10b_1
      INTEGER h11b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER p8b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER nsuperp(2)
      INTEGER isuperp
      INTEGER l_c
      INTEGER k_c
      DOUBLE PRECISION FACTORIAL
      EXTERNAL NXTASK
      EXTERNAL FACTORIAL
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h10b-1)+
     &int_mb(k_spin+h11b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11
     &b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+h10b-1),in
     &t_mb(k_sym+h11b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+h10b-1) * int_
     &mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      DO p8b = p7b,noab+nvab
      IF (int_mb(k_spin+p7b-1)+int_mb(k_spin+p8b-1) .eq. int_mb(k_spin+h
     &10b-1)+int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),ieor(int_mb(k_sym+p8b-1),ieor(int_mb(
     &k_sym+h10b-1),int_mb(k_sym+h11b-1)))) .eq. irrep_t) THEN
      CALL TCE_RESTRICTED_4(p7b,p8b,h10b,h11b,p7b_1,p8b_1,h10b_1,h11b_1)
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,p7b,p8b,h4b_2,h5b_2,h6b_2,p1
     &b_2,p7b_2,p8b_2)
      dim_common = int_mb(k_range+p7b-1) * int_mb(k_range+p8b-1)
      dima_sort = int_mb(k_range+h10b-1) * int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_15_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (h10b_1 - 1 + noab * (p8b_1 - noab - 1 + nvab * (p7
     &b_1 - noab - 1)))))
      CALL TCE_SORT_4(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+h10b-1),int_mb(k_range+h11b-
     &1),4,3,2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_15_1',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_15_1',5,MA_ERR)
      IF ((p8b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p8b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p8b-1),int_mb(k_range+p1b-1),6,3,2,1,5,4,1.0d0)
      END IF
      IF ((p7b .lt. p1b) .and. (p1b .le. p8b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p8b-1),5,3,2,1,6,4,-1.0d0)
      END IF
      IF ((p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p8b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p8b-1),4,3,2,1,6,5,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_15_1',6,MA
     &_ERR)
      nsuperp(1) = 1
      nsuperp(2) = 1
      isuperp = 1
      IF (p7b .eq. p8b) THEN
      nsuperp(isuperp) = nsuperp(isuperp) + 1
      ELSE
      isuperp = isuperp + 1
      END IF
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,2.0d0/FACTORIAL(
     &nsuperp(1))/FACTORIAL(nsuperp(2)),dbl_mb(k_a_sort),dim_common,dbl_
     &mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sort),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_15_1'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_15_1'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_15_1',9,MA_ERR)
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h6b-1),int_mb(k_range+h5b-1),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h11b-1),int_mb(k_range+h10b-1),4,3,2,1,6,5,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p1b - noab - 1 + nvab * (h6b - 1 
     &+ noab * (h5b - 1 + noab * (h4b - 1)))))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_15_1',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_15_1'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_15_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h6 h10 h11 p1 )_yt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h10b
      INTEGER h11b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1
     &b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb(k_sym+h11b-1),i
     &nt_mb(k_sym+p1b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1)
     &+int_mb(k_spin+p1b-1).ne.12)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_15_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO h11b = h10b,noab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1)+int_mb(k_spin+p1
     &b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb(k_sym+h11b-1),i
     &nt_mb(k_sym+p1b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11b-1)
     &+int_mb(k_spin+p1b-1).ne.12)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = h11b - 1 + noab * (h10b - 1 + noab * (p1
     &b - noab - 1 + nvab * (h6b - 1 + noab * (h5b - 1 + noab * (h4b - 1
     &)))))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+h10b-1)
     & * int_mb(k_range+h11b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_15_2(d_a,k_a_offset,d_b,k_b_offset,d_c,k_
     &c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i1 ( h4 h5 h6 h10 h11 p1 )_ytt + = 2 * Sum ( p7 ) * t ( p7 h11 )_t * i2 ( h4 h5 h6 h10 p1 p7 )_yt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h11b
      INTEGER h10b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p7b
      INTEGER p7b_1
      INTEGER h11b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p1b_2
      INTEGER h10b_2
      INTEGER p7b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h11b = 1,noab
      DO h10b = 1,noab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h10b-1)+
     &int_mb(k_spin+h11b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+h11
     &b-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+h10b-1),in
     &t_mb(k_sym+h11b-1)))))) .eq. ieor(irrep_y,ieor(irrep_t,irrep_t))) 
     &THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+h10b-1) * int_
     &mb(k_range+h11b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_2',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+p7b-1) .eq. int_mb(k_spin+h11b-1)) THEN
      IF (ieor(int_mb(k_sym+p7b-1),int_mb(k_sym+h11b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p7b,h11b,p7b_1,h11b_1)
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,h10b,p7b,h4b_2,h5b_2,h6b_2,p
     &1b_2,h10b_2,p7b_2)
      dim_common = int_mb(k_range+p7b-1)
      dima_sort = int_mb(k_range+h11b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+h10b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_2',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_15_2',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h11b_
     &1 - 1 + noab * (p7b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p7b-1)
     &,int_mb(k_range+h11b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_15_2',3,MA
     &_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_2',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_15_2',5,MA_ERR)
      IF ((h10b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (h10b_2 - 1 + noab * (p1b_2 - noab - 1 + nvab
     & * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+h10b-1),int_mb(k_range+p7b-1),5,4,3,2,1,6,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_15_2',6,MA
     &_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_15_2'
     &,7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_15_2'
     &,8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_15_2',9,MA_ERR)
      IF ((h10b .le. h11b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h11b-1),5,4,3,2,1,6,1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h11b 
     &- 1 + noab * (h10b - 1 + noab * (p1b - noab - 1 + nvab * (h6b - 1 
     &+ noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF ((h11b .le. h10b)) THEN
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+h10b-1
     &),int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1
     &),int_mb(k_range+h4b-1),int_mb(k_range+h11b-1),5,4,3,2,6,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(h10b 
     &- 1 + noab * (h11b - 1 + noab * (p1b - noab - 1 + nvab * (h6b - 1 
     &+ noab * (h5b - 1 + noab * (h4b - 1)))))))
      END IF
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_15_2',10,M
     &A_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_15_2'
     &,11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE ccsdt_lambda3_15_2_1(d_a,k_a_offset,d_b,k_b_offset,d_c,
     &k_c_offset)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 h5 h6 h10 p1 p7 )_yt + = -1 * Sum ( p9 ) * t ( p9 h10 )_t * y ( h4 h5 h6 p1 p7 p9 )_y
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER d_a
      INTEGER k_a_offset
      INTEGER d_b
      INTEGER k_b_offset
      INTEGER d_c
      INTEGER k_c_offset
      INTEGER NXTASK
      INTEGER next
      INTEGER nprocs
      INTEGER count
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h10b
      INTEGER p7b
      INTEGER dimc
      INTEGER l_c_sort
      INTEGER k_c_sort
      INTEGER p9b
      INTEGER p9b_1
      INTEGER h10b_1
      INTEGER h4b_2
      INTEGER h5b_2
      INTEGER h6b_2
      INTEGER p1b_2
      INTEGER p7b_2
      INTEGER p9b_2
      INTEGER dim_common
      INTEGER dima_sort
      INTEGER dima
      INTEGER dimb_sort
      INTEGER dimb
      INTEGER l_a_sort
      INTEGER k_a_sort
      INTEGER l_a
      INTEGER k_a
      INTEGER l_b_sort
      INTEGER k_b_sort
      INTEGER l_b
      INTEGER k_b
      INTEGER l_c
      INTEGER k_c
      EXTERNAL NXTASK
      nprocs = GA_NNODES()
      count = 0
      next = NXTASK(nprocs)
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (next.eq.count) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+h10b-1)+
     &int_mb(k_spin+p7b-1).ne.12)) THEN
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+p1b-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p7b
     &-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+p1b-1),ieor(int_mb(k_sym+h10b-1),in
     &t_mb(k_sym+p7b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      dimc = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb(k_ra
     &nge+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+h10b-1) * int_
     &mb(k_range+p7b-1)
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c_sort,k_c_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_2_1',0,MA_ERR)
      CALL DFILL(dimc,0.0d0,dbl_mb(k_c_sort),1)
      DO p9b = noab+1,noab+nvab
      IF (int_mb(k_spin+p9b-1) .eq. int_mb(k_spin+h10b-1)) THEN
      IF (ieor(int_mb(k_sym+p9b-1),int_mb(k_sym+h10b-1)) .eq. irrep_t) T
     &HEN
      CALL TCE_RESTRICTED_2(p9b,h10b,p9b_1,h10b_1)
      CALL TCE_RESTRICTED_6(h4b,h5b,h6b,p1b,p7b,p9b,h4b_2,h5b_2,h6b_2,p1
     &b_2,p7b_2,p9b_2)
      dim_common = int_mb(k_range+p9b-1)
      dima_sort = int_mb(k_range+h10b-1)
      dima = dim_common * dima_sort
      dimb_sort = int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_mb
     &(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+p7b-1)
      dimb = dim_common * dimb_sort
      IF ((dima .gt. 0) .and. (dimb .gt. 0)) THEN
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a_sort,k_a_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_2_1',1,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dima,'noname',l_a,k_a)) CALL ERRQUIT('
     &ccsdt_lambda3_15_2_1',2,MA_ERR)
      CALL GET_HASH_BLOCK(d_a,dbl_mb(k_a),dima,int_mb(k_a_offset),(h10b_
     &1 - 1 + noab * (p9b_1 - noab - 1)))
      CALL TCE_SORT_2(dbl_mb(k_a),dbl_mb(k_a_sort),int_mb(k_range+p9b-1)
     &,int_mb(k_range+h10b-1),2,1,1.0d0)
      IF (.not.MA_POP_STACK(l_a)) CALL ERRQUIT('ccsdt_lambda3_15_2_1',3,
     &MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b_sort,k_b_sort)) CALL
     & ERRQUIT('ccsdt_lambda3_15_2_1',4,MA_ERR)
      IF (.not.MA_PUSH_GET(mt_dbl,dimb,'noname',l_b,k_b)) CALL ERRQUIT('
     &ccsdt_lambda3_15_2_1',5,MA_ERR)
      IF ((p9b .lt. p7b) .and. (p7b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p9b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p1b-1),5,6,3,2,1,4,-1.0d0)
      END IF
      IF ((p7b .le. p9b) .and. (p9b .lt. p1b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p1b_2
     & - noab - 1 + nvab * (p9b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p1b-1),4,6,3,2,1,5,1.0d0)
      END IF
      IF ((p7b .lt. p1b) .and. (p1b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p7b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p9b-1),4,5,3,2,1,6,-1.0d0)
      END IF
      IF ((p9b .lt. p1b) .and. (p1b .le. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p1b_2 - noab - 1 + nvab * (p9b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p9b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+p7b-1),6,5,3,2,1,4,1.0d0)
      END IF
      IF ((p1b .le. p9b) .and. (p9b .lt. p7b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p7b_2
     & - noab - 1 + nvab * (p9b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p9b-1),int_mb(k_range+p7b-1),6,4,3,2,1,5,-1.0d0)
      END IF
      IF ((p1b .le. p7b) .and. (p7b .le. p9b)) THEN
      CALL GET_HASH_BLOCK(d_b,dbl_mb(k_b),dimb,int_mb(k_b_offset),(p9b_2
     & - noab - 1 + nvab * (p7b_2 - noab - 1 + nvab * (p1b_2 - noab - 1 
     &+ nvab * (h6b_2 - 1 + noab * (h5b_2 - 1 + noab * (h4b_2 - 1)))))))
      CALL TCE_SORT_6(dbl_mb(k_b),dbl_mb(k_b_sort),int_mb(k_range+h4b-1)
     &,int_mb(k_range+h5b-1),int_mb(k_range+h6b-1),int_mb(k_range+p1b-1)
     &,int_mb(k_range+p7b-1),int_mb(k_range+p9b-1),5,4,3,2,1,6,1.0d0)
      END IF
      IF (.not.MA_POP_STACK(l_b)) CALL ERRQUIT('ccsdt_lambda3_15_2_1',6,
     &MA_ERR)
      CALL DGEMM('T','N',dima_sort,dimb_sort,dim_common,1.0d0,dbl_mb(k_a
     &_sort),dim_common,dbl_mb(k_b_sort),dim_common,1.0d0,dbl_mb(k_c_sor
     &t),dima_sort)
      IF (.not.MA_POP_STACK(l_b_sort)) CALL ERRQUIT('ccsdt_lambda3_15_2_
     &1',7,MA_ERR)
      IF (.not.MA_POP_STACK(l_a_sort)) CALL ERRQUIT('ccsdt_lambda3_15_2_
     &1',8,MA_ERR)
      END IF
      END IF
      END IF
      END DO
      IF (.not.MA_PUSH_GET(mt_dbl,dimc,'noname',l_c,k_c)) CALL ERRQUIT('
     &ccsdt_lambda3_15_2_1',9,MA_ERR)
      CALL TCE_SORT_6(dbl_mb(k_c_sort),dbl_mb(k_c),int_mb(k_range+p7b-1)
     &,int_mb(k_range+p1b-1),int_mb(k_range+h6b-1),int_mb(k_range+h5b-1)
     &,int_mb(k_range+h4b-1),int_mb(k_range+h10b-1),5,4,3,2,6,1,-1.0d0)
      CALL ADD_HASH_BLOCK(d_c,dbl_mb(k_c),dimc,int_mb(k_c_offset),(p7b -
     & noab - 1 + nvab * (h10b - 1 + noab * (p1b - noab - 1 + nvab * (h6
     &b - 1 + noab * (h5b - 1 + noab * (h4b - 1)))))))
      IF (.not.MA_POP_STACK(l_c)) CALL ERRQUIT('ccsdt_lambda3_15_2_1',10
     &,MA_ERR)
      IF (.not.MA_POP_STACK(l_c_sort)) CALL ERRQUIT('ccsdt_lambda3_15_2_
     &1',11,MA_ERR)
      END IF
      END IF
      END IF
      next = NXTASK(nprocs)
      END IF
      count = count + 1
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      next = NXTASK(-nprocs,1)
      call GA_SYNC()
      RETURN
      END
      SUBROUTINE OFFSET_ccsdt_lambda3_15_2_1(l_a_offset,k_a_offset,size)
C     $Id: ccsdt_lambda3.F 24184 2013-05-04 00:43:17Z edo $
C     This is a Fortran77 program generated by Tensor Contraction Engine v.1.0
C     Copyright (c) Battelle & Pacific Northwest National Laboratory (2002)
C     i2 ( h4 h5 h6 h10 p1 p7 )_yt
      IMPLICIT NONE
#include "global.fh"
#include "mafdecls.fh"
#include "sym.fh"
#include "errquit.fh"
#include "tce.fh"
      INTEGER l_a_offset
      INTEGER k_a_offset
      INTEGER size
      INTEGER length
      INTEGER addr
      INTEGER h4b
      INTEGER h5b
      INTEGER h6b
      INTEGER p1b
      INTEGER h10b
      INTEGER p7b
      length = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+h10b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p7b
     &-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb(k_sym+p1b-1),in
     &t_mb(k_sym+p7b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p1b-1)+
     &int_mb(k_spin+p7b-1).ne.12)) THEN
      length = length + 1
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      IF (.not.MA_PUSH_GET(mt_int,2*length+1,'noname',l_a_offset,k_a_off
     &set)) CALL ERRQUIT('ccsdt_lambda3_15_2_1',0,MA_ERR)
      int_mb(k_a_offset) = length
      addr = 0
      size = 0
      DO h4b = 1,noab
      DO h5b = h4b,noab
      DO h6b = h5b,noab
      DO p1b = noab+1,noab+nvab
      DO h10b = 1,noab
      DO p7b = noab+1,noab+nvab
      IF (int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1)+int_mb(k_spin+h6b-1)
     & .eq. int_mb(k_spin+h10b-1)+int_mb(k_spin+p1b-1)+int_mb(k_spin+p7b
     &-1)) THEN
      IF (ieor(int_mb(k_sym+h4b-1),ieor(int_mb(k_sym+h5b-1),ieor(int_mb(
     &k_sym+h6b-1),ieor(int_mb(k_sym+h10b-1),ieor(int_mb(k_sym+p1b-1),in
     &t_mb(k_sym+p7b-1)))))) .eq. ieor(irrep_y,irrep_t)) THEN
      IF ((.not.restricted).or.(int_mb(k_spin+h4b-1)+int_mb(k_spin+h5b-1
     &)+int_mb(k_spin+h6b-1)+int_mb(k_spin+h10b-1)+int_mb(k_spin+p1b-1)+
     &int_mb(k_spin+p7b-1).ne.12)) THEN
      addr = addr + 1
      int_mb(k_a_offset+addr) = p7b - noab - 1 + nvab * (h10b - 1 + noab
     & * (p1b - noab - 1 + nvab * (h6b - 1 + noab * (h5b - 1 + noab * (h
     &4b - 1)))))
      int_mb(k_a_offset+length+addr) = size
      size = size + int_mb(k_range+h4b-1) * int_mb(k_range+h5b-1) * int_
     &mb(k_range+h6b-1) * int_mb(k_range+p1b-1) * int_mb(k_range+h10b-1)
     & * int_mb(k_range+p7b-1)
      END IF
      END IF
      END IF
      END DO
      END DO
      END DO
      END DO
      END DO
      END DO
      RETURN
      END
