{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Case # 1 :  INSOMNIA\n",
      "Case # 2 : 10\n",
      "Case # 3 : 90\n",
      "Case # 4 : 110\n",
      "Case # 5 : 594\n",
      "Case # 6 : 1296\n",
      "Case # 7 : 900\n",
      "Case # 8 : 90\n",
      "Case # 9 : 1910\n",
      "Case # 10 : 549\n",
      "Case # 11 : 749\n",
      "Case # 12 : 792\n",
      "Case # 13 : 560\n",
      "Case # 14 : 609\n",
      "Case # 15 : 2356\n",
      "Case # 16 : 1110\n",
      "Case # 17 : 805\n",
      "Case # 18 : 476\n",
      "Case # 19 : 1304\n",
      "Case # 20 : 1036\n",
      "Case # 21 : 345\n",
      "Case # 22 : 729\n",
      "Case # 23 : 920\n",
      "Case # 24 : 1085\n",
      "Case # 25 : 189\n",
      "Case # 26 : 70\n",
      "Case # 27 : 1190\n",
      "Case # 28 : 552\n",
      "Case # 29 : 1176\n",
      "Case # 30 : 2560\n",
      "Case # 31 : 1136\n",
      "Case # 32 : 790\n",
      "Case # 33 : 270\n",
      "Case # 34 : 976\n",
      "Case # 35 : 9000\n",
      "Case # 36 : 490\n",
      "Case # 37 : 918\n",
      "Case # 38 : 378\n",
      "Case # 39 : 896\n",
      "Case # 40 : 1107\n",
      "Case # 41 : 1701\n",
      "Case # 42 : 900\n",
      "Case # 43 : 459\n",
      "Case # 44 : 1930\n",
      "Case # 45 : 790\n",
      "Case # 46 : 189\n",
      "Case # 47 : 924\n",
      "Case # 48 : 1309\n",
      "Case # 49 : 1048\n",
      "Case # 50 : 558\n",
      "Case # 51 : 1208\n",
      "Case # 52 : 576\n",
      "Case # 53 : 900\n",
      "Case # 54 : 1800\n",
      "Case # 55 : 970\n",
      "Case # 56 : 1990\n",
      "Case # 57 : 5478\n",
      "Case # 58 : 198\n",
      "Case # 59 : 870\n",
      "Case # 60 : 1038\n",
      "Case # 61 : 90\n",
      "Case # 62 : 1590\n",
      "Case # 63 : 730\n",
      "Case # 64 : 190\n",
      "Case # 65 : 119\n",
      "Case # 66 : 9000\n",
      "Case # 67 : 912\n",
      "Case # 68 : 905\n",
      "Case # 69 : 1239\n",
      "Case # 70 : 90\n",
      "Case # 71 : 900\n",
      "Case # 72 : 156\n",
      "Case # 73 : 470\n",
      "Case # 74 : 910\n",
      "Case # 75 : 900\n",
      "Case # 76 : 930\n",
      "Case # 77 : 900\n",
      "Case # 78 : 330\n",
      "Case # 79 : 2475\n",
      "Case # 80 : 360\n",
      "Case # 81 : 990\n",
      "Case # 82 : 590\n",
      "Case # 83 : 792\n",
      "Case # 84 : 730\n",
      "Case # 85 : 801\n",
      "Case # 86 : 92\n",
      "Case # 87 : 1390\n",
      "Case # 88 : 396\n",
      "Case # 89 : 90\n",
      "Case # 90 : 830\n",
      "Case # 91 : 710\n",
      "Case # 92 : 945\n",
      "Case # 93 : 896\n",
      "Case # 94 : 1276\n",
      "Case # 95 : 96\n",
      "Case # 96 : 30\n",
      "Case # 97 : 1352\n",
      "Case # 98 : 290\n",
      "Case # 99 : 456\n",
      "Case # 100 : 576\n"
     ]
    }
   ],
   "source": [
    "# input() reads a string with a line of input, stripping the '\\n' (newline) at the end.\n",
    "# This is all you need for most Google Code Jam problems.\n",
    "\n",
    "fil = open(\"A-small-attempt2.in.txt\").readlines()\n",
    "t = int(fil[0])  # read a line with a single integer\n",
    "def populate(m):\n",
    "    #print 'enter populate'\n",
    "    while m>0 and -1 in array:\n",
    "        digit = m%10\n",
    "        array[digit] += 1\n",
    "        #print digit\n",
    "        #print array\n",
    "        m = m/10\n",
    "        \n",
    "for i in range(1, t+1):\n",
    "    array = [-1 for p in range(10)]\n",
    "    m = int(fil[i])  # read a list of integers, 2 in this case\n",
    "    j = 1\n",
    "    if m == 0:\n",
    "        print\"Case #\",i,\":\",\" INSOMNIA\"\n",
    "    else:\n",
    "        while -1 in array:\n",
    "            l = m*j\n",
    "            #print 'number passed',l\n",
    "            populate(l)\n",
    "            j += 1\n",
    "        if -1 in array:\n",
    "            print\"Case #\",i,\":\",\" INSOMNIA\"\n",
    "        else:\n",
    "            print \"Case #\",i,\":\",l\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
