global class LoanerApplicationWebService {

	webservice static String loanIndication(String laId){
        List<loaner_application__c> laList = [select id, Status__c, Detail_count__c from loaner_application__c where id = :laId];
        if (laList.size() == 0) {
            return '样机借出申请不存在。';
        }
        loaner_application__c la = laList[0];
        if (la.Status__c != '已批准') {
            return '样机借出申请状态不正确，不能做出库指示。状态：' + la.Status__c;
        }
        if (la.Detail_count__c == 0) {
            return '样机借出申请未分配样机。';
        }

        la.Status__c = '已出库指示';
        la.Bollow_Date__c = Date.today();

        List<loaner_application_detail__c> ladList = [select id from loaner_application_detail__c where loaner_application__c = :laId and RAESD_Status__c = '已批准'];
        for (loaner_application_detail__c lad : ladList) {
            lad.RAESD_Status__c = '已出库指示';
        }

        try{
            update ladList;
            update la;
        } catch(Exception ex) {
            return ex.getMessage() + '|Line:' + ex.getLineNumber();
        }
		return '1';
	}

    webservice static String sendOutAll(String laId){
         List<loaner_application__c> laList = [select id, Status__c, delivery_company__c, Tracking_Number__c, Return_to_wh_staff__c,pickup_time__c,Equipment_Type__c,Agent__c,Rental_Start_Date__c,Rental_end_Date__c,Owner.Name from loaner_application__c where id = :laId];
        if (laList.size() == 0) {
            return '样机借出申请不存在。';
        }
        loaner_application__c la = laList[0];
        if(la.pickup_time__c != null && la.Status__c == '出库前已检测'){
            List<loaner_application_detail__c> ladList = [select id,Receipt_Date__c,Receipt_Status__c, LOANER__c, LOANER__r.RecordType.DeveloperName from loaner_application_detail__c where loaner_application__c = :laId and RAESD_Status__c = '出库前已检测'];
            la.Status__c = '申请者已收货';
            la.Shipping_Finished_Date__c =  Date.today();
            la.Shipping_Finished_Date_All__c = Date.today();

            for (loaner_application_detail__c lad : ladList) {
                lad.RAESD_Status__c = '申请者已收货';
                lad.Shipment_Request_Date__c =  Date.today();
                lad.Receipt_Date__c =  Date.today();
                lad.outTime__c = Datetime.now();
                lad.Receipt_Status__c = 'OK';
            }

            List<Asset> astList = new List<Asset>();
            for (loaner_application_detail__c lad : ladList) {
                if (lad.LOANER__r.RecordType.DeveloperName == 'loaner_individual') {
                    Asset ast = new Asset(Id = lad.LOANER__c);
                    ast.Status = '出借';
                    if(la.Equipment_Type__c== 'NDT' || la.Equipment_Type__c == 'ANI' || la.Equipment_Type__c == 'BS'){
                        ast.Loaner__c = la.Owner.Name;
                        ast.Rental_Customer__c = la.Agent__c;
                        ast.Rental_Start_Date__c = la.Rental_Start_Date__c;
                        ast.Rental_end_Date__c = la.Rental_end_Date__c;
                    }
                    astList.add(ast);
                }
            }

            try{
                update ladList;
                update la;
                update astList;
            } catch(Exception ex) {
                return ex.getMessage() + '|Line:' + ex.getLineNumber();
            }

            return '1';
        }
        
        if (la.Status__c != '出库前已检测' && la.Status__c != '部分发货') {
            return '样机借出申请状态不正确，不能做全部发货。状态：' + la.Status__c;
        }
        if (la.delivery_company__c == null || la.delivery_company__c == '' ||
            la.Tracking_Number__c == null || la.Tracking_Number__c == '' ||
            la.Return_to_wh_staff__c == null) {
            return '发货信息不完整，请填写发货信息。';
        }

        List<loaner_application_detail__c> ladList = [select id, LOANER__c, LOANER__r.RecordType.DeveloperName from loaner_application_detail__c where loaner_application__c = :laId and RAESD_Status__c = '出库前已检测'];
        if (ladList.size() == 0) {
            return '样机已经全部出库。';
        }

        la.Status__c = '全部发货';
        la.Shipping_Finished_Date__c = Date.today();
        la.Shipping_Finished_Date_All__c = Date.today();

        Date temp = Date.today();
        Loaner_Express__c le = new Loaner_Express__c();
        le.loaner_application__c = laId;
        le.Name = temp.day()+ '日发货物流单';
        insert le;

        Integer count =0;

        for (loaner_application_detail__c lad : ladList) {
            lad.RAESD_Status__c = '已出库';
            lad.Shipment_Request_Date__c = Date.today();
            lad.delivery_company__c = la.delivery_company__c;
            lad.Tracking_Number__c = la.Tracking_Number__c;
            lad.Return_to_wh_staff__c = la.Return_to_wh_staff__c;
            lad.outTime__c = Datetime.now();
            count++;
            lad.Loaner_Express__c = le.id;  
        }

        le.Consignor_LogisticsNumber__c = la.Tracking_Number__c;
        le.Consignor_LogisticsCompany__c = la.delivery_company__c;
        le.consignor__c = la.Return_to_wh_staff__c;
        le.Shipment_Request_Date__c = Date.today();       
        le.NotReceivingNum__c = count;

        List<Asset> astList = new List<Asset>();
        for (loaner_application_detail__c lad : ladList) {
            if (lad.LOANER__r.RecordType.DeveloperName == 'loaner_individual') {
                Asset ast = new Asset(Id = lad.LOANER__c);
                ast.Status = '出借';
                if(la.Equipment_Type__c== 'NDT' || la.Equipment_Type__c == 'ANI' || la.Equipment_Type__c == 'BS'){
                    ast.Loaner__c = la.Owner.Name;
                    ast.Rental_Customer__c = la.Agent__c;
                    ast.Rental_Start_Date__c = la.Rental_Start_Date__c;
                    ast.Rental_end_Date__c = la.Rental_end_Date__c;
                }
                astList.add(ast);
            }
        }

        try{
            update le;
            update ladList;
            update la;
            update astList;
        } catch(Exception ex) {
            return ex.getMessage() + '|Line:' + ex.getLineNumber();
        }

        return '1';
    }

    webservice static String installConfirm(String laId){
        List<loaner_application__c> laList = [select id, Status__c from loaner_application__c where id = :laId];
        if (laList.size() == 0) {
            return '样机借出申请不存在。';
        }
        loaner_application__c la = laList[0];
        if (la.Status__c != '申请者已收货') {
            return '样机借出申请状态不正确，不能做装机确认。状态：' + la.Status__c;
        }

        List<loaner_application_detail__c> ladList = [select id from loaner_application_detail__c where loaner_application__c = :laId and RAESD_Status__c = '申请者已收货'];

        la.Status__c = '申请者已装机确认';
        la.HP_Received_Sign_Date__c = Date.today();

        for (loaner_application_detail__c lad : ladList) {
            lad.RAESD_Status__c = '申请者已装机确认';
        }

        try{
            update ladList;
            update la;
        } catch(Exception ex) {
            return ex.getMessage() + '|Line:' + ex.getLineNumber();
        }

        return '1';
    }

    webservice static String sendBackAll(String laId){
        List<loaner_application__c> laList = [select id,loaner_request_number__c,loaner_manage_place__c,return_Number__c, Status__c, Return_Track_Company__c, Return_Track_Number__c, Return_Trake_Staff__c,Equipment_Type__c,loaner_return__c from loaner_application__c where id = :laId];
        if (laList.size() == 0) {
            return '样机借出申请不存在。';
        }

        loaner_application__c la = laList[0];
        //String.contains(String str)
        //Boolean isOK = true;
        List<loaner_application__c> lappList = [select id,AllLead_OrderName__c,Equipment_Type__c  from loaner_application__c where  Status__c = '已批准'];
        if(lappList.size() > 0){
            for(loaner_application__c lapp : lappList){
                if(lapp.AllLead_OrderName__c != null){
                    if(lapp.AllLead_OrderName__c.contains(la.loaner_request_number__c) && lapp.Equipment_Type__c == 'BS'){
                        return '存在已批准的转借申请单，请点击 转借发货';
                    }
                }
            }
        }
        /*if(lappList.size() > 0){
            return '有已批准的转借该借用单中样机的借用单，不能全部回寄';
        }*/
        
        if (la.Status__c != '部分发货' && la.Status__c != '全部发货' && la.Status__c != '申请者已收货' && la.Status__c != '申请者已装机确认' && la.Status__c != '部分回寄') {
            return '样机借出申请状态不正确，不能做全部回寄。状态：' + la.Status__c;
        }
        if((la.Equipment_Type__c == 'NDT' || la.Equipment_Type__c == 'ANI') && la.loaner_return__c == true){
            system.debug('111');
            /*if(la.Status__c != '申请者已装机确认'){
                return '必须装机确认才可以回寄样机';
            }*/
            if(la.loaner_manage_place__c == null || la.loaner_manage_place__c == ''){
                return '请填写样机管理地';
            }
            if(la.Return_Trake_Staff__c == null || la.Return_Trake_Staff__c == ''){
                return '请填写返品人';
            }
            if(la.return_Number__c == null || la.return_Number__c == ''){
                return '请填写返品人电话';
            }
        }else{
            if(la.Equipment_Type__c == 'BS' && la.Status__c != '申请者已装机确认'){
                return '未装机确认，不能全部回寄。';
            }
            if (la.Return_Track_Company__c == null || la.Return_Track_Company__c == '' ||
                la.Return_Track_Number__c == null || la.Return_Track_Number__c == '' ||
                la.Return_Trake_Staff__c == null) {
                return '回寄信息不完整，请填写回寄信息。';
            }

        }
        system.debug('222222222');
        List<loaner_application_detail__c> ladList = [select id, LOANER__c, LOANER__r.RecordType.DeveloperName from loaner_application_detail__c where loaner_application__c = :laId and (RAESD_Status__c = '已出库' or RAESD_Status__c = '申请者已收货' or RAESD_Status__c = '申请者收货NG' or RAESD_Status__c = '申请者已装机确认')];
        if (ladList.size() == 0) {
            return '样机已经全部回寄。';
        }
        Loaner_Express__c le = new Loaner_Express__c();
        system.debug(la.Equipment_Type__c+'++++++++'+la.loaner_return__c);
        if((la.Equipment_Type__c != 'NDT' && la.Equipment_Type__c != 'ANI') || la.loaner_return__c == false || la.loaner_return__c == null){
            system.debug('1');
            la.Status__c = '全部回寄';
            la.Asset_Return_Date__c = Date.today();
            la.Asset_Return_Date_All__c = Date.today();

            Date temp = Date.today();
           
            le.loaner_application__c = laId;
            le.Name = temp.day()+ '日回寄物流单';
            le.IsDeliveryLogistics__c = false;
            insert le;

            Integer count = 0;

            for (loaner_application_detail__c lad : ladList) {
                lad.Return_Express__c = le.id;
                lad.RAESD_Status__c = '已回寄';
                lad.Asset_Return_Date__c = Date.today();
                lad.loaner_manage_place__c = la.loaner_manage_place__c;
                lad.Return_Track_Company__c = la.Return_Track_Company__c;
                lad.Return_Track_Number__c = la.Return_Track_Number__c;
                lad.Return_Trake_Staff__c = la.Return_Trake_Staff__c;
                lad.return_Number__c = la.return_Number__c;
                //lad.inTime__c = Datetime.now();
                count++;
            }

            le.Asset_Return_Date__c = Date.today();
            le.Return_LogisticsCompany__c = la.Return_Track_Company__c;
            le.Return_LogisticsNumber__c = la.Return_Track_Number__c;
            le.Return_Sender__c = la.Return_Trake_Staff__c;
            le.NotReceivingNum__c = count;
            le.return_Number__c = la.return_Number__c;
    /*        List<Asset> astList = new List<Asset>();
            for (loaner_application_detail__c lad : ladList) {
                if (lad.LOANER__r.RecordType.DeveloperName == 'loaner_individual') {
                    Asset ast = new Asset(Id = lad.LOANER__c);
                    ast.Status = '在库';
                    astList.add(ast);
                }
            }*/
        }else{
            system.debug('2');
            la.Status__c = '全部回收';
            la.Asset_Return_Date__c = Date.today();
            la.Asset_Return_Date_All__c = Date.today();
            la.LoanerClosedDateAll__c = Date.today();
            for (loaner_application_detail__c lad : ladList) {
                lad.RAESD_Status__c = '已回收';
                lad.Asset_Return_Date__c = Date.today();
                lad.loaner_manage_place__c = la.loaner_manage_place__c;
                lad.Return_Track_Company__c = '自己送还';
                lad.Return_Track_Number__c = '自己送还';
                lad.Return_Trake_Staff__c = la.Return_Trake_Staff__c;
                lad.Lost_item_check_Date__c = Date.today();
                lad.Received_loaner_Date__c = Date.today();
                lad.return_Number__c = la.return_Number__c;
                //lad.inTime__c = Datetime.now();
                lad.Check_lost_Item__c = 'ok';
            }
            le = null;
        }
        try{
            if(le != null){
                update le;
            }

            if(ladList != null){
                update ladList;
            }
            if(la != null){
                update la;
            }
            //update astList;
        } catch(Exception ex) {
            return ex.getMessage() + '|Line:' + ex.getLineNumber();
        }

        return '1';
    }

    webservice static String splitLoanerApplication(String laId){
        test001();
        List<loaner_application__c> laCheckList = [select id, Status__c, Equipment_Type__c from loaner_application__c where id = :laId];
        if (laCheckList.size() == 0) {
            return '样机借出申请不存在。';
        }
        loaner_application__c laCheck = laCheckList[0];

        if (laCheck.Equipment_Type__c == 'IE') { 
            if (laCheck.Status__c != '销售担当批准') {
                return '样机借出申请状态不正确，不能做分割申请。状态：' + laCheck.Status__c;
            } 
        }else if(laCheck.Equipment_Type__c == 'NDT' || laCheck.Equipment_Type__c == 'ANI'){
            if(laCheck.Status__c != '已批准'){
                return '样机借出申请状态不正确，不能做分割申请。状态：' + laCheck.Status__c;
            }
        }else{
            return laCheck.Equipment_Type__c + '不可以做分割申请。';    
        }
        
        List<AggregateResult> checkList = [select LOANER__r.loaner_place__c lp
                                             from loaner_application_detail__c
                                            where loaner_application__c = :laId
                                            group by LOANER__r.loaner_place__c
                                            order by LOANER__r.loaner_place__c];
        if (checkList.size() == 0) {
            return '样机借出申请没有明细，不能做分割申请。';
        }
        if (checkList.size() == 1) {
            return '借出样机的存放地一致，不需要做分割申请';
        }

        Schema.DescribeSobjectResult d_la = loaner_application__c.sObjectType.getDescribe();
        Map<String, Schema.SObjectField> d_la_map = d_la.fields.getMap();
        String soql_la = 'select ';
        String fields_la = '';
        for (String field : d_la_map.keySet()) {
            if (fields_la.length() > 0) {
                fields_la += ', ';
            }
            fields_la += field;
        }
        soql_la += fields_la;
        soql_la += ' from loaner_application__c where Id = \'' + laId + '\'';
        List<loaner_application__c> laList = Database.query(soql_la);

        loaner_application__c la_org = laList[0];

        Schema.DescribeSobjectResult d_lad = loaner_application_detail__c.sObjectType.getDescribe();
        Map<String, Schema.SObjectField> d_lad_map = d_lad.fields.getMap();
        String soql_lad = 'select ';
        String fields_lad = '';
        for (String field : d_lad_map.keySet()) {
            if (fields_lad.length() > 0) {
                fields_lad += ', ';
            }
            fields_lad += field;
        }
        soql_lad += fields_lad;
        soql_lad += ' from loaner_application_detail__c where loaner_application__c = \'' + laId + '\'';
        soql_lad += ' order by loaner_place__c';
        List<loaner_application_detail__c> ladList = Database.query(soql_lad);

        List<String> keyList = new List<String>();
        Map<String, List<loaner_application_detail__c>> keyMap = new Map<String, List<loaner_application_detail__c>>();
        String loaner_place_back = '*start*';

        for (loaner_application_detail__c lad : ladList) {
            if (lad.loaner_place__c != loaner_place_back) {
                List<loaner_application_detail__c> temp = new List<loaner_application_detail__c>();
                temp.add(lad);

                keyList.add(lad.loaner_place__c);
                keyMap.put(lad.loaner_place__c, temp);

                loaner_place_back = lad.loaner_place__c;
            } else {
                List<loaner_application_detail__c> temp = keyMap.get(lad.loaner_place__c);
                temp.add(lad);
            }
        }

        try {
            List<loaner_application__c> insList = new List<loaner_application__c>();
            Map<String, loaner_application__c> insMap = new Map<String, loaner_application__c>();
            String otherName = '';

            for (Integer i = 1; i < keyList.size(); i++) {
                String key = keyList[i];
                loaner_application__c la_new = la_org.clone();
                la_new.Id = null;
               // la_new.IsSplitLoanerApplication__c = true;
                la_new.Name = la_new.Name + '-' + ('00' + i).right(2);
                otherName = otherName + la_new.Name + ' \r\n ';
                la_new.loaner_place__c = key;
                insList.add(la_new);
                insMap.put(key, la_new);
            }
            insert insList;

             if (keyList.size() > 0) {
                la_org.loaner_place__c = keyList[0];
                la_org.IsSplitLoanerApplication__c = true;
                la_org.Other_Form__c = otherName;
            }
            update la_org;

            List<loaner_application_detail__c> updList = new List<loaner_application_detail__c>();
            for (Integer i = 1; i < keyList.size(); i++) {
                String key = keyList[i];
                for (loaner_application_detail__c lad : keyMap.get(key)) {
                    lad.loaner_application__c = insMap.get(key).Id;
                    updList.add(lad);
                }
            }
            update updList;

        } catch(Exception ex) {
            return ex.getMessage() + '|Line:' + ex.getLineNumber();
        }

        return '1';
    }

    webservice static String cancelLoanerApplication(String laId){
        List<loaner_application__c> laList = [select id, Status__c, Cancel_Reason__c from loaner_application__c where id = :laId];
        if (laList.size() == 0) {
            return '样机借出申请不存在。';
        }
        loaner_application__c la = laList[0];
        if (la.Status__c != '草案中' && la.Status__c != '销售担当批准' && la.Status__c != '已批准') {
            return '样机借出申请状态不正确，不能做取消。状态：' + la.Status__c;
        }
        if (la.Cancel_Reason__c == null || la.Cancel_Reason__c == '') {
            return '请输入取消理由。';
        }

        List<loaner_application_detail__c> ladList = [select id, LOANER__c, LOANER__r.RecordType.DeveloperName from loaner_application_detail__c where loaner_application__c = :laId];

        la.Status__c = '取消';
        la.Cancel_Date__c = Date.today();

        for (loaner_application_detail__c lad : ladList) {
            lad.RAESD_Status__c = '取消';
            lad.Cancel_Date__c = Date.today();
        }

        List<Asset> astList = new List<Asset>();
        for (loaner_application_detail__c lad : ladList) {
            if (lad.LOANER__r.RecordType.DeveloperName == 'loaner_individual') {
                Asset ast = new Asset(Id = lad.LOANER__c);
                ast.Status = '在库';
                astList.add(ast);
            }
        }

        try{    
            update ladList;
            update la;
            update astList;
        } catch(Exception ex) {
            return ex.getMessage() + '|Line:' + ex.getLineNumber();
        }

        return '1';
    }
    /*
     *检查所分配个体管理样机样机是否都在库， 
     *检查所分配数量管理样机是否都有足够数量用来分配。
    */
    webservice static String haveFreeze(String laId){
        if(laId == null || laId == ''){
            return '样机借出申请不存在。';
        }

        loaner_application__c la = [select id,Loaner_LendOrder__c from loaner_application__c where id =: laId];

        if(la.Loaner_LendOrder__c == true ){ 
            return '1';
        }
        //获取数量管理和个体管理的明细
        List<loaner_application_detail__c> ladList = [select id,LOANER__r.Status,LOANER__r.Name from loaner_application_detail__c where LOANER__r.RecordType.DeveloperName = 'loaner_individual' and loaner_application__c = :laId];        
        List<AggregateResult> ladList1 = [select LOANER__c,count(Id) LoanerNO from loaner_application_detail__c where LOANER__r.RecordType.DeveloperName = 'loaner_number' and loaner_application__c = :laId GROUP by LOANER__c];
        //数量管理判断
        if(ladList1.size() > 0){
            List<String> loanerIdList = new List<String>(); 
            Map<String,Integer> loanerMap = new Map<String,Integer>();

            for(AggregateResult ar:ladList1){
                loanerIdList.add(String.valueOf(ar.get('LOANER__c')));
                loanerMap.put(String.valueOf(ar.get('LOANER__c')), Integer.valueOf(ar.get('LoanerNO')));
            }

            List<Asset> assetList = [select id,Count_can_allocate_F__c,Name from Asset where Id = :loanerIdList];

            for(Asset ass : assetList){
                //如果分配数量大于样机可分配数量则提示错误
                if(loanerMap.get(ass.Id) > ass.Count_can_allocate_F__c){
                    return '您所分配的样机\''+ass.Name+'\'库存不足，现余'+ass.Count_can_allocate_F__c+'个，请调整分配后再提交.';
                }
            }

        }
        //个体管理判断
        if(ladList.size() > 0){
            for(loaner_application_detail__c lad : ladList){ 
                //如果存在状态不是'在库'的样机则提示错误
                if(lad.LOANER__r.Status != '在库'){
                    return '您所分配的样机\''+lad.LOANER__r.Name+'\'已冻结，请重新分配在库样机.';
                }
            }
        }
        return '1';
        
    }






    private static void test001(){
        Integer i = 0;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
    }
}