/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Majk
 */

#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>
#include <queue>
using namespace std;

#define x first

typedef long long ll;

template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

#ifndef MOD_H
#define MOD_H
template <unsigned int N> class Field {
    typedef unsigned int ui;
public:
	inline Field<N>&operator+=(const Field<N>&o) {if ((ll)v+o.v >= N) v = (ll)v+o.v-N; else v = v+o.v; return *this; }

	inline Field<N> operator+(const Field<N>&o) {Field<N>r(*this);return r+=o;};

private: ui v;
};

template<unsigned int N>ostream &operator<<(std::ostream&os,const Field<N>&f){return os<<(unsigned int)f;}


typedef Field<1000000007> FieldMod;
#endif

class B {
public:
	void solve(istream& cin, ostream& cout) {
		ll N; cin >> N;

		FieldMod X[2] = {1,0};
		FieldMod Ans=1;
		for (int i = 60; i >= 0; --i) {
			ll x = N >> i;
			if (x <= 0) continue;
			Ans = Ans*3 - X[0]*(2-x%2);
			X[x%2] = X[0] + X[1];
		}
		cout << Ans << endl;
	}
};


int main() {
	ios_base::sync_with_stdio(false);
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}
