#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
        if(a[i]%a[0])
        {
            cout<<-1<<endl;
            return;
        }
    cout<<n<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;

}

int32_t main()
{

    IOS;

    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    int g = 0;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.push_back(x);
        g = __gcd(x,g);
    }

    if (g == 1) {
        cout << "-1\n";
        exit(0);
    }

    cout << n << '\n';
    for (int i = 0; i < n; i++) cout << v[i] << " ";
    cout << '\n';
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    int g = 0;
    vector<int> v;
    set<int> s;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.push_back(x);
        g = __gcd(x,g);
        s.emplace(x);
    }

    if (s.count(g) == 0) {
        cout << "-1\n";
        exit(0);
    }

    cout << n << '\n';
    for (int i = 0; i < n; i++) cout << v[i] << " ";
    cout << '\n';
}
/*

 */


#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    int g = 0;
    vector<int> v;
    set<int> s;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.push_back(x);
        g = __gcd(x,g);
        s.emplace(x);
    }

    if (s.count(g) == 0) {
        cout << "-1\n";
        exit(0);
    }

    cout << n*2 << '\n';
    for (int i = 0; i < n; i++) cout << v[i] << " " << g << " ";
    cout << '\n';
}
/*

 */


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <cstdio>
#define turbo ios::sync_with_stdio(false)
#define ll long long
#define inf 1000000007
using namespace std;
ll a, b, c, d, n, m, k, q, v;
string s;
int main(){
    turbo;
    cin>>n;
    ll arr[n];
    a=inf;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        a=min(a,arr[i]);
    }
    for(int i=0; i<n; i++){
        if(arr[i]%a!=0){
            cout<<-1; return 0;
        }
    }
    cout<<2*n<<endl;
    for(int i=0; i<n; i++){
        cout<<arr[i]<<" "<<a<<" ";
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long LL;
const int N=50050;

int a[N],n;
int mn=2333333;

int main(){

	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]<mn)mn=a[i];
	}
	for(i=1;i<=n;i++)
		if(a[i]%mn)
			break;
	if(i<=n)
		puts("-1");
	else{
		printf("%d\n%d",2*n-1,a[1]);
		for(i=2;i<=n;i++)
			printf(" %d %d",mn,a[i]);
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <cstdio>
#define turbo ios::sync_with_stdio(false)
#define ll long long
#define inf 1000000000000000
using namespace std;
ll a, b, c, d, n, m, k, q, v;

int main(){
    turbo;
    cin>>n;
    ll arr[n];
    for(int i=0; i<n; i++){
        cin>>arr[i];
        m=min(m, arr[i]);
    }
    for(int i=0; i<n; i++){
        if(arr[i]%m!=0){cout<<-1; return 0;}
    }
    cout<<n<<endl;
    for(int i=0; i<n; i++){
        cout<<arr[i]<<" ";
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tar
{
    class Program
    {
        static void Main(string[] args)
        {
            //Contester cont1 = new Contester(1, 5);
           // Contester cont2 = new Contester(2, 1);
            //Contester[] ar2 = new Contester[2];

            int[] ar = Util.getArray();

            int n = ar[0];
            int t1 = ar[1];
            int t2 = ar[2];
            int k = ar[3];

            int[,] array = new int[n, 2];
            for (int i = 0; i < n;i++ )
            {
                int[] temp = Util.getArray();
                array[i, 0] = temp[0];
                array[i, 1] = temp[1];
            }

            Contester[] contesters = new Contester[n];
            for (int i = 0; i < n;i++ )
            {
                contesters[i] = new Contester(i, t1, t2, array[i, 0], array[i, 1], k);
            }

            Array.Sort(contesters);
            Array.Reverse(contesters);

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(contesters[i]);
            }
        }

    }

    class Contester : IComparable
    {
        public int number;
        public decimal value;

        public Contester(int _number, decimal _value) {
            number = _number;
            value = _value;
        }

        public Contester(int _number, int t1, int t2, int u, int w, int k)
        {
            number = _number;
            value = Math.Max(getValue(t1, t2, u, w, k), getValue(t1, t2, w, u, k));
        }

        public override string ToString()
        {
            return (number+1) + " " + value.ToString("F2");
        }

        public static decimal getValue(int t1, int t2, int u, int w, int k) {
            decimal res = 0;

            res += (decimal)u * (decimal)t1;
            res -= res * (decimal)k / (decimal)100;
            res += (decimal)w * (decimal)t2;

            return res;
        }

        public int CompareTo(object obj)
        {
            if (obj is Contester)
            {
                if (this.value.CompareTo((obj as Contester).value)==0)
                {
                    return -this.number.CompareTo((obj as Contester).number);
                }
                return this.value.CompareTo((obj as Contester).value);  // compare user names
            }
            throw new ArgumentException("Object is not a User");
        }

    }

    class Util
    {
        public static int getNum()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] getArray()
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] array = new int[str.Length];

            for (int i = 0; i < array.Length; i++)
            {
                try
                {
                    array[i] = int.Parse(str[i]);
                }
                catch (Exception e)
                {
                    //Console.WriteLine(str[i]+"/");
                }
            }

            return array;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tar
{
    class Program
    {
        static void Main(string[] args)
        {
            //Contester cont1 = new Contester(1, 5);
           // Contester cont2 = new Contester(2, 1);
            //Contester[] ar2 = new Contester[2];

            int[] ar = Util.getArray();

            int n = ar[0];
            int t1 = ar[1];
            int t2 = ar[2];
            int k = ar[3];

            int[,] array = new int[n, 2];
            for (int i = 0; i < n;i++ )
            {
                int[] temp = Util.getArray();
                array[i, 0] = temp[0];
                array[i, 1] = temp[1];
            }

            Contester[] contesters = new Contester[n];
            for (int i = 0; i < n;i++ )
            {
                contesters[i] = new Contester(i, t1, t2, array[i, 0], array[i, 1], k);
            }

            Array.Sort(contesters);
            Array.Reverse(contesters);

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(contesters[i]);
            }
        }

    }

    class Contester : IComparable
    {
        public int number;
        public decimal value;

        public Contester(int _number, decimal _value) {
            number = _number;
            value = _value;
        }

        public Contester(int _number, int t1, int t2, int u, int w, int k)
        {
            number = _number;
            value = Math.Max(getValue(t1, t2, u, w, k), getValue(t1, t2, w, u, k));
        }

        public override string ToString()
        {
            string str = value.ToString("F2");
            str = str.Replace(",", ".");
            return (number+1) + " " + str;
        }

        public static decimal getValue(int t1, int t2, int u, int w, int k) {
            decimal res = 0;

            res += (decimal)u * (decimal)t1;
            res -= res * (decimal)k / (decimal)100;
            res += (decimal)w * (decimal)t2;

            return res;
        }

        public int CompareTo(object obj)
        {
            if (obj is Contester)
            {
                if (this.value.CompareTo((obj as Contester).value)==0)
                {
                    return -this.number.CompareTo((obj as Contester).number);
                }
                return this.value.CompareTo((obj as Contester).value);  // compare user names
            }
            throw new ArgumentException("Object is not a User");
        }

    }

    class Util
    {
        public static int getNum()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] getArray()
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] array = new int[str.Length];

            for (int i = 0; i < array.Length; i++)
            {
                try
                {
                    array[i] = int.Parse(str[i]);
                }
                catch (Exception e)
                {
                    //Console.WriteLine(str[i]+"/");
                }
            }

            return array;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Growing_Mushrooms
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input.Split(' ')[0]);
            int t1 = int.Parse(input.Split(' ')[1]);
            int t2 = int.Parse(input.Split(' ')[2]);
            int k = int.Parse(input.Split(' ')[3]);
            List<double> winnertable = new List<double>();
            List<double> comp = new List<double>();
            for (int i = 0; i < n; i++)
            {
                double temp = 0;
                double[] speeds = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
                if(speeds[0]<speeds[1])
                {
                    temp = (speeds[0] * t1) - (speeds[0] *t1* (k / 100.00) )+ (speeds[1] * t2);
                }
                else
                {
                    temp = speeds[1] * t1 - speeds[1] *t1* (k / 100.00) + speeds[0] * t2;
                }
                winnertable.Add(temp);
                comp.Add(i + 1);
            }
            for (int i = 0; i < n; i++)
            {
                int index=winnertable.IndexOf(winnertable.Max());
                Console.WriteLine(comp[index]+" "+winnertable.Max().ToString("0.00"));
                winnertable.Remove(winnertable.Max());
                comp.RemoveAt(index);

            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Growing_Mushrooms
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input.Split(' ')[0]);
            int t1 = int.Parse(input.Split(' ')[1]);
            int t2 = int.Parse(input.Split(' ')[2]);
            int k = int.Parse(input.Split(' ')[3]);
            List<double> winnertable = new List<double>();
            List<double> comp = new List<double>();
            for (int i = 0; i < n; i++)
            {
                double temp = 0,temp1;
                double[] speeds = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);

                    temp = (speeds[0] * t1) - (speeds[0] *t1* (k / 100.00) )+ (speeds[1] * t2);

                    temp1 = speeds[1] * t1 - speeds[1] *t1* (k / 100.00) + speeds[0] * t2;

                if(temp>temp1)
                {
                    winnertable.Add(temp);

                }
                else
                {
                    winnertable.Add(temp1);
                }
                comp.Add(i + 1);
            }
            for (int i = 0; i < n; i++)
            {
                int index=winnertable.IndexOf(winnertable.Max());
                Console.WriteLine(comp[index]+" "+winnertable.Max().ToString("0.00"));
                winnertable.Remove(winnertable.Max());
                comp.RemoveAt(index);

            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Growing_Mushrooms
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input.Split(' ')[0]);
            int t1 = int.Parse(input.Split(' ')[1]);
            int t2 = int.Parse(input.Split(' ')[2]);
            int k = int.Parse(input.Split(' ')[3]);
            List<double> winnertable = new List<double>();
            List<double> comp = new List<double>();
            for (int i = 0; i < n; i++)
            {
                double temp = 0,temp1;
                double[] speeds = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);

                    temp = (speeds[0] * t1) - (speeds[0] *t1* (k / 100.00) )+ (speeds[1] * t2);

                    temp1 = speeds[1] * t1 - speeds[1] *t1* (k / 100.00) + speeds[0] * t2;

                if(temp>temp1)
                {
                    winnertable.Add(temp);

                }
                else
                {
                    winnertable.Add(temp1);
                }
                comp.Add(i + 1);
            }
            for (int i = 0; i < n; i++)
            {
                int index=winnertable.IndexOf(winnertable.Max());
                Console.WriteLine(comp[index] + " " + winnertable.Max().ToString("0.00", CultureInfo.GetCultureInfo("en-GB")));
                winnertable.Remove(winnertable.Max());
                comp.RemoveAt(index);

            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Growing_Mushrooms
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int n = int.Parse(input.Split(' ')[0]);
            int t1 = int.Parse(input.Split(' ')[1]);
            int t2 = int.Parse(input.Split(' ')[2]);
            int k = int.Parse(input.Split(' ')[3]);
            List<double> winnertable = new List<double>();
            List<double> comp = new List<double>();
            for (int i = 0; i < n; i++)
            {
                double temp = 0,temp1;
                double[] speeds = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);

                    temp = (speeds[0] * t1) - (speeds[0] *t1* (k / 100.00) )+ (speeds[1] * t2);

                    temp1 = speeds[1] * t1 - speeds[1] *t1* (k / 100.00) + speeds[0] * t2;

                winnertable.Add(Math.Max(temp,temp1));
                comp.Add(i + 1);
            }
            for (int i = 0; i < n; i++)
            {
                int index=winnertable.IndexOf(winnertable.Max());
                Console.WriteLine(comp[index]+" "+winnertable.Max().ToString("0.00"));
                winnertable.Remove(winnertable.Max());
                comp.RemoveAt(index);

            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;

namespace Growing_Mushrooms
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next(), t1 = Next(), t2 = Next(), k = Next();

            double kk = (100.0 - k)/100;

            var a = new int[n];
            var b = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = Next();
                b[i] = Next();
            }

            var list = new List<Tuple<int, double>>(n);
            for (int i = 0; i < n; i++)
            {
                list.Add(new Tuple<int, double>(i + 1, Math.Max(a[i]*t1*kk + b[i]*t2, b[i]*t1*kk + a[i]*t2)));
            }

            list.Sort((p1, p2) =>
                          {
                              int c = p2.Item2.CompareTo(p1.Item2);
                              if (c == 0) c = p1.Item1.CompareTo(p2.Item1);
                              return c;
                          });

            foreach (var tuple in list)
            {
                writer.Write(tuple.Item1);
                writer.Write(' ');
                writer.WriteLine(tuple.Item2.ToString("#0.00", CultureInfo.InvariantCulture));
            }

            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _118b
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(File.OpenText("in.txt"));
            var d = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var n = d[0];
            var t1 = d[1];
            var t2 = d[2];
            var k = d[3];
            var per = k / 100d;

            var a = new Tuple<int, double>[n];

            for (int i = 0; i < n; i++)
            {
                var t = Console.ReadLine().Split(' ').Select(i1 => int.Parse(i1)).ToArray();
                var b1 = t[0];
                var b2 = t[1];

                var fi = b1 * t1 * (1 - per) + b2 * t2;
                var sec = b2 * t1 * (1 - per) + b1 * t2;
                a[i] = Tuple.Create(i, Math.Max(fi, sec));
                //a[i].Item2 = Math.Max(fi, sec);
                //a[i].Item1 = i;

            }

            var ar = a.OrderBy(i => i.Item2).ThenByDescending(i => i.Item1).ToArray();
            for (int i = n - 1; i >= 0; i--)
            {
                Console.WriteLine("{0} {1:0.00}", ar[i].Item1 + 1, ar[i].Item2);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace _118b
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(File.OpenText("in.txt"));
            var d = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var n = d[0];
            var t1 = d[1];
            var t2 = d[2];
            var k = d[3];
            var per = k / 100d;

            var a = new Tuple<int, double>[n];

            for (int i = 0; i < n; i++)
            {
                var t = Console.ReadLine().Split(' ').Select(i1 => int.Parse(i1)).ToArray();
                var b1 = t[0];
                var b2 = t[1];

                var fi = b1 * t1 * (1 - per) + b2 * t2;
                var sec = b2 * t1 * (1 - per) + b1 * t2;
                a[i] = Tuple.Create(i, Math.Max(fi, sec));
                //a[i].Item2 = Math.Max(fi, sec);
                //a[i].Item1 = i;

            }

            //Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
            var ar = a.OrderBy(i => i.Item2).ThenByDescending(i => i.Item1).ToArray();
            for (int i = n - 1; i >= 0; i--)
            {
                Console.WriteLine("{0} {1}", ar[i].Item1 + 1, ar[i].Item2.ToString("0.00", CultureInfo.GetCultureInfo("en-GB")));
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace _118b
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(File.OpenText("in.txt"));
            var d = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var n = d[0];
            var t1 = d[1];
            var t2 = d[2];
            var k = d[3];
            var per = k / 100d;

            var a = new Tuple<int, double>[n];

            for (int i = 0; i < n; i++)
            {
                var t = Console.ReadLine().Split(' ').Select(i1 => int.Parse(i1)).ToArray();
                var b1 = t[0];
                var b2 = t[1];

                var fi = b1 * t1 * (1 - per) + b2 * t2;
                var sec = b2 * t1 * (1 - per) + b1 * t2;
                a[i] = Tuple.Create(i, Math.Max(fi, sec));
                //a[i].Item2 = Math.Max(fi, sec);
                //a[i].Item1 = i;

            }

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
            var ar = a.OrderBy(i => i.Item2).ThenByDescending(i => i.Item1).ToArray();
            for (int i = n - 1; i >= 0; i--)
            {
                Console.WriteLine("{0} {1:0.00}", ar[i].Item1 + 1, ar[i].Item2);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _118b
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(File.OpenText("in.txt"));
            var d = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var n = d[0];
            var t1 = d[1];
            var t2 = d[2];
            var k = d[3];
            var per = k / 100d;

            var a = new double[n];
            var g = new int[n];
            for (int i = 0; i < n; i++)
            {
                var t = Console.ReadLine().Split(' ').Select(i1 => int.Parse(i1)).ToArray();
                var b1 = t[0];
                var b2 = t[1];

                var fi = b1 * t1 * (1 - per) + b2 * t2;
                var sec = b2 * t1 * (1 - per) + b1 * t2;
                a[i] = Math.Max(fi, sec);
                g[i] = i;

            }

            Array.Sort(a, g);
            for (int i = n - 1; i >= 0; i--)
            {
                Console.WriteLine("{0} {1:0.00}", g[i], a[i]);
            }
        }
    }
}


import java.text.DecimalFormat
import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val n : Int = sc.nextInt()
    val t1 : Int = sc.nextInt()
    val t2 : Int = sc.nextInt()
    val k : Double = sc.nextInt().toDouble()
    val percent : Double = ((100.0 - k) / 100.0)

    val place = IntArray(n)

    for (i in 0 until n) place[i] = i + 1

    val height = DoubleArray(n)

    for (i in 0 until n) {
        val a1 : Double = sc.nextInt().toDouble()
        val a2 : Double = sc.nextInt().toDouble()

        val f : Double = (a1 * t1 * percent) + (a2 * t2)
        val s : Double = (a1 * t1) + (a2 * t2 * percent)

        height[i] = if (f > s) f else s

    }

    sort(height, place, 0, n - 1)
    var count : Int = 0

    for (i in 1 until n) {
        if (height[i] != height[count]) {
            count = i
        }
    }

    sort(place, count, n - 1)

    for (i in 0 until n) {
        print(place[i])
        print(" ")
        println("%.2f".format(height[i].toFloat()))
    }

}

fun sort(array1 : DoubleArray, array2 : IntArray, low : Int, high : Int) {

    var i : Int = low
    var j : Int = high
    val x : Double = array1[low + (high - low) / 2]

    do {
        while(array1[i] > x) ++i
        while(array1[j] < x) --j
        if (i <= j) run {
            val tmp: Double = array1[i]
            array1[i] = array1[j]
            array1[j] = tmp

            val mtp: Int = array2[i]
            array2[i] = array2[j]
            array2[j] = mtp

            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array1, array2, low, j)
    if (i < high) sort(array1, array2, i, high)

}

fun sort(array : IntArray, low : Int, high : Int) {

    var i = low
    var j = high
    val x = array[low + (high - low) / 2]

    do {
        while(array[i] < x) ++i
        while(array[j] > x) --j
        if (i <= j) run {
            val tmp = array[i]
            array[i] = array[j]
            array[j] = tmp
            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array, low, j)
    if (i < high) sort(array, i, high)

}


import java.text.DecimalFormat
import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val n : Int = sc.nextInt()
    val t1 : Int = sc.nextInt()
    val t2 : Int = sc.nextInt()
    val k : Double = sc.nextInt().toDouble()
    val percent : Double = ((100.0 - k) / 100.0)

    val place = IntArray(n)

    for (i in 0 until n) place[i] = i + 1

    val height = DoubleArray(n)

    for (i in 0 until n) {
        val a1 : Double = sc.nextInt().toDouble()
        val a2 : Double = sc.nextInt().toDouble()

        val f : Double = (a1 * t1 * percent) + (a2 * t2)
        val s : Double = (a2 * t1 * percent) + (a1 * t2)

        height[i] = if (f > s) f else s

    }

    sort(height, place, 0, n - 1)
    var count : Int = 0

    for (i in 1 until n) {
        if (height[i] != height[count]) {
            count = i
        }
    }

    sort(place, count, n - 1)

    for (i in 0 until n) {
        print(place[i])
        print(" ")
        println("%.2f".format(height[i].toFloat()))
    }

}

fun sort(array1 : DoubleArray, array2 : IntArray, low : Int, high : Int) {

    var i : Int = low
    var j : Int = high
    val x : Double = array1[low + (high - low) / 2]

    do {
        while(array1[i] > x) ++i
        while(array1[j] < x) --j
        if (i <= j) run {
            val tmp: Double = array1[i]
            array1[i] = array1[j]
            array1[j] = tmp

            val mtp: Int = array2[i]
            array2[i] = array2[j]
            array2[j] = mtp

            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array1, array2, low, j)
    if (i < high) sort(array1, array2, i, high)

}

fun sort(array : IntArray, low : Int, high : Int) {

    var i = low
    var j = high
    val x = array[low + (high - low) / 2]

    do {
        while(array[i] < x) ++i
        while(array[j] > x) --j
        if (i <= j) run {
            val tmp = array[i]
            array[i] = array[j]
            array[j] = tmp
            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array, low, j)
    if (i < high) sort(array, i, high)

}


import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val n : Int = sc.nextInt()
    val t1 : Int = sc.nextInt()
    val t2 : Int = sc.nextInt()
    val k : Double = sc.nextInt().toDouble()
    val percent : Double = ((100.0 - k) / 100.0)

    val place = IntArray(n)

    for (i in 0 until n) place[i] = i + 1

    val height = DoubleArray(n)

    for (i in 0 until n) {
        val a1 : Double = sc.nextInt().toDouble()
        val a2 : Double = sc.nextInt().toDouble()

        val f : Double = (a1 * t1 * percent) + (a2 * t2)
        val s : Double = (a2 * t1 * percent) + (a1 * t2)

        height[i] = if (f > s) f else s

    }

    sort(height, place, 0, n - 1)
    var count = 0

    for (i in 1 until n) {
        if (height[i] != height[count]) {
            sort(place, count, i - 1)
            count = i
        }
    }

    sort(place, count, n - 1)

    for (i in 0 until n) {
        print(place[i])
        print(" ")
        println("%.2f".format(height[i].toFloat()))
    }

}

fun sort(array1 : DoubleArray, array2 : IntArray, low : Int, high : Int) {

    var i : Int = low
    var j : Int = high
    val x : Double = array1[low + (high - low) / 2]

    do {
        while(array1[i] > x) ++i
        while(array1[j] < x) --j
        if (i <= j) run {
            val tmp: Double = array1[i]
            array1[i] = array1[j]
            array1[j] = tmp

            val mtp: Int = array2[i]
            array2[i] = array2[j]
            array2[j] = mtp

            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array1, array2, low, j)
    if (i < high) sort(array1, array2, i, high)

}

fun sort(array : IntArray, low : Int, high : Int) {

    var i = low
    var j = high
    val x = array[low + (high - low) / 2]

    do {
        while(array[i] < x) ++i
        while(array[j] > x) --j
        if (i <= j) run {
            val tmp = array[i]
            array[i] = array[j]
            array[j] = tmp
            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array, low, j)
    if (i < high) sort(array, i, high)

}


import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val n : Int = sc.nextInt()
    val t1 : Int = sc.nextInt()
    val t2 : Int = sc.nextInt()
    val k : Double = sc.nextInt().toDouble()
    val percent : Double = ((100.0 - k) / 100.0)

    val place = IntArray(n)

    for (i in 0 until n) place[i] = i + 1

    val height = DoubleArray(n)

    for (i in 0 until n) {
        val a1 : Double = sc.nextInt().toDouble()
        val a2 : Double = sc.nextInt().toDouble()

        val f : Double = (a1 * t1 * percent) + (a2 * t2)
        val s : Double = (a1 * t1) + (a2 * t2 * percent)

        height[i] = if (f > s) f else s

    }

    sort(height, place, 0, n - 1)
    var count : Int = 0

    for (i in 1 until n) {
        if (height[i] != height[count]) {
            count = i
        }
    }

    sort(place, count, n - 1)

    for (i in 0 until n) {
        print(place[i])
        print(" ")
        println(height[i])
    }

}

fun sort(array1 : DoubleArray, array2 : IntArray, low : Int, high : Int) {

    var i : Int = low
    var j : Int = high
    val x : Double = array1[low + (high - low) / 2]

    do {
        while(array1[i] > x) ++i
        while(array1[j] < x) --j
        if (i <= j) run {
            val tmp: Double = array1[i]
            array1[i] = array1[j]
            array1[j] = tmp

            val mtp: Int = array2[i]
            array2[i] = array2[j]
            array2[j] = mtp

            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array1, array2, low, j)
    if (i < high) sort(array1, array2, i, high)

}

fun sort(array : IntArray, low : Int, high : Int) {

    var i = low
    var j = high
    val x = array[low + (high - low) / 2]

    do {
        while(array[i] < x) ++i
        while(array[j] > x) --j
        if (i <= j) run {
            val tmp = array[i]
            array[i] = array[j]
            array[j] = tmp
            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array, low, j)
    if (i < high) sort(array, i, high)

}


import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val n : Int = sc.nextInt()
    val t1 : Int = sc.nextInt()
    val t2 : Int = sc.nextInt()
    val k : Double = sc.nextInt().toDouble()
    val percent : Double = ((100.0 - k) / 100.0)

    val place = IntArray(n)

    for (i in 0 until n) place[i] = i + 1

    val height = DoubleArray(n)

    for (i in 0 until n) {
        val a1 : Double = sc.nextInt().toDouble()
        val a2 : Double = sc.nextInt().toDouble()

        val f : Double = (a1 * t1 * percent) + (a2 * t2)
        val s : Double = (a1 * t1) + (a2 * t2 * percent)

        height[i] = if (f > s) f else s

    }

    sort(height, place, 0, n - 1)

    for (i in 0 until n) {
        print(place[i])
        print(" ")
        println(height[i])
    }

}

fun sort(array1 : DoubleArray, array2 : IntArray, low : Int, high : Int) {

    var i : Int = low
    var j : Int = high
    val x : Double = array1[low + (high - low) / 2]

    do {
        while(array1[i] > x) ++i
        while(array1[j] < x) --j
        if (i <= j) run {
            val tmp : Double = array1[i]
            array1[i] = array1[j]
            array1[j] = tmp

            val mtp : Int = array2[i]
            array2[i] = array2[j]
            array2[j] = mtp

            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array1, array2, low, j)
    if (i < high) sort(array1, array2, i, high)

}


import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val n : Int = sc.nextInt()
    val t1 : Int = sc.nextInt()
    val t2 : Int = sc.nextInt()
    val k : Double = sc.nextInt().toDouble()
    val percent : Double = ((100.0 - k) / 100.0)

    val place = IntArray(n)

    for (i in 0 until n) place[i] = i + 1

    val height = DoubleArray(n)

    for (i in 0 until n) {
        val a1 : Double = sc.nextInt().toDouble()
        val a2 : Double = sc.nextInt().toDouble()

        val f : Double = (a1 * t1 * percent) + (a2 * t2)
        val s : Double = (a2 * t1 * percent) + (a1 * t2)

        height[i] = if (f > s) f else s

    }

    sort(height, place, 0, n - 1)
    var count = 0

    for (i in 1 until n) {
        if (height[i] != height[count]) {
            sort(place, count, i - 1)
            count = i
        }
    }

    sort(place, count, n - 1)

    for (i in 0 until n) {
        print(place[i])
        print(" ")
        println("%.2f".format(height[i]))
    }

}

fun sort(array1 : DoubleArray, array2 : IntArray, low : Int, high : Int) {

    var i : Int = low
    var j : Int = high
    val x : Double = array1[low + (high - low) / 2]

    do {
        while(array1[i] > x) ++i
        while(array1[j] < x) --j
        if (i <= j) run {
            val tmp: Double = array1[i]
            array1[i] = array1[j]
            array1[j] = tmp

            val mtp: Int = array2[i]
            array2[i] = array2[j]
            array2[j] = mtp

            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array1, array2, low, j)
    if (i < high) sort(array1, array2, i, high)

}

fun sort(array : IntArray, low : Int, high : Int) {

    var i = low
    var j = high
    val x = array[low + (high - low) / 2]

    do {
        while(array[i] < x) ++i
        while(array[j] > x) --j
        if (i <= j) run {
            val tmp = array[i]
            array[i] = array[j]
            array[j] = tmp
            i++
            j--
        }
    } while(i <= j)

    if (low < j) sort(array, low, j)
    if (i < high) sort(array, i, high)

}


fun main() = java.util.Scanner(System.`in`)
    .run {
        val contestants = nextInt()
        val times = Pair(nextInt(), nextInt())
        val percentage = nextInt()
        Triple(List(contestants) { index -> Triple(nextInt(), nextInt(), index + 1) }, times, percentage)
    }
    .let { (contestants, times, percentage) ->
        contestants.map { (firstSpeed, secondSpeed, number) ->
            Pair(
                number,
                maxOf(
                    (firstSpeed.toDouble() * times.first * ((100 - percentage.toDouble()) / 100)) +
                            (secondSpeed.toDouble() * times.second),
                    (secondSpeed.toDouble() * times.first * ((100 - percentage.toDouble()) / 100)) +
                            (firstSpeed.toDouble() * times.second)
                )
            )
        }
    }
    .sortedByDescending { (_, length) -> length }
    .forEach { (number, length) -> "$number ${"%.2f".format(length)}".run(::println) }


fun main() = java.util.Scanner(System.`in`)
    .run {
        val contestants = nextInt()
        val times = Pair(nextInt(), nextInt())
        val percentage = nextInt()
        Triple(List(contestants) { index -> Triple(nextInt(), nextInt(), index + 1) }, times, percentage)
    }
    .let { (contestants, times, percentage) ->
        contestants.map { (firstSpeed, secondSpeed, number) ->
            Pair(
                number,
                maxOf(
                    (firstSpeed.toDouble() * times.first * ((100 - percentage.toDouble()) / 100)) +
                            (secondSpeed.toDouble() * times.second),
                    (secondSpeed.toDouble() * times.first * ((100 - percentage.toDouble()) / 100)) +
                            (firstSpeed.toDouble() * times.second)
                )
            )
        }
    }
    .sortedByDescending { (_, length) -> length }
    .map { (number, length) -> "$number ${"%.2f".format(length)}" }
    .forEach(::println)


import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    fun readNums () = br.readLine().split(" ").map { it.toDouble() }
    val (n, t1, t2, k) = readNums()
    val speeds = List(n.toInt()){
        val (a, b) = readNums()
        a to b
    }

    val finalHeights = speeds.map { (a, b) ->
        max(a*t1*(1 - k/100) + t2*b, b*t1*(1 - k/100) + t2*a)
    }.zip(1..n.toInt()).sortedByDescending { it.first }

    for ((h, i) in finalHeights) {
        println("${i} ${"%.2f".format(h)}")
    }
}


#include<iostream>
#include<string.h>
#include<stdio.h>
#include<iomanip>
using namespace std;

int main()
{
    int n,t1,t2,a,b;
    double k;
    double c[1005];
    int v[1005];
    scanf("%d%d%d",&n,&t1,&t2);
    cin>>k;
    k/=100;
    k=1-k;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&a,&b);
        v[i]=i;
        c[i]=double(a)*t1*k+b*t2;
        c[i]=max(c[i],double(b)*t1*k+a*t2);
    }
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
            if(c[i]<c[j]||(c[i]==c[j]&&v[i]>v[j]))swap(c[i],c[j]),swap(v[i],v[j]);
    for(int i=1;i<=n;i++)
        cout<<v[i]<<" "<<fixed<<setprecision(2)<<c[i]<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

double a[1500], b[1500];

vector <pair <double, int> > r;

int main () {
	#ifndef ONLINE_JUDGE
		freopen (".in", "r", stdin);
	#endif

	double n, t1, t2, K;

	cin >> n >> t1 >> t2 >> K;

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}

	double k = K / 100.0;

	for (int i = 0; i < n; i++) {
		double A = (t1 * a[i]) - (t1 * a[i]) * k + (t2 * b[i]), B = (t1 * b[i]) - (t1 * b[i]) * k + (t2 * a[i]);

		r.push_back (make_pair (max (A, B), i + 1));
	}

	sort (r.begin(), r.end(), greater <pair <int, int> >());

	for (int i = 0; i < r.size(); i++)
		cout << r[i].second << " " << setprecision (2) << fixed << r[i].first << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

double a[1500], b[1500];

vector <pair <double, int> > r;

bool cmp (pair <double, int> a, pair <double, int> b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first > b.first;
}

int main () {
	#ifndef ONLINE_JUDGE
		freopen (".in", "r", stdin);
	#endif

	double n, t1, t2, K;

	cin >> n >> t1 >> t2 >> K;

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}

	double k = K / 100.0;

	for (int i = 0; i < n; i++) {
		double A = (t1 * a[i]) - (t1 * a[i]) * k + (t2 * b[i]), B = (t1 * b[i]) - (t1 * b[i]) * k + (t2 * a[i]);

		r.push_back (make_pair (max (A, B), i + 1));
	}

	sort (r.begin(), r.end(), cmp);

	for (int i = 0; i < r.size(); i++)
		cout << r[i].second << " " << setprecision (2) << fixed << r[i].first << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
bool comp(pair<double,int> a, pair<double,int> b)
{
    double ep = 10e-9;
    if(a.first - ep <= b.first && b.first <= a.first + ep)
        return a.second > b.second;
    return a.first > b.first;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int T = 2;
//while(T--)
{
    int n,t1,t2,k,a,b;
    double c = 1.0;
    cin >> n >> t1 >> t2 >> k;
    pair<int,int>* arr = new pair<int,int>[n];
    pair<double,int> *res = new pair<double,int>[n];
    for(int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        arr[i] = make_pair(min(a,b),max(a,b));
        c = 0;
        c = arr[i].first * t1 * (1 - (double)k/100) + arr[i].second * t2;
        res[i] = make_pair(c,i);
    }
    sort(res,res+n,comp);
    for(int i = 0; i < n; ++i)
    {
        printf("%d %.2f\n",res[i].second,res[i].first);
    }
    delete[]arr; delete[]res;
}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
bool comp(pair<double,int> a, pair<double,int> b)
{
    double ep = 10e-9;
    if(a.first - ep <= b.first && b.first <= a.first + ep)
        return a.second < b.second;
    return a.first > b.first;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int T = 2;
//while(T--)
{
    int n,t1,t2,k,a,b;
    double c = 1.0;
    cin >> n >> t1 >> t2 >> k;
    pair<int,int>* arr = new pair<int,int>[n];
    pair<double,int> *res = new pair<double,int>[n];
    for(int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        arr[i] = make_pair(min(a,b),max(a,b));
        c = 0;
        c = arr[i].first * t1 * (1 - (double)k/100) + arr[i].second * t2;
        res[i] = make_pair(c,i+1);
    }
    sort(res,res+n,comp);
    for(int i = 0; i < n; ++i)
    {
        printf("%d %.2f\n",res[i].second,res[i].first);
    }
    delete[]arr; delete[]res;
}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
bool comp(pair<double,int> a, pair<double,int> b)
{
    double ep = 10e-9;
    if(a.first - ep <= b.first && b.first <= a.first + ep)
        return a.second < b.second;
    return a.first > b.first;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int T = 2;
//while(T--)
{
    int n,t1,t2,k,a,b;
    double c = 1.0;
    cin >> n >> t1 >> t2 >> k;
    pair<double,int> *res = new pair<double,int>[n];
    for(int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        c = max(a * t1 * (1 - (double)k/100) + b * t2, b * t1 * (1 - (double)k/100) + a * t2);
        res[i] = make_pair(c,i+1);
    }
    sort(res,res+n,comp);
    for(int i = 0; i < n; ++i)
    {
        printf("%d %.2f\n",res[i].second,res[i].first);
    }
    delete[]res;
}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
bool comp(pair<double,int> a, pair<double,int> b)
{
    double ep = 10e-9;
    if(a.first - ep <= b.first && b.first <= a.first + ep)
        return a.second > b.second;
    return a.first > b.first;
}

int main()
{
    freopen("input.txt","r",stdin);
    int T = 2;
while(T--)
{
    int n,t1,t2,k,a,b;
    double c = 1.0;
    cin >> n >> t1 >> t2 >> k;
    pair<int,int>* arr = new pair<int,int>[n];
    pair<double,int> *res = new pair<double,int>[n];
    for(int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        arr[i] = make_pair(min(a,b),max(a,b));
        c = 0;
        c = arr[i].first * t1 * (1 - (double)k/100) + arr[i].second * t2;
        res[i] = make_pair(c,i);
    }
    sort(res,res+n,comp);
    for(int i = 0; i < n; ++i)
    {
        printf("%d %.2f\n",res[i].second,res[i].first);
    }
    delete[]arr; delete[]res;
}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
bool comp(pair<double,int> a, pair<double,int> b)
{
    double ep = 10e-9;
    if(a.first - ep <= b.first && b.first <= a.first + ep)
        return a.second > b.second;
    return a.first > b.first;
}

int main()
{
    //freopen("input.txt","r",stdin);
    int T = 2;
//while(T--)
{
    int n,t1,t2,k,a,b;
    double c = 1.0;
    cin >> n >> t1 >> t2 >> k;
    pair<int,int>* arr = new pair<int,int>[n];
    pair<double,int> *res = new pair<double,int>[n];
    for(int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        arr[i] = make_pair(min(a,b),max(a,b));
        c = 0;
        c = arr[i].first * t1 * (1 - (double)k/100) + arr[i].second * t2;
        res[i] = make_pair(c,i+1);
    }
    sort(res,res+n,comp);
    for(int i = 0; i < n; ++i)
    {
        printf("%d %.2f\n",res[i].second,res[i].first);
    }
    delete[]arr; delete[]res;
}
    return 0;
}


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<long long,int> > H;
bool cmp(pair<long long,int> p1,pair<long long,int> p2)
{
	if (p1.first >p2.first) return 1;
	else if(p1.first<p2.first) return 0;
	else if(p1.second<p2.second)return 1;
	else return 0;
}
int main()
{
	long long n,t1,t2,k,a,b;
	long long h1,h2;
	scanf("%I64d%I64d%I64d%I64d",&n,&t1,&t2,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%I64d%I64d",&a,&b);
		h1 = a*t1*(100-k) + b*t2*100;
		h2 = b*t1*(100-k) + a*t2*100;
		H.push_back(make_pair(max(h1,h2),i+1));
	}
	sort(H.begin(),H.end(),cmp);
	for(int i=0;i<n;i++)
	{
		double tmp = H[i].first/100.0;
		printf("%d %.2lf\n",H[i].second,tmp);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stdio.h>

using namespace std;

struct uchastniki
{
    int ind;
    double length;
};

int compare(uchastniki x, uchastniki y)
{
    if (x.length != y.length)
        return x.length > y.length;
    else return x.ind < y.ind;
}

int main()
{
//    freopen("input.txt", "r", stdin);
    int i, n;
    double t1, t2, k, n1, n2, v1, v2;
    cin >> n >> t1 >> t2 >> k;
    uchastniki a[n];

    for(i = 0; i < n; i++)
    {
        cin >> v1 >> v2;
        a[i].ind = i + 1;

        double sum = 0, max = 0;
        max = 1.0 * v1 * t1 * (100 - k)/ 100 + 1.0 * v2 * t2;
        sum = 1.0 * v2 * t1 * (100 - k)/ 100 + 1.0 * v1 * t2;
        if(sum>max) max=sum;
        a[i].length = max;

    }

    sort(a, a + n, compare);
    for(i = 0; i < n; i++)
    {
        cout << a[i].ind << " ";
        printf("%.2f", a[i].length);
        cout << "\n";
    }

    return 0;
}


//
//  main.cpp
//  CF
//
//  Created by Hossein Yousefi on 9/10/1393 AP.
//  Copyright (c) 1393 IranGeek. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
vector<pii> v;

#define it(x) x::iterator

int main(int argc, const char * argv[]) {
    int n, t1, t2, k;
    cin >> n >> t1 >> t2 >> k;
    k = 100 - k;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        int j = max(t1 * a * k + t2 * b * 100, t1 * b * k + t2 * a * 100);
        v.push_back(pii(j, i + 1));
    }
    sort(v.begin(), v.end());
    for (int i = (int)v.size() - 1; i >= 0; --i) {
        cout << v[i].second << ' ';
        cout.precision(2);
        cout << fixed << v[i].first / 100.0 << '\n';
    }
    return 0;
}


//
//  main.cpp
//  CF
//
//  Created by Hossein Yousefi on 9/10/1393 AP.
//  Copyright (c) 1393 IranGeek. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
vector<pii> v;

#define it(x) x::iterator

int main(int argc, const char * argv[]) {
    int n, t1, t2, k;
    cin >> n >> t1 >> t2 >> k;
    k = 100 - k;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        int j = max(t1 * a * k + t2 * b * 100, t1 * b * k + t2 * a * 100);
        v.push_back(pii(j, n - i));
    }
    sort(v.begin(), v.end());
    for (int i = (int)v.size() - 1; i >= 0; --i) {
        cout << n - v[i].second + 1<< ' ';
        cout.precision(2);
        cout << fixed << v[i].first / 100.0 << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define oo 100000000000
typedef pair<double,int> pdi;
//typedef pair<int,int> pii;
typedef long long ll;

int n,t1,t2;
double k;
pdi a[1005];
int main(){
    ios_base::sync_with_stdio(false);
    cin >> n >> t1 >> t2 >> k;
    k /= (double) 100;
    for(int i = 0; i < n; i++){
        double q,p;
        cin >> q >> p;
        double ans = (double) (min(q,p)*t1);
        double tmp = ans * k;
        ans -= tmp;
        ans += (double) (max(p,q)*t2);
        a[i] = mp(ans,-1 * i);
    }
    sort(a,a+n);
    for(int i = n-1; i >= 0; i--){
        cout << (-1 * a[i].S) + 1 << " ";
        cout << fixed << setprecision(2) << a[i].F << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define oo 100000000000
typedef pair<double,int> pdi;
//typedef pair<int,int> pii;
typedef long long ll;

int n,t1,t2;
double k;
pdi a[1005];
int main(){
    ios_base::sync_with_stdio(false);
    cin >> n >> t1 >> t2 >> k;
    k /= (double) 100;
    for(int i = 0; i < n; i++){
        double q,p;
        cin >> q >> p;
        double tmp1,tmp2;
        tmp1 = (double) t1*p;
        tmp1 -= (tmp1*k);
        tmp1 += (double) t2*q;
        tmp2 = (double) t1*q;
        tmp2 -= (tmp2*k);
        tmp2 += (double) t2*p;
        double ans;
        if(tmp1 >= tmp2)
            ans = tmp1;
        else
            ans = tmp2;
        a[i].F = ans;
        a[i].S = (i * -1);
    }
    sort(a+0,a+n);
    for(int i = n-1; i >= 0; i--){
        cout << (-1 * a[i].S) + 1 << " ";
        cout << fixed << setprecision(2) << a[i].F << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
  int n, t1, t2, k;
  cin >> n >> t1 >> t2 >> k;

  vector< pair<double, int> > results;

  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    double h0 = a * t1 * (100 - k) * .01 + b * t2;
    double h1 = b * t1 * (100 - k) * .01 + a * t2;
    results.push_back(make_pair(-max(h0, h1), i+1));
  }

  sort(results.begin(), results.end());

  for (auto it = results.begin(); it != results.end(); it++)
    printf("%d %.2f\n", it->second, -it->first);

}


#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 1005;

int n, t1, t2, k;

struct Mushroom {
    int id, a, b;
    double c;
    bool operator<(const Mushroom& rhs) const {
        if (c == rhs.c) {
            return id < rhs.id;
        }
        return c > rhs.c;
    }

    void calc() {
        double ta = a * t1 * (k * 0.01) + b * t2;
        double tb = b * t1 * (k * 0.01) + a * t2;
        if (ta > tb) {
            c = ta;
        } else {
            c = tb;
        }
    }
}p[MAXN];

int main() {
    cin >> n >> t1 >> t2 >> k;
    k = 100 - k;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].a >> p[i].b;
        p[i].id = i;
        p[i].calc();
    }
    sort(p, p + n);
    for (int i = 0; i < n; ++i) {
        printf("%d %.2f\n", p[i].id + 1, p[i].c);
    }
}


#pragma comment(linker, "/STACK:16777216")
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#ifndef ONLINE_JUDGE
#define Eo(x) { cerr << #x << " = " << (x) << endl; }
#else
#define Eo(x)
#endif

typedef long long int64;
const int inf = 0x3f3f3f3f;
const int64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
typedef double real;
const real eps = 1e-6;
typedef pair<int64,int64> pip;

int64 gcd(int64 a, int64 b) {
  return a ? gcd(b%a,a) : b;
}

template <typename A,typename B>
ostream& operator<<(ostream& os, const pair<A,B>& p) {
                 return os << p.first << "," << p.second;
}

template <typename A>
ostream& operator<<(ostream& os, const vector<A>& v) {
                 for (int i = 0; i < v.size(); i++) {
                   os << v[i] << ";";
                 }
                 return os;
}

template <typename A>
ostream& operator<<(ostream& os, const set<A>& v) {
                 for (typename set<A>::const_iterator it = v.begin(); it != v.end(); ++it) {
                   os << *it << ";";
                 }
                 return os;
}

template <typename A, typename B>
ostream& operator<<(ostream& os, const map<A,B>& v) {
                 for (typename map<A,B>::const_iterator it = v.begin(); it != v.end(); ++it) {
                   os << it->first << "=" << it->second << ";";
                 }
                 return os;
}

inline int64 bit(int64 k) {
  return int64(1)<<k;
}

int SolveSquareEquation(real a, real b, real c, real& x1, real& x2) {
  real desc = b*b-4*a*c;
  if (desc<0) return 0;
  real sqrt_desc = sqrt(desc);
  x1 = (-b+sqrt_desc)/(2*a);
  x2 = (-b-sqrt_desc)/(2*a);
  if (desc<eps) {
    return 1;
  }
  return 2;
}

int SolveSquareEquationInt(int64 a, int64 b, int64 c, int64& x1, int64& x2) {
  int64 desc = b*b-4*a*c;
  if (desc<0) return 0;
  real sqrt_desc_r = sqrt(real(desc));
  int64 sqrt_desc = sqrt_desc_r;
  for (;sqrt_desc*sqrt_desc<desc; sqrt_desc++);
  for (;sqrt_desc*sqrt_desc>desc; sqrt_desc--);
  if (sqrt_desc*sqrt_desc != desc) {
    return 0;
  }
  int64 u1 = -b+sqrt_desc;
  int64 u2 = -b-sqrt_desc;
  int64 a2 = a*2;
  vector<int64> res;
  if (!(u1%a2)) {
    res.push_back(u1/a2);
  }
  if (!(u2%a2)) {
    res.push_back(u2/a2);
  }
  int oldsize = res.size();
  res.resize(2);
  x1=res[0];
  x2=res[1];
  return oldsize;
}

int main() {
  int n,t1,t2,k; cin >> n >> t1 >> t2 >> k;
  vector<pair<int64,int>> all;
  for (int i = 0; i < n; i++) {
    int x,y; scanf("%d%d",&x,&y);
    if (x>y) swap(x,y);
    int64 h = (x*t1)*(100-k) + y*t2*100;
    all.push_back(make_pair(-h,i));
  }
  sort(all.begin(),all.end());
  for (int i= 0 ; i < n; i++) {
    printf("%d %.2lf\n",all[i].second+1,double(real(-all[i].first*0.01)));
  }
  return 0;
}


#pragma comment(linker, "/STACK:16777216")
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#ifndef ONLINE_JUDGE
#define Eo(x) { cerr << #x << " = " << (x) << endl; }
#else
#define Eo(x)
#endif

typedef long long int64;
const int inf = 0x3f3f3f3f;
const int64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
typedef double real;
const real eps = 1e-6;
typedef pair<int64,int64> pip;

int64 gcd(int64 a, int64 b) {
  return a ? gcd(b%a,a) : b;
}

template <typename A,typename B>
ostream& operator<<(ostream& os, const pair<A,B>& p) {
                 return os << p.first << "," << p.second;
}

template <typename A>
ostream& operator<<(ostream& os, const vector<A>& v) {
                 for (int i = 0; i < v.size(); i++) {
                   os << v[i] << ";";
                 }
                 return os;
}

template <typename A>
ostream& operator<<(ostream& os, const set<A>& v) {
                 for (typename set<A>::const_iterator it = v.begin(); it != v.end(); ++it) {
                   os << *it << ";";
                 }
                 return os;
}

template <typename A, typename B>
ostream& operator<<(ostream& os, const map<A,B>& v) {
                 for (typename map<A,B>::const_iterator it = v.begin(); it != v.end(); ++it) {
                   os << it->first << "=" << it->second << ";";
                 }
                 return os;
}

inline int64 bit(int64 k) {
  return int64(1)<<k;
}

int SolveSquareEquation(real a, real b, real c, real& x1, real& x2) {
  real desc = b*b-4*a*c;
  if (desc<0) return 0;
  real sqrt_desc = sqrt(desc);
  x1 = (-b+sqrt_desc)/(2*a);
  x2 = (-b-sqrt_desc)/(2*a);
  if (desc<eps) {
    return 1;
  }
  return 2;
}

int SolveSquareEquationInt(int64 a, int64 b, int64 c, int64& x1, int64& x2) {
  int64 desc = b*b-4*a*c;
  if (desc<0) return 0;
  real sqrt_desc_r = sqrt(real(desc));
  int64 sqrt_desc = sqrt_desc_r;
  for (;sqrt_desc*sqrt_desc<desc; sqrt_desc++);
  for (;sqrt_desc*sqrt_desc>desc; sqrt_desc--);
  if (sqrt_desc*sqrt_desc != desc) {
    return 0;
  }
  int64 u1 = -b+sqrt_desc;
  int64 u2 = -b-sqrt_desc;
  int64 a2 = a*2;
  vector<int64> res;
  if (!(u1%a2)) {
    res.push_back(u1/a2);
  }
  if (!(u2%a2)) {
    res.push_back(u2/a2);
  }
  int oldsize = res.size();
  res.resize(2);
  x1=res[0];
  x2=res[1];
  return oldsize;
}

int main() {
  int64 n,t1,t2,k; cin >> n >> t1 >> t2 >> k;
  vector<pair<int64,int>> all;
  for (int i = 0; i < n; i++) {
    int x,y; scanf("%d%d",&x,&y);
    if (x>y) swap(x,y);
    int64 h1 = (x*t1)*(100-k) + y*t2*100;
    int64 h2 = (y*t1)*(100-k) + x*t2*100;
    all.push_back(make_pair(-max(h1,h2),i));
  }
  sort(all.begin(),all.end());
  for (int i = 0 ; i < n; i++) {
    printf("%d %d.%02d\n",all[i].second+1,int((-all[i].first)/100),int((-all[i].first)%100));
  }
  return 0;
}


#pragma comment(linker, "/STACK:16777216")
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#ifndef ONLINE_JUDGE
#define Eo(x) { cerr << #x << " = " << (x) << endl; }
#else
#define Eo(x)
#endif

typedef long long int64;
const int inf = 0x3f3f3f3f;
const int64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
typedef double real;
const real eps = 1e-6;
typedef pair<int64,int64> pip;

int64 gcd(int64 a, int64 b) {
  return a ? gcd(b%a,a) : b;
}

template <typename A,typename B>
ostream& operator<<(ostream& os, const pair<A,B>& p) {
                 return os << p.first << "," << p.second;
}

template <typename A>
ostream& operator<<(ostream& os, const vector<A>& v) {
                 for (int i = 0; i < v.size(); i++) {
                   os << v[i] << ";";
                 }
                 return os;
}

template <typename A>
ostream& operator<<(ostream& os, const set<A>& v) {
                 for (typename set<A>::const_iterator it = v.begin(); it != v.end(); ++it) {
                   os << *it << ";";
                 }
                 return os;
}

template <typename A, typename B>
ostream& operator<<(ostream& os, const map<A,B>& v) {
                 for (typename map<A,B>::const_iterator it = v.begin(); it != v.end(); ++it) {
                   os << it->first << "=" << it->second << ";";
                 }
                 return os;
}

inline int64 bit(int64 k) {
  return int64(1)<<k;
}

int SolveSquareEquation(real a, real b, real c, real& x1, real& x2) {
  real desc = b*b-4*a*c;
  if (desc<0) return 0;
  real sqrt_desc = sqrt(desc);
  x1 = (-b+sqrt_desc)/(2*a);
  x2 = (-b-sqrt_desc)/(2*a);
  if (desc<eps) {
    return 1;
  }
  return 2;
}

int SolveSquareEquationInt(int64 a, int64 b, int64 c, int64& x1, int64& x2) {
  int64 desc = b*b-4*a*c;
  if (desc<0) return 0;
  real sqrt_desc_r = sqrt(real(desc));
  int64 sqrt_desc = sqrt_desc_r;
  for (;sqrt_desc*sqrt_desc<desc; sqrt_desc++);
  for (;sqrt_desc*sqrt_desc>desc; sqrt_desc--);
  if (sqrt_desc*sqrt_desc != desc) {
    return 0;
  }
  int64 u1 = -b+sqrt_desc;
  int64 u2 = -b-sqrt_desc;
  int64 a2 = a*2;
  vector<int64> res;
  if (!(u1%a2)) {
    res.push_back(u1/a2);
  }
  if (!(u2%a2)) {
    res.push_back(u2/a2);
  }
  int oldsize = res.size();
  res.resize(2);
  x1=res[0];
  x2=res[1];
  return oldsize;
}

int main() {
  int64 n,t1,t2,k; cin >> n >> t1 >> t2 >> k;
  vector<pair<int64,int>> all;
  for (int i = 0; i < n; i++) {
    int x,y; scanf("%d%d",&x,&y);
    if (x>y) swap(x,y);
    int64 h = (x*t1)*(100-k) + y*t2*100;
    all.push_back(make_pair(-h,i));
  }
  sort(all.begin(),all.end());
  for (int i = 0 ; i < n; i++) {
    printf("%d %d.%02d\n",all[i].second+1,int((-all[i].first)/100),int((-all[i].first)%100));
  }
  return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
#include <string>
#include <cctype>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <list>
#include <cstring>
using namespace std;

#pragma region defines

typedef long long ll;
typedef unsigned long long ull;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
const double PI = 3.14159265358979;
const double PI2 = 6.28318530717958;
const double PId2 = 1.570796326794895;
#define REP(to, counter) for (int counter=0; counter < int(to); counter++)
#define X first
#define Y second
#define eps 1E-7
inline vi ReadVI(int count) {vi arrayname(count); REP(count, i) cin >> arrayname[i]; return arrayname; };
inline vii ReadVII(int count) {vii arrayname(count); REP(count, i) {cin >> arrayname[i].first; arrayname[i].second = i; } return arrayname; };
#pragma endregion defines
const int MOD = 1000000007;
const int MAXVALUE = 100001;

bool comp(pair<int, double> f, pair<int, double> s)
{
	if (f.second != s.second) return f.second > s.second;
	else return f.first < s.first;
}

int main(void)
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	double beginTime=clock();
#endif
	int n, t1, t2;
	double k;
	cin >> n >> t1 >> t2 >> k;
	k /= 100; k = 1-k;

	vector<pair<int, double>> a(n);
	for (int i = 0; i < n; i++)
	{
		int v1, v2;
		scanf("%d %d", &v1, &v2);
		double r1 = (t1*v1)*k+t2*v2;
		double r2 = (t1*v2)*k+t2*v1;
		a.push_back(make_pair(i+1, max(r1, r2)));
	}

	sort(a.begin(), a.end(), comp );
	for (int i = 0; i < n; i++)
		printf("%d %.2f\n", a[i].X, a[i].Y);

#ifndef ONLINE_JUDGE
	double endTime=clock();
	printf("\n***Elapsed = %.5lf******", (endTime-beginTime)/CLOCKS_PER_SEC);
#endif
}


#include<stdio.h>
#include<iostream>
#include<iomanip>
using namespace std;
struct s{
int f;
int a;
int b;
double sum;
}st[1500];
struct s d;
int main()
{int n,t1,t2,i,k;
cin>>n;
cin>>t1;
cin>>t2;
cin>>k;
for(int i=1;i<=n;i++)
{ cin>>st[i].a>>st[i].b;
st[i].f=i;
double x1=((double)(st[i].a * t1)-(double)(k*(st[i].a*t1)/100.0))+(double)(st[i].b)*t2;
double x2=((st[i].b)*t1-((k*st[i].b*t1)/100.0))+(st[i].a)*t2;
if(x1>x2)
st[i].sum=x1;
else
st[i].sum=x2;
}
for(int i=1;i<=n;i++)
{
	for(int j=1;j<=n-i;j++)
	{
		if((st[j].sum)>(st[j+1].sum))
		{
		d=st[j];
		st[j]=st[j+1];
		st[j+1]=d;
		}
		if((st[j].sum==st[j+1].sum)&&(st[j].f<st[j+1].f))
		{
//		printf("asfs\n");
		d=st[j];
		st[j]=st[j+1];
		st[j+1]=d;
		}

	}
}
for(int i=n;i>=1;i--){
printf("%d% .2lf\n",st[i].f,st[i].sum);
}
//cout<<"i="<<i<<"\t"<<st[i].a<<"\t"<<st[i].b<<"\t sum="<<setprecision(4)<<st[i].sum<<endl;

}


#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <climits>
#include <vector>
#include <functional>

using namespace std;

typedef long long Int;

int main() {

    Int n, t1, t2;
    double k;

    cin >> n >> t1 >> t2 >> k;
        k = (100-k)/100;

    vector< pair<Int,Int> > speeds;
        speeds.reserve(n+1);

    for( Int i=0; i < n; ++i ) {
        Int s1, s2;
        cin >> s1 >> s2;
        speeds.push_back( make_pair(s1,s2) );
    }
    vector< pair<Int,double> > scores;
    for( Int i=0; i < n; ++i ) {
        double score = max( speeds[i].first*t1+speeds[i].second*t2*k, speeds[i].first*t1*k+speeds[i].second*t2 );
        scores.push_back( make_pair(i+1, score) );
    }

    stable_sort( begin(scores), end(scores), []( const pair<Int,double> &s1, const pair<Int,double> &s2) {
        return s1.second > s2.second;
    } );

    for_each( begin(scores), end(scores), []( const pair<Int,double> &score ) {
        cout << score.first << ' ' << fixed << setprecision(2) << score.second << endl;
    } );

    return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <climits>
#include <vector>
#include <functional>

using namespace std;

typedef long long Int;

int main() {

    Int n, t1, t2;
    double k;

    cin >> n >> t1 >> t2 >> k;
        k = (100-k)/100;

    vector< pair<Int,Int> > speeds;
        speeds.reserve(n+1);

    for( Int i=0; i < n; ++i ) {
        Int s1, s2;
        cin >> s1 >> s2;
        speeds.push_back( make_pair(s1,s2) );
    }
    vector< pair<Int,double> > scores;
    for( Int i=0; i < n; ++i ) {
        double score = max( k * speeds[i].first  * t1 + speeds[i].second * t2,
                            k * speeds[i].second * t1 + speeds[i].first  * t2 );

        scores.push_back( make_pair(i+1, score) );
    }

    stable_sort( begin(scores), end(scores), []( const pair<Int,double> &s1, const pair<Int,double> &s2) {
        return s1.second > s2.second;
    } );

    for_each( begin(scores), end(scores), []( const pair<Int,double> &score ) {
        cout << score.first << ' ' << fixed << setprecision(2) << score.second << endl;
    } );

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

int main() {
    //freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    int n, t1, t2, k;
    while (cin >> n >> t1 >> t2 >> k) {
        vector< pair<double,int> > p(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            double g1 = a * t1 - a * t1 * k / 100.0 + t2 * b;
            double g2 = b * t1 -  b * t1 * k / 100.0 + t2 * a;
            double s1 = max(g1, g2);
            p[i] = {s1, i + 1};
        }

        sort(p.begin(), p.end(), [](const pair<double, int>& a,const pair<double, int>&b)-> bool {
            return a.first - b.first >= 0.01;
        });
        cout.precision(2);
        for (int i = 0; i < n; i++) {
            cout << p[i].second << " ";
            cout << fixed << p[i].first << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

int main() {
    //freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    int n, t1, t2, k;
    while (cin >> n >> t1 >> t2 >> k) {
        vector< pair<double,int> > p(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            double g1 = a * t1 - a * t1 * k / 100.0 + t2 * b;
            double g2 = b * t1 -  b * t1 * k / 100.0 + t2 * a;
            double s1 = max(g1, g2);
            p[i] = {s1, i + 1};
        }

        sort(p.begin(), p.end(), [](const pair<double, int>& a,const pair<double, int>&b)-> bool {
            if (a.first - b.first <= 0.001) {
                return a.second < b.second;
            }
            return a.first > b.first;
        });
        cout.precision(2);
        for (int i = 0; i < n; i++) {
            cout << p[i].second << " ";
            cout << fixed << p[i].first << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

int main() {
   // freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    int n, t1, t2, k;
    while (cin >> n >> t1 >> t2 >> k) {
        vector< pair<double,int> > p(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            double g1 = a * t1 - a * t1 * k / 100.0 + t2 * b;
            double g2 = b * t1 -  b * t1 * k / 100.0 + t2 * a;
            double s1 = max(g1, g2);
            p[i] = {s1, i + 1};
        }

        sort(p.begin(), p.end(), greater< pair<double,int> >());
        cout.precision(2);
        for (int i = 0; i < n; i++) {
            cout << p[i].second << " ";
            cout << fixed << p[i].first << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

int main() {
    //freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    int n, t1, t2, k;
    while (cin >> n >> t1 >> t2 >> k) {
        vector< pair<double,int> > p(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            double g1 = a * t1 - a * t1 * k / 100.0 + t2 * b;
            double g2 = b * t1 -  b * t1 * k / 100.0 + t2 * a;
            double s1 = max(g1, g2);
            p[i] = {s1, i + 1};
        }

        sort(p.begin(), p.end(), [](const pair<double, int>& a,const pair<double, int>&b)-> bool {
            if (a.first - b.first <= 0.001) {
                return a.second < b.second;
            }
            return true;
        });
        cout.precision(2);
        for (int i = 0; i < n; i++) {
            cout << p[i].second << " ";
            cout << fixed << p[i].first << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

int main() {
    //freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    int n, t1, t2, k;
    while (cin >> n >> t1 >> t2 >> k) {
        vector< pair<double,int> > p(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            double g1 = a * t1 - a * t1 * k / 100.0 + t2 * b;
            double g2 = b * t1 -  b * t1 * k / 100.0 + t2 * a;
            double s1 = max(g1, g2);
            p[i] = {s1, i + 1};
        }

        sort(p.begin(), p.end(), [](const pair<double, int>& a,const pair<double, int>&b)-> bool {
            return a.first - b.first > 0.01;
        });
        cout.precision(2);
        for (int i = 0; i < n; i++) {
            cout << p[i].second << " ";
            cout << fixed << p[i].first << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

int main() {
    //freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    int n, t1, t2, k;
    while (cin >> n >> t1 >> t2 >> k) {
        vector< pair<double,int> > p(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            double g1 = a * t1 - a * t1 * k / 100.0 + t2 * b;
            double g2 = b * t1 -  b * t1 * k / 100.0 + t2 * a;
            double s1 = max(g1, g2);
            p[i] = {s1, i + 1};
        }

        sort(p.begin(), p.end(), [](const pair<double, int>& a,const pair<double, int>&b)-> bool {
            return a.first - b.first > 0.001;
        });
        cout.precision(2);
        for (int i = 0; i < n; i++) {
            cout << p[i].second << " ";
            cout << fixed << p[i].first << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

int main() {
    //freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    int n, t1, t2, k;
    while (cin >> n >> t1 >> t2 >> k) {
        vector< pair<double,int> > p(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            double g1 = a * t1 - a * t1 * k / 100.0 + t2 * b;
            double g2 = b * t1 -  b * t1 * k / 100.0 + t2 * a;
            double s1 = max(g1, g2);
            p[i] = {-s1, i + 1};
        }

        sort(p.begin(), p.end());
        cout.precision(2);
        for (int i = 0; i < n; i++) {
            cout << p[i].second << " ";
            cout << fixed << -p[i].first << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

int main() {
    //freopen("test.in", "r", stdin); freopen("test.out", "w", stdout);
    ios::sync_with_stdio(0);
    int n, t1, t2, k;
    while (cin >> n >> t1 >> t2 >> k) {
        vector< pair<double,int> > p(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            double g1 = a * t1 - a * t1 * k / 100.0 + t2 * b;
            double g2 = b * t1 -  b * t1 * k / 100.0 + t2 * a;
            double s1 = max(g1, g2);
            p[i] = {s1, i + 1};
        }

        sort(p.begin(), p.end(), [](const pair<double, int>& a,const pair<double, int>&b)-> bool {
            return a.first > b.first;
        });
        cout.precision(2);
        for (int i = 0; i < n; i++) {
            cout << p[i].second << " ";
            cout << fixed << p[i].first << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAXN=2050;
const ll INF=1e18;

ll n,k,l[MAXN],r[MAXN],a[MAXN],f[MAXN];

int main(){
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n+5;i++){
		f[i]=INF;
	}
	for(ll i=1;i<=n;i++){
		scanf("%lld%lld%lld",l+i,r+i,a+i);
	}

	for(ll i=1;i<=n;i++){
		ll now=k,time,ans=f[i];
		for(ll j=i;j<=n;j++){
			time=(max(0ll,a[j]-now)+k-1)/k;
			if(time>r[j]-l[j]) break;
			ans+=a[j];
			now=(now+time*k)-a[j];
			if(j+1<=n){
				if(l[j]+time<l[j+1]){
					f[j+1]=min(f[j+1],ans+now);
				}
			}
			else{
				f[j+1]=min(f[j+1],ans);
			}
		}
	}
	if(f[n+1]==INF){
		printf("-1");
	}
	else{
		printf("%lld",f[n+1]);
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAXN=2050;
const ll INF=1e18;

ll n,k,l[MAXN],r[MAXN],a[MAXN],f[MAXN];

int main(){
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n+5;i++){
		f[i]=INF;
	}
	for(ll i=1;i<=n;i++){
		scanf("%lld%lld%lld",l+i,r+i,a+i);
	}

	f[1]=0;
	for(ll i=1;i<=n;i++){
		ll now=k,time,ans=f[i];
		for(ll j=i;j<=n;j++){
			time=(max(0ll,a[j]-now)+k-1)/k;
			if(time>r[j]-l[j]) break;
			ans+=a[j];
			now=(now+time*k)-a[j];
			if(j+1<=n){
				if(l[j]+time<l[j+1]){
					f[j+1]=min(f[j+1],ans+now);
				}
			}
			else{
				f[j+1]=min(f[j+1],ans);
			}
		}
	}
	if(f[n+1]==INF){
		printf("-1");
	}
	else{
		printf("%lld",f[n+1]);
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAXN=2050;
const ll INF=1e18;

ll n,k,l[MAXN],r[MAXN],a[MAXN],f[MAXN];

int main(){
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n+5;i++){
		f[i]=INF;
	}
	for(ll i=1;i<=n;i++){
		scanf("%lld%lld%lld",l+i,r+i,a+i);
	}

	for(ll i=1;i<=n;i++){
		ll now=k,time,ans=f[i];
		for(ll j=i;j<=n;j++){
			time=(max(0,a[j]-m)+k-1)/k;
			if(time>r[j]-l[j]) break;
			ans+=a[j];
			now=(now+(time-1)*k)-a[j];
			if(j+1<=n){
				if(l[j]+time<l[j+1]){
					f[j+1]=min(f[j+1],ans+now);
				}
			}
			else{
				f[j+1]=min(f[j+1],ans);
			}
		}
	}
	if(f[n+1]==INF){
		printf("-1");
	}
	else{
		printf("%lld",f[n+1]);
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAXN=2050;
const ll INF=1e18;

ll n,k,l[MAXN],r[MAXN],a[MAXN],f[MAXN];

int main(){
	scanf("%lld%lld",&n,&k);
	for(ll i=1;i<=n+5;i++){
		f[i]=INF;
	}
	for(ll i=1;i<=n;i++){
		scanf("%lld%lld%lld",l+i,r+i,a+i);
	}

	for(ll i=1;i<=n;i++){
		ll now=k,time,ans=f[i];
		for(ll j=i;j<=n;j++){
			time=(max(0ll,a[j]-now)+k-1)/k;
			if(time>r[j]-l[j]) break;
			ans+=a[j];
			now=(now+(time-1)*k)-a[j];
			if(j+1<=n){
				if(l[j]+time<l[j+1]){
					f[j+1]=min(f[j+1],ans+now);
				}
			}
			else{
				f[j+1]=min(f[j+1],ans);
			}
		}
	}
	if(f[n+1]==INF){
		printf("-1");
	}
	else{
		printf("%lld",f[n+1]);
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> p;

struct wave{
    int l;
    int r;
    int a;
};

typedef struct wave wave;

int main(){
    int n, k;
    cin >> n >> k;
    vector<wave> w(n);
    for(int i = 0;i < n; i++){
        cin >> w[i].l >> w[i].r >> w[i].a;
    }

    vector<ll> dp(n+1, LLONG_MAX);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        if(dp[i] != LLONG_MAX){
            ll bullets = k, used = dp[i];
            bool possible = true;
            for(int j = i; j < n; j++){
                ll reloads = (max(0LL, w[j].a - bullets) + k-1)/k;
                if(reloads > w[j].r - w[j].l){
                    possible = false;
                    break;
                }
                bullets = reloads * k + bullets - w[j].a;
                used += w[j].a;
                if(j + 1 < n){
                    if (w[j].l + reloads < w[j+1].l){ // can finish off before the new one starts
                        dp[j+1] = min(dp[j+1], bullets + used);
                    }
                }
            }
            if(possible){
                dp[n] = min(dp[n], used);
            }
        }
    }
    if (dp[n] == LLONG_MAX) cout << "-1" << endl;
    else cout << dp[n] << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
int l[maxn],r[maxn],a[maxn],n,k;
long long f[maxn];
int main() {
	scanf("%d%d",&n,&k);
	long long ans=0,cnt=0;
	for(int i=1;i<=n;i++) {
		scanf("%d%d%d",l+i,r+i,a+i);
		ans+=a[i];
	}
	for(int i=n;i>=1;i--) {
		long long nd=a[i]+(r[i]==l[i+1]?f[i+1]:0);
		if((r[i]-l[i]+1)*k<nd)return puts("-1"),0;
		f[i]=max(0,nd-(r[i]-l[i])*k);
	}
	for(int i=1;i<=n;i++) {
		if(cnt<f[i])ans+=cnt,cnt=k;
		cnt=(((cnt-a[i])%k)+k)%k;
	}
	printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
int l[maxn],r[maxn],a[maxn],n,k;
long long f[maxn];
int main() {
	scanf("%d%d",&n,&k);
	long long ans=0,cnt=0;
	for(int i=1;i<=n;i++) {
		scanf("%d%d%d",l+i,r+i,a+i);
		ans+=a[i];
	}
	for(int i=n;i>=1;i--) {
		long long nd=a[i]+(r[i]==l[i+1]?f[i+1]:0);
		if(1ll*(r[i]-l[i]+1)*k<nd)return puts("-1"),0;
		f[i]=max(0ll,nd-1ll*(r[i]-l[i])*k);
	}
	for(int i=1;i<=n;i++) {
		if(cnt<f[i])ans+=cnt,cnt=k;
		cnt=(((cnt-a[i])%k)+k)%k;
	}
	printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
int l[maxn],r[maxn],a[maxn],n,k;
long long f[maxn];
int main() {
	scanf("%d%d",&n,&k);
	long long ans=0,cnt=0;
	for(int i=1;i<=n;i++) {
		scanf("%d%d%d",l+i,r+i,a+i);
		ans+=a[i];
	}
	for(int i=n;i>=1;i--) {
		int nd=a[i]+(r[i]==l[i+1]?f[i+1]:0);
		if((r[i]-l[i]+1)*k<nd)return puts("-1"),0;
		f[i]=max(0,nd-(r[i]-l[i])*k);
	}
	for(int i=1;i<=n;i++) {
		if(cnt<f[i])ans+=cnt,cnt=k;
		cnt=(((cnt-a[i])%k)+k)%k;
	}
	printf("%lld\n",ans);
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 2e3 + 10;
int l[N], r[N], a[N];
const ll inf = 1e18;

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> l[i] >> r[i] >> a[i];
	}

	vector<ll> f(n+1, inf);
	f[0] = 0;
	for (int i = 0; i < n; i++) {
		ll now = k;
		ll ans = f[i];
		for (int j = i; j < n; j++) {
		    // �����굱ǰ�������������������ĵ�ʱ��
			int time = (max(0LL, a[j] - now) + k - 1) / k;
			if (time > r[j]-l[j]) break;

			ll newNow = (now + k*time) - a[j];
			ans += a[j];

			if (j+1 < n) {
				// ����������1��ʱ����л���
				if (l[j] + time < l[j+1])
					f[j+1] = min(f[j+1], ans + newNow);
			} else {
				f[j+1] = min(f[j+1], ans);
			}

			now = newNow;
		}
	}

	if (f[n] == inf) {
		cout << -1;
	} else {
		cout << f[n] << endl;
	}
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

const ll mod = 1e9 + 7;
const ll N = 2005;
const ll inf = 1e18;

ll n, k;
ll l[N], r[N], a[N];
unordered_map<ii, ll> dp;

ll rec(ll pos, ll rem){
	if(pos == n)
		return 0;

	ll tmp = a[pos] - (r[pos] - l[pos]) * k - rem;

	if(tmp > 0)
		return inf;
	if(dp.find({pos, rem}) != dp.end())
		return dp[{pos, rem}];
	tmp = a[pos] - rem;

	ll m = (tmp + k - 1) / k;
	ll new_rem = m * k - tmp;

	ll ans = rec(pos + 1, new_rem);

	if(m < (l[pos + 1] - l[pos]))
		ans = min(ans, new_rem + rec(pos+1, k));

	if(ans >= inf) ans = inf;

	return dp[{pos, rem}] = ans;
}

void solve()
{
	cin>>n>>k;
	dp.clear();
	rep(i, n)
		cin>>l[i]>>r[i]>>a[i];
	ll val = 0;
	rep(i, n)
		val += a[i];
	cout<<(rec(0, k) >= inf ? -1 : rec(0, k)+val)<<endl;
}

// #define _DEBUG
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	while(tc--)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		solve();

#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef int ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

const ll mod = 1e9 + 7;
const ll N = 2005;
const ll inf = 2e9;

int n, k;
int l[N], r[N], a[N];
map<ii, ll> dp;

ll rec(ll pos, ll rem){
	if(pos == n)
		return 0;

	ll tmp = a[pos] - (r[pos] - l[pos]) * 1ll * k - rem;

	if(tmp > 0)
		return inf;
	if(dp.find({pos, rem}) != dp.end())
		return dp[{pos, rem}];
	tmp = a[pos] - rem;

	ll m = (tmp + k - 1) / k;
	ll new_rem = m * k - tmp;

	ll ans = rec(pos + 1, new_rem);

	if(m < (l[pos + 1] - l[pos]))
		ans = min(ans, new_rem + rec(pos+1, k));

	if(ans >= inf) ans = inf;

	return dp[{pos, rem}] = ans;
}

void solve()
{
	cin>>n>>k;
	dp.clear();
	rep(i, n)
		cin>>l[i]>>r[i]>>a[i];
	ll val = 0;
	rep(i, n)
		val += a[i];
	cout<<(rec(0, k) >= inf ? -1 : rec(0, k)+val)<<endl;
}

// #define _DEBUG
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	while(tc--)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		solve();

#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

const ll mod = 1e9 + 7;
const ll N = 2005;
const ll inf = 4e17;

int n, k;
int l[N], r[N], a[N];
unordered_map<ll, ll> dp[N];

ll rec(ll pos, ll rem){
	if(pos == n)
		return 0;

	ll tmp = a[pos] - (r[pos] - l[pos]) * 1ll * k - rem;

	if(tmp > 0)
		return inf;
	if(dp[pos].count(rem))
		return dp[pos][rem];
	tmp = a[pos] - rem;

	ll m = (tmp + k - 1) / k;
	ll new_rem = m * k - tmp;

	ll ans = rec(pos + 1, new_rem);

	if(m < (l[pos + 1] - l[pos]))
		ans = min(ans, new_rem + rec(pos+1, k));

	if(ans >= inf) ans = inf;

	return dp[pos][rem] = ans;
}

void solve()
{
	cin>>n>>k;
	// dp.clear();
	rep(i, n)
		cin>>l[i]>>r[i]>>a[i];
	ll val = 0;
	rep(i, n)
		val += a[i];
	cout<<(rec(0, k) >= inf ? -1 : rec(0, k)+val)<<endl;
}

// #define _DEBUG
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	while(tc--)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		solve();

#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef int ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

const ll mod = 1e9 + 7;
const ll N = 2005;
const ll inf = 4e9;

int n, k;
int l[N], r[N], a[N];
map<ii, ll> dp;

ll rec(ll pos, ll rem){
	if(pos == n)
		return 0;

	ll tmp = a[pos] - (r[pos] - l[pos]) * 1ll * k - rem;

	if(tmp > 0)
		return inf;
	if(dp.find({pos, rem}) != dp.end())
		return dp[{pos, rem}];
	tmp = a[pos] - rem;

	ll m = (tmp + k - 1) / k;
	ll new_rem = m * k - tmp;

	ll ans = rec(pos + 1, new_rem);

	if(m < (l[pos + 1] - l[pos]))
		ans = min(ans, new_rem + rec(pos+1, k));

	if(ans >= inf) ans = inf;

	return dp[{pos, rem}] = ans;
}

void solve()
{
	cin>>n>>k;
	dp.clear();
	rep(i, n)
		cin>>l[i]>>r[i]>>a[i];
	ll val = 0;
	rep(i, n)
		val += a[i];
	cout<<(rec(0, k) >= inf ? -1 : rec(0, k)+val)<<endl;
}

// #define _DEBUG
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	while(tc--)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		solve();

#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}


#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << ", ";
	err(++it, args...);
	cout<<"\n";
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

const ll mod = 1e9 + 7;
const ll N = 2005;
const ll inf = 1e18;

ll n, k;
ll l[N], r[N], a[N];
map<ii, ll> dp;

ll rec(ll pos, ll rem){
	if(pos == n)
		return 0;

	ll tmp = a[pos] - (r[pos] - l[pos]) * k - rem;

	if(tmp > 0)
		return inf;
	if(dp.find({pos, rem}) != dp.end())
		return dp[{pos, rem}];
	tmp = a[pos] - rem;

	ll m = (tmp + k - 1) / k;
	ll new_rem = m * k - tmp;

	ll ans = rec(pos + 1, new_rem);

	if(m < (l[pos + 1] - l[pos]))
		ans = min(ans, new_rem + rec(pos+1, k));

	if(ans >= inf) ans = inf;

	return dp[{pos, rem}] = ans;
}

void solve()
{
	cin>>n>>k;
	dp.clear();
	rep(i, n)
		cin>>l[i]>>r[i]>>a[i];
	ll val = 0;
	rep(i, n)
		val += a[i];
	cout<<(rec(0, k) >= inf ? -1 : rec(0, k)+val)<<endl;
}

// #define _DEBUG
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	while(tc--)
	{
#ifdef _DEBUG
	int tt = clock();
#endif
		solve();

#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define int long long
#define maxn (2020)
#define inf (10000000000000ll)
int l[maxn], r[maxn], a[maxn], d[maxn];
signed main()
{
	ios::sync_with_stdio(false);

	int n, k; cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> l[i] >> r[i] >> a[i];
	}
	for(int i = 1; i <= n; i++) d[i] = inf;
	int ok = 1;
	for(int i = n; i >= 1; i--) {
		int total = (r[i] - l[i] + 1) * k;
		if(total < a[i]) {ok = 0; break;}
		int remain = (total - a[i]) % k;
		int reload = (int)(total - a[i] >= k || l[i + 1] - r[i] > 0);
		int sum = a[i], over = 1;
		for(int j = i + 1; j <= n; j++) {
			if(reload) d[i] = min(d[i], sum + remain + d[j]);
			int total = remain + (r[j] - l[j]) * k;
			if(total < a[j]) {over = 0; break;}
			remain = (total - a[j]) % k;
			reload = (int)(total - a[j] >= k || l[j + 1] - r[j] > 0);
			sum += a[j];
		}
		if(over) d[i] = min(d[i], sum);
// 		if(d[i] >= inf) {ok = 0; break;}
	}
	if(d[1] < inf)
		cout << d[1] << endl;
	else
		cout << -1 << endl;

	return 0;
}