Mark bought some files at $4 each. He later sold them to his customers at $8 each. For customers who bought two files were given another file for free. The customers bought either one or two files. Mark gave away 160 free files and collected a total of $1240 more than what he had paid for. How many customers bought just one file?

Let's start by using algebra to solve the problem.

Let x be the number of customers who bought one file, and y be the number of customers who bought two files.

We know that Mark gave away 160 free files, which means that he gave away 160/3 = 53.33... sets of free files (since each set includes three files). However, since he cannot give away a fractional set, we know that he gave away either 53 sets (which means he gave away 159 files) or 54 sets (which means he gave away 162 files). We'll consider both possibilities.

Case 1: Mark gave away 159 files (53 sets)

In this case, we know that Mark sold a total of x + y customers. The number of files he sold is therefore:

1x + 2y + (53 sets) = x + y + 159

Simplifying this equation:

x + 2y = 106

We also know that Mark collected a total of $1240 more than what he had paid for, which means:

8(x + 2y) = 4(x + y) + 1240

Simplifying this equation:

4x = 1496 - 12y

We can now solve for x and y:

x + 2y = 106

4x + 12y = 1496

Multiplying the first equation by -2:

-2x - 4y = -212

4x + 12y = 1496

Adding the equations:

2x = 1284

x = 642

This solution doesn't make sense, since x represents the number of customers who bought just one file, and we can't have a non-integer number of customers. Therefore, we need to try the second case.

Case 2: Mark gave away 162 files (54 sets)

Using the same logic as before:

x + 2y = 107

4x = 1492 - 12y

Multiplying the first equation by -2:

-2x - 4y = -214

4x + 12y = 1492

Adding the equations:

2x = 1278

x = 639

This time, the solution makes sense, since x represents the number of customers who bought just one file, and we have x = 639 (an integer).

Therefore, the answer is:

639 customers bought just one file, and

(107 - 639) = 468 customers bought two files.