solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) flag = 0 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 a + b == r1 and c + d == r2 and a + d == d1 and b + c == d2 and a + c == c1 and b + d == c2 and a != b and a != c and a != d and b != c and b != d and c != d: print(a, b) print(c, d) flag = 1 break if flag: break if flag: break if flag: break else: print(-1) # Fri Oct 16 2020 18:40:37 GMT+0300 (Москва, стандартное время)
7
PYTHON3
def solution(r,c,d): n1=n2=n3=n4=0 for i in range(1,10): n1=i n2=r[0]-i n3=c[0]-i n4=d[0]-i if (n2 in range(1,10)) and (n3 in range(1,10)) and (n4 in range(1,10)) and n1!=n2 and n1!=n3 and n1!=n4 and n2!=n3 and n2!=n4 and n3!=n4: if n3+n4==r[1] and n2+n4==c[1] and n2+n3==d[1]: print("{} {}".format(n1,n2)) print("{} {}".format(n3,n4)) return print(-1) r=list(map(int,input('').split())) c=list(map(int,input('').split())) d=list(map(int,input('').split())) solution(r,c,d)
7
PYTHON3
row1, row2 = map(int, input().split()) col1, col2 = map(int, input().split()) diag1, diag2 = map(int, input().split()) for i in range(1, 10): a = i for j in range(1, 10): b = j for k in range(1, 10): c = k for l in range(1, 10): d = l if a != b and a != c and a != d and b != c and b != d and c != d: if a+b == row1 and c+d == row2 and a+d == diag1 and b+c == diag2 and a+c == col1 and b+d == col2: print(a,b) print(c,d) exit() print('-1')
7
PYTHON3
r1, r2 = map(int,input().split()) c1, c2 = map(int,input().split()) d1, d2 = map(int,input().split()) l1 = [1,2,3,4,5,6,7,8,9] res = 0 for i in range(1, 10): x = i a = r1 - x b = c1 - x c = r2 - b if (x != a and x != b and x != c and a != b and a != c and b != c) and (a in l1 and b in l1 and c in l1 and x in l1) and (d1 == x + c and d2 == a + b and r1 == x + a and r2 == b + c and c1 == x + b and c2 == a + c): print(x, a) print(b, c) break res += 1 if res == 9: print(-1) # Tue Oct 13 2020 23:24:35 GMT+0300 (Москва, стандартное время)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; bool inrange(int y) { return ((y >= 1) && (y <= 9)); } int main() { int r1, r2, c1, c2, d1, d2; bool taken[9] = {false}; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int x = (r1 + r2); int y = (c1 + c2); int z = (d1 + d2); int w; if (x == y && y == z) { if ((r1 + c2 - d1) % 2) { cout << "-1\n"; return 0; } y = (r1 + c2 - d1) / 2; if (!inrange(y)) { cout << "-1\n"; return 0; } if (taken[y - 1]) { cout << "-1\n"; return 0; } else taken[y - 1] = true; x = r1 - y; if (!inrange(x)) { cout << "-1\n"; return 0; } if (taken[x - 1]) { cout << "-1\n"; return 0; } else { taken[x - 1] = true; } w = d2 - y; if (!inrange(w)) { cout << "-1\n"; return 0; } if (taken[w - 1]) { cout << "-1\n"; return 0; } else { taken[w - 1] = true; } z = c2 - y; if (!inrange(z)) { cout << "-1\n"; return 0; } if (taken[z - 1]) { cout << "-1\n"; return 0; } else { taken[z - 1] = true; } cout << x << " " << y << "\n"; cout << w << " " << z << "\n"; } else cout << "-1\n"; return 0; }
7
CPP
r1 , r2 = map(int , input().split( ) ) c1 , c2 = map(int , input().split( ) ) d1 , d2 = map(int , input().split( ) ) ans=0 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 a+b == r1 and c+d==r2 and a+c==c1 and b+d==c2 and a+d==d1 and b+c==d2: check = [a,b,c,d] check = set(check) if len(check)==4: print(a,b) print(c,d) ans = 1 break if ans == 0: 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 ) 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
import sys r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) lst = [] r1l = [] r2l = [] c1l = [] c2l = [] d1l = [] d2l = [] newlist = [] perfectlist = [] for i in range(10): for y in range(10): lst.append([i,y]) for item in lst: if sum(item) == r1: r1l.append(item) if sum(item) == r2: r2l.append(item) if sum(item) == c1: c1l.append(item) if sum(item) == c2: c2l.append(item) if sum(item) == d1: d1l.append(item) if sum(item) == d2: d2l.append(item) for item1 in r1l: for item2 in r2l: if item1[0] + item2[0] == c1 and item1[1] + item2[1] == c2: newlist.append([item1,item2]) for item in newlist: r11,r22 = item if r11[0] + r22[1] == d1 and r11[1] + r22[0] == d2: perfectlist.append([r11,r22]) if perfectlist == []: print(-1) sys.exit() y = perfectlist[0] if y == [] or y[0][0] == y[0][1] or y[0][0] == y[1][0] or y[0][0] == y[1][1] or y[0][1] == y[1][0] or y[0][1] == y[1][1] or y[1][1] == y[1][0] or y[0][0] == 0 or y[0][1] == 0 or y[1][0] == 0 or y[1][1] == 0: print(-1) sys.exit() print(y[0][0],y[0][1]) print(y[1][0],y[1][1])
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2, a = 1, b, c, d; int main() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; while (a <= 9) { b = 1; while (b <= 9) { if (a == b) { b++; continue; } c = 1; while (c <= 9) { if (c == b || c == a) { c++; continue; } d = 1; while (d <= 9) { if (c == d || d == b || d == a) { d++; continue; } if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 && a + d == d1 && b + c == d2) { return cout << a << " " << b << endl << c << " " << d << endl, 0; } d++; } c++; } b++; } a++; } cout << -1 << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2, i; cin >> r1 >> r2; cin >> c1 >> c2; cin >> d1 >> d2; int x1, x2, y1, y2, y3, y4; bool flag = false; for (i = 1; i <= 9; i++) { y1 = i, y2 = r1 - i, y3 = c1 - y1, y4 = c2 - y2, x1 = y1 + y4, x2 = y2 + y3; if (y1 + y2 == r1 and y1 != y2 and y3 + y4 == r2 and y3 != y4 and y1 != y3 and y1 + y3 == c1 and y2 != y4 and y2 + y4 == c2 and y1 != y4 and y1 + y4 == d1 and y2 != y3 and y2 + y3 == d2) { if (y1 >= 1 and y1 <= 9 and y2 >= 1 and y2 <= 9 and y3 >= 1 and y3 <= 9 and y4 >= 1 and y4 <= 9) { flag = true; break; } } } if (flag) { cout << y1 << " " << y2 << "\n"; cout << y3 << " " << y4; } else { cout << -1; } }
7
CPP
#Help Vasilisa the Wise 2 r1,r2 = map(int,input().split()) c1,c2= map(int,input().split()) d1,d2 = map(int,input().split()) arr = [] ;a,b,c,d = 0,0,0,0 arr2 = [1,2,3,4,5,6,7,8,9] for i in range(1,10): arr = [] a = i; arr.append(a) if (r1-a)not in arr and (r1-a) in arr2 : b = r1-a ; arr.append(b) if (c2-b)not in arr and (c2-b) in arr2: d = c2-b ; arr.append(d) if (r2-d not in arr) and r2-d in arr2: c = r2-d ; arr.append(c) if (a+c == c1 and b+d == c2 and a+b == r1 and c+d == r2 and a+d == d1 and b+c == d2): print(a,b) print(c,d) exit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; bool cd = false; 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 k = 1; k <= 9; ++k) { for (int l = 1; l <= 9; ++l) { if (i + j == r1 && k + l == r2 && i + k == c1 && j + l == c2 && i + l == d1 && j + k == d2 && i != j && i != k && i != l && j != k && j != l && k != l) { printf("%d %d\n%d %d", i, j, k, l); cd = true; } } } } } if (!cd) printf("-1\n"); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; scanf("%d %d", &r1, &r2); scanf("%d %d", &c1, &c2); scanf("%d %d", &d1, &d2); int a1 = -1; int a2 = -1; int a3 = -1; int a4 = -1; for (int i = 1; i <= 9; i++) { for (int y = 1; y <= 9; y++) { for (int l = 1; l <= 9; l++) { for (int p = 1; p <= 9; p++) { if (i != y && i != l && i != p && y != l && y != p && l != p) { if (i + y == r1) { if (l + p == r2) { if (i + l == c1) { if (y + p == c2) { if (i + p == d1) { if (y + l == d2) { a1 = i; a2 = y; a3 = l; a4 = p; } } } } } } } } } } } if (a1 != -1) { printf("%d %d\n", a1, a2); printf("%d %d\n", a3, a4); } else { printf("-1\n"); } }
7
CPP
import sys r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) a = (d1 + c1 - r2) // 2 b = (d2 + c2 - r2) // 2 c = (c1 + d2 - r1) // 2 d = (c2 + r2 - d2) // 2 e = [a, b, c, d] if (d1 + c1 - r2) % 2 == 0 and (d2 + c2 - r2) % 2 == 0 and (c1 + d2 - r1) % 2 == 0 and (c2 + r2 - d2) % 2 == 0: if a >= 1 and a <= 9 and b >= 1 and b <= 9 and c >= 1 and c <= 9 and d >= 1 and d <= 9: if a != b and b != c and c != d and a != c and a != d and b != d: print(a, b) print(c, d) sys.exit() print(-1) # Wed Oct 14 2020 15:48:35 GMT+0300 (Москва, стандартное время)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int a[maxn]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int k2 = (d2 + r2 - c2); if (k2 % 2 == 1) { cout << -1 << endl; return 0; } int c = k2 / 2; int a = c1 - c; int b = r1 - a; int d = r2 - c; if (a < 1 || b < 1 || c < 1 || d < 1 || a > 9 || b > 9 || c > 9 || d > 9) { cout << -1 << endl; return 0; } if (a == b || a == c || a == d || b == c || b == d || c == d) { cout << -1 << endl; return 0; } if (a + b != r1 || a + c != c1 || a + d != d1 || b + c != d2 || b + d != c2 || c + d != r2) { cout << -1 << endl; return 0; } cout << a << " " << b << endl; cout << c << " " << d << endl; }
7
CPP
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; vector<int> sums{r1, c1, d1, d2, c2, r2}; for (int c = 1; c < 10; c++) for (int d = 1; d < 10; d++) for (int e = 1; e < 10; e++) for (int f = 1; f < 10; f++) { vector<int> vec{c, d, e, f}; set<int> s(vec.begin(), vec.end()); if (s.size() == 4) { int i = 0; for (int g = 0; g < 4; g++) for (int h = g + 1; h < 4; h++) if (vec[g] + vec[h] != sums[i++]) goto fail; cout << c << ' ' << d << endl << e << ' ' << f << endl; return 0; fail:; } } cout << "-1\n"; return 0; }
7
CPP
r = list(map(int,input().strip().split())) c = list(map(int,input().strip().split())) d = list(map(int,input().strip().split())) a11 = (r[0]+c[0]-d[1])/2 a12= r[0]-a11 a21 = c[0]-a11 a22 = d[0]-a11 if (a11 != a12 and a11 != a21 and a11 != a22 and a12 != a21 and a12 != a22 and a21 != a22 and a11 >= 1 and a11 <= 9 and a12 >= 1 and a12 <= 9 and a21 >= 1 and a21 <= 9 and a22 >= 1 and a22 <= 9 and a21 + a22 == r[1] and a12 + a22 == c[1] and a12 + a21 == d[1]): print("{} {}\n".format(int(a11),int(a12))) print("{} {}\n".format(int(a21),int(a22))) else: print("-1")
7
PYTHON3
"""609C""" # import math def main(): r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) # r1c1 = 0 for i in range(1,10): r1c1 = i r2c1 = c1 - r1c1 r1c2 = r1 - r1c1 r2c2 = d1 - r1c1 if r2c1<=0 or r2c1>=10: continue if r1c2<=0 or r1c2>=10: continue if r2c2<=0 or r2c2>=10: continue if r2c1+r2c2 == r2 and d2==r1c2+r2c1 and c2==r2c2+r1c2: if len(set([r1c1,r2c2,r1c2,r2c1]))==4: print(r1c1,r1c2) print(r2c1,r2c2) return print("-1") return main() # t= int(input()) # while t: # main() # t-=1
7
PYTHON3
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) if r1+r2==c1+c2==d1+d2: if r1==c1 or r1==c2 or r1==d1 or r1==d2 or r2==c1 or r2==c2 or r2==d1 or r2==d2 or c1==d1 or c1==d2 or c2==d1 or c2==d2: print(-1) else: if (d1+r1-c2)%2==0 and (c1+r1-d2)%2==0: if (d1+r1-c2)==(c1+r1-d2): if (d1+r1-c2)//2 ==(d1+r1-c2)/2>0: a=(d1+r1-c2)//2 if 0<a<10 and 0<r1-a<10 and 0<c1-a<10 and 0<d1-a<10: print(a,r1-a) print(c1-a,d1-a) else: print(-1) else: print(-1) else: print(-1) else: print(-1) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int r1, r2, d1, d2, c1, c2, a, b, c, d; cin >> r1 >> r2; cin >> d1 >> d2; cin >> c1 >> c2; a = (c1 + d1 - r2) / 2; b = c1 - a; c = r1 - a; d = r2 - b; if (a != b && a != c && a != d && b != c && b != d && c != d && a && b && c && d && a <= 9 && b <= 9 && c <= 9 && d <= 9) { cout << a << " " << c << endl; cout << d << " " << b; } else cout << "-1"; return 0; }
7
CPP
r1,r2 = input().split() c1,c2 = input().split() d1,d2 = input().split() r1 = int(r1) r2 = int(r2) c1 = int(c1) c2 = int(c2) d1 = int(d1) d2 = int(d2) """ print(r1) print(r2) print(c1) print(c2) print(d1) print(d2) """ for block1 in range(1,10): for block2 in range(1,10): for block3 in range(1,10): for block4 in range(1,10): #print(str(block1) + " "+str(block2)+" "+str(block3) + " "+str(block4)) if block1+block2 != r1: continue if block3+block4 != r2: continue if block1+block3 != c1: continue if block2+block4 != c2: continue if block1+block4 != d1: continue if block2+block3 != d2: continue if block1 == block2 or block1 == block3 or block1 == block4 or block2 == block3 or block2 == block4 or block3 == block4: continue print(str(block1) + " "+str(block2)) print(str(block3) + " "+str(block4)) exit(0) print(-1)
7
PYTHON3
r1, r2 = list(map(int, input().split())) c1, c2 = list(map(int, input().split())) d1, d2 = list(map(int, input().split())) a = (c1-d2+r1)/2 b = r1-a c = c1-a d = d1-a if a+c==c1 and a+b==r1 and a+d==d1 and b+d==c2 and b+c==d2 and c+d==r2 and\ a in range(1,10) and b in range(1,10) and c in range(1,10) and d in range(1,10) and\ a!=b and a!=c and a!=d and b!=c and b!=d and c!=d: print(int(a),int(b)) print(int(c),int(d)) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; bool compare(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } int main() { float r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; float a = c1 / 2 + (d1 + r1 - d2 - r2) / 4; float c = c1 / 2 - (d1 + r1 - d2 - r2) / 4; float b = c2 / 2 + (r1 + d2 - r2 - d1) / 4; float d = c2 / 2 - (r1 + d2 - r2 - d1) / 4; if (a > 9 || a < 1) { cout << -1; return 0; } if (b > 9 || b < 1) { cout << -1; return 0; } if (c > 9 || c < 1) { cout << -1; return 0; } if (d > 9 || d < 1) { cout << -1; return 0; } if (a + b != r1) { cout << -1; return 0; } if (d + c != r2) { cout << -1; return 0; } if (a + c != c1) { cout << -1; return 0; } if (d + b != c2) { cout << -1; return 0; } if (a + d != d1) { cout << -1; return 0; } if (c + b != d2) { cout << -1; return 0; } if (a == b || a == c || a == d || b == c || b == d || c == d) { cout << -1; return 0; } cout << (int)a << " " << (int)b << endl << (int)c << " " << (int)d; return 0; }
7
CPP
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) gems = [i for i in range(1, 10)] required_sum = r1 + r2 + c1 + c2 + d1 + d2 if required_sum % 3 == 0: sum_to = required_sum / 3 for i in range(1, 10): a = r1 - i b = c1 - i c = r2 - b if a in gems and b in gems and c in gems and len({i, a, b, c}) == 4: if i + c == d1 and a + b == d2 and i + a == r1 and b + c == r2 and i + b == c1 and a + c == c2: print(i, a) print(b, c) exit() print(-1) else: print(-1)
7
PYTHON3
r1, r2 = list(map(int, input().split())) c1, c2 = list(map(int, input().split())) d1, d2 = list(map(int, input().split())) l1 = [] l2 = [] for i in range(1, r1 + 1): for j in range(1, r1 + 1): if i + j == r1 and i < 10 and j < 10: l1.append([j, i]) for i in range(1, r2 + 1): for j in range(1, r2 + 1): if i + j == r2 and i < 10 and j < 10: l2.append([j, i]) found = False for i in l1: for j in l2: r1c1 = i[0] r1c2 = i[1] r2c1 = j[0] r2c2 = j[1] if ((r1c1 + r2c1) == c1) and ((r1c2 + r2c2) == c2) and ((r1c1 + r1c2) == r1) and ((r2c1 + r2c2) == r2) and ((r1c1 + r2c2) == d1) and ((r2c1 + r1c2) == d2) and r1c1 != r1c2 and r1c1 != r2c1 and r1c1 != r2c2 and r1c2 != r2c1 and r1c2 != r2c2 and r2c1 != r2c2: print('{} {}'.format(r1c1, r1c2)) print('{} {}'.format(r2c1, r2c2)) exit() print(-1)
7
PYTHON3
# Problem Link: http://codeforces.com/problemset/problem/143/A # Author: Raunak Sett import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ # do magic here r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) used = [False for i in range(9)] board = [0, 0, 0, 0] def isSafe(board): row1 = board[0] + board[1] <= r1 row2 = board[2] + board[3] <= r2 col1 = board[0] + board[2] <= c1 col2 = board[1] + board[3] <= c2 diag1 = board[0] + board[3] <= d1 diag2 = board[2] + board[1] <= d2 return row1 and row2 and col1 and col2 and diag1 and diag2 def isSolved(board): row1 = board[0] + board[1] == r1 row2 = board[2] + board[3] == r2 col1 = board[0] + board[2] == c1 col2 = board[1] + board[3] == c2 diag1 = board[0] + board[3] == d1 diag2 = board[2] + board[1] == d2 return row1 and row2 and col1 and col2 and diag1 and diag2 def solve(board, itr): if itr == 4: return isSolved(board) for i in range(1, 10): if not used[i-1] and isSafe(board): used[i-1] = True board[itr] = i if (solve(board, itr + 1)): return True used[i-1] = False board[itr] = 0 return False result = solve(board, 0) if (result): print(str(board[0]) + " " + str(board[1])) print(str(board[2]) + " " + str(board[3])) else: print("-1")
7
PYTHON3
#include <bits/stdc++.h> int main() { int r1, r2, c1, c2, d1, d2, x1, x2, x3, x4; scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2); x1 = (d1 + r1 - c2) / 2; x2 = (c2 + r1 - d1) / 2; x3 = (2 * r2 + r1 - d1 - c2) / 2; x4 = (d1 + c2 - r1) / 2; bool ind = 1; if (x1 == x2 || x1 == x3 || x1 == x4 || x2 == x3 || x2 == x4 || x3 == x4) { ind = 0; } if (x1 > 9 || x1 < 1 || x2 > 9 || x2 < 1 || x3 > 9 || x3 < 1 || x4 > 9 || x4 < 1) { ind = 0; } if (c2 + c1 != r1 + r2 || d1 + d2 != r1 + r2) { ind = 0; } if (ind) { printf("%d %d\n%d %d\n", x1, x2, x3, x4); } else { printf("%d\n", -1); } return 0; }
7
CPP
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) f=False mn=set() for a11 in range(1,10): for a12 in range(1,10): for a21 in range(1,10): for a22 in range(1,10): mn={a11,a12,a21,a22} if(a11+a12 == r1)and(a21+a22==r2)and(a11+a21 == c1)and(a12+a22==c2)and(a11+a22==d1)and(a12+a21==d2)and(len(mn)==4): print(a11,a12) print(a21,a22) f=True break if not f: print(-1) # Sun Oct 11 2020 14:04:26 GMT+0300 (Москва, стандартное время)
7
PYTHON3
def question1(): r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) for i in range(1,10): a = [0 for i in range(4)] a[0] = i a[1] = r1 - i a[2] = c1 - i a[3] = r2 - a[2] if len(list(set(a))) == 4 and a[1] > 0 and a[1] < 10 and a[2]>0 and a[3]>0 and a[2] < 10 and a[3] < 10: if a[0] + a[1] == r1 and a[2] + a[3] == r2 and a[0] + a[2] == c1 and a[1] + a[3] == c2 and a[0] + a[3] == d1 and a[1] + a[2] == d2: return [1,a] return [-1] # remained_test_cases = int(input()) remained_test_cases = 1 while remained_test_cases > 0: ans = (question1()) if ans[0] == -1: print(-1) else: print(ans[1][0],ans[1][1]) print(ans[1][2],ans[1][3]) remained_test_cases -= 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 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; } } flag = 0; if (flag == 0) cout << "-1"; return 0; }
7
CPP
a,b=map(int,input().split()) c,d=map(int,input().split()) e,f=map(int,input().split()) for i1 in range(1,10): for i2 in range(1,10): for i3 in range(1,10): for i4 in range(1,10): if i1!=i2 and i1!=i3 and i1!=i4 and i2!=i3 and i2!=i4 and i3!=i4: if i1+i2==a and i3+i4==b and i1+i3==c and i2+i4==d and i1+i4==e and i2+i3==f: print(i1,i2) print(i3,i4) exit(0) print(-1)
7
PYTHON3
r,r2 = [int(x) for x in input().split()] c,c2 = [int(x) for x in input().split()] d,d2 = [int(x) for x in input().split()] res = [] for x in range(1,10): for y in range(1,10): for z in range(1,10): for k in range(1,10): if x!=y and x!=z and x!=k and y!=z and y!=k and k!=z and x+y==r and z+k==r2 and x+z==c and y+k==c2 and x+k==d and y+z==d2: res = [x,y,z,k] break if res: print(res[0],res[1]) print(res[2],res[3]) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int notIdentical(int a, int b, int c, int d) { if (a != b && b != c && c != d && d != a && a != c && b != d) return 1; return 0; } int main() { int r1, r2, c1, c2, d1, d2, i; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (i = 1; i <= 9; ++i) { if (r1 - i >= 1 && r1 - i <= 9) { if (c1 - i >= 1 && c1 - i <= 9) { if (r2 - c1 + i >= 1 && r2 - c1 + i <= 9) { if (notIdentical(i, r1 - i, c1 - i, r2 - c1 + i)) { if (2 * i + r2 - c1 == d1 && r1 + c1 - i * 2 == d2) { cout << i << " " << r1 - i << endl << c1 - i << " " << r2 - c1 + i; return 0; } } } } } } cout << -1; return 0; }
7
CPP
def main(): r1 = r2 = c1 = c2 = d1 = d2 = None h1 = h2 = h3 = h4 = 0 for i in range(3): inp = list(input().split()) if i == 0: r1 = int(inp[0]) r2 = int(inp[1]) elif i == 1: c1 = int(inp[0]) c2 = int(inp[1]) else: d1 = int(inp[0]) d2 = int(inp[1]) for i in range(1, 10, 1): h1 = i h2 = abs(r1 - h1) h3 = abs(c1 - h1) h4 = abs(c2 - h2) if h1 <= 9 and h2 <= 9 and h3 <= 9 and h4 <= 9 and h1 != h2 and h1 != h3 and h1 != h4 and h2 != h3 and h2 != h4 and h3 != h4 and h1 != 0 and h2 != 0 and h3 != 0 and h4 != 0 and h1+h4 == d1 and h2+h3 == d2 and h1+h2 == r1 and h3+h4 == r2 and h1+h3 == c1 and h2+h4 == c2: print(h1, h2) print(h3, h4) return print(-1) if __name__ == '__main__' : main()
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; 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) { if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 && a + d == d1 && b + c == d2) { cout << a << " " << b << endl; cout << c << " " << d << endl; return 0; } } } cout << "-1\n"; return 0; }
7
CPP
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) lis = [] true = False for i in range(1, 10): pa1 = 0 pa2 = 0 pb1 = 0 lis.clear() lis.append(i) pa1 = d1 - i pa2 = c2 - i pb1 = r2 - i if not pa1 in lis and pa1 > 0 and pa1 < 10: lis.append(pa1) if not pa2 in lis and pa2 > 0 and pa2 < 10: lis.append(pa2) if not pb1 in lis and pb1 > 0 and pb1 < 10: if pa2 + pb1 == d2 and pa1 + pb1 == c1 and pa1 + pa2 == r1: print(pa1, pa2) print(pb1, i) true = True break if not true: print(-1) # Wed Oct 14 2020 17:50:40 GMT+0300 (Москва, стандартное время)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { 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) { if (i == j) continue; for (int k = 1; k <= 9; ++k) { if (k == i || k == j) continue; for (int l = 1; l <= 9; ++l) { if (l == i || l == j || l == k) continue; if (i + j == r1 && k + l == r2 && i + k == c1 && j + l == c2 && i + l == d1 && j + k == d2) { cout << i << " " << j << endl << k << " " << l << endl; return 0; } } } } } cout << -1; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2, x1, x2, y1, y2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; x1 = (r1 + d1 - c2) / 2; x2 = (r1 + d2 - c1) / 2; y1 = (r2 + d2 - c2) / 2; y2 = (r2 + d1 - c1) / 2; if (x1 + x2 == r1 && y1 + y2 == r2 && c1 == x1 + y1 && c2 == x2 + y2 && d1 == x1 + y2 && d2 == x2 + y1 && x1 != x2 && x1 != y1 && x1 != y2 && x2 != y1 && x2 != y2 && y1 != y2 && x1 < 10 && x2 < 10 && y1 < 10 && y2 < 10 && x1 > 0 && x2 > 0 && y1 > 0 && y2 > 0) { cout << x1 << " " << x2 << endl; cout << y1 << " " << y2 << endl; } else cout << -1 << endl; return 0; }
7
CPP
# python 3 """ """ from operator import itemgetter def help_vasilisa_the_wise_2(r_1_int, r_2_int, c_1_int, c_2_int, d_1_int, d_2_int) -> None: solution = True quotient, remainder = divmod(r_1 + c_1 - d_2, 2) if remainder == 0: x_1 = quotient else: solution = False quotient, remainder = divmod(r_1 + c_2 - d_1, 2) if remainder == 0: x_2 = quotient else: solution = False quotient, remainder = divmod(r_2 + c_1 - d_1, 2) if remainder == 0: x_3 = quotient else: solution = False quotient, remainder = divmod(r_2 + c_2 - d_2, 2) if remainder == 0: x_4 = quotient else: solution = False if solution and x_1 != x_2 and x_1 != x_3 and x_1 != x_4 and x_2 != x_3 and x_2 != x_4 and x_3 != x_4 \ and 1 <= x_1 <=9 and 1 <= x_2 <= 9 and 1 <= x_3 <= 9 and 1 <= x_4 <= 9: solution = True else: solution = False if solution: print(x_1, x_2) print(x_3, x_4) else: print(-1) if __name__ == "__main__": """ Inside of this is the test. Outside is the API """ r_1, r_2 = list(map(int, input().split())) c_1, c_2 = list(map(int, input().split())) d_1, d_2 = list(map(int, input().split())) help_vasilisa_the_wise_2(r_1, r_2, c_1, c_2, d_1, d_2)
7
PYTHON3
x = [] for i in range(3): x += [int(x) for x in input().split()] a = (x[0]+x[2]-x[5])//2 c = x[2] - a b = x[0] - a d = x[3] - b if (a+d==x[4]) and (c+d==x[1]) and (a!=b) and (a!=c) and (a!=d) and (b!=c) and (b!=d) and (c!=d) and (9>=a>=1) and (9>=b>=1) and (9>=c>=1) and (9>=d>=1): print(a,b) print(c,d) else: print(-1)
7
PYTHON3
r1, r2 = map(int,input().split()) c1, c2 = map(int,input().split()) d1, d2 = map(int,input().split()) for x1 in range(1, 10): for x2 in range(1, 10): for y1 in range(1, 10): for y2 in range(1, 10): k = set([x1,x2,y1,y2]) if len(k) != 4: continue if r1 != x1 + x2: continue if r2 != y1 + y2: continue if c1 != x1 + y1: continue if c2 != x2 + y2: continue if d1 != x1 + y2: continue if d2 != y1 + x2: continue print(x1,x2) print(y1,y2) exit() print(-1) # Thu Oct 08 2020 20:55:27 GMT+0300 (Москва, стандартное время)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2; int a[2][2]; bool solve() { if (a[0][0] + a[0][1] != r1) return false; if (a[1][0] + a[1][1] != r2) return false; if (a[0][0] + a[1][0] != c1) return false; if (a[0][1] + a[1][1] != c2) return false; if (a[0][0] + a[1][1] != d1) return false; if (a[0][1] + a[1][0] != d2) return false; return true; } int main() { bool flag = 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 k = 1; k <= 9; k++) { if (k == i || k == j) continue; for (int l = 1; l <= 9; l++) { if (l == i || l == j || l == k) continue; a[0][0] = i; a[0][1] = j; a[1][0] = k; a[1][1] = l; if (solve()) { flag = true; break; } } if (flag) break; } if (flag) break; } if (flag) break; } if (flag) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { cout << a[i][j] << " "; } cout << endl; } } else { cout << -1 << endl; } 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 i,j,k,l in permutations(range(1,10),4): if i+j == r1 and k+l == r2 and i+l == c1 and j+k == c2 and i+k == d1 and l+j == d2: print(i,j) print(l,k) quit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2; bool dfs(vector<int>& a) { bool ans = false; if (a.size() == 4) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { if (i == j) continue; if (a[i] == a[j]) return false; } } int i = a[0]; int j = a[1]; int s = a[2]; int t = a[3]; if (i + j == r1 && s + t == r2 && i + s == c1 && j + t == c2 && i + t == d1 && j + s == d2) { cout << i << " " << j << endl; cout << s << " " << t << endl; return true; } } else { for (int i = 1; i <= 9; ++i) { a.push_back(i); ans = dfs(a); if (ans) return true; a.pop_back(); } } return ans; } int main() { while (cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2) { vector<int> a; bool find = dfs(a); if (!find) { cout << -1 << endl; } } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { long c1, c2, r1, r2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; set<long> st; long t = 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 + k == c1 and j + l == c2 and i + j == r1 and k + l == r2 and i + l == d1 and j + k == d2 and (i != j and i != l and i != k)) { t = 1; st.insert(i); st.insert(j); st.insert(k); st.insert(l); if (st.size() == 4) { cout << i << " " << j << endl; cout << k << " " << l << endl; return 0; } else { cout << -1 << endl; return 0; } } } } } } if (t == 0) cout << -1 << endl; return 0; }
7
CPP
def check (p,q,r,s): if 0<int(p)<=9 and 0<int(q)<=9 and 0<int(r)<=9 and 0<int(s)<=9: return True r1,r2 = map(int,input().split()) c1,c2 = map(int,input().split()) d1,d2 = map(int,input().split()) for i in range(1,r1+1): l1 = [] l2 = [] l1.append(i) l1.append(r1-i) l2.append(c1-i) l2.append(c2-l1[1]) if len(set(l1+l2))==4 and check(l1[0],l1[1],l2[0],l2[1])==True: if sum(l2)==r2 and (l1[0]+l2[1])==d1 and (l2[0]+l1[1])==d2: print(*l1) print(*l2) exit() else: continue print('-1')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 100010; char s[N]; int t[N]; int main() { int r1, r2, c1, c2, d1, d2; scanf("%d%d%d%d%d%d", &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 != 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; if (a == b || b == c || c == d) continue; if (a == c || b == d) continue; if (a == d) continue; printf("%d %d\n%d %d\n", a, b, c, d); scanf(" "); exit(0); } puts("-1"); scanf(" "); }
7
CPP
# Codeforces - Help Vasilisa the Wise 2 # https://codeforces.com/contest/143/problem/A # # Author: eloyhz # Date: Sep/02/2020 # if __name__ == '__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()] found = False for x1 in range(1, 10): for x2 in range(1, 10): if x1 == x2: continue for x3 in range(1, 10): if x1 == x3 or x2 == x3: continue for x4 in range(1, 10): if x1 == x4 or x2 == x4 or x3 == x4: continue if x1 + x2 == r1 and x3 + x4 == r2 \ and x1 + x3 == c1 and x2 + x4 == c2 \ and x1 + x4 == d1 and x2 + x3 == d2: found = True break if found: break if found: break if found: break if not found: print(-1) else: print(x1, x2) print(x3, x4)
7
PYTHON3
def f(ll): for g0 in range(1,10): g1 = ll[0][0]-g0 #r1 if g1<1 or g1>9 or g1==g0: continue g2 = ll[1][0]-g0 #c1 if g2<1 or g2>9 or g2==g0: continue g3 = ll[2][0]-g0 #d1 if g3<1 or g3>9 or g3==g0: continue if g1==g2 or g2==g3 or g1==g3: continue if g2+g3 != ll[0][1]: #r2 continue if g1+g3 != ll[1][1]: #c2 continue if g1+g2 != ll[2][1]: #d3 continue return [[g0,g1],[g2,g3]] return [[-1]] ll = [list(map(int,input().split())) for _ in range(3)] [print(*r) for r in f(ll)]
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 a11 = (r1 + c1 - d2) / 2; int a12 = r1 - a11; int a21 = c1 - a11; int a22 = d1 - a11; if (a11 != a12 && a11 != a21 && a11 != a22 && a12 != a21 && a12 != a22 && a21 != a22 && 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
r1, r2 = list(map(int, input().split())) c1, c2 = list(map(int, input().split())) d1, d2 = list(map(int, input().split())) x = [0] * 4; y = []; f = True x[2] = ((c2+d1)-r1) // 2 x[3] = r2 - x[2] x[1] = c1 - x[3] x[0] = c2 - x[2] for i in x: if i not in y: y.append(i) for i in x: if i < 1 or i > 9: f = False if len(y) != 4 or f is False: print(-1) else: print(str(x[1]) + " " + str(x[0]) + '\n' + str(x[3]) + " " + str(x[2]))
7
PYTHON3
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 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
#include <bits/stdc++.h> using namespace std; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; bool flag = true; int A, B, C, D; if ((r1 - c2 + d1) % 2 == 0) { A = (r1 - c2 + d1) / 2; D = (d1 - r1 + c2) / 2; } else { flag = false; } if ((c2 - r2 + d2) % 2 == 0) { B = (c2 - r2 + d2) / 2; C = (d2 - c2 + r2) / 2; } else { flag = false; } if (flag && (0 < A && A < 10 && 0 < B && B < 10 && 0 < C && C < 10 && 0 < D && D < 10) && !(A == B || B == C || C == D || A == D || A == C || B == D) && ((A + C) == c1 && (B + D) == c2 && (A + B) == r1 && (C + D) == r2 && (A + D) == d1 && (B + C) == d2)) { cout << A << " " << B << endl; cout << C << " " << D << endl; } else { cout << -1 << endl; } return 0; }
7
CPP
import sys import math r1, r2 = [int(x) for x in (sys.stdin.readline()).split()] c1, c2 = [int(x) for x in (sys.stdin.readline()).split()] d1, d2 = [int(x) for x in (sys.stdin.readline()).split()] for i in range(1, 10): a1 = i a2 = r1 - i a3 = c1 - i a4 = d1 - i if(a1 > 0 and a1 < 10 and a2 > 0 and a2 < 10 and a3 > 0 and a3 < 10 and a4 > 0 and a4 < 10 and a1 != a2 and a1 != a3 and a1 != a4 and a2 != a3 and a2 != a4 and a3 != a4 and d2 == a2 + a3 and r2 == a3 + a4 and c2 == a2 + a4): print(str(a1) + " " + str(a2)) print(str(a3) + " " + str(a4)) exit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long fx[] = {1, -1, 0, 0}; long long fy[] = {0, 0, 1, -1}; bool isprime(int n) { int i; if (n == 1) return false; else if (n == 2) return true; for (i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } void SieveOE(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++) if (prime[p]) cout << p << " "; } void dtb(int n) { if (n <= 1) { printf("%d", n); } else { dtb(n / 2); printf("%d", n % 2); } } int btd(int n) { int num = n, dec_value = 0, base = 1; int temp = num; while (temp) { int last_digit = temp % 10; temp = temp / 10; dec_value += last_digit * base; base = base * 2; } return dec_value; } void printDivisors(int n) { for (int i = 1; i <= n; i++) if (n % i == 0) cout << i << " "; } int smallestDivisor(long long n) { if (n % 2 == 0) return 2; for (long long i = 3; i * i <= n; i += 2) { if (n % i == 0) return i; } return n; } int main() { ios::sync_with_stdio(false); cin.tie(0); ; long long r1, r2, c1, c2, d1, d2, a, b, c, d; 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 and a != c and a != d and b != c and b != d and c != d) { if (a + b == r1 and c + d == r2 and a + d == d1 and b + c == d2 and a + c == c1 and b + d == c2) { cout << a << " " << b << endl; cout << c << " " << d << endl; return 0; } } } } } } cout << -1 << endl; }
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(a==b): continue for c in range(1,10): if(a==c or b==c): continue for d in range(1,10): if(a==d or b==d or c==d): continue chk1 = a+d==d1 and b+c==d2 chk2 = a+b==r1 and c+d==r2 chk3 = a+c==c1 and b+d==c2 if(chk1 and chk2 and chk3): print(a,b) print(c,d) exit() print(-1)
7
PYTHON3
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()] a1=(r1+c1-d2)//2 a2=r1-a1 a3=c1-a1 a4=r2-a3 if a1>0 and a2>0 and a3>0 and a4>0 and a1!=a2 and a1!=a3 and a1!=a4 and a2!=a3 and a2!=a4 and a3!=a4 and a1<10 and a2<10 and a3<10 and a4<10: if a1+a2==r1 and a1+a3==c1 and a3+a4==r2 and a2+a4==c2 and a1+a4==d1 and a2+a3==d2: print(a1,a2) print(a3,a4) 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()) def prog(): for a1 in range(1,10): for a2 in range(1, 10): for b1 in range(1 ,10): for b2 in range(1 ,10): if (not (a1 == b1 or a1 == a2 or a1 == b2 or b1 == b2 or b1 == a2 or a2 == b2)) and \ r1 == a1 + a2 and r2 == b1 + b2 and c1 == a1 + b1 \ and c2 == a2 + b2 and d1 == a1 + b2 and d2 == a2 + b1: print(a1, a2) print(b1, b2) return print(-1) prog()
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 a11, a12, a21, a22; a11 = (r1 + c1 - d2) / 2; a21 = c1 - a11; a12 = r1 - a11; a22 = r2 - a21; if (a11 != a22 && a11 != a12 && a11 != a21 && a12 != a21 && a12 != a22 && a21 != a22 && d2 == a21 + a12 && c2 == a12 + a22 && r2 == a21 + a22 && a11 > 0 && a11 <= 9 && a12 > 0 && a12 <= 9 && a21 > 0 && a21 <= 9 && a22 > 0 && a22 <= 9) { cout << a11 << " " << a12 << endl; cout << a21 << " " << a22 << endl; } else { cout << "-1" << endl; } }
7
CPP
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2; int A[4]; int main() { 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 != j && i != k && i != l && j != k && j != l && k != l) { if (i + j == r1 && i + k == c1 && i + l == d1 && j + k == d2 && j + l == c2 && k + l == r2) { cout << i << " " << j << "\n" << k << " " << l; 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; 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 == 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) { cout << a << " " << b << endl << c << " " << d << endl; return 0; } } cout << -1 << endl; return 0; }
7
CPP
from sys import stdin,stdout import math from collections import Counter,deque L=lambda:list(map(int, stdin.readline().strip().split())) M=lambda:map(int, stdin.readline().strip().split()) I=lambda:int(stdin.readline().strip()) IN=lambda:stdin.readline().strip() C=lambda:stdin.readline().strip().split() mod=1000000007 #Keymax = max(Tv, key=Tv.get) def s(a):print(" ".join(list(map(str,a)))) #______________________-------------------------------_____________________# #I_am_pavan def solve(): r1,r2=M();d1,d2=M();c1,c2=M() a=(c1+d1-r2)//2;b=c1-a;c=r1-a;d=r2-b if a!=b and a!=c and a!=d and b!=c and b!=d and c!=d and 1<=a<=9 and 1<=b<=9 and 1<=c<=9 and 1<=d<=9: print(a,c);print(d,b) else:print(-1) for i in range(1): solve()
7
PYTHON3
def readln(): return tuple(map(int, input().split())) r = readln() c = readln() d = readln() ans = [-1, -1, -1, -1] for i in range(1, 10): for j in range(1, 10): for k in range(1, 10): for m in range(1, 10): if len(set([i, j, k, m])) == 4 and r == (i + j, k + m) and c == (i + k, j + m) and d == (i + m, j + k): ans = [i, j, k, m] if ans[0] == -1: print(-1) else: print(ans[0], ans[1]) print(ans[2], ans[3])
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 < 10; i++) for (int j = 1; j < 10; j++) for (int k = 1; k < 10; k++) for (int z = 1; z < 10; z++) { if (i == j || i == k || i == z || j == k || j == z || k == z) continue; if (i + j == r1 && k + z == r2 && i + k == c1 && j + z == c2 && i + z == d1 && j + k == d2) { cout << i << " " << j << endl << k << " " << z; return 0; } } cout << -1; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { set<int> s; int r1, r2, c1, c2, d1, d2, a1, a2, a3, a4; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (int i = 1; i <= 20; i++) { for (int j = 1; j <= 20; j++) { a1 = i; a2 = j; if (a1 + a2 == r1) { a3 = c1 - a1; a4 = c2 - a2; if (a1 + a4 == d1 && a2 + a3 == d2 && a3 + a4 == r2) { if (a1 > 9 || a2 > 9 || a3 > 9 || a4 > 9 || a1 < 1 || a2 < 1 || a3 < 1 || a4 < 1) continue; s.insert(a1); s.insert(a2); s.insert(a3); s.insert(a4); if (s.size() == 4) { cout << a1 << " " << a2 << endl << a3 << " " << a4; 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()) w = (d1 - r1 + c2) // 2 z = r2 - w x = d1 - w y = c2 - w for i in [w, z, x, y]: if i < 1 or i > 9: print(-1) exit() if w == z or x == y or x == w or y == z or y == w or x == z : print(-1) exit() elif x != r1 - y or z != c1 - x or y != d2 - z: print(-1) exit() print(x, y) print(z, w)
7
PYTHON3
__author__ = 'asmn' r1,r2=tuple(map(int,input().split())) c1,c2=tuple(map(int,input().split())) d1,d2=tuple(map(int,input().split())) for a11 in range(1,10): a12=r1-a11 a21=c1-a11 a22=c2-a12 if a21+a22==r2 and a11+a22==d1 and a12+a21==d2 and 1<=a12<=9 and 1<=a21<=9 and 1<=a22<=9 and a12 !=a11 and a21!=a11 and a21!=a12 and a22 != a11 and a22!=a12 and a22!=a21: print('%d %d\n%d %d'%(a11,a12,a21,a22)) break else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int c1, c2, d1, d2, r1, r2, i, j, k, l; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (i = 1; i < 10; i++) { j = r1 - i; k = c1 - i; l = d1 - i; if (i != j && i != k && i != l && j != k && j != l && k != l && j < 10 && k < 10 && l < 10 && j > 0 && k > 0 && l > 0) { if (c2 == j + l && r2 == k + l && d2 == k + j) { cout << i << " " << j << "\n" << k << " " << l; 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()) x = (c1 + r1 - d2) / 2 if x != int(x): print(-1) else: a = r1 - x b = c1 - x c = d1 - x if ((x == a) or (x == b) or (x == c) or (a == b) or (a == c) or (b == c)): print(-1) elif(x < 1 or x > 9 or a < 1 or a > 9 or b < 1 or b > 9 or c < 1 or c > 9): print(-1) elif b + c != r2 or a + c != c2 or a + b != d2: print(-1) else: print(str(int(x)) + " " + str(int(a))) print(str(int(b)) + " " + str(int(c)))
7
PYTHON3
from itertools import combinations, permutations 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 x, y, z, w in combinations(range(1, 10), 4): for x, y, z, w in permutations([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): print(x, y) print(z, w) break else: continue break else: print(-1)
7
PYTHON3
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) ans = [] 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 a + b == r1 and c + d == r2 and a + c == c1 and b + d == c2 and a + d == d1 and b + c == d2: ans.append([a, b, c, d]) for i in range(len(ans)): if len(set(ans[i])) == 4: print(ans[i][0], ans[i][1]) print(ans[i][2], ans[i][3]) exit() print(-1)
7
PYTHON3
import sys import math import collections import heapq input=sys.stdin.readline r1,r2=(int(i) for i in input().split()) c1,c2=(int(i) for i in input().split()) d1,d2=(int(i) for i in input().split()) c3=0 for i in range(1,10): b=r1-i c=c1-i d=d1-i if(len(set([i,b,c,d]))==4 and max(i,b,c,d)<=9 and min(i,b,c,d)>=1 and b+c==d2 and c+d==r2 and b+d==c2): print(i,b) print(c,d) c3=1 break if(c3==0): print(-1)
7
PYTHON3
r1, r2 = map(int, input().split(" ")) c1, c2 = map(int, input().split(" ")) d1, d2 = map(int, input().split(" ")) row1_list = list() row2_list = list() unlock_gems_of_r1 = list() unlock_gems_of_r2 = list() final_set = set() for gem_no1 in range(1, 10): for gem_no2 in range(1, 10): if (gem_no1 + gem_no2) == r1: row1_list.append(gem_no1) row1_list.append(gem_no2) if (gem_no1 + gem_no2) == r2: row2_list.append(gem_no1) row2_list.append(gem_no2) for i in range(0, int(len(row1_list)), 2): if len(unlock_gems_of_r1) > 0 or len(unlock_gems_of_r2) > 0: break for x in range(0, int(len(row2_list)), 2): if ((row1_list[i] + row2_list[x]) == c1 and (row1_list[i+1] + row2_list[x+1]) == c2) and ((row1_list[i] + row2_list[x+1]) == d1 and (row1_list[i+1] + row2_list[x]) == d2): unlock_gems_of_r1.append(row1_list[i]) unlock_gems_of_r1.append(row1_list[i+1]) unlock_gems_of_r2.append(row2_list[x]) unlock_gems_of_r2.append(row2_list[x+1]) final_set.add(row1_list[i]) final_set.add(row1_list[i+1]) final_set.add(row2_list[x]) final_set.add(row2_list[x+1]) break if len(final_set) < 4: print(-1) else: print(*unlock_gems_of_r1) print(*unlock_gems_of_r2) # print("i: " + str(row1_list[i]), "i+1: " + str(row1_list[i+1])) # print("x: " + str(row2_list[x]), "x+1: " + str(row2_list[x+1]))
7
PYTHON3
def is_valid(a, b, headers): r1, r2, c1, c2, d1, d2 = headers c, d = r1 - a, r2 - b res = [a, b, c, d] if a + d == d1 and b + c == d2 and len(res) == len(set(res)) and max(res) < 10: return res return -1 def print_result(res): if res == -1: return 0 print(res[0], res[2]) print(res[1], res[3]) return 1 def solve(): r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) headers = [r1, r2, c1, c2, d1, d2] if not (r1 + r2 == c1 + c2 == d1 + d2): print(-1) return for i in range(1, c1//2+1): if print_result(is_valid(i, c1-i, headers)) == 1: return if print_result(is_valid(c1-i, i, headers)) == 1: return print(-1) solve()
7
PYTHON3
r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) a=(r1+d1-c2)/2 b=(d2+c2-r2)/2 c=c1-a d=c2-b x=[a,b,c,d] if a==int(a) and b==int(b) and c==int(c) and d==int(d) and a+b==r1 and c+d==r2 and x.count(a)==1 and x.count(b)==1 and x.count(c)==1 and x.count(d)==1 and max(x)<=9 and min(x)>=1: print(int(a),int(b)) print(int(c),int(d)) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int freq[10]; memset(freq, 0, sizeof(freq)); int k, r1, r2, c1, c2, d1, d2, x1, x2, y1, y2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; x1 = (c1 + r1 - d2) / 2; v.push_back(x1); x2 = c1 - x1; v.push_back(x2); y1 = (d2 + c2 - r2) / 2; v.push_back(y1); y2 = c2 - y1; v.push_back(y2); for (int i = 0; i < v.size(); i++) { k = v[i]; if (k < 10 && k > 0) freq[k]++; } for (int i = 0; i < 10; i++) { if (freq[i] > 1) { cout << -1; return 0; } } if (x1 > 0 && x2 > 0 && y1 > 0 && y2 > 0) { if (x1 < 10 && x2 < 10 && y1 < 10 && y2 < 10) { cout << x1 << " " << y1 << "\n"; cout << x2 << " " << y2; } else { cout << -1; return 0; } } else 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 a1, a2, a3, a4; for (int i = 1; i <= 9; i++) { a1 = i; a2 = r1 - a1; a3 = c1 - a1; a4 = c2 - a2; if (1 > a2 or 1 > a3 or 1 > a4 or a2 > 9 or a3 > 9 or a4 > 9) continue; if (a1 == a2 or a1 == a3 or a1 == a4 or a2 == a3 or a2 == a4 or a3 == a4) continue; if (a3 + a4 != r2 or a1 + a4 != d1 or a2 + a3 != d2) continue; cout << a1 << " " << a2 << endl; cout << a3 << " " << a4 << endl; return 0; } puts("-1"); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { solve(); } return 0; } void solve() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int a; bool ans = false; for (a = 1; a <= 9; ++a) { int b = r1 - a; int c = c1 - a; int d = d1 - a; if (a > 0 && a < 10 && b > 0 && b < 10 && c > 0 && c < 10 && d > 0 && d < 10) { if (a != b && b != c && c != d && b != d && a != d && a != c) { if (a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 && a + d == d1 && b + c == d2) { cout << a << " " << b << "\n"; cout << c << " " << d << "\n"; ans = true; } } } } if (!ans) cout << "-1"; }
7
CPP
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; for (long long int i = 1; i < 10; ++i) { for (long long int j = 1; j < 10; ++j) { for (long long int k = 1; k < 10; ++k) { for (long long int l = 1; l < 10; ++l) { if (i + k == c1 && i + j == r1 && i + l == d1 && j + k == d2 && k + l == r2 && j + l == c2 && i != j && i != k && i != l && j != k && j != l && k != l) { cout << i << " " << j << " " << '\n' << k << " " << l; return 0; } } } } } cout << -1 << '\n'; return 0; }
7
CPP
r = lambda :map(int,input().split()) r1,r2 = r() c1,c2 = r() d1,d2 = r() if (r1-c1+d2)%2==0: x2 = (r1-c1+d2)//2 x1 = r1-x2 x3 = d2-x2 x4 = c2-x2 if (0<x1<=9 and 0<x2<=9 and 0<x3<=9 and 0<x4<=9 and x1+x3==c1 and x3+x4==r2 and x1+x4==d1): if len(set([x1,x2,x3,x4]))<4: print(-1) else: print(x1,x2) print(x3,x4) else: print(-1) else: print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { bool ff = false; 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 l = 1; l <= 9; l++) { if (i + j == a && k + l == b && i + k == c && j + l == d && i + l == e && j + k == f && i != j && i != k && i != l && j != k && j != l && k != l) { ff = true; cout << i << " " << j << endl << k << " " << l << endl; break; } } if (ff == true) break; } if (ff == true) break; } if (ff == true) break; } if (ff == false) cout << -1 << endl; return 0; }
7
CPP
#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); int tag = 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) continue; if (i == l || j == k) continue; if (j == l || k == l) continue; if (i + j == r1 && i + k == c1 && k + l == r2 && j + l == c2 && i + l == d1 && j + k == d2) { printf("%d %d\n", i, j); printf("%d %d\n", k, l); tag = 1; break; } } if (tag) break; } if (tag) break; } if (tag) break; } if (!tag) 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()) d = (d1-c1+r2) if d%2==0: D=d//2 c=r2-D b = c2-D a = r1-b if 9>=a>0 and 9>=b>0 and 9>=c>0 and 9>=D>0: if len(set([a,b,c,D]))==4: print(a,b) print(c,D) else: print(-1) else: print(-1) else: print(-1)
7
PYTHON3
rows = list(map(int,input().split())) cols = list(map(int,input().split())) diags = list(map(int,input().split())) r1 = rows[0] r2 = rows[1] c1 = cols[0] c2 = cols[1] d1 = diags[0] d2 = diags[1] boo = True n = 9 for i in range(1,n+1): for j in range(1,n+1): for k in range(1,n+1): for l in range(1,n+1): if (i!=j and i!=k and i!=l and j!=k and j!=l and k!=l) and i+j==r1 and k+l==r2 and i+k==c1 and j+l==c2 and i+l==d1 and k+j==d2: boo = False print(i,end=" ") print(j) print(k,end=" ") print(l) if boo: print(-1)
7
PYTHON3
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") from collections import defaultdict from math import ceil,floor,sqrt,log2,gcd,pi from heapq import heappush,heappop from bisect import bisect_left,bisect import sys abc='abcdefghijklmnopqrstuvwxyz' ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ" r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) tl,tr,bl,br=0,0,0,0 tl=(r1+c1-d2) if tl%2==1 or tl<0: print(-1) else: tl=tl//2 tr=r1-tl bl=c1-tl br=c2-tr # print([tl,tr,bl,br]) s=set([tl,tr,bl,br]) if len(s)!=4: print(-1) # break elif max(s)>9: print(-1) elif min(s)<1: print(-1) # break else: if tl+tr!=r1 or tl+bl!=c1 or tr+br!=c2 or bl+br!=r2 or tl+br!=d1 or tr+bl!=d2: print(-1) else: print(tl,tr) print(bl,br)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; bool comp(int n) { return n > 0 && n < 10; } bool noteq(int a, int b, int c, int d) { return a != b && a != c && a != d && b != c && b != d && c != d; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int k = r1 - c2 + d1; if (k & 1) { cout << "-1"; } else { int a, b, c, d; a = k / 2; b = r1 - a; c = c1 - a; d = r2 - c; if ((comp(a) && comp(b) && comp(c) && comp(d) && noteq(a, b, c, d)) && ((a + b == r1) && (c + d == r2) && (a + c == c1) && (b + d == c2) && (a + d == d1) && (b + c == d2))) { cout << a << " " << b << "\n" << c << " " << d; } else { cout << "-1"; } } return 0; }
7
CPP
#include <bits/stdc++.h> const int Inf = 2e9; long long LINF = (long long)4e18; using namespace std; int r1, r2, c1, c2, d1, d2; bool ok(int i, int j, int k, int l) { if (i + j != r1) return false; if (k + l != r2) return false; if (i + k != c1) return false; if (j + l != c2) return false; if (i + l != d1) return false; if (j + k != d2) return false; return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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 == j) continue; if (i == k) continue; if (i == l) continue; if (j == k) continue; if (j == l) continue; if (k == l) continue; if (!ok(i, j, k, l)) continue; cout << i << ' ' << j << '\n'; cout << k << ' ' << l << '\n'; return 0; } } } } cout << -1; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; void SR(int &x) { scanf("%d", &x); } void SR(long long &x) { scanf("%lld", &x); } void SR(double &x) { scanf("%lf", &x); } void SR(char *s) { scanf("%s", s); } void RI() {} template <typename I, typename... T> void RI(I &x, T &...tail) { SR(x); RI(tail...); } int main() { int r[2], c[2], d[2]; for (int i = 0; i < int(2); i++) RI(r[i]); for (int i = 0; i < int(2); i++) RI(c[i]); for (int i = 0; i < int(2); i++) RI(d[i]); for (int x = (1); x <= int(9); x++) for (int y = (1); y <= int(9); y++) for (int z = (1); z <= int(9); z++) for (int w = (1); w <= int(9); w++) { if (x + y != r[0]) continue; if (z + w != r[1]) continue; if (x + z != c[0]) continue; if (y + w != c[1]) continue; if (x + w != d[0]) continue; if (y + z != d[1]) continue; set<int> s; s.insert(x); s.insert(y); s.insert(z); s.insert(w); if (((int)(s).size()) != 4) continue; printf("%d %d\n%d %d\n", x, y, z, w); return 0; } puts("-1"); return 0; }
7
CPP
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) l1 = [] l2 = [] for i in range(1, 10): for j in range(1, 10): if i + j == r1: l1.append([i, j]) if i + j == r2: l2.append([i, j]) lp = [] for i in l1: for j in l2: if i[0] + j[0] == c1 and i[1] + j[1] == c2: lp.append([i, j]) li = [] for i in lp: if i[0][0] + i[1][1] == d1 and i[0][1] + i[1][0] == d2: li.append(i) if len(li) == 0: print(-1) exit() for i in li: cl = [i[0][0], i[1][0], i[1][1], i[0][1]] if len(cl) == len(set(cl)): print(i[0][0], i[0][1]) print(i[1][0], i[1][1]) exit() print(-1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int c[10]; int main() { int r1, r2, c1, c2, d1, d2; cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; int x1, x2, x3, x4; x2 = (c2 - r2 + d2) / 2; x3 = (r2 - c2 + d2) / 2; x1 = r1 - x2; x4 = c2 - x2; int flag = 0; if (x1 + x2 == r1 && x3 + x4 == r2 && x1 + x3 == c1 && x2 + x4 == c2 && x1 + x4 == d1 && x2 + x3 == d2) flag = 1; c[x1]++; c[x2]++; c[x3]++; c[x4]++; int sum = 0; for (int i = 1; i < 10; i++) { sum += c[i]; if (c[i] > 1) flag = 0; } if (sum != 4) flag = 0; if (flag) { cout << x1 << " " << x2 << endl; cout << x3 << " " << x4 << endl; } else cout << -1 << endl; return 0; }
7
CPP
# Help Vasilisa the Wise 2 import itertools def calculate(r1, r2, c1, c2, d1, d2): combinations = list(itertools.permutations([i for i in range(1,10)], 4)) for (x1, x2, x3, x4) in combinations: r1_sum = x1 + x2 r2_sum = x3 + x4 c1_sum = x1 + x3 c2_sum = x2 + x4 d1_sum = x1 + x4 d2_sum = x2 + x3 if (r1_sum == r1 and r2_sum == r2 and c1_sum == c1 and c2_sum == c2 and d1_sum == d1 and d2_sum == d2): print(str(x1) + " " + str(x2)) print(str(x3) + " " + str(x4)) return print(-1) if __name__ == "__main__": r1, r2 = list(map(lambda x: int(x), input().split())) c1, c2 = list(map(lambda x: int(x), input().split())) d1, d2 = list(map(lambda x: int(x), input().split())) calculate(r1, r2, c1, c2, d1, d2)
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) for (int k = 1; k < 10; k++) if (k != i && k != j) for (int l = 1; l < 10; 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) { printf("%d %d\n%d %d\n", i, j, k, l); return 0; } printf("-1\n"); return 0; }
7
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int MAXN = 100000 + 10; const int INF = 0x7fffffff; bool vis[10]; int main() { int r1, r2, c1, c2, d1, d2, a, b, c, d; while (scanf("%d%d%d%d%d%d", &r1, &r2, &c1, &c2, &d1, &d2) == 6) { bool f = false; memset(vis, -1, sizeof(vis)); for (a = 1; a < 10; a++) { vis[a] = false; for (b = 1; b < 10; b++) { if (vis[b]) { vis[b] = false; for (c = 1; c < 10; c++) { if (vis[c]) { vis[c] = false; for (d = 1; d < 10; d++) { if (vis[d] && a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 && a + d == d1 && b + c == d2) { f = true; break; } } if (f) break; vis[c] = true; } } if (f) break; vis[b] = true; } } if (f) break; vis[a] = true; } if (f) printf("%d %d\n%d %d\n", a, b, c, d); else printf("-1\n"); } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int c1, c2, r1, r2, d1, d2, x[5], i, j; cin >> r1 >> r2; cin >> c1 >> c2; cin >> d1 >> d2; x[3] = ((r1 - d1) + c2) / 2; x[2] = d2 - x[3]; x[4] = c2 - x[3]; x[1] = d1 - x[4]; if (x[1] + x[2] == c1 && x[3] + x[4] == c2 && x[1] + x[3] == r1 && x[2] + x[4] == r2 && x[1] + x[4] == d1 && x[2] + x[3] == d2) { for (i = 1; i < 4; i++) { for (j = i + 1; j <= 4; j++) if (x[i] == x[j] || x[i] > 9 || x[j] > 9 || x[i] < 1 || x[j] < 1) { cout << -1; return 0; } } cout << x[1] << " " << x[3] << endl << x[2] << " " << x[4]; } else cout << -1; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int r1, r2, c1, c2, d1, d2; int board[2][2]; bool taken[10]; bool ans; void check() { int a = board[0][0] + board[0][1]; int b = board[1][0] + board[1][1]; int c = board[0][0] + board[1][1]; int d = board[0][1] + board[1][0]; int e = board[0][0] + board[1][0]; int f = board[0][1] + board[1][1]; if (a == r1 and b == r2 and c == d1 and d == d2 and e == c1 and f == c2) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { cout << board[i][j] << " "; } cout << endl; } ans = true; return; } else { return; } } void solve(int i, int j) { if (j == 2) { i++; j = 0; } if (i == 2) { check(); return; } for (int ii = 1; ii <= 9; ii++) { if (!taken[ii]) { taken[ii] = true; board[i][j] = ii; solve(i, j + 1); board[i][j] = 0; taken[ii] = false; } } } int main() { memset(taken, false, sizeof(taken)); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { board[i][j] = 0; } } cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2; solve(0, 0); if (!ans) { cout << -1 << endl; } }
7
CPP
#include <bits/stdc++.h> #define fst first #define snd second #define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i) #define pb push_back #define ALL(s) s.begin(),s.end() #define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define SZ(s) int(s.size()) using namespace std; typedef long long ll; typedef pair<int,int> ii; const int MAXN=5e5+10,MOD=1e9+7; int add(int a, int b){a+=b;if(a>=MOD)a-=MOD;return a;} int sub(int a, int b){a-=b;if(a<0)a+=MOD;return a;} int mul(ll a, ll b){return a*b%MOD;} int fpow(int a, ll b){ int r=1; while(b){if(b&1)r=mul(r,a); b>>=1; a=mul(a,a);} return r; } int p[MAXN],am[MAXN],did[MAXN]; int find(int x){return p[x]=p[x]==x?x:find(p[x]);} bool join(int x, int y){ x=find(x); y=find(y); if(x==y)return 0; if(x!=y)p[x]=y,am[y]|=am[x]; return 1; } int main(){FIN; int n,m,tot=0; cin>>n>>m; fore(i,0,m) p[i]=i; fore(i,0,n){ int k; cin>>k; if(k==1){ int x; cin>>x; x--; if(!am[find(x)]) am[find(x)]=1,did[i]=1,tot++; } if(k==2){ int x,y; cin>>x>>y; x--; y--; int has=am[find(x)]&&am[find(y)]; if(join(x,y)&&!has)did[i]=1,tot++; } } cout<<fpow(2,tot)<<" "<<tot<<"\n"; fore(i,0,n)if(did[i])cout<<i+1<<" ";cout<<"\n"; }
12
CPP
import sys input = sys.stdin.buffer.readline def _find(s, u): p = [] while s[u] != u: p.append(u) u = s[u] for v in p: s[v] = u return u def _union(s, u, v): su, sv = _find(s, u), _find(s, v) if su != sv: s[su] = sv return su != sv n, m = map(int, input().split()) s, solo = list(range(m+1)), [0]*(m+1) res, pos = [], set() for i in range(n): p = list(map(int, input().split())) if p[0] == 1: pos.add(p[1]) p1 = _find(s, p[1]) if not solo[p1]: res.append(i+1) solo[p1] = 1 else: pos.add(p[1]) pos.add(p[2]) p1, p2 = _find(s, p[1]), _find(s, p[2]) if not (p1 == p2 or (solo[p1] and solo[p2])): _union(s, p1, p2) res.append(i+1) if solo[p1] or solo[p2]: solo[_find(s, p1)] = 1 cc = 0 for u in pos: su = _find(s, u) cc += 1 if not solo[su] and su == u: cc -= 1 print(pow(2, cc, 10**9+7), len(res)) print(*res)
12
PYTHON3
/** * author: akifpathan * created: Thursday 31.12.2020 11:51:21 AM **/ /* #pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */ #ifdef LOCAL #include "debug.h" #else #include<bits/stdc++.h> using namespace std; #define debug(x...) #endif /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using ordered_set= tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; template<class T> using ordered_mset= tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update> ; */ /* PBDS ------------------------------------------------- 0 based indexing ------------------------------------------------- 1) insert(value) 2) erase(value) 3) order_of_key(value) // Number of items strictly smaller than value 4) *find_by_order(k) : K-th element in a set (counting from zero) */ typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T,typename U> T power(T b,U n) { assert(n>=0); T ans=1; for(;n>0;n/=2,b*=b) if(n&1) ans*=b; return ans; } ll power(ll b,ll n,ll mod) { assert(n>=0); ll ans=1; for(;n>0;n/=2,b=(b*b)%mod) if(n&1) ans=(ans*b)%mod; return ans; } template<ll mod> struct Modular { ll val; Modular(){ val=0; } Modular(ll _val) { val=_val%mod; if(val<0) val+=mod; } Modular normalize(const ll x) { val=x%mod; if(val<0) val+=mod; return val; } bool operator == (const Modular &a) const { return val==a.val; } bool operator != (const Modular &a) const { return val!=a.val; } bool operator < (const Modular &a) const { return val<a.val; } Modular operator = (ll x) { return normalize(x); } Modular operator = (const Modular &x){ val=x.val;return *this;} Modular operator += (const Modular &a) { return normalize(val+a.val); } Modular operator -= (const Modular &a) { return normalize(val-a.val); } Modular operator *= (const Modular &a) { return normalize(val*a.val);} Modular operator /= (const Modular &b) { return normalize(val*inverse(b).val); } //friend Modular power(Modular b,ll n) {Modular ans=1; for(;n>0;n/=2,b*=b) if(n&1) ans*=b;return ans; } friend Modular operator ^ (Modular b,ll n) { return power(b,n); } friend Modular inverse(Modular b) { return b^(mod-2); } friend Modular operator + (Modular a,const Modular &b) { return a+=b; } friend Modular operator - (Modular a,const Modular &b) { return a-=b; } friend Modular operator * (Modular a,const Modular &b) { return a*=b; } friend Modular operator / (Modular a,const Modular &b) { return a/=b; } friend Modular operator + (Modular a,ll b) { return a+=b; } friend Modular operator - (Modular a,ll b) { return a-=b; } friend Modular operator * (Modular a,ll b) { return a*=b; } friend Modular operator / (Modular a,ll b) { return a/=b; } friend Modular operator + (ll b,Modular a) { return a+=b; }; friend Modular operator - (ll b,const Modular &a) { Modular c(b); return c-=a; } friend Modular operator * (ll b,Modular a) { return a*=b; }; friend Modular operator / (ll b,const Modular &a) { Modular c(b); return c/=a; } friend istream& operator >> (istream& in,Modular &a) {ll x; in>>x; a.normalize(x); return in; } friend ostream& operator << (ostream& out,const Modular& a) { return out<<a.val; } }; //const ll mod=998244353; const ll mod=1e9+7; typedef Modular<mod> Mint; struct DSU { vector<int>par; vector<int>sz; DSU(int n) { par.resize(n+1); iota(par.begin(),par.end(),0); sz.assign(n+1,1); } int Find(int a) { return par[a]==a?a:par[a]=Find(par[a]); } bool same(int a,int b) { a=Find(a); b=Find(b); return a==b; } bool Union(int a,int b) { a=Find(a); b=Find(b); if(a==b) return false; if(sz[a]<sz[b]) swap(a,b); sz[a]+=sz[b]; par[b]=a; return true; } }; void solve() { int n,m; cin>>n>>m; DSU dsu(m+1); vector<int>ans; for(int i=1;i<=n;i++) { int k; cin>>k; int u,v; cin>>u; if(k==2) cin>>v; else v=m+1; if(dsu.Union(u,v)) ans.push_back(i); } cout<<(Mint(2)^ans.size())<<" "<<ans.size()<<"\n"; for(int x: ans) cout<<x<<" "; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int testcase=1; //cin>>testcase; for(int i=1;i<=testcase;i++) { //cout<<"Case "<<i<<": "; solve(); } #ifdef LOCAL cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n"; #endif return 0; }
12
CPP
class UnionFind: def __init__(self, n): self.parent = list(range(n)) def find(self, a): acopy = a while a != self.parent[a]: a = self.parent[a] while acopy != a: self.parent[acopy], acopy = a, self.parent[acopy] return a def union(self, a, b): self.parent[self.find(b)] = self.find(a) import sys;input = sys.stdin.readline;n, m = map(int, input().split());UF = UnionFind(m + 1);MOD = 10 ** 9 + 7;out = [] for i in range(1, n + 1): l = list(map(int, input().split())) if len(l) == 2:u = 0;v = l[1] else:_, u, v = l uu = UF.find(u);vv = UF.find(v) if uu != vv:UF.union(uu,vv);out.append(i) print(pow(2, len(out), MOD), len(out));print(' '.join(map(str,out)))
12
PYTHON3
import sys input = sys.stdin.buffer.readline def prog(): n,m = map(int,input().split()) mod = 10**9 + 7 has_one = [0]*(m+1) basis = [] sizes = [1]*(m+1) parent = list(range(m+1)) def find_parent(v): if v == parent[v]: return v v = find_parent(parent[v]) return v def union_sets(a,b): a = find_parent(a) b = find_parent(b) if a != b and (not has_one[a] or not has_one[b]): if sizes[a] < sizes[b]: a,b = b,a parent[b] = a sizes[a] += sizes[b] has_one[a] = has_one[a] | has_one[b] return True else: return False for i in range(1,n+1): a = list(map(int,input().split())) if a[0] == 1: par = find_parent(a[1]) if not has_one[par]: has_one[par] = 1 basis.append(i) elif union_sets(a[1],a[2]): basis.append(i) print(pow(2,len(basis),mod),len(basis)) print(*basis) prog()
12
PYTHON3