jiahuimbzuai/CoQuIR huggingface dataset:
//  [c]
#include <stdio.h>

inline static int read_int() {
    int x = 0, k;
    while ((k = getchar_unlocked() - '0') >= 0) x = x * 10 + k;
    return x;
}

inline static void put_int(int x) {
    int s = 0;
    char f[4] = {'0', '0', '0', '0'};
    while (x) {
        f[s++] += x % 10;
        x /= 10;
    }

    while (s--) putchar_unlocked(f[s]);
    putchar_unlocked('\n');
}

short highest[2000], streak[2000];

#pragma GCC optimize ("O3")
int main() {
    int h = read_int(), w = read_int(), max = 0, height, width, lastWall, tmp, len;

    for (height = 0; height < h; height++) {
        lastWall = -1;

        for (width = 0; width < w; width++) {
            if (getchar_unlocked() & 1) {
                if (lastWall != width - 1) {
                    len = width - lastWall - 1;
                    for (tmp = lastWall + 1; tmp < width; tmp++) if (len > highest[tmp]) highest[tmp] = len;
                }

                tmp = highest[width] + streak[width];
                if (tmp > max) max = tmp;

                highest[width] = streak[width] = 0;
                lastWall = width;
            } else streak[width]++;
        }

        getchar_unlocked();

        if (++lastWall != width) for (len = width - lastWall; lastWall < width; lastWall++) if (len > highest[lastWall]) highest[lastWall] = len;
    }

    for (width = 0; width < w; width++) {
        if (streak[width] != 0) {
            tmp = highest[width] + streak[width];
            if (tmp > max) max = tmp;
        }
    }

    put_int(max - 1);
}
//  [c]
#include <stdio.h>
#include <string.h>
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

typedef long long int int64;
typedef unsigned char uchar8;

#define MAX_W 2000
#define MAX_H 2000

uchar8 S[MAX_H][MAX_W];

int spW[MAX_H];
int spH[MAX_W];

int H = 0;
int W = 0;

int sp_N(int w, int h) {
  int cnt_sp = 0;
  int x,y;
  static int cache_spN[MAX_H][MAX_W] = {0,};

  x = w;

  if ((h > 0) &&
      (cache_spN[h-1][w] > 0)) {
    if (S[h][w] != 1) {
      cache_spN[h][w] = cache_spN[h-1][w] + 1;
      return cache_spN[h][w];
    }
  }
  
  for (y=h; y>=0; y--) {
    if (S[y][x] == 1) {
      break;
    }
    cnt_sp++;
  }

  cache_spN[h][w] = cnt_sp;
  
  return cnt_sp;
}

int sp_S(int w, int h) {
  int cnt_sp = 0;
  int x,y;
  static int cache_spS[MAX_H][MAX_W] = {0,};

  x = w;

  if ((h < (H - 1)) &&
      (cache_spS[h + 1][w] > 0)) {
    if (cache_spS[h][w] != 1) {
      cache_spS[h][w] = cache_spS[h + 1][w] + 1;
    }
  }
  
  for (y=h; y<H; y++) {
    if (S[y][x] == 1) {
      break;
    }
    cnt_sp++;
  }
  cache_spS[h][w] + cnt_sp;
    
  return cnt_sp;
}

int sp_W(int w, int h) {
  int cnt_sp = 0;
  int x,y;
  static int cache_spW[MAX_H][MAX_W] = {0,};

  y = h;

  if ((w > 0) &&
      (cache_spW[h][w - 1] > 0)) {
    if (S[h][w] != 1) {
      cache_spW[h][w] = cache_spW[h][w - 1] + 1;
      return cache_spW[h][w];
    }
  }
  
  for (x=w; x>=0; x--) {
    if (S[y][x] == 1) {
      break;
    }
    cnt_sp++;
  }

  cache_spW[h][w] = cnt_sp;
  
  return cnt_sp;
}

int sp_E(int w, int h) {
  int cnt_sp = 0;
  int x,y;

  y = h;
  for (x=w; x<W; x++) {
    if (S[y][x] == 1) {
      break;
    }
    cnt_sp++;
  }
  
  return cnt_sp;
}

int main()
{

  int cnt;
  int i,j;
  int cnt_sp;
  int max_sp = 0;
  char str[MAX_W];
 

  cnt = scanf("%d %d", &H, &W);

  for (i=0; i<H; i++) {
   cnt = scanf("%s", (char *)(str));
    str[W]= 0x1;
    for(j=0; j<W; j++) {
      if(str[j] == '#') {
        S[i][j] = 1;
      } else {
        S[i][j] = 0;
      }
    }
  }

  for (i=0; i<H; i++) {
    for (j=0; j<W; j++) {
      if (S[i][j] != 0) continue;
      cnt_sp = 0;
      cnt_sp += sp_N(j,i);
      if (MAX(max_sp, (cnt_sp - 1 + W + (H-j))) == max_sp) continue;
      cnt_sp += sp_S(j,i);
      if (MAX(max_sp, (cnt_sp + W - 2)) == max_sp) continue;
      cnt_sp += sp_W(j,i);
//      if (MAX(max_sp, (cnt_sp - 2 + (W-i))) == max_sp) continue;
      cnt_sp += sp_E(j,i);
      cnt_sp -= 3;
      max_sp = MAX(max_sp, cnt_sp);
    }
  }

  printf(" %d", max_sp);
  
  return 0;
}
//  [c]
#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

void unite(int t[], int x, int y);
int root(int t[], int x);
int size(int t[], int x);

int row[2005][2005];
int col[2005][2005];
char mp[2005][2005];
int h, w;
int ans = 0;

int main()
{
    for (int i = 0; i < 2005; i++) {
        for (int j = 0; j < 2005; j++) {
            row[i][j] = col[i][j] = -1;
        }
    }
    
    scanf("%d %d", &h, &w);
    for (int i = 0; i < h; i++) {
        scanf("%s", mp[i]);
    }

    // row
    for (int i = 0; i < h; i++) {
        for (int j = 1; j < w; j++) {
            if (mp[i][j] == '.' && mp[i][j - 1] == '.') {
                unite(row[i], j, j - 1);
            }
        }
    }

    // col
    for (int j = 0; j < w; j++) {
        for (int i = 1; i < h; i++) {
            if (mp[i][j] == '.' && mp[i - 1][j] == '.') {
                unite(col[j], i, i - 1);
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ans = max(ans, size(col[j], i) + size(row[i], j) - 1);
        }
    }
    printf("%d\n", ans);

    return 0;
}

void unite(int t[], int x, int y)
{
    x = root(t, x);
    y = root(t, y);

    if (x == y) {
        return;
    }

    t[x] += t[y];
    t[y] = x;

    return;
}
    
int root(int t[], int x)
{
    if (t[x] < 0) {
        return x;
    }
    return t[x] = root(t, t[x]);
}

int size(int t[], int x)
{
    x = root(t, x);
    return -t[x];
}
//  [c]
#include <stdio.h>

#define H_MAX 2000
#define W_MAX 2000

int main(void){
	int i, j, k;

	int h, w;
	scanf("%d%d", &h, &w);

	char sym;
	int board[H_MAX][W_MAX] = {};
	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			scanf(" %c", &sym);
			if(sym == '#') board[i][j] = 1;
		}
	}

	int board_value[H_MAX][W_MAX] = {}, cnt;
	for(i = 0; i < h; i++){
		cnt = 0;
		for(j = 0; j < w; j++){
			if(board[i][j] == 0){
				board_value[i][j] += cnt++;
			}else{
				cnt = 0;
			}
		}
	}
	for(i = 0; i < h; i++){
		cnt = 0;
		for(j = w-1; j >= 0; j--){
			if(board[i][j] == 0){
				board_value[i][j] += cnt++;
			}else{
				cnt = 0;
			}
		}
	}
	for(i = 0; i < w; i++){
		cnt = 0;
		for(j = 0; j < h; j++){
			if(board[j][i] == 0){
				board_value[j][i] += cnt++;
			}else{
				cnt = 0;
			}
		}
	}
	for(i = 0; i < w; i++){
		cnt = 0;
		for(j = h-1; j >= 0; j--){
			if(board[j][i] == 0){
				board_value[j][i] += cnt++;
			}else{
				cnt = 0;
			}
		}
	}

	int max = 0;
	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			if(board_value[i][j]+1 > max) max = board_value[i][j]+1;
		}
	}

	printf("%d\n", max);

	return 0;
}
//  [javascript]
console.log((args=>{
  const [HW,...S] = args.trim().split`\n`;
  const [H,W] = HW.split` `.map(v=>v|0);
  const map = Array.from({length:H},_=>Array(W).fill(0));
  for ( let i = 0; i < H; i++ ) {
    let w = 0;
    for ( let j = 0; j <= W; j++ ) {
      if ( j === W || S[i][j] === '#' ) {
        for ( let k = j-w; k < j; k++ ) map[i][k] += w;
        w = 0;
      } else w++;
    }
  }
  let max = 0;
  for ( let i = 0; i < W; i++ ) {
    let h = 0, hmax = 0;
    for ( let j = 0; j <= H; j++ ) {
      if ( j === H || S[j][i] === '#' ) {
        if ( max < hmax + h ) max = hmax + h;
        h = 0; hmax = 0;
      } else {
        ++h;
        if ( hmax < map[j][i] ) hmax = map[j][i]
      }
    }
  }
  return `${max-1}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
//  [javascript]


function Main(input) {
  input = input.split("\n");
  var H = parseInt(input[0].split(" ")[0]);
  var W = parseInt(input[0].split(" ")[1]);
  input.shift();
  var S = input.map(i => i.split(""));
  S.splice(H,S.length-H);
  var dp1=new Array(H);
  var dp2=new Array(H);
  for(var i=0;i<H;i++){
    var tmp1=new Array(W).fill(1);
    var tmp2=new Array(W).fill(1);
    dp1[i]=tmp1;
    dp2[i]=tmp2;
  }
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      if(j==0){
        if(S[i][j]=="#"){
          dp1[i][j]=0;
        }
      }else{
        if(S[i][j]=="."){
          dp1[i][j]=dp1[i][j-1]+1;
        }else{
          dp1[i][j]=0;
        }
      }
    }
  }
  for(var i=0;i<H;i++){
    for(var j=W-2;j>=0;j--){
      if(S[i][j]=="."){
        if(dp1[i][j+1]!=0){
          dp1[i][j]=dp1[i][j+1];
        }
      }
    }
  }
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      if(i==0){
        if(S[i][j]=="#"){
          dp2[i][j]=0;
        }
      }else{
        if(S[i][j]=="."){
          dp2[i][j]=dp2[i-1][j]+1;
        }else{
          dp2[i][j]=0;
        }
      }
    }
  }
  for(var i=H-2;i>=0;i--){
    for(var j=0;j<W;j++){
      if(S[i][j]=="."){
        if(dp2[i+1][j]!=0){
          dp2[i][j]=dp2[i+1][j];
        }
      }
    }
  }
  var ans=0;
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      ans=Math.max(ans,dp1[i][j]+dp2[i][j]-1);
    }
  }
  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return r[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var i in r)e.d(n,i,function(t){return r[t]}.bind(null,i));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=0)}([function(r,t,e){"use strict";var n=e(1),i=new(e(2))(n.readFileSync("/dev/stdin","utf8").trim().split(/\s+/g));e(4)(i)},function(r,t){r.exports=require("fs")},function(r,t,e){"use strict";var n=e(3);r.exports=class{constructor(r){this.inp=new n(r)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}add(r){this.inp.enq(r)}}},function(r,t,e){"use strict";r.exports=class{constructor(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=r.length,this.items=r,this.ind=0}enq(r){this.size+=1,this.items.push(r)}deq(){var r=this.items[this.ind];return this.size-=1,this.ind+=1,r}}},function(r,t,e){"use strict";r.exports=function(r){for(var t=r.in(),e=r.in(),n=new Array(t),i=new Array(t),o=0;o<t;o++){var u=r.inr();n[o]=u,i[o]=new Array(e);for(var s=0;s<e;s++)i[o][s]={l:0,r:0,u:0,d:0},"#"!=n[o][s]&&(s>0&&(i[o][s].l=i[o][s-1].l),o>0&&(i[o][s].u=i[o-1][s].u),i[o][s].l++,i[o][s].u++)}for(var c=0,f=t-1;f>=0;f--)for(var l=e-1;l>=0;l--)if("#"!=n[f][l]){l<e-1&&(i[f][l].r=i[f][l+1].r),f<t-1&&(i[f][l].d=i[f+1][l].d),i[f][l].r++,i[f][l].d++;var a=i[f][l].l+i[f][l].r+i[f][l].u+i[f][l].d-3;c<a&&(c=a)}console.log(c)}}]);
//  [javascript]
'use strict'
function main(input) {
  input = input.trim().split('\n')
  const HW = input.shift().split(' ').map(v => Number(v))
  input = input.map(r => r.split(''))
  const newArray = new Array(HW[0]).fill(new Array(HW[1]).fill(0));
  const L = JSON.parse(JSON.stringify(newArray)) 
  const R = JSON.parse(JSON.stringify(newArray))
  const U = JSON.parse(JSON.stringify(newArray))
  const D = JSON.parse(JSON.stringify(newArray))
  let max = 0
  for (let h = 0; h < HW[0]; h++) {
    for (let w = 0; w < HW[1]; w++) {
      if (input[h][w] === '.') {
        L[h][w] = w === 0 ? 1 : L[h][w-1] + 1
        U[h][w] = h === 0 ? 1 : U[h-1][w] + 1
      }
    }
  }
  for (let h = HW[0] - 1; h >= 0; h--) {
    for (let w = HW[1] - 1; w >= 0; w--) {
      if (input[h][w] === '.') {
        R[h][w] = w === HW[1] - 1 ? 1 : R[h][w+1] + 1
        D[h][w] = h === HW[0] - 1 ? 1 : D[h+1][w] + 1

        const sum = L[h][w] + R[h][w]+ U[h][w] + D[h][w] - 3
        if (sum > max) max = sum
      }
    }
  }
  console.log(max)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [javascript]
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var H = one[0];
	var W = one[1];
	var list = new Array(H);
	var obj = new Array(H);
	for(var i = 0; i < H; i++){
		list[i] = nextCharArray();
		obj[i] = new Array(W);
		for(var j = 0; j < W; j++){
			obj[i][j] = {
				tate : 0,
				yoko : 0
			};
			if(list[i][j] == "."){
				if(j == 0){
					obj[i][j].yoko = 1;
				}else{
					obj[i][j].yoko += obj[i][j - 1].yoko + 1;
				}
			}
		}
	}
	for(var i = 0; i < W; i++){
		for(var j = 0; j < H; j++){
			if(list[j][i] == "."){
				if(j == 0){
					obj[j][i].tate = 1;
				}else{
					obj[j][i].tate += obj[j - 1][i].tate + 1;
				}
			}
		}
	}
	for(var i = H - 1; i >= 0; i--){
		for(var j = W - 1; j >= 0; j--){
			if(list[i][j] == "."){
				if(j != W - 1){
					obj[i][j].yoko = Math.max(obj[i][j].yoko, obj[i][j + 1].yoko);
				}
				if(i != H - 1){
					obj[i][j].tate = Math.max(obj[i][j].tate, obj[i + 1][j].tate);
				}
			}
		}
	}
	var output = 0;
	for(var i = 0; i < H; i++){
		for(var j = 0; j < W; j++){
			output = Math.max(output, obj[i][j].tate + obj[i][j].yoko - 1);
		}
	}
	myout(output);
}
//  [javascript]
'use strict'

const INF = 900719925474099;
function mapint(temp){
    return temp.split(' ').map((v)=>parseInt(v));
}
const MOD = 1000000007;

function Main(input){
    let temp = input.trim().split('\n');
    let h = mapint(temp[0])[0];
    let w = mapint(temp[0])[1];

    let m = new Array(h+2);
    m[0] = '#'.repeat(w+2);
    m[h+1] = '#'.repeat(w+2);
    for(let i=1;i<=h;i++){
        m[i]='#' + temp[i] + '#';
    }

    let yoko = [...new Array(h+2)].map(()=>new Array(w+2).fill(0));

    for(let i=1;i<=h;i++){
        for(let j=1;j<=w;j++){
            if(m[i][j]=='.') yoko[i][j] = yoko[i][j-1]+1;
        }
    }
    // for(let i=h;i>=1;i--){
    //     for(let j=w;j>=1;j--){
    //         if(m[i][j]=='.' && m[i][j+1] != '#') yoko[i][j] = yoko[i][j+1];
    //     }
    // }

    let tate = [...new Array(h+2)].map(()=>new Array(w+2).fill(0));
    for(let i=1;i<=w;i++){
        for(let j=1;j<=h;j++){
            if(m[j][i]=='.') tate[j][i] = tate[j-1][i]+1;
        }
    }
    // for(let i=w;i>=1;i--){
    //     for(let j=h;j>=1;j--){
    //         if(m[j][i]=='.' && m[j+1][i] != '#') tate[j][i] = tate[j+1][i];
    //     }
    // }
    //console.log(h,w,m,yoko,tate);

    let ans = 0;
    for(let i=h;i>=1;i--){
        for(let j=w;j>=1;j--){
            if(m[i][j]=='.' && m[i][j+1] != '#') yoko[i][j] = yoko[i][j+1];
            if(m[i][j]=='.' && m[i+1][j] != '#') tate[i][j] = tate[i+1][j];
            ans = Math.max(ans,yoko[i][j]+tate[i][j]-1);
        }
    }
    // for(let i=1;i<=h;i++){
    //     for(let j=1;j<=w;j++){
    //         ans = Math.max(ans,yoko[i][j]+tate[i][j]-1);
    //     }
    // }
    console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

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

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100000)}
  h,w := input.NextInts()
  var g [2002][2002]int
  for j:=0;j<w+2;j++ { g[0][j],g[h+1][j] = -1,-1 }
  for i:=1;i<h+1;i++ {
    s := input.NextLine()
    g[i][0],g[i][w+1] = -1,-1
    for j:=1;j<w+1;j++ {
      if s[j-1:j] == "#" { g[i][j] = -1 }
    }
  }
  for i:=1;i<h+1;i++ {
    l := 0
    for j:=1;j<w+2;j++ {
      if g[i][j] != -1 { continue }
      for k:=l+1;k<j;k++ { g[i][k] = j-l-1 }
      l = j
    }
  }
  for j:=1;j<w+1;j++ {
    u := 0
    for i:=1;i<h+2;i++ {
      if g[i][j] != -1 { continue }
      for k:=u+1;k<i;k++ { g[k][j] += i-u-2 }
      u = i
    }
  }
  m := -1
  for i:=1;i<h+1;i++ {
    for j:=1;j<w+1;j++ {
      if m < g[i][j] { m = g[i][j] }
    }
  }
  fmt.Println(m)
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInts() (int,int) {
  s := strings.Split(i.NextLine()," ")
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}
//  [go]
package main

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

func main() {
	var h, w int
	fmt.Scan(&h)
	fmt.Scan(&w)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	cStarts := make([]int, w)
	light := make([][]int, h)
	for i := 0; i < h; i++ {
		light[i] = make([]int, w)
	}

	for i := 0; i < h; i++ {
		rStart := 0
		scanner.Scan()
		row := scanner.Text()
		for j := 0; j < w; j++ {
			if row[j] == '#' {
				for k := rStart; k < j; k++ {
					light[i][k] += j - rStart
				}
				for k := cStarts[j]; k < i; k++ {
					light[k][j] += i - cStarts[j] - 1
				}
				rStart = j + 1
				cStarts[j] = i + 1
			}
		}

		for k := rStart; k < w; k++ {
			light[i][k] += w - rStart
		}
	}

	for j := 0; j < w; j++ {
		for k := cStarts[j]; k < h; k++ {
			light[k][j] += h - cStarts[j] - 1
		}
	}

	var max int
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if light[i][j] > max {
				max = light[i][j]
			}
		}
	}

	fmt.Println(max)
}
//  [go]
package main

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

const (
	INF int = 1<<62
	MOD int = 1000000007
)

var DX, DY []int

var H, W int
var M []string
var ans int

func Input(){
	H = NextInt()
	W = NextInt()
	M = NextStrings(H)
}

func Solve(){
	res := Ints3D(H, W, 4)
	for h := 0; h<H; h++{
		sum := 0
		for w:=0; w<W; w++{
			if M[h][w] == '#'{
				sum = 0
				continue
			}
			res[h][w][0] = sum
			sum++
		}
		sum = 0
		for w:=W-1; w>=0; w--{
			if M[h][w] == '#'{
				sum = 0
				continue
			}
			res[h][w][1] = sum
			sum++
		}
	}
	for w:=0; w<W; w++{
		sum:=0
		for h:=0; h<H; h++{
			if M[h][w] == '#'{
				sum = 0
				continue
			}
			res[h][w][2] = sum
			sum++
		}
		sum = 0
		for h:=H-1; h>=0; h--{
			if M[h][w] == '#'{
				sum = 0
				continue
			}
			res[h][w][3] = sum
			sum++
		}
	}
	for _, a := range(res){
		for _, b:=range(a){
			sum := 0
			for _, c := range(b){
				sum += c
			}
			ans = Max(ans, sum)
		}
	}
}

func Output(){
	fmt.Println(ans+1)
}

func main() {
	Initialize()
	for {
		Input()
		Solve()
		Output()
	}
}

// Initilize ===================
var io *IO;
func Initialize(){
	io = NewIO()
	DY = []int{-1, 0, 1, 0}
	DX = []int{0, 1, 0, -1}
}
// IO ====================

type IO struct{
	sc *bufio.Scanner
}
func NewIO() *IO {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &IO{
		sc: sc,
	}
}
func Next() string{
	ok := io.sc.Scan()
	if !ok {
		os.Exit(0)
	}
	return io.sc.Text()
}
func NextInt() int {
	s := Next()
	a, err:= strconv.Atoi(s)
	if err != nil {
		print(err)
	}
	return a
}

func NextInts(N int) []int{
	ret := Ints(N)
	for i := range ret {
		ret[i] = NextInt()
	}
	return ret
}
func NextStrings(N int) []string {
	ret := Strings(N)
	for i := range ret {
		ret[i] = Next()
	}
	return ret
}

// =============
func Sort( a[]int){
	sort.Ints(a)
}
func Min(nums ...int) int {
	ret := int(nums[0])
	for _, n := range nums {
		if n < ret {
			ret = n
		}
	}
	return ret
}
func Max(nums ...int) int {
	ret := int(nums[0])
	for _, n := range nums {
		if n > ret {
			ret = n
		}
	}
	return ret
}
func Abs(n int)int{
	if n < 0{
		return -n
	}
	return n
}
func Ints(n int) []int{
	return make([]int, n)
}
func Ints2D(x, y int) [][]int{
	ret := [][]int{}
	for i:=0; i< x; i++{
		ret = append(ret, Ints(y))
	}
	return ret
}
func Ints3D(x, y, z int)[][][]int{
	ret := [][][]int{}
	for i:=0; i<x; i++ {
		ret = append(ret, Ints2D(y, z))
	}
	return ret
}
func Bools(n int) []bool{
	return make([]bool, n)
}
func Strings(n int) []string{
	return make([]string, n)
}
//  [go]
package main

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

type HW struct {
	H int
	W int
}

func solve() int {
	var H, W int
	fmt.Scan(&H, &W)

	r := bufio.NewReader(os.Stdin)
	dp := make([][]HW, H)

	var l []*HW

	for h := 0; h < H; h++ {
		dp[h] = make([]HW, W)
		for w := 0; w < W; w++ {
			c, _ := r.ReadByte()
			if c == '.' {
				if h > 0 {
					dp[h][w].H += dp[h-1][w].H

				}
				if w > 0 {
					dp[h][w].W += dp[h][w-1].W
				}
				dp[h][w].H++
				dp[h][w].W++

				l = append(l, &dp[h][w])

			} else {
				for i := h - 1; i >= 0; i-- {
					if dp[i][w].H == 0 {
						break
					}
					dp[i][w].H = dp[h-1][w].H
				}
				for i := w - 1; i >= 0; i-- {
					if dp[h][i].W == 0 {
						break
					}
					dp[h][i].W = dp[h][w-1].W
				}
			}
		}
		r.ReadByte()
	}

	for w := 0; w < W; w++ {
		for i := H - 1; i >= 0; i-- {
			if dp[i][w].H == 0 {
				break
			}
			dp[i][w].H = dp[H-1][w].H
		}
	}
	for h := 0; h < H; h++ {
		for i := W - 1; i >= 0; i-- {
			if dp[h][i].W == 0 {
				break
			}
			dp[h][i].W = dp[h][W-1].W
		}
	}

	max := 0
	for _, hw := range l {
		cnt := hw.W + hw.H - 1
		if max < cnt {
			max = cnt
		}
	}
	return max
}

func main() {
	ans := solve()
	fmt.Println(ans)
}
//  [go]
// 今いるところより右側にある得点, 左側にある得点、あと上下
// のデータがあればうまくいきそう うまく構築する
// TLEをくらったのでたぶん入出力のせいだということで対策
// 馬鹿みたいなバグをして1WA 丁寧にやれ

package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	H, W := nextInt(), nextInt()
	Table := make([][]string, H)
	pointR, pointL, pointU, pointD := make([][]int, H), make([][]int, H), make([][]int, H), make([][]int, H)
	for i := 0; i < H; i++ {
		pointR[i], pointL[i], pointU[i], pointD[i] = make([]int, W), make([]int, W), make([]int, W), make([]int, W)
		Table[i] = chars(next())
	}
	// 構築フェーズ
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if Table[i][j] != "#" {
				if j == 0 {
					pointL[i][j] = 1
				} else {
					pointL[i][j] = pointL[i][j-1] + 1
				}
			} else {
				pointL[i][j] = 0
			}

			if Table[i][W-j-1] != "#" {
				if j == 0 {
					pointR[i][W-1] = 1
				} else {
					pointR[i][W-1-j] = pointR[i][W-j] + 1
				}
			} else {
				pointR[i][W-1-j] = 0
			}
		}
	}
	for j := 0; j < W; j++ {
		for i := 0; i < H; i++ {
			if Table[i][j] != "#" {
				if i == 0 {
					pointU[i][j] = 1
				} else {
					pointU[i][j] = pointU[i-1][j] + 1
				}
			} else {
				pointU[i][j] = 0
			}
			if Table[H-1-i][j] != "#" {
				if i == 0 {
					pointD[H-1][j] = 1
				} else {
					pointD[H-1-i][j] = pointD[H-i][j] + 1
				}
			} else {
				pointD[H-1-i][j] = 0
			}
		}
	}

	// 探索フェーズ
	ans := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			tmp := pointD[i][j] + pointL[i][j] + pointR[i][j] + pointU[i][j] - 3
			ans = max(ans, tmp)
		}
	}
	fmt.Fprintln(out, ans)
}

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

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}
//  [ruby]
H, W = gets.split.map(&:to_i)

G = []

H.times do
  a = Array.new(W)
  line = gets.chomp.bytes.push 35
  i, j = 0, 0
  while i <= W
    if line[i] == 35
      if j < i
        c = i - j
        k = j
        while k < i
          a[k] = c
          k += 1
        end
      end 
      i += 1
      j = i
    else
      i += 1
    end
  end
  G << a
end 
G << Array.new(W)

ans = 0
G.transpose.each do |ar|
  i, j = 0, 0
  local_max = 0
  while i <= H
    v = ar[i]
    if v.nil?
      if j < i
        local_max += (i - j)
        ans = local_max if ans < local_max
        local_max = 0
      end 
      i += 1
      j = i
    else
      local_max = v if local_max < v  
      i += 1
    end 
  end 
end
STDOUT.puts ans - 1
//  [ruby]
H, W = gets.split.map(&:to_i)

G = []

H.times do
  a = Array.new(W)
  line = gets.chomp.bytes.push 35
  i, j = 0, 0
  while i <= W
    if line[i] == 35
      if j < i
        c = i - j
        k = j
        while k < i
          a[k] = c
          k += 1
        end
      end 
      i += 1
      j = i
    else
      i += 1
    end
  end
  G << a
end 
G << Array.new(W)

ans = 0
G.transpose.each do |ar|
  i, j = 0, 0
  local_max = 0
  while i <= H
    v = ar[i]
    if v.nil?
      if j < i
        local_max += (i - j)
        ans = local_max if ans < local_max
        local_max = 0
      end 
      i += 1
      j = i
    else
      local_max = v if local_max < v  
      i += 1
    end 
  end 
end
puts ans - 1
//  [ruby]
H, W = STDIN.gets.split.map(&:to_i)

G = []

H.times do
  a = Array.new(W)
  line = STDIN.gets.chomp.bytes.push 35
  i, j = 0, 0
  while i <= W
    if line[i] == 35
      if j < i
        c = i - j
        k = j
        while k < i
          a[k] = c
          k += 1
        end
      end 
      i += 1
      j = i
    else
      i += 1
    end
  end
  G << a
end 
G << Array.new(W)

ans = 0
G.transpose.each do |ar|
  i, j = 0, 0
  local_max = 0
  while i <= H
    v = ar[i]
    if v.nil?
      if j < i
        local_max += (i - j)
        ans = local_max if ans < local_max
        local_max = 0
      end 
      i += 1
      j = i
    else
      local_max = v if local_max < v  
      i += 1
    end 
  end 
end
puts ans - 1
//  [ruby]
h, w = gets.split.map(&:to_i)
w+=1

s = readlines.map(&:bytes)

a = Array.new(h+1) { Array.new(w+1,0) }
blockers=Array.new(w+1) { Array.new }

h.times do |i|
  l=0
  w.times.select {|j| s[i][j]!=46 }.each do |j|
    blockers[j] << i
    l.upto(j-1) {|c_j| a[i][c_j] = j-l }
    l=j+1
  end
end

w.times { |k| blockers[k] << h }

blockers.each_with_index do |blocks, height|
  l=0
  blocks.each do |b|
    l.upto(b-1) {|j| a[j][height] += b-l }
    l = b+1
  end
end

p a.map(&:max).push(1).max-1
//  [ruby]
h, w = gets.split.map(&:to_i)
w += 1
s = $<.map(&:bytes)
a = Array.new(h+2) { Array.new(w+2,0) }
hh=Array.new(w+2) { Array.new }

h.times do |i|
	l = 0
	w.times.select { |j| s[i][j] != 46 }.each do |r|
		hh[r] << i
		l.upto(r-1) { |j| a[i][j] = r-l }
		l = r + 1 
	end
end
w.times { |k| hh[k] << h }


hh.each_with_index do |x,i|
	u = 0
	x.each do |d| 
		u.upto(d-1) { |j| a[j][i] += d-u }
		u = d + 1 
	end
end

p a.map(&:max).push(1).max-1
//  [ruby]
h, w = gets.split.map(&:to_i)
w+=1

s = $<.map(&:bytes)

a = Array.new(h+1) { Array.new(w+1,0) }
blockers=Array.new(w+1) { Array.new }

h.times do |i|
  l=0
  w.times.select {|j| s[i][j]!=46 }.each do |j|
    blockers[j] << i
    l.upto(j-1) {|c_j| a[i][c_j] = j-l }
    l=j+1
  end
end

w.times { |k| blockers[k] << h }

blockers.each_with_index do |blocks, height|
  l=0
  blocks.each do |b|
    l.upto(b-1) {|j| a[j][height] += b-l }
    l = b+1
  end
end

p a.map(&:max).push(1).max-1
//  [rust]
use std::io;
use std::usize::MAX;

type Range = (usize, usize);

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.chars().collect()
}

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn count(row_idx: usize, column_idx: usize, row_range: &Vec<Vec<Range>>, column_range: &Vec<Vec<Range>>) -> usize {
    let mut sum = 0;
    // row
    for r in &row_range[row_idx] {
        // print!("{} {} ", r.0, r.1);
        if column_idx < r.1 {
            sum += r.1 - r.0;
            break;
        }
    }
    // print!("{} ", sum);

    // column
    for r in &column_range[column_idx] {
        if row_idx < r.1 {
            sum += r.1 - r.0;
            break;
        }
    }
    // print!("{} ", sum);
    sum - 1
}
fn main() {
    let (h, w) = input_tuple();
    // let h = 2000;
    // let w = 2000;
    let mut map: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
        let row = input_char_vec();
        // let row = vec!['.'; 2000];
        map.push(row);
    }

    let mut row_range: Vec<Vec<Range>> = vec![Vec::new(); h];
    let mut column_range: Vec<Vec<Range>> = vec![Vec::new(); w];

    for i in 0..h {
        let mut start = MAX;
        for j in 0..w {
            if map[i][j] == '#' {
                if start != MAX {
                    row_range[i].push((start, j));
                    start = MAX
                }
            } else {
                if start == MAX {
                    start = j;
                }
            }
        }
        if start != MAX {
            row_range[i].push((start, w));
        }
    }

    for i in 0..w {
        let mut start = MAX;
        for j in 0..h {
            if map[j][i] == '#' {
                if start != MAX {
                    column_range[i].push((start, j));
                    start = MAX
                }
            } else {
                if start == MAX {
                    start = j;
                }
            }
        }
        if start != MAX {
            column_range[i].push((start, h));
        }
    }

    // for i in 0..h {
    //     println!("{}", i);
    //     for r in &row_range[i] {
    //         println!("({}, {})", r.0, r.1);
    //     }
    // }

    // for i in 0..w {
    //     println!("{}", i);
    //     for r in &column_range[i] {
    //         println!("({}, {})", r.0, r.1);
    //     }
    // }

    let mut max = 0usize;
    for i in 0..h {
        for j in 0..w {
            if map[i][j] != '#' {
                let num = count(i, j, &row_range, &column_range);
                // println!("{}, {}, {}", i, j, num);
                if num > max {
                    max = num;
                }
            }
        }
    }
    println!("{}", max);
}
//  [swift]
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}


func main() {
    let hw = readWords { Int($0)! }
    let h = hw[0]
    let w = hw[1]

    let grid = (1...h).map { _ in Array(readLine()!) }

    let makeGrid = { (1...h).map { _ in [Int](repeating: 0, count: w) } }
    var L = makeGrid()
    var R = makeGrid()
    var U = makeGrid()
    var D = makeGrid()

    for i in 0..<h {
        for j in 0..<w {
            if j == 0 { 
                L[i][j] = 1
                R[i][w-j-1] = 1
            } else {
                L[i][j] = L[i][j-1] + 1
                R[i][w-j-1] = R[i][w-j] + 1 
            }

            if i == 0 {
                U[i][j] = 1
                D[h-i-1][j] = 1
            } else {
                U[i][j] = U[i-1][j] + 1
                D[h-i-1][j] = D[h-i][j] + 1
            }

            if grid[i][j] == "#" {
                L[i][j] = 0
                U[i][j] = 0
            }

            if grid[i][w-j-1] == "#" {
                R[i][w-j-1] = 0
            }

            if grid[h-i-1][j] == "#" {
                D[h-i-1][j] = 0
            }
        }
    }

    var ans = 0
    for i in 0..<h {
        for j in 0..<w {
            ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
        }
    }

    print(ans)
}


main()
//  [swift]
class Node {
  var val: Int
  var next: Node?
  init(_ v: Int) {
    self.val = v
  }
}
class Stack {
  var head: Node?
  
  var isEmpty: Bool { return head == nil }
  
  func push(_ v: Int) {
    let node = Node(v)
    node.next = head
    head = node
  }
  func pop() -> Int {
    let v = head!.val
    let tmp = head
    head = head?.next
    tmp?.next = nil
    return v
  }
}


let inp = readLine()!.split(separator: " ").map { Int($0)! }
let h = inp[0]
let w = inp[1]
var grid: [[Character]] = .init(repeating: [], count: h)

var memo: [[Int]] = .init(repeating: .init(repeating: 0, count: w), count: h)

for i in 0..<h {
  grid[i] = Array(readLine()!)
}

let stack = Stack()

var curSum = 0

for row in 0..<h {
  curSum = 0
  for col in 0..<w {
    if grid[row][col] == "#" {
      while !stack.isEmpty {
        let v = stack.pop()
        let r = v / w
        let c = v % w
        memo[r][c] += curSum
      }
      curSum = 0
    } else {
      curSum += 1
      let index = row * w + col
      stack.push(index)
    }
  }
  while !stack.isEmpty {
	let v = stack.pop()
   	let r = v / w
   	let c = v % w
  	memo[r][c] += curSum
  }
}


var ans = 0

for col in 0..<w {
  curSum = 0
  for row in 0..<h {
    if grid[row][col] == "#" {
      while !stack.isEmpty {
        let v = stack.pop()
        let r = v / w
        let c = v % w
        memo[r][c] += curSum
        ans = max(ans, memo[r][c])
      }
      curSum = 0
    } else {
      curSum += 1
      let index = row * w + col
      stack.push(index)
    }
  }
  while !stack.isEmpty {
	let v = stack.pop()
   	let r = v / w
   	let c = v % w
  	memo[r][c] += curSum
  	ans = max(ans, memo[r][c])
  }
}

print(max(ans - 1, 0))
//  [typescript]
function main(input) {
  lines = input.split('\n')
  v = lines[0].split(' ').map((n) => parseInt(n));
  h = v[0];
  w = v[1];
  s = [];
  for (i = 1; i < h + 1; i++) {
    s.push(lines[i]);
  }
  dw = [];
  dh = [];
  for (i = 0; i < h; i++) {
    cw = [];
    count = 0;
    for (j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        cw.push(0);
      } else if (j == 0 || s[i][j - 1] == '#') {
        count = 0;
        for (k = j; k < w; k++) {
          if (s[i][k] == '.') {
            count ++;
          } else {
            break;
          }
        }
        cw.push(count);
      } else {
        cw.push(count);
      }
    }
    dw.push(cw);
  }
  for (j = 0; j < w ; j++) {
   ch = [];
   count = 0;
   for (i = 0 ; i < h ; i++) {
     if (s[i][j] == '#') {
       ch.push(0);
     } else if (i == 0 || s[i - 1][j] == '#') {
       count = 0;
       for (k = i; k < h; k++) {
         if (s[k][j] == '.') {
           count += 1;
         } else {
           break;
         }
       }
       ch.push(count);
     } else {
       ch.push(count);
     }
   }
   dh.push(ch);
  }
  max = 0;
  for (i = 0; i< h; i++) {
    for (j = 0; j < w; j++) {
      sum = dw[i][j] + dh[j][i];
      if (max < sum) {
        max = sum;
      }
    }
  }
  console.log( max - 1);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [typescript]
{
  const main = (input: string) => {
    const read = reader(input)
    const [H, W] = read.ns()
    const s = read.lines

    const l: number[][] = _arr2D(H, W)
    const r: number[][] = _arr2D(H, W)
    const t: number[][] = _arr2D(H, W)
    const d: number[][] = _arr2D(H, W)

    for (let i = 0; i < H; i++) {
      for (let j = 0; j < W; j++) {
        if (s[i][j] !== '#') l[i][j] = (l[i][j - 1] || 0) + 1
        if (s[i][j] !== '#') t[i][j] = (i > 0 ? t[i - 1][j] : 0) + 1
        if (s[i][W - j - 1] !== '#') r[i][W - j - 1] = (r[i][W - j] || 0) + 1
        if (s[H - i - 1][j] !== '#')
          d[H - i - 1][j] = (i > 0 ? d[H - i][j] : 0) + 1
      }
    }

    // console.log(t.map(ll => ll.join('')).join('\n'))
    // console.log(d.map(ll => ll.join('')).join('\n'))
    let max = 0

    for (let i = 0; i < H; i++) {
      for (let j = 0; j < W; j++) {
        if (s[i][j] === '#') continue

        const score = l[i][j] + r[i][j] + t[i][j] + d[i][j] - 3

        max = Math.max(max, score)
      }
    }
    console.log(max)
  }
  const _arr2D = (h: number, w: number, fill = 0) => {
    return new Array(h)
      .fill(0)
      .reduce((p, c) => p.concat([Array(w).fill(fill)]), [])
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}
//  [typescript]
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

function getTable(H: number, W: number): number[][] {
	let table: number[][] = [];
	for(let i=0; i<H; i++) {
		table.push(new Array(W).fill(null).map(() => 0));
	}
	return table;
}

function solve(): number {
	let reader = new Reader();
	let table: string[][] = [];
	let [H, W] = reader.readInts();
	for(let i=0; i<H; i++) {
		let row = reader.readLine();
		table.push(new Array(W).fill(null).map((value, index) => row.charAt(index)));
	}
	let fromLeft = getTable(H, W);
	let fromTop = getTable(H, W);
	for(let i=0; i<H; i++) {
		for(let j=0; j<W; j++) {
			if (table[i][j] == '.') {
				fromLeft[i][j] = 1;
				fromTop[i][j] = 1;
				if (j > 0)
					fromLeft[i][j] += fromLeft[i][j-1];
				if (i > 0)
					fromTop[i][j] += fromTop[i-1][j];
			}
		}
	}

	let fromRight = getTable(H, W);
	let fromBottom = getTable(H, W);
	for(let i=H-1; i>=0; i--) {
		for(let j=W-1; j>=0; j--) {
			if (table[i][j] == '.') {
				fromRight[i][j] = 1;
				fromBottom[i][j] = 1;
				if (i < H-1)
					fromBottom[i][j] += fromBottom[i+1][j];
				if (j < W-1)
					fromRight[i][j] += fromRight[i][j+1];
			}
		}
	}
	let maximumLight = 0;
	for(let i=0; i<H; i++) {
		for(let j=0; j<W; j++) {
			if (table[i][j] == '.') {
				maximumLight = Math.max(maximumLight, fromLeft[i][j]+fromTop[i][j]+fromRight[i][j]+fromBottom[i][j]-3);
			}
		}
	}
	return maximumLight;
}

console.log(solve());
//  [typescript]
import { readFileSync } from 'fs'

const transpose = <T>(a: T[][]) =>
  a[0].map((_, c) => a.map(r => r[c]))

const mapWithPrev = <T, U>(list: T[], fn: (prev: U, value: T) => U, init: U) => {
  const result = [] as U[]
  let prev = init
  for (const value of list) {
    result.push(prev = fn(prev, value))
  }
  return result
}

function main(input: string) {
  const [header, ...lines] = input.split('\n')
  const grid = lines.map(v => v.split(''))

  const fn = (list: string[]) =>
    mapWithPrev(list, (prev, value) => {
      if (value === '#') return { value: 0 }
      const current = prev.value === 0 ? { value: 0 } : prev
      current.value += 1

      return current
    }, { value: 0 })
      .map(v => v.value)

  const horizontalList = grid.map(fn)

  const verticalList = transpose(
    transpose(grid).map(fn)
  )

  const resultGrid = grid.map((row, r) =>
    row.map((_, c) => horizontalList[r][c] + verticalList[r][c] - 1)
  )

  const max = Math.max(...resultGrid.map(v => Math.max(...v)))

  console.log(max)
}

main(readFileSync('/dev/stdin', 'utf8').trim())
//  [python]
# B - Iron Bar Cutting
from bisect import bisect
from itertools import accumulate


def main():
    N, *A = map(int, open(0).read().split())
    cumsum = tuple(accumulate(A))
    idx = bisect(cumsum, cumsum[-1] // 2)
    print(min(cumsum[idx] * 2 - cumsum[-1], cumsum[-1] - cumsum[idx - 1] * 2))


if __name__ == "__main__":
    main()
//  [python]
from itertools import accumulate, count
from bisect import bisect_right

input()
a = [0] + list(accumulate(map(int, input().split())))
i = bisect_right(a, a[-1] // 2)
print(min(2 * a[i] - a[-1], a[-1] - 2 * a[i - 1]))
//  [python]
import sys
from itertools import accumulate
from bisect import bisect_left
read = sys.stdin.read

N, *A = map(int, read().split())
A = list(accumulate([0] + A))
a = A[-1] // 2
n = bisect_left(A, a) - 1

print(min(abs(2 * A[n] - A[-1]), abs(2 * A[n + 1] - A[-1])))
//  [python]
N=input()
b=input().split()
sum=0
bigsum=0
for i in b:
    sum+=eval(i)
standard=sum/2
for i in b:
    bigsum+=eval(i)
    if bigsum>standard:
        smallsum=bigsum-eval(i)
        break
if bigsum-standard>standard-smallsum:
    print(sum-2*smallsum)
else:
    print(2*bigsum-sum)
//  [python]
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

A = np.array(A, dtype=int)
cs1 = A.cumsum()
cs2 = cs1[-1] - cs1
ans = np.abs(cs1 - cs2).min()
print(ans)
//  [python]
import numpy as np

N = int(input())
A = list(map(int, input().split()))

A = np.array(A)
L = np.sum(A)

l=0
ans = -1

for i in range(N):
    l += A[i]
    if l == L/2:
        ans = 0
        break
    elif l > L/2:
        Am = A[i]
        break

if ans < 0:
    L2 = L - l
    L1 = l - Am
    ans = int(min(L1+Am-L2, L2+Am-L1))

print(ans)
//  [java]
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int N = sc.nextInt();
		long[] divide = new long[N];
		long sum = 0;
		for (int i = 0; i < N; i++) {
			long val = sc.nextLong();
			divide[i] = val;
			sum += val;
		}
		long half = sum / 2;
		long pIndex = 0;
		long lIndex = 0;
		long tmpSum = 0;
		for (int i = 0; i < N; i++) {
			tmpSum += divide[i];
			if (tmpSum <= half) {
				pIndex = tmpSum;
			}
			if (tmpSum >= half) {
				lIndex = tmpSum;
				break;
			}
		}
		if (pIndex == lIndex) {
			System.out.println(0);
			return;
		}
		long pNear = half - pIndex;
		long lNear = lIndex - half;
		if (pNear < lNear) {
			long abs = Math.abs(pIndex - (sum - pIndex));
			System.out.println(abs);
			return;
		} else {
			long abs = Math.abs(lIndex - (sum - lIndex));
			System.out.println(abs);
			return;
		}
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}
//  [java]

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc    = new Scanner(System.in);
    static final int     MOD   = (int) 1E9 + 7;
    static final long    INF_L = (long) 4E18;

    public static void main(String[] args) {
        int N = nint();
        long[] A = nlongs(N);
        long[] sum = new long[N];
        
        sum[0] = A[0];
        for (int i = 1; i < N; i++) {
            sum[i] = sum[i-1] + A[i];
        }
        long len = sum[N-1];
        
        long minDiffAbs = INF_L;
        for (int i = 0; i <= N - 2; i++) {
            long right = len - sum[i];
            long left = sum[i];
            minDiffAbs = min(minDiffAbs, abs(right - left));
        }
        System.out.println(minDiffAbs);
    }

    @Deprecated
    static int nint() {
        return sc.nextInt();
    }

    @Deprecated
    static int[] nints(int N) {
        return nints(0, N, 0);
    }

    @Deprecated
    private static int[] nints(int padL, int N, int padR) {
        int[] a = new int[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nint();
        return a;
    }

    static long nlong() {
        return sc.nextLong();
    }

    static long[] nlongs(int N) {
        return nlongs(0, N, 0);
    }

    static long[] nlongs(int padL, int N, int padR) {
        long[] a = new long[padL + N + padR];
        for (int i = 0; i < N; i++)
            a[padL + i] = nlong();
        return a;
    }

    static double ndouble() {
        return sc.nextDouble();
    }

    static double[] ndoubles(int N) {
        return ndoubles(0, N, 0);
    }

    static double[] ndoubles(int padL, int N, int padR) {
        double[] d = new double[N + padL + padR];
        for (int i = 0; i < N; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    static String nstr() {
        return sc.next();
    }

    static char[] nchars() {
        return sc.next().toCharArray();
    }

    static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    static char[][] nchars2(int H, int W) {
        return nchars2(H, W, 0, 0);
    }

    static char[][] nchars2(int H, int W, int padLU, int padRD) {
        char[][] a2 = new char[H + padLU + padRD][W + padLU + padRD];
        for (int i = 0; i < H; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, W);
        return a2;
    }

    static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    static long abs(long a) {
        return Math.abs(a);
    }
}