fork download
  1. #include <bits/stdc++.h>
  2. #define gl(x) getline(cin,x);
  3. using namespace std;
  4. //declare mod
  5. long long fib[1000000],mod=1000000007;
  6. int main()
  7. {
  8. int tc;
  9. cin>>tc;
  10. string s;
  11. while(tc--)
  12. {
  13. int a,b;
  14. cin>>a>>b;
  15. fib[0]=a;
  16. fib[1]=b;
  17. for(int i=2;i<1000000;i++)
  18. fib[i] = (fib[i-1]+fib[i-2])%mod;
  19. //we need 2 getlines because the
  20. //first getline will take the '\n' from the previous input
  21. //second getline will take the string as input
  22. gl(s)
  23. gl(s)
  24. stringstream ss;
  25. ss<<s;
  26. int x;
  27. int sum=0;
  28. while(ss>>x){
  29. sum += fib[x-1];
  30. }
  31. cout<<sum<<endl;
  32. }
  33. }
  34.  
Success #stdin #stdout 0.07s 11232KB
stdin
2
1 2
1 2 3 6
1 1
1 6 8 7 9
stdout
19
77