B. Kolya and Tanya
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.

More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied.

Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways).

Input

A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three.

Output

Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7.

Examples
Input
1
Output
20
Input
2
Output
680
Note

20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex):

题意: 输入一个n      3*n个位置 0~3n-1 每个位置的k等于(1,2,3)

ai + ai + n + ai + 2n ≠ 6 则算做一种情况  问共有多少情况 % 1000000000+9

题解:   计算式子

ans1=3^3n%mod

ans2=7^n%mod

( ans1-ans2)%mod

若 ans1<ans2

则输出(ans1+mod-ans2)%mod

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<cmath>
#define ll __int64
#define pi acos(-1.0)
#define mod 1000000007
using namespace std;
ll n;
ll ans1,ans2;
ll quickmod(ll a,ll b)
{
ll sum=;
while(b)
{
if(b&)
sum=(sum*a)%mod;
b>>=;
a=(a*a)%mod;
}
return sum;
}
int main()
{
scanf("%I64d",&n);
ans1=quickmod(,*n)%mod;
ans2=quickmod(,n)%mod;
if(ans1>=ans2)
printf("%I64d\n",(ans1-ans2)%mod);
else
printf("%I64d\n",(ans1+mod-ans2)%mod);
return ;
}

最新文章

  1. 在Windows环境中开始Docker的学习和体验
  2. makefile编写要点
  3. Point Grey FlyCapture 实例汇总
  4. 关于LED 流水灯的软件调试方法(非开发板调试)
  5. [maven] 搭建多模块企业级项目
  6. SQL Server自增长列插入指定值 -- SET IDENTITY_INSERT ON|OFF(转)
  7. Feature Engineering versus Feature Extraction: Game On!
  8. Vue + Webpack + Vue-loader 1
  9. 搜索-hdu-3720-Arranging Your Team
  10. ubuntu profile-environment-bashrc 添加环境变量
  11. javaTemplates-学习笔记一
  12. 解决在某些IE浏览器下字符乱码的问题
  13. 转:面向切面编程AOP的理解
  14. 【Bootstrap简单用法】
  15. 根据 inotify 自己开发软件监控文件系统活动
  16. [APIO2016]
  17. Java 异常体系
  18. 页面添加锚点后如何点击不改变URL?
  19. A problem has been detected and windows has been shut down to prevent damage to your computer.他么啥意思?看这里!【蓝屏】
  20. 洛谷P2050 美食节

热门文章

  1. JS - 简单的下载图片至本地
  2. MySQL(mariadb)主从复制模式与复制过滤
  3. MySQL中使用group_concat()函数数据被截取(有默认长度限制),谨慎!
  4. dts--framework(三)
  5. java中substring()、charAt()、indexOf() (2013-05-05-bd 写的日志迁移
  6. Ball CodeForces - 12D
  7. P1414 又是毕业季II (数学?
  8. react+redux状态管理实现排序 合并多个reducer文件
  9. 十四、pymysql模块
  10. Trident学习笔记(二)