Monday, 3 August 2015

N Boy and Sum

N Boy and Sum 


Problem Description

First question is easy to set you up with the online judge. You are given a number 'N'. You need to find the sum of first N terms of the series: 1 - 2 + 3 - 4 + 5 - 6 ...

Input

First line contains T, the number of test cases. Each test case contains the number N on a new line,which denotes the number of events

Output

For each test case, print the total number of registrations on a new line for every test case.

Constraints

Subtask 1 (30 points):
  • 1 ≤ T ≤ 105
  • 1 ≤ N ≤ 100
Subtask 2 (70 points):
  • 1 ≤ T ≤ 105
  • 1 ≤ N ≤ 105

Example

Input:
3
3
1
2


Output:
2
1
-1


**************************************editorial***************************************************************

  just inset string .. if that strin is a part of substring of any existing  string than ans will be vulna......
  there are 2 possibilities of test case 
 type 1-
  likeme
 like .. 
  type 2
 like
likeme 
in both case ans will be vulnarable 
***************************************************************







#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
 struct node
  {
    int word_count;
      struct node * has[26];
      bool ispre[26];
  };
  int exist=0;

// return vacant node 
node* init()
 {
   node *node1=new node;
   node1->word_count=0;
     for(int  i=0;i<26;i++){
     
   node1->has[i]=NULL;
   node1->ispre[i]=false;
    //cout<<"here"<<endl;}
 }
         return node1;
         
 }
 
 
 node *root;
 
 
  void build(char arr[])
   {
      node *present=root;
      
        int len=strlen(arr);

    
          for(int i=0;i<len;i++)
           {
       
            int flag=0;

              if(present->has[arr[i]-'a']==NULL)
               {
           
                flag=1;
                
                  present->has[arr[i]-'a']=init();
               }
               
            if(present->ispre[arr[i]-'a']==true)// means this string is a part of of any existing string 
            {
                       exist=1;// variable 
            
   }

            
                if(i==len-1)// a word is formed completly ..
                 {
         
                  present->ispre[arr[i]-'a']=true;// which indicate that a new word is formed 
                 
                
                 }




                 if(i==len-1 && flag==0)// if a new word in formed without creating any new node since flag==0
                                                      // than it means this new word inserting is substring of any existing word 
                 {
                  exist=1;
                 }

                present=present->has[arr[i]-'a'];

           }
           
          
   }
   
int main()
 {
  int t;
   cin>>t;
   node *node1=init();
   root=node1;
     while(t--)
      {
      
         char arr[100000];
           cin>>arr;
           build(arr);
           
      }
      if(exist==1)
       {
          cout<<"vulnerable"<<endl;
          
       }
       else
         cout<<"non vulnerable"<<endl;
 }