akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int n, ans = 0;
char dummy;
vector<int> memo[2];
void solve();

int main() {
  int i, a, b, c, x, y, z;
  while(1) {
    cin >> n;
    if(n == 0) break;
    ans = 0;
    for(i = 0; i < n; ++i) {
      cin >> a >> dummy >> b >> dummy >> c >> x >> dummy >>
          y >> dummy >> z;
      memo[0].push_back(a * 3600 + b * 60 + c);
      memo[1].push_back(x * 3600 + y * 60 + z);
    }
    for(i = 0; i < 2; ++i)
      sort(memo[i].begin(), memo[i].end());
    solve();
    cout << ans << endl;
    for(i = 0; i < 2; ++i)
      memo[i].erase(memo[i].begin(), memo[i].end());
  }
  return 0;
}

void solve() {
  int now = 0, ns = 0, ng = 0;
  for(ng = 0; ng < n; ++ng) {
    ns = ng;
    while(memo[0][ns] < memo[1][ng] && ns < n) {
      ++now;
      ++ns;
    }
    ans = max(ans, now);
    now = 0;
  }
}


Measured memory_bytes: 3276
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil
(defun main ()
  (let* ((n (read))
         (x (read))
         (end (- (* 2 n) 1))
         (seq (loop for i from 1 to end collect i))
         (res (make-array end :element-type 'uint32)))
    (declare (uint32 n x))
    (cond ((or (= x 1) (= x end))
           (println "No"))
          ((= n 2)
           (format t "Yes~%1~%2~%3~%"))
          (t
           (let ((fixed (if (> x 2)
                            (list (- x 2) x (+ x 1) (- x 1))
                            (list (+ x 2) x (- x 1) (+ x 1)))))
             (setf (aref res (- n 2)) (elt fixed 0)
                   (aref res (- n 1)) (elt fixed 1)
                   (aref res n) (elt fixed 2)
                   (aref res (+ n 1)) (elt fixed 3))
             (setf seq (set-difference seq fixed))
             (loop for i from 0 below (- n 2)
                   for a = (pop seq)
                   do (setf (aref res i) a))
             (loop for i from (+ n 2) below end
                   for a = (pop seq)
                   do (setf (aref res i) a))
             (println "Yes")
             (loop for a across res
                   do (println a)))))))

#-swank(main)


Measured memory_bytes: 21988
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<int> a, b;
    vector<int> tmp;
    map<int,  int> tmp3;
    vector<vector<int>> list(n+1, tmp);
    vector<map<int, int>> color(n+1, tmp3);
    rep(i, n - 1) {
      int x, y;
      cin >> x >> y;
      a.push_back(x);
      b.push_back(y);
      list[a[i]].push_back(b[i]);
      list[b[i]].push_back(a[i]);
    }
    int maximcolor=0;
    rep2(i, 1, n+1){
        int size = list[i].size();
        maximcolor = max(maximcolor, size);
    }
    cout << maximcolor << endl;
    queue<int> tyoten;
    int nowcolor = 0;
    int now = 1;
    while(1){
        int len = list[now].size();
        int dis = 0;
        rep(i, len){
            if(now<list[now][i]){
                tyoten.push(list[now][i]);
                if (i+1+dis == nowcolor) {
                    dis++;
                }
                color[now][list[now][i]] = i + 1 + dis;
                color[list[now][i]][list[now][i]] = i + 1 + dis;
            }else{
                dis--;
            }
        }
        if(tyoten.empty()){
            break;
        }
        now = tyoten.front();
        tyoten.pop();
        nowcolor = color[now][now];
    }
    rep(i, n-1){
        cout << color[a[i]][b[i]] << endl;
    }
    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int N; cin >> N;
	V<int> A(N), B(N), C(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N) cin >> C[i];
	sort(ALL(A));
	sort(ALL(B));
	sort(ALL(C));

	ll ans = 0;
	rep(i, N) {
		ll l = lower_bound(ALL(A), B[i]) - A.begin();
		ll r = C.end() - upper_bound(ALL(C), B[i]);
		ans += l * r;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
import qualified Data.ByteString.Char8 as B
import Data.List
 
main = do
  _ <- getLine
  as <- map (maybe undefined fst . B.readInt) . B.words <$> B.getLine
  print (sarray 0 as)
 
sarray acc [] = acc
sarray acc [x] = acc + 1
sarray acc xxs@(x:xs)
  | lg > ls = sarray (acc + 1) (drop (lg + 1) xxs)
  | otherwise = sarray (acc + 1) (drop (ls + 1) xxs)
  where
    ds = map signum $ zipWith (-) xs xxs
    lg = length $ takeWhile (/= -1) ds
    ls = length $ takeWhile (/= 1) ds

Measured memory_bytes: 16636
#include "bits/stdc++.h"

using namespace ::std;

typedef long long ll;
typedef unsigned long long ull;


int px[] = {0, 1, 0, -1, 1, -1, -1, 1};
int py[] = {1, 0, -1, 0, 1, 1, -1, -1};

int main()
{
    int test, n, m, a, b;

    //scanf("%d", &test);


    int in[5];
    for(int i = 0; i<5; ++i) scanf("%d", &in[i]);

    int p = 1;

    for(int i = 0; i<5; ++i)
    {
        if(in[i] == p) p += 1;
    }
    cout << p << endl;
}

Measured memory_bytes: 3760
import math

N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
a, b = 0, 0
P_l = [0] * N
Q_l = [0] * N
for i in range(N-1):
  P_l[P[i]-1] = 1
  a += (P[i] - 1 - sum(P_l[:P[i]-1])) * math.factorial(N-i-1)
  Q_l[Q[i]-1] = 1
  b += (Q[i] - 1 - sum(Q_l[:Q[i]-1])) * math.factorial(N-i-1)
print(abs(a-b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1e9 + 7;
const int Maxn = 5e3 + 10;
const int Maxm = 2e2 + 10;
const ll Inf = 1e16;

ll a[Maxn], ps[Maxn], A[Maxn][Maxm], val[Maxn][Maxm];

stack<ll> st[Maxm];


ll seg[4 * Maxn];
ll lazy[4 * Maxn];

void shift(int id){
	if(lazy[id] == 0) return ;
	for(int i = 0; i <= 1; i++){
		lazy[id << 1 | i] += lazy[id];
		seg[id << 1 | i] += lazy[id];
	}
	lazy[id] = 0;
}

void add(int id, int l, int r, ll val, int L, int R){
	if(r <= L || l >= R) return ;
	if(l <= L && R <= r){
		seg[id] += val;
		lazy[id] += val;
		return ;
	}
	int mid = (L + R) >> 1;
	shift(id);
	add(id << 1, l, r, val, L, mid);
	add(id << 1 | 1, l, r, val, mid, R);
	seg[id] = max(seg[id << 1], seg[id << 1 | 1]);
	return ;
}

ll get_max(int id, int l, int r, int L, int R){
	if(r <= L || R <= l) return -Inf;
	if(l <= L && R <= r){
		return seg[id];
	}
	int mid = (L + R) >> 1;
	shift(id);
	return max(get_max(id << 1, l, r, L, mid),
		get_max(id << 1 | 1, l, r, mid, R));
}


int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, m;
	cin >> n >> m;
	for(int i = 2; i <= n; i++) cin >> a[i];
	ps[1] = 0;
	for(int i = 2; i <= n; i++) ps[i] = ps[i - 1] + a[i];
	for(int i = 1; i <= n; i++) add(1, i, i + 1, ps[i], 1, n + 1);
	//for(int i = 1; i <= n; i++) cerr << get_max(1, i, i + 1, 1, n + 1) << " \n"[i == n];
	fill(A[0], A[0] + Maxm, Inf);
	for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> A[i][j];
	for(int i = 1; i <= m; i++) st[i].push(0);
	ll ans = 0, tp;
	for(int i = 1; i <= n; i++){
		//for(int i = 1; i <= n; i++) cerr << get_max(1, i, i + 1, 1, n + 1) << " \n"[i == n];
		for(int j = 1; j <= m; j++){
			while(A[i][j] >= A[st[j].top()][j]){
				tp = st[j].top();
				add(1, val[tp][j] + 1, tp + 1, -A[tp][j], 1, n + 1);
				st[j].pop();
			}
			val[i][j] = st[j].top();
			st[j].push(i);
			add(1, val[i][j] + 1, i + 1, A[i][j], 1, n + 1);
		}
		ans = max(ans, get_max(1, 1, i + 1, 1, n + 1) - ps[i]);
	}
	//for(int i = 1; i <= n; i++) cerr << get_max(1, i, i + 1, 1, n + 1) << " \n"[i == n];
	cout << ans;
	return 0;
}



Measured memory_bytes: 17152
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1e18;
int v, e, s;

typedef struct edge_{
		int from, to, cost;
		edge_(int f, int t, int c): from(f), to(t), cost(c){};
} edge;

vector<edge> vec;
ll d[1001];

bool bellmanford(){
		fill(d, d+v, linf);
		bool updated;
		d[s] = 0;
		for(int i = 0; i < v; i++){
				updated = false;
				for(auto itr = vec.begin(); itr != vec.end(); ++itr){
						int from = (*itr).from;
						int to = (*itr).to;
						int cost = (*itr).cost;
						if(d[from] != linf && d[from] + cost < d[to]){
								updated = true;
								d[to] = d[from] + cost;
						}
				}
		}
		return !updated;
}

int main(int argc, char const* argv[])
{
	cin >> v >> e >> s;
	for(int i = 0; i < e; i++){
			int a, b, c;
			cin >> a >> b >> c;
			vec.pb(edge(a, b, c));
	}
	if(bellmanford()){
			for(int i = 0; i < v; i++){
					if(d[i] != linf)cout << d[i] << endl;
					else cout << "INF" << endl;
			}
	}else{
			cout << "NEGATIVE CYCLE" << endl;
	}
	return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define INF 1000000007
#define fi first
#define se second

using namespace std;

typedef pair<int,int>pi;
typedef pair<double,int>pd;
typedef pair<pd,pi>PP;

struct edge
{
    int to,dist,limit;
};

int n,m,s,g;
double dp[31][31][31];
vector<edge> G[31];

void dijkstra()
{
    rep(i,n){
        rep(j,n){
            rep(k,31){
                dp[i][j][k] = INF;
            }
        }
    }
    priority_queue<PP,vector<PP>,greater<PP> > que;
    que.push(PP(pd(0.0,s),pi(s,0)));
    dp[s][s][0] = 0.0;
    while(!que.empty()){
        PP pp = que.top();
        pd p = pp.fi;
        pi q = pp.se;
        que.pop();
        double cost = p.fi;
        int v = p.se, prv = q.fi, sp = q.se;
        if(dp[v][prv][sp] < cost) continue;
        if(v == g && sp == 1){
            printf("%.12lf\n",cost);
            return;
        }
        for(int i=sp-1;i<=sp+1;i++){
            if(i <= 0) continue;
            for(auto& e : G[v]){
                if(e.to != prv && i <= e.limit && dp[e.to][v][i] > cost+(double)e.dist/i){
                    dp[e.to][v][i] = cost+(double)e.dist/i;
                    que.push(PP(pd(dp[e.to][v][i],e.to),pi(v,i)));
                }
            }
        }
    }
    printf("unreachable\n");
}

int main()
{
    while(1){
        cin >> n >> m;
        if(n == 0){
            break;
        }
        rep(i,n){
            G[i].clear();
        }
        cin >> s >> g;
        s--,g--;
        rep(i,m){
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            G[a-1].push_back((edge){b-1,c,d});
            G[b-1].push_back((edge){a-1,c,d});
        }
        dijkstra();
    }
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];

	int ans = 0;
	rep(i,n){
		int j = i;
		while(j < n and a[j] == a[i]) j++;
		ans += (j - i) /2;
		i = j - 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
	int ening;
	cin>>ening;
	while(ening != 0){
		string result;
		int runner = 0;
		int score = 0;
		int out = 0;
		while(cin>>result){
			if(result == "HIT"){
					runner++;
					if(runner == 4){
						score+=1;
						runner=3;
					}
			}
			else if(result ==  "OUT"){
					out++;
			}
			else if(result == "HOMERUN"){
					score += runner + 1;
					runner = 0;
			}
			if(out == 3){
				break;
			}
		}
		cout<<score<<endl;
		ening -= 1;
	}
	return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<math.h>
#define N 10000

main(){
  int a,x,i,count=0;


  while(scanf("%d",&x) != EOF){
    a=1;
    if( x == 2 )
      a=1;
    else if( x < 2 || x%2 == 0)
      a=0;
    else{
      for( i = 3; i <= sqrt((double)x); i += 2 ){
	if( x%i == 0 ){
	  a=0;
	  break;
	}
	else
	 a=1;
      }
    
    }
    if(a==1)
      count++;


  }

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

  return 0;
}

Measured memory_bytes: 596
import java.util.*;
import java.lang.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		String n=sc.next();
		int a[]=new int [n.length()+1];
		int ans=0;
		for(int i=0;i<n.length();i++)
		{
			a[i]=n.charAt(i)-'0';
		}
		for(int i=0;i<n.length();i++)
		{
			ans=ans+a[i];
		}
		if(ans%9==0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 40820
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <time.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;


int main(int argc, char* argv[])
{
    int h,a;
    scanf("%d%d", &h, &a);
    printf("%d\n", (h-1+a)/a);


    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

X,Y=LI()

print(X+Y//2)

Measured memory_bytes: 3320
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	char s[100+2];
	while(scanf("%100[a-z]\n", s)==1)
	{
		int l=strlen(s);
		int ans=0;
		for(int i=0;i<l/2;i++)
		{
			if(s[i]!=s[l-1-i]) ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <iomanip>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#define ll long long
         
using namespace std;
     
long long gcd(int x, int y){
     if ( x == 0 ) return y;
     
     return gcd(y%x, x);
}
     
long long lcm(int x, int y){
     if ( y == 0 ){
          return x;
     }
     
     return x*y/gcd(x, y);
}
     
int min(int a, int b){
     return a > b ? b : a;
}
     
double max(double a, double b){
     return a > b ? a : b;
}

int main()
{
     cin.sync_with_stdio( false );

     ll n,k;
     cin>>n>>k;

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

     sort(a.begin(), a.end());

     ll suma = 0;
     if ( k >= n ){
          cout<<0<<endl;
     }else{
          for (ll i=n-1-k;i>=0;i--){
               suma+=a[i];
          }

          cout<<suma<<endl;
     }
}

Measured memory_bytes: 4824
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int EX=100,EY=100;
  while(true){
    int m,n,t,p;
    //入力
    cin >>n>>m>>t>>p;

    //終了条件
    if(n==0&&m==0)break;

    //折り紙のinit
    int map[EX][EY];
    for(int x=0;x<EX;x++){
      for(int y=0;y<EY;y++){
        if(x<n&&y<m){
          map[x][y]=1;
        }else{
          map[x][y]=0;
        }
      }
    }


    //折り返し動作の処理
    for(int i=0;i<t;i++){
      int d,c;
      cin >>d>>c;
      //init
      int n_map[EX][EY];
      for(int x=0;x<EX;x++){
        for(int y=0;y<EY;y++){
          if(x<n&&y<m){
            n_map[x][y]=1;
          }else{
            n_map[x][y]=0;
          }
        }
      }

      //処理
      if(d==1){
        for(int x=0;x+c<EX;x++){
          for(int y=0;y<EY;y++){
            n_map[x][y]=map[x+c][y];
          }
        }
        for(int x=0;x<c;x++){
          for(int y=0;y<EY;y++){
            n_map[x][y]+=map[c-(x+1)][y];
          }
        }

      }else{
        for(int x=0;x<EX;x++){
          for(int y=0;y+c<EY;y++){
            n_map[x][y]=map[x][y+c];
          }
        }
        for(int x=0;x<EX;x++){
          for(int y=0;y<c;y++){
            n_map[x][y]+=map[x][c-(y+1)];
          }
        }

      }
      //mapにn_mapを転送
      //cout<<"start"<<endl;
      for(int x=0;x<EX;x++){
        for(int y=0;y<EY;y++){
          map[x][y]=n_map[x][y];
          //cout<<map[x][y]<<" ";
        }
        //cout<<endl;
      }
      //cout<<"end"<<endl;
    }
    //穴あけ処理
    for(int i=0;i<p;i++){
      int x,y;
      cin >>x >> y;
      cout<<map[x][y]<<endl;
    }
  }
}


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

#define int long long
#define pii pair<int,int>
signed main(){
  int n,m;
  cin >> n >> m;

  vector<pii> v;

  for(int i = 1;i<=m;i++){
    int x,y;
    cin >> y >> x;
    v.push_back({x,y});
    //cin >> a[i] >> b[i];
  }

  sort(v.begin(), v.end());

  int mn = 100005, mx = 0;
  int ans = 0;
  for(int i = 1;i<=m;i++){
    pii p = v[i-1];
    int x = p.second, y = p.first;

    if((x<= mn && y<=mn) || (x>=mx && y>=mx)){
        ans++;
        mn = min(mn, y-1);
        mx = max(mx, y);
    }
  }

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


Measured memory_bytes: 2420
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int N;
int freq[100000+1];

int main(void){
    cin>>N;
    REP(i,N){
        int a;
        cin>>a;
        freq[a]++;
    }
    int ans=0;
    FOR(i,1,100000)
        ans=max(ans,freq[i-1]+freq[i]+freq[i+1]);
    cout<<ans<<endl;
     return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

//二分累乗法
ll mult(ll n,ll m){//n^m%modを求める
    if(m==1){
        return n%mod;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%mod;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%mod;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    map<ll,ll> a;
    if(n==1){
      ll x;
      cin>>x;
      cout<<1<<endl;
      return 0;
    }
    rep(i,n){
      ll x;
      cin>>x;
      a[x]++;
    }
    if(n%2==0){
      bool flag=true;
      ll cnt=1;
      for(auto itr:a){
        if(itr.first!=cnt || itr.second!=2) flag=false;
        cnt+=2;
      }
      if(!flag){
        cout<<0<<endl;
        return 0;
      }
      cout<<mult(2,n/2)<<endl;
    }else{
      bool flag=true;
      ll cnt=0;
      for(auto itr:a){
        if(itr.first!=cnt){
          flag=false;
          break;
        }
        if(cnt==0 && itr.second!=1){
          flag=false;
          break;
        }
        if(cnt>0 && itr.second!=2){
          flag=false;
          break;
        }
        cnt+=2;
      }
      if(!flag){
        cout<<0<<endl;
        return 0;
      }
      cout<<mult(2,n/2)<<endl;
    }
}

Measured memory_bytes: 4224
n, k = map(int, input().split())

d = [0] * k
a = [0] * k

for i in range(k):
    d[i] = int(input())
    a[i] = list(map(int, input().split()))

funuke_list = []
for j in a:
    funuke_list += j

ans = n - len(set(funuke_list))

print(ans)

Measured memory_bytes: 9192
#include <iostream>
using namespace std;
int main(void){
    long long n, ans = 0;
    cin >> n;
    if(n%2 == 0){
        long long p = 10;
        while(p <= n){
            ans += n/p;
            p *= 5;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*考えを書くスペース
  累乗和で解く

  ・総和を求める
  ・取り消すところの一つ先を見る
*/
//main.cpp----------------------------
#define max_n 100

void solve();

string s;

int main() {
  cin >> s;

  solve();

  return 0;
}

void solve() {

  string t;
  rep(i, 4) {
    t += s[i];
  }
  int y = atoi(t.c_str());
  if(y<2019) {
    cout << "Heisei" << endl;
    return;
  }else if(y>2019) {
    cout << "TBD" << endl;
    return;
  }
  string r;
  for(int i=5; i<7; ++i) r += s[i];
  y = atoi(r.c_str());
  if(y<4) {
    cout << "Heisei" << endl;
    return;
  }else if(y>4) {
    cout << "TBD" << endl;
    return;
  }
  string p;
  for(int i=8; i<10; ++i) p += s[i];
  y = atoi(p.c_str());
  if(y<=30) {
    cout << "Heisei" << endl;
  }else {
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;sc.hasNext();){
			double v=sc.nextDouble();
			double y=v*v/19.6;
			int N=(int)(y/5+2);
			println(N+"");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    for (int h = 1; h <= 3500; h++) {
      for (int n = 1; n <= 3500; n++) {
        long a = (long)N*h*n;
        long b = (long)4*h*n-(long)N*n-(long)N*h;
        if (b != 0 && a%b == 0
            && 1 <= a/b && a/b <= 3500) {
          System.out.println(h+" "+n+" "+a/b);
          return;
        }
      }
    }
  }
}

Measured memory_bytes: 23892
import java.util.*;

public class Main {
	

	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		
		long end=1;
		for(int i=0;i<18;i++) {
			end*=10;
		}
		
		long ans=1;
		
		long[] a=new long[n];
		
		for(int i=0;i<n;i++) {
			a[i]=sc.nextLong();
			if(a[i]==0) {
				System.out.println(0);
				System.exit(0);
			}
		}
		
		for(int i=0;i<n;i++) {
			if(a[i]>end) {
				System.out.println(-1);
				System.exit(0);
			}
		}
		Arrays.sort(a);
		
		for(int i=0;i<n;i++) {
			if(a[i]<=Math.floor(end/ans)) {
				ans*=a[i];
			}
			else {
				ans=-1;
				break;
			}
		}
		
		System.out.println(ans);
	}

}



Measured memory_bytes: 61612
n = int(input())
a = list(map(int,input().split()))

sum_a=[0]*n
sum_a[0]=a[0]
for i in range(1,n):
  sum_a[i]=sum_a[i-1]+a[i]

ans = float("inf")
for i in range(n-1):
  ans=min(ans,abs(sum_a[i]-(sum_a[n-1]-sum_a[i])))

print(ans)


Measured memory_bytes: 24832
#include <iostream>
#include <cstring>
using namespace std;

int main() {
  char str[30];
  int l;
  char tmp;

  cin >> str;
  l = strlen(str);
  for (int i=0; i<l/2; i++) {
    tmp = str[i];
    str[i] = str[l-i-1];
    str[l-i-1] = tmp;
  }
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 1136
A, B = [int(v) for v in input().split(' ')]

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2

    i = 3
    while i * i <= n:
        if n % i == 0:
            a.append(i)
            n //= i
        else:
            i += 2

    if n != 1:
        a.append(n)
    return a

a_fact = prime_factorize(A)
b_fact = prime_factorize(B)

print(len(set(a_fact) & set(b_fact)) + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i; i<(n); i++)
using namespace std;

  
int main() {

  int n;
  cin >> n;
  
  vector<int> h(n);
  
  rep(i, n) cin >> h[i];
  
  int highest = h[0];
  int ans = 1;
  
  for(int i=1; i<n; i++)
  {
    if(highest <=h[i])
    {
      highest = h[i];
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N, T;
    cin >> N >> T;

    vector<int> c(N), t(N);
    for (int i = 0; i < N; i++) cin >> c[i] >> t[i];

    int minV = INT_MAX;
    for (int i = 0; i < N; i++) {
        if (t[i] <= T) {
            minV = min(minV, c[i]);
        }
    }

    if(minV == INT_MAX) cout << "TLE";
    else cout << minV;

    return 0;
}











































































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}


int main() {
    int n;
    cin >> n;
    int z;
    string ans = "APPROVED";
    for(int i = 0;i < n;i++){
        cin >> z;
        if(z % 2 == 0 && z % 3 != 0 && z % 5 != 0){
            ans = "DENIED";
            break;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	int w,h;
	
	class Goods{
		int num, d, start, end;

		public Goods(int num, int d, int start, int end) {
			this.num = num;
			this.d = d;
			this.start = start;
			this.end = end;
		}
	}
	
	class State{
		int x,y,step, bit, value;

		public State(int x, int y, int step, int bit, int value) {
			this.x = x;
			this.y = y;
			this.step = step;
			this.bit = bit;
			this.value = value;
		}

		@Override
		public String toString() {
			return "State [x=" + x + ", y=" + y + ", step=" + step + ", bit="
					+ bit + ", value=" + value + "]";
		}
		
	}
	
	private void doit(){
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) ==0) break;
			char [][] data = new char[h][w];
			int sx = -1, sy = -1;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					data[i][j] = sc.next().charAt(0);
					if(data[i][j] == 'P'){
						sx = j;
						sy = i;
						data[i][j] = '.';
					}
				}
			}
			int n = sc.nextInt(), maxT = 0;
			HashMap<Integer, Goods> map = new HashMap<Integer, Main.Goods>();
			for(int i = 0; i < n;i++){
				int num = sc.nextInt();
				int d = sc.nextInt();
				int start = sc.nextInt();
				int end = sc.nextInt();
				map.put(num, new Goods(i, d, start, end));
				maxT = Math.max(maxT, end);
			}
			
			LinkedList<State> open = new LinkedList<Main.State>();
			open.add(new State(sx, sy, 0, 0, 0));
			boolean [][][][] close = new boolean[h][w][1 << n][maxT + 1];
			close[sy][sx][0][0] = true;
			int ans = 0;
			while(! open.isEmpty()){
				State now = open.poll();
				ans = Math.max(ans, now.value);
				if(now.step >= maxT){
					break;
				}
				if(now.bit == (1 << n) - 1){
					break;
				}
				for(int i = 0; i < 4; i++){
					int xx = now.x + vx[i];
					int yy = now.y + vy[i];
					if(! isOK(xx,yy)) continue;
					if(data[yy][xx] != '.') continue;
					int nextstep = now.step + 1;
					int nextbit = now.bit;
					int nextvalue = now.value;
					for(int j = 0; j < 4; j++){
						int xxx = xx + vx[j];
						int yyy = yy + vy[j];
						if(! isOK(xxx, yyy)) continue;
						if(data[yyy][xxx] != '.'){
							Goods g = map.get(data[yyy][xxx] - '0');
							if(g.start <= nextstep && nextstep < g.end){
								if((nextbit & (1 << g.num)) > 0) continue;
								nextbit = nextbit | (1 << g.num);
								nextvalue += g.d;
							}
						}
					}
					if(close[yy][xx][nextbit][nextstep]) continue;
					open.add(new State(xx, yy, nextstep, nextbit, nextvalue));
					close[yy][xx][nextbit][nextstep] = true;
				}
				
			}
			System.out.println(ans);
		}
	}

	private boolean isOK(int xx, int yy) {
		if(0 <= xx && xx < w && 0 <= yy && yy < h) return true;
		return false;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
int main(){
    cin>>n;
    vector<int> a(n);
    rep(i,n){cin>>a.at(i);}
        int attention=1;
    for(int i=0;i<n;i++){
        if(a.at(i)==attention){
            attention++;
        }
    }
    if(attention==1){
        cout<<-1<<endl;
    }
    else{
        cout<<n-attention+1<<endl;
    }
    return 0;
}




Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
using namespace std;

int main() {
	int N, M;

	// N: #switch, M:dennkyuu
	cin >> N >> M;
	vector<int> SW(N);

	for (size_t i=0; i<M; i++) {
		int K = 0;
		cin >> K;
		for (size_t j=0; j<K; j++) {
			int sw_id = 0;
			cin >> sw_id;
			sw_id--;
			SW.at(sw_id) |= (1 << i);
		}
	}
	int P=0;
	for(size_t i=0; i<M; i++) {
		int x;
		cin >> x;
		P |= x << i;
	}

	// finish to store input
	int total = 0;
	for (size_t s=0; s<(1<<N);s++) {
		int t = 0;
		for (size_t i=0; i<N; i++) {
			if ((s >> i) & 1) {
				t ^= SW.at(i);
			}
		}
		if (t == P) {
			total++;
		}
	}

	cout << total << endl;

}

Measured memory_bytes: 256
let rec fix ~f x = f (fix ~f) x

let hands = [|'r'; 's'; 'p'|]

let () =
  Scanf.scanf "%d %d %d %d %d %s" @@ fun n k r s p t ->
  let wp = [|r; s; p|] in
  let calc m =
    fix 0 [|0; 0; 0|] ~f:(fun f i mem ->
      if i * k + m >= n then Array.fold_left max 0 mem
      else 
        [|0; 1; 2|]
        |> Array.map (fun j ->
          let c = if hands.((j+1) mod 3) = t.[i * k + m] then wp.(j) else 0
          in c + max mem.((j+1) mod 3) mem.((j+2) mod 3))
        |> f (i+1))
  in
  fix 0 0 ~f:(fun f i ans -> if i >= k then ans else f (i+1) (ans + calc i))
  |> Printf.printf "%d\n"


Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

const double INF = 1<<29;
const double EPS = 1e-8;

struct Vec { double x, y, z; };
Vec operator+(const Vec& a, const Vec& b) {
    return { a.x + b.x, a.y + b.y, a.z + b.z };
}
Vec operator-(const Vec& a, const Vec& b) {
    return { a.x - b.x, a.y - b.y, a.z - b.z };
}
Vec operator*(const Vec& v, double n) {
    return { v.x * n, v.y * n, v.z * n };
}
double operator*(const Vec& a, const Vec& b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
}
double abs(const Vec& v) {
    return pow(v * v, 0.5);
}

double dist_l2p(Vec a, Vec b, Vec p) {
    Vec l = (b - a) * (1.0 / abs(b - a));
    double len = l * (p - a);
    if (len < 0) return abs(a - p);
    if (len > abs(b - a)) return abs(b - p);
    return abs((l * len) - (p - a));
}

double dist_l2l(Vec a1, Vec a2, Vec b1, Vec b2) {
    double l = 0, r = 1;
    while (l + EPS < r) {
        double m = (l + r) / 2;
        double v1 = dist_l2p(a1, a2, b1 + ((b2 - b1) * m));
        double v2 = dist_l2p(a1, a2, b1 + ((b2 - b1) * (m + EPS)));
        if (v1 < v2) r = m;
        else l = m;
    }
    return dist_l2p(a1, a2, b1 + ((b2 - b1) * l));
}

double dist(Vec s, Vec t, Vec a, Vec b, double h) {
    double d = dist_l2l(s, t, a, b);
    if (d < h) return d;
    a.z = h, b.z = h;
    double l = d, r = 2000;
    while (l + EPS < r) {
        double m = (l + r) / 2;
        s.z = m, t.z = m;
        if (m < dist_l2l(s, t, a, b)) l = m;
        else r = m;
    }
    return l;
}

int main()
{
    while (1) {
        int n; cin >> n;
        if (!n) break;
        Vec s, t;
        cin >> s.x >> s.y >> t.x >> t.y;
        s.z = 0, t.z = 0;
        double ans = INF;
        while (n--) {
            Vec a, b, c, d;
            double h;
            cin >> a.x >> a.y >> c.x >> c.y >> h;
            b.x = a.x, b.y = c.y, d.x = c.x, d.y = a.y;
            a.z = b.z = c.z = d.z = 0;
            if (a.x < min(s.x, t.x) && a.y < min(s.y, t.y) && c.x > max(s.x, t.x) && c.y > max(s.y, t.y)) ans = 0;
            ans = min(ans, dist(s, t, a, b, h));
            ans = min(ans, dist(s, t, b, c, h));
            ans = min(ans, dist(s, t, c, d, h));
            ans = min(ans, dist(s, t, d, a, h));
        }
        cout << setprecision(8) << fixed << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


ll n;
ll p[100005];
ll pos[200005];
multiset<ll> S;
ll getzd(ll x)
{
        auto it = S.lower_bound(x);
        if(it == S.begin()) return 0;
        it--;
        return *it;
}
ll getzu(ll x)
{
        auto it = S.upper_bound(x);
        if(it == S.end()) return n+1;
        return *it;
}
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++) {
                cin >> p[i];
                pos[p[i]] = i;
        }
        S.insert(pos[n]);
        ll ans = 0;
        for(ll i=n-1;i>=1;i--) {

                ll a,b,c,d;
                /// b .. a ...i... c ... d ..
                ll pp = pos[i];
                a = getzd(pp);
                b = getzd(a);
                c = getzu(pp);
                d = getzu(c);
                ans += i* ((a-b)*(c-pp)  +   (d-c)*(pp-a));
                S.insert(pp);
        }
        cout << ans << endl;
        return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    int x;
    cin>>x;
    cout<<(x>=30 ? "Yes\n" : "No\n");
    
    
    return 0;
}


Measured memory_bytes: 3508
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\0534-input.txt"));

		while (scan.hasNext()) {

			int m = scan.nextInt();
			int n = scan.nextInt();
			if (m == 0)
				break;
			Park p = new Park(m, n);
			for (int y = 0; y < n; y++)
				for (int x = 0; x < m; x++)
					p.add(x, y, scan.nextInt());

			System.out.println(p.maxRoot());
		}

		scan.close();
		System.exit(0);

	}
}

class Park {
	boolean[][] loc;

	public Park(int m, int n) {
		loc = new boolean[m][n];
	}

	public int maxRoot() {
		int max = 0;
		for (int sx = 0; sx < loc.length; sx++)
			for (int sy = 0; sy < loc[sx].length; sy++)
				if (loc[sx][sy]) {
					Root root = new Root();
					int l = root.len(sx, sy);
					if (l > max)
						max = l;
				}
		return max;
	}

	class Root {
		boolean[][] rt;

		public Root() {
			rt = new boolean[loc.length][loc[0].length];
		}

		public int len(int x, int y) {
			if (x < 0 || y < 0 || x == loc.length || y == loc[0].length)
				return 0;
			if (!loc[x][y] || rt[x][y])
				return 0;
			rt[x][y] = true;
			int max = 0;
			int l = len(x, y + 1);
			if (l > max)
				max = l;
			l = len(x, y - 1);
			if (l > max)
				max = l;
			l = len(x + 1, y);
			if (l > max)
				max = l;
			l = len(x - 1, y);
			if (l > max)
				max = l;
			rt[x][y] = false;
			return max + 1;
		}

	}

	public void add(int x, int y, int is) {
		if (is == 1)
			loc[x][y] = true;
	}
}

Measured memory_bytes: 66792
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long INT;
double PI = 3.14159265;

const long long INF = 1LL << 60;
//---//


int main() {
    int x,sum=0;

    cin >> x;

    cout << 1000 * (x / 500) +  (x % 500) / 5 *5<< endl;

  return 0;
}

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

int main(){
    int a, b;
    cin>> a>> b;
    if(a == 1) a = 100;
    if(b == 1) b = 100;
    if(a > b) cout<< "Alice"<< endl;
    else if(a < b) cout<< "Bob"<< endl;
    else cout<< "Draw"<< endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;


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

    int N;
    cin >> N;

    unordered_map<string, int> items;

    while (N--)
    {
        string item;
        cin >> item;

        ++items[item];
    }

    cout << items.size();
}


Measured memory_bytes: 17696
#include<stdio.h>
#include<stdlib.h>

int main()
{
  int n;
  char* s;
  int c = 0;
  scanf("%d", &n);
  s = (char*)malloc(n + 1);
  if (s == NULL)
    return 0;
  scanf("%s", s);
  for (int i = 0; i < n; i++)
  {
    if (s[i] != s[i + 1])
      c++;
  }
  printf("%d", c);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  int i,j,cnt=0;
  int a[6];
  cin>>a[0]>>a[1]>>a[2];
  cin>>a[3]>>a[4]>>a[5];
  int b[5];
  for(i=0;i<5;i++)b[i]=0;
  for(i=0;i<6;i++)b[a[i]]++;
  sort(b,b+5);
  if(b[1]==1 && b[2]==1 && b[3]==2 && b[4]==2)cout<<"YES";
  else cout<<"NO";
}

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

int main(){
	string s;
	cin >> s;

	bool res = false;
	rep(i, s.size()-1){
		if(s.at(i) == s.at(i+1)) res = true;
	}
	
	if(res) cout << "Bad" << endl;
	else cout << "Good" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
vector < vector < ll > > g;
bool vis[101];
ll org;
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll a,b,c,n,m,k,x,y,z=0,ans=0;

int main()
{
    //freopen("test.in","r",stdin);


    cin>>a>>b>>c>>k;

    if(abs(a-b)>1e18) cout<<"Unfair";
    else
    {

    if(k&1) cout<<b-a;
    else cout<<a-b;
    }
    return 0;
}


Measured memory_bytes: 256
import collections
n = int(input())
v = list(map(int, input().split()))

a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])

a = collections.Counter(a)
b = collections.Counter(b)
 
 
if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n - a.most_common()[0][1] - b.most_common()[0][1])
elif len(a.most_common()) == 1 and len(b.most_common()) == 1:
    print(n//2)
elif a.most_common()[1][1] + b.most_common()[0][1] > a.most_common()[0][1] + b.most_common()[1][1]:
    print(n - a.most_common()[1][1] - b.most_common()[0][1])
else:
    print(n - a.most_common()[0][1] - b.most_common()[1][1])

Measured memory_bytes: 18656
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

class UnionFind {
public:
    vector<int> Parent;
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    int size(int A) {
        return -Parent[root(A)];
    }
    bool connect(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) {
            return false;
        }
        if (size(A) < size(B)) swap(A, B);
        Parent[A] += Parent[B];
        Parent[B] = A;
        return true;
    }
};
struct Node {
    vector<int> neig;
};
Node node[100007];
int main() {
    int n; cin >> n;
    UnionFind sep(n);
    rep(i, n - 1) {
        int u, v, w; cin >> u >> v >> w;
        u--; v--;
        node[u].neig.push_back(v);
        node[v].neig.push_back(u);
        if (w % 2 != 0) {
            sep.connect(u, v);
        }
    }
    int now = 0;
    rep(i, n) {
        if (node[i].neig.size() == 1) {
            now = i;
            break;
        }
    }
    int reached[100007] = {0};
    queue<int> q;
    q.push(now);
    reached[now] = 1;
    while (!q.empty()) {
        now = q.front();
        q.pop();
        rep(i, node[now].neig.size()) {
            int next = node[now].neig[i];
            if (reached[next]) continue;
            q.push(next);
            if (sep.root(now) == sep.root(next)) {
                if (reached[now] == 1) reached[next] = 2;
                else reached[next] = 1;
            } else {
                if (reached[now] == 1) reached[next] = 1;
                else reached[next] = 2;
            }
        }
    }
    rep(i, n) if (reached[i] == 2) cout << 0 << endl; else cout << 1 << endl;
}



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

int main() {
	int x;
	cin>>x;
	if(x>=400 && x<600)
	    cout<<"8";
	else if(x>=600 && x<800)   
	    cout<<"7";
	else if(x>=800 && x<1000)
	    cout<<"6";
	else if(x>=1000 && x<1200)
	    cout<<"5"; 
	else if(x>=1200 && x<1400)
	    cout<<"4";
	else if(x>=1400 && x<1600)
	    cout<<"3";
	else if(x>=1600 && x<1800)
	    cout<<"2";
	else if(x>=1800 && x<2000)
	    cout<<"1";
	else
	    cout<<"Invalid";
	return 0;
}


Measured memory_bytes: 3620
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int res = N*N*N;

		out.println(res);
	}


	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 21844