#include<bits/stdc++.h>
using namespace std;
int d(int n)
{
// the sum of all divisors of n except itself.
int sum = 0;
for (int i = 1; i * i <= n; ++ i)
{
if (n % i == 0)
{
sum += i;
if (i * i != n && i != 1) sum += n / i;
}
}
return sum;
}
int main(void)
{
int ans = 0;
for (int i = 0; i <= 10000; ++ i)
{
int x = d(i);
int y = d(x);
if (y == i && i != x)
{
cout << x << " " << y << endl;
ans += i;
}
}
cout << ans << endl;
return 0;
}