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 =...
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...
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...
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 i...
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 (...
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 ...
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 ...
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:...
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++; ...
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...
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) ...
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) { ...
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 = ...
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 ...
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; } i...
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 = ...
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 a1...
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...
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: ...
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 !=...
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): ...
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...
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 ...
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 -...
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...
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)] boa...
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 == ...
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(...
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] > ...
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; } ...
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...
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...
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 &...
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...
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 && ...
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: ...
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 == ...
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 == x...
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, remain...
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) el...
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: continu...
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 ...
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) qu...
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]; ...
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 ...
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.ap...
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+...
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 ...
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 ...
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 != a...
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: ...
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 = c...
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 == ...
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 >...
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) { ...
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): ...
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==...
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 == ...
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 && ...
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 &...
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 ...
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...
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,...
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...
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 ...
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) ...
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!=...
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 != ...
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...
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 ==...
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 ...
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,...
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) ==...
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]) ...
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 mi...
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) ...
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) c...
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 <...
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...
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) ...
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 == ...
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 == ...
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: ...
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 ra...
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...
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...
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) re...
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()...
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] + ...
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...
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 ...
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++) ...
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; ...
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 && ...
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]; i...
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<i...
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 ...
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; #...
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): ...
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])...
12
PYTHON3