-
Notifications
You must be signed in to change notification settings - Fork 0
/
babakacube.cpp
104 lines (74 loc) · 1.17 KB
/
babakacube.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<iostream>
using namespace std;
#define right _right
#define left _left
long long top,up,down,sum,temp,bottom,right,left;
void move_d()
{
// cout<<"\nMoving down";
temp=top;
top=up;
up=bottom;
bottom=down;
down=temp;
sum += top;
//cout<<"\nSum="<<sum;
}
void single_l()
{
//cout<<"\nMoving single left";
temp=top;
top=right;
right=bottom;
bottom=left;
left=temp;
sum += top;
//cout<<"\nSum="<<sum;
}
void single_r()
{
//cout<<"\nMoving singhle right";
temp=top;
top=left;
left=bottom;
bottom=right;
right=temp;
sum += top;
//cout<<"\nsum="<<sum;
}
void move_l(long long n)
{
sum += (n/4) * 14;
// cout<<"\nMoving left";
// cout<<"\nSum="<<sum;;
for(long long i=0;i< n%4;++i) single_l();
}
void move_r(long long n)
{
// cout<<"\nMoving rught";
sum += (n/4) * 14;
// cout<<"\nSum="<<sum;;
for(long long i=0;i< n%4;++i) single_r();
}
int main()
{
long long r,c;
cin>>r>>c;
top=2;
bottom=5;
right=3;
left=4;
up=1;
down=6;
sum=0;
for(long long i=0;i<r;++i)
{
move_d();
if(i%2==0)
move_r(c-1);
else
move_l(c-1);
}
cout<<sum<<endl;
return 0;
}