CF 1107D
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
int n;
cin>>n;
vector<vector<int>>a(n+1,vector<int>(n+1));
string s;
auto parse_char=[&](int x,int y,char c){
int num;
if(isdigit(c)){
num=c-'0';
}else{
num=c-'A'+10;
}
for(int j=1;j<=4;++j){
a[x][y+4-j]=num&1;
num>>=1;
}
};
for(int i=1;i<=n;++i){
cin>>s;
for(int j=0;j<n/4;++j){
parse_char(i,j*4+1,s[j]);
}
}
int g=n;
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
int k=j;
while(k<=n&&a[i][j]==a[i][k])++k;
g=gcd(g,k-j);
j=k-1;
}
}
for(int j=1;j<=n;++j){
for(int i=1;i<=n;++i){
int k=i;
while(k<=n&&a[i][j]==a[k][j])++k;
g=gcd(g,k-i);
i=k-1;
}
}
cout<<g<<'\n';
}
CF 1119E
#define int long long
signed main(){
int n;
cin>>n;
vector<int>a(n+2);
for(int i=1;i<=n;++i)cin>>a[i];
int cur=1;
int ans=0;
for(int i=1;i<=n;++i){
ans+=(a[i]/3);
a[i]%=3;
if(cur<=i)cur=i+1;
while(cur<=n&&a[cur]<2)++cur;
if(a[i]>=1&&a[cur]>=2){
ans++;
a[cur]-=2;
a[i]--;
}
while(cur<=n&&a[cur]<2)++cur;
if(a[i]>=1&&a[cur]>=2){
ans++;
a[cur]-=2;
a[i]--;
}
}
cout<<ans<<'\n';
}