{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "file_name = 'A-small-attempt0.in'\n",
    "file_solu = 'A-small-attempt0.out'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def add_to_chars(chars, number):\n",
    "    for c in str(number):\n",
    "        chars.add(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "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: 952\n",
      "Case #6: 900\n",
      "Case #7: 1309\n",
      "Case #8: 1085\n",
      "Case #9: 900\n",
      "Case #10: 1800\n",
      "Case #11: 1160\n",
      "Case #12: 900\n",
      "Case #13: 70\n",
      "Case #14: 960\n",
      "Case #15: 90\n",
      "Case #16: 207\n",
      "Case #17: 980\n",
      "Case #18: 558\n",
      "Case #19: 198\n",
      "Case #20: 256\n",
      "Case #21: 560\n",
      "Case #22: 90\n",
      "Case #23: 1970\n",
      "Case #24: 1169\n",
      "Case #25: 918\n",
      "Case #26: 390\n",
      "Case #27: 469\n",
      "Case #28: 710\n",
      "Case #29: 9000\n",
      "Case #30: 798\n",
      "Case #31: 180\n",
      "Case #32: 9000\n",
      "Case #33: 1304\n",
      "Case #34: 2356\n",
      "Case #35: 456\n",
      "Case #36: 590\n",
      "Case #37: 665\n",
      "Case #38: 30\n",
      "Case #39: 576\n",
      "Case #40: 900\n",
      "Case #41: 290\n",
      "Case #42: 5478\n",
      "Case #43: 1253\n",
      "Case #44: 1296\n",
      "Case #45: 900\n",
      "Case #46: 1892\n",
      "Case #47: 900\n",
      "Case #48: 90\n",
      "Case #49: 1520\n",
      "Case #50: 104\n",
      "Case #51: 301\n",
      "Case #52: 910\n",
      "Case #53: 900\n",
      "Case #54: 92\n",
      "Case #55: 96\n",
      "Case #56: 896\n",
      "Case #57: 369\n",
      "Case #58: 564\n",
      "Case #59: 1176\n",
      "Case #60: 680\n",
      "Case #61: 495\n",
      "Case #62: 945\n",
      "Case #63: 990\n",
      "Case #64: 904\n",
      "Case #65: 715\n",
      "Case #66: 1990\n",
      "Case #67: 890\n",
      "Case #68: 940\n",
      "Case #69: 90\n",
      "Case #70: 190\n",
      "Case #71: 970\n",
      "Case #72: 570\n",
      "Case #73: 1096\n",
      "Case #74: 924\n",
      "Case #75: 792\n",
      "Case #76: 545\n",
      "Case #77: 730\n",
      "Case #78: 946\n",
      "Case #79: 345\n",
      "Case #80: 1239\n",
      "Case #81: 990\n",
      "Case #82: 1890\n",
      "Case #83: 90\n",
      "Case #84: 920\n",
      "Case #85: 1701\n",
      "Case #86: 390\n",
      "Case #87: 539\n",
      "Case #88: 918\n",
      "Case #89: 792\n",
      "Case #90: 912\n",
      "Case #91: 930\n",
      "Case #92: 819\n",
      "Case #93: 1071\n",
      "Case #94: 552\n",
      "Case #95: 1936\n",
      "Case #96: 830\n",
      "Case #97: 2625\n",
      "Case #98: 609\n",
      "Case #99: 1040\n",
      "Case #100: 203\n"
     ]
    }
   ],
   "source": [
    "with open(file_name, 'r') as input_file:\n",
    "    with open(file_solu, 'w') as output_file:\n",
    "        T = int(input_file.readline())\n",
    "        for case in range(T):\n",
    "            N = int(input_file.readline())\n",
    "            chars = set()\n",
    "            if N == 0:\n",
    "                print \"Case #%d: INSOMNIA\"%(case+1)\n",
    "                output_file.write(\"Case #%d: INSOMNIA\\n\"%(case+1))\n",
    "            else:\n",
    "                for i in range(1, int(1e5)):\n",
    "                    num = N*i\n",
    "                    add_to_chars(chars, num)\n",
    "                    if len(chars) == 10:\n",
    "                        print \"Case #%d: %d\"%(case+1,num)\n",
    "                        output_file.writelines(\"Case #%d: %d\\n\"%(case+1,num))\n",
    "                        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
