jiahuimbzuai/CoQuIR huggingface dataset:
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define type 26

int constant(int day)//1~26 順番
{
  return day%type+1;
}
int get_random()//1~26 ランダム
{
  return rand()%type+1;
}
int max(int s[][type+1],int day)//その日の最大の満足度選ぶ
{
  int m,max_score=0,i;
  for(i=1;i<=type;i++)
  {
    if(s[day][i]>max_score){
      max_score=s[day][i];
      m=i;
    }
  }
  return m;
}
void cal(int select,int c[type+1],int last[type+1],int s[][type+1],int day,int sum[])
{
  int i;
  sum[day]=sum[day-1]+s[day][select];
  for(i=1;i<=type;i++){
    sum[day]-=c[i]*(day-last[i]);
  }
}
void change(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
//ランダムに変更
{
  int d,t,old,total=0,i,j;
  d=rand()%D+1;
  t=rand()%type+1;
  old=schedul[d];
  schedul[d]=t;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
  //  printf("change\n");
    sum[D]=total;
  }
  else{
    schedul[d]=old;
  }
}
void cross(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
//ランダムな２つ交換
{
  int a,b,old_a,old_b,flag=0,i,j,total=0;
  flag=rand()%2;
  a=rand()%D+1;
  if(flag==0){
    b=a+rand()%16+1;
    if(b>D) b=a-(rand()%16+1);
  }
  else{
    b=a-(rand()%16+1);
    if(b<1)   b=a+rand()%16+1;
  }
  old_a=schedul[a];
  old_b=schedul[b];
  schedul[a]=old_b;
  schedul[b]=old_a;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
    sum[D]=total;
  }
  else
  {
    schedul[a]=old_a;
    schedul[b]=old_b;
  }
}
int main(void)
{
  int D,c[type+1],i,j;
  clock_t start,stop;
  start=clock();
  srand((unsigned int)time(NULL));
  scanf("%d",&D);//D=365
  int s[D+1][type+1],last[type+1],sum[D+1],schedul[D+1];
  for(i=0;i<=D;i++) sum[i]=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=type;i++) scanf("%d",&c[i]);
  for(i=1;i<D+1;i++){
    for(j=1;j<=type;j++) scanf("%d",&s[i][j]);
  }
  for(i=1;i<D+1;i++){
    int select;
    select=max(s,i);
    last[select]=i;
    schedul[i]=select;
    cal(select,c,last,s,i,sum);
    //printf("%d\n",sum[i]);
  }
  int count=0;
  stop=start;
  while((double)(stop - start) / CLOCKS_PER_SEC<1.988){
    int flag=rand()%2;
    if(flag==0) cross(c,last,s,sum,schedul,D);
    else change(c,last,s,sum,schedul,D);
    count++;
    stop=clock();
  }
/*
  printf("count:%d\n",count);
  printf("time:%f\n",(double)(stop - start) / CLOCKS_PER_SEC);
  printf("%d\n",sum[D]);
  printf("確認\n");
  int total=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  printf("%d\n",total);
*/
  for(i=1;i<=D;i++) printf("%d\n",schedul[i]);
  return 0;
}
//  [javascript]
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var ans = [];
  for(var i = 0; i < 365; i++){
    ans[i] = i%26+1;
  }
  return ans.join("\n");
}
//  [javascript]
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	input = input.map(e => toIntArr(e.split(' ')));
	var d = input[0][0];
	var cs = input[1][0];
	var ss = input.slice(1);
	
	var ans = '';
	for(let i = 0; i < 365; i++){
		ans += (i%26)+1+'\n';
	}

	console.log(ans);
}
//  [javascript]
console.log((args=>{
  const [[D],c,...s] = args.trim().split('\n').map(r=>r.split(' ').map(v=>v|0));
  const his = [];
  const last = Array(26).fill(0);
  for ( let i = 0; i < D; i++ ) {
    let max = 0, task = 0;
    for ( let j = 0; j < 26; j++ ) {
      let score = s[i][j] + (i-last[j]) * c[j];
      if ( score > max ) {
        task = j;
        max = score;
      }
    }
    his.push(task+1);
    last[task] = i;
  }
  return his.join`\n`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
//  [javascript]
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	input = input.map(e => toIntArr(e.split(' ')));
	var d = input[0][0];
	var cs = input[1];
	var ss = input.slice(2);
	//var ts = input.slice(d+2).map(e=>e[0]);
	
	var score = 0;
	var ans = [];
	let type;
	var lastday = [];
	lastday.length = 26;
	lastday.fill(-1);

	//let scoreDay = [];

	//day(0~25)にtype(1~26)を選んだ場合の満足度の変化(lastdayのdayは0~)
	function getScore(day,type,lastday){
		let ans = 0;
		ans += ss[day][type-1];
		for(let t = 0; t < 26; t++){
			if(t!==type-1) ans -= cs[t] * (day - lastday[t]);
		}
		return ans;
	}

	let d3 = Math.floor(d/3);
	let rest = d - d3*3;

	var tempScore; // [[t0,t1,t2,score],...]
	var tempLastday;
	let subScore;

	for(let i = 0; i < d3; i++){
		tempScore = [];

		for(let t0 = 0; t0 < 26; t0++){
			tempLastday = lastday.concat();
			subScore = 0;

			tempLastday[t0] = i*3;
			subScore += getScore(i*3,t0+1,tempLastday);
			for(let t1 = 0; t1 < 26; t1++){
				tempLastday[t1] = i*3 +1;
				subScore += getScore(i*3+1,t1+1,tempLastday);
				for(let t2 = 0; t2 < 26; t2++){
					tempLastday[t2] = i*3 +2;
					subScore += getScore(i*3+2,t2+1,tempLastday);
					tempScore.push([t0,t1,t2,subScore]);
					}
				}
			}

		//console.log(tempScore)
		let want = tempScore.map(e=>e[3]).indexOf(Math.max(...tempScore.map(e=>e[3])));
		let want2 = tempScore[want];
		//console.log(want,want2)
		ans.push(want2[0]+1,want2[1]+1,want2[2]+1);
		lastday[want2[0]] = i*3;
		lastday[want2[1]] = i*3+1;
		lastday[want2[2]] = i*3+2;

	}

	for(let i = d3*3; i < d; i++){
		tempScore = [];

		for(let j = 0; j < 26; j++){
			tempScore[j] = getScore(i,j+1,lastday);
		}

		let want = tempScore.indexOf(Math.max(...tempScore));
		ans.push(want+1);
		lastday[want] = i;

	}

	console.log(ans.join('\n'));
}

//a.indexOf(Math.max(...a))
//  [javascript]
'use strict';

function Main(input) {
    let [D, C, ...S] = input.trim().split('\n');
    D = Number(D);
    C = C.split(' ').map((v) => Number(v));
    S = S.map((v) => v.split(' ').map((v) => Number(v)));

    let last = Array(26).fill(0); // コンテストの最終開催日
    let drop = Array(26).fill(0); // 不満度の累計

    // 各日において、満足度 - 不満度 が最大になる日程
    // let total = 0;
    for (let i = 0; i < D; i++) {
        drop = drop.map((_v, index) => C[index] * (i + 1 - last[index]));
        const s = S[i];
        let tmp = Array(26).fill(0);
        for (let j = 0; j < 26; j++) {
            const lebel =
                s[j] - (drop.reduce((acc, cur) => acc + cur) - drop[j]);
            tmp[j] = lebel;
        }
        const max = tmp.reduce((a, b) => Math.max(a, b));
        const index = tmp.indexOf(max);
        // total += max;
        // console.log(total);
        console.log(index + 1);
        last[index] = i + 1;
    }

    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
function main() {
  const D = Number(input[0]);
  const c = input[1].split(' ').map(Number);
  
  const scores_of_day = input.slice(2,D+2);
  const scores = scores_of_day.map((text) => {
    return text.split(' ').map(Number);
  });
  let s = 0;
  let c_stock = Array.from(c);
  let real_s, add, t;
  
  for (i=0;i<D;i++) {
    real_s = [];
    for (j=0;j<26;j++) {
      real_s.push(scores[i][j]-c_stock[j]);
    }
    t = real_s.indexOf(Math.max.apply(null, real_s));
    s += scores[i][t];
    add = Array.from(c);
    add[t] = 0;
    
    for (j=0;j<26;j++) {
      c_stock[j] += add[j];
    }
    s -= c_stock.reduce(function(a, x){return a + x;});
    console.log(t+1);  
  }
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});
//  [go]
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	d := io.NextInt()
	for i := 0; i < d; i++ {
		io.Println(1)
	}
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	D int
	c [26]int
	s [365][26]int
)

func main() {
	readVariables()
	for row := 0; row < D; row++ {
		fmt.Println(maxGreed(row))
	}
}

func maxGreed(row int) int {
	max := 0
	result := 0
	for i, v := range s[row] {
		if v > max {
			result = i
			max = v
		}
	}
	return result + 1
}

func readVariables() {
	D = nextInt()
	for i := 0; i < 26; i++ {
		c[i] = nextInt()
	}
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			s[i][j] = nextInt()
		}
	}
}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func calcScore(day int, score, c, last []int) (int, []int) {
	loss := make([]int, 26)
	for i := 0; i < 26; i++ {
		loss[i] = c[i] * (day - last[i])
	}

	ret := 0
	new := make([]int, 26)
	for j := 0; j < 26; j++ {
		new[j] = score[j] - loss[j]
		ret += new[j]
	}

	return ret, new
}

func calcAllScore(D int, days []int, c []int, s [][]int) int {
	last := make([]int, 26)
	score := make([]int, 26)

	ans := 0
	for i := 0; i < D; i++ {
		t := days[i]
		score[t] += s[i][t]
		last[t] = i + 1
		ret, nw := calcScore(i+1, score, c, last)
		score = nw
		ans = ret
		// out(score)
	}
	return ans
}

var tab [366][26]int
var sum [366][26]int
var exe [366]int
var D int
var c []int
var s [][]int

func calc(typ int) {
	score := 0
	last := 0
	for i := 1; i <= D; i++ {
		if tab[i][typ] == 1 {
			score += s[i][typ]
			last = i
		}
		score += c[typ] * (last - i)
		sum[i][typ] = score
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	D = getInt()
	c = getInts(26)
	s = make([][]int, D+1)
	for i := 0; i < D; i++ {
		s[i+1] = getInts(26)
	}

	for i := 1; i <= D; i++ {
		maxS := s[i][0]
		idx := 0
		for j := 0; j < 26; j++ {
			if maxS < s[i][j] {
				maxS = s[i][j]
				idx = j
			}
			exe[i] = idx + 1
		}

	}

	// 	t := 0
	// 	tab[i][t] = 1
	// 	exe[i] = t + 1
	// }

	// for i := 0; i < 26; i++ {
	// 	calc(i)
	// }
	// ans := 0
	// for i := 0; i < 26; i++ {
	// 	ans += sum[D][i]
	// }
	// out(ans)

	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()
	for i := 1; i <= D; i++ {
		fmt.Fprintln(wr, exe[i])
	}

	// M := getInt()
	// for i := 0; i < M; i++ {
	// 	d, q := getInt(), getInt()-1
	// 	tab[d][q] = 1
	// 	if exe[d] != 0 {
	// 		tab[d][exe[d]-1] = 0
	// 	}
	// 	for i := 0; i < 26; i++ {
	// 		calc(i)
	// 	}
	// 	exe[d] = q + 1
	// 	tot := 0
	// 	for i := 0; i < 26; i++ {
	// 		tot += sum[D][i]
	// 	}
	// 	fmt.Fprintln(wr, tot)
	// }
}
//  [ruby]
d = gets.to_i
c = gets.split.map &:to_i
s = d.times.map { gets.split.map &:to_i }
s.each do |row|
  p 1 + row.index(row.max)
end
//  [ruby]
d = gets.to_i
c = gets.split.map &:to_i
s = d.times.map { gets.split.map &:to_i }

last = [0] * 26
s.each_with_index do |row, day|
  down_sum = last.each_with_index.sum { |day_last, i| c[i] * (day - day_last) }
  i = (0...26).max { |i| s[day][i] - down_sum + c[i] }
  p 1 + i
end
//  [ruby]
puts 365.times.map{ rand(1 .. 26) }
//  [ruby]
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
L,M,N = [-1]*27,2,10
1 < (I=(0..25).select{C[_1]==0}).size and S.each {|s;z|
  I.each {|i| if i!=(z||=i); s[z]<s[i] ? z = i+s[z]=0 : s[i]=0 end }
}
def calc(d,n)
  s,x = S[d],0
  n = D-d  if n > D-d
  t = (0..25).map { C[_1]*(d-L[_1])*n+s[_1] }
  i = (0..25).max_by(n){t[_1]}
  i = n==1 ? i[0] : [i[0],i[n>>1]].max_by {|i|
    l,L[i] = L[i],d
    c = t[i] + (calc(d+1,n-1) >> 5)
    L[i] = l
    x < c ? x=c : c
  }
  ((x>0 ? x : t[i]) << 5) + i
end
D.times { p 1 + i=calc(_1,N)&31; L[i]=_1 }
//  [ruby]
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
1 < (I=(0..25).select{C[_1]==0}).size and S.each {|s;z|
  I.each {|i| if i!=(z||=i); s[z]<s[i] ? (s[z]=0; z=i) : (s[i]=0) end }
}
L,M,N = [-1]*27,9,3
def calc(d,n)
  s,x = S[d],0
  t = (0..25).map {s[_1] > 0 ? C[_1]*(d-L[_1])+s[_1] : 0}
  i = (0..25).max_by(M){t[_1]}.max_by {|i|
    next t[i]  if n == 0 || d+1 >= D || t[i]==0
    l,L[i] = L[i],d
    c = calc(d+1,n-1) >> 5
    L[i] = l
    x < c ? x=c : c
  }
  ((t[i]+x) << 5) + i
end
D.times { p 1 + i=calc(_1,N)&31; L[i]=_1 }
//  [ruby]
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
C.count(0)>1 and S.each {|s|
  26.times {|i| if s[i]==0 && i!=(z||=i); s[z]<s[i] ? (s[z]=0; z=i) : (s[i]=0) end }
}
L,M,N = [-1]*27,2,9
def calc(d,n)
  s = S[d]
  t = (0..25).map {s[_1] > 0 ? C[_1]*(d-L[_1])+s[_1] : 0}
  i = (0..25).max_by(M){t[_1]}.max_by {|i|
    next t[i]  if n == 0 || d+1 >= D || t[i] == 0
    l,L[i] = L[i],d
    calc(d+1,n-1)[1].tap {L[i]=l}
  }
  [i, t[i]]
end
D.times { p 1 + i=calc(_1,N)[0]; L[i]=_1 }
//  [rust]
use proconio::*;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };
    let mut t = vec![100; d];
    let mut lasts = [-1; 26];
    // let mut score = 0;

    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let cur_score = calc_score(i, j, &c, &s, &mut lasts);
            if cur_score > max_score {
                max_score = cur_score;
                t[i] = j;
            }
        }
        lasts[t[i]] = i as i64;
        // score += max_score;
    }
    // println!("{}", score);

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = Number(input[0][0]);

  const T = [...Array(D)].map((_, i) => (i % 26) + 1);

  return T.join("\n");
};

console.log(main(read()));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = Number(input[0][0]);
  const C = input[1].map(Number);

  const T: number[] = [];

  let CS: number[] = Array(26).fill(0);

  for (let i = 2; i < D + 2; i++) {
    const S = input[i].map(Number);

    const maxS = Math.max(...S);
    const maxCS = Math.max(...CS);

    const indexOfMaxS = S.indexOf(maxS);
    const indexOfMaxCS = CS.indexOf(maxCS);

    CS = CS.map((cs, t) => cs + C[t]);

    if (maxS > maxCS) {
      T.push(indexOfMaxS + 1);
    } else {
      T.push(indexOfMaxCS + 1);

      CS[indexOfMaxCS] = 0;
    }
  }

  return T.join("\n");
};

console.log(main(read()));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = Number(input[0][0]);

  const T: number[] = [];

  for (let i = 2; i < D + 2; i++) {
    const S = input[i].map(Number);

    const max = Math.max(...S);

    T.push(S.indexOf(max) + 1);
  }

  return T.join("\n");
};

console.log(main(read()));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const D = Number(input[0][0]);
  const C = input[1].map(Number);

  let score = 0;

  const T: number[] = [];
  const L = Array(26).fill(0);

  for (let d = 0; d < D; d++) {
    const S = input[d + 2].map(Number);

    let max = Number.MIN_SAFE_INTEGER;
    let index = 0;

    S.forEach((s, i) => {
      const temp =
        score +
        s -
        C.reduce((sum, c, j) => (j === i ? sum : sum + c * (d + 1 - L[j])), 0);

      if (temp > max) {
        max = temp;
        index = i;
      }
    });

    T.push(index + 1);
    L[d] = index;
  }

  return T.join("\n");
};

console.log(main(read()));
//  [python]
import numpy as np


n,m,X,Y = list(map(int,input().split()))
x = list(map(int,input().split()))
y = list(map(int,input().split()))

x.append(X)
y.append(Y)

if np.max(x) < np.min(y):
    print('No War')
else:
    print('War')
//  [python]
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


n,m,x,y = map(int, input().split())

# 空白区切りの数列をリストに代入
xx = [int(i) for i in input().split()]
yy = [int(i) for i in input().split()]

for i in range(n):
    x = max(x,xx[i])
for i in range(m):
    y = min(y,yy[i])
if x < y:
    print('No War')
else:
    print('War')
//  [python]
n,m,X,Y = map(int, raw_input().split(' '))
xis = map(int,raw_input().split(' '))
xis.sort()
yis = map(int,raw_input().split(' '))
yis.sort()

aa = [xis[n - 1], yis[-m]]
aa[0] = max(aa[0], X)
aa[1] = min(aa[1], Y)
print 'No War' if aa[0]<aa[1] else 'War'
//  [java]
import java.io.*;
import java.math.*;
import java.util.*;

class Main {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        sc.nextLine();
        int maxX = Arrays.stream(sc.nextLine().split(" +")).mapToInt(Integer::parseInt).max().getAsInt();
        int minY = Arrays.stream(sc.nextLine().split(" +")).mapToInt(Integer::parseInt).min().getAsInt();
        maxX = Math.max(maxX, x);
        minY = Math.min(minY, y);

        System.out.println(maxX < minY ? "No War" : "War");

        sc.close();
    }
}
//  [java]
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;
import java.util.OptionalInt;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B1DimensionalWorldsTale solver = new B1DimensionalWorldsTale();
        solver.solve(1, in, out);
        out.close();
    }

    static class B1DimensionalWorldsTale {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt(), x = in.nextInt(), y = in.nextInt();
            int xm = IntStream.range(0, n).map(z -> in.nextInt()).max().orElse(0);
            int ym = IntStream.range(0, m).map(z -> in.nextInt()).min().orElse(0);
            if (x < ym && xm < y && xm < ym) {
                out.println("No War");
            } else {
                out.println("War");
            }
        }

    }
}
//  [java]
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int[] xArray = new int[n];
		int[] yArray = new int[m];
		for(int i = 0; i < n; i++)
			xArray[i] = sc.nextInt();
		for(int i = 0; i < m; i++)
			yArray[i] = sc.nextInt();
		int low = Arrays.stream(xArray).max().getAsInt();
		int high = Arrays.stream(yArray).min().getAsInt();
		boolean b = false;
		for(int i = low+1; i <= high && !b; i++)
			b |= x < i && i <= y;
		System.out.println(b ?"No War" :"War" );
	}
}
//  [cpp]
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m;
int x,y;
int a[102],b[102];
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d%d",&x,&y);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=m;i++)
		scanf("%d",&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	bool f=0;
	for(int i=x+1;i<=y;i++)
		if(a[n]<i&&b[1]>=i)
		{
			f=1;
			break;
		}
	if(f)printf("No War");
	else printf("War");
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  vi xs(n);
  rep(i,n)cin>>xs[i];
  vi ys(m);
  rep(i,m)cin>>ys[i];
  vsort(xs);
  vsort(ys);
  string ans="War";
  if(xs[n-1]<ys[0]){
    if(x<ys[0]&&xs[n-1]<y&&x<y)ans="No War";
  }
  cout(ans);

  return 0;
}
//  [cpp]
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(1000000);
    vector<int>b(1000000);
    cin>>a[0]>>b[0];
    for(int i=0;i<n;i++){
        cin>>a[i+1];
    }
     for(int i=0;i<=n;i++){
     	a[i]+=100;
    }
    for(int i=0;i<m;i++){
        cin>>b[i+1];
    }
    for(int i=0;i<=m;i++){
    	b[i]+=100;
    }
    sort(a.begin(),a.end(),greater<>());
    sort(b.begin(),b.end(),greater<>());
    if(a[0]>=b[m]){
        cout<<"War"<<endl;
    }
    else{
        cout<<"No War"<<endl;
    }
    return 0;
}
//  [c]
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n, m, X, Y, x[max], y[max];
    int xmax=INT_MIN, ymin=INT_MAX;
    
    scanf("%d%d%d%d", &n, &m, &X, &Y);
    rep(i, n){
        scanf("%d", &x[i]);
        if (xmax<x[i]) {
            xmax=x[i];
        }
    }
    rep(i, m){
        scanf("%d", &y[i]);
        if (ymin>y[i]) {
            ymin=y[i];
        }
    }
    
    for (int i=X+1; i<=Y; i++) {
        if (xmax<i&&ymin>=i) {
            printf("No War\n");
            return 0;
        }
    }
    
    printf("War\n");
    
    return 0;
}
//  [c]
#include<stdio.h>
int main(){
  int N, M, X, Y;
  scanf("%d %d %d %d", &N, &M, &X, &Y);
  
  int xn[101];
  int xm[101];
  for(int i = 0; i < N; i++){
    scanf("%d",&xn[i]);
    if(X < xn[i]){
      X = xn[i];
    }
  }
  
  for(int i = 0; i < M; i++){
    scanf("%d",&xm[i]);
    if(Y > xm[i]){
      Y = xm[i];
    }
  }
  if(X >= Y){
    printf("War");
  }else{
    printf("No War");
  }
}
//  [c]
#include<stdio.h>
int main(){
  int n,m,x,y;
  scanf("%d %d %d %d",&n,&m,&x,&y);
  int xn[101];
  int xm[101];
  for(int i=0;i<n;i++){
    scanf("%d",&xn[i]);
    if(x < xn[i]){
      x = xn[i];
    }
  }
  for(int i=0;i<m;i++){
    scanf("%d",&xm[i]);
    if(y > xm[i]){
      y = xm[i];
    }
  }
  if(x >= y){
    printf("War");
  }else{
    printf("No War");
  }
}
//  [javascript]
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var X = o.a();
  var Y = o.a();
  var x = o.l();
  var y = o.l();
  x = Math.max(...x);
  y = Math.min(...y);
  if(y > Y)y = Y;
  return x < y  && X < y ? "No War":"War";
}
//  [javascript]
function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var m = parseInt(input[0].split(" ")[1]);
  var X = parseInt(input[0].split(" ")[2]);
  var Y = parseInt(input[0].split(" ")[3]);
  x = new Array(n).fill(0);
  y = new Array(m).fill(0);
  tmp1=input[1].split(" ");
  for(i=0;i<n;i++){
    x[i]=parseInt(tmp1[i]);
  }
  tmp2=input[2].split(" ");
  for(i=0;i<m;i++){
    y[i]=parseInt(tmp2[i]);
  }
  var ans = "War";
  maxx=Math.max.apply(null,x);
  miny=Math.min.apply(null,y);
  if(X<Y&&X<miny&&maxx<Y&&maxx<miny){
    ans = "No War";
  }


  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<v)v=rest[i];return v}
function max(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>v)v=rest[i];return v}
function gcd(){var rest=arguments,v=rest[0],temp=(a,b)=>b?temp(b,a%b):a;for(var i=1;i<rest.length;i++)v=temp(v,rest[i]);return v}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var nmxy = toIntArr(input[0].split(' '));
	var xs = toIntArr(input[1].split(' ')).sort((a,b)=>a-b);
	var ys = toIntArr(input[2].split(' ')).sort((a,b)=>a-b);
	var x = max(nmxy[2],xs[nmxy[0]-1]);
	var y = min(nmxy[3],ys[0]);
	var ans = y-x>0? 'No War': 'War';
	console.log(ans);
	return 0;
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := iScan()
	p := iScan()
	q := iScan()
	x := iSScan(n)
	y := iSScan(m)
	if p < q {
		if max(x) < q && min(y) > p && max(x) < min(y) {
			fmt.Println("No War")
		} else {
			fmt.Println("War")
		}
	} else {
		fmt.Println("War")
	}
}
//  [go]
package main
import (
	"fmt"
	//"math"
	//"math/rand"
)
func main() {
	var N,M,X,Y int
	fmt.Scan(&N,&M,&X,&Y)
	var x [100]int
	var y [100]int
	P:=-10000
	Q:=10000
	for i:=0;i<N;i++{
		fmt.Scan(&x[i])
		if P<x[i]{
			P = x[i]
		}
	}
	for i:=0;i<M;i++{
		fmt.Scan(&y[i])
		if Q>y[i]{
			Q = y[i]
		}
	}
	if P<X {
		P=X
	}
	if Q>Y {
		Q=Y
	}
	if Q-P>=1{
		fmt.Println("No War")
	}else{
		fmt.Println("War")
	}
}
//  [ruby]
n, m, x, y = gets.chomp.split.map(&:to_i)
xarr = gets.chomp.split.map(&:to_i)
yarr = gets.chomp.split.map(&:to_i)
puts xarr.max < yarr.min && (x < xarr.max && yarr.min <= y) ? "No War" : "War"
//  [ruby]
n,m,X,Y = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map(&:to_i)
y = gets.chomp.split(" ").map(&:to_i)
war = false
if X < Y
  n.times do |i|
    m.times do |j|
      if x[i] >= y[j]
        war = true
      end
    end
  end
  if x.max >= Y || y.min <= X
    war = true
  end
else
  war = true
end
if war
  puts "War"
else
  puts "No War"
end
//  [ruby]
n,m,x,y = gets.chomp.split.map(&:to_i)
xis = gets.chomp.split.map(&:to_i)
yis = gets.chomp.split.map(&:to_i)
if xis.max+1 > yis.min
  puts "War"
else
  if x<yis.min && y>=xis.max+1
    puts "No War"
  else
    puts "War"
  end
end
//  [rust]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize,m:usize,x:isize,y:isize,mut xn:[isize;n],mut ym:[isize;m]);

    xn.sort();
    ym.sort();

    let is_oc = if xn[xn.len() - 1] >= ym[0] {
        true
    } else {
        let count = (xn[xn.len() - 1] + 1..ym[0] + 1)
            .filter(|&xxx| x < xxx && xxx <= y)
            .count();
        count == 0
    };

    println!("{}", if is_oc { "War" } else { "No War" });
}
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        x: i64,
        y: i64,
        xs: [i64;n],
        ys: [i64;m],
    }

    if x>=y {
        println!("War");
        return;
    }

    let mut z_can: Vec<i64> = Vec::new();
    for i in x+1..y+1 {
        z_can.push(i);
    }

    let mut ok = true;
    for i in 0..z_can.len() {
        ok = true;
        for j in 0..n {
            if xs[j]>=z_can[i] {
                ok = false;
            }
        }
        for j in 0..m {
            if ys[j]<z_can[i] {
                ok = false;
            }
        }
        if ok==true {
            break;
        }
    }

    if ok==true {
        println!("No War");
    } else {
        println!("War");
    }

}
//  [rust]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn main() {
    input! {
    n: usize,
    m: usize,
    x: i64,
    y: i64,
    mut xs: [i64; n],
    mut ys: [i64; m]
    }
    xs.sort();
    ys.sort();
    for z in x + 1..=y {
        if xs[n - 1] < z && z <= ys[0] {
            println!("No War");
            return
        }
    }
    println!("War");
}
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [N, M, X, Y] = input[0].map(Number);
  const x = input[1].map(Number);
  const y = input[2].map(Number);

  const maxX = Math.max(...x);
  const minY = Math.min(...y);

  if (maxX >= Y || minY <= X || maxX >= minY) {
    return "War";
  } else {
    return "No War";
  }
};

console.log(main(read()));
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [, , X, Y] = input[0].map(Number);
  const x = input[1].map(Number);
  const y = input[2].map(Number);

  const maxX = Math.max(...x);
  const minY = Math.min(...y);

  if (maxX >= Y || minY <= X || maxX >= minY) {
    return "War";
  } else {
    return "No War";
  }
};

console.log(main(read()));
//  [typescript]
var lines=[];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', function (line) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines);
});

function main(lines) {
  const [n, m, x, y, xs, ys] = parseLines(lines);
  console.log(formula(x, y, xs, ys));
}

function formula(x, y, xs, ys) {
  const xMax = Math.max(...xs, x);
  const yMin = Math.min(...ys, y);
  return xMax < yMin ? 'No War' : 'War';
}

function parseLines(lines) {
  const [n, m, x, y] = lines[0].trim().split(' ').map(s => parseInt(s));
  const xs = lines[1].trim().split(' ').map(s => parseInt(s));
  const ys = lines[2].trim().split(' ').map(s => parseInt(s));
  return [n, m, x, y, xs, ys];
}
//  [python]
def main():
    n, m, *l = map(int, open(0).read().split())
    ab = list(zip(l[::2], l[1::2]))
    ab.sort(key = lambda x: x[0])
    sum = 0
    ans = 0
    for i, j in ab:
        if sum + j < m:
            sum += j
            ans += i * j
        else:
            ans += (m - sum) * i
            break
    print(ans)


if __name__ == '__main__':
    main()
//  [python]
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *AB = map(int, read().split())
    X = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

    X.sort()

    ans = 0
    n = 0
    for a, b in X:
        if n + b >= M:
            ans += (M - n) * a
            break
        else:
            ans += a * b
            n += b

    print(ans)
    return


if __name__ == '__main__':
    main()
//  [python]
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
# row = [int(input().rstrip()) for _ in range(n)]

def resolve():
    import sys
    input = sys.stdin.readline

    n, m = [int(x) for x in input().rstrip().split(" ")]

    ab = {}
    for _ in range(n):
        a, b = [int(x) for x in input().rstrip().split(" ")]
        if a not in ab:
            ab[a] = 0
        ab[a] += b

    a_list = sorted(ab.keys())
    ans = 0
    for a in a_list:
        if m <= ab[a]:
            ans += m * a
            break
        else:
            ans += ab[a] * a
            m -= ab[a]

    print(ans)



if __name__ == "__main__":
    resolve()
//  [python]
# coding: utf-8

data = input().split()
shoplist = []
for i in range(int(data[0])):
    shopdata = list(map(int, input().split()))
    shoplist.append(shopdata)
shoplist.sort()

payment = 0
wantdrink = int(data[1])
while wantdrink > 0 :
    restdrink = shoplist[0][1]
    if restdrink >= wantdrink:
        payment += wantdrink * shoplist[0][0]
        break
    else:
        payment += restdrink * shoplist[0][0]
        wantdrink -= restdrink
        del shoplist[0]
print(payment)
//  [python]
n, m = map(int, input().split())
money = 0
li = []

for i in range(n):
    li.append(list(map(int, input().split())))
li.sort()

while 0 < m:
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

# 再提出 4715718
//  [python]
n,m = map(int, input().split())
shops = sorted([list(map(int,input().split())) for _ in range(n)])
rest = m
ans = 0
while rest > 0:
    shop = shops.pop(0)
    buy = min(rest, shop[1])
    ans += buy*shop[0]
    rest -= buy
print(ans)
//  [java]
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        List<String> shopList = new ArrayList<String>();
        for (int i=0; i<N; i++) {
            shopList.add(String.format("%09d",sc.nextLong()) + "," + String.format("%09d",sc.nextLong()));
        }
        Collections.sort(shopList);
        Long kingaku = 0L;
        for (String sp : shopList) {
            //System.out.println(sp);
            if (M == 0) {
                break;
            }
            String[] strArray  = sp.split(",");
            Long A = Long.parseLong(strArray[0]);
            Long B = Long.parseLong(strArray[1]);

            if (M <= B) {
                kingaku += A * M;
                M -= M;
            }
            else {
                kingaku += A * B;
                M -= B;
            }

        }
        System.out.println(kingaku);
    }

}
//  [java]
import java.math.BigInteger;
import java.util.*;
import java.util.TreeMap;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int shopNum = sc.nextInt();
		int drinkNum = sc.nextInt();
		Map<Integer, Integer> drinks = new TreeMap<>();
		for(int i = 0; i < shopNum; i++){
			int key = sc.nextInt();
			try {
				int prev = drinks.get(key);
				drinks.put(key, sc.nextInt()+prev);
			}catch(Exception e) {
				drinks.put(key, sc.nextInt());
			}
		}

		BigInteger ans = BigInteger.ZERO;
		for(Map.Entry<Integer, Integer> entry : drinks.entrySet()) {
			if(drinkNum > entry.getValue()) {
				drinkNum -= entry.getValue();
				ans = ans.add(new BigInteger(entry.getKey().toString()).multiply(new BigInteger(entry.getValue().toString())));
			}else {
				ans = ans.add(new BigInteger(String.valueOf(drinkNum)).multiply(new BigInteger(entry.getKey().toString())));
				break;
			}
		}
		System.out.println(ans);
	}
}
//  [java]
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Shop> list = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            list.add(new Shop(sc.nextLong(), sc.nextInt()));
        }
        list.sort(Comparator.comparingLong(a -> a.value));

        long ans = 0;

        while (m > 0) {
            Shop target = list.get(0);
            list.remove(0);
            int kosu = Math.min(m, target.kosu);
            ans += target.value * kosu;
            m -= kosu;
        }

        System.out.println(ans);
    }

    public static class Shop {
        public long value;
        public int kosu;

        public Shop(long value, int kosu) {
            this.value = value;
            this.kosu = kosu;
        }
    }
}
//  [cpp]
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[100001];
	rep(k, 8) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	ll M = getint();
	ll P[100000];
	rep(i, N) {
		P[i] = (ll)getint() << 30;
		P[i] += getint();
	}

	ll kotae = 0;
	pakuri_sort(N, P);
	rep(j, N) {
		if (M) {
			ll k = min(M, P[j] & (1 << 30) - 1);
			kotae += k * (P[j] >> 30);
			M -= k;
		}
	}
	printf("%lld", kotae);

	Would you please return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	pair<int, int> P[100000];
	rep(i, N) {
		int a = getint();
		P[i] = mp(a, getint());
	}
	ll kotae = 0;
	sort(P, P + N);
	rep(j, N) {
		if (M) {
			int k = min(M, P[j].second);
			kotae += (ll)k * P[j].first;
			M -= k;
		}
	}
	co(kotae);

	Would you please return 0;
}