akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
int clz(unsigned long long N) { return N ? 64 - __builtin_clzll(N) : -INF;}//may not work for some compiler returns position of msb; 
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fiṇxed;
const ll mod =1000000007;
ll modinv(ll x)
{
    return pow(x,mod-2,mod);
}
vector<vi> v;
int  vis[100005],dist[100005],ans;
int dfs(int x)
{
    vis[x]=1;
    for(auto u:v[x])
    {
        if(!vis[u])
        {dist[u]=dfs(u);}
        dist[x]=max(dist[u]+1,dist[x]);  
    }  
    return dist[x];
}
int main()
{
        FastIO
        int n,m,i,x,y;
        cin>>n>>m;
        v.resize(n+5);
        for(i=0;i<m;i++) 
        {
            cin>>x>>y;
            v[x].pb(y);
            
        }     
        for(i=1;i<=n;i++)
        {
            
            if(!vis[i])
            dist[i]=dfs(i);
        }
        for(i=1;i<=n;i++)
        ans=max(ans,dist[i]);
    
    cout<<ans;
    return 0;
}

        

Measured memory_bytes: 12032
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let s = next()
    if(s.length % 2 !== 0){
        console.log("No")
        return
    }
    let first = s.slice(0, s.length/2)
    let second = s.slice(s.length/2)
    console.log(first == second ? "Yes": "No")
}
Main()


Measured memory_bytes: 29360
#include <stdio.h>

int d(int a,int b)
{
	int c;
	if(a<=b){
		c=b-a;
	}else if(a>b){
		c=a-b;
	}
	return c;
}

int main(void)
{
	int n,t[100001],x[100001],y[100001];
	int i,nt=0,nx=0,ny=0,dt=0,dx=0,dy=0,z=0;
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d%d%d",&t[i],&x[i],&y[i]);
	}
	for(i=0; i<n; i++){
		dt=d(t[i],nt);
		dx=d(x[i],nx);
		dy=d(y[i],ny);
		if((dt-dx-dy)%2!=0 || dt<dx+dy){
			z=1;
			
		}
		nt=t[i];
		nx=x[i];
		ny=y[i];
	}
	if(z==1){
		printf("No\n");
	}else if(z==0){
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<vector>
#include<algorithm>

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>;


int main(void)
{
	char s[200000+2];

	while(scanf("%200000[a-z]\n", s)==1)
	{
		vi c;

		char p='\0';
		for(int i=0;s[i];i++)
		{
			if(p!=s[i])
			{
				c.push_back(1);
			}
			else
			{
				c.back()++;
			}
			p=s[i];
		}

		int ans=0;
		for(int i=0;i+1<c.size();i++)
		{
			ans+=(c[i]/3)*2;
			switch(c[i]%3)
			{
				case 1: ans++; break;
				case 2: ans+=2; c[i+1]--; break;
			}
		}
		ans+=(c.back()/3)*2;
		if(c.back()%3) ans++;

		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1528
#!/usr/bin/env python3
from functools import reduce
import sys
try:
    from typing import List
except ImportError:
    pass


def gcd(a: int, b: int):
    if a < b:
        return gcd(b, a)
    while b != 0:
        a, b = b, a % b
    return a


def solve(N: int, A: "List[int]"):
    print(reduce(gcd, A))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15880
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=105;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
//inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int h,w,sx,sy,a[MAXN][MAXN],b[MAXN][MAXN],c[MAXN][MAXN],F[2][MAXN][MAXN][MAXN];char s[MAXN];
inline void upd(int&x,int y){y>x?x=y:0;}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	h=read(),w=read();
	Rep(i,1,h){
		scanf("%s",s+1);
		Rep(j,1,w){
			if(s[j]=='E')sx=i,sy=j;
			a[i][j]=s[j]=='o',b[i][j]=a[i][j]+b[i][j-1],c[i][j]=a[i][j]+c[i-1][j];
		}
	}
	int now=0;
	Rep(u,0,sx-1){
		Rep(d,0,h-sx)Rep(l,0,sy-1)Rep(r,0,w-sy){
			if(u<sx-1)upd(F[now^1][d][l][r],F[now][d][l][r]+(sx-u-1>d?min(sy+r,w-l)>=max(sy-l,r+1)?b[sx-u-1][min(sy+r,w-l)]-b[sx-u-1][max(sy-l,r+1)-1]:0:0));
			if(d<h-sx)upd(F[now][d+1][l][r],F[now][d][l][r]+(sx+d+1<h-u+1?min(sy+r,w-l)>=max(sy-l,r+1)?b[sx+d+1][min(sy+r,w-l)]-b[sx+d+1][max(sy-l,r+1)-1]:0:0));
			if(l<sy-1)upd(F[now][d][l+1][r],F[now][d][l][r]+(sy-l-1>r?min(sx+d,h-u)>=max(sx-u,d+1)?c[min(sx+d,h-u)][sy-l-1]-c[max(sx-u,d+1)-1][sy-l-1]:0:0));
			if(r<w-sy)upd(F[now][d][l][r+1],F[now][d][l][r]+(sy+r+1<w-l+1?min(sx+d,h-u)>=max(sx-u,d+1)?c[min(sx+d,h-u)][sy+r+1]-c[max(sx-u,d+1)-1][sy+r+1]:0:0));
		}if(u==sx-1)break;
		memset(F[now],0,sizeof(now)),now^=1;
	}cout<<F[now][h-sx][sy-1][w-sy]<<'\n';
	return 0;
}




Measured memory_bytes: 11828
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

//Time Limit Exceeded case......
public class Main {
	FastScanner in = new FastScanner(System.in);
	int n, m;
	int[][][] dp;
	int[][] map;
	int[] cost;
	int[] vx = {1, 0, -1, 0};
	int[] vy = {0, 1, 0, -1};
	
	void dijkstra(int dir, int x, int y) {
		if (dp[dir][y][x] == -1 || (x == n && y == m)) return;
		//debug(dir);
		int order = map[y-1][x-1];
		int go = (order == 4) ? -1 : (order + dir) % 4;
		for (int i = 0; i < vx.length; i++) {
			int nx = x + vx[i], ny = y + vy[i];
			int c = (go == i) ? 0 : cost[(i - dir + 4) % 4];
			if (dp[dir][y][x] != Integer.MAX_VALUE && dp[i][ny][nx] > dp[dir][y][x] + c && dp[dir][y][x] + c <= Math.min(dp[0][m][n], dp[1][m][n])) {
				dp[i][ny][nx] = dp[dir][y][x] + c;
				dijkstra(i, nx, ny);
			}
		}
	}
	
	public void run() {
		while (true) {
			n = in.nextInt();
			m = in.nextInt();
			if ((n|m) == 0) break;

			map = new int[m][n];
			for (int i = 0; i < map.length; i++) {
				for (int j = 0; j < map[i].length; j++) {
					map[i][j] = in.nextInt();
				}
			}
			
			cost = new int[4];
			for (int i = 0; i < cost.length; i++) {
				cost[i] = in.nextInt();
			}
			
			dp = new int[4][m+2][n+2];			
			for (int i = 0; i < dp.length; i++) {
				for (int j = 0; j < dp[i].length; j++) {
					for (int k = 0; k < dp[i][j].length; k++) {
						if (j == 0 || j == m + 1 || k == 0 || k == n + 1) 
							dp[i][j][k] = -1;
						else
							dp[i][j][k] = Integer.MAX_VALUE;
					}
				}
			}
			
			
			dp[0][1][1] = 0;
			dijkstra(0, 1, 1);
			
			for (int i = 0; i < 4; i++) {
				//debug(i);
			}
			int res = Integer.MAX_VALUE;
			for (int i = 0; i < dp.length; i++) {
				res = Math.min(res, dp[i][m][n]);
			}
			
			System.out.println(res);
		}
	}
	
	void debug(int i) {
		System.out.println("dir = " + i);
		for (int j = 1; j < dp[i].length - 1; j++) {
			for (int k = 1; k < dp[i][j].length - 1; k++) {
				System.out.print((dp[i][j][k] == Integer.MAX_VALUE ? "F" : dp[i][j][k]) + " ");
			}
			System.out.println();
		}
		System.out.println();
	}

	public static void main(String[] args) {
		new Main().run();
	}
	
	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
		}

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {	
			return Double.parseDouble(next());
		}
	}
}

Measured memory_bytes: 25584
import sys
input =sys.stdin.readline
import heapq

def dijkstra(edge, start):
    n = len(edge)
    dist = [float("inf")]*n
    dist[start] = 0
    que = [(0, start)]
    while que:
        d, v = heapq.heappop(que)
        if dist[v] < d:
            continue
        for nv, nd in edge[v]:
            if dist[nv] > d + nd:
                dist[nv] = d + nd
                heapq.heappush(que, (dist[nv], nv))
    return dist

n, m, s = map(int, input().split())
G = [[] for _ in range(n)]
if s >= 2500:
  for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append((v, b))
    G[v].append((u, b))
  L = dijkstra(G, 0)
else:
  for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append((v, a, b))
    G[v].append((u, a, b))
  CD = [list(map(int, input().split())) for _ in range(n)]
  edge = [[] for _ in range(n*2500)]
  for i in range(n):
    c, d = CD[i]
    for k in range(2500):
      for v, a, b in G[i]:
        if k >= a:
          edge[2500*i+k].append((2500*v+(k-a), b))
      if k+c < 2500:
        edge[2500*i+k].append((2500*i+(k+c), d))
  dist = dijkstra(edge, s)
  L = [0]*n
  for i in range(n):
    L[i] = min(dist[2500*i:2500*(i+1)])
print(*L[1:], sep="\n")

Measured memory_bytes: 95112
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];

  deque<int> deq;
  deq.push_back(-1);

  for(auto x:a){
    if(deq.size()==0){
      deq.push_back(x);
      continue;
    }
    else{
      if(x<=deq.front()) deq.push_front(x);
      else{
        auto itr=lower_bound( begin(deq),end(deq),x );
        if(itr == end(deq)) deq.back()=x;
        else{
          while( *itr>=x ) itr--;
          *itr=x;
        }
      }
    }
    //for(auto x:deq) cout << x << " ";
    //cout << endl;  
  }
  cout << deq.size() << endl;
  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 1408
#include <stdio.h>

#define Max 26

int n, D[Max], H[Max], Deg[Max] = {0};

typedef struct {
  int parent;
  int left;
  int right;
} Node;

Node T[Max];

int max(int a, int b) {
  return a >= b ? a : b;
}

void get_depth(int u, int p) {
  D[u] = p;
  if (T[u].left != -1)  get_depth(T[u].left, p + 1);
  if (T[u].right != - 1) get_depth(T[u].right, p + 1);
}

int get_height(int u) {
  int h1 = 0, h2 = 0;
  if (T[u].right != -1) h1 = get_height(T[u].right) + 1;
  if (T[u].left != -1) h2 = get_height(T[u].left) + 1;

  return H[u] = max(h1, h2);
}

void print(void) {
  int i;
  for (i = 0; i < n; i++) {
    printf("node %d: ", i);
    printf("parent = %d, sibling = ", T[i].parent);

    if (i == T[T[i].parent].left && T[i].parent != -1) {
      printf("%d, degree = %d, depth = %d, height = %d, ", T[T[i].parent].right, Deg[i], D[i], H[i]);
    } else if (i == T[T[i].parent].right && T[i].parent != -1) {
      printf("%d, degree = %d, depth = %d, height = %d, ", T[T[i].parent].left, Deg[i], D[i], H[i]);
    } else {
      printf("-1, degree = %d, depth = %d, height = %d, ", Deg[i], D[i], H[i]);
    }

    if (T[i].parent == -1) {
      printf("root\n");
    } else if (Deg[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }

  }
}

int main(int argc, char const *argv[]) {
  int i, c, l, r, root;
  for (i = 0; i < Max; i++) {
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
  }

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &c, &l, &r);
    T[c].left = l, T[c].right = r;
    if (T[c].left != -1)  {
      T[T[c].left].parent = c;
      Deg[c]++;
    }
    if (T[c].right != -1) {
      T[T[c].right].parent = c;
      Deg[c]++;
    }
  }
  for (i = 0; i < n; i++) {
    if (T[i].parent == -1)  root = i;
  }
  get_depth(root, 0);
  c = get_height(root);
  print();

  return 0;
}



Measured memory_bytes: 2104
N = int(input())
B = list(map(int, input().split()))

import numpy as np
A = np.zeros(N)

BB = np.ones(N+1) * 10**6
BB[1:N] = B

for i in range(N):
    A[i] = min(BB[i], BB[i+1]) 

print(int(sum(A)))

Measured memory_bytes: 12508
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e12
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
int n, k;

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

ll calc(ll a) {
	if (a == 1)return 1;
	return calc(a / 2) * 2 + 1;
}

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

	cin >> n >> k;

	int ans = 0;
	while (n > 0) {
		n /= k;
		ans++;
	}
	cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll dp[55][55][2501];

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

  ll n,K;
  cin>>n>>K;
  dp[0][0][0]=1;
  rep(i,n)rep(j,n+1)rep(k,K+1){
    if(dp[i][j][k]==0)continue;
    if(k+2*j<=K)(dp[i+1][j][k+2*j]+=dp[i][j][k])%=mod;
    if(k+2*(j+1)<=K&&j+1<=n){
      (dp[i+1][j+1][k+2*(j+1)]+=dp[i][j][k])%=mod;
    }
    if(j>0&&k+2*(j-1)<=K){
      (dp[i+1][j-1][k+2*(j-1)]+=((dp[i][j][k]*j%mod)*j)%mod)%=mod;
    }
    if(k+2*j<=K)(dp[i+1][j][k+2*j]+=dp[i][j][k]*j%mod)%=mod;
    if(k+2*j<=K)(dp[i+1][j][k+2*j]+=dp[i][j][k]*j%mod)%=mod;
  }
  cout<<dp[n][0][K]<<endl;

  return 0;
}


Measured memory_bytes: 53504
#include <iostream>


int main(){
    int a,b,c,k;
    std::cin >> a >> b >> c >> k;

    for(int i = 0;i<k;i++){
        if (a < b){
            if(b < c){
                std::cout << "Yes" << std::endl;
                return 0;
            }
            else{
                c= c*2;                
            }
        }
        else{
            b=b*2;
        }

    }

    if(a<b && b<c){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }
    return 0;
}


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

void dfs(int node, vector<int>& visited, vector<int>& component, vector<vector<int> >& graph) {
    visited[node] = 1;
    component.push_back(node);

    for(int i = 0; i < graph[node].size(); i++) {
        if(!visited[graph[node][i]]) {
            dfs(graph[node][i], visited, component, graph);
        }
    }
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,m,k;
    cin>>n>>m>>k;

    vector<vector<int> > graph(n + 1);
    vector<int> remove(n + 1);

    for(int i = 0; i < m; i++) {
        int a,b;
        cin>>a>>b;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> visited(n + 1);
    vector<int> par(n + 1);
    vector<int> sz(n + 1);

    for(int i = 1; i <= n; i++) {
        if(!visited[i]) {
            vector<int> component;
            dfs(i, visited, component, graph);

            for(int j = 0; j < component.size(); j++) {
                par[component[j]] = i;
            }

            sz[i] = component.size();
        }
    }

    for(int i = 0; i < k; i++) {
        int a,b;
        cin>>a>>b;

        if(par[a] == par[b]) {
            remove[a]++;
            remove[b]++;
        }
    }

    for(int i = 1; i <= n; i++) {
        int ans = sz[par[i]] - (1 + remove[i] + graph[i].size());
        cout<<ans<<" ";
    }
    cout<<endl;

}


Measured memory_bytes: 9280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

template <typename T>
vector<T> smallest_prime_factors(T n) {
  vector<T> spf(n + 1);
  for (int i = 0; i <= n; i++) spf[i] = i;

  for (T i = 2; i * i <= n; i++) {
    // 素数だったら
    if (spf[i] == i) {
      for (T j = i * i; j <= n; j += i) {
        // iを持つ整数かつまだ素数が決まっていないなら
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }

  return spf;
}

template <typename T>
vector<T> factolization(T x, vector<T> &spf) {
  vector<T> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x /= spf[x];
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  constexpr int MAX = 1000000;

  auto spf = smallest_prime_factors(MAX);

  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i < n; i++) {
    int count = 1;
    map<int, int> mp;
    auto result = factolization(n - i, spf);
    for (auto z : result) mp[z]++;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
      count *= itr->second + 1;
    }
    ans += count;
  }
  cout << ans << endl;
  return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#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()

typedef unsigned long long ull;

const int B = 60;

int N;
int A[2010];
int S;
ull f[70010];
ull t[70010];
ull mask[61];

int main() {
	cin >> N;

	rep(i, N) {
		cin >> A[i];
		S += A[i];
	}

	mask[1] = 1;
	for (int i = 2; i < 61; ++i) {
		mask[i] = mask[i-1] * 2 + 1;
	}

	f[0] = 1;

	rep(i, N) {
		int c = A[i] / B, d = A[i] % B;

		memset(t, 0, sizeof(t));

		rep(i, 70000) {
			if (f[i] > 0) {
				t[i + c] = f[i];
			}
		}

		if (d) {
			for (int i = 70000; i >= 0; --i) {
				t[i+1] = ((t[i+1] & mask[B-d]) << d) + (t[i] >> (B-d));
			
				if (i == 0) {
					t[0] = ((t[0] & mask[B-d]) << d);
				}
			}
		}

		for (int j = 70000; j >= 0; --j) {
			f[j] |= t[j];
		}
	}

	rep(i, 70000) {
		rep(j, B) {
			if ((f[i] >> j) & 1) {
				int c = i * B + j;
				if (c * 2 >= S) {
					cout << c << endl;
					return 0;
				}
			}
		}
	}
  
	return 0;
}

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

int tax(int rate,int before);

int main(void){
    int  a,b,c,d;
    
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;
    
    while(a > 0  and c > 0){
        a -= d;
        c -= b;
    }
    
    if(a <= 0 and c > 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
vector<string> vec;

void dfs(string S, int i){
  if(i >= S.size()) return;
  string tmp = S;
  if(tmp[i] == 'A') {
    tmp.erase(i, 1);
    vec.push_back(tmp);
    dfs(tmp, i);
  }
  dfs(S, i+1);
}

int main(void){
  string S;
  cin >> S;
  vec.push_back("AKIHABARA");
  dfs("AKIHABARA", 0);

  bool tf = true;
  for(int i=0; i<vec.size(); i++) {
    if(S == vec[i]) break;
    if(i == vec.size()-1) tf = false;
  }
  if(tf) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_149
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            long[] rsp = ReadLongs();
            string s = Read();
            long[,] dp = new long[n, 3];
            for (int i = 0; i < n; i++)
            {
                long score = 0;
                if (s[i] == 's') score += rsp[0];
                if (i - k >= 0)
                {
                    score += Max(dp[i - k, 1], dp[i - k, 2]);
                }
                dp[i, 0] = score;

                score = 0;
                if (s[i] == 'p') score += rsp[1];
                if (i - k >= 0)
                {
                    score += Max(dp[i - k, 2], dp[i - k, 0]);
                }
                dp[i, 1] = score;

                score = 0;
                if (s[i] == 'r') score += rsp[2];
                if (i - k >= 0)
                {
                    score += Max(dp[i - k, 0], dp[i - k, 1]);
                }
                dp[i, 2] = score;
            }
            long res = 0;
            for(int i = 0; i < k; i++)
            {
                res += Max(Max(dp[n - 1 - i, 0], dp[n - 1 - i, 1]), dp[n - 1 - i, 2]);
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13664
def main():
    h, n = map(int, raw_input().split())
    ab = []
    for _ in xrange(n):
        a, b = map(int, raw_input().split())
        ab.append([a, b])
    dp = [float('inf')] * (h + 1)
    dp[0] = 0
    for i in range(1, h + 1):
        for a, b in ab:
            dp[i] = min(dp[i], b + dp[max(0, i - a)])
    print dp[-1]

main()


Measured memory_bytes: 33512
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

# 0:中央 1:南 2:東 3:西 4:北 5:裏側


class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self, loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3], self.work[1], self.work[0],
                           self.work[5], self.work[4], self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1], self.work[5], self.work[2],
                           self.work[3], self.work[0], self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4], self.work[0], self.work[2],
                           self.work[3], self.work[5], self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2], self.work[1], self.work[5],
                           self.work[0], self.work[4], self.work[3])

    def equals(self, another):

        ret = False

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret


diceA = Dice()
diceB = Dice()

table = list(map(int, input().split()))
diceA.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

table = list(map(int, input().split()))
diceB.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

if diceA.equals(diceB):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 6404
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        int[] sort = new int[3];
        sort[0] = sc.nextInt();
        sort[1] = sc.nextInt();
        sort[2] = sc.nextInt();
        Arrays.sort(sort);
        System.out.println(sort[0] + " " + sort[1] + " " + sort[2]);
        sc.close();

    }

}


Measured memory_bytes: 26332
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  int c = sc.nextInt();
  if(a+b <= b+c && a+b <= a+c)System.out.println(a+b);
  else if (b+c <= a+b && b+c <= a+c)System.out.println(b+c);
  else System.out.println(a+c);
}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    int n,m;
    cin>>n>>m;
    int x[m];
    for(int i=0;i<m;i++) cin>>x[i];
    sort(x,x+m);
    int a[m-1];
    for(int i=1;i<m;i++) a[i-1]=x[i]-x[i-1];
    sort(a,a+m-1);
    int ans=0;
    for(int i=0;i<m-n;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;

}

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

int main(){

    int n; cin>>n;

    vector<ll> l(n+1);

    l.at(0) = 2; l.at(1) = 1;

    for(int i=2; i<n+1; i++){
        l[i] = l[i-1] + l[i-2];
    }

    cout<<l[n]<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String symbol;
		ArrayDeque<Integer> stack = new ArrayDeque<Integer>();

		while (sc.hasNext()) {
			symbol = sc.next();
			
			if(symbol.equals("+")){
				stack.push(stack.pop() + stack.pop());
			} else if (symbol.equals("-")){
				stack.push((stack.pop() * -1) + stack.pop());
			} else if (symbol.equals("*")){
				stack.push(stack.pop() * stack.pop());
			} else {
				stack.push(Integer.parseInt(symbol));
			}
		}
		System.out.println(stack.pop());
	}
}

Measured memory_bytes: 12000
N = int(input())
S = input()
rgb = [0]*3

for i in range(N):
    if S[i] == "R":
        rgb[0] += 1
    elif S[i] == "G":
        rgb[1] += 1
    else:
        rgb[2] += 1
ans = 0
for i in range(N):
    for h in range(N):
        j = i+h
        k = i+2*h
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans += 1

print(rgb[0]*rgb[1]*rgb[2]-ans)


Measured memory_bytes: 73728
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
  
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)a[i] = i + 1;
	do{
		cout << a[0];
		for(int i = 1; i < n; i++)cout << ' ' << a[i];
		cout << '\n';
	}while(next_permutation(a, a + n));
    return 0;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int a[10005];
int n;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    printf("%d\n",a[n-1]-a[0]);
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0)
typedef long long ll;


ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

//#######################################




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

  for(int i=n-1;i>=0;i--){
    if(i!=n-1){
      dp[i]=(a[i]+dp[i+1])%mod;
    }
    else{
      dp[i]=a[i];
    }
  }

  ll ans=0;
  for(int i=0;i<n;i++){
    ans=(ans+(a[i]*(mod+dp[i]-a[i])%mod)%mod)%mod;
  }
  cout<<ans;
}



Measured memory_bytes: 6712
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rup(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rdn(i, a, b) for(int (i) = (a); (i) > (b); (i)--)

int main() {
	string s;
	cin >> s;
	string str = s;
	int wholeResult = INT_MAX;
	rup(loopCount, 0, str.length()) {
		int result = 0;
		char same = str[loopCount];

		s = str;
		int iteration = 0;
		while (1) {
			//judge
			int count = 0;
			rup(i, 0, s.length() - iteration) {
				if (s[i] == same) count++;
			}
			if (count == s.length() - iteration) break;
			result++;
		
			//change
			rup(i, 1, s.length()) {
				if (s[i] == same) {
					s[i - 1] = same;
				}

			}
			iteration++;
		}
		if (result < wholeResult) wholeResult = result;
	}
	cout << wholeResult;
	return 0;
}





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

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b){
		if(b==c){
			cout<<1<<endl;
		}else{
			cout<<2<<endl;
		}
	}else{
		if(a==c){
			cout<<2<<endl;
		}else if(b==c){
			cout<<2<<endl;
		}else{
			cout<<3<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include<algorithm>
using namespace std;

int main()
{
    int i,a,b,q;
	string str,order,rep,rev;
	string left;
	string right;
	cin>>str>>q;
	for(i=0;i<q;i++){
		cin>>order>>a>>b;
		if(order=="replace"){
			cin>>rep;
			left = str.substr(0, a);
			right = str.substr(b+1);
			str = left + rep + right;
		}else if(order=="reverse"){
		    rev = str.substr(a,b - a + 1);
			reverse(rev.begin(),rev.end());
			str.replace(a, b - a + 1, rev);
		}
		else if(order=="print"){
			cout << str.substr(a, b - a + 1) << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1228
//omajinai
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//omajinai

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;
    ll m=0,a=0,r=0,c=0,h=0;
    string s;

    for(int i = 0;i < n;i ++){
        cin >> s;
        if("M" <= s && s < "N"){
            m ++;
        }else if("A" <= s && s < "B"){
            a ++;
        }else if("R" <= s && s < "S"){
            r ++;
        }else if("C" <= s && s < "D"){
            c ++;
        }else if("H" <= s && s < "I"){
            h ++;
        }
    }

    ll ans;
    ans = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

ll calcNumOfCombination(ll n, ll r){
  ll num = 1;
  for(ll i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(snip_i, n) cin >> a.at(snip_i);
  sort(a.begin(), a.end());
  pair<int, int> ans;
  ans.first = a.back();
  a.pop_back();
  int mid = ans.first/2;
  auto itr = lower_bound(a.begin(), a.end(), mid);
  auto mitr = itr;
  if(mitr != a.begin()) mitr--;
  if((itr == a.end()) || (abs(mid - *itr) > abs(mid - *mitr))) ans.second = *mitr;
  else ans.second = *itr;
  cout << ans.first << " " << ans.second << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll a[6];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    rep(i,1,6)
    {
        cin>>a[i];
        if(!a[i])
            cout<<i;
    }
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#include <queue>
#define INF (1LL<<31)
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

int main(){
  string str;
  cin>>str;
  cout<<str[0]<<str.length()-2<<str[str.length()-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define INF 1234567890

int map[100][100];
int x_max, y_max;
int ans;

int dp(int x, int y){
	if (map[x][y] == 0) return 0;
	int answer = 1;
	map[x][y] = 0;
	if (map[x][y - 1] == 1) answer = max(answer, dp(x, y - 1) + 1);
	if (map[x][y + 1] == 1) answer = max(answer, dp(x, y + 1) + 1);
	if (map[x - 1][y] == 1) answer = max(answer, dp(x - 1, y) + 1);
	if (map[x + 1][y] == 1) answer = max(answer, dp(x + 1, y) + 1);
	map[x][y] = 1;
	return answer;
}

int main(){
	while (1){
		memset(map, 0, sizeof(map));
		ans = 0;

		scanf("%d%d", &x_max, &y_max);
		if (x_max == 0 && y_max == 0) break;
		for (int a = 1; a <= x_max; a++){
			for (int b = 1; b <= y_max; b++){
				scanf("%d", &map[a][b]);
			}
		}
		for (int a = 1; a <= x_max; a++){
			for (int b = 1; b <= y_max; b++){
				ans = max(ans, dp(a, b));
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long lcm = lcm(c,d);
		long cnomi = b / c - (a - 1) / c;
		long dnomi = b / d - (a - 1) / d;
		long ctod = b / lcm - (a - 1) / lcm;
		long result = (b - a + 1) - cnomi -dnomi + ctod;
		System.out.println(result);

	}
	
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	
	static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}

}


Measured memory_bytes: 21844
A,B,C=map(int,input().split())
point=0
if C>7*A+B:
    warareru=C%((7*A)+B)
    ans=C//((7*A)+B)
    while warareru>0:
        point+=1
        if point%7!=0:
            warareru-=A

        else:
            warareru-=A+B


    print(ans*7+point)
elif C>=7*A and C<=7*A+B:
    print("7")
else:
    if C%A==0:
        print(C//A)
    else:print((C//A)+1)


Measured memory_bytes: 5596
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;

//頂点は0からn-1
struct UnionFind {
    //par[i]はiの親で根のときは自分自身
    vector<int> par;

    //すべてが根として初期化
    //ここの書き方がわからない
    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }
    
    // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    // 木の併合
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry; //xとyの根が同じでない時：xの根rxをyの根ryにつける
    }
    
    // x, yが属する木が同じか判定
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//頂点数, 辺数
int V,E;

//MAX
const int MAX_V = 100005;
const int MAX_E = 200005;
const int INF=1500000000;
//辺 (各頂点にtoとcostのペアのリストが対応します)
struct edge { int u, v, cost; };
edge es[MAX_E];
bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}

//クラスカル法
int kruskal(){
    sort(es, es+E, comp);
    UnionFind tree(V);
    int res=0;

    for(int i=0; i<E; i++){
        edge e = es[i];
        if(!tree.same(e.u, e.v)){
            tree.unite(e.u, e.v);
            res += e.cost;
        }
    }

    return res;
}

int main() {
    cin >> V;
    pii x[MAX_V], y[MAX_V]; //座標と頂点の番号のくみにする
    for(int i=0; i<V; i++){
        int p,q;
        cin >> p >> q;
        x[i] = make_pair(p,i);
        y[i] = make_pair(q,i);
    }
    sort(x, x+V);
    sort(y, y+V);
    for(int i=0; i<V-1; i++){
        es[2*i] = (edge){x[i].second,x[i+1].second,x[i+1].first-x[i].first};
        es[2*i+1] = (edge){y[i].second,y[i+1].second,y[i+1].first-y[i].first};
    }

    E=(V-1)*2;
    cout << kruskal() << endl; 
}

Measured memory_bytes: 7560
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], pre[maxn], suf[maxn];
//pre[i]表示1-i的gcd
//suf[i]表示i-n的gcd
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)cin >> a[i];
    pre[1] = a[1];
    for(int i = 2; i <= n; i++)
        pre[i] = __gcd(a[i], pre[i - 1]);
    suf[n] = a[n];
    for(int i = n - 1; i >= 1; i--)
        suf[i] = __gcd(a[i], suf[i + 1]);
    int ans = max(pre[n - 1], suf[2]);
    for(int i = 2; i < n; i++)
        ans = max(ans, __gcd(pre[i - 1], suf[i + 1]));
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1408
N = int(input())
L = list(input())
a = int(N / 2)
if N%2 == 0:
    flag = 0
    for i in range(a):
        if L[i] != L[i+a]:
            flag = 1
    if flag:
        print("No")
    else:
        print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=1000000007;
ll MOD=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int n;
    cin >> n;
    vector<ll> d(n);
    rep(i,n) cin >> d[i];
    if (d[0]!=0) {cout << 0 << endl;return 0;}
    ll ans=1;
    sort(all(d));
    int u=1;
    vector<ll> a(n+1);
    a[0]=1;
    for (int i=1;i<n;i++){
        if (d[i]==0) {cout << 0 << endl;return 0;}
        if (d[i]>u+1) {cout << 0 << endl;return 0;}
        if (u==d[i]) a[u]++;
        if (d[i]==u+1) {u++;a[u]++;}
    } 
    for (int i=1;i<n+1;i++){
        if (a[i]==0) {cout << ans << endl;return 0;}
        rep(j,a[i]){
            ans=(ans*a[i-1])%MOD;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.*;

class Main {
	Scanner sc;
	int K, N;
	int[] p;
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		K = sc.nextInt();
		p = new int[N];
		long s = 0;
		int size = 0;
		long max = -1;
		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s += p[i];
			size++;
			if (size > K) {
				s -= p[i-K];
				size--;
			}
			max = Math.max(max, s);
		}
		System.out.println( ((double)max+K)/2 );
	}

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


Measured memory_bytes: 84908
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int mx=0;
  rep(i,n) {
    cin >> a[i];
    mx = max(mx,a[i]);
  }

  int r = mx;
  int l = 0;
  int ans;
  while(r-l > 1){
    int mid = (r+l)/2;
    int cut_total = 0;
    rep(i,n){
      if(a[i]<mid) continue;
      cut_total += (a[i]-1)/mid;
    }
    if(cut_total <= k) r = mid;
    else l = mid;
    ans = r;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3968
#中心通れば半分になる
#指定された点が中心でないなら、二点を通る直線なので1通り
w,h,x,y = map(int, input().split())
b = w*h/2
if x*2==w and y*2 == h:
  c = 1
else:
  c = 0
print(b,c)

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

using namespace std;
long long int c[26];

long long int ans = 0;

int main() {
  string a;

  cin >> a;

  for(int i = 0; i < a.size(); i++) {
    c[a[i] - 'a']++;
  }

  for(int i = 0; i < 26; i++) {
    for(int j = i+1; j < 26; j++) {
      ans += c[i] * c[j];
    }
  }

  cout << ans + 1 << endl;
}
  


Measured memory_bytes: 640
#include<iostream>
#include<vector>
int main(){
  int n,m,l;
  std::cin >> n >> m >> l;
  std::vector<std::vector<unsigned long long> > A,B,C;
  A.resize(n),B.resize(m),C.resize(n);
  for(int i=0; i<n; i++) A[i].resize(m);
  for(int i=0; i<m; i++) B[i].resize(l);
  for(int i=0; i<n; i++) C[i].resize(l);
  for(int i=0; i<n; i++) for(int j=0; j<m; j++) std::cin >> A[i][j];
  for(int i=0; i<m; i++) for(int j=0; j<l; j++) std::cin >> B[i][j];
  for(int i=0; i<n; i++){
    for(int j=0; j<l; j++){
      C[i][j] = 0;
      for(int k=0; k<m; k++) C[i][j] += A[i][k] * B[k][j];
    }
  }
  for(int i=0; i<n; i++){
    for(int j=0; j<l; j++) std::cout << C[i][j] << (j < l-1 ? " " : "\n");
  }
  return 0;
}

Measured memory_bytes: 3208