Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
K = int(input())
x = list(map(int,input().split()))
ans = 0
for i in range(N):
    ans += min(x[i],K-x[i])*2
print(ans)


Fixed submission:
N = int(input())
A = int(input())
print(N**2 - A)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split()) 
l = list(map(int,input().split()))
l.sort(reverse = True)
length = 0
for i in range(K): 
    length += l[i]
print(leng

Fixed submission:
N,K = map(int,input().split()) 
l = list(map(int,input().split()))
l.sort(reverse = True)
length = 0
for i in range(K): 
    length += l[i]
print(length)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
b = []
if N%2 == 0:
    for i in range(N):
        if i%2 == 0:
            b.append(A[i])
        else:
            b.insert(0,A[i])
else:
    for i in range(N):
        if i%2 == 1:
            b.append(A[i])
        else:
            b.insert(0,A[i])
print(*b)

Fixed submission:
from collections import deque
N = int(input())
A = list(map(int, input().split()))
B = deque()

if N % 2 == 0:
	for i in range(N):
		if i % 2 == 0:
			B.append(A[i])
		else:
			B.appendleft(A[i])
else:
	for i in range(N):
		if i % 2 == 0:
			B.appendleft(A[i])
		else:
			B.append(A[i])
			
print(*B)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
b = []
if N%2 == 0:
    for i in range(N):
        if i%2 == 0:
            b.append(A[i])
        else:
            b.insert(0,A[i])
else:
    for i in range(N):
        if i%2 == 1:
            b.append(A[i])
        else:
            b.insert(0,A[i])
print(*b)

Fixed submission:
from collections import deque
N = int(input())
A = list(map(int, input().split()))
B = deque()

if N % 2 == 0:
	for i in range(N):
		if i % 2 == 0:
			B.append(A[i])
		else:
			B.appendleft(A[i])
else:
	for i in range(N):
		if i % 2 == 0:
			B.appendleft(A[i])
		else:
			B.append(A[i])
			
print(*B)
Buggy python submission (verdict: Runtime Error):
r,g,b= map(int(input().split()))
num = 100*r + 10*g + b
if num %4 == 0:
    print('YES')
else:
    print('NO')

Fixed submission:
a = list(map(int,input().split()))
num = 100*a[0]+ 10*a[1] + a[2]
if num %4 == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
A,B = map(int,iput().split())
if A+B< 10:
  print(A+B)
else:
  print('error')

Fixed submission:
A,B = map(int,input().split())
if A+B< 10:
  print(A+B)
else:
  print('error')
Buggy python submission (verdict: Runtime Error):
s = sorted(input())
x = len(s)
for i in range(s-1):
  if s[i+1] ==s[i]:
    print('no')
    exit()
print('yes') 

Fixed submission:
s = sorted(input())
x = len(s)
for i in range(x-1):
  if s[i+1] ==s[i]:
    print('no')
    exit()
print('yes')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
po = 1
for i in range(1,N+1):
    po *= i
print(po%(1000000007))

Fixed submission:
import math
N = int(input())
po = math.factorial(N)
print(po%(1000000007))
Buggy python submission (verdict: Runtime Error):
a = list(map(int,inptu().split()))
print(len(set(a)))


Fixed submission:
a = list(map(int,input().split()))
print(len(set(a)))
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
	int n; cin >> n;
    vector<ll> v(n);
    rep(i, n){
        cin >> v[i];
    }
    sort(All(v));
    if(v[0] == 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = v[n-1];
    for(int i = 0; i < n-1; i++){
        ans *= v[i];
        if(ans > (ll)1e18){
            cout << -1 << endl;
            return 0;
        }
    }
    if(ans < 0){
        cout << -1 << endl;
    }
    else cout << ans << endl;
    system("pause");
}


Fixed submission:
N = int(input())
L = list(map(int, input().split()))
ans = 1
if 0 in L:
  print(0)
  exit()
for i in range(N):
  ans *= L[i]
  if ans > 10**18:
    print(-1)
    exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L = [int(i) for i in input().split()]

ans = 1;
for i in range(N):
	ans *= L[i]
  
if ans > 1000000000000000000:
  ans = -1
print(ans)


Fixed submission:
N = int(input())
L = list(map(int, input().split()))
ans = 1
if 0 in L:
  print(0)
  exit()
for i in range(N):
  ans *= L[i]
  if ans > 10**18:
    print(-1)
    exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations_with_replacement

n = int(input())

calc = lambda x,y,z: x**2+y**2+z**2+x*y+y*z+z*x

def pattern(x,y,z):
   if x == y and y == z:
      return 1
   elif x == y or y == z or z == x:
      return 3
   elif x != y and y != z and z != x:
      return 6
   else:
      raise RuntimeError

def f(a):
   ans = 0
   nums = [i for i in range(1, a+1)]
   for x,y,z in combinations_with_replacement(nums, 3):
      if calc(x,y,z) == a:
         ans += pattern(x,y,z)
   return ans

for i in range(1, n+1):
   print(f(i))

Fixed submission:
from itertools import combinations_with_replacement
from collections import defaultdict

n = int(input())

calc = lambda x,y,z: x**2+y**2+z**2+x*y+y*z+z*x

def pattern(x,y,z):
   if x == y and y == z:
      return 1
   elif x == y or y == z or z == x:
      return 3
   elif x != y and y != z and z != x:
      return 6
   else:
      raise RuntimeError

d = defaultdict(int)
n_ = int(pow(n, 0.5))
nums = [i for i in range(1, n_+1)]
for x,y,z in combinations_with_replacement(nums, 3):
   d[calc(x,y,z)] += pattern(x,y,z)
for i in range(1, n+1):
   print(d[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

d = [0] * (n+1)
for i in range(1, n+1):
   for j in range(i, n+1, i):
      d[j] += 1
print(sum([k * d[k] for k in range(n+1)]))

Fixed submission:
n = int(input())

ans = 0
for i in range(1, n+1):
   num = n // i
   end = i * num
   ans += (num/2) * (end + i)
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
upper = 1e18
res = 1
for x in map(int, input().split()):
   res *= x
print(-1 if res > upper else res)

Fixed submission:
n = int(input())
upper = 1e18
res = 1
generator = map(int, input().split())
for x in generator:
   res *= x
   if res > upper:
      break

for x in generator:
   if x == 0:
      res = 0
   
print(-1 if res > upper else res)
Buggy python submission (verdict: Runtime Error):
k = int(input())
a,b = map(int, input().split())
for i in range(a, b+1):
  if i % k == 0:
    print('Yes')
  	exit()
print('No')

Fixed submission:
k = int(input())
a,b = map(int, input().split())
for i in range(a, b+1):
  if i % k == 0:
    print('OK')
    exit()
print('NG')
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor

a,b,n = map(int, input().split())
mx = 0
for i in range(n+1):
  v = floor(a*i/b) - a*floor(i/b)
  if v < mx:
    break
  else:
    mx = v
print(mx)


Fixed submission:
from math import floor

a,b,n = map(int, input().split())
i = min(n,b-1)
print(floor(a*i/b) - a*floor(i/b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(sum([i for i in range(1, n+1) if and i%5 != 0 and i%3 != 0]))

Fixed submission:
n = int(input())
print(sum([i for i in range(1, n+1) if i%5 != 0 and i%3 != 0]))
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,A,B,C = list(map(int, input().split()))
As = sorted(list(map(int, input().split())), reverse=True)
Bs = sorted(list(map(int, input().split())), reverse=True)
Cs = sorted(list(map(int, input().split())), reverse=True)

s = 0
_C = 0
while A+B+C > 0:
  if X+Y == _C:
    break
  if X+Y == 0:
    break
  mx = 0
  mxi = None
  for i, v in enumerate([As[0] if A>0 and X>0 else 0, Bs[0] if B>0 and Y>0 else 0, Cs[0] if C>0 else 0]):
    if v > mx:
      mx = v
      mxi = i
  if mxi == 0:
    A -= 1
    X -= 1
    As = As[1:] if len(As) > 1 else []
  elif mxi == 1:
    B -= 1
    Y -= 1
    Bs = Bs[1:] if len(Bs) > 1 else []
  elif mxi == 2:
    C -= 1
    _C += 1
    Cs = Cs[1:] if len(Cs) > 1 else []
  s += mx

print(s)


Fixed submission:
X,Y,A,B,C = list(map(int, input().split()))
As = sorted(list(map(int, input().split())), reverse=True)
Bs = sorted(list(map(int, input().split())), reverse=True)
Cs = list(map(int, input().split()))

As = As[:X]
Bs = Bs[:Y]
ans = 0
Xs = sorted(As+Bs+Cs, reverse=True)
print(sum(Xs[:X+Y]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
for k, v in counter.items():
  res[k] = (ncr(v, 2), ncr(v-1, 2))
total = sum(v[0] for k,v in res.items())
for a in As:
  v1, v2 = res[a]
  print(total - v1 + v2)

Fixed submission:
from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
total = 0
for k, v in counter.items():
  x = ncr(v, 2)
  res[k] = (x, (x * (v-2) // (v)))
  total += x
for a in As:
  v1, v2 = res[a]
  print(total - v1 + v2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
for k, v in counter.items():
  res[k] = (ncr(v, 2), ncr(v-1, 2))

for a in As:
  print(sum(v[0] if k != a else v[1] for k,v in res.items()))

Fixed submission:
from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
total = 0
for k, v in counter.items():
  x = ncr(v, 2)
  res[k] = (x, (x * (v-2) // (v)))
  total += x
for a in As:
  v1, v2 = res[a]
  print(total - v1 + v2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))

for i in range(n):
  while l[i] % 2 == 0:
    count += 1
    l[i] = l[i]/2

print(count)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
count = 0
for i in range(n):
  while l[i] % 2 == 0:
    count += 1
    l[i] = l[i]/2

print(count)
Buggy python submission (verdict: Runtime Error):
N, nums = int(input()), list(map(int, input().split()))
total, ano = sum(nums), 0
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif or i == 0:
        dif = abs(ano-total)
        last_dif = dif
print(dif)

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000000000
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif:
        dif = abs(ano-total)
        last_dif = dif
print(dif)

Buggy python submission (verdict: Runtime Error):
N, nums = int(input()), list(map(int, input().split()))
total, ano = sum(nums), 0
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif or i == 0:
        dif, last_dif = abs(ano-total), dif
print(dif)

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000000000
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif:
        dif = abs(ano-total)
        last_dif = dif
print(dif)

Buggy python submission (verdict: Runtime Error):
N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif:
        dif = abs(ano-total)
        last_dif = dif
print(dif)
    

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000000000
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif:
        dif = abs(ano-total)
        last_dif = dif
print(dif)

Buggy python submission (verdict: Runtime Error):
# N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif:
        dif = abs(ano-total)
        last_dif = dif
print(dif)
    

Fixed submission:
N = int(input())
nums = list(map(int, input().split()))
total, ano = sum(nums), 0
last_dif = 100000000000000
for i in range(len(nums)-1):
    total -= nums[i]
    ano += nums[i]    
    if abs(ano-total) < last_dif:
        dif = abs(ano-total)
        last_dif = dif
print(dif)
Buggy python submission (verdict: Runtime Error):
N=input()
def waru(num):
    return int(num)//400
a = list(map(waru, input().split()))
b = []
num = 0
for i in a:
    if i >= 8:
        b.append(i)
minu = len(set(a)) - len(set(b))
if min==0:
    min = 1

print(minu, len(b)+minu)


Fixed submission:
tmp = input().split()
tmp1 = int(''.join(tmp))
if tmp1%4 == 0:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
N=input()
def waru(num):
    return int(num)//400
    
a = list(map(waru, input().split()))
num = 0
for i in a:
    num+=1 if i >= 8 else 0
min = len(set(a))-num+1

print(min, num+min)


Fixed submission:
tmp = input().split()
tmp1 = int(''.join(tmp))
if tmp1%4 == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
def hantei(num):
    if num>0 and num<400:
        return 1
    elif num>=400 and num<800:
        return 2
    elif num>=800 and num<1200:
        return 3
    elif num>=1200 and num<1600:
        return 4
    elif num>= 1600 and num<2000:
        return 5
    elif num>=2000 and num<2400:
        return 6
    elif num>=2400 and num<2800:
        return 7
    elif num>=2800 and num<3200:
        return 8
    else:
        return 0

N = input()
l = input().split()
tmp_list = []
num=0
for i in l:
    hoge = hantei(int(i))
    if hoge == 0:
        num+=1
    else:
        tmp_list.append(hoge)
min = len(set(tmp_list))
max = min + num
print(min + ' ' + max)

Fixed submission:
N=input()
def waru(num):
    return int(num)//400
a = list(map(waru, input().split()))
b = []
num = 0
for i in a:
    if i >= 8:
        b.append(i)
minu = len(set(a)) - len(set(b))
if minu==0:
    minu = 1
    maxi = len(b)
else:
    maxi = len(b)+minu
print(minu, maxi)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for i in range(1,N+1):
    ans = 0
    L = int(i**0.5)
    for x in range(1,L+1):
        for y in range(x,L+1):
            if (x*x+y*y+x*y)>i:
                break
            for z in range(y,L+1):
                num = x*x+y*y+z*z+x*y+y*z+z*x
                if num == i:
                    if x==y and y==z:
                        ans += 1
                    elif x==y or y==z or z==x:
                        ans += 3
                    else:
                        ans += 6
    print(ans)
        

Fixed submission:
N = int(input())
A = [0]*(N+1)
L = int(N**0.5)+1
for x in range(1,L+1):
    for y in range(1,L+1):
        for z in range(1,L+1):
            num = x*x+y*y+z*z+x*y+y*z+z*x
            if num <= N:
                A[num] += 1
    

for i in range(1,N+1):
    print(A[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

for i in range(1,N+1):
    ans = 0
    L = int(i**0.5)
    for x in range(1,L+1):
        for y in range(1,L+1):
            for z in range(1,L+1):
                num = x*x+y*y+z*z+x*y+y*z+z*x
                if num == i:
                    ans += 1
    print(ans)
        

Fixed submission:
N = int(input())
A = [0]*(N+1)
L = int(N**0.5)+1
for x in range(1,L+1):
    for y in range(1,L+1):
        for z in range(1,L+1):
            num = x*x+y*y+z*z+x*y+y*z+z*x
            if num <= N:
                A[num] += 1
    

for i in range(1,N+1):
    print(A[i])
Buggy python submission (verdict: Runtime Error):

#INPUT
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    new = [int(i) for i in input().split()]
    s.append(new)

#Utilitiy
def score(ans):
    if len(ans) != D:
        print("wrong length")
        return 0
    else:
        p = 0
        last = [-1]*26
        for i in range(D):
            contest = ans[i]-1
            p += s[i][contest]
            last[contest] = i
            for j in range(26):
                p -= c[j]*(i-last[j])
        return p

def greedy(ahead=0):
    ans = []
    p = 0
    last = [-1]*26
    for i in range(D):
        decay = 0
        for j in range(26):
            decay -= c[j]*(i-last[j])
            
        max_j = -1
        max_plus = decay
        for j in range(26):
            plus = s[i][j] + c[j]*(i-last[j]) + c[j]*ahead
            if plus > max_plus:
                max_plus = plus
                max_j = j
        ans.append(max_j+1)
        last[max_j]=i
        p += max_plus + decay - c[max_j]*ahead
    return ans, p
        
#MAIN
max_points = 0
for k in range(20):
    ans_temp, points = greedy(ahead = k)
    if points > max_points:
        max_points = points
        ans = ans_temp

for i in range(D):
    print(ans[i])

Fixed submission:

#INPUT
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    new = [int(i) for i in input().split()]
    s.append(new)

#Utilitiy
def score(ans):
    if len(ans) != D:
        print("wrong length")
        return 0
    else:
        p = 0
        last = [-1]*26
        for i in range(D):
            contest = ans[i]-1
            p += s[i][contest]
            last[contest] = i
            for j in range(26):
                p -= c[j]*(i-last[j])
        return p

def greedy():
    ans = []
    p = 0
    last = [-1]*26
    for i in range(D):
        decay = 0
        for j in range(26):
            decay -= c[j]*(i-last[j])
            
        max_j = -1
        max_plus = decay
        for j in range(26):
            plus = s[i][j] + c[j]*(i-last[j])
            if plus > max_plus:
                max_plus = plus
                max_j = j
        ans.append(max_j+1)
        last[max_j]=i
        p += max_plus + decay
    return ans, p
        
#MAIN
ans, points = greedy()


for i in range(D):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print(1)
elif N == 2:
    print(5)
elif N == 3:
    print(11)
else:
    ans = N*(N+1)-1
    for i in range(2,N//2):
        t = N//i
        ans += i*(t*(t+1)//2-1)
        
print(ans)

Fixed submission:
N = int(input())
if N == 1:
    print(1)
elif N == 2:
    print(5)
elif N == 3:
    print(11)
else:
    ans = N*(N+1)-1
    for i in range(2,N//2+1):
        t = N//i
        ans += i*(t*(t+1)//2-1)
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

i=1
now=26
before = 0
while True:
    if N <= now:
        break
    i += 1
    before = now
    now += 26**i
    
#print(i)
M = N-before
alphabet = "abcdefghijklmnopqrstuvwxyz"
ans=""
for j in range(i):
    dig = int(M//26**(i-j-1))
    #print(dig)
    if j==i-1:
        ans = ans + alphabet[dig-1]
    else:
        ans = ans + alphabet[dig]
        M -= dig*26**(i-j-1)
    
print(ans)

Fixed submission:
N = int(input())

i=1
now=26
before = 0
while True:
    if N <= now:
        break
    i += 1
    before = now
    now += 26**i
    
#print(i)
M = N-before
alphabet = "abcdefghijklmnopqrstuvwxyz"
ans=""
for j in range(i):
    dig = int((M-1)//26**(i-j-1))
    #print(M, dig)
    ans = ans + alphabet[dig]
    M -= dig*26**(i-j-1)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
A = input()
if A = "ABC":
    print("ARC")
else:
    print("ABC")

Fixed submission:
A = input()
if A == "ABC":
    print("ARC")
else:
    print("ABC")
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

K = int(input())

GCD = [[0]*200 for i in range(200)]
for i in range(200):
    for j in range(200):
        GCD[i][j] = gcd(i+1, j+1)

tot = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            s = GCD[j-1][k-1]
            t = GCD[i-1][s-1]
            tot += t
print(tot)


Fixed submission:
K = int(input())

GCD = [[0]*200 for i in range(200)]
def gcd(x, y):
    if GCD[x-1][y-1] == 0:
        if y == 0:
            return x
        else:
            return gcd(y, x % y)
    else:
        return GCD[x-1][y-1]

tot = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        s = gcd(i, j)
        if s != 1:
            for k in range(1, K+1):
                t = gcd(k, s)
                tot += t
        else:
            tot += K
print(tot)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

K = int(input())

tot = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            s = gcd(j, k)
            t = gcd(i, s)
            tot += t
print(tot)


Fixed submission:
K = int(input())

GCD = [[0]*200 for i in range(200)]
def gcd(x, y):
    if GCD[x-1][y-1] == 0:
        if y == 0:
            return x
        else:
            return gcd(y, x % y)
    else:
        return GCD[x-1][y-1]

tot = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        s = gcd(i, j)
        if s != 1:
            for k in range(1, K+1):
                t = gcd(k, s)
                tot += t
        else:
            tot += K
print(tot)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(10**9 + 7)

N, K = map(int, input().split())
tot = [0]*(K+1)

for i in range(K,0,-1):
    tot[i] = ((K//i)**N) % MOD
    s = 2
    while s*i <= K:
        tot[i] -= tot[s*i]
        s += 1
        
ans = 0
for i in range(K+1):
    ans += ((tot[i]%MOD)*i)%MOD

print(ans%MOD)

Fixed submission:
MOD = int(10**9 + 7)

def pow_mod(x, n, mod):
    if n > 1:
        return pow_mod(pow(x,2) % mod, n//2, mod) * pow(x, n%2) % mod
    else:
        return x


N, K = map(int, input().split())
tot = [0]*(K+1)

for i in range(K,0,-1):
    tot[i] = pow_mod(K//i, N, MOD)
    s = 2
    while s*i <= K:
        tot[i] -= tot[s*i]
        s += 1
        
ans = 0
for i in range(K+1):
    ans += ((tot[i]%MOD)*i)%MOD

print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(10**9 + 7)

N, K = map(int, input().split())
tot = [0]*(K+1)

for i in range(K,0,-1):
    tot[i] = (K//i)**N
    s = 2
    while s*i <= K:
        tot[i] -= tot[s*i]
        s += 1
        
ans = 0
for i in range(K+1):
    ans += ((tot[i]%MOD)*i)%MOD

print(ans%MOD)

Fixed submission:
MOD = int(10**9 + 7)

def pow_mod(x, n, mod):
    if n > 1:
        return pow_mod(pow(x,2) % mod, n//2, mod) * pow(x, n%2) % mod
    else:
        return x


N, K = map(int, input().split())
tot = [0]*(K+1)

for i in range(K,0,-1):
    tot[i] = pow_mod(K//i, N, MOD)
    s = 2
    while s*i <= K:
        tot[i] -= tot[s*i]
        s += 1
        
ans = 0
for i in range(K+1):
    ans += ((tot[i]%MOD)*i)%MOD

print(ans%MOD)