puwaer/puwaer_code_translation huggingface dataset:
AtCoder problem 073

C++ solution:
#include <iostream>

#include <vector>

using namespace std;



long long N, A[1 << 18], B[1 << 18];

char C[1 << 18];



long long mod = 1000000007;

long long dp[1 << 18][3];

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



void dfs(int pos, int pre) {

	long long val1 = 1, val2 = 1;

	for (int i : G[pos]) {

		if (i == pre) continue;

		dfs(i, pos);

		if (C[pos] == 'a') {

			val1 *= (dp[i][0] + dp[i][2]);

			val2 *= (dp[i][0] + dp[i][1] + 2LL * dp[i][2]);

		}

		if (C[pos] == 'b') {

			val1 *= (dp[i][1] + dp[i][2]);

			val2 *= (dp[i][0] + dp[i][1] + 2LL * dp[i][2]);

		}

		val1 %= mod;

		val2 %= mod;

	}



	if (C[pos] == 'a') {

		dp[pos][0] = val1;

		dp[pos][2] = (val2 - val1 + mod) % mod;

	}

	if (C[pos] == 'b') {

		dp[pos][1] = val1;

		dp[pos][2] = (val2 - val1 + mod) % mod;

	}

}



int main() {

	// Step #1. Input

	cin >> N;

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

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

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

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

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

	}



	// Step #2. DFS

	dfs(1, -1);

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

	return 0;

}





Kuin solution: var dp: [][]int
var c: []char

func main()
	const mod: int :: 1000000007
	var n: int :: cui@inputInt()
	do @c :: #[n]char
	for i(0, n - 1)
		do @c[i] :: cui@inputChar()
	end for
	var g: []list<int> :: #[n]list<int>
	for i(0, n - 1)
		do g[i] :: #list<int>
	end for
	for(1, n - 1)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		do g[a].add(b)
		do g[b].add(a)
	end for
	
	do @dp :: #[n, 3]int
	do dfs(g, 0, -1)
	var ans: int :: @dp[0][2]
	do cui@print("\{ans}\n")
	
	func dfs(g: []list<int>, u: int, p: int)
		var x: int :: @c[u] $ int - 'a' $ int
		do @dp[u][x] :: 1
		do @dp[u][2] :: 1
		do g[u].head()
		for(1, ^g[u])
			var v: int :: g[u].get()
			if(v <> p)
				do dfs(g, v, u)
				var v2: int :: @dp[v][x] + @dp[v][2]
				var v3: int :: @dp[v][0] + @dp[v][1] + 2 * @dp[v][2]
				do @dp[u][x] :* v2
				do @dp[u][x] :% mod
				do @dp[u][2] :* v3
				do @dp[u][2] :% mod
			end if
			do g[u].next()
		end for
		do @dp[u][2] :+ mod - @dp[u][x]
		do @dp[u][2] :% mod
	end func
end func
AtCoder problem 073

C++ solution:

Crystal solution: MOD = 10**9 + 7

class Graph
  def initialize(size, @color : Array(Char))
    @graph = Array(Array(Int32)).new(size) { [] of Int32 }
  end

  def add_edge(u, v)
    @graph[u] << v
    @graph[v] << u
  end

  def run
    dfs(0, -1)[2] % MOD
  end

  def dfs(v, p)
    val1, val2 = 1i64, 1i64
    @graph[v].each do |u|
      next if u == p
      a, b, ab = dfs(u, v)
      val1 *= (@color[v] == 'a' ? a : b) + ab
      val2 *= a + b + ab * 2
      val1 %= MOD
      val2 %= MOD
    end

    if @color[v] == 'a'
      {val1, 0i64, val2 - val1}
    else
      {0i64, val1, val2 - val1}
    end
  end
end

n = read_line.to_i
c = read_line.split.map(&.[0])
g = Graph.new(n, c)
n.pred.times do
  a, b = read_line.split.map(&.to_i.pred)
  g.add_edge(a, b)
end
puts g.run





Kuin solution: var dp: [][]int
var c: []char

func main()
	const mod: int :: 1000000007
	var n: int :: cui@inputInt()
	do @c :: #[n]char
	for i(0, n - 1)
		do @c[i] :: cui@inputChar()
	end for
	var g: []list<int> :: #[n]list<int>
	for i(0, n - 1)
		do g[i] :: #list<int>
	end for
	for(1, n - 1)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		do g[a].add(b)
		do g[b].add(a)
	end for
	
	do @dp :: #[n, 3]int
	do dfs(g, 0, -1)
	var ans: int :: @dp[0][2]
	do cui@print("\{ans}\n")
	
	func dfs(g: []list<int>, u: int, p: int)
		var x: int :: @c[u] $ int - 'a' $ int
		do @dp[u][x] :: 1
		do @dp[u][2] :: 1
		do g[u].head()
		for(1, ^g[u])
			var v: int :: g[u].get()
			if(v <> p)
				do dfs(g, v, u)
				var v2: int :: @dp[v][x] + @dp[v][2]
				var v3: int :: @dp[v][0] + @dp[v][1] + 2 * @dp[v][2]
				do @dp[u][x] :* v2
				do @dp[u][x] :% mod
				do @dp[u][2] :* v3
				do @dp[u][2] :% mod
			end if
			do g[u].next()
		end for
		do @dp[u][2] :+ mod - @dp[u][x]
		do @dp[u][2] :% mod
	end func
end func
AtCoder problem 074

C++ solution:
#include <iostream>

using namespace std;



long long N, Answer = 0;

string S;



int main() {

	cin >> N >> S;

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

		if (S[i] == 'b') Answer += 1LL * (1LL << i);

		if (S[i] == 'c') Answer += 2LL * (1LL << i);

	}

	cout << Answer << endl;

	return 0;

}

Crystal solution: read_line
s = read_line.chars
puts s.each_with_index.sum { |c, i|
  2i64**i * (c - 'a')
}
AtCoder problem 074

C++ solution:
#include <iostream>

using namespace std;



long long N, Answer = 0;

string S;



int main() {

	cin >> N >> S;

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

		if (S[i] == 'b') Answer += 1LL * (1LL << i);

		if (S[i] == 'c') Answer += 2LL * (1LL << i);

	}

	cout << Answer << endl;

	return 0;

}


Python solution: n = int(input())
s = input()
num = [ord(i) - 97 for i in s]

ans = 0
for i, j in enumerate(num):
    if j == 0: continue
    if j == 1:
        ans += 2 ** i
    elif j == 2:
        ans += 2 ** (i + 1)
print(ans)
AtCoder problem 074

C++ solution:

Crystal solution: read_line
s = read_line.chars
puts s.each_with_index.sum { |c, i|
  2i64**i * (c - 'a')
}


Python solution: n = int(input())
s = input()
num = [ord(i) - 97 for i in s]

ans = 0
for i, j in enumerate(num):
    if j == 0: continue
    if j == 1:
        ans += 2 ** i
    elif j == 2:
        ans += 2 ** (i + 1)
print(ans)
AtCoder problem 075

C++ solution:
#include <iostream>

#include <vector>

using namespace std;



vector<long long> prime_factors(long long N) {

	long long rem = N;

	vector<long long> p;

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

		while (rem % i == 0) {

			rem /= i;

			p.push_back(i);

		}

	}

	if (rem != 1LL) p.push_back(rem);

	return p;

}



int main() {

	// Step #1. Input

	long long N;

	cin >> N;

	

	// Step #2. Get Answer

	int Answer = 0;

	vector<long long> vec = prime_factors(N);

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

		if ((1 << i) >= (int)vec.size()) { Answer = i; break; }

	}

	cout << Answer << endl;

	return 0;

}

Crystal solution: n = read_line.to_i64
now, cnt = n, 0
(2i64..).each do |x|
  break if x * x > n
  while now % x == 0
    now //= x
    cnt += 1
  end
end
cnt += 1 if now != 1
puts Math.log2(cnt).ceil.to_i
AtCoder problem 075

C++ solution:
#include <iostream>

#include <vector>

using namespace std;



vector<long long> prime_factors(long long N) {

	long long rem = N;

	vector<long long> p;

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

		while (rem % i == 0) {

			rem /= i;

			p.push_back(i);

		}

	}

	if (rem != 1LL) p.push_back(rem);

	return p;

}



int main() {

	// Step #1. Input

	long long N;

	cin >> N;

	

	// Step #2. Get Answer

	int Answer = 0;

	vector<long long> vec = prime_factors(N);

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

		if ((1 << i) >= (int)vec.size()) { Answer = i; break; }

	}

	cout << Answer << endl;

	return 0;

}


Python solution: def factorization(n):
    arr = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append([i, cnt])
    if tmp != 1:
        arr.append([tmp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

num = sum(i[1] for i in factorization(int(input())))
if num == 1:
    print(0)
else:
    i = 0
    while True:
        if num <= 2 ** i:
            break
        i += 1
    print(i)
AtCoder problem 075

C++ solution:
#include <iostream>

#include <vector>

using namespace std;



vector<long long> prime_factors(long long N) {

	long long rem = N;

	vector<long long> p;

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

		while (rem % i == 0) {

			rem /= i;

			p.push_back(i);

		}

	}

	if (rem != 1LL) p.push_back(rem);

	return p;

}



int main() {

	// Step #1. Input

	long long N;

	cin >> N;

	

	// Step #2. Get Answer

	int Answer = 0;

	vector<long long> vec = prime_factors(N);

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

		if ((1 << i) >= (int)vec.size()) { Answer = i; break; }

	}

	cout << Answer << endl;

	return 0;

}






Ruby solution: p Math.log2(`factor`.count(' ')).ceil
AtCoder problem 075

C++ solution:
#include <iostream>

#include <vector>

using namespace std;



vector<long long> prime_factors(long long N) {

	long long rem = N;

	vector<long long> p;

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

		while (rem % i == 0) {

			rem /= i;

			p.push_back(i);

		}

	}

	if (rem != 1LL) p.push_back(rem);

	return p;

}



int main() {

	// Step #1. Input

	long long N;

	cin >> N;

	

	// Step #2. Get Answer

	int Answer = 0;

	vector<long long> vec = prime_factors(N);

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

		if ((1 << i) >= (int)vec.size()) { Answer = i; break; }

	}

	cout << Answer << endl;

	return 0;

}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var primeFactors: []int :: math@primeFactors(n)
	var num: int :: ^primeFactors
	var ans: int :: 0
	while(num <> 1)
		do num :: (num + 1) / 2
		do ans :+ 1
	end while
	do cui@print("\{ans}\n")
end func
AtCoder problem 075

C++ solution:

Crystal solution: n = read_line.to_i64
now, cnt = n, 0
(2i64..).each do |x|
  break if x * x > n
  while now % x == 0
    now //= x
    cnt += 1
  end
end
cnt += 1 if now != 1
puts Math.log2(cnt).ceil.to_i


Python solution: def factorization(n):
    arr = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append([i, cnt])
    if tmp != 1:
        arr.append([tmp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

num = sum(i[1] for i in factorization(int(input())))
if num == 1:
    print(0)
else:
    i = 0
    while True:
        if num <= 2 ** i:
            break
        i += 1
    print(i)
AtCoder problem 075

C++ solution:

Crystal solution: n = read_line.to_i64
now, cnt = n, 0
(2i64..).each do |x|
  break if x * x > n
  while now % x == 0
    now //= x
    cnt += 1
  end
end
cnt += 1 if now != 1
puts Math.log2(cnt).ceil.to_i






Ruby solution: p Math.log2(`factor`.count(' ')).ceil
AtCoder problem 075

C++ solution:

Crystal solution: n = read_line.to_i64
now, cnt = n, 0
(2i64..).each do |x|
  break if x * x > n
  while now % x == 0
    now //= x
    cnt += 1
  end
end
cnt += 1 if now != 1
puts Math.log2(cnt).ceil.to_i





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var primeFactors: []int :: math@primeFactors(n)
	var num: int :: ^primeFactors
	var ans: int :: 0
	while(num <> 1)
		do num :: (num + 1) / 2
		do ans :+ 1
	end while
	do cui@print("\{ans}\n")
end func
AtCoder problem 075

C++ solution:


Python solution: def factorization(n):
    arr = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append([i, cnt])
    if tmp != 1:
        arr.append([tmp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

num = sum(i[1] for i in factorization(int(input())))
if num == 1:
    print(0)
else:
    i = 0
    while True:
        if num <= 2 ** i:
            break
        i += 1
    print(i)




Ruby solution: p Math.log2(`factor`.count(' ')).ceil
AtCoder problem 075

C++ solution:


Python solution: def factorization(n):
    arr = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            arr.append([i, cnt])
    if tmp != 1:
        arr.append([tmp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

num = sum(i[1] for i in factorization(int(input())))
if num == 1:
    print(0)
else:
    i = 0
    while True:
        if num <= 2 ** i:
            break
        i += 1
    print(i)



Kuin solution: func main()
	var n: int :: cui@inputInt()
	var primeFactors: []int :: math@primeFactors(n)
	var num: int :: ^primeFactors
	var ans: int :: 0
	while(num <> 1)
		do num :: (num + 1) / 2
		do ans :+ 1
	end while
	do cui@print("\{ans}\n")
end func
AtCoder problem 075

C++ solution:





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var primeFactors: []int :: math@primeFactors(n)
	var num: int :: ^primeFactors
	var ans: int :: 0
	while(num <> 1)
		do num :: (num + 1) / 2
		do ans :+ 1
	end while
	do cui@print("\{ans}\n")
end func


Ruby solution: p Math.log2(`factor`.count(' ')).ceil
AtCoder problem 076

C++ solution:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#define fs(n) fixed << setprecision(n)
#define mp(a, b) make_pair(a, b)
using ll = long long;
using ld = long double;

int main(){
  int n; cin >> n;
  // {A1～An} + {A1～An} from the beginning
  vector<ll> a(n * 2);
  ll sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
    a[i + n] = a[i];
  }
  // Two-Pointer Technique
  int l = 0, r = 0;
  ll t = a[0];
  while(true){
    if(t * 10 == sum){
      cout << "Yes" << endl;
      return 0;
    }
    r++;
    if(r >= n * 2) break;
    t += a[r];
    if(t * 10 > sum){
      t -= a[l];
      l++;
    }
  }
  cout << "No" << endl;
}

Crystal solution: n = read_line.to_i
a = read_line.split.map(&.to_i64) * 2
sum = a.sum // 2

culsum = a.each_with_object([0i64]) do |x, culsum|
  culsum << culsum[-1] + x
end

puts (0...n).any? { |i|
  pos = (i...2*n).bsearch { |j| (culsum[j] - culsum[i]) * 10 >= sum }
  pos && (culsum[pos] - culsum[i]) * 10 == sum
} ? "Yes" : "No"
AtCoder problem 076

C++ solution:

Crystal solution: n = read_line.to_i
a = read_line.split.map(&.to_i64) * 2
sum = a.sum // 2

culsum = a.each_with_object([0i64]) do |x, culsum|
  culsum << culsum[-1] + x
end

puts (0...n).any? { |i|
  pos = (i...2*n).bsearch { |j| (culsum[j] - culsum[i]) * 10 >= sum }
  pos && (culsum[pos] - culsum[i]) * 10 == sum
} ? "Yes" : "No"


Python solution: from bisect import bisect_left
n = int(input())
a = list(map(int,input().split()))

# 入力は整数なので10分の1も整数でなければNoになる
if sum(a) % 10 != 0:
    exit(print("No"))

# 目標となる1/10の値
num = sum(a) // 10

# 前からの累積和と後ろからの累積和
x, y = [a[0]], [a[-1]]
for i in range(n - 1):
    x.append(a[i + 1] + x[-1])
    y.append(a[-2 - i] + y[-1])

for i in range(n):
    # 目的の大きさと一致した場合
    if x[i] == num:
        exit(print("Yes"))
    # 目的の大きさより多く選んでしまった場合
    elif x[i] > num:
        j = bisect_left(x, x[i] - num) # 余分な分を二分探索
        if x[i] - x[j] == num:
            exit(print("Yes"))
    # 目的の大きさより小さい場合は後ろから持ってくる
    elif x[i] < num:
        j = bisect_left(y, num - x[i]) # 後ろから二分探索
        if x[i] + y[j] == num:
            exit(print("Yes"))

print("No")
AtCoder problem 076

C++ solution:

Crystal solution: n = read_line.to_i
a = read_line.split.map(&.to_i64) * 2
sum = a.sum // 2

culsum = a.each_with_object([0i64]) do |x, culsum|
  culsum << culsum[-1] + x
end

puts (0...n).any? { |i|
  pos = (i...2*n).bsearch { |j| (culsum[j] - culsum[i]) * 10 >= sum }
  pos && (culsum[pos] - culsum[i]) * 10 == sum
} ? "Yes" : "No"





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var a: []int :: #[2 * n]int
	var sum: int :: 0
	for i(0, n - 1)
		var x: int :: cui@inputInt()
		do a[i] :: x
		do a[n + i] :: x
		do sum :+ x
	end for
	
	var ans: bool :: false
	if(sum % 10 = 0)
		do sum :/ 10
		var l: int :: 0
		var r: int :: 0
		var sum2: int :: 0
		while loop(l <> 2 * n)
			if(sum2 < sum & r <> 2 * n)
				do sum2 :+ a[r]
				if(sum2 = sum)
					do ans :: true
					break loop
				end if
				do r :+ 1
			else
				do sum2 :- a[l]
				do l :+ 1
			end if
		end while
	end if
	do cui@print((ans ?("Yes", "No")) ~ "\n")
end func
AtCoder problem 076

C++ solution:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#define fs(n) fixed << setprecision(n)
#define mp(a, b) make_pair(a, b)
using ll = long long;
using ld = long double;

int main(){
  int n; cin >> n;
  // {A1～An} + {A1～An} from the beginning
  vector<ll> a(n * 2);
  ll sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
    a[i + n] = a[i];
  }
  // Two-Pointer Technique
  int l = 0, r = 0;
  ll t = a[0];
  while(true){
    if(t * 10 == sum){
      cout << "Yes" << endl;
      return 0;
    }
    r++;
    if(r >= n * 2) break;
    t += a[r];
    if(t * 10 > sum){
      t -= a[l];
      l++;
    }
  }
  cout << "No" << endl;
}


Python solution: from bisect import bisect_left
n = int(input())
a = list(map(int,input().split()))

# 入力は整数なので10分の1も整数でなければNoになる
if sum(a) % 10 != 0:
    exit(print("No"))

# 目標となる1/10の値
num = sum(a) // 10

# 前からの累積和と後ろからの累積和
x, y = [a[0]], [a[-1]]
for i in range(n - 1):
    x.append(a[i + 1] + x[-1])
    y.append(a[-2 - i] + y[-1])

for i in range(n):
    # 目的の大きさと一致した場合
    if x[i] == num:
        exit(print("Yes"))
    # 目的の大きさより多く選んでしまった場合
    elif x[i] > num:
        j = bisect_left(x, x[i] - num) # 余分な分を二分探索
        if x[i] - x[j] == num:
            exit(print("Yes"))
    # 目的の大きさより小さい場合は後ろから持ってくる
    elif x[i] < num:
        j = bisect_left(y, num - x[i]) # 後ろから二分探索
        if x[i] + y[j] == num:
            exit(print("Yes"))

print("No")
AtCoder problem 076

C++ solution:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#define fs(n) fixed << setprecision(n)
#define mp(a, b) make_pair(a, b)
using ll = long long;
using ld = long double;

int main(){
  int n; cin >> n;
  // {A1～An} + {A1～An} from the beginning
  vector<ll> a(n * 2);
  ll sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
    a[i + n] = a[i];
  }
  // Two-Pointer Technique
  int l = 0, r = 0;
  ll t = a[0];
  while(true){
    if(t * 10 == sum){
      cout << "Yes" << endl;
      return 0;
    }
    r++;
    if(r >= n * 2) break;
    t += a[r];
    if(t * 10 > sum){
      t -= a[l];
      l++;
    }
  }
  cout << "No" << endl;
}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var a: []int :: #[2 * n]int
	var sum: int :: 0
	for i(0, n - 1)
		var x: int :: cui@inputInt()
		do a[i] :: x
		do a[n + i] :: x
		do sum :+ x
	end for
	
	var ans: bool :: false
	if(sum % 10 = 0)
		do sum :/ 10
		var l: int :: 0
		var r: int :: 0
		var sum2: int :: 0
		while loop(l <> 2 * n)
			if(sum2 < sum & r <> 2 * n)
				do sum2 :+ a[r]
				if(sum2 = sum)
					do ans :: true
					break loop
				end if
				do r :+ 1
			else
				do sum2 :- a[l]
				do l :+ 1
			end if
		end while
	end if
	do cui@print((ans ?("Yes", "No")) ~ "\n")
end func
AtCoder problem 076

C++ solution:


Python solution: from bisect import bisect_left
n = int(input())
a = list(map(int,input().split()))

# 入力は整数なので10分の1も整数でなければNoになる
if sum(a) % 10 != 0:
    exit(print("No"))

# 目標となる1/10の値
num = sum(a) // 10

# 前からの累積和と後ろからの累積和
x, y = [a[0]], [a[-1]]
for i in range(n - 1):
    x.append(a[i + 1] + x[-1])
    y.append(a[-2 - i] + y[-1])

for i in range(n):
    # 目的の大きさと一致した場合
    if x[i] == num:
        exit(print("Yes"))
    # 目的の大きさより多く選んでしまった場合
    elif x[i] > num:
        j = bisect_left(x, x[i] - num) # 余分な分を二分探索
        if x[i] - x[j] == num:
            exit(print("Yes"))
    # 目的の大きさより小さい場合は後ろから持ってくる
    elif x[i] < num:
        j = bisect_left(y, num - x[i]) # 後ろから二分探索
        if x[i] + y[j] == num:
            exit(print("Yes"))

print("No")



Kuin solution: func main()
	var n: int :: cui@inputInt()
	var a: []int :: #[2 * n]int
	var sum: int :: 0
	for i(0, n - 1)
		var x: int :: cui@inputInt()
		do a[i] :: x
		do a[n + i] :: x
		do sum :+ x
	end for
	
	var ans: bool :: false
	if(sum % 10 = 0)
		do sum :/ 10
		var l: int :: 0
		var r: int :: 0
		var sum2: int :: 0
		while loop(l <> 2 * n)
			if(sum2 < sum & r <> 2 * n)
				do sum2 :+ a[r]
				if(sum2 = sum)
					do ans :: true
					break loop
				end if
				do r :+ 1
			else
				do sum2 :- a[l]
				do l :+ 1
			end if
		end while
	end if
	do cui@print((ans ?("Yes", "No")) ~ "\n")
end func
AtCoder problem 078

C++ solution:
#include <vector>

#include <iostream>

using namespace std;

int main() {

	int N, M;

	cin >> N >> M;

	vector<vector<int> > G(N);

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

		int a, b;

		cin >> a >> b; --a, --b;

		G[a].push_back(b);

		G[b].push_back(a);

	}

	int answer = 0;

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

		int cnt = 0;

		for (int j : G[i]) {

			if (j < i) {

				++cnt;

			}

		}

		if (cnt == 1) {

			++answer;

		}

	}

	cout << answer << endl;

	return 0;

}

Crystal solution: n, m = read_line.split.map(&.to_i)
graph = Array.new(n) { [] of Int32 }
m.times do
  a, b = read_line.split.map(&.to_i.pred)
  graph[a] << b
  graph[b] << a
end
puts graph.each_with_index.count { |a, i|
  a.one? { |j| i > j }
}
AtCoder problem 078

C++ solution:

Crystal solution: n, m = read_line.split.map(&.to_i)
graph = Array.new(n) { [] of Int32 }
m.times do
  a, b = read_line.split.map(&.to_i.pred)
  graph[a] << b
  graph[b] << a
end
puts graph.each_with_index.count { |a, i|
  a.one? { |j| i > j }
}


Python solution: n, m = map(int,input().split())
ans = [0] * n
for i in range(m):
    a, b = map(int,input().split())
    if a < b:
        ans[b - 1] += 1
    else:
        ans[a - 1] += 1

# 自分より小さい頂点が１つしかないものをカウントする
print(ans.count(1))
AtCoder problem 078

C++ solution:

Crystal solution: n, m = read_line.split.map(&.to_i)
graph = Array.new(n) { [] of Int32 }
m.times do
  a, b = read_line.split.map(&.to_i.pred)
  graph[a] << b
  graph[b] << a
end
puts graph.each_with_index.count { |a, i|
  a.one? { |j| i > j }
}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var m: int :: cui@inputInt()
	var nums: []int :: #[n]int
	for i(0, m - 1)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		if(a < b)
			do nums[b] :+ 1
		else
			do nums[a] :+ 1
		end if
	end for
	
	var ans: int :: 0
	for i(0, n - 1)
		if(nums[i] = 1)
			do ans :+ 1
		end if
	end for
	do cui@print("\{ans}\n")
end func
AtCoder problem 078

C++ solution:
#include <vector>

#include <iostream>

using namespace std;

int main() {

	int N, M;

	cin >> N >> M;

	vector<vector<int> > G(N);

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

		int a, b;

		cin >> a >> b; --a, --b;

		G[a].push_back(b);

		G[b].push_back(a);

	}

	int answer = 0;

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

		int cnt = 0;

		for (int j : G[i]) {

			if (j < i) {

				++cnt;

			}

		}

		if (cnt == 1) {

			++answer;

		}

	}

	cout << answer << endl;

	return 0;

}


Python solution: n, m = map(int,input().split())
ans = [0] * n
for i in range(m):
    a, b = map(int,input().split())
    if a < b:
        ans[b - 1] += 1
    else:
        ans[a - 1] += 1

# 自分より小さい頂点が１つしかないものをカウントする
print(ans.count(1))
AtCoder problem 078

C++ solution:
#include <vector>

#include <iostream>

using namespace std;

int main() {

	int N, M;

	cin >> N >> M;

	vector<vector<int> > G(N);

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

		int a, b;

		cin >> a >> b; --a, --b;

		G[a].push_back(b);

		G[b].push_back(a);

	}

	int answer = 0;

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

		int cnt = 0;

		for (int j : G[i]) {

			if (j < i) {

				++cnt;

			}

		}

		if (cnt == 1) {

			++answer;

		}

	}

	cout << answer << endl;

	return 0;

}





Kuin solution: func main()
	var n: int :: cui@inputInt()
	var m: int :: cui@inputInt()
	var nums: []int :: #[n]int
	for i(0, m - 1)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		if(a < b)
			do nums[b] :+ 1
		else
			do nums[a] :+ 1
		end if
	end for
	
	var ans: int :: 0
	for i(0, n - 1)
		if(nums[i] = 1)
			do ans :+ 1
		end if
	end for
	do cui@print("\{ans}\n")
end func
AtCoder problem 078

C++ solution:


Python solution: n, m = map(int,input().split())
ans = [0] * n
for i in range(m):
    a, b = map(int,input().split())
    if a < b:
        ans[b - 1] += 1
    else:
        ans[a - 1] += 1

# 自分より小さい頂点が１つしかないものをカウントする
print(ans.count(1))



Kuin solution: func main()
	var n: int :: cui@inputInt()
	var m: int :: cui@inputInt()
	var nums: []int :: #[n]int
	for i(0, m - 1)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		if(a < b)
			do nums[b] :+ 1
		else
			do nums[a] :+ 1
		end if
	end for
	
	var ans: int :: 0
	for i(0, n - 1)
		if(nums[i] = 1)
			do ans :+ 1
		end if
	end for
	do cui@print("\{ans}\n")
end func