Lang:Python2
Edit1234567891011121314151617181920212223n, m = map(int, raw_input().split())s = raw_input()len_list = []for w in s.split():len_list.append(len(w))times = 1row = 1col = 0temp = 0while times <= n:for w in len_list:temp += wif temp == m:row += 1temp = 0elif temp > m:row += 1temp = wcol = temptemp += 1times += 1print row, col