/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <algorithm>
// #include "./Debug.h"

namespace AtCoder {
	using Input = std::vector<std::string>;
	using Num = std::vector<int>;

	Input input(void) {
		Input result;
		{
			std::string buf = "", row = "";
			std::getline(std::cin, buf);
			for (unsigned int i = 0; i < buf.size(); i++) {
				if (' ' == buf[i]) {
					result.push_back(row);
					row = "";
				} else {
					row += buf[i];
				}
			}
			result.push_back(row);
		}
		return result;
	}

	Num replaceToInteger(Input original = { "" }) {
		Num result;
		for (unsigned int i = 0; i < original.size(); i++) {
			result.push_back(atoi(original[i].c_str()));
		}
		return result;
	}
}

bool checkLocal(int v = 0) {
	switch (v) {
	case (1):
	case (4):
	case (9):
	case (16):
	case (25):
	case (36):
	case (49):
	case (64):
	case (81):
	case (100):
	case (121):
	case (144):
	case (169):
	case (196):
	case (225):
	case (256):
	case (289):
	case (324):
	case (361):
	case (400):
	case (441):
	case (484):
	case (529):
	case (576):
	case (625):
	case (676):
	case (729):
	case (784):
	case (841):
	case (900):
	case (961):
	case (1024):
	case (1089):
	case (1156):
	case (1225):
	case (1296):
	case (1369):
	case (1444):
	case (1521):
	case (1600):
	case (1681):
	case (1764):
	case (1849):
	case (1936):
	case (2025):
	case (2116):
	case (2209):
	case (2304):
	case (2401):
	case (2500):
	case (2601):
	case (2704):
	case (2809):
	case (2916):
	case (3025):
	case (3136):
	case (3249):
	case (3364):
	case (3481):
	case (3600):
	case (3721):
	case (3844):
	case (3969):
	case (4096):
	case (4225):
	case (4356):
	case (4489):
	case (4624):
	case (4761):
	case (4900):
	case (5041):
	case (5184):
	case (5329):
	case (5476):
	case (5625):
	case (5776):
	case (5929):
	case (6084):
	case (6241):
	case (6400):
	case (6561):
	case (6724):
	case (6889):
	case (7056):
	case (7225):
	case (7396):
	case (7569):
	case (7744):
	case (7921):
	case (8100):
	case (8281):
	case (8464):
	case (8649):
	case (8836):
	case (9025):
	case (9216):
	case (9409):
	case (9604):
	case (9801):
	case (10000):
	case (10201):
	case (10404):
	case (10609):
	case (10816):
	case (11025):
	case (11236):
	case (11449):
	case (11664):
	case (11881):
	case (12100):
	case (12321):
	case (12544):
	case (12769):
	case (12996):
	case (13225):
	case (13456):
	case (13689):
	case (13924):
	case (14161):
	case (14400):
	case (14641):
	case (14884):
	case (15129):
	case (15376):
	case (15625):
	case (15876):
	case (16129):
	case (16384):
	case (16641):
	case (16900):
	case (17161):
	case (17424):
	case (17689):
	case (17956):
	case (18225):
	case (18496):
	case (18769):
	case (19044):
	case (19321):
	case (19600):
	case (19881):
	case (20164):
	case (20449):
	case (20736):
	case (21025):
	case (21316):
	case (21609):
	case (21904):
	case (22201):
	case (22500):
	case (22801):
	case (23104):
	case (23409):
	case (23716):
	case (24025):
	case (24336):
	case (24649):
	case (24964):
	case (25281):
	case (25600):
	case (25921):
	case (26244):
	case (26569):
	case (26896):
	case (27225):
	case (27556):
	case (27889):
	case (28224):
	case (28561):
	case (28900):
	case (29241):
	case (29584):
	case (29929):
	case (30276):
	case (30625):
	case (30976):
	case (31329):
	case (31684):
	case (32041):
	case (32400):
	case (32761):
	case (33124):
	case (33489):
	case (33856):
	case (34225):
	case (34596):
	case (34969):
	case (35344):
	case (35721):
	case (36100):
	case (36481):
	case (36864):
	case (37249):
	case (37636):
	case (38025):
	case (38416):
	case (38809):
	case (39204):
	case (39601):
	case (40000):
	case (40401):
	case (40804):
	case (41209):
	case (41616):
	case (42025):
	case (42436):
	case (42849):
	case (43264):
	case (43681):
	case (44100):
	case (44521):
	case (44944):
	case (45369):
	case (45796):
	case (46225):
	case (46656):
	case (47089):
	case (47524):
	case (47961):
	case (48400):
	case (48841):
	case (49284):
	case (49729):
	case (50176):
	case (50625):
	case (51076):
	case (51529):
	case (51984):
	case (52441):
	case (52900):
	case (53361):
	case (53824):
	case (54289):
	case (54756):
	case (55225):
	case (55696):
	case (56169):
	case (56644):
	case (57121):
	case (57600):
	case (58081):
	case (58564):
	case (59049):
	case (59536):
	case (60025):
	case (60516):
	case (61009):
	case (61504):
	case (62001):
	case (62500):
	case (63001):
	case (63504):
	case (64009):
	case (64516):
	case (65025):
	case (65536):
	case (66049):
	case (66564):
	case (67081):
	case (67600):
	case (68121):
	case (68644):
	case (69169):
	case (69696):
	case (70225):
	case (70756):
	case (71289):
	case (71824):
	case (72361):
	case (72900):
	case (73441):
	case (73984):
	case (74529):
	case (75076):
	case (75625):
	case (76176):
	case (76729):
	case (77284):
	case (77841):
	case (78400):
	case (78961):
	case (79524):
	case (80089):
	case (80656):
	case (81225):
	case (81796):
	case (82369):
	case (82944):
	case (83521):
	case (84100):
	case (84681):
	case (85264):
	case (85849):
	case (86436):
	case (87025):
	case (87616):
	case (88209):
	case (88804):
	case (89401):
	case (90000):
	case (90601):
	case (91204):
	case (91809):
	case (92416):
	case (93025):
	case (93636):
	case (94249):
	case (94864):
	case (95481):
	case (96100):
	case (96721):
	case (97344):
	case (97969):
	case (98596):
	case (99225):
	case (99856):
		return true;
	default:
		return false;
	}
}

int main(void) {

	AtCoder::Num s = AtCoder::replaceToInteger(AtCoder::input());

	const int n = s[0], d = s[1];

	std::vector<AtCoder::Num> ds;
	for (int i = 0; i < n; i++) {
		ds.push_back(AtCoder::replaceToInteger(AtCoder::input()));
	}
	
	int ans = 0;

	for (int i = 0; i < (n - 1); i++) {
		for (int j = i; j < n; j++) {
			int bufans = 0;
			for (int kk = 0; kk < d; kk++) {
				int buf = 0;
				buf = ds[i][kk] - ds[j][kk];
				bufans += ( buf * buf );
			}
			if (checkLocal(bufans)) {
				ans++;
			}
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256