H - Happy Birthday

You have a set of birthday cake candles. Each of such candles represents a digit between 00 and 99, inclusive.

 Example of birthday cake candles.

Let's denote the candle representing the digit dd as dd-candle.

Your set contains c0c0 instances of 00-candles, c1c1 instances of 11-candles and so on. So, the total number of candles is c0+c1+⋯+c9c0+c1+⋯+c9.

These digits are needed to wish your cat a happy birthday. For each birthday, starting with the first, you want to compose the age of the cat using the digits from the set.

Since you light candles for a very short time, candles don't have time to burn out. For this reason you can reuse candles an arbitrary number of times (therefore your set of candles never changes).

For example, if you have one instance of each digit (i.e. c0=c1=⋯=c9=1c0=c1=⋯=c9=1), you can compose any number from 11 to 1010 using this set, but you cannot compose 1111.

You have to determine the first birthday, on which you cannot compose the age of the cat using the candles from your set. In other words, find the minimum number yy such that all numbers from 11 to y−1y−1 can be composed by digits from your set, but yy cannot be composed.

Input

The first line contains an integer tt (1≤t≤1041≤t≤104) — the number of test cases in the input.

The only line of each test case contains ten integer numbers c0,c1,…,c9c0,c1,…,c9 (0≤ci≤1050≤ci≤105) — the number of 00-candles, 11-candles, 22-candles and so on.

It is guaranteed that the sum of all cici in the input does not exceed 106106.

Output

For each test case, output one integer in single line — the minimum age which cannot be composed by candles from your set. Please note that the age can be quite large (it may exceed the standard 64-bit integer types in your programming language).

Example

Input

4
1 1 1 1 1 1 1 1 1 1
0 0 1 1 2 2 3 3 4 4
1 2 1 2 1 3 1 0 0 0
0 1 2 1 4 3 1 1 2 1

Output

11
1
7
10

这一题主要没有AC的原因是自己没有看懂题意,我当时很憨憨我以为题意是相加,但是这一道题的意思是这几个数字的组成,这几个数字能组成哪些数字 暂时先不考虑0  考虑其他的数字,如果数字7的数量是3个 其余的数字数量都比7大,那么这些数字中组不成最小的数字应该是7777,然后再继续往下想那么如果要考虑到0呢??你会发现这一题的隐藏输入的条件就是不能输出单个0,比如现在0和1这两个数字的数量都是最小的都是2个,那么最小的应该是111而不是1000因此当0的数量>=除了0之外所有数字的数量的最小值时,输出最小数字。反之先输出一个1再输出0.具体代码如下

#include<bits/stdc++.h>
using namespace std;
long long a[99];
int main()
{
	long long t;
	cin>>t;
	while(t--)
	{
		memset(a,0,sizeof(a));
		long long k=0;
		long long min=10000000;
		for(long long i=0;i<10;i++)
		{
			cin>>a[i];
		}
		for(long long i=1;i<10;i++)
		{
			if(min>a[i])
			{
				min=a[i];
				k=i;
			}
		}
		if(a[0]>=min)
		{
			for(long long i=0;i<=min;i++)
			{
				cout<<k;
			}
			cout<<endl;
		}
		else
		{
			cout<<1;
			for(long long i=0;i<=a[0];i++)
			{
				cout<<0;
		}
		cout<<endl;
		}
	}
	return 0;
 } 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值