#include #include #include using namespace std; long long m,n,p,x[100000],ans[10000]; int byn(long long x) { long long m1=m,ans=1; long long left=m1/3; long long right=m1/3*2; while((x<=left||x>right)&&m1>1) { if(x<=left) { m1/=3; ans++; } else if(x>right) { m1/=3; x-=right; ans++; } else break; left=m1/3; right=m1/3*2; } return ans; } int main() { ifstream fin("farm.in"); ofstream fout("farm.out"); fin>>p>>n; m=1; for(int i=0;i>x[i]; ans[i]=byn(x[i]); } for(int i=0;i