A. Mocha and Math(codeforces#738(div2))

简介: A. Mocha and Math(codeforces#738(div2))

A. Mocha and Math


time limit per test


1 second


memory limit per test


256 megabytes


input


standard input


output


standard output


Mocha is a young girl from high school. She has learned so much interesting knowledge from her teachers, especially her math teacher. Recently, Mocha is learning about binary system and very interested in bitwise operation.


This day, Mocha got a sequence aa of length nn. In each operation, she can select an arbitrary interval [l,r][l,r] and for all values ii (0≤i≤r−l0≤i≤r−l), replace al+ial+i with al+i&ar−ial+i&ar−i at the same time, where && denotes the bitwise AND operation. This operation can be performed any number of times.


For example, if n=5n=5, the array is [a1,a2,a3,a4,a5][a1,a2,a3,a4,a5], and Mocha selects the interval [2,5][2,5], then the new array is [a1,a2&a5,a3&a4,a4&a3,a5&a2][a1,a2&a5,a3&a4,a4&a3,a5&a2].


Now Mocha wants to minimize the maximum value in the sequence. As her best friend, can you help her to get the answer?


Input


Each test contains multiple test cases.


The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. Each test case consists of two lines.


The first line of each test case contains a single integer nn (1≤n≤1001≤n≤100) — the length of the sequence.


The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109).


Output


For each test case, print one integer — the minimal value of the maximum value in the sequence.


Example


input

Copy

4

2

1 2

3

1 1 3

4

3 11 3 7

5

11 7 15 3 7


output

Copy

0

1

3

3


Note


In the first test case, Mocha can choose the interval [1,2][1,2], then the sequence becomes [0,0][0,0], where the first element is 1&21&2, and the second element is 2&12&1.


In the second test case, Mocha can choose the interval [1,3][1,3], then the sequence becomes [1,1,1][1,1,1], where the first element is 1&31&3, the second element is 1&11&1, and the third element is 3&13&1.


题意分析,就是全部&;

 

#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
typedef long long ll;
int a[maxn],b[maxn];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        int ans=a[0];
        for(int i=0;i<n;i++)
            ans&=a[i];
        printf("%d\n",ans);
    }
    return 0;
}
相关文章
|
Ubuntu Apache 安全
|
2天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8077 2
|
11天前
|
域名解析 人工智能 Linux
|
19天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
10265 13
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
5天前
|
人工智能 安全 网络安全
|
10天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1547 5
|
9天前
|
云安全 数据采集 人工智能
|
16天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2697 8