solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> T amax(T a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T a, T1 b) { if (b < a) a = b; return a; } template <typename T> T amod(T a) { if (a < 0) a = -a; return a; } void solve() { long long int c1, c2, d1, d2, r1, r2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; long long int i = (c1 - d2 + r1) % 2 ? -1 : (c1 - d2 + r1) / 2; long long int j = (r1 - c1 + d2) % 2 ? -1 : (r1 - c1 + d2) / 2; long long int k = (r2 - c2 + d2) % 2 ? -1 : (r2 - c2 + d2) / 2; long long int l = (c2 - d2 + r2) % 2 ? -1 : (c2 - d2 + r2) / 2; if (i == j || i == k || i == l || j == k || j == l || k == l) { cout << "-1"; return; } if (i >= 1 && i <= 9 && j >= 1 && j <= 9 && k >= 1 && k <= 9 && l >= 1 && l <= 9) { cout << i << " " << j << "\n" << k << " " << l; } else { cout << "-1"; } } int main() { long long int t; t = 1; while (t--) { solve(); } return 0; }
7
CPP
#include <bits/stdc++.h> int main() { int r1, r2, c1, c2, d1, d2; scanf("%d %d\n", &r1, &r2); scanf("%d %d\n", &c1, &c2); scanf("%d %d", &d1, &d2); int a, b, c, d; b = (r1 - c1 + d2) / 2; c = d2 - b; a = c1 - c; d = c2 - b; if (a != b && b != c && c != d && d != a && a != c && b != d && a > 0 && a < 10 && b < 10 && b > 0 && c < 10 && c > 0 && d < 10 && d > 0) { if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 && a + d == d1 && b + c == d2) printf("%d %d\n%d %d", a, b, c, d); else printf("-1"); } else printf("-1"); }
7
CPP
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) for a in range(1,10): for b in range(1,10): if b==a:continue for c in range(1,10): if c==a or c==b:continue for d in range(1,10): if d==c or d==a or d==b:continue if a+b==r1 and\ c+d==r2 and\ a+d==d1 and\ b+c==d2 and\ a+c==c1 and\ b+d==c2: print(a,b) print(c,d) exit() print(-1) # Mon Oct 05 2020 12:46:44 GMT+0300 (Москва, стандартное время)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 11; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int i = 1; i <= 9; i++) for (int j = 1; j <= 9; j++) for (int k = 1; k <= 9; k++) for (int t = 1; t <= 9; t++) if (i != j && i != k && i != t && j != k && j != t && k != t && i + j == r1 && k + t == r2 && i + k == c1 && j + t == c2 && i + t == d1 && j + k == d2) { cout << i << " " << j << endl; cout << k << " " << t << endl; return 0; } cout << -1 << endl; }
7
CPP
#include <bits/stdc++.h> int main() { int r1, r2, c1, c2, d1, d2; while (scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2) != EOF) { int n = 0; int a, b, c, d; for (a = 1; a <= 9; a++) { for (b = 1; b <= 9; b++) { for (c = 1; c <= 9; c++) { for (d = 1; d <= 9; d++) { if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 && a + d == d1 && b + c == d2 && a != b && a != c && a != d && b != c && b != d && c != d) { printf("%d %d\n%d %d\n", a, b, c, d); n++; } } } } } if (n == 0) printf("-1\n"); } }
7
CPP
def check(x, y, z, w): if x + y == r1 and z + w == r2 and x + z == c1 and y + w == c2 and x + w == d1 and y + z == d2: return True else: return False def equal(x, y, z, w): if x != y and x != z and x != w and y != z and y != w and z != w: return True else: return False r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) f = True for a in range(1, 10): for b in range(1, 10): for c in range(1, 10): for d in range(1, 10): if check(a, b, c, d) and equal(a, b, c, d): f = False print(a, b) print(c, d) break if not f: break if not f: break if not f: break if f: print(-1)
7
PYTHON3
r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) a=0 ;b=0;c=0;d=0 if (r1+c1-d2)%2==0: a = (r1+c1-d2)//2 if (r1+c2-d1)%2==0: b = (r1-d1+c2)//2 if (r2+c1-d1)%2==0: c = (r2-d1+c1)//2 if (c2+d1-r1)%2==0: d = (c2+d1-r1)//2 set1 = {a,b,c,d} # print(set1) if 0<a<10 and 0<b<10 and 0<c<10 and 0<d<10 and len(set1)==4 : print(a,b) print(c,d) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2, k; scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2); if ((c1 + d1 - r2) % 2 == 1) printf("-1\n"); else { k = (c1 + d1 - r2) / 2; if (k == (r1 - k) || k == (c1 - k) || k == (d1 - k) || r1 == c1 || r1 == d1 || c1 == d1) printf("-1\n"); else if (k <= 0 || k > 9 || (r1 - k) <= 0 || (r1 - k) > 9 || (c1 - k) <= 0 || (c1 - k) > 9 || (d1 - k) <= 0 || (d1 - k) > 9) printf("-1\n"); else { printf("%d ", k); printf("%d\n", r1 - k); printf("%d ", c1 - k); printf("%d\n", d1 - k); } } return 0; }
7
CPP
import itertools r1,r2=map(int, input().split()) c1,c2=map(int, input().split()) d1,d2=map(int, input().split()) flag=False for a,b,c,d in itertools.permutations(range(1,10),4): if a+b==r1 and c+d==r2 and a+c==c1 and b+d==c2 and a+d==d1 and b+c==d2: print(a,b) print(c,d) flag=True break if flag==False: print(-1)
7
PYTHON3
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) for r in range(1,10): for rr in range(1,10): for c in range(1,10): for cc in range(1,10): l=[r,rr,c,cc] if r+rr==c1 and r+c==r1 and r+cc==d1 and rr+c==d2 and rr+cc==r2 and len(set(l))==4: print(r,c) print(rr,cc) exit() print(-1)
7
PYTHON3
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) l1,l2,count=[],[],0 for i in range(1,10): for j in range(1,10): if i+j==r1 and i!=j:l1.append([i,j]) if i+j==r2 and i!=j:l2.append([i,j]) for k in range(len(l1)): for l in range(len(l2)): if l1[k][1]!=l2[l][0] and l1[k][1]+l2[l][0]==c1 and l1[k][0]!=l2[l][1] and l1[k][0]+l2[l][1]==c2: if l1[k][0]!=l2[l][0] and l1[k][0]+l2[l][0]==d2 and l1[k][1]!=l2[l][1] and l1[k][1]+l2[l][1]==d1: print(l1[k][1],l1[k][0]) print(*l2[l]) count+=1 break if count!=0:break if count==0:print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2, flag; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { for (int k = 1; k <= 9; k++) { for (int n = 1; n <= 9; n++) { if (i != j && i != k && i != n && j != k && j != n && k != n) { flag++; if (i + j == r1 && k + n == r2 && i + k == c1 && j + n == c2 && i + n == d1 && j + k == d2) { cout << i << " " << j << endl << k << " " << n << endl; return 0; } else if (flag == 3024) cout << "-1" << endl; } } } } } return 0; }
7
CPP
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) a=[[0,0],[0,0]] def debug(x): for i in range(2): for j in range(2): print(a[i][j],end=" ") print() def valid(): if a[0][0]+a[1][1]==d1 and a[0][1]+a[1][0]==d2: for i in range(2): for j in range(2): if a[i][j] not in range(1,10): return False return True return False for i in range(1,10): a[0][0]=i a[0][1]=r1-a[0][0] a[1][0]=c1-a[0][0] a[1][1]=r2-a[1][0] l=[] for i in range(2): for j in range(2): l.append(a[i][j]) l=set(l) if len(l)==4 and valid(): debug(a) break else: print(-1)
7
PYTHON3
def main(): r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) x1 = -0.5 * r2 + -0.5 * c2 + d1 + 0.5 * d2 x2 = -0.5 * r2 + 0.5 * c2 + 0.5 * d2 x3 = 0.5 * r2 + -0.5 * c2 + 0.5 * d2 x4 = 0.5 * r2 + 0.5 * c2 + -0.5 * d2 solutions = {x1, x2, x3, x4} if len(solutions) != 4: print(-1) return if all(0 < x <= 9 and x.is_integer() for x in solutions): print(int(x1), int(x2)) print(int(x3), int(x4)) else: print(-1) if __name__ == '__main__': main()
7
PYTHON3
list = [1,2,3,4,5,6,7,8,9] r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) a = (d1 - r2 + c1)//2 d = (r2 - c1 + d1)//2 b = r1 - a c = r2 - d if a in list and b in list and c in list and d in list and a!=b and a!=c and a!=d and b!=c and c!=d and b!=d: print(a,b) print(c,d) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int a1 = ((r1 + c1 - d2)) % 2 == 0 ? ((r1 + c1 - d2) / 2) : -1; int a2 = ((r1 + c2 - d1)) % 2 == 0 ? ((r1 + c2 - d1) / 2) : -1; int a3 = ((r2 + c1 - d1)) % 2 == 0 ? ((r2 + c1 - d1) / 2) : -1; int a4 = ((r2 + c2 - d2)) % 2 == 0 ? ((r2 + c2 - d2) / 2) : -1; if (a1 < 1 || a2 < 1 || a3 < 1 || a4 < 1 || a1 > 9 || a2 > 9 || a3 > 9 || a4 > 9 || a1 == a2 || a1 == a3 || a1 == a4 || a2 == a3 || a2 == a4 || a3 == a4) { cout << "-1"; } else { cout << a1 << " " << a2 << endl; cout << a3 << " " << a4; } return 0; }
7
CPP
from functools import reduce from operator import * from math import * from sys import * from string import * setrecursionlimit(10**7) dX= [ 0, 0, 1,-1, 1,-1, 1,-1] dY= [ 1,-1, 0, 0, 1,-1,-1, 1] RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() ################################################# r1,r2=RI() c1,c2=RI() d1,d2=RI() for a in range(1,10): x=(a,r1-a,c1-a,d1-a) if any(i<1 or i>9 for i in x) or any(x[i] in x[i+1:] for i in range(4)): continue if x[1]+x[3]==c2 and x[1]+x[2]==d2 and x[2]+x[3]==r2: print(*(x[:2])) print(*(x[2:])) exit(0) print(-1)
7
PYTHON3
import math y = [int(i) for i in input().split()] r2 = y[0] r1 = y[1] y = [int(i) for i in input().split()] c1 = y[0] c2 = y[1] y = [int(i) for i in input().split()] d1 = y[0] d2 = y[1] for i in range(1,10): a = i b = r2-i c = c1-i d = d1-i set1 = {a,b,c,d} if(len(set1)!=4): continue; if(max({a,b,c,d})>9): continue; if(min({a,b,c,d})<1): continue; if(r1==c+d and c2==b+d and d2==b+c): print(a,b) print(c,d) quit() print(-1)
7
PYTHON3
r1 ,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1 , d2 = map(int,input().split()) for a1 in range(1 , 10): for a2 in range(1,10): for a3 in range(1,10): for a4 in range(1 ,10): if a1 == a2 or a1 == a3 or a1 == a4 or a2 == a3 or a2 == a4 or a3 == a4: pass elif a1 + a2 == r1 and a3 + a4 == r2 and a1 + a4 == d1 and a1 + a3 == c1 and a2 + a4 == c2 and a2 + a3 == d2: print(a1,a2) print(a3,a4) exit() print(-1)
7
PYTHON3
r=[int(i)for i in input().split()] c=[int(i)for i in input().split()] d=[int(i)for i in input().split()] a=(d[0]-r[1]+c[0])//2 b= r[0]-a y= c[0]-a z= d[0]-a if (a>9 or a<=0) or (b>9 or b<=0) or (y>9 or y<=0) or (z>9 or z<=0) or (a==b) or (a==c)or (a==y) or (a==z) or (z==y) or (z==c) or (b==z) or (c==y) or (c==b) or (b==y): print("-1") else: print(a,b) print(y,z)
7
PYTHON3
r1,r2= map(int, input().split()) c1,c2= map(int, input().split()) d1,d2= map(int, input().split()) # arr =[int(x) for x in input().split()] y=(r1-c1+d2)//2 x=r1-y n=c2-y m=r2-n ar=[x,y,m,n] ar = sorted(set(ar)) if len(ar)==4 and ar[0]>0 and ar[3]<10 and r1==x+y and c1 == x+m and d1 == x+n: print(str(x),str(y)) print(str(m),str(n)) else: print(str(-1))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int i = 1; i <= 9; ++i) { bool print = true; int arr[30] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int r11 = i; int r12 = r1 - r11; int r21 = c1 - r11; int r22 = r2 - r21; if ((r11 > 9 || r11 < 0) || (r12 > 9 || r12 < 0) || (r21 > 9 || r21 < 0) || (r22 > 9 || r22 < 0)) continue; arr[r11] += 1; arr[r12] += 1; arr[r21] += 1; arr[r22] += 1; if ((r12 == r1 - r11) && (r21 == c1 - r11) && (r22 == r2 - r21)) { if (d1 == r11 + r22 && d2 == r12 + r21) { for (int s = 0; s < 10; s++) if (arr[s] > 1) print = false; if (r11 <= 0 || r12 <= 0 || r21 <= 0 || r22 <= 0) print = false; if (print) { cout << r11 << " " << r12 << endl; cout << r21 << " " << r22 << endl; exit(0); } } } } cout << -1 << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { for (int k = 1; k <= 9; k++) { for (int g = 1; g <= 9; g++) { if (i + j == a && k + g == b && i + k == c && j + g == d && i + g == e && j + k == f && i != j && i != k && i != g && j != k && j != g && k != g) { cout << i << " " << j << endl; cout << k << " " << g << endl; return 0; } } } } } cout << -1; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int a, b, c, d; a = (r1 + c1 - d2) / 2; b = r1 - a; c = d2 - b; d = r2 - c; int x = c1 + c2 - d1 - d2; int y = d1 + d2 - r1 - r2; if (a <= 0 || b <= 0 || c <= 0 || d <= 0 || a == b || b == c || c == d || d == a || a == c || b == d || a > 9 || b > 9 || c > 9 || d > 9 || x < 0 || y < 0) cout << "-1"; else cout << a << " " << b << "\n" << c << " " << d; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, d, e, f, g, i, j, k, t, x, y, z, m, n; int flag = 0; cin >> a >> b >> c >> d >> e >> f; for (x = 1; x < 10; x++) { for (y = 1; y < 10; y++) { for (m = 1; m < 10; m++) { for (n = 1; n < 10; n++) { if (x + y == a && m + n == b && x + m == c && y + n == d && x + n == e && y + m == f && x != y && x != m && x != n && y != m && y != n && m != n) { cout << x << " " << y << endl << m << " " << n; flag = 1; } } } } } if (flag == 0) cout << -1; return 0; }
7
CPP
from collections import deque, defaultdict, Counter from itertools import product, groupby, permutations, combinations from math import gcd, floor, inf from bisect import bisect_right, bisect_left r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) rr = r1+r2 cc = c1+c2 dd = d1+d2 mn = min(r1, r2, c1, c2, d1, d2) mx = max(r1, r2, c1, c2, d1, d2) if (rr ++ cc)/2 != dd or mn < 3 or mx > 17: print(-1) else: top_left = (dd - d2 - r2 + c1)/2 if int(top_left) != top_left: print(-1) exit() else: top_left = int(top_left) top_right = r1 - top_left bottom_left = c1 - top_left bottom_right = r2 - bottom_left st = {top_left, top_right, bottom_left, bottom_right} mn = min(st) mx = max(st) if len(st) != 4 or mn < 1 or mx > 9: print(-1) else: print(top_left, top_right) print(bottom_left, bottom_right)
7
PYTHON3
from collections import Counter r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) c = 0 for i in range(1,10): for j in range(1, 10): for k in range(1, 10): for l in range(1, 10): if i+j == r1 and k+l == r2: if i+k == c1 and j+l == c2: if i+l == d1 and j+k == d2: if len(Counter([i,j,k,l])) == 4: print(f'{i} {j}\n{k} {l}') c = 1 if c != 1: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } template <typename t1> t1 gcd(t1 a, t1 b) { return b == 0 ? a : gcd(b, a % b); } template <typename t1> t1 lcm(t1 a, t1 b) { return a * (b / gcd(a, b)); } int main() { int r1, r2, c1, c2, d1, d2; while (cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2) { int a, b, c, d; int flag = 0; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { for (int k = 1; k <= 9; k++) { for (int l = 1; l <= 9; l++) { if (i != j && i != k && i != l && j != k && j != l && k != l && i + j == r1 && k + l == r2 && i + k == c1 && j + l == c2 && i + l == d1 && j + k == d2) { a = i; b = j; c = k; d = l; flag = 1; break; } } } } } if (flag) cout << a << " " << b << endl << c << " " << d << endl; else cout << -1 << endl; } }
7
CPP
i1 = input() i1 = i1.split(' ') r1 = int(i1[0]) r2 = int(i1[1]) i2 = input() i2 = i2.split(' ') c1 = int(i2[0]) c2 = int(i2[1]) i3 = input() i3 = i3.split(' ') d1 = int(i3[0]) d2 = int(i3[1]) one = int(((r1 + c1 ) - d2 ) / 2) two = int(r1 - one) three = int(c1 - one) four = int(d1 - one) if one != two and one != three and one!= four and two != three and two != four and c1 +c2 == r1 + r2 and c1 + c2 == d1 + d2 and three != four and one <10 and two <10 and three <10 and four <10 and one >0 and two >0 and three >0 and four > 0 : print(str(one) + ' ' + str(two)) print(str(three) + ' ' + str(four)) else : print(-1)
7
PYTHON3
#include <bits/stdc++.h> int main() { int r1, r2, c1, c2, d1, d2, key[2][2]; int i1, i2, i3, i4, flag = 0; scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2); for (i1 = 1; i1 < 10; i1++) { for (i2 = 1; i2 < 10; i2++) { for (i3 = 1; i3 < 10; i3++) { for (i4 = 1; i4 < 10; i4++) { if ((i1 + i2 == r1) && (i3 + i4 == r2) && (i1 + i3 == c1) && (i2 + i4 == c2) && (i1 + i4 == d1) && (i2 + i3 == d2)) { flag = 1; break; } } if (flag == 1) break; } if (flag == 1) break; } if (flag == 1) break; } if ((i1 != i2) && (i1 != i3) && (i1 != i4) && (i2 != i3) && (i2 != i4) && (i3 != i4)) flag = 2; if (flag == 2) printf("%d %d\n%d %d", i1, i2, i3, i4); else printf("-1"); return 0; }
7
CPP
# https://codeforces.com/contest/143/problem/A r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) if (r1 - c1 + d2) % 2 == 0: m = (r1 - c1 + d2) // 2 l = r1 - m n = c1 - l o = c2 - m gems = {l, m, n, o} if len(gems) != 4: print(-1) else: for i in gems: if i < 1 or i > 9: print(-1) break else: if l + m == r1 and n + o == r2 and l + n == c1 and m + o == c2 and l + o == d1 and n + m == d2: print(l, m) print(n, o) else: print(-1) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; set<int> ani; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int a11 = (r1 + c1 - d2) / 2; int a22 = d1 - a11; int a12 = r1 - a11; int a21 = c1 - a11; ani.insert(a11); ani.insert(a12); ani.insert(a21); ani.insert(a22); if (ani.size() == 4 && a11 >= 1 && a11 <= 9 && a12 >= 1 && a12 <= 9 && a21 >= 1 && a21 <= 9 && a22 >= 1 && a22 <= 9 && a21 + a22 == r2 && a12 + a22 == c2 && a12 + a21 == d2) { cout << a11 << " " << a12 << endl; cout << a21 << " " << a22 << endl; } else cout << "-1" << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int m[2][2]; for (int a = 1; a < 10; a++) { for (int b = 1; b < 10; b++) { for (int c = 1; c < 10; c++) { for (int d = 1; d < 10; d++) { if (a == b || a == c || a == d || b == c || b == d || c == d) continue; if (a + b != r1) continue; if (c + d != r2) continue; if (a + c != c1) continue; if (b + d != c2) continue; if (a + d != d1) continue; if (b + c != d2) continue; cout << a << " " << b << endl << c << " " << d; exit(0); } } } } cout << -1; fclose(stdout); return 0; }
7
CPP
r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) a=[] a.append((r1+c1-d2)//2) a.append(r1-a[0]) a.append(d2-a[1]) a.append(d1-a[0]) if(len(set(a))!=4): print(-1) exit(0) for i in a: if(i<1 or i>9): print(-1) exit(0) if(a[0]+a[1]!=r1 or a[2]+a[3]!=r2 or a[0]+a[2]!=c1 or a[1]+a[3]!=c2 or a[0]+a[3]!=d1 or a[1]+a[2]!=d2): print(-1) exit(0) print("{} {}\n{} {}".format(a[0],a[1],a[2],a[3]))
7
PYTHON3
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) def valid(s): if not 1 <= min(s) <= 9: return False elif not 1 <= max(s) <= 9: return False elif len(s) != len(set(s)): return False elif s[2] + s[3] != r2: return False elif s[1] + s[3] != c2: return False elif s[1] + s[2] != d2: return False else: return True for i in range(1, min(r1, c1, d1)): if valid([i, r1 - i, c1 - i, d1 - i]): print(i, r1 - i) print(c1 - i, d1 - i) exit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, const string& delim = " ") { vector<string> res; string t; for (int i = 0; i != s.size(); i++) { if (delim.find(s[i]) != string::npos) { if (!t.empty()) { res.push_back(t); t = ""; } } else { t += s[i]; } } if (!t.empty()) { res.push_back(t); } return res; } vector<int> splitInt(const string& s, const string& delim = " ") { vector<string> tok = split(s, delim); vector<int> res; for (int i = 0; i != tok.size(); i++) res.push_back(atoi(tok[i].c_str())); return res; } template <typename T> void print(T a) { cerr << a; } static void print(long long a) { cerr << a << "L"; } static void print(string a) { cerr << '"' << a << '"'; } template <typename T> void print(vector<T> a) { cerr << "{"; for (int i = 0; i != a.size(); i++) { if (i != 0) cerr << ", "; print(a[i]); } cerr << "}" << endl; } int r1, r2, c1, c2, d1, d2; bool valid(vector<int>& x) { bool can = true; can &= (x[0] + x[1] == r1); can &= (x[2] + x[3] == r2); can &= (x[0] + x[2] == c1); can &= (x[1] + x[3] == c2); can &= (x[0] + x[3] == d1); can &= (x[1] + x[2] == d2); return can; } int main() { while (cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2) { vector<int> p; for (int i = 0, _n = (5); i < _n; i++) p.push_back(0); for (int i = 0, _n = (4); i < _n; i++) p.push_back(1); vector<int> res; bool found = 0; do { vector<int> temp; for (int i = 0, _n = (p.size()); i < _n; i++) if (p[i]) temp.push_back(i + 1); do { if (valid(temp)) { res = temp; found = 1; break; } } while (next_permutation(temp.begin(), temp.end())); } while (!found && next_permutation(p.begin(), p.end())); if (!found) cout << -1 << endl; else { cout << res[0] << " " << res[1] << endl; cout << res[2] << " " << res[3] << endl; } } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2; cin >> c1 >> c2; cin >> d1 >> d2; for (int a = 1; a <= 9; a++) { for (int b = 1; b <= 9; b++) { for (int c = 1; c <= 9; c++) { for (int d = 1; d <= 9; d++) { if (a != b && a != c && a != d && b != c && b != d && c != d) { if (a + d == d1 && b + c == d2 && a + c == c1 && b + d == c2 && a + b == r1 && c + d == r2) { cout << a << " " << b << endl; cout << c << " " << d << endl; return 0; } } } } } } cout << "-1" << endl; return 0; }
7
CPP
#include <bits/stdc++.h> int main() { int r1, r2, c1, c2, d1, d2; std::cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int ii, j, jj; for (int i = 1; i != 10; ++i) { ii = r1 - i; j = c1 - i; jj = d1 - i; if (ii > 0 && ii < 10 && j > 0 && j < 10 && jj > 0 && jj < 10 && j + ii == d2 && j + jj == r2 && ii + jj == c2 && i != ii && i != j && i != jj && ii != j && ii != jj && j != jj) { std::cout << i << " " << ii << std::endl; std::cout << j << " " << jj << std::endl; return 0; } } std::cout << -1; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2, ans = 0, i, j, k, l; int main() { cin >> r1 >> r2; cin >> c1 >> c2; cin >> d1 >> d2; for (i = 1; i < 10; i++) { for (j = 1; j < 10; j++) { for (k = 1; k < 10; k++) { for (l = 1; l < 10; l++) { if (i + k == c1 && j + l == c2 && i + j == r1 && k + l == r2 && i + l == d1 && k + j == d2) { ans = 1; break; } } if (ans == 1) break; } if (ans == 1) break; } if (ans == 1) break; } if (ans == 1 && i != j && i != k && i != l && j != k && j != l && k != l) cout << i << " " << j << endl << k << " " << l << endl; else cout << "-1" << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; bool eshta = false; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { if (i == j) continue; for (int c = 1; c <= 9; c++) { if (i == c || j == c) continue; for (int l = 1; l <= 9; l++) { if (i == l || c == l || j == l) continue; if (i + j == r1 && c + l == r2 && i + c == c1 && l + j == c2 && i + l == d1 && c + j == d2) { eshta = true; cout << i << " " << j << endl << c << " " << l; } } } } } if (eshta == false) { cout << -1; } }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int x1 = (d1 - r2 + c1) / 2; int y1 = r1 - x1; int x2 = c1 - x1; int y2 = (r2 - c1 + x1); if (x1 == x2 || x1 == y1 || x1 == y2 || x2 == y1 || x2 == y2 || y1 == y2) { cout << "-1" << endl; } else if (x1 == 0 || y1 == 0 || x2 == 0 || y2 == 0 || x1 > 9 || x2 > 9 || y1 > 9 || y2 > 9) { cout << "-1" << endl; } else { cout << x1 << " " << y1 << endl; cout << x2 << " " << y2 << endl; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; int a, b, c, d, ok; ok = 0; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (a = 1; a <= 9; a++) { for (b = 1; b <= 9; b++) { for (c = 1; c <= 9; c++) { for (d = 1; d <= 9; d++) { if (a == b || a == c || a == d || b == c || b == d || c == d) continue; if (r1 != a + b) continue; if (r2 != c + d) continue; if (c1 != a + c) continue; if (c2 != b + d) continue; if (d1 != a + d) continue; if (d2 != c + b) continue; ok = 1; break; } if (ok) break; } if (ok) break; } if (ok) break; } if (ok == 0) puts("-1"); else printf("%d %d\n%d %d\n", a, b, c, d); return 0; }
7
CPP
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) c=0 for a in range (1,10): for b in range (1,10): for x in range (1,10): for y in range (1,10): if a +b ==r1 and x+y==r2 and a+x== c1 and b+y==c2 and a+y==d1 and b+x==d2 and len(set([a,b,x,y]))==4: print(a,b) print(x,y) c=1 if c==0: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 44; int main() { int r1, r2, c1, c2, d1, d2, a, b, c, d, f; while (cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2) { f = 0; for (a = 1; a < 10; a++) for (b = 1; b < 10; b++) if (b != a && a + b == r1) for (c = 1; c < 10; c++) if (c != a && c != b && a + c == c1 && c + b == d2) for (d = 1; d < 10; d++) if (d != a && d != b && d != c && c + d == r2 && b + d == c2 && a + d == d1) { f = 1; goto end; } end: if (f) cout << a << " " << b << endl << c << " " << d << endl; else cout << -1 << endl; } }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z, h, c1, c2, r1, r2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; y = (r1 - c1 + d2) / 2; x = r1 - y; z = d2 - y; h = c2 - y; if (x == y || x == z || x == h || y == z || y == h || z == h || x <= 0 || y <= 0 || z <= 0 || h <= 0 || x > 9 || y > 9 || h > 9 || z > 9) cout << -1 << endl; else if (x + y == r1 && x + z == c1 && x + h == d1 && y + z == d2 && y + h == c2 && z + h == r2) { cout << x << ' ' << y << endl; cout << z << ' ' << h << endl; } else cout << -1 << endl; return 0; }
7
CPP
#include <bits/stdc++.h> int main() { int x1, x2, x3, x4, num, a, b, c, d, e, f, g, h, i, j; while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) != EOF) { num = 0; for (g = 1; g <= 9; g++) { for (h = 1; h <= 9; h++) { if (h == g) { continue; } else { for (i = 1; i <= 9; i++) { if (i == g || i == h) { continue; } else { for (j = 1; j <= 9; j++) { if (j == g || j == h || j == i) { continue; } else { if ((a == g + h) && (b == i + j) && (e == g + j) && (c == g + i) && (d == h + j) && (f == h + i)) { num = num + 1; x1 = g; x2 = h; x3 = i; x4 = j; } } } } } } } } if (num == 0) { printf("-1\n"); } else { printf("%d %d\n", x1, x2); printf("%d %d\n", x3, x4); } } return 0; }
7
CPP
F=lambda : map(int, input().split()) R=list(range(1, 10)) r1,r2=F() c1,c2=F() d1,d2=F() z = [(a,b,c,d) for a in R for b in R for c in R for d in R if len(set((a,b,c,d))) > 3 and a+b == r1 and c+d == r2 and a+c == c1 and b+d == c2 and a+d == d1 and b+c == d2] if z:z=z[0];print(z[0],z[1]);print(z[2],z[3]) else:print(-1)
7
PYTHON3
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) def ok(a, b, c, d): if a <= 0 or b <= 0 or c <= 0 or d <= 0: return 0 if a >= 10 or b >= 10 or c >= 10 or d >= 10: return 0 if a == b or a == c or a == d or b == c or b == d or c == d: return 0 if a + b == r1 and c + d == r2 and a + c == c1 and b + d == c2 and a + d == d1 and b + c == d2: return 1 return 0 for i in range(1, 10): a = i b = r1 - a c = c1 - a d = d1 - a if ok(a, b, c, d): print(str(a) + " " + str(b) ) print(str(c) + " " + str(d) ) exit(0) print(-1)
7
PYTHON3
r1, r2 = [int(y) for y in input().split()] c1, c2 = [int(y) for y in input().split()] d1, d2 = [int(y) for y in input().split()] a = (r1+c1-d2)//2 b = r1 - a c = c1 - a d = d1 - a if a not in range(1,10) or b not in range(1,10) or c not in range(1,10) or d not in range(1,10): print(-1) elif a == b or a == c or a == d or b == c or b == d or c == d: print(-1) elif a+b != r1 or c+d != r2 or a+c != c1 or b+d != c2 or a+d != d1 or b+c != d2: print(-1) else: print(a,b) print(c,d)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int num1, num2, num3, num4, flag = 0; for (int i = 1; i < r1; i++) { num1 = i; num2 = r1 - i; if (c1 - num1 > 0 && num1 <= 9) { flag++; num3 = c1 - num1; } else { flag = 0; continue; } if (c2 - num2 > 0 && num2 <= 9) { flag++; num4 = c2 - num2; } else { flag = 0; continue; } if (num3 + num4 == r2 && num3 <= 9) flag++; else { flag = 0; continue; } if (num1 + num4 == d1 && num4 <= 9) flag++; else { flag = 0; continue; } if (num2 + num3 == d2) flag++; else { flag = 0; continue; } if (flag == 5 && num1 != num2 && num1 != num3 && num1 != num4 && num2 != num3 && num2 != num4 && num3 != num4) { cout << num1 << " " << num2 << "\n" << num3 << " " << num4; return 0; } } cout << "-1"; return 0; }
7
CPP
from itertools import permutations r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) for a, b, c, d in permutations(range(1, 10), 4): if a + b == r1 and c + d == r2 and a + c == c1 and b + d == c2 and a + d == d1 and c + b == d2: print(a, b) print(c, d) exit() print(-1)
7
PYTHON3
import math def main(): r1,r2 = [int(x) for x in input().split()] c1,c2 = [int(x) for x in input().split()] d1,d2 = [int(x) for x in input().split()] a = math.floor((r1 - c2 + d1)/2) b = r1 - a c = c1 - a d = d1 - a if a == b or a == c or a == d or b == c or b == d or c == d: print(-1) elif (a + b) != r1 or (c + d) != r2 or (a + c) != c1 or (b + d) != c2 or (a + d) != d1 or (c + b) != d2: print(-1) elif a > 9 or b > 9 or c > 9 or d > 9: print(-1) elif a == 0 or b == 0 or c == 0 or d == 0: print(-1) else: print(a, b) print(c, d) if __name__ == '__main__': main()
7
PYTHON3
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) a=(r1+c1-d2)/2 b=r1-a;c=c1-a;d=d1-a A=set() A.add(a);A.add(b);A.add(c);A.add(d) if(a>9 or b>9 or c>9 or d>9): print("-1") elif(a<1 or c<1 or b<1 or d<1): print("-1") elif(a!=int(a)): print("-1") elif(len(A)<4): print("-1") elif(a+b!=r1 or c+d !=r2 or a+c !=c1 or b+d!=c2 or a+d!=d1 or b+c !=d2): print("-1") else: print(int(a),int(b)) print(int(c),int(d))
7
PYTHON3
#include <bits/stdc++.h> int main() { int x1, x2, x3, x4, r1, r2, c1, c2, d1, d2; scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2); x1 = (r1 + c1 - d2) / 2; x2 = r1 - x1; x3 = (c1 + d2 - r1) / 2; x4 = r2 - x3; if ((x1 >= 1 && x1 <= 9) && (x2 >= 1 && x2 <= 9) && (x3 >= 1 && x3 <= 9) && (x4 >= 1 && x4 <= 9)) { if (x1 != x2 && x3 != x4 && x1 != x3 && x1 != x4 && x2 != x3 && x2 != x4) { if ((x1 + x2 == r1) && (x3 + x4 == r2) && (x1 + x3 == c1) && (x2 + x4 == c2) && (x1 + x4 == d1) && (x2 + x3 == d2)) printf("%d %d\n%d %d\n", x1, x2, x3, x4); else printf("-1\n"); } else printf("-1\n"); } else printf("-1\n"); return 0; }
7
CPP
#include <bits/stdc++.h> int main() { int r1, r2, c1, c2, d1, d2, x; scanf("%d %d %d %d %d %d", &r1, &r2, &c1, &c2, &d1, &d2); if ((r1 + r2) == (c1 + c2) && (c1 + c2) == (d1 + d2) && (r1 + r2) == (d1 + d2)) { x = (d1 + r1 - c2) / 2; if (x) { int a, b, c, d; a = x; b = r1 - x; c = c1 - x; d = c2 - r1 + x; if (a != b && b != c && c != d && a != d && b != d && c != a && a <= 9 && b <= 9 && c <= 9 && d <= 9 && a >= 1 && b >= 1 && c >= 1 && d >= 1) printf("%d %d\n%d %d", a, b, c, d); else printf("-1\n"); } else printf("-1\n"); } else printf("-1\n"); return 0; }
7
CPP
r1,r2 = map(int, input().split(" ")) c1,c2 = map(int, input().split(" ")) d1,d2 = map(int, input().split(" ")) for a1 in range(1,10): for a2 in range(1,10): for a3 in range(1,10): for a4 in range(1,10): if (a1!=a2)and(a1!=a3)and(a1!=a4)and(a2!=a3)and(a2!=a4)and(a3!=a4)and(a1+a2==r1)and(a3+a4==r2)and(a1+a3==c1)and(a2+a4==c2)and(a1+a4==d1)and(a2+a3==d2): print(a1,a2) print(a3,a4) exit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int r[2], c[2], d[2]; int n[3]; int cntn = 0; int main() { cin >> r[0] >> r[1] >> c[0] >> c[1] >> d[0] >> d[1]; for (int i = 1; i <= 9; i++) for (int j = 1; j <= 9; j++) if (i + j == r[0] && i != j) for (int q = 1; q <= 9; q++) if (i != q && j != q && i + q == c[0] && j + q == d[1]) for (int k = 1; k <= 9; k++) if (i != k && j != k && q != k && i + k == d[0] && j + k == c[1] && q + k == r[1]) { cout << i << " " << j << endl << q << " " << k << endl; return 0; } cout << -1 << endl; return 0; }
7
CPP
import math r = list(map(int, input().split())) c = list(map(int, input().split())) d = list(map(int, input().split())) x3 = math.ceil((c[0] + d[1] - r[0])/2) x1 = c[0] - x3 x2 = d[1] - x3 x4 = r[1] - x3 #print(x1,x2) #print(x3,x4) if (x3 > 9) or (x1 > 9) or (x2 > 9) or (x4 > 9) or (x3 <= 0) or (x1 <= 0) or (x2 <= 0) or (x4 <= 0): print(-1) #print(0) elif x3 == x1 or x3 == x2 or x3 == x4 or x1 == x2 or x1 == x4 or x2 == x4 : print(-1) #print(1) elif (x1+x2) != r[0] or (x3+x4) != r[1] or (x1+x3) != c[0] or (x2+x4) != c[1] or (x1 + x4) != d[0] or (x2 + x3) != d[1] : print(-1) else: print(x1,x2) print(x3,x4)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; int r1, r2, c1, c2, d1, d2; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> r1 >> r2; cin >> c1 >> c2; cin >> d1 >> d2; int a, b, c, d; int first_sum = r1 - c2 + d1; if (first_sum % 2 == 0) { a = first_sum / 2; b = r1 - a; c = c1 - a; d = d1 - a; if ((d2 - b != c) || (c2 - b != d) || (r2 - c != d)) { cout << "-1" << endl; return 0; } if (a > 0 && b > 0 && c > 0 && d > 0 && a < 10 && b < 10 && c < 10 && d < 10 && a != b && a != c && a != d && b != c && b != d && c != d) { cout << a << " " << b << endl; cout << c << " " << d << endl; } else { cout << "-1" << endl; } } else { cout << "-1" << endl; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long c1, c2, r1, r2, d1, d2; bool flag = false; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int i = 1; i <= 9; i++) for (int j = 1; j <= 9; j++) for (int k = 1; k <= 9; k++) for (int m = 1; m <= 9; m++) { if (i != j && i != k && i != m && j != k && j != m && k != m) { if (i + m == d1 && j + k == d2 && i + j == r1 && k + m == r2 && i + k == c1 && j + m == c2) { if (flag) break; flag = true; cout << i << " " << j << endl; cout << k << " " << m << endl; break; } } } if (!flag) cout << "-1" << endl; return 0; }
7
CPP
r1, r2 = map(int,input().split()) c1, c2 = map(int,input().split()) d1, d2 = map(int,input().split()) l = [] for i in range(1,c2+1) : l.append((c2-i,i)) for i in l : x2,y2 = i x1 = r1 - x2 y1 = c1 - x1 a = [x1+y1 == c1, x2+y2 == c2, x1+x2 == r1,y1+y2 == r2, x1+ y2 == d1, x2 + y1 == d2, len(set([x1,x2,y1,y2])) == 4, 1<=x1 <= 9,1<=y2 <= 9,1<=x2 <= 9,1<=y1 <= 9 ] if all(a) == True : print(x1,x2) print(y1,y2) exit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; int a, b, c, d; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; a = (r1 - d2 + c1) / 2; b = r1 - a; c = c1 - a; d = c2 - b; if (a < 1 || b < 1 || c < 1 || d < 1 || a > 9 || b > 9 || c > 9 || d > 9) { cout << "-1"; } else if (a == b || b == d || b == c || a == d || c == d || a == c || c + d != r2) { cout << "-1"; } else { cout << a << " " << b << "\n" << c << " " << d; } return 0; }
7
CPP
def check(a , b , c, d): if (a==b): return False if (a==c): return False if (a==d): return False if (b==c): return False if (b==d): return False if (c==d): return False return True r=(input().split()) c=(input().split()) d=(input().split()) r = list(map(int, r)) c = list(map(int, c)) d = list(map(int, d)) t=False total=(r[0]+r[1]+c[0]+c[1]+d[0]+d[1])/3 for i in range(1,10): a=i for j in range(1,10): b=j for k in range(1,10): for z in range(1,10): if total==a+b+k+z: if r[0]== (a+b): if r[1]== (k+z): if c[0] == (a + k): if c[1] == (b+z): if d[0] == (a+z): if d[1] == (k + b): if check(a,b,k,z): t=True print(a,b) print(k,z) if not t : print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int num[10], cells[10]; bool used[10]; bool bt(int idx) { if (idx == 4) { if (num[0] == cells[0] + cells[1] && num[1] == cells[2] + cells[3] && num[2] == cells[0] + cells[2] && num[3] == cells[1] + cells[3] && num[4] == cells[0] + cells[3] && num[5] == cells[1] + cells[2]) return true; else return false; } else { for (int i = 1; i <= 9; i++) { if (!used[i]) { cells[idx] = i; used[i] = true; if (bt(idx + 1)) return true; used[i] = false; } } return false; } } int main() { for (int i = 0; i < 6; i++) cin >> num[i]; memset(used, false, sizeof used); memset(cells, -1, sizeof cells); if (bt(0)) cout << cells[0] << " " << cells[1] << endl << cells[2] << " " << cells[3] << endl; else cout << -1 << endl; }
7
CPP
""" a b c d a+b=r1 c+d=r2 a+c=c1 b+d=c2 a+d=d1 b+c=d2 a2+c+b= r1+c1 2a+d2=r1+c1 a=(r1+c1-d2)//2 b=r1-a c=d2-b d=r2-c """ r1, r2 = map(int, input().strip().split()) c1, c2 = map(int, input().strip().split()) d1, d2 = map(int, input().strip().split()) a=(r1+c1-d2)//2 b=r1-a c=d2-b d=r2-c if len(set([a, b, c, d])) != 4: print(-1) elif min(a, b, c, d)<1 or max(a, b, c, d)>9: print(-1) else: if [a+b==r1, c+d==r2, a+c==c1, b+d==c2, a+d==d1, b+c==d2].count(True) == 6: print(a, b) print(c, d) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int a = 1; a < 10; ++a) { for (int b = 1; b < 10; ++b) { for (int c = 1; c < 10; ++c) { for (int d = 1; d < 10; ++d) { if (a + d == d1 && c + b == d2 && a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2) { if (a != b && a != c && a != d && b != c && b != d && c != d) { cout << a << " " << b << endl << c << " " << d; return 0; } } } } } } cout << -1; return 0; }
7
CPP
r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2= map(int,input().split()) l = [r1,r2,c1,c2,d1,d2] if len({r1+r2,c1+c2,d1+d2}) != 1: print(-1) else: a = (r1-c2+d1)//2 b = r1-a c = c1-a d= d1-a s = len({a,b,c,d}) if (a >0 and a<=9) and (b >0 and b<=9) and (c >0 and c<=9) and ( d >0 and d<=9): if s == 4 : print(a,b) print(c,d) else: print(-1) else: print(-1)
7
PYTHON3
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) num = [1,2,3,4,5,6,7,8,9] for i in range(1,10): x1 = i x2 = c1 - x1 y1 = r1 - x1 y2 = r2 - x2 if(x1 != x2 and x1 != y1 and x1 != y2 and x2 != y1 and x2 != y2 and y1 != y2) and (x1 in num and x2 in num and y1 in num and y2 in num) and (d1 == (x1+y2) and d2 == (y1+x2)): print(x1, y1) print(x2, y2) quit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2; bool flag; int main() { while (~scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2)) { flag = true; for (int i = 1; i <= 9; i++) for (int j = 1; j <= 9; j++) if (j != i) for (int k = 1; k <= 9; k++) if (k != i && k != j) for (int l = 1; l <= 9; l++) if (l != i && l != j && l != k) { if (i + j == r1 && k + l == r2 && i + k == c1 && j + l == c2 && i + l == d1 && j + k == d2) { flag = false; cout << i << " " << j << endl; cout << k << " " << l << endl; break; } } if (flag) cout << "-1" << endl; } return 0; }
7
CPP
r1,r2 = [int(x) for x in input("").split()] c1,c2 = [int(x) for x in input("").split()] d1,d2 = [int(x) for x in input("").split()] for i in range(1, 9+1): for j in range(1, 9+1): for k in range(1, 9+1): for l in range(1, 9+1): if len(set([i,j,k,l])) != 4: continue if i + j == r1 and k + l == r2 and i + k == c1 and j + l == c2 and i + l == d1 and j + k == d2: print(i, j) print(k, l) exit() print(-1)
7
PYTHON3
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) for i in range(1,10): for j in range(1,10): if i == j: continue for k in range(1,10): if i == k or j == k: continue for l in range(1,10): if i == l or j == l or k == l: continue if i + j == c1 and k + l == c2 and i + k == r1 and j + l == r2 and i + l == d1 and j + k == d2: print(i, k) print(j, l) exit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> int main() { int r1, r2, c1, c2, d1, d2; scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2); for (int i = 1; i < 10; i++) for (int j = 1; j < 10; j++) if (i + j == r1) for (int k = 1; k < 10; k++) if (j + k == d2 && i + k == c1) for (int l = 1; l < 10; l++) if (k + l == r2 && j + l == c2 && i + l == d1 && i != l && j != l && k != l && i != k && j != k && i != j) { printf("%d %d\n%d %d", i, j, k, l); return 0; } puts("-1"); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main(void) { double c1, c2, r1, r2, d1, d2, i, j, k, l; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; l = (r2 - d2 + c2) / 2; i = d1 - l; k = c1 - i; j = d2 - k; if ((i >= 1 && i <= 9) && (j >= 1 && j <= 9) && (k >= 1 && k <= 9) && (l >= 1 && l <= 9) && (i != j) && (i != k) && (i != l) && (j != k) && (j != l) && (k != l)) { cout << (int)i << " " << (int)j << endl; cout << (int)k << " " << (int)l << endl; } else { cout << "-1" << endl; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int p, q, r, s; p = ((d1 + r1 + c1) - (d2 + c2 + r2) / 2) / 3; q = r1 - p; r = c1 - p; s = d1 - p; if (p != q && p != r && p != s && q != r && q != s && r != s) { if ((p > 0 && p < 10) && (q > 0 && q < 10) && (r > 0 && r < 10) && (s > 0 && s < 10)) { if ((p + q == r1) && (r + s == r2) && (p + r == c1) && (q + s == c2) && (p + s == d1) && (q + r == d2)) { cout << p << " " << q << endl << r << " " << s; } else cout << -1; } else cout << -1; } else cout << -1; return 0; }
7
CPP
r1, r2 = map(int, input().split(" ")) c1, c2 = map(int, input().split(" ")) d1, d2 = map(int, input().split(" ")) i,j,k,z=9,9,9,9 while(i>0): j=i-1 while(j>0): k=j-1 while(k>0): z=k-1 while(z>0): q, w, r, e = i, j, k, z for _ in range(4): for _ in range(3): for _ in range(2): if (q + w == r1 and w + e == c2 and e + r == r2 and r + q == c1 and q + e == d1 and w + r == d2 ): print(q, w) print(r, e) exit() r,e=e,r w,r,e=r,e,w q, w, r,e =w,r,e,q z-=1 k-=1 j-=1 i-=1 print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; template <typename T> string toString(T x) { if (x == 0) return "0"; bool negative = x < 0; string res; while (x) { res.push_back('0' + x % 10); x /= 10; } if (negative) res.push_back('-'); reverse(res.begin(), res.end()); return res; } void ioFromFile(string inputFileName, string outputFileName) { ifstream fin(inputFileName); ofstream fout(outputFileName); cin.rdbuf(fin.rdbuf()); cout.rdbuf(fout.rdbuf()); } int read() { int res; scanf("%d", &res); return res; } template <typename T> T gcd(T a, T b) { return a == 0 ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int main() { int r0, r1, c0, c1, d0, d1; cin >> r0 >> r1 >> c0 >> c1 >> d0 >> d1; int res[2][2]; res[0][0] = r0 + c0 - d1; if (res[0][0] % 2 == 1) { cout << -1; return 0; } res[0][0] /= 2; res[0][1] = r0 - res[0][0]; res[1][0] = c0 - res[0][0]; res[1][1] = r1 - res[1][0]; if (res[0][0] + res[0][1] != r0 || res[1][0] + res[1][1] != r1 || res[0][0] + res[1][0] != c0 || res[0][1] + res[1][1] != c1 || res[0][0] + res[1][1] != d0 || res[1][0] + res[0][1] != d1) { cout << -1; return 0; } for (int i = 0; i < 4; i++) { int x = res[i / 2][i % 2]; if (x < 1 || x > 9) { cout << -1; return 0; } for (int j = 0; j < 4; j++) { if (i == j) continue; int y = res[j / 2][j % 2]; if (x == y) { cout << -1; return 0; } } } for (int y = 0; y < 2; y++) { for (int x = 0; x < 2; x++) { cout << res[y][x] << " "; } cout << endl; } return 0; }
7
CPP
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) def f(): for a in range(1,10): for b in range(1,10): for c in range(1,10): for d in range(1,10): if len(set([a,b,c,d]))==4: if r1==a+b and r2==c+d and c1==a+c and c2==b+d and d1==a+d and d2==b+c: return [1,a,b,c,d] return [0] l=f() if l[0]: print(l[1],l[2]) print(l[3],l[4]) else: print(-1)
7
PYTHON3
import itertools sum_to_sockets = [ (0, 1), (2, 3), (0, 2), (1, 3), (0, 3), (1, 2) ] sums = [] for _ in range(3): sums += list(map(int, input().split())) for seq in itertools.permutations(range(1, 10), r=4): if all([seq[sum_to_sockets[i][0]] + seq[sum_to_sockets[i][1]] == sums[i] for i in range(6)]): print(str(seq[0]) + " " + str(seq[1])) print(str(seq[2]) + " " + str(seq[3])) break else: print(-1)
7
PYTHON3
I = lambda: map(int, input().split()) r1, r2 = I() c1, c2 = I() d1, d2 = I() for a in range(1, 10): b, c, d = r1-a, c1-a, d1-a if ( 0<b<=9 and 0<c<=9 and 0<d<=9 and b+d==c2 and c+d==r2 and b+c==d2 and len({a,b,c,d})>3 ): print(a, b) print(c, d) break else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> int main(void) { int r1, r2, c1, c2, d1, d2, i, j, k, l; scanf("%d%d", &r1, &r2); scanf("%d%d", &c1, &c2); scanf("%d%d", &d1, &d2); for (i = 1; i <= 9; i++) for (j = r1 - i; j <= 9; j++) for (k = c1 - i; k <= 9; k++) for (l = d1 - i; l <= 9; l++) { if (j >= 1 && k >= 1 && l >= 1 && (k + j) == d2 && (k + l) == r2 && (i + k) == c1 && (j + l) == c2) { if ((i != j) && (i != k) && (i != l) && (j != k) && (j != l) && (k != l)) { printf("%d %d\n%d %d", i, j, k, l); return 0; } } } printf("-1"); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int i = 1; i <= 9; i++) for (int j = 1; j <= 9; j++) for (int k = 1; k <= 9; k++) for (int l = 1; l <= 9; l++) if (i + k == c1 && j + l == c2 && i + j == r1 && k + l == r2 && i + l == d1 && j + k == d2 && i != j && i != k && i != l && j != k && j != l && k != l) { cout << i << " " << j << endl << k << " " << l << endl; return 0; } cout << "-1" << endl; return 0; }
7
CPP
#include <bits/stdc++.h> int main(void) { int r1, r2; int c1, c2; int d1, d2; int countr1 = 0; int countr2 = 0; int a[100]; int b[100]; int i, j, k; scanf("%d%d", &r1, &r2); getchar(); scanf("%d%d", &c1, &c2); getchar(); scanf("%d%d", &d1, &d2); for (i = 1, j = 0; i <= 9; i++) { if (r1 - i > 9) continue; else { if (r1 - i <= 0) break; a[j] = i; a[j + 1] = r1 - i; j += 2; countr1++; } } for (i = 1, j = 0; i <= 9; i++) { if (r2 - i > 9) continue; else { if (r2 - i <= 0) break; b[j] = i; b[j + 1] = r2 - i; j += 2; countr2++; } } for (i = 0; i < countr1 * 2; i += 2) { for (j = 0; j < countr2 * 2; j += 2) { if (a[i] != b[j] && a[i] != b[j + 1] && a[i + 1] != b[j] && a[i + 1] != b[j + 1] && a[i] != a[i + 1] && b[j] != b[j + 1]) { if (a[i] + b[j] == c1 && a[i + 1] + b[j + 1] == c2 && a[i] + b[j + 1] == d1 && a[i + 1] + b[j] == d2) { printf("%d %d\n", a[i], a[i + 1]); printf("%d %d\n", b[j], b[j + 1]); return 0; } else continue; } else continue; } } printf("%d", -1); return 0; }
7
CPP
def read(): return map(int, input().split()) r1, r2 = read() c1, c2 = read() d1, d2 = read() a11 = (r1 + c1 - d2) // 2 a21 = c1 - a11 a22 = d1 - a11 a12 = r1 - a11 if a11 + a12 == r1 and a21 + a22 == r2 and a11 + a21 == c1 and a12 + a22 == c2\ and a11 + a22 == d1 and a21 + a12 == d2 and 1 <= a11 <= 9 and 1 <= a12 <= 9 and\ 1 <= a21 <= 9 and 1 <= a22 <= 9 and len({a11, a12, a21, a22}) == 4: print(a11, a12) print(a21, a22) else: print(-1)
7
PYTHON3
r=[int(x) for x in input().split()] c=[int(x) for x in input().split()] d=[int(x) for x in input().split()] w=(d[0]-r[1]+c[0])//2 x=r[0]-w y=c[0]-w z=d[0]-w if 1<=w<=9 and 1<=x<=9 and 1<=y<=9 and 1<=z<=9 and w!=x and w!=y and w!=z and x!=y and x!=z and y!=z: print(w,x) print(y,z) else: print(-1)
7
PYTHON3
try: r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) b=(r1-d1+c2) if(b%2==0): b=b//2 a=r1-b c=d2-b d=c2-b if(a>0 and a<10 and b>0 and b<10 and c>0 and c<10 and d<10 and d>0): if(a==b or a==c or a==d or b==c or b==d or c==d ): print("-1") else: if(a+b==r1 and a+c==c1 and a+d==d1 and b+c==d2 and b+d==c2 and c+d==r2): print(a,b) print(c,d) else: print("-1") else: print("-1") else: print("-1") except: pass
7
PYTHON3
#include <bits/stdc++.h> const long long mod = (long long)1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long e, f, g, h, i, j; cin >> e >> f >> g >> h >> i >> j; bool valid = false; for (long long a = 1; a <= 9; a++) { for (long long b = 1; b <= 9; b++) { for (long long c = 1; c <= 9; c++) { for (long long d = 1; d <= 9; d++) { if (a != b and a != c and a != d and b != c and b != d and c != d and a + d == i and b + c == j and a + b == e and c + d == f and a + c == g and b + d == h) { cout << a << " " << b << "\n" << c << " " << d << "\n"; valid = true; break; } } } } } if (valid == false) { cout << -1 << "\n"; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2, n[4], b[4]; cin >> r1 >> r2; cin >> c1 >> c2; cin >> d1 >> d2; n[0] = (d1 + c1 - r2) / 2; b[0] = n[0]; n[1] = (c2 + d2 - r2) / 2; b[1] = n[1]; n[2] = (c1 + d2 - r1) / 2; b[2] = n[2]; n[3] = (c2 + d1 - r1) / 2; b[3] = n[3]; sort(b, b + 4); int m = (unique(b, b + 4) - b); if (m == 4 && n[0] < 10 && n[1] < 10 && n[2] < 10 && n[3] < 10 && n[0] > 0 && n[1] > 0 && n[2] > 0 && n[3] > 0) { cout << n[0] << " " << n[1] << "\n"; cout << n[2] << " " << n[3] << "\n"; } else cout << "-1\n"; return 0; }
7
CPP
import math def invalid(a, b, x): if (a+b==x): return 0 else: return 1 r1 , r2 = input().split() r1 = int(r1) r2 = int(r2) c1, c2 = input().split() c1 = int(c1) c2 = int(c2) e1, e2 = input().split() e1 = int(e1) e2 = int(e2) x = 9 flag = 1 while(x): x -= 1 a1, a2, a3, a4 = 0, 0, 0, 9-x a2 = abs(c2 - a4) if invalid(a2, a4, c2): continue a1 = abs(r1 - a2) if invalid(a1, a2, r1) or invalid(a1, a4, e1): continue a3 = abs(c1 - a1) if invalid(a1, a3, c1) or invalid(a3, a2, e2) or invalid(a3, a4, r2): continue s = set() s.add(a1) s.add(a2) s.add(a3) s.add(a4) s = sorted(s) if len(s) == 4 and s[0] > 0 and s[3] <= 9: print(a1, a2) print(a3, a4) x = 0 flag = 0 if flag: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int a = 1; a <= 9; ++a) { for (int b = 1; b <= 9; ++b) { for (int c = 1; c <= 9; ++c) { for (int d = 1; d <= 9; ++d) { if (a == b or a == c or a == d or b == c or b == d or c == d) continue; if (a + b == r1 && a + d == d1 && a + c == c1 && b + d == c2 && b + c == d2 && d + c == r2) { cout << a << " " << b << endl << c << " " << d << endl; return 0; } } } } } cout << -1 << endl; return 0; }
7
CPP
import math from collections import defaultdict ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) """========main code===============""" t=1 #t=ii() for _ in range(t): a,b=ml() c,d=ml() e,f=ml() flag=0 ans=[] for i in range(1,10): for j in range(1,10): for k in range(1,10): for l in range(1,10): if((i+k==c and i!=k) and (j+l==d and j!=l) and (i+j==a and i!=j) and (k+l==b and k!=l) and (i+l==e and i!=l) and (j+k==f and j!=k) ): flag=1 ans=[[i,j],[k,l]] break if(flag): for i in ans: print(*i) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2; int main() { scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2); for (int i = 1; i <= 9; ++i) for (int j = 1; j <= 9; ++j) for (int ii = 1; ii <= 9; ++ii) for (int jj = 1; jj <= 9; ++jj) { if (i != j && i != ii && i != jj && j != ii && j != jj && ii != jj) if (i + j == r1 && jj + ii == r2 && i + ii == c1 && j + jj == c2 && i + jj == d1 && j + ii == d2) { printf("%d %d\n%d %d", i, j, ii, jj); return 0; } } printf("-1"); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2; cin >> c1 >> c2; cin >> d1 >> d2; int a1, a2, a3, a4; int flag = 0; for (a1 = 1; a1 <= 9; a1++) { for (a2 = 1; a2 <= 9; a2++) { for (a3 = 1; a3 <= 9; a3++) { for (a4 = 1; a4 <= 9; a4++) { if (a1 + a2 == r1 && a3 + a4 == r2 && a1 + a3 == c1 && a2 + a4 == c2 && a1 + a4 == d1 && a2 + a3 == d2 && a1 != a2 && a2 != a3 && a3 != a4 && a1 != a3 && a1 != a4 && a2 != a4) { flag = 1; cout << a1 << " " << a2 << endl; cout << a3 << " " << a4 << endl; break; } } } } } if (!flag) { cout << "-1" << endl; } return 0; }
7
CPP
row = list(map(int, input().strip().split())) col = list(map(int, input().strip().split())) diag = list(map(int, input().strip().split())) (r1, r2) = (row[0], row[1]) (c1, c2) = (col[0], col[1]) (d1, d2) = (diag[0], diag[1]) lst = [[(r1 + c1 - d2) / 2, (d2 + r1 - c1) / 2], [(d2 + c1 - r1) / 2, (2*c2 + c1 - d2 - r1) / 2]] val = True for item in lst: if item[0] not in [1, 2, 3, 4, 5, 6, 7, 8, 9] or item[1] not in [1, 2, 3, 4, 5, 6, 7, 8 , 9] or item[0] == item[1]: val = False break else: item[0] = int(item[0]) item[1] = int(item[1]) if lst[0][0] == lst[1][0] or lst[0][1] == lst[1][1] or lst[0][0] == lst[1][1] or lst[0][1] == lst[1][0] or (r1 + r2) != (c1 + c2): val = False if val: for item in lst: print(item[0], item[1]) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int maxn = 1e5 + 5; int r1, r2, c1, c2, d1, d2; int ans[5][5]; int main() { while (cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2) { int flag = 0; for (int i = 1; i <= 9; i++) { ans[0][0] = i; ans[0][1] = r1 - i; ans[1][0] = c1 - i; ans[1][1] = c2 - ans[0][1]; if (ans[0][0] > 9 || ans[0][1] > 9 || ans[1][0] > 9 || ans[1][1] > 9) continue; if (ans[0][0] <= 0 || ans[0][1] <= 0 || ans[1][0] <= 0 || ans[1][1] <= 0) continue; if (ans[0][0] == ans[1][1] || ans[0][1] == ans[1][0] || ans[0][0] == ans[1][0] || ans[0][0] == ans[0][1] || ans[0][1] == ans[1][1] || ans[1][0] == ans[1][1]) continue; if (ans[0][0] + ans[1][1] == d1 && ans[0][1] + ans[1][0] == d2 && ans[1][0] + ans[1][1] == r2) { printf("%d %d\n%d %d\n", ans[0][0], ans[0][1], ans[1][0], ans[1][1]); flag = 1; break; } } if (!flag) printf("-1\n"); } }
7
CPP
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) d = int((d1-(r1-c2))/2) a = r1+d-c2 b = r1-a c=c1-a if ((c+b==d2)&(a+d==d1) &(a+b==r1) &(c+d==r2) &(a+c==c1)&(b+d==c2) &(a!=b) &(a!=c) & (a!=d) & (b!=c) & (b!=d) &(c!=d) &(0<a<=9) &(0<b<=9)&(0<c<=9)&(0<d<=9)): print(a,b) print(c,d) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2; int main() { cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; vector<int> nums; if (r1 + r2 == c1 + c2 && c1 + c2 == d1 + d2) { int x = (d1 + r1 - c2); int y = (c2 + d2 - r2); int w = (d1 + c2 - r1); int z = (2 * c1 - d1 - r1 + c2); if (x % 2 || y % 2 || z % 2 || w % 2) { cout << -1; return 0; } nums.push_back(x / 2); nums.push_back(y / 2); nums.push_back(z / 2); nums.push_back(w / 2); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (i != j && nums[i] == nums[j]) { cout << -1; return 0; } } } for (int i = 0; i < 4; i++) { if (nums[i] >= 10 || nums[i] <= 0) { cout << -1; return 0; } } cout << x / 2 << ' ' << y / 2 << '\n'; cout << z / 2 << ' ' << w / 2 << '\n'; return 0; } cout << -1; }
7
CPP
r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) y = (d2+(r2-c2))//2 x = d2-y w = r1-x z = d1-w if not 1<=w<=9 or not 1<=x<=9 or not 1<=y<=9 or not 1<=z<=9: print(-1) exit() if w == x or w == y or w == z or x == y or x == z or y == z: print(-1) exit() if w+x+y+z != r1+r2: print(-1) exit() else: print(w,x) print(y,z)
7
PYTHON3
from sys import stdin,stdout i1 = lambda : int(stdin.readline()) iia = lambda : map(int, stdin.readline().split()) isa = lambda: stdin.readline().split() r1, r2 = iia() c1, c2 = iia() d1, d2 = iia() if (c2 + r2 - d2) % 2 == 0: d = (c2 + r2 - d2) // 2 c = r2 - d b = c2 - d a = r1 - b temp = [a, b, c, d] if len(set(temp)) != 4: print(-1) else: for i in temp: if not (i > 0 and i < 10): print(-1) break else: print(a, b) print(c, d) else: print(-1)
7
PYTHON3
rs = input().strip().split(' ') cs = input().strip().split(' ') ds = input().strip().split(' ') r1 = int(rs[0]) r2 = int(rs[1]) c1 = int(cs[0]) c2 = int(cs[1]) d1 = int(ds[0]) d2 = int(ds[1]) if min(r1, r2, c1, c2, d1, d2)==1: print(-1) else: row1 = [] k = 1 while r1-k>0: if k!=r1-k and k<=9 and r1-k<=9: row1.append([k, r1-k]) k+=1 row2 = [] k = 0 while k<len(row1): r21 = c1-row1[k][0] r22 = c2-row1[k][1] if r21>0 and r22>0 and r21<=9 and r22<=9 and r21+r22==r2 and r21+row1[k][1]==d2 and r22+row1[k][0]==d1 and len(set([r22, r21]+row1[k]))==4: row2.append([r21, r22]) k += 1 else: row1.pop(k) if len(row1)>0: print(row1[0][0], row1[0][1]) print(row2[0][0], row2[0][1]) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2, a, b, c, d; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; a = d1 - 1; d = 1; while (a > 0) { b = r1 - a; c = c1 - a; if ((r1 == a + b) && (r2 == c + d) && (c1 == a + c) && (c2 == b + d) && (d2 == b + c) && (a != b) && (a != c) && (a != d) && (b != c) && (b != d) && (c != d) && (a < 10) && (b < 10) && (c < 10) & (d < 10)) break; a--; d++; } if ((a == 0) || (b == 0) || (c == 0) || (d == 0)) { cout << -1 << endl; return 0; } cout << a << " " << b << endl; cout << c << " " << d << endl; return 0; }
7
CPP