puwaer/puwaer_code_translation huggingface dataset:
AtCoder problem 005

C++ solution:
#include <iostream>

using namespace std;



long long modpow(long long a, long long b, long long m) {

	long long p = 1, q = a;

	for (int i = 0; i < 63; i++) {

		if ((b & (1LL << i)) != 0) {

			p *= q;

			p %= m;

		}

		q *= q;

		q %= m;

	}

	return p;

}



const long long mod = 1000000007;



// 入力

long long N, B, K;

long long C[11];



// その他の変数

long long power10[64];

long long DP[64][1009];

long long Answer[64][1009];



int main() {

	// Step #1. 入力

	cin >> N >> B >> K;

	for (int i = 1; i <= K; i++) cin >> C[i];

	

	// Step #2. 前計算

	for (int i = 0; i <= 62; i++) {

		power10[i] = modpow(10LL, (1LL << i), B);

	}

	

	// Step #3. dp[1][i] を求める

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

		DP[0][C[i] % B] += 1;

	}



	// Step #4. dp[1][i], dp[2][i], ..., dp[2^n][i] を求める

	for (int i = 0; i < 62; i++) {

		for (int j = 0; j < B; j++) {

			for (int k = 0; k < B; k++) {

				int nex = (j * power10[i] + k) % B;

				DP[i + 1][nex] += DP[i][j] * DP[i][k];

				DP[i + 1][nex] %= mod;

			}

		}

	}



	// Step #5. 繰り返し二乗法により dp[N][i] を求める

	Answer[0][0] = 1;

	for (int i = 0; i < 62; i++) {

		if ((N & (1LL << i)) != 0LL) {

			for (int j = 0; j < B; j++) {

				for (int k = 0; k < B; k++) {

					int nex = (j * power10[i] + k) % B;

					Answer[i + 1][nex] += Answer[i][j] * DP[i][k];

					Answer[i + 1][nex] %= mod;

				}

			}

		}

		else {

			for (int j = 0; j < B; j++) Answer[i + 1][j] = Answer[i][j];

		}

	}



	// Step #6. 出力

	cout << Answer[62][0] << endl;

	return 0;

}





Kuin solution: func main()
	const mod: int :: 1000000007
	var n: int :: cui@inputInt()
	var b: int :: cui@inputInt()
	var k: int :: cui@inputInt()
	
	var dp: []int :: #[b]int
	for i(0, k - 1)
		var c: int :: cui@inputInt()
		do dp[c % b] :+ 1
	end for
	
	var ans: []int :: #[b]int
	var pow10: int :: 10 % b
	do ans[0] :: 1
	while(n > 0)
		if(n % 2 = 1)
			var ansNext: []int :: #[b]int
			for i(0, b - 1)
				for j(0, b - 1)
					do ansNext[(i * pow10 + j) % b] :+ ans[i] * dp[j]
					do ansNext[(i * pow10 + j) % b] :% mod
				end for
			end for
			do ans :: ansNext
		end if
		block
			var dpNext: []int :: #[b]int
			for i(0, b - 1)
				for j(0, b - 1)
					do dpNext[(i * pow10 + j) % b] :+ dp[i] * dp[j]
					do dpNext[(i * pow10 + j) % b] :% mod
				end for
			end for
			do dp :: dpNext
		end block
		do pow10 :: (pow10 ^ 2) % b
		do n :/ 2
	end while
	do cui@print("\{ans[0]}\n")
end func
AtCoder problem 005

C++ solution:


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
MOD = 10**9 + 7
def main():
    input = sys.stdin.readline
    N, B, K = map(int, input().split())
    *C, = map(int, input().split())

    def f(left, right, shift):
        res = [0] * B
        for lm in range(B):
            for rm in range(B):
                nm = (lm * shift + rm) % B
                res[nm] = (res[nm] + left[lm] * right[rm]) % MOD
        return res

    t = [0] * B

    # 1桁のとき
    for c in C: t[c % B] += 1

    ans = [0] * B
    ans[0] = 1
    shift = 1
    for i in range(N.bit_length()):
        shift = pow(10, 1 << i, B)
        if N & (1 << i):
            ans = f(ans, t, shift)
        t = f(t, t, shift)
    print(ans[0])

if __name__ == '__main__':
    main()




Kuin solution: func main()
	const mod: int :: 1000000007
	var n: int :: cui@inputInt()
	var b: int :: cui@inputInt()
	var k: int :: cui@inputInt()
	
	var dp: []int :: #[b]int
	for i(0, k - 1)
		var c: int :: cui@inputInt()
		do dp[c % b] :+ 1
	end for
	
	var ans: []int :: #[b]int
	var pow10: int :: 10 % b
	do ans[0] :: 1
	while(n > 0)
		if(n % 2 = 1)
			var ansNext: []int :: #[b]int
			for i(0, b - 1)
				for j(0, b - 1)
					do ansNext[(i * pow10 + j) % b] :+ ans[i] * dp[j]
					do ansNext[(i * pow10 + j) % b] :% mod
				end for
			end for
			do ans :: ansNext
		end if
		block
			var dpNext: []int :: #[b]int
			for i(0, b - 1)
				for j(0, b - 1)
					do dpNext[(i * pow10 + j) % b] :+ dp[i] * dp[j]
					do dpNext[(i * pow10 + j) % b] :% mod
				end for
			end for
			do dp :: dpNext
		end block
		do pow10 :: (pow10 ^ 2) % b
		do n :/ 2
	end while
	do cui@print("\{ans[0]}\n")
end func
AtCoder problem 006

C++ solution:
/*
競プロ典型90問　第6問　s
https://atcoder.jp/contests/typical90/submissions/23191468
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<char, int> P;

int N, K;
string s;

int main()
{

	cin >> N >> K;
	cin >> s;

	priority_queue<P, vector<P>, greater<P>> pq;
	//前からN - K + 1個をまず入れる。
	for (int i = 0; i < N - K + 1; i++)
		pq.push(make_pair(s[i], i));

	string ans = "";
	int topIdx = -1;
	for (int i = 0; i < K; i++)
	{
		P top;
		while (true)
		{
			top = pq.top();
			pq.pop();
			if (top.second > topIdx)
				break;
		}
		ans += top.first;
		topIdx = top.second;
		pq.push(make_pair(s[N - K + 1 + i], N - K + 1 + i));
	}
	cout << ans << endl;

	return 0;
}

Crystal solution: n, k = read_line.split.map(&.to_i)
s = read_line
next_index = ('a'..'z').map { |c|
  prev_index = n
  (0...n).reverse_each.map { |i|
    if s[i] == c
      prev_index = i
    else
      prev_index
    end
  }.to_a.reverse
}

index = 0
puts (1..k).join { |size|
  ('a'..'z').find { |char|
    next_index[char - 'a'][index] <= n - (k - size + 1)
  }.not_nil!.tap { |char|
    index = next_index[char - 'a'][index] + 1
  }
}
AtCoder problem 006

C++ solution:

Crystal solution: n, k = read_line.split.map(&.to_i)
s = read_line
next_index = ('a'..'z').map { |c|
  prev_index = n
  (0...n).reverse_each.map { |i|
    if s[i] == c
      prev_index = i
    else
      prev_index
    end
  }.to_a.reverse
}

index = 0
puts (1..k).join { |size|
  ('a'..'z').find { |char|
    next_index[char - 'a'][index] <= n - (k - size + 1)
  }.not_nil!.tap { |char|
    index = next_index[char - 'a'][index] + 1
  }
}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var k: int :: cui@inputInt()
	var s: []char :: cui@input()
	var nextPos: [][]int :: #[n, 26]int
	var pos: []int :: [n].repeat(26)
	for i(n - 1, 0, -1)
		do pos[s[i] $ int - 'a' $ int] :: i
		for j(0, 25)
			do nextPos[i][j] :: pos[j]
		end for
	end for
	var p: int :: 0
	var ans: []char :: #[k]char
	for i(0, k - 1)
		for j(0, 25)
			var remains: int :: n - 1 - nextPos[p][j]
			if(remains >= k - 1 - i)
				do ans[i] :: 'a'.offset(j)
				do p :: nextPos[p][j] + 1
				break j
			end if
		end for
	end for
	do cui@print("\{ans}\n")
end func
AtCoder problem 006

C++ solution:
/*
競プロ典型90問　第6問　s
https://atcoder.jp/contests/typical90/submissions/23191468
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<char, int> P;

int N, K;
string s;

int main()
{

	cin >> N >> K;
	cin >> s;

	priority_queue<P, vector<P>, greater<P>> pq;
	//前からN - K + 1個をまず入れる。
	for (int i = 0; i < N - K + 1; i++)
		pq.push(make_pair(s[i], i));

	string ans = "";
	int topIdx = -1;
	for (int i = 0; i < K; i++)
	{
		P top;
		while (true)
		{
			top = pq.top();
			pq.pop();
			if (top.second > topIdx)
				break;
		}
		ans += top.first;
		topIdx = top.second;
		pq.push(make_pair(s[N - K + 1 + i], N - K + 1 + i));
	}
	cout << ans << endl;

	return 0;
}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var k: int :: cui@inputInt()
	var s: []char :: cui@input()
	var nextPos: [][]int :: #[n, 26]int
	var pos: []int :: [n].repeat(26)
	for i(n - 1, 0, -1)
		do pos[s[i] $ int - 'a' $ int] :: i
		for j(0, 25)
			do nextPos[i][j] :: pos[j]
		end for
	end for
	var p: int :: 0
	var ans: []char :: #[k]char
	for i(0, k - 1)
		for j(0, 25)
			var remains: int :: n - 1 - nextPos[p][j]
			if(remains >= k - 1 - i)
				do ans[i] :: 'a'.offset(j)
				do p :: nextPos[p][j] + 1
				break j
			end if
		end for
	end for
	do cui@print("\{ans}\n")
end func
AtCoder problem 007

C++ solution:
#include <iostream>

#include <algorithm>

#include <cmath>

using namespace std;



const int INF = 2000000000;

int N;

int A[300009];

int Q;

int B[300009];



int main() {

	// Step #1. Input

	cin >> N;

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

	cin >> Q;

	for (int i = 1; i <= Q; i++) cin >> B[i];



	// Step #2. Sorting

	sort(A + 1, A + N + 1);



	// Step #3. Binary Search

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

		int pos1 = lower_bound(A + 1, A + N + 1, B[i]) - A;

		int Diff1 = INF, Diff2 = INF;

		if (pos1 <= N) Diff1 = abs(B[i] - A[pos1]);

		if (pos1 >= 2) Diff2 = abs(B[i] - A[pos1 - 1]);

		cout << min(Diff1, Diff2) << endl;

	}

	return 0;

}



Crystal solution: read_line
a = [-2*10**9] + read_line.split.map(&.to_i).sort + [2*10**9]
read_line.to_i.times do
  b = read_line.to_i
  i = a.bsearch_index { |x| x > b }.not_nil!
  puts a[i - 1..i + 1].min_of { |x| (b - x).abs }
end
AtCoder problem 007

C++ solution:
#include <iostream>

#include <algorithm>

#include <cmath>

using namespace std;



const int INF = 2000000000;

int N;

int A[300009];

int Q;

int B[300009];



int main() {

	// Step #1. Input

	cin >> N;

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

	cin >> Q;

	for (int i = 1; i <= Q; i++) cin >> B[i];



	// Step #2. Sorting

	sort(A + 1, A + N + 1);



	// Step #3. Binary Search

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

		int pos1 = lower_bound(A + 1, A + N + 1, B[i]) - A;

		int Diff1 = INF, Diff2 = INF;

		if (pos1 <= N) Diff1 = abs(B[i] - A[pos1]);

		if (pos1 >= 2) Diff2 = abs(B[i] - A[pos1 - 1]);

		cout << min(Diff1, Diff2) << endl;

	}

	return 0;

}




Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from bisect import bisect_left
N = int(input())
*A, = map(int, input().split())
Q = int(input())
A.sort()
for _ in range(Q):
    b = int(input())
    i = bisect_left(A, b)
    u = 10**18
    if i < N:
        u = min(u, abs(A[i] - b))
    if i > 0:
        u = min(u, abs(A[i - 1] - b))
    print(u)
AtCoder problem 007

C++ solution:
#include <iostream>

#include <algorithm>

#include <cmath>

using namespace std;



const int INF = 2000000000;

int N;

int A[300009];

int Q;

int B[300009];



int main() {

	// Step #1. Input

	cin >> N;

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

	cin >> Q;

	for (int i = 1; i <= Q; i++) cin >> B[i];



	// Step #2. Sorting

	sort(A + 1, A + N + 1);



	// Step #3. Binary Search

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

		int pos1 = lower_bound(A + 1, A + N + 1, B[i]) - A;

		int Diff1 = INF, Diff2 = INF;

		if (pos1 <= N) Diff1 = abs(B[i] - A[pos1]);

		if (pos1 >= 2) Diff2 = abs(B[i] - A[pos1 - 1]);

		cout << min(Diff1, Diff2) << endl;

	}

	return 0;

}







Kuin solution: func main()
	var n: int :: cui@inputInt()
	
	var a: []int :: #[n]int
	for i(0, n - 1)
		do a[i] :: cui@inputInt()
	end for
	do a.sort()
	
	var q: int :: cui@inputInt()
	for(1, q)
		var b: int :: cui@inputInt()
		var ok: int :: 0
		var ng: int :: n
		while((ok - ng).abs() > 1)
			var mid: int :: (ok + ng) / 2
			if(a[mid] <= b)
				do ok :: mid
			else
				do ng :: mid
			end if
		end while
		
		var ans: int :: (b - a[ok]).abs()
		if(ok <> n - 1)
			do ans :: [ans, a[ok + 1] - b].min()
		end if
		do cui@print("\{ans}\n")
	end for
end func
AtCoder problem 007

C++ solution:

Crystal solution: read_line
a = [-2*10**9] + read_line.split.map(&.to_i).sort + [2*10**9]
read_line.to_i.times do
  b = read_line.to_i
  i = a.bsearch_index { |x| x > b }.not_nil!
  puts a[i - 1..i + 1].min_of { |x| (b - x).abs }
end


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from bisect import bisect_left
N = int(input())
*A, = map(int, input().split())
Q = int(input())
A.sort()
for _ in range(Q):
    b = int(input())
    i = bisect_left(A, b)
    u = 10**18
    if i < N:
        u = min(u, abs(A[i] - b))
    if i > 0:
        u = min(u, abs(A[i - 1] - b))
    print(u)
AtCoder problem 007

C++ solution:

Crystal solution: read_line
a = [-2*10**9] + read_line.split.map(&.to_i).sort + [2*10**9]
read_line.to_i.times do
  b = read_line.to_i
  i = a.bsearch_index { |x| x > b }.not_nil!
  puts a[i - 1..i + 1].min_of { |x| (b - x).abs }
end





Kuin solution: func main()
	var n: int :: cui@inputInt()
	
	var a: []int :: #[n]int
	for i(0, n - 1)
		do a[i] :: cui@inputInt()
	end for
	do a.sort()
	
	var q: int :: cui@inputInt()
	for(1, q)
		var b: int :: cui@inputInt()
		var ok: int :: 0
		var ng: int :: n
		while((ok - ng).abs() > 1)
			var mid: int :: (ok + ng) / 2
			if(a[mid] <= b)
				do ok :: mid
			else
				do ng :: mid
			end if
		end while
		
		var ans: int :: (b - a[ok]).abs()
		if(ok <> n - 1)
			do ans :: [ans, a[ok + 1] - b].min()
		end if
		do cui@print("\{ans}\n")
	end for
end func
AtCoder problem 007

C++ solution:


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from bisect import bisect_left
N = int(input())
*A, = map(int, input().split())
Q = int(input())
A.sort()
for _ in range(Q):
    b = int(input())
    i = bisect_left(A, b)
    u = 10**18
    if i < N:
        u = min(u, abs(A[i] - b))
    if i > 0:
        u = min(u, abs(A[i - 1] - b))
    print(u)




Kuin solution: func main()
	var n: int :: cui@inputInt()
	
	var a: []int :: #[n]int
	for i(0, n - 1)
		do a[i] :: cui@inputInt()
	end for
	do a.sort()
	
	var q: int :: cui@inputInt()
	for(1, q)
		var b: int :: cui@inputInt()
		var ok: int :: 0
		var ng: int :: n
		while((ok - ng).abs() > 1)
			var mid: int :: (ok + ng) / 2
			if(a[mid] <= b)
				do ok :: mid
			else
				do ng :: mid
			end if
		end while
		
		var ans: int :: (b - a[ok]).abs()
		if(ok <> n - 1)
			do ans :: [ans, a[ok + 1] - b].min()
		end if
		do cui@print("\{ans}\n")
	end for
end func
AtCoder problem 008

C++ solution:
#include <iostream>
#include <string>
#include <vector>
#define mod 1000000007
using namespace std;

//19[ms]
string t = "atcoder";
int main(){
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> dp(8, vector<int>(n + 1));
  for(int i = 0; i <= n; i++) dp[0][i] = 1;
  for(int i = 0; i < 7; i++){
    for(int j = 0; j < n; j++){
      if(t[i] == s[j]){
        dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + 1] %= mod;
      }
      dp[i + 1][j + 1] += dp[i + 1][j];
      dp[i + 1][j + 1] %= mod;
    }
  }
  cout << dp[7][n] << "\n";
}

Crystal solution: read_line
s = read_line

atcoder = "?atcoder"
m = atcoder.size
puts s.chars.each_with_object([1] + [0] * m.pred) { |c, dp|
  if i = atcoder.index(c)
    dp[i] = (dp[i] + dp[i - 1]) % (10**9 + 7)
  end
}.last
AtCoder problem 008

C++ solution:
#include <iostream>
#include <string>
#include <vector>
#define mod 1000000007
using namespace std;

//19[ms]
string t = "atcoder";
int main(){
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> dp(8, vector<int>(n + 1));
  for(int i = 0; i <= n; i++) dp[0][i] = 1;
  for(int i = 0; i < 7; i++){
    for(int j = 0; j < n; j++){
      if(t[i] == s[j]){
        dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + 1] %= mod;
      }
      dp[i + 1][j + 1] += dp[i + 1][j];
      dp[i + 1][j + 1] %= mod;
    }
  }
  cout << dp[7][n] << "\n";
}


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from collections import defaultdict
MOD = 10**9 + 7
N = int(input())
S = input()
C = defaultdict(int)
ATCODER = 'atcoder'
dp = [0] * len(ATCODER)
for s in S[::-1]:
    if s in ATCODER:
        i = ATCODER.index(s)
        if i == len(ATCODER) - 1:
            dp[i] += 1
        else:
            dp[i] = (dp[i] + dp[i + 1]) % MOD
print(dp[0])
AtCoder problem 008

C++ solution:
#include <iostream>
#include <string>
#include <vector>
#define mod 1000000007
using namespace std;

//19[ms]
string t = "atcoder";
int main(){
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> dp(8, vector<int>(n + 1));
  for(int i = 0; i <= n; i++) dp[0][i] = 1;
  for(int i = 0; i < 7; i++){
    for(int j = 0; j < n; j++){
      if(t[i] == s[j]){
        dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + 1] %= mod;
      }
      dp[i + 1][j + 1] += dp[i + 1][j];
      dp[i + 1][j + 1] %= mod;
    }
  }
  cout << dp[7][n] << "\n";
}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var s: []char :: cui@input()
	var atcoder: []char :: "atcoder"
	
	var dp: []int :: #[^atcoder + 1]int
	do dp[0] :: 1
	for i(0, n - 1)
		for j(0, ^atcoder - 1)
			if(s[i] = atcoder[j])
				do dp[j + 1] :+ dp[j]
				do dp[j + 1] :% 10 ^ 9 + 7
			end if
		end for
	end for
	
	var ans: int :: dp[^atcoder]
	do cui@print("\{ans}\n")
end func
AtCoder problem 008

C++ solution:

Crystal solution: read_line
s = read_line

atcoder = "?atcoder"
m = atcoder.size
puts s.chars.each_with_object([1] + [0] * m.pred) { |c, dp|
  if i = atcoder.index(c)
    dp[i] = (dp[i] + dp[i - 1]) % (10**9 + 7)
  end
}.last


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from collections import defaultdict
MOD = 10**9 + 7
N = int(input())
S = input()
C = defaultdict(int)
ATCODER = 'atcoder'
dp = [0] * len(ATCODER)
for s in S[::-1]:
    if s in ATCODER:
        i = ATCODER.index(s)
        if i == len(ATCODER) - 1:
            dp[i] += 1
        else:
            dp[i] = (dp[i] + dp[i + 1]) % MOD
print(dp[0])
AtCoder problem 008

C++ solution:

Crystal solution: read_line
s = read_line

atcoder = "?atcoder"
m = atcoder.size
puts s.chars.each_with_object([1] + [0] * m.pred) { |c, dp|
  if i = atcoder.index(c)
    dp[i] = (dp[i] + dp[i - 1]) % (10**9 + 7)
  end
}.last





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var s: []char :: cui@input()
	var atcoder: []char :: "atcoder"
	
	var dp: []int :: #[^atcoder + 1]int
	do dp[0] :: 1
	for i(0, n - 1)
		for j(0, ^atcoder - 1)
			if(s[i] = atcoder[j])
				do dp[j + 1] :+ dp[j]
				do dp[j + 1] :% 10 ^ 9 + 7
			end if
		end for
	end for
	
	var ans: int :: dp[^atcoder]
	do cui@print("\{ans}\n")
end func
AtCoder problem 008

C++ solution:


Python solution: # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from collections import defaultdict
MOD = 10**9 + 7
N = int(input())
S = input()
C = defaultdict(int)
ATCODER = 'atcoder'
dp = [0] * len(ATCODER)
for s in S[::-1]:
    if s in ATCODER:
        i = ATCODER.index(s)
        if i == len(ATCODER) - 1:
            dp[i] += 1
        else:
            dp[i] = (dp[i] + dp[i + 1]) % MOD
print(dp[0])




Kuin solution: func main()
	var n: int :: cui@inputInt()
	var s: []char :: cui@input()
	var atcoder: []char :: "atcoder"
	
	var dp: []int :: #[^atcoder + 1]int
	do dp[0] :: 1
	for i(0, n - 1)
		for j(0, ^atcoder - 1)
			if(s[i] = atcoder[j])
				do dp[j + 1] :+ dp[j]
				do dp[j + 1] :% 10 ^ 9 + 7
			end if
		end for
	end for
	
	var ans: int :: dp[^atcoder]
	do cui@print("\{ans}\n")
end func
AtCoder problem 009

C++ solution:
#include <iostream>

#include <cmath>

#include <vector>

#include <algorithm>

using namespace std;



struct Point {

	double px, py;

};



Point operator-(const Point& a1, const Point& a2) {

	return Point{ a1.px - a2.px, a1.py - a2.py };

}



double getangle(Point G) {

	// 点 G の偏角を求める

	if (G.py >= 0.0) {

		double I = G.px / sqrt(G.px * G.px + G.py * G.py);

		double kaku = acos(I) * 180.0 / 3.14159265358979;

		return kaku;

	}

	else {

		double I = G.px / sqrt(G.px * G.px + G.py * G.py);

		double kaku = acos(I) * 180.0 / 3.14159265358979;

		return 360.0 - kaku;

	}

}



double getangle2(double I1, double I2) {

	// [偏角 I1] - [原点] - [偏角 I2] のなす角度を求める

	// 例えば I1 = 240°、I2 = 30°のとき、求める角度は 150°

	double res = abs(I1 - I2);

	if (res >= 180.0) return 360.0 - res;

	return res;

}



int N;

Point G[2009];



double solve(int pos) {

	// 最初に偏角の昇順にソートする

	vector<double> vec;

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

		if (i == pos) continue;

		Point SA = G[i] - G[pos];

		double angle = getangle(SA);

		vec.push_back(angle);

	}

	sort(vec.begin(), vec.end());



	// 点 A を全探索して、最も偏角の大きくなる点 C を二分探索（std::lower_bound）で求める

	double ret = 0.0;

	for (int i = 0; i < vec.size(); i++) {

		double target = vec[i] + 180.0;

		if (target >= 360.0) target -= 360.0;

		int pos1 = lower_bound(vec.begin(), vec.end(), target) - vec.begin();



		// 点 C の候補は高々 2 つに絞れる

		int CandIdx1 = pos1 % vec.size();

		int CandIdx2 = (pos1 + vec.size() - 1) % vec.size();

		double Candidate1 = getangle2(vec[i], vec[CandIdx1]);

		double Candidate2 = getangle2(vec[i], vec[CandIdx2]);

		ret = max({ ret, Candidate1, Candidate2 });

	}

	return ret;

}



// O(N^3) のアルゴリズム（点 A, B, C を全探索）

double solve_Slow() {

	double Answer = 0.0;

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

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

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

				if (i == j || i == k || j == k) continue;

				double I1 = getangle(G[i] - G[j]);

				double I2 = getangle(G[k] - G[j]);

				Answer = max(Answer, getangle2(I1, I2));

			}

		}

	}

	return Answer;

}



// O(N^2 log N) のアルゴリズム

double solve_Fast() {

	// 点 B を全探索

	double Answer = 0.0;

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

		double ret = solve(i);

		Answer = max(Answer, ret);

	}

	return Answer;

}



int main() {

	// Step #1. 入力

	cin >> N;

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

		cin >> G[i].px >> G[i].py;

	}



	// Step #2. 出力

	double FinalAns = solve_Fast();

	printf("%.12lf\n", FinalAns);

	return 0;

}

Crystal solution: # 0.36.0 以降は Math::TAU があります
TAU = Math::PI * 2
n = read_line.to_i
xy = (1..n).map {
  {Int32, Int32}.from read_line.split.map(&.to_i)
}
puts (0...n).max_of { |i|
  angle = (0...n).select { |j| i != j }.map { |j|
    Math.atan2(xy[j][1] - xy[i][1], xy[j][0] - xy[i][0])
  }
  angles = angle.flat_map { |a| [a, a + Math::PI * 2] }.sort
  angle.max_of { |a|
    index = angles.bsearch_index { |b| b >= a + Math::PI }.not_nil!
    {angles[index - 1], angles[index]}.max_of { |b|
      res = (b - a) % TAU
      res > Math::PI ? Math::PI - res : res
    }
  }
} * 360 / TAU