int n;
freopen("auxiliary.in","r",stdin);
freopen("auxiliary.out","w",stdout);
while(~scanf("%d",&n))
{
if(n==2) puts("1");
else
{
int ans=n/3;
n%=3;
if(n==0) printf("%d\n",ans*7);
else if(n==1) printf("%d\n",(ans-1)*7+4);
else printf("%d\n",ans*7+1);
}
}
int vis[505][2];
int fun(char c)
{
if(c>='a'&&c<='z') return (c-'a');
else if(c>='A'&&c<='Z') return (c-'A'+100);
}
int main()
{
int n;
freopen("boolean.in","r",stdin);
freopen("boolean.out","w",stdout);
string s;
while(cin>>s)
{
int len=s.size();
memset(vis,0,sizeof(vis));
for(int i=0; i<len; i++)
{
if(s[i]=='|') continue;
if(s[i]=='~')
{
i++;
vis[fun(s[i])][1]=1;
}
else vis[fun(s[i])][0]=1;
}
LL ans=0;
int flag=0;
for(int i=0; i<300; i++)
{
if(vis[i][0]||vis[i][1]) ans++;
if(vis[i][0]&&vis[i][1]) flag=1;
}
ans=(1LL)<<ans;
if(!flag) ans-=1;
cout<<ans<<endl;
}
return 0;
}
int dis[1100][1100];
int judge(char c)
{
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='w'||c=='y')
return 0;
return 1;
}
string ss="bcdfghjklmnpqrstvxz";
int fanss[1100];
int vis[110];
int ans,he;
void dfs(int num,int f,int val)
{
if(f>18) return ;
dfs(num,f+1,val);
int ha=0;
for(int i=0; i<=18; i++)
{
int tmp=dis[ss[f]][ss[i]];
if(tmp!=0&&ss[i]!=ss[f])
{
if(vis[i])
ha-=tmp;
else
ha+=tmp;
}
}
if(val+ha>ans)
{
//printf("num=%d f=%d val=%d ha=%d\n",num,f,val,ha);
ans=val+ha;
he=num|(1<<f);
}
vis[f]=1;
dfs(num|(1<<f),f+1,val+ha);
vis[f]=0;
return ;
}
int main()
{
freopen("consonant.in","r",stdin);
freopen("consonant.out","w",stdout);
for(int i=0; i<=18; i++)
fanss[ss[i]]=i;
string s;
while(cin>>s)
{
ans=0;
he=0;
memset(dis,0,sizeof(dis));
memset(vis,0,sizeof(vis));
int len=s.size();
for(int i=0; i<len-1; i++)
{
if(judge(s[i])&&judge(s[i+1]))
{
dis[s[i]][s[i+1]]++;
dis[s[i+1]][s[i]]++;
}
}
dfs(0,0,0);
memset(vis,0,sizeof(vis));
// printf("he=%d ans=%d\n",he,ans);
for(int i=18; i>=0; i--)
{
if((1<<i)&he)
{
//printf("i=%d\n",i);
vis[i]=1;
}
}
for(int i=0; i<len; i++)
{
//printf("\nhehe=%d i=%d\n",fanss[ss[i]],i);
if(judge(s[i])&&vis[fanss[s[i]]])
printf("%c",s[i]-32);
else
printf("%c",s[i]);
}
printf("\n");
}
}
#include<algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <map>
using namespace std;
int _,d1,d2,d3,d4,x,v;
int pw[30],d[30];
map<int,vector<int> > hs;
int a[400];
void dfs(int d) {
if (d>=3&&a[d-1]<1<<(d-3)) return;
for (int i=d-1;i>=0;i--) {
a[d]=a[i]+a[d-1];
if (a[d]<(1<<22)) {
int u=a[d],N=__builtin_popcount(u);
if (N<=4) {
int M=31-__builtin_clz(u);
if (d<N+M-1&&!hs.count(u)) {
hs[u]=vector<int>(a,a+d+1);
}
}
dfs(d+1);
}
}
}
int main()
{
freopen("dividing.in","r",stdin);
freopen("dividing.out","w",stdout);
a[0]=1;
dfs(1);
pw[0]=1;
for (int i=1;i<=25;i++) pw[i]=pw[i-1]*2;
for (scanf("%d",&_);_;_--) {
scanf("%d%d%d%d",&d1,&d2,&d3,&d4);
x=pw[d1]+pw[d2]+pw[d3]+pw[d4];
v=0;
for (int i=0;i<25;i++) if (x&pw[i]) {
d[v++]=i;
}
if (v!=4||!hs.count(x)) {
printf("%d\n",d[v-1]+v-1);
while (x!=1) {
printf("%d %d %d\n",x,x/2,x-x/2);
if (x%2==1) {
printf("%d %d %d\n",x/2+1,x/2,1);
}
x/=2;
}
} else {
printf("%d\n",d[3]+2);
vector<int> w=hs[x];
for (int i=w.size()-1;i>=1;i--) {
printf("%d %d %d\n",w[i],w[i-1],w[i]-w[i-1]);
}
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back
#define fir first
#define sec second
const int maxd = 1000006;
int n;
int d[maxd];
vi a;
vi b;
int main() {
freopen( "equal.in", "r", stdin );
freopen( "equal.out", "w", stdout );
memset(d, 0, sizeof(d));
scanf( "%d", &n );
for (int i = 1; i <= n; ++i) {
int a;
scanf( "%d", &a );
d[a]++;
}
for (int i = 1; i < maxd; ++i)
if (d[i] > 0) {
a.pb(d[i]);
bool flag = false;
for (int j = 2; i * j < maxd; ++j)
if (d[i*j] > 0) {
flag = true;
break;
}
if (flag) b.pb(d[i]);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ans = a.size();
int p = 0, q = 0, sp = 0, sq = 0;
for (int i = 0; i <= n; ++i) {
while (p < (int)a.size() && sp + a[p] <= i) {
sp += a[p];
p++;
}
while (q < (int)b.size() && sq + b[q] <= i) {
sq += b[q];
q++;
}
printf( "%d ", min(ans-p+1, ans-q));
}
puts( "" );
}
#include <cstdio>
#include <map>
#include <bitset>
typedef long long i64;
typedef std::bitset<27> BS;
BS bs[27];
std::map<unsigned,i64> f;
#define cvs(x) (x=='1'?0:x-'a'+1)
void ins(char a,char b)
{
a=cvs(a);b=cvs(b);
bs[a].set(b);bs[a].set(a);
bs[b].set(b);
}
i64 gcd(i64 a,i64 b){return b?gcd(b,a%b):a;}
i64 dfs(BS x)
{
if(x.none())return 1;
unsigned xl=x.to_ulong();
if(f.find(xl)!=f.end())return f[xl];
i64 ret=0;
for(int i=0;i<27;++i)
if((x&bs[i]).count()==1&&(x&bs[i])[i])
{ret+=dfs(x.reset(i));x.set(i);}
return f[xl]=ret;
}
int n,amsk;char a,b,c;
int main()
{
freopen("fygon20.in","r",stdin);
freopen("fygon20.out","w",stdout);
scanf("%d",&n);
ins('1','n');
for(int i=0;i<n-1;++i)
{
scanf(" for %c in range(%c, %c):",&a,&b,&c);
ins(b,a);ins(a,c);
}
scanf("%*s");
for(int i=0;i<27;++i)for(int j=0;j<27;++j)
if(bs[j][i])bs[j]|=bs[i];
BS m=BS((1<<27)-1);
for(int i=0;i<27;++i)
{
if(bs[i].none())m.reset(i);
for(int j=i+1;j<27;++j)
if(bs[i]==bs[j])m.reset(j);
}
i64 an=dfs(m),ad=1,g;
for(int i=1;i<m.count()-1;++i)ad*=i;
g=gcd(an,ad);an/=g;ad/=g;
printf("%d %lld/%lld\n",m.count()-2,an,ad);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back
#define fir first
#define sec second
using pii = pair<int,int>;
const int mxn = 100006;
int n, m;
vector<pii> edge;
vi e[mxn];
void sel(int lim) {
for (int i = 1; i <= n; ++i)
e[i] = {};
for (int i = 0; i <= lim; ++i) {
int x = edge[i].fir, y = edge[i].sec;
e[x].pb(y);
e[y].pb(x);
}
}
#define ass(x) ({if(!(x)) throw 1;})
int dfn[mxn], cnt;
int cactus(int x, int p) {
dfn[x] = ++cnt; int a = 0;
for (auto i : e[x]) if (i != p)
if (!dfn[i]) {
int t = cactus(i, x);
if (t && t != x) ass(!a), a = t;
} else if (dfn[i] < dfn[x]) {
ass(!a), a = i;
}
return a;
}
bool check(int lim) {
sel(lim);
try {
cnt = 0;
fill(dfn, dfn + n + 1, 0);
for (int i = 1; i <= n; ++i) if (!dfn[i])
cactus(i, 0);
} catch (...) {
return false;
}
return true;
}
bool v[mxn];
vi st;
void dfs(int x, int y) {
v[x] = true;
st.pb(x);
if (x == y)
throw 1;
for (auto i : e[x]) if (!v[i])
dfs(i, y);
st.pop_back();
}
int rid[mxn];
vi pa;
void dfs2(int x, int o) {
v[x] = true;
pa.pb(x);
if (x != o && rid[x])
throw 1;
for (auto i : e[x]) if (!v[i])
dfs2(i, o);
pa.pop_back();
}
void out(vi a) {
printf("%d", (int)a.size());
for (auto i : a)
printf(" %d", i);
puts("");
}
void out(vi a, int x, int y) {
rotate(a.begin(), find(a.begin(), a.end(), x), a.end());
out(vi(a.begin(), find(a.begin(), a.end(), y) + 1));
}
int main() {
freopen("grand.in", "r", stdin);
freopen("grand.out", "w", stdout);
int T;
cin >> T;
while (T--) {
scanf("%d%d", &n, &m);
edge = {};
for (int i = 0; i < m; ++i) {
int x, y;
scanf("%d%d", &x, &y);
edge.pb({x, y});
}
int L = 0, R = m - 1, M;
while (L < R)
if (M = L + R + 1 >> 1, check(M))
L = M;
else
R = M - 1;
// L : last legal
if (L == m - 1) {
puts("-1");
} else {
int p = L + 1;
sel(p - 1);
int x = edge[p].fir, y = edge[p].sec;
fill(v, v + n + 1, false);
st = {};
try { dfs(x, y); } catch (...) {}
assert(!st.empty() && st.front() == x && st.back() == y);
fill(rid, rid + n + 1, 0);
for (int i = 0; i < st.size(); ++i)
rid[st[i]] = i + 1;
for (int i = 1; i <= n; ++i)
e[i] = {};
for (int i = 0; i <= p - 1; ++i) {
int x = edge[i].fir, y = edge[i].sec;
if (!(rid[x] && rid[y] && abs(rid[x] - rid[y]) == 1)) {
e[x].pb(y);
e[y].pb(x);
}
}
fill(v, v + n + 1, false);
pa = {};
try {
for (int i = 1; i <= n; ++i) if (!v[i] && rid[i])
dfs2(i, i);
} catch (...) {}
assert(!pa.empty() && rid[pa.front()] && rid[pa.back()] && pa.front() != pa.back());
x = pa.front();
y = pa.back();
printf("%d %d\n", x, y);
out(pa, x, y);
out(st, x, y);
reverse(st.begin(), st.end());
out(st, x, y);
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back
#define fir first
#define sec second
const int maxn = 100006;
vi e[maxn];
int p[maxn];
int n;
bool mat[maxn];
vi q;
void dfs(int x) {
for (auto i : e[x]) {
dfs(i);
if (!mat[i] && !mat[x]) {
mat[x] = mat[i] = true;
}
}
}
void dfs2(int x) {
if (!mat[x]) q.pb(x);
for (auto i : e[x])
dfs2(i);
}
int tot;
void dfs3(int x) {
if (!mat[x]) tot++;
for (auto i : e[x])
dfs3(i);
}
vector<pair<int,int>> S;
int main() {
freopen( "hidden.in", "r", stdin );
freopen( "hidden.out", "w", stdout );
scanf( "%d", &n );
for (int i = 2; i <= n; ++i) {
scanf( "%d", &p[i] );
if (p[i] != 0) e[p[i]].pb(i);
}
for (int i = 1; i <= n; ++i)
if (p[i] == 0) dfs(i);
dfs2(1);
for (int i = 2; i <= n; ++i)
if (p[i] == 0 && mat[i]) {
p[i] = 1;
dfs2(i);
}
for (int i = 2; i <= n; ++i)
if (p[i] == 0) {
tot = 0;
dfs3(i);
S.pb( {tot,i} );
}
sort(S.begin(), S.end());
reverse(S.begin(), S.end());
for (auto x : S) {
int i = x.sec;
while (!q.empty() && mat[q.back()]) q.pop_back();
if (!q.empty()) {
mat[q.back()] = true;
mat[i] = true;
p[i] = q.back();
q.pop_back();
}
else p[i] = 1;
dfs2(i);
}
int ans = 0;
for (int i = 1; i <= n; ++i)
if (mat[i]) ans++;
cout<<ans/2<<endl;
for (int i = 2; i <= n; ++i) printf( "%d ", p[i] );
puts( "" );
}
struct zp
{
LL x,y;
}node[maxn];
int main()
{
int n;
freopen("intel.in","r",stdin);
freopen("intel.out","w",stdout);
while(~scanf("%d",&n))
{
LL ans=0,rmin=inf,rmax=-inf,lmin=inf,lmax=-inf;
for(int i=0;i<n;i++)
{
cin>>node[i].x>>node[i].y;
rmin=min(rmin,node[i].x);
lmin=min(lmin,node[i].y);
rmax=max(rmax,node[i].x);
lmax=max(lmax,node[i].y);
}
for(int i=0;i<n;i++)
ans+=abs(node[(i+1)%n].x+node[(i+1)%n].y-node[i].x-node[i].y);
//printf("rmin=%lld rmax=%lld lmin=%lld lmax=%lld ans=%lld\n",rmin,rmax,lmin,lmax,ans);
cout<<ans-2*(rmax-rmin)-2*(lmax-lmin)<<endl;
}
return 0;
}
int main()
{
int n,m,k;
freopen("kotlin.in","r",stdin);
freopen("kotlin.out","w",stdout);
while(~scanf("%d%d%d",&n,&m,&k))
{
memset(ans,0,sizeof(ans));
if(k>((n+1)/2)*((m+1)/2))
{
printf("Impossible\n");
continue;
}
int a=-1,b=-1,he=sqrt(k);
for(int i=1;i<=he&&a==-1;i++)
{
if(k%i==0)
{
int tmp=k/i;
if(tmp<=(max(n,m)+1)/2&&i<=(min(n,m)+1)/2)
{
a=tmp-1;
b=i-1;
if(n<m)
swap(a,b);
break;
}
}
}
if(a<0&&b<0)
{
printf("Impossible\n");
continue;
}
//printf("a=%d b=%d\n",a,b);
for(int i=1;i<n&&a;i+=2)
{
for(int j=0;j<m;j++)
ans[i][j]=1;
a--;
}
for(int j=1;j<m&&b;j+=2)
{
for(int i=0;i<n;i++)
ans[i][j]=1;
b--;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
if(ans[i][j])
printf("#");
else
printf(".");
printf("\n");
}
}
return 0;
}
ll n;
bool base2(ll n)
{
return (n&(-n))==n;
}
struct node
{
ll a,b;
int aa,bb;
} ans
;
int fun(ll a,ll b)//判断b是否是a的幂次
{
int num=0;
while(b%a==0)
{
b/=a;
num++;
}
if(b!=1) num=-1;
return num;
}
int del()
{
int num=0;
// if(n>1000000)
ans[num].a=n,ans[num].aa=1,ans[num++].bb=0;
for(ll i=2; i*i*i<=n; i++)
{
ll tmp=i;
for(int j=1; j<64; j++)
if(n%tmp==0)
{
ll other=n/tmp;
int num1=fun(i,other);
int num2=fun(i+1,other);
if(num1!=-1)
{
ans[num].a=i,ans[num].aa=j+num1,ans[num++].bb=0;
break;
}
if(num2!=-1)
{
ans[num].a=i,ans[num].aa=j,ans[num].b=i+1,ans[num++].bb=num2;
break;
}
if(n/tmp<i) break;
tmp*=i;
}
}
ll x=sqrt(n);
// if(x>1000000)
// {
if(x*x==n) ans[num].a=x,ans[num].aa=2,ans[num++].bb=0;
if(x*(x+1)==n) ans[num].a=x,ans[num].aa=1,ans[num].b=x+1,ans[num++].bb=1;
// }
return num;
}
void solve()
{
int num=del();
printf("%d\n",num);
for(int i=0; i<num; i++)
{
printf("%d",ans[i].aa+ans[i].bb);
for(int j=0; j<ans[i].aa; j++) printf(" %lld",ans[i].a);
for(int j=0; j<ans[i].bb; j++) printf(" %lld",ans[i].b);
puts("");
}
}
int main()
{
freopen("little.in ","r",stdin);
freopen("little.out","w",stdout);
while(~scanf("%lld",&n))
{
if(n==1||base2(n)) puts("-1");
else solve();
}
return 0;
}
//1000000000000000000
//576460752303423488
//864691128455135232