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 105 106 107 108 109 110 111
   | #include<bits/stdc++.h> #define RG register #define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout); #define clear(x, y) memset(x, y, sizeof(x)); namespace std { template<> inline void swap(int &x, int &y) { y^=x^=y^=x; } } using namespace std;
  template<typename T = long long> inline T read() { 	T data=0, w=1; 	char ch=getchar(); 	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar(); 	if(ch=='-') w=-1, ch=getchar(); 	while(ch>='0'&&ch<='9') data=(data<<3)+(data<<1)+(ch^48), ch=getchar(); 	return data*w; }
  struct node { long long a, b, c, s1, s2; } p, q, rtp, rtq; inline node turn(node &&x) { 	if(x.a>x.b) swap(x.a, x.b); 	if(x.a>x.c) swap(x.a, x.c); 	if(x.b>x.c) swap(x.c, x.b); 	x.s1=x.b-x.a; x.s2=x.c-x.b; 	return x; } inline pair<node, int> get_root(const node &x) { 	int depth=0; 	int a=x.a, b=x.b, c=x.c, s1=x.s1, s2=x.s2; 	while(s1!=s2) 	{ 		if(s1<s2) 		{ 			depth+=s2/s1; s2%=s1; 			if(s2==0) s2=s1, depth--; 			b=c-s2; a=b-s1; 		} 		else 		{ 			depth+=s1/s2; s1%=s2; 			if(s1==0) s1=s2, depth--; 			b=a+s1; c=b+s2; 		} 	} 	return {{a, b, c, s1, s2}, depth}; } inline node jump(const node &x, int depth) { 	int a=x.a, b=x.b, c=x.c, s1=x.s1, s2=x.s2, dep=0; 	while(s1!=s2) 	{ 		if(s1<s2) 		{ 			dep+=s2/s1; 			if(dep>depth) 			{ 				int tmp=depth-dep+s2/s1; 				s2-=s1*tmp; b=c-s2; a=b-s1; 				return {a, b, c, s1, s2}; 			} 			else 			{ 				s2%=s1; 				if(s2==0) s2=s1, dep--; 				b=c-s2; a=b-s1; 			} 		} 		else 		{ 			dep+=s1/s2; 			if(dep>depth) 			{ 				int tmp=depth-dep+s1/s2; 				s1-=s2*tmp; b=a+s1; c=b+s2; 				return {a, b, c, s1, s2}; 			} 			else 			{ 				s1%=s2; 				if(s1==0) s1=s2, dep--; 				b=a+s1; c=b+s2; 			} 		} 	} 	return {a, b, c, s1, s2}; } bool operator == (const node &a, const node &b) { return a.a==b.a&&a.b==b.b&&a.c==b.c; } int dp, dq; int main() { 	p=turn({read(), read(), read(), 0, 0}); 	q=turn({read(), read(), read(), 0, 0}); 	auto t=get_root(p); rtp=t.first;  dp=t.second; 	t=get_root(q); rtq=t.first;  dq=t.second; 	if(!(rtp==rtq)) { puts("NO"); return 0; } 	int ans=abs(dp-dq); 	if(dp>dq) p=jump(p, dp-dq), dp=dq; 	else q=jump(q, dq-dp), dq=dp; 	int l=0, r=dp; 	while(l<r) 	{ 		int mid=(l+r)>>1; 		node x=jump(p, mid), y=jump(q, mid); 		if(x==y) r=mid; 		else l=mid+1; 	} 	printf("YES\n%d\n", ans+(r<<1)); 	return 0; }
   |