Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string s of length n, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string s. The newspaper contains string t, consisting of uppercase and lowercase English letters. We know that the length of string t greater or equal to the length of the string s.The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some n letters out of the newspaper and make a message of length exactly n, so that it looked as much as possible like s. If the letter in some position has correct value and correct letter case (in the string s and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS".Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.

The first line contains line s (1 ≤ |s| ≤ 2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message. The second line contains line t (|s| ≤ |t| ≤ 2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper. Here |a| means the length of the string a.

Print two integers separated by a space:   the first number is the number of times Tanya shouts "YAY!" while making the message,  the second number is the number of times Tanya says "WHOOPS" while making the message.

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val need = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val haveO = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val res = need.foldLeft((haveO, Map.empty[Char, Int], 0)) {
    case((have, newNeed, yes), (el, count)) =>
      val newYes = Math.min(have.getOrElse(el, 0), count)
      (have + (el -> (have.getOrElse(el, 0) - newYes)),
        newNeed + (el -> (count - newYes)),
        yes + newYes)
  }
  val res2 = res._2.foldLeft(0) {
    case(no, (el, count)) =>
      val diffSymbol = if (el.isLower) el.toUpper else el.toLower
      no + Math.min(res._1.getOrElse(diffSymbol, 0), count)
  }

  println(s"${res._3} $res2")
}

import scala.collection.mutable

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object B518 extends App {

  def solve() = {
    val str: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val txt: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val strMap: Map[Char, Int] = str.groupBy(s => s).map(e => e._1 -> e._2.length)
    var txtMap: Map[Char, Int] = txt.groupBy(s => s).map(e => e._1 -> e._2.length)
    var postMap: mutable.Map[Char, Int] = mutable.Map.empty[Char, Int]
    var hooray = 0
    var opa = 0
    strMap.foreach(e => {
      if (txtMap.contains(e._1)) {
        if (e._2 <= txtMap.get(e._1).get) {
          hooray += e._2
          txtMap += (e._1 -> (txtMap.get(e._1).get - e._2))
        } else {
          hooray += txtMap.get(e._1).get
          postMap += (e._1 -> (-txtMap.get(e._1).get + e._2))
          txtMap -= e._1
        }
      } else {
        postMap += (e._1 -> e._2)
      }
    })
    postMap.foreach(e => {
      if (Character.isUpperCase(e._1)) {
        val chLower = Character.toLowerCase(e._1)
        if (txtMap.contains(chLower)) {
          if (e._2 <= txtMap.get(chLower).get) {
            opa += e._2
            txtMap += (chLower -> (txtMap.get(chLower).get - e._2))
          } else {
            opa += txtMap.get(chLower).get
            txtMap -= chLower
          }
        }
      } else {
        val chUpper = Character.toUpperCase(e._1)
        if (txtMap.contains(chUpper)) {
          if (e._2 <= txtMap.get(chUpper).get) {
            opa += e._2
            txtMap += (chUpper -> (txtMap.get(chUpper).get - e._2))
          } else {
            opa += txtMap.get(chUpper).get
            txtMap -= chUpper
          }
        }
      }
    })
    println(hooray + " " + opa)
  }

  solve()

}

import java.io._
import java.util
import java.util._

object B {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = {
    return Integer.parseInt(next)
  }

  def nextLong: Long = {
    return java.lang.Long.parseLong(next)
  }

  def solve: Int = {
    val s = next.toCharArray
    val t = next.toCharArray
    val m = new scala.collection.mutable.HashMap[Char, Int]()
    for (i <- 0 until t.length) {
      val x = m.getOrElse(t(i), 0)
      m.put(t(i), x + 1)
    }
    var u = 0
    var o = 0
    val missed = new util.ArrayList[Char]()
    for (i <- 0 until s.length) {
      val symb = s(i)
      val x = m.getOrElse(symb, 0)
      if (x > 0) {
        u += 1
        m.put(symb, x - 1)
      } else {
        missed.add(symb)
      }
    }
    for (i <- 0 until missed.size()) {
      val symb = missed.get(i)
      if (Character.isUpperCase(symb)) {
        val lowerCase: Char = Character.toLowerCase(symb)
        val y = m.getOrElse(lowerCase, 0)
        if (y > 0) {
          o += 1
          m.put(lowerCase, y - 1)
        }
      } else {
        val upCase: Char = Character.toUpperCase(symb)
        val y = m.getOrElse(upCase, 0)
        if (y > 0) {
          o += 1
          m.put(upCase, y - 1)
        }
      }

    }
    out.println(u + " " + o)
    return 1
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

object Main extends App {

  val letters = (97 to 122).map(_.toChar).map(_.toString)

  def counter[A](seq: Seq[A]): Map[A, Int] = {
    seq.foldLeft(Map[A, Int]())({
      (acc, n) => acc.get(n) match {
        case None => acc + (n -> 1)
        case Some(m) => acc + (n -> (m+1))
      }
    })
  }

  val s = readLine.map(_.toString).toList
  val t = readLine.map(_.toString).toList
  val s1 = counter(s)
  val t1 = counter(t)

  val init = (0, 0)
  val (pos, neg) = letters.foldLeft(init)({
    case ((pos, neg), letter) =>
      val sLower = s1.getOrElse(letter, 0)
      val sUpper = s1.getOrElse(letter.toUpperCase, 0)
      val tLower = t1.getOrElse(letter, 0)
      val tUpper = t1.getOrElse(letter.toUpperCase, 0)
      val usedLower = Math.min(sLower, tLower)
      val usedUpper = Math.min(sUpper, tUpper)
      val pos2 = usedLower + usedUpper
      val neg2 = Math.min((sLower-usedLower), (tUpper - usedUpper)) + Math.min((sUpper-usedUpper), (tLower - usedLower))
      (pos + pos2, neg + neg2)
  })

  println("%d %d".format(pos, neg))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val need = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val have = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val res = need.foldLeft((have, 0, 0)) {
    case((have, yes, no), (el, count)) =>
      val newYes = Math.min(have.getOrElse(el, 0), count)
      val diffSymbol = if (el.isLower) el.toUpper else el.toLower
      if (newYes == count) {
        (have + (el -> (have.getOrElse(el, 0) - newYes)), yes + newYes, no)
      }
      else {
        val newNo = Math.min(count - newYes, have.getOrElse(diffSymbol, 0))
        (have + (el -> (have.getOrElse(el, 0) - newYes)) +
          (diffSymbol -> (have.getOrElse(diffSymbol, 0) - newNo))
          , yes + newYes, no + newNo)
      }
  }

  println(s"${res._2} ${res._3}")
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val need = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val haveO = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val res = need.foldLeft((haveO, 0, 0)) {
    case((have, yes, no), (el, count)) =>
      val newYes = Math.min(have.getOrElse(el, 0), count)
      val diffSymbol = if (el.isLower) el.toUpper else el.toLower
      val newNo = Math.min(count - newYes, have.getOrElse(diffSymbol, 0))
      (have + (el -> (have.getOrElse(el, 0) - newYes)) +
        (diffSymbol -> (have.getOrElse(diffSymbol, 0) - newNo))
        , yes + newYes, no + newNo)
  }

  println(s"${res._2} ${res._3}")
}

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object B518 extends App {

  def solve() = {
    val str: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val txt: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val strMap: Map[Char, Int] = str.groupBy(s => s).map(e => e._1 -> e._2.length)
    var txtMap: Map[Char, Int] = txt.groupBy(s => s).map(e => e._1 -> e._2.length)
    var hooray = 0
    var opa = 0
    strMap.foreach(e => {
      if (txtMap.contains(e._1)) {
        if (e._2 <= txtMap.get(e._1).get) {
          hooray += e._2
          txtMap += (e._1 -> (txtMap.get(e._1).get - e._2))
        } else {
          hooray += txtMap.get(e._1).get
          txtMap -= e._1
        }
      }
      if (Character.isUpperCase(e._1)) {
        if (txtMap.contains(Character.toLowerCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toLowerCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toLowerCase(e._1) -> (txtMap.get(Character.toLowerCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toLowerCase(e._1)).get
            txtMap -= Character.toLowerCase(e._1)
          }
        }
      } else {
        if (txtMap.contains(Character.toUpperCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toUpperCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toUpperCase(e._1) -> (txtMap.get(Character.toUpperCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toUpperCase(e._1)).get
            txtMap -= Character.toUpperCase(e._1)
          }
        }
      }
    })
    println(hooray + " " + opa)
  }

  solve()

}

import scala.collection.mutable

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object B518 extends App {

  def solve() = {
    val str: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val txt: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val strMap: Map[Char, Int] = str.groupBy(s => s).map(e => e._1 -> e._2.length)
    var txtMap: Map[Char, Int] = txt.groupBy(s => s).map(e => e._1 -> e._2.length)
    var postMap: mutable.Map[Char, Int] = mutable.Map.empty[Char, Int]
    var hooray = 0
    var opa = 0
    strMap.foreach(e => {
      if (txtMap.contains(e._1)) {
        if (e._2 <= txtMap.get(e._1).get) {
          hooray += e._2
          txtMap += (e._1 -> (txtMap.get(e._1).get - e._2))
        } else {
          hooray += txtMap.get(e._1).get
          txtMap -= e._1
          postMap += (e._1 -> e._2)
        }
      } else {
        postMap += (e._1 -> e._2)
      }
    })
    postMap.foreach(e => {
      if (Character.isUpperCase(e._1)) {
        if (txtMap.contains(Character.toLowerCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toLowerCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toLowerCase(e._1) -> (txtMap.get(Character.toLowerCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toLowerCase(e._1)).get
            txtMap -= Character.toLowerCase(e._1)
          }
        }
      } else {
        if (txtMap.contains(Character.toUpperCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toUpperCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toUpperCase(e._1) -> (txtMap.get(Character.toUpperCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toUpperCase(e._1)).get
            txtMap -= Character.toUpperCase(e._1)
          }
        }
      }
    })
    println(hooray + " " + opa)
  }

  solve()

}

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object B518 extends App {

  def solve() = {
    val str: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val txt: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val strMap: Map[Char, Int] = str.groupBy(s => s).map(e => e._1 -> e._2.length)
    var txtMap: Map[Char, Int] = txt.groupBy(s => s).map(e => e._1 -> e._2.length)
    var hooray = 0
    var opa = 0
    strMap.foreach(e => {
      if (txtMap.contains(e._1)) {
        if (e._2 <= txtMap.get(e._1).get) {
          hooray += e._2
          txtMap += (e._1 -> (txtMap.get(e._1).get - e._2))
        } else {
          hooray += txtMap.get(e._1).get
          txtMap -= e._1
          if (Character.isUpperCase(e._1)) {
            if (txtMap.contains(Character.toLowerCase(e._1))) {
              if (e._2 <= txtMap.get(Character.toLowerCase(e._1)).get) {
                opa += e._2
                txtMap += (Character.toLowerCase(e._1) -> (txtMap.get(Character.toLowerCase(e._1)).get - e._2))
              } else {
                opa += txtMap.get(Character.toLowerCase(e._1)).get
                txtMap -= Character.toLowerCase(e._1)
              }
            }
          } else {
            if (txtMap.contains(Character.toUpperCase(e._1))) {
              if (e._2 <= txtMap.get(Character.toUpperCase(e._1)).get) {
                opa += e._2
                txtMap += (Character.toUpperCase(e._1) -> (txtMap.get(Character.toUpperCase(e._1)).get - e._2))
              } else {
                opa += txtMap.get(Character.toUpperCase(e._1)).get
                txtMap -= Character.toUpperCase(e._1)
              }
            }
          }
        }
      }
      if (Character.isUpperCase(e._1)) {
        if (txtMap.contains(Character.toLowerCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toLowerCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toLowerCase(e._1) -> (txtMap.get(Character.toLowerCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toLowerCase(e._1)).get
            txtMap -= Character.toLowerCase(e._1)
          }
        }
      } else {
        if (txtMap.contains(Character.toUpperCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toUpperCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toUpperCase(e._1) -> (txtMap.get(Character.toUpperCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toUpperCase(e._1)).get
            txtMap -= Character.toUpperCase(e._1)
          }
        }
      }
    })
    println(hooray + " " + opa)
  }

  solve()

}

import java.io._
import java.util
import java.util._

object B {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = {
    return Integer.parseInt(next)
  }

  def nextLong: Long = {
    return java.lang.Long.parseLong(next)
  }

  def solve: Int = {
    val s = next.toCharArray
    val t = next.toCharArray
    val m = new scala.collection.mutable.HashMap[Char, Int]()
    for (i <- 0 until t.length) {
      val x = m.getOrElse(t(i), 0)
      m.put(t(i), x + 1)
    }
    var u = 0
    var o = 0
    for (i <- 0 until s.length) {
      val symb = s(i)
      val x = m.getOrElse(symb, 0)
      if (x > 0) {
        u += 1
        m.put(symb, x - 1)
      } else {
        if (Character.isUpperCase(symb)) {
          val lowerCase: Char = Character.toLowerCase(symb)
          val y = m.getOrElse(lowerCase, 0)
          if (y > 0) {
            o += 1
            m.put(lowerCase, y - 1)
          }
        } else {
          val upCase: Char = Character.toUpperCase(symb)
          val y = m.getOrElse(upCase, 0)
          if (y > 0) {
            o += 1
            m.put(upCase, y - 1)
          }
        }
      }
    }
    out.println(u + " " + o)
    return 1
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

import java.io._
import java.util
import java.util._

object B {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = {
    return Integer.parseInt(next)
  }

  def nextLong: Long = {
    return java.lang.Long.parseLong(next)
  }

  def solve: Int = {
    val s = next
    val t = next.toCharArray
    val m = new scala.collection.mutable.HashMap[Char, Int]()
    for (i <- 0 until t.length) {
      val x = m.getOrElse(t(i), 0)
      m.put(t(i), x + 1)
    }
    var u = 0
    var o = 0
    for (i <- 0 until s.length) {
      val x = m.getOrElse(s(i), 0)
      if (x > 0) {
        u += 1
        m.put(s(i), x - 1)
      } else {
        if (Character.isUpperCase(s(i))) {
          val lowerCase: Char = Character.toLowerCase(s(i))
          val y = m.getOrElse(lowerCase, 0)
          if (y > 0) {
            o += 1
            m.put(lowerCase, y - 1)
          }
        }
        else {
          val upCase: Char = Character.toUpperCase(s(i))
          val y = m.getOrElse(upCase, 0)
          if (y > 0) {
            o += 1
            m.put(upCase, y - 1)
          }
        }
      }
    }
    out.println(u + " " + o)
    return 1
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}


Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.  So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. The battery of the newest device allows to highlight at most n sections on the display. Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer.

The first line contains the integer n (2 ≤ n ≤ 100 000) — the maximum number of sections which can be highlighted on the display.

Print the maximum integer which can be shown on the display of Stepan's newest device.

object Main extends App {
    var ans :String = ""
    val n = readInt

    if (n % 2 == 0) {
      for (i <- 1 to n / 2) {
        print(1)
      }
    }
   else {
     print(7)
     for (i <- 1 to (n - 3) / 2) {
       print(1)
     }
   }

    println()

}

object Main extends App {
    val n = readInt
   if(n%2==0){
        for (i <- 1 to n/2) {
         print(1)
        }
   }
   else{
       print(7)
        for (i <- 1 to (n-3)/2) {
         print(1)
        }

   }
}

object Main extends App {
    var n = readInt
    if(n%2==1){
        print(7)
        n=n-3
    }
    n/=2
    for (i <- 1 to n) {
        print(1)
    }
}

object Main extends App {
    var n = readInt;
    var num = 0;
    if(n % 2 == 1 && n > 1){
        print(7);
        n -= 3;
    }
    while(n > 1){
        n -= 2;
        print(1);
    }
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1) {
        print("7")
        n = n - 3
    }
    while (n >= 2) {
        print("1")
        n = n - 2
    }
    println("")
}

object Main extends App {
  val cost = Array( 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 )
  var N = readInt // keyword val seems to work like const, in contrast to var
  if( N % 2 == 1 ) {
    print( 7 )
    N -= 3
  }
  while( N > 0 ) {
    print( 1 )
    N -= 2
  }
  println()
}

object HelloWorld {
    def main(args: Array[String])
    {
        var n = readInt;
        var i = 0;
        if(n%2==0) print(1);
        else print(7);
        for(i <- 2 to n/2)
        {
            print(1);
        }
    }
}

object Main extends App {
    val n = readInt
    if (n % 2 == 1)
    {
        print(7);
        for (i <- 1 to (n - 3) / 2)
            print(1);
    }
    else
    {
        for (i <- 1 to n / 2)
            print(1);
    }
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1) {
        n = n - 3;
        print(7)
    }
    while (n >= 2) {
        n = n - 2;
        print(1)
    }
}

object X extends App {
  val n = scala.io.StdIn.readLine.toInt
  if (n < 2)
    println(0)
  else {
    var res = 1
    if (n % 2 == 1) res = 7
    print(res)
    for (i <- 2 to n/2) {
        print(1);
    }
    println()
  }
}

object TEST extends App{
    var n = readInt
    if(n%2==1)
    {
        print(7)
        n-=3
    }
    for(i <- 1 to n/2) print(1)
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1)
    {
        print(7)
        n = n - 3
    }
    for (i <- 1 to n / 2) print(1)
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1) {
        print("7")
        n = n - 3
    }

    for (i <- 1 to n / 2) {
        print("1")
    }
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1) {
        print(7)
        n = n - 3
    }
    n = n / 2
    for (i <- 1 to n) {
        print(1)
        //println(if (k <= 10) s else s(0) + (k - 2).toString + s(k-1))
    }
}

object c {
    def main(args: Array[String]) {
      val n = readInt()
      var seven = 0
      var one = 0
      if (n % 2 == 1) {
          one = n / 2 - 1
          seven = 1
      } else {
          one = n / 2
      }

      for (i <- 1 to seven) {
          print(7)
      }
      for (i <- 1 to one) {
          print(1)
      }
   }
}

object Main extends App {
	var n = readInt
	if (n % 2 == 1) {
		print(7)
		n = n - 3
	}
	while( n > 0 ) {
		print(1)
		n = n - 2
	}
}

object Main extends App {
	// your code goes here
	var n = readInt
	while (n > 0) {
		if (n % 2 == 1) {
			n -= 3;
			print(7);
		}
		else {
			n -= 2;
			print(1);
		}
	}
}

object Main extends App {
    val n = readInt
    var a = 0
    if (n % 2 == 0) {
        for ( a <- 1 to n / 2) {
            print(1);
        }
    } else {
        print(7);
        for ( a <- 1 to n / 2 - 1) {
            print(1);
        }
    }
}

import java.util.Scanner
object Main extends App {
	val in = new Scanner(System.in)
	var n = in.nextInt()
	if (n % 2 == 1) {
		print(7)
		n = n - 3
	}
	n = n / 2
	var a = 0
	for(a <- 1 to n)
	    print(1)
}

object Main extends App {
    val n = readInt
	val k = n / 2 - 1
	val t = n % 2
	print(if (t == 1) '7' else '1')
	for (i <- 1 to k) {
		print('1')
	}
}

object Main extends App {
    val n = readInt
    print(if (n % 2 == 0) 1 else 7)
    for (i <- 1 to (n - 2) / 2) print(1)
}

object Main extends App {
    var n = readInt
    if(n%2==1){
        println(7)
        n=n-3
    }
    n/=2
    for (i <- 1 to n) {
        println(1)
    }
}

object Main extends App {
  val cost = Array( 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 )
  var N = readInt // keyword val seems to work like const, in contrast to var
  while( N >= 2 ) {
    // for に break のキーワードはないらしい...
    var i = 9
    while( i >= 0 ) {
      if( N >= cost( i ) ) { // [] ではなく () なんですね...
        print( i )
        N -= cost( i )
        i = -1 // break とする
      }
      i -= 1
    }
  }
  println()
}

object HelloWorld {
    def main(args: Array[String])
    {
        var n = readInt;
        var i = 0;
        if(n%2==0) print(1);
        else print(7);
        for(i <- 1 to n/2)
        {
            print(1);
        }
    }
}

object X extends App {
  val n = scala.io.StdIn.readLine.toInt
  if (n < 2)
    println(0)
  else {
    var res = 1
    if (n % 2 == 1) res = 7
    for (i <- 2 to n/2) {
        res = res * 10 + 1;
    }
    println(res)
  }
}

object c {
    def main(args: Array[String]) {
      val n = readInt()
      var seven = 0
      var one = 0
      if (n % 3 == 1) {
          seven = n / 3 - 1
          one = 2
      } else if (n % 3 == 2) {
          seven = n / 3
          one = 1
      } else {
          seven = n / 3
      }

      for (i <- 1 to seven) {
          print(7)
      }
      for (i <- 1 to one) {
          print(1)
      }
   }
}

object Main extends App {
	var n = readInt
	while( n > 3 ) {
		print(1)
		n = n - 2
	}
	if (n == 3)
		print(7)
	else
		print(1)
}

import java.util.Scanner
object Main extends App {
	val in = new Scanner(System.in)
	var n = in.nextInt()
	if (n % 2 == 1) {
		print(7)
		n = n - 1
	}
	n = n / 2
	var a = 0
	for(a <- 1 to n)
	    print(1)
}


Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute.Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes up in another.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of alarms. Each of the next n lines contains a description of one alarm. Each description has a format "hh:mm", where hh is the hour when the alarm rings, and mm is the minute of that hour when the alarm rings. The number of hours is between 0 and 23, and the number of minutes is between 0 and 59. All alarm times are distinct. The order of the alarms is arbitrary. Each alarm starts ringing in the beginning of the corresponding minute and rings for exactly one minute (i. e. stops ringing in the beginning of the next minute). Polycarp can start sleeping instantly when no alarm is ringing, and he wakes up at the moment when some alarm starts ringing.

Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. hh denotes the number of hours, and mm denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better.

NoteIn the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.

object Solution {
   def main(args: Array[String]) {
      val sc = new java.util.Scanner(System.in);
      val n: Int = sc.nextInt();
      var i = 0;
      var t = new Array[Boolean](1440);

      for (i <- 0 to 1439) t(i) = false;

      for (i <- 0 to n-1) {
          var s = sc.next();
          var arr = s.split(":");

          var x = arr(0).toInt * 60 + arr(1).toInt;
          t(x) = true;
      }

      var res = 0;
      var cnt = 0;
      for (i <- 0 to 3000) {
          if (t(i % 1440) == false) cnt += 1; else cnt = 0;
          if (cnt > res) res = cnt;
      }

      var h = res / 60;
      var m = res % 60;

      println(f"$h%02d:$m%02d");
   }
}


Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ..., xr, where xi is the i-th element of the array x. You are given two arrays a and b of length n. You need to determine the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays. The second line contains n integers ai (0 ≤ ai ≤ 109). The third line contains n integers bi (0 ≤ bi ≤ 109).

Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

NoteBitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation.In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose l = 1 and r = 4, l = 1 and r = 5, l = 2 and r = 4, l = 2 and r = 5, l = 3 and r = 4, or l = 3 and r = 5.In the second sample, the maximum value is obtained for l = 1 and r = 9.

import java.io._
import java.util.Scanner

import scala.collection.mutable.ListBuffer

object Solution extends ConsoleIO {
  def main(args: Array[String]) = {
    withIO {(reader, writer) =>
      val n = reader.nextInt()
      val a = ListBuffer.empty[Int]
      (1 to n).foreach { _ =>
        a.append(reader.nextInt())
      }
      val b = ListBuffer.empty[Int]
      (1 to n).foreach { _ =>
        b.append(reader.nextInt())
      }
      val result = a.reduce( _ | _)  + b.reduce(_ | _)
      writer.print(result)
    }
  }
}

trait ConsoleIO {
  def withIO(task: (Scanner, PrintWriter) => Unit) = {
    val reader = new Scanner(new BufferedReader(new InputStreamReader(System.in)))
    val writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
    task(reader, writer)
    reader.close()
    writer.close()
  }
}

trait FileIO {
  def withIO(task: (Scanner, PrintWriter) => Unit) = {
    val reader = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))))
    val writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output.txt"))))
    task(reader, writer)
    reader.close()
    writer.close()
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt).zip(in.next().split(' ').map(_.toInt))
  println((0 until n).foldLeft(0) {
    case (acc, i) =>
      val drop1 = data.drop(i)
      val head = drop1.head
      drop1.tail.foldLeft(head, Math.max(acc, head._1 + head._2)) {
        case (((fSoFar, sSoFar), max), (first, second)) =>
          val nfSoFar = fSoFar | first
          val nsSoFar = sSoFar | second
          ((nfSoFar, nsSoFar), Math.max(max, nfSoFar + nsSoFar))
      }._2
  })
}

object A631 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(num) = readInts(1)
    val a = readInts(num).foldLeft(0L){case (sum, n) => sum|n}
    val b = readInts(num).foldLeft(0L){case (sum, n) => sum|n}
    println(a+b)
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine;
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

object Interview extends App {
  //println((1 to 1000).mkString(" "))
  val n = scala.io.StdIn.readLine().toInt
  val array1 = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val array2 = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def fSum(x1: Array[Int], x2: Array[Int], l: Int, r: Int): Int = {
    var sum1 = x1(l)
    var sum2 = x2(l)
    var i = l + 1
    while (i <= r) {
      sum1 = sum1 | x1(i)
      sum2 = sum2 | x2(i)
      i += 1
    }
    sum1 + sum2
  }

  var max = fSum(array1, array2, 0, 0)
  var l = 0
  while (l < n - 1) {
    var r = l
    while (r < n) {
      val candidate = fSum(array1, array2, l, r)
      if (candidate > max) max = candidate
      r += 1
    }
    l += 1
  }

  println(max)
}

import annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._

object _631A extends CodeForcesApp {
  override type Result = Long

  override def solve(read: InputReader) = {
    val n = read[Int]
    val a, b = read[IndexedSeq, Long](n).foldLeft(0L){case (i, j) => i | j}
    a + b
  }

  override def format(result: Result) = result.toString
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  type Result
  def solve(scanner: InputReader): Result
  def format(result: Result): String
  def apply(scanner: InputReader): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))
  def this(str: String) = this(new StringReader(str))

  private[this] val tokenizers = Iterator.continually(reader.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered

  @inline private[this] def tokenizer(): Option[StringTokenizer] = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    if (tokenizers.nonEmpty) Some(tokenizers.head) else None
  }

  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)

  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {
    val builder = cbf()
    for {_ <- 1 to n} builder += apply[A]
    builder.result()
  }

  def till(delim: String): String = tokenizer().get.nextToken(delim)
  def tillEndOfLine() = till("\n\r")

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

class Parser[A](val apply: InputReader => A) {
  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)
}
object Parser {
  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]
  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))
  implicit val string                                                        : Parser[String]          = new Parser(_.next())
  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)
  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)
  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)
  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))
  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)
  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))
  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))
  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))
  implicit def tuple4[A: Parser, B: Parser, C: Parser, D: Parser]            : Parser[(A, B, C, D)]    = new Parser(r => (r[A], r[B], r[C], r[D]))
  implicit def tuple5[A: Parser, B: Parser, C: Parser, D: Parser, E: Parser] : Parser[(A, B, C, D, E)] = new Parser(r => (r[A], r[B], r[C], r[D], r[E]))
}

/**
 * Created by aborisenko on 21.02.16.
 */

import io.StdIn._

object Main extends App {
  def a631 (){

    val n = readInt()
    val a: Array[Long] = readLine().split(" ").map(_.toLong)
    val b: Array[Long] = readLine().split(" ").map(_.toLong)

    var result1: Long = 0
    for( i <- 0 to n-1)
      result1 |= a(i)
    var result2: Long = 0

    for( i <- 0 to n-1)
      result2 |= b(i)

    println(result1 + result2)
  }

  a631()
}

import scala.io.StdIn

/**
  * http://codeforces.com/problemset/problem/631/A
  * */
object AInterview {

  private def orValues(values: Seq[Long]): Long = {
    values.foldLeft(0L)(_ | _)
  }

  def main(args: Array[String]): Unit = {
    StdIn.readLine()
    val fstValues = StdIn.readLine().split(" ").map(_.toLong)
    val scdValues = StdIn.readLine().split(" ").map(_.toLong)
    val result = orValues(fstValues) + orValues(scdValues)
    println(result)
  }
}

object Interview extends App {
  //println((1 to 1000).mkString(" "))
  val n = scala.io.StdIn.readLine().toInt
  val array1 = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val array2 = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def fSum(x1: Array[Int], x2: Array[Int], l: Int, r: Int): Int = {
    var sum1 = x1(l)
    var sum2 = x2(l)
    var i = l + 1
    while (i < r) {
      sum1 = sum1 | x1(i)
      sum2 = sum2 | x2(i)
      i = i + 1
    }
    sum1 + sum2
  }

  var max = fSum(array1, array2, 0, 0)
  var l = 0
  while (l < n - 1) {
    var r = l
    while (r < n) {
      val candidate = fSum(array1, array2, l, r)
      if (candidate > max) max = candidate
      r = r + 1
    }
    l = l + 1
  }

  println(max)
}

object Interview extends App {
  //println((1 to 1000).mkString(" "))
  val n = scala.io.StdIn.readLine().toInt
  val array1 = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val array2 = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def fSum(x1: Array[Int], x2: Array[Int], l: Int, r: Int): Int = {
    var sum1 = x1(l)
    var sum2 = x2(l)
    var i = l + 1
    while(i < r) {
      sum1 = sum1 | x1(i)
      sum2 = sum2 | x2(i)
      i = i + 1
    }
    /*for {
      i <- (l + 1) until r
    } {
      sum1 = sum1 | x1(i)
      sum2 = sum2 | x2(i)
    }*/
    sum1 + sum2
  }

  var max = 0L
  var l = 0
  while(l < n -1) {
    var r = l + 1
    while(r < n) {
      val candidate = fSum(array1, array2, l, r)
      if (candidate > max) max = candidate
      r = r + 1
    }
    l = l + 1
  }
  /*for {
    l <- 0 until n - 1
    r <- l + 1 until n
  } {
    val candidate = fSum(array1, array2, l, r)
    if (candidate > max) max = candidate
  }*/

  println(max)
}


Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.Help Amr by choosing the smallest subsegment possible.

The first line contains one number n (1 ≤ n ≤ 105), the size of the array. The second line contains n integers ai (1 ≤ ai ≤ 106), representing elements of the array.

Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively. If there are several possible answers you may output any of them.

NoteA subsegment B of an array A from l to r is an array of size r - l + 1 where Bi = Al + i - 1 for all 1 ≤ i ≤ r - l + 1

//package c558.b

object Solution extends App {
  case class C3(counter: Int, left: Int, right: Int)
  case object C3 { def empty(i: Int) = C3(1, i, i) }
  def solve(n: Int, array: Seq[Int]) = {
    import scala.collection.mutable
    val indexedArray = array.zip(1 to n)
    val beautyMap = mutable.Map.empty[Int, C3]
    indexedArray.foreach(xi ⇒ {
      val (x, i) = xi._1 → xi._2
      val elem = beautyMap.getOrElse(x, C3.empty(i))
      beautyMap.put(x, elem.copy(counter = elem.counter + 1, right = i))
    })
    val maxElem = beautyMap.maxBy(kv ⇒ kv._2.counter)
    val best = beautyMap
      .filter(_._2.counter == maxElem._2.counter)
      .minBy(kv ⇒ kv._2.right - kv._2.left)._2
    s"${best.left} ${best.right}"
  }
  import scala.io.StdIn
  val n = StdIn.readInt()
  val array = StdIn.readLine().split(" ").map(_.toInt)
  println(solve(n, array))
}

import scala.io.StdIn.readLine
import scala.collection.mutable.PriorityQueue
import scala.annotation.tailrec

object Main {
  case class LR(left : Int, right : Int, cnt : Int)
  object EnRich {
    implicit class AString(val self : String) extends AnyVal {
      def splitToIntArray = self.split(" ").map(_.toInt)
    }
  }
  import EnRich._

  def main(args : Array[String]) : Unit = {
    val n = readLine.toInt
    val a = readLine.splitToIntArray
    val h = scala.collection.mutable.HashMap[Int,LR]()
    (a.zipWithIndex).foreach({case (a,i) => h.get(a) match {
                                case None => h(a) = LR(i,i,1)
                                case Some(LR(l,r,k)) => h(a) = LR(l,i,k+1)
                              }})
    val m = h.toList.map({case (_,LR(_,_,k)) => k}).max
    val f = h.toList.filter({case (_,LR(_,_,k)) => k == m}).
                     sortBy(({case (_,LR(l,r,_)) => r-l}))
    val l = f.head._2.left+1
    val r = f.head._2.right+1
    println(s"$l $r")
  }
}

import scala.collection.mutable.HashMap

object B extends App {
 val n = readInt
 val str = readLine.split(" ").map(_.toInt).zipWithIndex
 val mp = new HashMap[Int, (Int, Int, Int)]()
 for((i, j) <- str) {
 val k = mp.getOrElse(i, (0, 0, 0))
 if(k._1 == 0)
  mp(i) = (1, j, j)
 else
  mp(i) = (k._1 + 1, k._2, j)
 }

 val res = mp.toList.sortWith((i, j) => i._2._1 > j._2._1 || i._2._1 == j._2._1 && (i._2._3 - i._2._2) < (j._2._3 - j._2._2))(0)
 print(res._2._2 + 1 + " " + (res._2._3 + 1))
}

import annotation.tailrec, collection.mutable, util.control.Breaks._, math.Ordering.Implicits._
object _558B extends CodeForcesApp[(Int, Int)]({scanner => import scanner._
  val array = List.fill(nextInt)(nextInt)
  val start = mutable.Map.empty[Int, Int] withDefaultValue Integer.MAX_VALUE
  val end = mutable.Map.empty[Int, Int] withDefaultValue Integer.MIN_VALUE
  val counter = mutable.Map.empty[Int, Int] withDefaultValue 0
  for {(n, p) <- array.zipWithIndex} {
    start(n) = start(n) min p
    end(n) = end(n) max p
    counter(n) += 1
  }
  val (_, maxRepeat) = counter.maxBy(_._2)

  val answers = for {
    (n, count) <- counter if count == maxRepeat
  } yield start(n) -> end(n)

  answers minBy {case (x, y) => (y - x, x)}
}) {
  override def format(result: (Int, Int)) = result match {
    case (x, y) => s"${x+1} ${y+1}"
  }
}
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[B](x: Boolean)(f: => B): Option[B] = if (x) Some(f) else None
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}

import scala.io.StdIn.readLine

object AmrAndTheLargeArray{
  case class Triplet( left : Int, right : Int, count : Int)
  def main(args : Array[String]) : Unit = {
      readLine()
      val a = readLine().split("\\s+").map( _.toInt )
      val map = scala.collection.mutable.HashMap[Int, Triplet]()
      (a.zipWithIndex).foreach({
        case (a,i) => map.get(a) match {
          case None => map(a) = Triplet(i,i,1)
          case Some(Triplet(l,r,k)) => map(a) = Triplet(l,i,k+1)
        }
      })

      val ans = map.valuesIterator.reduceLeft( (thiz, that) => {
         if(thiz.count != that.count)
          if(thiz.count >= that.count) thiz else that
        else if ((thiz.right - thiz.left) <= (that.right - that.left)) thiz else that
      })

      val l = ans.left + 1
      val r = ans.right + 1
      println(l + " " + r)
  }
}

import scala.io.StdIn.readLine

object AmrAndTheLargeArray{
  case class Triplet( left : Int, right : Int, count : Int)
  def main(args : Array[String]) : Unit = {
      readLine()
      val a = readLine().split("\\s+").map( _.toInt )
      val map = scala.collection.mutable.HashMap[Int, Triplet]()
      (a.zipWithIndex).foreach({
        case (a,i) => map.get(a) match {
          case None => map(a) = Triplet(i,i,1)
          case Some(Triplet(l,r,k)) => map(a) = Triplet(l,i,k+1)
        }
      })
      val ans = map.reduceLeft( (thiz, that) => {
        if(thiz._2.count != that._2.count)
          if(thiz._2.count >= that._2.count) thiz else that
        else if ((thiz._2.right - thiz._2.left) <= (that._2.right - that._2.left)) thiz else that
      })

      val l = ans._2.left + 1
      val r = ans._2.right + 1
      println(l + " " + r)
  }
}

//package c558.b

object Solution extends App {
  case class C3(counter: Int, left: Int, right: Int)
  case object C3 { def empty(i: Int) = C3(1, i, i) }
  def solve(n: Int, array: Seq[Int]) = {
    import scala.collection.mutable
    val indexedArray = array.zip(1 to n)
    val beautyMap = mutable.Map.empty[Int, C3]
    indexedArray.foreach(xi ⇒ {
      val (x, i) = xi._1 → xi._2
      val elem = beautyMap.getOrElse(x, C3.empty(i))
      beautyMap.put(x, elem.copy(counter = elem.counter + 1, right = i))
    })
    val maxElem = beautyMap.maxBy(kv ⇒ kv._2.counter)
    val best = beautyMap.filter(_._2 == maxElem._2).maxBy(kv ⇒ kv._2.right - kv._2.left)._2
    s"${best.left} ${best.right}"
  }
  import scala.io.StdIn
  val n = StdIn.readInt()
  val array = StdIn.readLine().split(" ").map(_.toInt)
  println(solve(n, array))
}

//package c558.b

object Solution extends App {
  def solve(n: Int, array: Seq[Int]) = {
    import scala.collection.mutable
    val indexedArray = array.zip(1 to n)
    val beautyMap = mutable.Map.empty[Int, Int]
    indexedArray.foreach(xi ⇒ {
      val x = xi._1
      val elem = beautyMap.getOrElse(x, 0)
      beautyMap.put(x, elem + 1)
    })
    val maxElem = beautyMap.maxBy(kv ⇒ kv._2)
    val left = array.indexOf(maxElem._1) + 1
    val right = array.lastIndexOf(maxElem._1) + 1
    s"$left $right"
  }
  import scala.io.StdIn
  val n = StdIn.readInt()
  val array = StdIn.readLine().split(" ").map(_.toInt)
  println(solve(n, array))
}

//package c558.b

object Solution extends App {
  import scala.io.StdIn
  import scala.collection.mutable
  val n = StdIn.readInt()
  val array = StdIn.readLine().split(" ").map(_.toInt)
  val indexedArray = array.zip(0 until n)
  case class C3(counter: Int, left: Int, right: Int)
  case object C3 { def empty = C3(0, 0, 0) }
  val beautyMap = mutable.Map.empty[Int, C3]
  indexedArray.foreach(xi ⇒ {
    val (x, i) = xi._1 → xi._2
    val elem = beautyMap.getOrElse(x, C3.empty.copy(left = i))
    beautyMap.put(x, elem.copy(counter = elem.counter + 1, right = i))
  })
  val maxElem = beautyMap.maxBy(kv ⇒ kv._2.counter)
  println(s"${maxElem._2.left + 1} ${maxElem._2.right + 1}")
}

import scala.io.StdIn.readLine
import scala.collection.mutable.PriorityQueue
import scala.annotation.tailrec

object Main {
  case class LR(left : Int, right : Int, cnt : Int)
  object EnRich {
    implicit class AString(val self : String) extends AnyVal {
      def splitToIntArray = self.split(" ").map(_.toInt)
    }
  }
  import EnRich._

  def main(args : Array[String]) : Unit = {
    val n = readLine.toInt
    val a = readLine.splitToIntArray
    val h = scala.collection.mutable.HashMap[Int,LR]()
    (a.zipWithIndex).foreach({case (a,i) => h.get(a) match {
                                case None => h(a) = LR(i,i,1)
                                case Some(LR(l,r,k)) => h(a) = LR(l,i,k+1)
                              }})
    val m = h.toList.map({case (_,LR(_,_,k)) => k}).max
    val f = h.toList.filter({case (_,LR(_,_,k)) => k == m})
    val l = f.head._2.left+1
    val r = f.head._2.right+1
    println(s"$l $r")
  }
}

import scala.collection.mutable.HashMap

object B extends App {
 val n = readInt
 val str = readLine.split(" ").map(_.toInt).zipWithIndex
 val mp = new HashMap[Int, (Int, Int, Int)]()
 for((i, j) <- str) {
 val k = mp.getOrElse(i, (0, 0, 0))
 if(k._1 == 0)
  mp(i) = (1, j, j)
 else
  mp(i) = (k._1 + 1, k._2, j)
 }

 val res = mp.toList.sortWith((i, j) => i._2._1 > j._2._1 || i._2._1 == j._2._1 && (i._2._3 - i._2._1) < (j._2._3 - j._2._1))(0)
 print(res._2._2 + 1 + " " + (res._2._3 + 1))
}


Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai milliliters of water.It turned out that among Pasha's friends there are exactly n boys and exactly n girls and all of them are going to come to the tea party. To please everyone, Pasha decided to pour the water for the tea as follows:  Pasha can boil the teapot exactly once by pouring there at most w milliliters of water;  Pasha pours the same amount of water to each girl;  Pasha pours the same amount of water to each boy;  if each girl gets x milliliters of water, then each boy gets 2x milliliters of water. In the other words, each boy should get two times more water than each girl does.Pasha is very kind and polite, so he wants to maximize the total amount of the water that he pours to his friends. Your task is to help him and determine the optimum distribution of cups between Pasha's friends.

The first line of the input contains two integers, n and w (1 ≤ n ≤ 105, 1 ≤ w ≤ 109) — the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters. The second line of the input contains the sequence of integers ai (1 ≤ ai ≤ 109, 1 ≤ i ≤ 2n) — the capacities of Pasha's tea cups in milliliters.

Print a single real number — the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.

NotePasha also has candies that he is going to give to girls but that is another task...

import scala.io.StdIn._
import scala.math.min
import scala.language.postfixOps

object B {
  def main(args: Array[String]) {
    val n :: w :: _ = readLine split " " map (_.toDouble) toList
    val arr = readLine split " " map (_.toDouble) sorted
    var boy = arr(arr.length / 2)
    var girl = boy / 2
    if (girl > arr(0)) {
      girl = arr(0)
      boy = girl * 2
    }
    val sum = boy * n + girl * n
    println(min(sum, w))
  }
}

import scala.annotation.tailrec, scala.collection.mutable
import CodeForcesApp._
object _557B extends CodeForcesApp[Double]({scanner => import scanner._
  val (n, w) = (nextInt, nextInt)
  val cups = IndexedSeq.fill(2*n)(nextInt).sorted
  val (x, y) = (cups(n).toDouble, cups(0).toDouble)
  val g = y min (x/2)
  3*g*n min w
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val (modulus: Int, eps: Double) = (1000000007, 1e-9)
  def when[A](x: Boolean)(f: => A): Option[A] = if (x) Some(f) else None
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
}

import scala.annotation.tailrec, scala.collection.mutable
import CodeForcesApp._
object _557B extends CodeForcesApp[Double]({scanner => import scanner._
  val (n, w) = (nextInt, nextInt)
  val cups = IndexedSeq.fill(2*n)(nextInt).sorted
  val (x, y) = (cups(n).toDouble, cups(0).toDouble)
  val g = y min (x/2)
  val ans = 3*g*n
  ans min w
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val modulus: Int = 1000000007
  val eps: Double = 1e-9
  def when[A](x: Boolean)(f: => A): Option[A] = if (x) Some(f) else None
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer

object B_311 {

  def main(args: Array[String]): Unit = {

    //COMMENT ME !
//    is = new ByteArrayInputStream(Test.sa1.trim.getBytes("ISO-8859-1"))
//    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val w = line1.long
    var cups = new Array[Long](2*n)
    val capasLine = readLine()
    for (i<-0 until 2*n) {
      cups(i) = capasLine.long
    }
    cups = cups.sortWith(_<_)
    val girlsCap = cups(0)
    val boysCap = cups(n)
    val min = Math.min(girlsCap, boysCap/2d)
    val possibleVol = min*n*3

    val res = Math.min(possibleVol, w)
    println(res)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()

  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
3 18
4 4 4 2 2 2
"""

}

}

import scala.annotation.tailrec, scala.collection.mutable
import CodeForcesApp._
object _557B extends CodeForcesApp[Double]({scanner => import scanner._
  val (n, w) = (nextInt, nextInt)
  val cups = List.fill(2*n)(nextInt)
  val (girls, boys) = cups.sorted.splitAt(n)
  val (x, y) = (boys.last.toDouble, girls.last.toDouble)
  debug(x, y, y >= x/2)
  val ans = if (y >= x/2) {
    x*n + (x/2)*n
  } else {
    y*n + 2*y*n
  }
  ans min w
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val modulus: Int = 1000000007
  val eps: Double = 1e-9
  def when[A](x: Boolean)(f: => A): Option[A] = if (x) Some(f) else None
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
}


Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn. Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.

The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ n) — the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.

Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).

NoteIn the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.In the third example for any values l and r there is a situation when Stepan said the truth.

object Main extends App {
    var Array(n,l,r) = readLine.split(" ").map(_.toInt)
    var a:Array[Int] = readLine.split(" ").map(_.toInt)
    var b:Array[Int] = readLine.split(" ").map(_.toInt)

    var lo:Int = 0
    var ro:Int = n - 1
   while(lo < n && (a(lo) equals b(lo))){
       lo = lo + 1
   }
   while(ro >= 0 && (a(ro) equals b(ro))){
       ro = ro - 1
   }
   l = l - 1
   r = r - 1
   if(lo >= l & ro <= r){
        println("TRUTH")
   }
   else{
       println("LIE")
   }

}

object tmp {
   def main(args: Array[String]) {
        val Array(n,l,r) = readLine.split(" ").map(_.toInt)
        val s1 = readLine
        val a: Array[Int] = s1.split(" ").map(_.toInt)
        val s2 = readLine
        val b: Array[Int] = s2.split(" ").map(_.toInt)
        var i = 0;
        var can = 1;
        for (i <- 0 to n-1){
            if (i < l-1 || i > r-1) {
                if (a(i) != b(i)) {
                    can = 0;
                }
            }
        }
        var l1 = Array.fill[Int](100001)(0);
        var l2 = Array.fill[Int](100001)(0);
        for (i <- l-1 to r-1){
            l1(a(i)) = l1(a(i)) + 1;
            l2(b(i)) = l2(b(i)) + 1;
        }
        for (i <- 0 to 100000){
            if (l1(i) != l2(i))
                can = 0;
        }
        if (can == 1) {
            println("TRUTH");
        } else {
            println("LIE");
        }
   }
}

object Main extends App {
	var i = 0
	var k1 = 0
	var k2 = 0
	var flag = 1
    val Token = readLine().split(" ").map(_.toLong)
    var n = Token(0).toInt
    var l = Token(1).toInt - 1
    var r = Token(2).toInt - 1
    val arr1 = readLine().split(" ").map(_.toLong)
    val arr2 = readLine().split(" ").map(_.toLong)

    while (i < n) {
        k1 = arr1(i).toInt
        k2 = arr2(i).toInt
        if ((i < l || i > r) && k1 != k2) {flag = 0}
        i += 1
    }
    if (flag == 1) {print("TRUTH")}
    else {print("LIE")}
}

import scala.io.StdIn._

import scala.collection.mutable

import scala.collection.mutable._

object CF795D {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val l = sc.nextInt
    val r = sc.nextInt
    val a = new Array[Int](n)
    val b = new Array[Int](n)
    for (i <- a.indices) a(i) = sc.nextInt
    for (j <- b.indices) b(j) = sc.nextInt
    if (!a.slice(0, l-1).sameElements(b.slice(0, l-1)) ||
        !a.slice(r, n).sameElements(b.slice(r, n))) {
      println("LIE")
    } else if (!a.slice(l-1, r).sorted.sameElements(b.slice(l-1, r).sorted)) {
      println("LIE")
    } else {
      println("TRUTH")
    }
  }
}

object Main extends App {
	val Array(n, l,r) = readLine().split(" ").map(_.toInt)
	var array1 = Array.fill[Int](n+5)(0)
	var array2 = Array.fill[Int](n+5)(0)

	val s = readLine
	val a: Array[Int] = s.split(" ").map(_.toInt)
    for (i <- 0 until a.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		array1(a(i)) = array1(a(i))+1
    	}
	}

	val s1 = readLine
	val a1: Array[Int] = s1.split(" ").map(_.toInt)
    for (i <- 0 until a1.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		array2(a1(i)) = array2(a1(i))+1
    	}
	}
	var flag = true
	for (i <- 0 until array1.length) {
		if(array1(i)!=array2(i))
			flag = false
    }
    for (i <- 0 until a1.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		// array2(a1(i)) = array2(a1(i))+1
    	}
    	else {
    		if(a(i)!=a1(i))
    			flag = false
    	}
	}
    if(flag) print("TRUTH")
    else print("LIE")
}

object D {
    def shuffle[T](array: Array[T]): Array[T] = {
        val rnd = new java.util.Random
        for (n <- Iterator.range(array.length - 1, 0, -1)) {
            val k = rnd.nextInt(n + 1)
            val t = array(k); array(k) = array(n); array(n) = t
        }
        return array
    }

	def main(args: Array[String]) = {
		val scanner = new java.util.Scanner(System.in)
		val n, l, r = scanner.nextInt()
		var a, b = new Array[Int](n)
		for (i <- 0 to n-1) {
			a(i) = scanner.nextInt()
		}
		for (i <- 0 to n-1) {
			b(i) = scanner.nextInt()
		}
		var i = 0
		var lie = false
		for (i <- 1 to n) {
			if (a(i-1) != b(i-1) && (i < l || r < i)) {
				lie = true
			}
		}
		shuffle(a)
		scala.util.Sorting.quickSort(a)
		shuffle(b)
		scala.util.Sorting.quickSort(b)
		for (i <- 1 to n) {
			if (a(i-1) != b(i-1)) {
				lie = true
			}
		}
		if (lie) {
			println("LIE")
		} else {
			println("TRUTH")
		}
	}
}

object CF {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val l = sc.nextInt()-2
    val r = sc.nextInt()
    val a = Array.tabulate(n)(_ => sc.nextInt())
    val b = Array.tabulate(n)(_ => sc.nextInt())
    var fl = 1
    val i = 0
    for( i <- 0 to l){
        if(a(i) != b(i)) fl = 0
    }
    for( i <- r to n-1){
        if(a(i) != b(i)) fl = 0
    }
    if(fl > 0){
        println("TRUTH")
    }else{
        println("LIE")
    }
  }
}

object Main extends App {
	val Array(n, l,r) = readLine().split(" ").map(_.toInt)
	var array1 = Array(0)
	var array2 = Array(0)
	val s = readLine
	val a: Array[Int] = s.split(" ").map(_.toInt)
    for (i <- 0 until a.length) {
    	if(l<=i && i<=r)
	    	array1 :+= a(i)
	}

	val s1 = readLine
	val a1: Array[Int] = s1.split(" ").map(_.toInt)
    for (i <- 0 until a1.length) {
    	if(l<=i && i<=r)
	    	array2 :+= a1(i)
	}
	scala.util.Sorting.quickSort(array1)
	scala.util.Sorting.quickSort(array2)
	var flag = true
	for (i <- 0 until array1.length) {
		// println(array1(i))
		// println(array2(i))
		if(array1(i)!=array2(i))
			flag = false
    }
    // print(flag)
    if(flag) print("TRUTH")
    else print("LIE")
}

object Main extends App {
	val Array(n, l,r) = readLine().split(" ").map(_.toInt)
	var array1 = Array.fill[Int](n+5)(0)
	var array2 = Array.fill[Int](n+5)(0)
	val s = readLine
	val a: Array[Int] = s.split(" ").map(_.toInt)
    for (i <- 0 until a.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		array1(a(i)) = array1(a(i))+1
    	}
	}

	val s1 = readLine
	val a1: Array[Int] = s1.split(" ").map(_.toInt)
    for (i <- 0 until a1.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		array2(a1(i)) = array2(a1(i))+1
    	}
	}
	var flag = true
	for (i <- 0 until array1.length) {
		if(array1(i)!=array2(i))
			flag = false
    }
    if(flag) print("TRUTH")
    else print("LIE")
}