puwaer/puwaer_code_translation huggingface dataset:
AtCoder problem 018

C++ solution:
#include <iostream>

#include <cmath>

using namespace std;



int Q;

long double T, L, X, Y, E;

long double PI = 3.14159265358979;



long double query(long double I) {

	long double cx = 0;

	long double cy = -(L / 2.0) * sin(I / T * 2.0 * PI);

	long double cz = (L / 2.0) - (L / 2.0) * cos(I / T * 2.0 * PI);

	long double d1 = sqrt((cx - X) * (cx - X) + (cy - Y) * (cy - Y));

	long double d2 = cz;

	long double kaku = atan2(d2, d1);

	return kaku * 180.0L / PI;

}



int main() {

	cin >> T;

	cin >> L >> X >> Y;

	cin >> Q;

	for (int i = 1; i <= Q; i++) {

		cin >> E;

		printf("%.12Lf\n", query(E));

	}

	return 0;

}


Python solution: import numpy as np

t = int(input())
l, x, y = map(int, input().split())
q = int(input())
for i in range(q):
    e = int(input())
    if(e % t == 0):
        print(0)
        continue
    rad = 3/2*np.pi - e/t*2*np.pi
    pos = np.array([0, l/2*np.cos(rad), l/2+l/2*np.sin(rad)])
    takahashi = np.array([x, y, 0])
    ground = pos.copy()
    ground[2] = 0
    vector1 = pos - takahashi
    vector2 = ground - takahashi
    inner = np.dot(vector1, vector2)
    inner /= np.linalg.norm(vector1)
    inner /= np.linalg.norm(vector2)
    theta = np.arccos(inner)
    print(theta*360/(2*np.pi))
AtCoder problem 018

C++ solution:
#include <iostream>

#include <cmath>

using namespace std;



int Q;

long double T, L, X, Y, E;

long double PI = 3.14159265358979;



long double query(long double I) {

	long double cx = 0;

	long double cy = -(L / 2.0) * sin(I / T * 2.0 * PI);

	long double cz = (L / 2.0) - (L / 2.0) * cos(I / T * 2.0 * PI);

	long double d1 = sqrt((cx - X) * (cx - X) + (cy - Y) * (cy - Y));

	long double d2 = cz;

	long double kaku = atan2(d2, d1);

	return kaku * 180.0L / PI;

}



int main() {

	cin >> T;

	cin >> L >> X >> Y;

	cin >> Q;

	for (int i = 1; i <= Q; i++) {

		cin >> E;

		printf("%.12Lf\n", query(E));

	}

	return 0;

}





Kuin solution: func main()
	var t: float :: cui@inputFloat()
	var l: float :: cui@inputFloat()
	var x: float :: cui@inputFloat()
	var y: float :: cui@inputFloat()
	
	var q: int :: cui@inputInt()
	for(1, q)
		var e: float :: cui@inputFloat()
		var posY: float :: -l / 2.0 * lib@sin(2.0 * lib@pi * e / t)
		var posZ: float :: l / 2.0 * (1.0 - lib@cos(2.0 * lib@pi * e / t))
		var ans: float :: lib@toDegree(lib@atan(posZ / (x ^ 2.0 + (posY - y) ^ 2.0) ^ 0.5))
		do cui@print("\{ans}\n")
	end for
end func
AtCoder problem 018

C++ solution:

Crystal solution: TAU = Math::PI * 2
t = read_line.to_i
l, tx, ty = read_line.split.map(&.to_i)
read_line.to_i.times do
  e = read_line.to_i
  angle = TAU / t * e
  y = -Math.sin(angle) * l / 2
  height = l / 2 - Math.cos(angle) * l / 2
  dist = Math.hypot(tx, ty - y)
  puts Math.atan(height / dist) * 360 / TAU
end


Python solution: import numpy as np

t = int(input())
l, x, y = map(int, input().split())
q = int(input())
for i in range(q):
    e = int(input())
    if(e % t == 0):
        print(0)
        continue
    rad = 3/2*np.pi - e/t*2*np.pi
    pos = np.array([0, l/2*np.cos(rad), l/2+l/2*np.sin(rad)])
    takahashi = np.array([x, y, 0])
    ground = pos.copy()
    ground[2] = 0
    vector1 = pos - takahashi
    vector2 = ground - takahashi
    inner = np.dot(vector1, vector2)
    inner /= np.linalg.norm(vector1)
    inner /= np.linalg.norm(vector2)
    theta = np.arccos(inner)
    print(theta*360/(2*np.pi))
AtCoder problem 018

C++ solution:

Crystal solution: TAU = Math::PI * 2
t = read_line.to_i
l, tx, ty = read_line.split.map(&.to_i)
read_line.to_i.times do
  e = read_line.to_i
  angle = TAU / t * e
  y = -Math.sin(angle) * l / 2
  height = l / 2 - Math.cos(angle) * l / 2
  dist = Math.hypot(tx, ty - y)
  puts Math.atan(height / dist) * 360 / TAU
end





Kuin solution: func main()
	var t: float :: cui@inputFloat()
	var l: float :: cui@inputFloat()
	var x: float :: cui@inputFloat()
	var y: float :: cui@inputFloat()
	
	var q: int :: cui@inputInt()
	for(1, q)
		var e: float :: cui@inputFloat()
		var posY: float :: -l / 2.0 * lib@sin(2.0 * lib@pi * e / t)
		var posZ: float :: l / 2.0 * (1.0 - lib@cos(2.0 * lib@pi * e / t))
		var ans: float :: lib@toDegree(lib@atan(posZ / (x ^ 2.0 + (posY - y) ^ 2.0) ^ 0.5))
		do cui@print("\{ans}\n")
	end for
end func
AtCoder problem 018

C++ solution:


Python solution: import numpy as np

t = int(input())
l, x, y = map(int, input().split())
q = int(input())
for i in range(q):
    e = int(input())
    if(e % t == 0):
        print(0)
        continue
    rad = 3/2*np.pi - e/t*2*np.pi
    pos = np.array([0, l/2*np.cos(rad), l/2+l/2*np.sin(rad)])
    takahashi = np.array([x, y, 0])
    ground = pos.copy()
    ground[2] = 0
    vector1 = pos - takahashi
    vector2 = ground - takahashi
    inner = np.dot(vector1, vector2)
    inner /= np.linalg.norm(vector1)
    inner /= np.linalg.norm(vector2)
    theta = np.arccos(inner)
    print(theta*360/(2*np.pi))




Kuin solution: func main()
	var t: float :: cui@inputFloat()
	var l: float :: cui@inputFloat()
	var x: float :: cui@inputFloat()
	var y: float :: cui@inputFloat()
	
	var q: int :: cui@inputInt()
	for(1, q)
		var e: float :: cui@inputFloat()
		var posY: float :: -l / 2.0 * lib@sin(2.0 * lib@pi * e / t)
		var posZ: float :: l / 2.0 * (1.0 - lib@cos(2.0 * lib@pi * e / t))
		var ans: float :: lib@toDegree(lib@atan(posZ / (x ^ 2.0 + (posY - y) ^ 2.0) ^ 0.5))
		do cui@print("\{ans}\n")
	end for
end func
AtCoder problem 019

C++ solution:
#include <iostream>

#include <cmath>

#include <algorithm>

using namespace std;



int N;

int A[1 << 18];

int dp[409][409];



int main() {

	// Step #1. Input

	cin >> N;

	for (int i = 1; i <= 2 * N; i++) cin >> A[i];



	// Step #2. Initialize

	for (int i = 1; i <= 2 * N; i++) {

		for (int j = i; j <= 2 * N; j++) dp[i][j] = (1 << 29);

		if (i < 2 * N) dp[i][i + 1] = abs(A[i] - A[i + 1]);

	}



	// Step #3. DP

	for (int i = 3; i <= 2 * N; i += 2) {

		for (int j = 1; j <= 2 * N - i; j++) {

			int cl = j, cr = j + i;

			for (int k = cl; k <= cr - 1; k++) dp[cl][cr] = min(dp[cl][cr], dp[cl][k] + dp[k + 1][cr]);

			dp[cl][cr] = min(dp[cl][cr], dp[cl + 1][cr - 1] + abs(A[cl] - A[cr]));

		}

	}



	// Step #4. Output

	cout << dp[1][2 * N] << endl;

	return 0;

}

Crystal solution: def rec(a, memo, l, r) : Int32
  memo[l][r] ||= l == r ? 0 : {
    (l + 2).step(to: r - 2, by: 2).min_of? { |mid|
      rec(a, memo, l, mid) + rec(a, memo, mid, r)
    } || 10**9,
    rec(a, memo, l + 1, r - 1) + (a[l] - a[r - 1]).abs,
  }.min
end

n = read_line.to_i
a = read_line.split.map(&.to_i)
memo = Array.new(2 * n) { Array(Int32?).new(2 * n + 1, nil) }
puts rec(a, memo, 0, 2 * n)
AtCoder problem 019

C++ solution:

Crystal solution: def rec(a, memo, l, r) : Int32
  memo[l][r] ||= l == r ? 0 : {
    (l + 2).step(to: r - 2, by: 2).min_of? { |mid|
      rec(a, memo, l, mid) + rec(a, memo, mid, r)
    } || 10**9,
    rec(a, memo, l + 1, r - 1) + (a[l] - a[r - 1]).abs,
  }.min
end

n = read_line.to_i
a = read_line.split.map(&.to_i)
memo = Array.new(2 * n) { Array(Int32?).new(2 * n + 1, nil) }
puts rec(a, memo, 0, 2 * n)


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from functools import lru_cache
def main(N, A):
    @lru_cache(None)
    def f(l, r):
        if r <= l: return 0
        res = abs(A[l] - A[r]) + f(l + 1, r - 1)
        for i in range(l + 1, r + 1, 2):
            res = min(res, abs(A[l] - A[i]) + f(l + 1, i - 1) + f(i + 1, r))
        return res

    print(f(0, 2 * N - 1))

if __name__ == '__main__':
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)
AtCoder problem 019

C++ solution:

Crystal solution: def rec(a, memo, l, r) : Int32
  memo[l][r] ||= l == r ? 0 : {
    (l + 2).step(to: r - 2, by: 2).min_of? { |mid|
      rec(a, memo, l, mid) + rec(a, memo, mid, r)
    } || 10**9,
    rec(a, memo, l + 1, r - 1) + (a[l] - a[r - 1]).abs,
  }.min
end

n = read_line.to_i
a = read_line.split.map(&.to_i)
memo = Array.new(2 * n) { Array(Int32?).new(2 * n + 1, nil) }
puts rec(a, memo, 0, 2 * n)





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var a: []int :: #[2 * n]int
	for i(0, 2 * n - 1)
		do a[i] :: cui@inputInt()
	end for
	
	; 区間DP
	; dp[l][r] = l以上r以下の区間の取り除きコストの最小値
	var dp: [][]int :: #[2 * n, 2 * n]int
	for l(0, 2 * n - 1)
		for r(0, 2 * n - 1)
			do dp[l][r] :: 10 ^ 9
		end for
	end for
	
	for w(2, 2 * n, 2)
		for l(0, 2 * n - w)
			var r: int :: l + w - 1
			if(w = 2)
				do dp[l][r] :: (a[l] - a[r]).abs()
			else
				for k(l + 1, r - 2)
					do dp[l][r] :: [dp[l][r], dp[l][k] + dp[k + 1][r]].min()
				end for
				do dp[l][r] :: [dp[l][r], dp[l + 1][r - 1] + (a[l] - a[r]).abs()].min()
			end if
		end for
	end for
	
	var ans: int :: dp[0][2 * n - 1]
	do cui@print("\{ans}\n")
end func
AtCoder problem 019

C++ solution:
#include <iostream>

#include <cmath>

#include <algorithm>

using namespace std;



int N;

int A[1 << 18];

int dp[409][409];



int main() {

	// Step #1. Input

	cin >> N;

	for (int i = 1; i <= 2 * N; i++) cin >> A[i];



	// Step #2. Initialize

	for (int i = 1; i <= 2 * N; i++) {

		for (int j = i; j <= 2 * N; j++) dp[i][j] = (1 << 29);

		if (i < 2 * N) dp[i][i + 1] = abs(A[i] - A[i + 1]);

	}



	// Step #3. DP

	for (int i = 3; i <= 2 * N; i += 2) {

		for (int j = 1; j <= 2 * N - i; j++) {

			int cl = j, cr = j + i;

			for (int k = cl; k <= cr - 1; k++) dp[cl][cr] = min(dp[cl][cr], dp[cl][k] + dp[k + 1][cr]);

			dp[cl][cr] = min(dp[cl][cr], dp[cl + 1][cr - 1] + abs(A[cl] - A[cr]));

		}

	}



	// Step #4. Output

	cout << dp[1][2 * N] << endl;

	return 0;

}


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from functools import lru_cache
def main(N, A):
    @lru_cache(None)
    def f(l, r):
        if r <= l: return 0
        res = abs(A[l] - A[r]) + f(l + 1, r - 1)
        for i in range(l + 1, r + 1, 2):
            res = min(res, abs(A[l] - A[i]) + f(l + 1, i - 1) + f(i + 1, r))
        return res

    print(f(0, 2 * N - 1))

if __name__ == '__main__':
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)
AtCoder problem 019

C++ solution:
#include <iostream>

#include <cmath>

#include <algorithm>

using namespace std;



int N;

int A[1 << 18];

int dp[409][409];



int main() {

	// Step #1. Input

	cin >> N;

	for (int i = 1; i <= 2 * N; i++) cin >> A[i];



	// Step #2. Initialize

	for (int i = 1; i <= 2 * N; i++) {

		for (int j = i; j <= 2 * N; j++) dp[i][j] = (1 << 29);

		if (i < 2 * N) dp[i][i + 1] = abs(A[i] - A[i + 1]);

	}



	// Step #3. DP

	for (int i = 3; i <= 2 * N; i += 2) {

		for (int j = 1; j <= 2 * N - i; j++) {

			int cl = j, cr = j + i;

			for (int k = cl; k <= cr - 1; k++) dp[cl][cr] = min(dp[cl][cr], dp[cl][k] + dp[k + 1][cr]);

			dp[cl][cr] = min(dp[cl][cr], dp[cl + 1][cr - 1] + abs(A[cl] - A[cr]));

		}

	}



	// Step #4. Output

	cout << dp[1][2 * N] << endl;

	return 0;

}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var a: []int :: #[2 * n]int
	for i(0, 2 * n - 1)
		do a[i] :: cui@inputInt()
	end for
	
	; 区間DP
	; dp[l][r] = l以上r以下の区間の取り除きコストの最小値
	var dp: [][]int :: #[2 * n, 2 * n]int
	for l(0, 2 * n - 1)
		for r(0, 2 * n - 1)
			do dp[l][r] :: 10 ^ 9
		end for
	end for
	
	for w(2, 2 * n, 2)
		for l(0, 2 * n - w)
			var r: int :: l + w - 1
			if(w = 2)
				do dp[l][r] :: (a[l] - a[r]).abs()
			else
				for k(l + 1, r - 2)
					do dp[l][r] :: [dp[l][r], dp[l][k] + dp[k + 1][r]].min()
				end for
				do dp[l][r] :: [dp[l][r], dp[l + 1][r - 1] + (a[l] - a[r]).abs()].min()
			end if
		end for
	end for
	
	var ans: int :: dp[0][2 * n - 1]
	do cui@print("\{ans}\n")
end func
AtCoder problem 019

C++ solution:


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from functools import lru_cache
def main(N, A):
    @lru_cache(None)
    def f(l, r):
        if r <= l: return 0
        res = abs(A[l] - A[r]) + f(l + 1, r - 1)
        for i in range(l + 1, r + 1, 2):
            res = min(res, abs(A[l] - A[i]) + f(l + 1, i - 1) + f(i + 1, r))
        return res

    print(f(0, 2 * N - 1))

if __name__ == '__main__':
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)




Kuin solution: func main()
	var n: int :: cui@inputInt()
	var a: []int :: #[2 * n]int
	for i(0, 2 * n - 1)
		do a[i] :: cui@inputInt()
	end for
	
	; 区間DP
	; dp[l][r] = l以上r以下の区間の取り除きコストの最小値
	var dp: [][]int :: #[2 * n, 2 * n]int
	for l(0, 2 * n - 1)
		for r(0, 2 * n - 1)
			do dp[l][r] :: 10 ^ 9
		end for
	end for
	
	for w(2, 2 * n, 2)
		for l(0, 2 * n - w)
			var r: int :: l + w - 1
			if(w = 2)
				do dp[l][r] :: (a[l] - a[r]).abs()
			else
				for k(l + 1, r - 2)
					do dp[l][r] :: [dp[l][r], dp[l][k] + dp[k + 1][r]].min()
				end for
				do dp[l][r] :: [dp[l][r], dp[l + 1][r - 1] + (a[l] - a[r]).abs()].min()
			end if
		end for
	end for
	
	var ans: int :: dp[0][2 * n - 1]
	do cui@print("\{ans}\n")
end func
AtCoder problem 020

C++ solution:
#include <iostream>

using namespace std;



long long A, B, C;

long long E = 1;



int main() {

	cin >> A >> B >> C;

	for (int i = 1; i <= B; i++) E *= C;

	if (A < E) cout << "Yes" << endl;

	else cout << "No" << endl;

	return 0;

}

Crystal solution: a, b, c = read_line.split.map(&.to_i64)
puts a < c**b ? "Yes" : "No"
AtCoder problem 020

C++ solution:
#include <iostream>

using namespace std;



long long A, B, C;

long long E = 1;



int main() {

	cin >> A >> B >> C;

	for (int i = 1; i <= B; i++) E *= C;

	if (A < E) cout << "Yes" << endl;

	else cout << "No" << endl;

	return 0;

}


Python solution: a, b, c = map(int, input().split())

tmp = 1

for i in range(b):
    tmp *= c

if a < tmp:
    print('Yes')
else:
    print('No')
AtCoder problem 020

C++ solution:
#include <iostream>

using namespace std;



long long A, B, C;

long long E = 1;



int main() {

	cin >> A >> B >> C;

	for (int i = 1; i <= B; i++) E *= C;

	if (A < E) cout << "Yes" << endl;

	else cout << "No" << endl;

	return 0;

}





Kuin solution: func main()
	var a: int :: cui@inputInt()
	var b: int :: cui@inputInt()
	var c: int :: cui@inputInt()
	var ans: bool :: a < c ^ b
	do cui@print((ans ?("Yes", "No")) ~ "\n")
end func
AtCoder problem 020

C++ solution:

Crystal solution: a, b, c = read_line.split.map(&.to_i64)
puts a < c**b ? "Yes" : "No"


Python solution: a, b, c = map(int, input().split())

tmp = 1

for i in range(b):
    tmp *= c

if a < tmp:
    print('Yes')
else:
    print('No')
AtCoder problem 020

C++ solution:

Crystal solution: a, b, c = read_line.split.map(&.to_i64)
puts a < c**b ? "Yes" : "No"





Kuin solution: func main()
	var a: int :: cui@inputInt()
	var b: int :: cui@inputInt()
	var c: int :: cui@inputInt()
	var ans: bool :: a < c ^ b
	do cui@print((ans ?("Yes", "No")) ~ "\n")
end func
AtCoder problem 020

C++ solution:


Python solution: a, b, c = map(int, input().split())

tmp = 1

for i in range(b):
    tmp *= c

if a < tmp:
    print('Yes')
else:
    print('No')




Kuin solution: func main()
	var a: int :: cui@inputInt()
	var b: int :: cui@inputInt()
	var c: int :: cui@inputInt()
	var ans: bool :: a < c ^ b
	do cui@print((ans ?("Yes", "No")) ~ "\n")
end func
AtCoder problem 021

C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;



// Input

int N, M;

int A[1 << 18], B[1 << 18];



// Graph

bool used[1 << 18];

vector<int> G[1 << 18];

vector<int> H[1 << 18];

vector<int> I;

long long cnts = 0;



void dfs(int pos) {

	used[pos] = true;

	for (int i : G[pos]) {

		if (used[i] == false) dfs(i);

	}

	I.push_back(pos);

}



void dfs2(int pos) {

	used[pos] = true;

	cnts++;

	for (int i : H[pos]) {

		if (used[i] == false) dfs2(i);

	}

}



int main() {

	// Step #1. Input

	cin >> N >> M;

	for (int i = 1; i <= M; i++) {

		cin >> A[i] >> B[i];

		G[A[i]].push_back(B[i]);

		H[B[i]].push_back(A[i]);

	}



	// Step #2. First DFS

	for (int i = 1; i <= N; i++) {

		if (used[i] == false) dfs(i);

	}



	// Step #3. Second DFS

	long long Answer = 0;

	reverse(I.begin(), I.end());

	for (int i = 1; i <= N; i++) used[i] = false;

	for (int i : I) {

		if (used[i] == true) continue;

		cnts = 0;

		dfs2(i);

		Answer += cnts * (cnts - 1LL) / 2LL;

	}



	// Step #4. Output The Answer!

	cout << Answer << endl;

	return 0;

}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var m: int :: cui@inputInt()
	var ab: []list<int> :: #[n]list<int>
	var ba: []list<int> :: #[n]list<int>
	for i(0, n - 1)
		do ab[i] :: #list<int>
		do ba[i] :: #list<int>
	end for
	for(1, m)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		do ab[a].add(b)
		do ba[b].add(a)
	end for
	
	var used1: []bool :: #[n]bool
	var ordersList: list<int> :: #list<int>
	for i(0, n - 1)
		if(!used1[i])
			do dfs1(ab, used1, i, ordersList)
		end if
	end for
	var orders: []int :: ordersList.toArray()
	do orders.reverse()
	
	var used2: []bool :: #[n]bool
	var ans: int :: 0
	for i(0, n - 1)
		if(!used2[orders[i]])
			var res: int :: dfs2(ba, used2, orders[i])
			do ans :+ res * (res - 1) / 2
		end if
	end for
	do cui@print("\{ans}\n")
	
	func dfs1(ab: []list<int>, used: []bool, u: int, ordersList: list<int>)
		do used[u] :: true
		do ab[u].head()
		for i(0, ^ab[u] - 1)
			var v: int :: ab[u].get()
			if(!used[v])
				do dfs1(ab, used, v, ordersList)
			end if
			do ab[u].next()
		end for
		do ordersList.add(u)
	end func
	
	func dfs2(ba: []list<int>, used: []bool, u: int): int
		var res: int :: 1
		do used[u] :: true
		do ba[u].head()
		for i(0, ^ba[u] - 1)
			var v: int :: ba[u].get()
			if(!used[v])
				do res :+ dfs2(ba, used, v)
			end if
			do ba[u].next()
		end for
		ret res
	end func
end func
AtCoder problem 022

C++ solution:
#include <iostream>

using namespace std;



long long gcd(long long a, long long b) {

	if (b == 0) return a;

	return gcd(b, a % b);

}



long long A, B, C;



int main() {

	cin >> A >> B >> C;

	long long S = gcd(A, gcd(B, C));

	cout << (A / S - 1LL) + (B / S - 1LL) + (C / S - 1LL) << endl;

	return 0;

}

Crystal solution: a = read_line.split.map(&.to_i64)
gcd = a.reduce { |x, y| x.gcd y }
puts a.sum { |x| x // gcd - 1 }
AtCoder problem 022

C++ solution:
#include <iostream>

using namespace std;



long long gcd(long long a, long long b) {

	if (b == 0) return a;

	return gcd(b, a % b);

}



long long A, B, C;



int main() {

	cin >> A >> B >> C;

	long long S = gcd(A, gcd(B, C));

	cout << (A / S - 1LL) + (B / S - 1LL) + (C / S - 1LL) << endl;

	return 0;

}


Python solution: import math

a,b,c = map(int,input().split())
g = math.gcd(math.gcd(a,b),c)
print((a+b+c)//g-3)
AtCoder problem 022

C++ solution:
#include <iostream>

using namespace std;



long long gcd(long long a, long long b) {

	if (b == 0) return a;

	return gcd(b, a % b);

}



long long A, B, C;



int main() {

	cin >> A >> B >> C;

	long long S = gcd(A, gcd(B, C));

	cout << (A / S - 1LL) + (B / S - 1LL) + (C / S - 1LL) << endl;

	return 0;

}





Kuin solution: func main()
	var a: []int :: #[3]int
	for i(0, 2)
		do a[i] :: cui@inputInt()
	end for
	var gcd: int :: a[0]
	for i(1, 2)
		do gcd :: math@gcd(gcd, a[i])
	end for
	var ans: int :: 0
	for i(0, 2)
		do ans :+ (a[i] / math@gcd(gcd, a[i]) - 1)
	end for
	
	do cui@print("\{ans}\n")
end func
AtCoder problem 022

C++ solution:

Crystal solution: a = read_line.split.map(&.to_i64)
gcd = a.reduce { |x, y| x.gcd y }
puts a.sum { |x| x // gcd - 1 }


Python solution: import math

a,b,c = map(int,input().split())
g = math.gcd(math.gcd(a,b),c)
print((a+b+c)//g-3)
AtCoder problem 022

C++ solution:

Crystal solution: a = read_line.split.map(&.to_i64)
gcd = a.reduce { |x, y| x.gcd y }
puts a.sum { |x| x // gcd - 1 }





Kuin solution: func main()
	var a: []int :: #[3]int
	for i(0, 2)
		do a[i] :: cui@inputInt()
	end for
	var gcd: int :: a[0]
	for i(1, 2)
		do gcd :: math@gcd(gcd, a[i])
	end for
	var ans: int :: 0
	for i(0, 2)
		do ans :+ (a[i] / math@gcd(gcd, a[i]) - 1)
	end for
	
	do cui@print("\{ans}\n")
end func
AtCoder problem 022

C++ solution:


Python solution: import math

a,b,c = map(int,input().split())
g = math.gcd(math.gcd(a,b),c)
print((a+b+c)//g-3)




Kuin solution: func main()
	var a: []int :: #[3]int
	for i(0, 2)
		do a[i] :: cui@inputInt()
	end for
	var gcd: int :: a[0]
	for i(1, 2)
		do gcd :: math@gcd(gcd, a[i])
	end for
	var ans: int :: 0
	for i(0, 2)
		do ans :+ (a[i] / math@gcd(gcd, a[i]) - 1)
	end for
	
	do cui@print("\{ans}\n")
end func
AtCoder problem 024

C++ solution:
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int cnt = 0;
  rep(i, n){
    int b; cin >> b;
    cnt += abs(a[i] - b);
  }
  if(k < cnt || (k-cnt) & 1){
    cout << "No\n";
  }else{
    cout << "Yes\n";
  }
}

Crystal solution: _, k = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i)
b = read_line.split.map(&.to_i)
x = k - a.zip(b).sum { |i, j| (i - j).abs }
puts x >= 0 && x.even? ? "Yes" : "No"
AtCoder problem 024

C++ solution:
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int cnt = 0;
  rep(i, n){
    int b; cin >> b;
    cnt += abs(a[i] - b);
  }
  if(k < cnt || (k-cnt) & 1){
    cout << "No\n";
  }else{
    cout << "Yes\n";
  }
}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var k: int :: cui@inputInt()
	var a: []int :: #[n]int
	for i(0, n - 1)
		do a[i] :: cui@inputInt()
	end for
	var b: []int :: #[n]int
	for i(0, n - 1)
		do b[i] :: cui@inputInt()
	end for
	
	var diff: int :: 0
	for i(0, n - 1)
		do diff :+ (a[i] - b[i]).abs()
	end for
	
	var ans: bool :: diff <= k & (diff - k) % 2 = 0
	do cui@print((ans ?("Yes", "No")) ~ "\n")
end func
AtCoder problem 024

C++ solution:

Crystal solution: _, k = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i)
b = read_line.split.map(&.to_i)
x = k - a.zip(b).sum { |i, j| (i - j).abs }
puts x >= 0 && x.even? ? "Yes" : "No"





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var k: int :: cui@inputInt()
	var a: []int :: #[n]int
	for i(0, n - 1)
		do a[i] :: cui@inputInt()
	end for
	var b: []int :: #[n]int
	for i(0, n - 1)
		do b[i] :: cui@inputInt()
	end for
	
	var diff: int :: 0
	for i(0, n - 1)
		do diff :+ (a[i] - b[i]).abs()
	end for
	
	var ans: bool :: diff <= k & (diff - k) % 2 = 0
	do cui@print((ans ?("Yes", "No")) ~ "\n")
end func
AtCoder problem 025

C++ solution:
#include <iostream>
#include <string>
#include <algorithm>
using ll = long long;
#define all(a) (a).begin(), (a).end()
using namespace std;

//50[ms]
ll n,b, ans = 0;
void dfs(string s, int v){
  ll cnt = 1;
  for(char c : s) cnt *= c - '0';
  cnt += b;
  string str = to_string(cnt);
  sort(all(str));
  if(str == s && cnt <= n) ans++;
  if((int)s.size() == 11) return;
  for(int i = v; i < 10; i++){
    dfs(s + char(i + '0'), i);
  }
}
int main(){
  cin >> n >> b;
  dfs("", 1);
  string str = to_string(b);
  for(char &c : str) if(c == '0'){
    if(n >= b) ans++;
    break;
  }
  cout << ans << "\n";
}

Crystal solution: n, b = read_line.split.map(&.to_i64)
puts (1..11).sum { |size|
  (0..9).to_a.repeated_combinations(size).count { |m_ary|
    m = m_ary.reduce(1i64) { |acc, i| acc * i } + b
    1 <= m <= n && m.to_s.chars.map(&.to_i).sort == m_ary
  }
}