forked from Mugdha-Hazra/PrepBytes-questions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTable Chair.cpp
46 lines (46 loc) · 880 Bytes
/
Table Chair.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
/*#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using namespace std;
bool comp(long long a, long long b)
{
return (a < b);
}
int main()
{
long long t,m,r1,r2,r3;
cin>>t;
while(t--)
{
cin>>m>>r1>>r2>>r3;
if(m%4==0)
cout<<"0\n";
else if((m+1)%4==0)
cout<<r1<<"\n";
else if((m+2)%4==0)
cout<<std::min({r1+r1 ,r2 },comp)<<"\n";
else if((m+3)%4==0)
cout<<std::min({r1+r1+r1 , r2+r1 , r3 }, comp)<<"\n";
}
return 0;
}
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{long long t,n,r1,r2,r3;
cin>>t;
while(t--)
{
cin>>n>>r1>>r2>>r3;
n%=4;
if(n==0)
cout<<"0\n";
if(n==3) cout<<min(r1,min(r2+r3,r3+r3+r3))<<"\n";
if(n==2) cout<<min(r2,min(r1,r3)*2)<<"\n";
if(n==1) cout<<min(r3,min(r1+r2,r1+r1+r1))<<"\n";
}
return 0;
}