Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
cs = [[0] * 61 for _ in range(N + 1)]
mod = 10 ** 9 + 7
for i in range(N):
  for j in range(61):
    t = 1 << j
    #print(a[i], t, a[i] & t)
    x = (a[i] & t) > 0
    cs[i + 1][j] = (cs[i][j] + x) % mod
res = 0
#print(cs[-1])
#print(cs[2])
for i in range(N):
  t = 0
  for j in range(61):
    x = 1 << j
    if a[i] & x != 0:
      #if i == 1: print((1 << j) * (N - i - 1), (cs[-1][j] - cs[i + 1][j]))
      t += x * ((N - i - 1) - (cs[-1][j] - cs[i + 1][j]))
    else:
      #if i == 1: print(a[i] & (1 << j), (cs[-1][j] - cs[i + 1][j]))
      t += x * (cs[-1][j] - cs[i + 1][j])
    #print(t)
    t %= mod
  res += t
  res %= mod
print(res % mod)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mxbit = 0
for i in range(N):
  mxbit = max(mxbit, a[i].bit_length())
cs = [0] * mxbit
for i in range(N):
  for j in range(mxbit):
    t = 1 << j
    #print(a[i], t, a[i] & t)
    x = (a[i] & t) > 0
    cs[j] += x
res = 0
#print(cs[-1])
#print(cs)
for i in range(N):
  t = 0
  for j in range(mxbit):
    x = 1 << j
    if a[i] & x != 0:
      x %= mod
      #if i == 1: print((1 << j) * (N - i - 1), (cs[-1][j] - cs[i + 1][j]))
      t += x * (N - (cs[j]))
    else:
      x %= mod
      #if i == 1: print(a[i] & (1 << j), (cs[-1][j] - cs[i + 1][j]))
      t += x * cs[j]
    #print(t)
    t %= mod
  res += t
  res %= mod
print(res % mod * pow(2, mod - 2, mod) % mod)
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
s = 0
for i in range(0, N-2):
	for j in range(i+1, N-1):
		for k in range(j+1, N):
			if L[i]<L[j]+L[k]:
				if L[j]<L[k]+L[i]:
					if L[k]<L[i]+L[j]:
						s += 1
print(s)

### FIXED CODE ###

import bisect

N = int(input())
L = list(map(int, input().split()))
s = 0

L = sorted(L)

for c in reversed(range(2, N)):
	for b in reversed(range(1, c)):
		a = bisect.bisect_right(L, L[c]-L[b])
		if a<b:
			s += b-a
print(s)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = []
if n % 2 == 0:
    for i in range(n-1,0,-2):
        ans = ans + [a[i]]
    for i in range(0,n,2):
        ans = ans + [a[i]]
else:
    for i in range(n-1,-1,-2):
        ans = ans + [a[i]]
    for i in range(1,n,2):
        ans = ans + [a[i]]
print(' '.join([str(i) for i in ans]))


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = []
if n % 2 == 0:
    for i in range(n-1,0,-2):
        ans.append(a[i])
    for i in range(0,n,2):
        ans.append(a[i])
else:
    for i in range(n-1,-1,-2):
        ans.append(a[i])
    for i in range(1,n,2):
        ans.append(a[i])
print(' '.join([str(i) for i in ans]))
### BUGGY CODE ###

import itertools
N, L = map(int, input().split())
str_list = [input() for _ in range(N)]

tmp_str=''.join(['z' for _ in range(N*L)])
for ii in itertools.permutations(str_list):
    if tmp_str > ''.join(ii):
        tmp_str=''.join(ii)
        
print(tmp_str)

### FIXED CODE ###

N, L = map(int, input().split())
str_list = sorted([input() for _ in range(N)])
print(''.join(str_list))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n):
    flag = True
    for j in range(i):
        if a[j] > a[i] // 2:
            break
        if a[i] % a[j] == 0:
            flag = False
            break
    if flag:
        if i < n - 1 and a[i] == a[i+1]:
            continue
        if i > 0 and a[i] == a[i-1]:
            continue
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
cnt = [0 for _ in range(10**6+5)]
ans = 0
if n == 1:
    print(1)
    exit()
if a[0] == 1:
    if a[1] != 1:
        print(1)
    else:
        print(0)
    exit()
for x in a:
    for i in range(x, 10**6+5, x):
        cnt[i] += 1
for x in a:
    if cnt[x] == 1:
        ans += 1
print(ans)
### BUGGY CODE ###

#60b
a,b,c =map(int,input().split())
i=0
aa=a
while i<b:
    if aa%b == c:
        print('YES')
        exit()
    aa+=a
print('NO')

### FIXED CODE ###

A,B,C = map(int,input().split())
i =0
AA = A
while i <B:
    i+=1
    if AA%B ==C:
        print('YES')
        exit()
    AA += A
print('NO')
### BUGGY CODE ###

N,K = map(int,input().split())
asiba = list(map(int,input().split()))
dp =[10**10] *N

#初期化
dp[0]=0
dp[1]=abs(asiba[1]-asiba[0])

for i in range(2,N):
    dp[i] = min(dp[i-j]+abs(asiba[i]-asiba[i-j]) for j in range(1,min(i+1,K+1)))
    
print(dp[N-1])

### FIXED CODE ###

def main():
  n, k = [int(e) for e in input().split()]
  h = [int(e) for e in input().split()]
  cost = [0] * n
  for i in range(1, n):
    cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
  print(cost[n - 1])
main()
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
n = int(input())
sum=0
for a in range(1, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            sum=sum+gcd_list([a,b,c])
print(sum)

### FIXED CODE ###

import math
#from functools import reduce

#def gcd(*numbers):
#    return reduce(math.gcd, numbers)

#def gcd_list(numbers):
#    return reduce(math.gcd, numbers)
  
n = int(input())
sum=0
for a in range(1, n+1):
    for b in range(1, n+1):
        ab=math.gcd(a,b)
        for c in range(1, n+1):
#            print(list(set([a,b,c])))
#            abc=list(set([a,b,c]))
#            sum=sum+gcd_list(abc)
            abc=math.gcd(ab,c)
            sum=sum+abc
print(sum)
### BUGGY CODE ###

def comb(n, k, MOD = 10 ** 9 + 7):
    if n < k:
        return 0
    if n - k < k:
        k = n - k
    comb = 1
    for x in range(n - k + 1, n + 1):
        comb = (comb * x) % MOD
    d = 1
    for x in range(1, k + 1):
        d = (d * x) % MOD
    comb *= pow(d, MOD - 2, MOD)
    return comb % MOD

def main():
    N = int(input())
    A = [int(v) for v in input().split()]
    C = [0] * (N + 1)
    M = [-1] * (N + 1)

    for i in A:
        C[i] += 1


    for i in range(N):
        C[A[i]] -= 1
        ans = 0
        for cnt in C:
            if M[cnt] == -1:
                value =  comb(cnt, 2)
                ans += value
                M[cnt] = value
            else:
                ans += M[cnt]
        C[A[i]] += 1
        print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N = int(input())
    A = [int(v) for v in input().split()]
    C = [0] * (N + 1)

    for i in A:
        C[i] += 1

    b = 0
    
    for cnt in C:
        b += ((cnt * (cnt - 1)) // 2)

    for i in range(N):
        p = ((C[A[i]] - 1) * (C[A[i]] - 2)) >> 1
        m = (C[A[i]] * (C[A[i]] - 1)) >> 1
        print(b - m + p)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
S = input()
S = [(a, p) for p, a in enumerate(S)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if S[i][0] != S[j][0] and S[i][0] != S[k][0] and S[j][0] != S[k][0] and j-i != k-j:
                count+=1
print(count)    

### FIXED CODE ###

N = int(input())
S = list(input())
count = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i < N:
            if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
                count-=1
print(count)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000000)

def rec(n):
    if n == 1:
        return 1
    return rec(n-1) + 1


print(rec(1000000))


### FIXED CODE ###

A, B = map(int, input().split())
print(max(A*2-1,A+B,B*2-1))
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
"""ナイーブ
for i in range(q):
    l, r = map(int, input().split())
    print(s[l-1:r].count("AC"))
"""

ac_li = []
for i in range(n-1):
    if s[i] + s[i+1] == "AC":
        ac_li.append([i, i+1])
#print(ac_li)
for i in range(q):
    ans = 0
    l, r = map(int, input().split())
    for j in ac_li:
        if set(range(l-1, r)) & set(j) == set(j):
            ans += 1
    print(ans)

### FIXED CODE ###

n, q = map(int, input().split())
s = input()
"""ナイーブ
for i in range(q):
    l, r = map(int, input().split())
    print(s[l-1:r].count("AC"))
"""
# 前処理＋全探索
# 区間なので累積和を疑う
t = [0]*n
count = 0
for i in range(n-1):
    t[i] = count
    if s[i] + s[i+1] == "AC":
        count += 1
    t[i+1] = count
#print(t)
for i in range(q):
    l, r = map(int, input().split())
    ans = t[r-1] - t[l-1]
    print(ans)
### BUGGY CODE ###

N = int(input())

keihin = []

for i in range(N):
  S = input()
  if S in keihin:
    continue
  keihin.append(S)

print(len(keihin))

### FIXED CODE ###

N = int(input())
 
keihin = {}
 
for i in range(N):
  S = input()
  try:
    keihin[S] += 1
  except:
    keihin[S] = 1
 
print(len(keihin))
### BUGGY CODE ###

N = int(input())
h = list(map(int, input().split()))
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += h[i] * h[j]
        ans = ans % (10 ** 9 + 7)
print(ans)

### FIXED CODE ###

N = int(input())
h = list(map(int, input().split()))
ans = 0
s = [h[N-1]]
for i in range(1, N):
    s.append(s[-1] + h[-i-1])
for i in range(N-1):
    ans += h[i] * s[-i-2]
ans = ans % (10 ** 9 + 7)
print(int(ans))
### BUGGY CODE ###

S=input()
c=0;s=[]
for i in range(0,len(S)+1):
  for j in range(i,len(S)):
    s.append(S[i:j+1])
del s[0]
ss = [int(i) for i in s]    
#print(ss)
sss = list(map(lambda x: x %2019, ss))

#print(sss)
print(sss.count(0))


### FIXED CODE ###

S=input()
s=int(S)
mod=2019
c=[0]*(len(S)+1)
d=[0]*2019


c[0]=0
d[0]=1
for i in range(len(S)):
  c[i+1]=(c[i]+int(S[-i-1])*pow(10,i,mod))%mod
  d[c[i+1]]+=1
  
m=0
for i in range(2019):
  m+=d[i]*(d[i]-1)//2

print(m)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))

b = sorted(a)
for i in range(1, n+1):
    print(b.count(i))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

b = [0] * n
for i in a:
    b[i-1] += 1
for i in b:
    print(i)
### BUGGY CODE ###

from math import sqrt
n = int(input())

for i in range(1, n+1):
    cnt = 0
    for x in range(1, int(sqrt(2*i))+1):
        for y in range(1, x+1):
            for z in range(1, y+1):
                if (x+y)**2 + (y+z)**2 + (z+x)**2 == 2*i:
                    if x == y == z:
                        cnt += 1
                    else:
                        cnt += 3
    print(cnt)

### FIXED CODE ###

from math import sqrt
n = int(input())

n_cnt = [0]*n

for x in range(1, int(sqrt(2*n))+1):
    for y in range(1, int(sqrt(2*n))+1):
        for z in range(1, int(sqrt(2*n))+1):
            t = (x+y)**2 + (y+z)**2 + (z+x)**2
            if t % 2 == 0 and t // 2 - 1 < n:
                n_cnt[t // 2 - 1] += 1


for i in range(n):
    print(n_cnt[i])
### BUGGY CODE ###

N,W=map(int,input().split())
v=[]
w=[]
for _ in range(N):
    ww,vv=map(int,input().split())
    v.append(vv)
    w.append(ww)
ans=[]

for i in range(2**N):
    bit=bin(i)[2:].zfill(N)
    temp=[0,0]
    for j in range(N):
        temp[0]+=int(bit[j])*v[j]
        temp[1]+=int(bit[j])*w[j]
    if temp[1]>W:
        temp[0]=0
    ans.append(temp[0])
print(max(ans))

### FIXED CODE ###

N,W=map(int,input().split())
w=[]
v=[]
for _ in range(N):
    a,b=map(int,input().split())
    w.append(a)
    v.append(b)
V=sum(v)

dp=[[10**9 for _ in range(V+1)] for _ in range(N+1)]
dp[0][0]=0
ans=0

for i in range(N): #i番目の荷物を拾うかどうか
    for j in range(V+1): #価値jを超える重量の最小値
        dp[i+1][j]=min(dp[i][j],dp[i][max(0,j-v[i])]+w[i])
        if dp[i+1][j]<=W:
            ans=max(ans,j)
        
print(ans)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

H, W = list(map(int, input().split()))
S = ["#" * (W+2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W+2)]

ans = 0

for j in range(1, H+1):
    for i in range(1, W+1):
        if S[j][i] != ".":
            continue
        m = [[-1] * (W+2) for _ in range(H+2)]

        q = deque()
        q.append((j, i, 0))

        while q:
            y, x, v = q.popleft()
            m[y][x] = v
            for d in ((y, x + 1), (y, x-1), (y+1, x), (y-1, x)):
                dj, di = d
                if S[dj][di] == "." and m[dj][di] == -1:
                    q.append((dj, di, v+1))
                    if ans < v+1:
                        ans = v+1
print(ans)


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

H, W = list(map(int, input().split()))
S = ["#" * (W+2)] + ["#" + input().strip() +
                     "#" for _ in range(H)] + ["#" * (W+2)]

ans = 0

for j in range(1, H+1):
    for i in range(1, W+1):
        if S[j][i] != ".":
            continue
        m = [[-1] * (W+2) for _ in range(H+2)]

        q = deque()
        q.append((j, i, 0))
        m[j][i] = 0

        while q:
            y, x, v = q.popleft()
            if ans < v:
                ans = v
            for dj, di in ((y, x+1), (y, x-1), (y+1, x), (y-1, x)):
                if S[dj][di] == "#" or m[dj][di] != -1:
                    continue
                q.append((dj, di, v+1))
                m[dj][di] = v+1
print(ans)
### BUGGY CODE ###

N, K, C = map(int, input().split())
S = input()

work_date = []

# 先詰めで出勤する場合
pw = 0

for d in range(K):

    w = S[pw:].index('o') + pw
    work_date.append(w)

    # 次出勤する可能性がある、最初の日を探す
    pw = w + C + 1
    
# 後詰めで出勤する場合
work_date_l = []

Sr = "".join(list(reversed(S)))
pw = 0

for d in range(K):

    w = Sr[pw:].index('o') + pw
    work_date_l.append((N-1)-w)

    # 次出勤する可能性がある、最初の日を探す
    pw = w + C + 1

work_date_l.sort()
    
for i in range(K):
    if work_date[i] == work_date_l[i]:
        print(work_date[i] + 1)

### FIXED CODE ###

N, K, C = map(int, input().split())
S = input()

Sr = "".join(list(reversed(S)))

wd = []
wdl = []

pw = 0
pwl = 0

for d in range(K):

    # 先詰めを探す
    while True:
        if S[pw] == ('o'):
            wd.append(pw)
            break
        pw += 1
    pw += C + 1
    
    # 後詰めを探す
    while True:
        if Sr[pwl] == ('o'):
            wdl.append((N-1) - pwl)
            break
        pwl += 1
    pwl += C + 1

wdl.sort()
    
for i in range(K):
    if wd[i] == wdl[i]:
        print(wd[i] + 1)
### BUGGY CODE ###

# coding: utf-8
#from mod10**9 import *

purasu_num, num_ijou = list(map(int, input().split(" ")))

sum_ways = 0 #和の個数
rupe_num = purasu_num - num_ijou + 2

atai_list = [i for i in range(purasu_num + 1)]
for i in range(rupe_num):
    kosu = i + num_ijou
    mi = sum(atai_list[:kosu])
    ma = sum(atai_list[-kosu:])
    sum_ways += ma - mi + 1
    #print(kosu, sum_ways)

print(sum_ways)


### FIXED CODE ###

mod = 10**9 + 7
def sum(a, b):
    r = (a + b)*(b - a + 1) / 2
    return int(r)

def main():
    sum_num = 0
    N, K = list(map(int, input().split(" ")))
    for i in range(K, N+2):
        mi = sum(0, i - 1)
        ma = sum(N-i+1, N)
        sum_num += ma - mi + 1

    print(sum_num % mod)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

N, K = map(int, input().split())
*V, = map(int, input().split())
V.sort()
A = [0]*(N+1)
B = [0]*(N+1)
MASK = 2**(K+1)-1
A[0] = 1
for i in range(N):
    if K <= V[i]:
        A[i+1] = A[i]
    else:
        A[i+1] = (A[i] | (A[i] << V[i])) & MASK
B[N] = 1 << K
for i in range(N-1, -1, -1):
    if K <= V[i]:
        B[i] = B[i+1]
    else:
        B[i] = (B[i+1] | (B[i+1] >> V[i])) & MASK

ans = N
for i in range(N):
    a = A[i]; b = B[i+1]
    t = K
    K0 = K-V[i]
    for s in range(K+1):
        if a & 1 == 0:
            a >>= 1
            if not a: break
            continue
        while t > -1 and (s + t >= K or b & 1 == 0):
            t -= 1
            b >>= 1
        if not b: break
        if K0 <= s + t:
            ans -= 1
            break
        a >>= 1
print(ans)


### FIXED CODE ###

import random
N, K = map(int, input().split())
*V, = map(int, input().split())
A = [0]*(N+1)
B = [0]*(N+1)
MASK = 2**(K+1)-1
A[0] = 1
for i in range(N):
    if K <= V[i]:
        A[i+1] = A[i]
    else:
        A[i+1] = (A[i] | ((A[i] << V[i]) & MASK))
B[N] = 1 << K
for i in range(N-1, -1, -1):
    if K <= V[i]:
        B[i] = B[i+1]
    else:
        B[i] = (B[i+1] | (B[i+1] >> V[i]))

ans = N
for i in range(N):
    if K <= V[i]:
        ans -= 1
        continue
    a = A[i]; b = B[i+1]
    VM = 2**(V[i]+1)-2
    l = 1
    while a and b and l:
        if a & 1 and b & VM:
            ans -= 1
            break
        l = max((a & -a).bit_length()-1, (b & -b).bit_length()-V[i]-1)
        a >>= l; b >>= l
print(ans)
### BUGGY CODE ###

def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            if S[i]!=S[j]:
                k1=S[j+1:].count(S[i])
                k2=S[j+1:].count(S[j])
                ans=ans+len(S[j+1:])-k1-k2
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)

main()


### FIXED CODE ###

def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()
### BUGGY CODE ###

a = input()
b = input()
c = input()

def match(c1, c2):
    return c1 == '?' or c2 == '?' or c1 == c2

M = 2000

ab, ac, bc = [], [], []
for _  in range(10000):
    ab.append(0)
    ac.append(0)
    bc.append(0)

for _  in range(10000):
    bc.append(0)

A, B, C = len(a), len(b), len(c)
for i in range(A):
    for j in range(B):
        if not match(a[i], b[j]):
            ab[i-j+5000] = 1
for i in range(A):
    for j in range(C):
        if not match(a[i], c[j]):
            ac[i-j+5000] = 1
for i in range(B):
    for j in range(C):
        if not match(b[i], c[j]):
            bc[i-j+10000] = 1

ans = 3 * M

for i in range(-2*M, 2*M):
    for j in range(-2*M, 2* M):
        if ab[i+5000] == 0 and ac[j+5000] == 0 and bc[j-i+10000] == 0:
            L = min(0, min(i, j))
            R = max(A, max(B+i, C+j))
            ans = min(ans, R - L)

print(ans)


### FIXED CODE ###

a = input()
b = input()
c = input()

def match(c1, c2):
    return c1 == '?' or c2 == '?' or c1 == c2

M = 2000

ab, ac, bc = [], [], []
ab_append = ab.append
ac_append = ac.append
bc_append = bc.append

for _  in range(10000):
    ab_append(0)
    ac_append(0)
    bc_append(0)

for _  in range(10000):
    bc_append(0)

A, B, C = len(a), len(b), len(c)
for i in range(A):
    for j in range(B):
        if not match(a[i], b[j]):
            ab[i-j+5000] = 1
for i in range(A):
    for j in range(C):
        if not match(a[i], c[j]):
            ac[i-j+5000] = 1
for i in range(B):
    for j in range(C):
        if not match(b[i], c[j]):
            bc[i-j+10000] = 1

ans = 3 * M

for i in range(-2*M, 2*M):
    for j in range(-2*M, 2* M):
        if ab[i+5000] == 0 and ac[j+5000] == 0 and bc[j-i+10000] == 0:
            L = min(0, min(i, j))
            R = max(A, max(B+i, C+j))
            ans = min(ans, R - L)

print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
if n == 1:
  print(1)
  exit()
  
chk = []
for i in range(n):
  a = int(input())
  chk.append((i,a))
  
from bisect import bisect_left,insort_left
ans = 1

c = []
for j in chk:
  i,a = j
  if i == 0:
    c.append((a,n-i))
  else:
    ind = bisect_left(c,(a,n-i))
    if ind == 0:
      ans += 1
      insort_left(c,(a,n-i))
    else:
      c[ind-1] = (a,n-i)
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
if n == 1:
  print(1)
  exit()
  
chk = []
for i in range(n):
  a = int(input())
  chk.append((i,a))
  
from bisect import bisect_left,insort_left
from collections import deque
ans = 1

c = deque([])
for j in chk:
  i,a = j
  if i == 0:
    c.append((a,n-i))
  else:
    ind = bisect_left(c,(a,n-i))
    if ind == 0:
      ans += 1
      c.appendleft((a,n-i))
    else:
      c[ind-1] = (a,n-i)
      
print(ans)
### BUGGY CODE ###

def test():
    global count, list_str
    for i, data in enumerate(list_str):
        try:
            if data == '#' and list_str[i + 1] == '.':
                list_str[i + 1] = '#'
                count += 1
        except IndexError:
            pass


N = input()
S = input()
count = 0

list_str = list(S)

for i in range(len(S)):
    test()

print(count)

### FIXED CODE ###

N = input()
S = input()
count = 0

list_str = S
count_black = 0
count_white = S.count('.')
ans = count_black + count_white

for i in S:
    if i == '#':
        count_black += 1
    else:
        count_white -= 1

    if ans >= count_white + count_black:
        ans = count_black + count_white

# print(count_black)
# print(count_white)

print(ans)
### BUGGY CODE ###

def resolve():
    s = input()
    n = len(s)
    counter = [0] * 2019
    counter[0] += 1
    temp = ""
    for i, c in enumerate(s[::-1], 1):
        temp = c + temp
        counter[int(temp) % 2019] += 1

    ans = 0
    for i in counter:
        ans += (i * (i - 1)) // 2

    print(ans)
resolve()

### FIXED CODE ###

a,*d=[0]*2020
for i in map(int,input()):
  p=[0]*2019
  for j in range(2019):p[(j*10+i)%2019]+=d[j]
  d=p
  d[i]+=1
  a+=d[0]
print(a)
### BUGGY CODE ###

N = int(input())
S = input()

key = set()
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in set(S[j+1:N]):
            key.add(S[i]+S[j]+k)

print(len(key))


### FIXED CODE ###

N = int(input())
S = input()

X = []
for i in range(10):
    X.append(str(i))

ans = 0
for i in X:
    if i in S:
        T = S[S.index(i) + 1:]
        for j in X:
            if j in T:
                U = T[T.index(j) + 1:]
                for k in X:
                    if k in U:
                        ans += 1

print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(S: str):
    nS = len(S)
    pS = ""
    while pS != S:
        pS = S
        S = S.replace("01", "")
        S = S.replace("10", "")
    print(nS - len(S))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(S: str):
    print(min(S.count("0"), S.count("1")) * 2)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())
p = 1
for i in range(0,n):
	p = p * (i+1)
print(p % (10**9 + 7))

### FIXED CODE ###

n = int(input())
p = 1
for i in range(1,n+1):
	p = (p * i) % (10**9 + 7)
print(p)
### BUGGY CODE ###

import numpy as np
n = int(input())

d = np.ones(n)
ii = np.arange(1, n+1)

for i in range(2, n+1):
    k = 1
    while i*k <= n:
        d[i*k-1] += 1
        k += 1

# ans = 0
# for i in range(n):
#     ans += (i+1)*d[i]

print(int(sum(d*ii)))

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1, n+1):
  d = n // i
  ans += d*(d+1)//2*i
print(ans)