akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010

using namespace std;

int busstop[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

int main(){
    int n;
    cin >> n;
    for(int k=0; k < n; k++){

        int e1,e2;
        bool isFirst = false;
        cin >> e1 >> e2;

        if(e1 > e2) isFirst = true;

        for(int i=0;; i++){
            if(busstop[i] == e1){
                if(isFirst){
                    isFirst = !isFirst;
                    continue;
                }
                for(int j=i; ; j++){
                    if(busstop[j] == e2){
                        cout << " " << busstop[j];
                        goto end_state;
                    }
                    else {
                        if(j == i) cout << busstop[j];
                        else cout << " " << busstop[j];
                    }
                }
            }
        }
end_state:
        cout << endl;
    }
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>
using namespace std;

int n, m, f[100005], cnt[100005], ans = 0;
int main(){
	scanf("%d%d", &n, &m);
	ans = 0; f[1] = 1;
	for (int i = 1; i <= n; ++i) cnt[i] = 1;
	for (int i = 1; i <= m; ++i){
		int x, y;
		scanf("%d%d", &x, &y);
		--cnt[x]; ++cnt[y];
		if (f[x]){
			f[y] = 1;
			if (cnt[x] == 0) f[x] = 0;
		}
	}
	for (int i = 1; i <= n; ++i) if (f[i] && cnt[i]) ++ans;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll s[100005];
    for (ll i=0;i<n;i++)
    cin>>s[i];
    ll ans=1;
    ll ss=1000000000000000000;
    for (ll i=0;i<n;i++)
    {
        if (s[i]==0)
        {
            cout<<"0";
            return 0;
        }
    }
    for (ll i=0;i<n;i++)
    {
        if ((ss/ans)<s[i])
        {
            cout<<"-1";
            return 0;
        }
        ans*=s[i];
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 4368
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
string s;
int main() {
	cin >> s;
	int A = s[0] - '0';
	int B = s[1] - '0';
	int C = s[2] - '0';
	int D = s[3] - '0';
	if (A + B + C + D == 7) {
		cout << A << "+" << B << "+" << C << "+" << D << "=" << 7 << endl;
	}
	else if (A - B + C + D == 7) {
		cout << A << "-" << B << "+" << C << "+" << D << "=" << 7 << endl;
	}
	else if (A + B - C + D == 7) {
		cout << A << "+" << B << "-" << C << "+" << D << "=" << 7 << endl;
	}
	else if (A + B + C - D==7) {
		cout << A << "+" << B << "+" << C << "-" << D << "=" << 7 << endl;
	}
	else if (A - B - C + D == 7) {
		cout << A << "-" << B << "-" << C << "+" << D << "=" << 7 << endl;
	}
	else if (A - B + C - D == 7) {
		cout << A << "-" << B << "+" << C << "-" << D << "=" << 7 << endl;
	}
	else if (A + B - C - D == 7) {
		cout << A << "+" << B << "-" << C << "-" << D << "=" << 7 << endl;
	}
	else if (A - B - C - D == 7) {
		cout << A << "-" << B << "-" << C << "-" << D << "=" << 7 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
A,B,C,D,E,F = map(int,input().split())
f = F//100

ans = [0,0]
per = -1

for w in range(1,f+1):
    wt = 0
    for b in range(0,w+1,B):
        if (w-b)%A == 0:
            wt = 1
            break
    if wt == 0:
        continue
    water = w*100

    for s in range(min(w*E,F-water),-1,-1):
        st = 0
        for d in range(0,s+1,D):
            if (s-d)%C == 0:
                st = 1
                break
        if st == 1:
            break

    if s/(s+water) > per:
        ans = [s+water,s]
        per = s/(s+water)

print(' '.join(map(str,ans)))


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

i64 mod = 1e9 + 7;

i64 add(i64 x, i64 y)
{
	i64 z = x + y;
	return z >= mod ? z - mod : z;
}

int main()
{
	int n;
	vector<int> cs;

	scanf("%d", &n);
	cs.reserve(n);
	for(int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		x = x - 1;
		if(cs.size() == 0 || *cs.rbegin() != x) {
			cs.push_back(x);
		}
	}

	n = cs.size();

	vector<i64> ans(n, 0);
	vector<i64> sum(2 * 1e5, 0);

	ans[n - 1] = 1;
	sum[cs[n - 1]] = 1;

	for(int pos = n - 1; pos >= 0; --pos) {

		int c = cs[pos];
		ans[pos] = sum[c];

		if(pos > 0) {
			int d = cs[pos - 1];
			sum[d] = add(sum[d], ans[pos]);
		}
	}

	printf("%lld\n", ans[0]);

	return 0;
}

/* waffle */


Measured memory_bytes: 4096
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
  ll N;
  cin >> N;
  int min=999;
  int tmp;
  while(N>=100){
    tmp=abs(753-N%1000);
    if(min>tmp){
      min = tmp;
    }
  N=N/10;
  }
  cout << min;
  return 0;
}


Measured memory_bytes: 256
X, N = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]

i = 0

if N == 0:
    print(X)
    exit(0)

while (True):
    a = X + i
    b = X - i
    if b in P and a not in P:
        print(a)
        break
    if a in P and b not in P:
        print(b)
        break
    if a not in P and b not in P:
        print(b)
        break
    i += 1

Measured memory_bytes: 9084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<stack>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define LARGE 1000000000
#define MOD 100000

int n, m;
int dis[100009];
int ans = 0, now = 1;

int main() {
	cin >> n >> m;
	dis[1] = 0;
	for (int i = 2; i <= n; i++) {
		cin >> dis[i];
		dis[i] += dis[i - 1];
		//cout << "dis[" << i << "] = " << dis[i] << endl;
	}
	for (int i = 0; i < m; i++) {
		int road;
		cin >> road;
		if (road > 0) ans += (dis[now + road] - dis[now]);
		else ans += (dis[now] - dis[now + road]);
		ans %= MOD;
		//cout << ans << endl;
		now += road;
	}
	cout << ans % MOD << endl;
}

//チーズ
/*
int H, W, N, ans, tag, si, sj;
char MAP[1009][1009];
int dp[1009][1009];

bool inmap(int i, int j) {
return ((i >= 0 && i <= H - 1) && (j >= 0 && j <= W - 1));
}
bool pass(int i, int j) {
return (MAP[i][j] != 'X');
}

int DFS(int i, int j) {
if (dp[i][j] != LARGE)return dp[i][j];
if (MAP[i][j] - '0' == tag) {
si = i; sj = j;
return 0;
}

if (inmap(i + 1, j) && pass(i + 1, j)) dp[i][j] = min(dp[i][j], DFS(i + 1, j) + 1);
if (inmap(i - 1, j) && pass(i - 1, j)) dp[i][j] = min(dp[i][j], DFS(i - 1, j) + 1);
if (inmap(i, j + 1) && pass(i, j + 1)) dp[i][j] = min(dp[i][j], DFS(i, j + 1) + 1);
if (inmap(i, j - 1) && pass(i, j - 1)) dp[i][j] = min(dp[i][j], DFS(i, j - 1) + 1);
cout << i << " " << j << " " << dp[i][j] << endl;
return dp[i][j];
}

int main() {
cin >> H >> W >> N;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> MAP[i][j];
if (MAP[i][j] == 'S') {
si = i; sj = j;
}
}
}

for (int i = 1; i <= N; i++) {
cout << i << " " << si << " " << sj << endl << endl;
for (int j = 0; j < H; j++) {
for (int k = 0; k < W; k++) {
dp[j][k] = LARGE;
}
}
tag = i;
ans += DFS(si, sj);

}

cout << ans << endl;
return 0;
}
*/



Measured memory_bytes: 3492
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;

void display(vector<int> ary) {
  for (int i = 0; i < ary.size(); i++) {
    if (i > 0) cout << " ";
    cout << ary[i];
  }

  cout << endl;
}

void insert_sort_and_display(vector<int> ary) {
  int v, i, j;
  for (i = 0; i < ary.size(); i++) {
    v = ary[i];
    j = i - 1;
    while (j >= 0 && v < ary[j]) {
      ary[j + 1] = ary[j];
      j--;
    }
    ary[j + 1] = v;
    display(ary);
  }
}

int main(void) {
  int len;
  vector<int> ary;
  char s[2000];

  cin >> len;

  for (int i = 0; i < len; i++) {
    cin >> s;
    ary.push_back(atoi(s));
  }

  insert_sort_and_display(ary);

  return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){


  int k,n;
  cin>>k>>n;
  
  vi data(n);
  rep(i,n){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  
  vi dis(n);

  for (int i=0;i<=n-2;i++){
    int tmp;
    tmp=data.at(i+1)-data.at(i);
    dis.at(i)=min(tmp,k-tmp);
  }
  
  int tmp;
  tmp=data.at(0)+k-data.at(n-1);
  dis.at(n-1)=min(tmp,k-tmp);
  
  sort(dis.begin(),dis.end());
  
  cout<<k-dis.at(n-1)<<endl;
  
  
}





Measured memory_bytes: 1792
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
template <usize N, class T, class... Args, std::enable_if_t<N==0, int> = 0>
auto mkvec(Args... args) {
    return T(args...);
}
template <usize N, class T, class... Args, std::enable_if_t<N!=0, int> = 0>
auto mkvec(usize sz, Args... args) {
    using value_type = std::decay_t<decltype(mkvec<N-1, T>(args...))>;
    return vec<value_type>(sz, mkvec<N-1, T>(args...));
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize h, w, q;
    std::cin >> h >> w >> q;
    auto g = mkvec<2, i64>(2*h, 2*w);
    for (usize i=0; i<h; i++) for (usize j=0; j<w; j++) {
        char c;
        std::cin >> c;
        if (c=='1') {
            g.at(2*i+1).at(2*j+1) = 1;
        }
    }
    for (usize i=1; i<2*h; i++) for (usize j=1; j<2*w; j++) {
        if (i%2==0 && j%2==1 && g.at(i-1).at(j) && g.at(i+1).at(j)
                ||
            i%2==1 && j%2==0 && g.at(i).at(j-1) && g.at(i).at(j+1)) {
            g.at(i).at(j) = -1;
        }
    }
    for (usize i=0; i<2*h; i++) for (usize j=0; j<2*w; j++) {
        i64& x = g.at(i).at(j);
        if (i) x += g.at(i-1).at(j);
        if (j) x += g.at(i).at(j-1);
        if (i&&j) x -= g.at(i-1).at(j-1);
    }

    while (q--) {
        usize i0, j0, i1, j1;
        std::cin >> i0 >> j0 >> i1 >> j1;
        i0--, j0--;
        i0 = 2 * i0;
        j0 = 2 * j0;
        i1 = 2 * i1 - 1;
        j1 = 2 * j1 - 1;
        std::cout << g.at(i1).at(j1) - g.at(i0).at(j1) - g.at(i1).at(j0) + g.at(i0).at(j0) << '\n';
    }
}


Measured memory_bytes: 126976
#include<bits/stdc++.h>
using namespace std;
long long int math(long long int x)
{
	long long int ans;
	ans=x*(x+1)/2;
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int ff,n,fv,th,total,totalff,totalfv,totalth,ans;
	cin>>n;
	total= math(n);
	ff=n/15;
	totalff=15*math(ff);
	th=(n/3);
	totalth=3*math(th);
	fv=(n/5);
	totalfv=5*math(fv);
	ans=total-totalfv-totalth+totalff;
	cout<<ans;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int x, count = 0;
	int flag = 0;
	cin >> x;
	count = x / 11;
	count *= 2;
	x %= 11;
	if(7 <= x) {
		count += 2;
	} else if(0 < x && x < 7) {
		count++;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y,a,c=-101,d=101;
  cin>>n>>m>>x>>y;
  for(int i=0;i<n;i++){
    cin>>a;
    c=max(a,c);
  }
  for(int i=0;i<m;i++){
    cin>>a;
    d=min(a,d);
  }
  for(int i=x+1;i<=y;i++){
    if(i>c&&i<=d){
      cout<<"No War";
      return 0;
    }
  }
  cout<<"War";
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MAX = 1000000000;

struct Edge {
	int to;
	int cost;
};


int main() {
	int n, m;
	cin >> n >> m;

	vector<vector<int>> edges(n, vector<int>(n, MAX));
	FOR(i, 0, n) {
		edges[i][i] = 0;
	}
	vector<int> as(m), bs(m);
	FOR(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		edges[a][b] = edges[b][a] = c;
		as[i] = a, bs[i] = b;
	}

	int cnt = 0;
	vector<vector<int>> cost(edges);
	FOR(k, 0, n) {
		FOR(i, 0, n) {
			FOR(j, 0, n) {
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}

	FOR(i, 0, m) {
		int a = as[i], b = bs[i];
		FOR(x, 0, n) {
			bool flag = false;
			FOR(y, 0, n) {
				if (cost[x][a] + cost[b][y] + edges[a][b] == cost[x][y]) {
					cnt++;
					flag = true;
					break;
				}
			}
			if (flag)
				break;
		}
	}
	cout << m - cnt << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include <cmath>
#define endl "\n"
using namespace std;




int main()
{
    int i,temp=0;
    string S;
    cin >> S;
    int freq[27]={};
    for (i = 0; i < S.length(); i++)
    {
        int c = S[i] - 96;
       // cout << c << endl;
        freq[(int)S[i]-96]++;
    }
    for (i = 0; i < 27; i++)
    {
        if (freq[i] % 2 != 0)
        {
            temp = 1;
            cout << "No\n";
            break;
        }
    }
    if (temp == 0)
    {
        cout << "Yes\n";
    }
}


Measured memory_bytes: 3492
#include <cstdio>
using namespace std;
const int maxn=1e5+10;

int fa[maxn];
int p[maxn];
int n,m,x,y,ans;

int father(int p)
{
	if (fa[p]==p) return p;
	else return fa[p]=father(fa[p]);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&p[i]),fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		x=father(x);y=father(y);
		fa[x]=y;
	}
	
	ans=0;
	for(int i=1;i<=n;i++)
		if (father(p[i])==father(i))
			ans++;	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define cyes cout<<"Yes"<<endl;
#define cno cout<<"No"<<endl;
#define gcd __gcd
using namespace std;

signed main() {
  int a,b,c,d,e,f,g,h,i;
  cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
  /*a b c
    d e f
    g h i*/
  if(a+e+i==b+f+g&&b+f+g==c+d+h) {
    cyes;
  }
  else {
    cno;
  }
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}

import Control.Monad
import Data.List
import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.Sequence as Sq
import Data.Sequence ((<|),(|>), empty)

readIntLL = map(unfoldr(B.readInt.B.dropWhile(==' '))).B.lines<$>B.getContents

pushl s [] = s
pushl s (a:as) = a <| (pushr s as)

pushr s [] = s
pushr s (a:as) = (pushl s as) |> a

main=do
    [n]:as:_ <- readIntLL
    --
    let rs = pushl empty $ reverse as
    forM_ rs $ \i -> do putStr $ show i ++ " "
    putStrLn ""


Measured memory_bytes: 20604
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  
  int a0;
  int L;
  int p;
  
  while(cin>>a0>>L,a0,L){
    vector<int> a(20);
    int result_a1,result_a2;
    int result;
    bool flag=false;

    a.clear();
    
    a[0]=a0;
    int hozon=a[0];

    for(int j=1;j<=20;++j){
      vector<int> temp;
      int max=0;
      int min=0;
      
      temp.clear();
      
      for(int i=0;i<L;++i){
	temp.push_back(hozon%10);
	hozon=hozon/10;
      }
      
      sort(temp.begin(),temp.end(),greater<int>());
      
      p=1;
      for(auto i:temp){
	min+=i*p;
	p=p*10;
      }
      
      sort(temp.begin(),temp.end());
      
      p=1;
      for(auto i:temp){
	max+=i*p;
	p=p*10;
      }

      a[j]=max-min;
      
      for(int i=0;i<j;++i){
	if(a[i]==a[j]){
	  flag=true;
	  result_a1=i;
	  result_a2=j;
	  result=a[j];
	  break;
	}
      }
      if(flag==true) break;
      else hozon=max-min;
    }
    cout<<result_a1<<" "<<result<<" "<<result_a2-result_a1<<endl;
  }
}

Measured memory_bytes: 3096
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, M;
vector<string> fi;

int main() {
    while (cin >> N >> M) {
        fi.resize(N);
        for (int i = 0; i < N; ++i) cin >> fi[i];
        
        bool ok = true;
        for (int x = 0; x < N; ++x) {
            for (int y = 0; y < M; ++y) {
                if (fi[x][y] == '.') continue;

                int con = 0;
                for (int dir = 0; dir < 4; ++dir) {
                    int nx = x + dx[dir], ny = y + dy[dir];
                    if (nx < 0 || nx >= N || ny < 0 || ny >= M) continue;
                    if (fi[nx][ny] == '#') ++con;
                }
                if (con == 0) ok = false;
            }
        }
        if (ok) puts("Yes");
        else puts("No");
    }
}










Measured memory_bytes: 256
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//競技プログラミングから逃げるな
//https://www.youtube.com/watch?v=z_B9iJ8r4ic

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
struct z{
  int c,a[100000];
};

__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n,m,x;cin>>n>>m>>x;
  vector<z> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i].c;
    for(int j = 0; m > j; j++){
      cin>>A[i].a[j];
    }
  }
  int mn = 1000000000;
  int tmpm = 0;
  int tmpa[m];
  for(int bit = 0; (1<<n) > bit;bit++){
    for(int i = 0; m > i; i++){
      tmpa[i] = 0;
    }
    tmpm = 0;
    for(int i = 0; n > i; i++){
      if(bit&(1<<i)){
        tmpm+=A[i].c;
        for(int j = 0; m > j; j++){
          tmpa[j] += A[i].a[j];
        }
      }
    }
    bool ok = true;
    for(int i = 0; m > i; i++){
      if(tmpa[i] < x){
        ok = false;
      }
    }
    if(ok){
      mn = min(mn,tmpm);
    }
  }
  if(mn == 1000000000){
    cout << -1 << endl;
    return 0;
  }
  cout << mn << endl;
}

Measured memory_bytes: 8200
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            Console.WriteLine(6 - (A + B));
        }
    }
}



Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	int s[100];
	int minNum = 1000;
	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> s[i];
		sum += s[i];

		if (s[i] % 10 != 0) {
			minNum = min(minNum, s[i]);
		}
	}
	if (sum % 10 == 0) {
		if (minNum == 1000)
		{
			sum = 0;
		}
		else {
			sum -= minNum;
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF 1e18+10  
using ll = long long; 

using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
using Ps=pair<int,string>;

using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

//const ll mod=998244353;
const ll mod=1e9+7;
const ll MAX=300000;

//////////////////////////////////////


int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<set<int>>a(26);
    rep(i,n){
        a[s[i]-'a'].insert(i+1);
    }
    int q;
    cin>>q;
    auto change=[&](int m, char c){
        char now=s[m-1];
        s[m-1]=c;
        a[(int)now-'a'].erase(m);
        a[(int)c-'a'].insert(m);
    };
    auto check=[&](int l,int r){
        int ret=0;
        rep(i,26){
            auto it=a[i].lower_bound(l);
            if(it!=a[i].end()&&*it<=r)ret++;
        }
        return ret;
    };
    vi ans;
    rep(i,q){
        int mode;
        cin>>mode;
        
        if(mode==1){
            int a;
            char b;
            cin>>a>>b;
            change(a,b);
        }
        else {
            int a,b;
            cin>>a>>b;
            ans.push_back(check(a,b));
        }
        
    }
    rep(i,(int)ans.size()){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 27444
#include<bits/stdc++.h>

using namespace std;

int main(){
	
	string s;
	int count=0;
	
	cin >> s;
	
	for(int i=0;i<3;i++){
		if(s[i] == 'o') count++;
	}
	
	cout << 700+count*100;
	
	return 0;
	
}
	

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
struct BIT {
    int N;
    vector<T> dat;

    // 0-indexing
    explicit BIT(int n): N(n), dat(N + 1, 0) {}

    T sum(int i) {
        T s = T();
        for(++i; i > 0; i -= i & -i) s += dat[i];
        return s;
    }

    void add(int i, const T& x) {
        for (++i; i <= N; i += i & -i) dat[i] += x;
    }

    // min_x {x | v1 + v2 + ⋯ + vx ≧ w}
    // Assuming v_q >= 0
    int lower_bound(T w) {
        if (w <= 0) return 0;

        int x = 0; T k = 1;
        while (k * 2 <= N) k <<= 1;
        for (; k > 0; k /= 2) {
            if (x + k <= N && dat[x + k] < w) {
                w -= dat[x + k];
                x += k;
            }
        }
        return x + 1;
    }
};

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, Q;
    cin >> N >> Q;

    vll c(N);
    for(auto &e: c) cin >> e;
    for(auto &e: c) --e;

    vector<vector<pair<int, int>>> query(N);
    REP(i, Q) {
        int l, r; cin >> l >> r;
        --l; --r;
        query[r].eb(l, i);
    }

    vector<int> last(N, -1);
    BIT<int> bit(N);
    vector<int> ans(Q);
    REP(i, N) {
        if (~last[c[i]]) bit.add(last[c[i]], -1);
        last[c[i]] = i;
        bit.add(i, 1);

        for(auto &p: query[i]) {
            ans[p.se] = bit.sum(i) - bit.sum(p.fi-1);
        }
    }

    for (auto &e: ans) {
        print(e);
    }

}


Measured memory_bytes: 35228
/**
*    author:  souzai32
*    created: 02.08.2020 21:05:18
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    int k;
    cin >> k;
    int ans=-1;

    int num=7%k;
    for(int i=1; i<100000000; i++){
        if(num==0){
            ans=i;
            break;
        }
        num*=10;
        num+=7;
        num=num%k;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3672
# 人数分布は一意
import numpy as np
MOD = 10**9 + 7
N = int(input())
A = np.array([int(x) for x in input().split()])

left = np.arange(N)
right = N-1-left
cnt_1 = np.bincount(np.abs(left-right))
cnt_2 = np.bincount(A)

if cnt_1.shape != cnt_2.shape or (cnt_1 != cnt_2).any():
    answer = 0
else:
    answer = pow(2, N//2, MOD)

print(answer)

Measured memory_bytes: 23392
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int n, a;
	double ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		ans += 1.0 / a;
	}
	ans = 1.0 / ans;

	printf("%lf", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int n;cin>>n;
    vector<int>p(n);
    rep(i,n){
        cin>>p.at(i);
    }
    int ans=0;
    for(int i=1;i<n-1;i++){
        if(p.at(i-1)<p.at(i)){
            if(p.at(i)<p.at(i+1)){
                ans++;
            }
        }
        if(p.at(i-1)>p.at(i)){
            if(p.at(i)>p.at(i+1)){
                ans++;
            }
        }   
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3604
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　RedcoderになるためAtCoderを巡る旅をしてます。

　　　 　＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<int> check(N + 1, true);
    rep(i, M) {
        int a;
        cin >> a;
        check[a] = false;
    }
    vector<ll> dp(N + 1);

    dp[0] = 1;
    rep(now, N) {
        REP(next, now + 1, min(N, now + 2) + 1) {
            if(check[next]) {
                dp[next] += dp[now];
                dp[next] %= MOD;
            }
        }
    }
    COUT(dp[N]);
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define N 105
using namespace std;
int n,m,x,y,f[N][N][N],g[N][N][N],r[N][N],c[N][N]; char st[N];
void maxself(int &x,int y){ x=max(x,y);}
int main()
{
	int i,j,k,l;
	scanf("%d %d\n",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%s",st+1);
		for(j=1;j<=m;j++){
			c[j][i]=c[j][i-1],r[i][j]=r[i][j-1];
			if(st[j]=='E') x=i,y=j;
			if(st[j]=='o') r[i][j]++,c[j][i]++;
		  }
	  }
	for(i=0;i<x;i++){
		memcpy(g,f,sizeof(g));
		memset(f,0,sizeof(f));
		for(j=0;j<=n-x;j++)
			for(k=0;k<y;k++)
				for(l=0;l<=m-y;l++){
					maxself(f[j][k][l],g[j][k][l]+(x-i-1>j ? r[x-i-1][min(y+l,m-k)]-r[x-i-1][max(y-k-1,l)] : 0));
					maxself(g[j+1][k][l],g[j][k][l]+(x+j+1<=n-i ? r[x+j+1][min(y+l,m-k)]-r[x+j+1][max(y-k-1,l)] : 0));
					maxself(g[j][k+1][l],g[j][k][l]+(y-k-1>l ? c[y-k-1][min(x+j,n-i)]-c[y-k-1][max(x-i-1,j)] : 0));
					maxself(g[j][k][l+1],g[j][k][l]+(y+l+1<=m-k ? c[y+l+1][min(x+j,n-i)]-c[y+l+1][max(x-i-1,j)] : 0));
				  }
	  }
	cout<<g[n-x][y-1][m-y];
	return 0;
}


Measured memory_bytes: 9472
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def calc(d, mask, probs, g):
    score = 0
    ret = 0
    flags = [mask & (1<<i) for i in range(d)]
    for i in range(d):
        val = (i+1)*100
        p = probs[i][0]
        c = probs[i][1]
        if flags[i]:
            ret += p
            score += c+p*val
    if g <= score:
        return ret
    for i in range(d, -1, -1):
        val = i*100
        p = probs[i-1][0]
        c = probs[i-1][1]
        if flags[i-1]:
            continue
        else:
            if (g - score) > val*(p-1):
                score += val*(p-1)
                ret += p-1
            else:
                np = (g-score+val-1)//val
                score += val*np
                ret += np
                break
    if score < g:
        return 100000
    return ret

def main():
    d, g = rli()
    probs = []
    for i in range(d):
        p, c = rli()
        probs.append([p, c])
    ans = -1
    for i in range(2**d):
        ret = calc(d, i, probs, g)
        # print(bin(i), ret)
        if ans == -1:
            ans = ret
        else:
            ans = min(ans, ret)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s,p="No";
    cin>>n>>s;
    if(n%2==0&&s.substr(0,n/2)==s.substr(n/2,n))
    p="Yes";
     cout<<p;
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<set<ll>> grp(m);
    UnionFind uf(n);
    rep(i, n) {
        ll k;
        cin >> k;
        rep(ii, k) {
            ll l;
            cin >> l;
            l--;
            if (sz(grp[l]) > 0) {
                auto it = grp[l].begin();
                uf.merge(*it, i);
            }
            grp[l].insert(i);
        }
    }
    if (uf.size(0) == n) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 9984
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
// use std::cmp::*;
use std::collections::*;

fn main() {
    input! {
       N:usize, M:usize,
       mut A:[i64;N],
       mut BC:[(usize,i64);M]
    }
    A.sort();
    A.reverse();
    let mut C = vec![0i64; N * 2];
    let mut j = 0;
    BC.sort_by_key(|bc| bc.1);
    BC.reverse();
    for &(b, c) in BC.iter() {
        for i in 0..b {
            C[j] = c;
            j += 1;
        }
        if N <= j + 1 {
            break;
        }
    }
    //println!("A{:?}", A);
    //println!("C{:?}", C);
    let mut ans = 0;
    let mut i = 0;
    let mut j = 0;
    for k in 0..N {
        if A[i] > C[j] {
            ans += A[i];
            i += 1;
        } else {
            ans += C[j];
            j += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 7972
#include <iostream>
typedef long long ll;
using namespace std;

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

    ll min=9223372036854775807LL;
    ll sum_now=0;
    for(int i=0; i<n-1; i++) {
        sum_now+=a[i];
        if(min>abs(sum-2*sum_now)) min = abs(sum-2*sum_now);
    }

    cout << min << endl;

    return 0;
}



Measured memory_bytes: 1792
# coding: utf-8

def main():
    N, A, B = map(int, input().split())
    S = input()
    cnt, cnt_f = 0, 0

    for c in S:
        if c == 'c':
            ans = 'No'
        elif c == 'a':
            if A + B > cnt:
                ans = 'Yes'
                cnt += 1
            else:
                ans = 'No'
        else:
            if A + B > cnt and B > cnt_f:
                ans = 'Yes'
                cnt += 1
                cnt_f += 1
            else:
                ans = 'No'
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#include <iostream>
#include <algorithm>
using namespace std;

long long N, A, B, C[5009];
long long dp[5009][5009];

int main() {
	cin >> N >> A >> B;
	for (int i = 1; i <= N; i++) cin >> C[i];

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) dp[i][j] = (1LL << 60);
	}
	
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		long long r = (1LL << 60);
		for (int j = 0; j <= C[i] - 1; j++) r = min(r, dp[i - 1][j]);
		dp[i][C[i]] = r;
		for (int j = 0; j <= C[i] - 1; j++) { dp[i][j] = dp[i - 1][j] + A; }
		for (int j = C[i] + 1; j <= N; j++) { dp[i][j] = dp[i - 1][j] + B; }
	}

	long long ret = (1LL << 60);
	for (int i = 0; i <= N; i++) ret = min(ret, dp[N][i]);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 195968
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    string s,t;
    cin >> s >> t;
    int ans = 0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 3800
s=sorted
(n,m,*b),a,*q=[map(int,t.split())for t in open(0)]
t=[-1]*n
def r(x):
 while-1<t[x]:x=t[x]
 return x
def u(x):
 x,y=map(r,x)
 if x-y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
[*map(u,q)]
i=c=0
k=j=n+~m<<1
*d,=eval('[],'*n)
for v in a:d[r(i)]+=v,;i+=1
for p in d:
 if p:x,*y=s(p);c+=x;b+=y;j-=1
print((c+sum(s(b)[:j]),'Impossible')[k>n]*(k>0))

Measured memory_bytes: 138816
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int tate[300][300];
int yoko[300][300];
int ue_l[300][300];
int ue_r[300][300];

int main(){
	
	int n, max;
	
	string str[500];
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}else if(n < 2 || n > 300){
			printf("NA\n");
			continue;
		}
		for(int i = 0; i < n; i++){
			cin >> str[i];
		}
		
		for(int x = 0; x < n; x++){
			if(str[0][x] == '1'){
				tate[0][x] = 1;
			}else{
				tate[0][x] = 0;
			}
		}
		for(int y = 1; y < n; y++){
			for(int x = 0; x < n; x++){
				if(str[y][x] == '1'){
					tate[y][x] = tate[y - 1][x] + 1;
				}else{
					tate[y][x] = 0;
				}
			}
		}
		
		max = 0;
		
		for(int y = 0; y < n; y++){
			for(int x = 0; x < n; x++){
				if(max < tate[y][x]){
					max = tate[y][x];
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			if(str[y][0] == '1'){
				yoko[y][0] = 1;
			}else{
				yoko[y][0] = 0;
			}
		}
		for(int x = 1; x < n; x++){
			for(int y = 0; y < n; y++){
				if(str[y][x] == '1'){
					yoko[y][x] = yoko[y][x - 1] + 1;
				}else{
					yoko[y][x] = 0;
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			for(int x = 0; x < n; x++){
				if(max < yoko[y][x]){
					max = yoko[y][x];
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			if(str[y][0] == '1'){
				ue_l[y][0] = 1;
			}else{
				ue_l[y][0] = 0;
			}
		}
		
		for(int x = 0; x < n; x++){
			if(str[0][x] == '1'){
				ue_l[0][x] = 1;
			}else{
				ue_l[0][x] = 0;
			}
		}
		
		for(int x = 1; x < n; x++){
			for(int y = 1; y < n; y++){
				if(str[y][x] == '1'){
					ue_l[y][x] = ue_l[y - 1][x - 1] + 1;
				}else{
					ue_l[y][x] = 0;
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			for(int x = 0; x < n; x++){
				if(max < ue_l[y][x]){
					max = ue_l[y][x];
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			if(str[y][n - 1] == '1'){
				ue_r[y][n - 1] = 1;
			}else{
				ue_r[y][n - 1] = 0;
			}
		}
		
		for(int x = 0; x < n; x++){
			if(str[0][x] == '1'){
				ue_r[0][x] = 1;
			}else{
				ue_r[0][x] = 0;
			}
		}
		
		for(int y = 1; y < n; y++){
			for(int x = 0; x < n - 1; x++){
				if(str[y][x] == '1'){
					ue_r[y][x] = ue_r[y - 1][x + 1] + 1;
				}else{
					ue_r[y][x] = 0;
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			for(int x = 0; x < n; x++){
				if(max < ue_r[y][x]){
					max = ue_r[y][x];
				}
			}
		}
		printf("%d\n", max);
	}
	
	return 0;
}

Measured memory_bytes: 2496
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	int h = 20;
	int w = 99;

	vector<string> white(h, string(w, '#'));
	vector<string> black(h, string(w, '.'));

	a--;
	b--;
	for (int i = 0; i < h; i += 2) {
		for (int j = 0; j < w; j += 2) {
			if (a > 0) {
				white[i][j] = '.';
				a--;
			}
		}
	}

	for (int i = 1; i < h; i += 2) {
		for (int j = 0; j < w; j += 2) {
			if (b > 0) {
				black[i][j] = '#';
				b--;
			}
		}
	}

	cout << 2 * h << " " << w << endl;
	for (auto s: white) {
		cout << s << endl;
	}
	for (auto s: black) {
		cout << s << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;

public class Main
{
	public static int A[] = new int[20];
	public static boolean rec(int s, int n, int now)
	{
		if(n == -1)
		{
			if(now == s)
			{
				return true;
			}
			return false;
		}
		return rec(s, n - 1, now + A[n]) | rec(s, n - 1, now);
	}
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n, q, m[] = new int[200];
		n = sc.nextInt();
		for(int i = 0; i < n; i++)
		{
			A[i] = sc.nextInt();
		}
		q = sc.nextInt();
		for(int i = 0; i < q; i++)
		{
			m[i] = sc.nextInt();
		}
		for(int i = 0; i < q; i++)
		{
			if(rec(m[i], n - 1, 0))
			{
				System.out.println("yes");
			}
			else
			{
				System.out.println("no");
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 26836
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll f(ll x){
 ll ret=0;
  while(x>0){
   ret+=x%10;
    x/=10;
  }
  
  
  return ret;
}

int main(){cout<<fixed<<setprecision(10);
          int a,b;
           cin>>a>>b;
           cout<<(a*b%2==0 ? "Even":"Odd")<<endl;
          }

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, n;
  cin >> A >> B;
// 回分数 abcba
// a = 1-9, b,c = 0-9
// 高々9*10*10=900しかない
  int a1=(A/10000)%10, a2=(A/1000)%10, a3=(A/100)%10;
  int b1=(B/10000)%10, b2=(B/1000)%10, b3=(B/100)%10;
  
  if (a1<b1){
    n+=(b1-a1-1)*100;
    n+=(9-a2)*10;
    n+=9-a3;
    if(A<=10001*a1+1010*a2+100*a3)
      n++;
    n+=b2*10;
    n+=b3;
    if(B>=10001*b1+1010*b2+100*b3)
      n++;
  }
  else{
    if(a2<b2){
      n+=(b2-a2-1)*10;
      n+=9-a3;
      if(A<=10001*a1+1010*a2+100*a3)
        n++;
      n+=b3;
      if(B>=10001*b1+1010*b2+100*b3)
        n++;
    }
    else{ //a1=b1, a2=b2
      if(a3<b3){
        n+=b3-a3-1;
        if(A<=10001*a1+1010*a2+100*a3)
          n++;
        if(B>=10001*b1+1010*b2+100*b3)
          n++;
      }
      else{
        if(A<=10001*a1+1010*a2+100*a3 || B>=10001*b1+1010*b2+100*b3)
          n++;
      }        
    }
  }
    cout << n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

string a = "keyence", b = "ecneyek";

int main() {
    string s; cin >> s;
    string t = s; reverse(t.begin(), t.end());

    int p = 0, q = 0;
    while (p<7&&s[p]==a[p]) p++;
    while (q<7&&t[q]==b[q]) q++;

    cout << (p+q>=7? "YES": "NO") << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+7;

LL a[maxn];
int n;
bool vis[70];
LL solve(LL x,LL add,LL tar){
    me0(vis);
    LL nw=1LL<<60;
    LL mx =nw;
    fod(i,60,0){
        if((add&nw)&&(x+nw<=tar)){
            vis[i]=true;x+=nw;
        }
        if((add&nw)&&(x+nw>tar)){
            mx = min(mx, nw+x);
        }
        nw>>=1;
    }
    if(x==tar) return x;
    nw=1;
    fo(i,0,60){
        if((add&nw)&&!vis[i]){
            x+=nw;break;
        }
        nw<<=1;
    }
    x = min(mx,x);
    return x;
}

int main(){
//    op;

    read(n);
    fo(i,1,n) scanf("%lld",&a[i]);
    LL sum = 0;
    fo(i,2,n) sum^=a[i];

    LL ans=1e18;

    fo(i,2,2){
        LL tar = sum^a[i];
        LL t = a[1]+a[i];
        if(t<tar||((t-tar)&1)||(tar&((t-tar)/2))) continue;
        LL x = (t-tar)/2;
        if(x>=a[i]){
            ans = min(ans, x-a[i]);continue;
        }
        x = solve(x,tar,a[i]);
        if(x<a[i]) continue;
        if(x==a[1]+a[i]) continue;
        ans = min(ans, x-a[i]);
    }
    if(ans==1e18) ans=-1;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3812
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>
#include<string.h>
#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define M -99999999
#define MOD 1000000007
 
//	rep(i,10)cout << i << endl;
using namespace std;

	int w,h,h_sum[2001][2001],w_sum[2001][2001];
/*void test(int[][] data){
	rep(i,h){
		rep(j,w){
			cout << data[i][j] << " " ;
		}
		cout << endl;
	}
	cout << endl;
}*/

int main(void){
	string m[2001];
	cin >> h >> w;
	rep(i,h){
		cin >> m[i];
		rep(j,w){
			int a = 0;
			if(m[i][j] == '#') a = -1;
			h_sum[i][j] = a;
			w_sum[i][j] = a;
		}
	}
	rep(i,h){
		int cnt = 1;
		rep(j,w){
			if(w_sum[i][j] != -1) w_sum[i][j] = cnt++;
			else cnt = 1;
		}
	}
	rep(j,w){
		int cnt = 1;
		rep(i,h){
			if(h_sum[i][j] != -1) h_sum[i][j] = cnt++;
			else cnt = 1;
		}
	}
	
	rep(i,h){
		int now = 0;
		for(int j = w-1;j>=0;j--){
			if(w_sum[i][j] != -1){
				if(now == 0) now = w_sum[i][j]; 
				w_sum[i][j] = now;
			}
			else now = 0;
		}
	}
	rep(j,w){
		int now = 0;
		for(int i = h-1;i>=0;i--){
			if(h_sum[i][j] != -1){
				if(now == 0) now = h_sum[i][j]; 
				h_sum[i][j] = now;
			}
			else now = 0;
		}
	}
	
	
	int ans = 0;
	rep(i,h){
		rep(j,w){
			if(m[i][j] != '#'){
				ans = max(ans, h_sum[i][j] + w_sum[i][j] -1);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35584