akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


class DGraph:
    def __init__(self, n, edges):
        self._vertice = [{} for _ in range(n)]
        for e in edges:
            self._vertice[e[0]][e[1]] = e[2] if len(e) == 3 else 1

    def __len__(self):
        return len(self._vertice)

    def edges(self, n=None):
        srcs = range(len(self)) if n is None else [n]
        return sum([[(s, d, c) for d, c in self._vertice[s].items()] for s in srcs], [])

    def transpose(self):
        tedges = [(t, f, c) for f, t, c in self.edges()]
        return DGraph(len(self), tedges)

    def cost(self, src, dst):
        return self._vertice[src].get(dst, float('inf'))

class Graph(DGraph):
    def __init__(self, n, edges):
        nd_edges = edges + [(d, s, c) for s, d, c in edges]
        super().__init__(n, nd_edges)

    def transpose(self):
        return self


def solve(N: int, x: "List[int]", y: "List[int]"):
    xs = {v:i for i, v in enumerate(set(x))}
    ys = {v:i for i, v in enumerate(set(y), len(xs))}
    
    n = len(xs) + len(ys)
    es = [(xs[cx], ys[cy], 1) for cx, cy in zip(x, y)]
    g = Graph(n, es)

    visited = [False] * len(g)
    def dfs(g, src):
        nonlocal visited
        stack = [(src, 0)]
        while stack:
            n, c = stack.pop()
            if visited[n]:
                continue
            visited[n] = True

            for _, d, _ in g.edges(n):
                #yield d
                stack.append((d, c + 1))
            yield n, c

    def _f(i):
        ls = list(i)
        if len(ls) == 0:
            return 0

        xc = 0
        yc = 0
        es = 0
        for i, _ in ls:
            es += len(g.edges(i))
            if i < len(xs):
                xc += 1
            else:
                yc += 1
        es //= 2

        if xc < 2 or yc < 2:
            return 0

        return xc * yc - es

    return sum([_f(dfs(g, i)) for i in range(n)])


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
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    result = solve(N, x, y)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 75732
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <atcoder/all>
#include <cstdio>
#include <vector>
using namespace std;
using namespace atcoder;

int m;

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)-1;
}

bool f(int a){
  return a<m;
}

int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  
  vector<int> A(n);
  rep(i,n) scanf("%d",&A[i]);
  
  segtree<int, op, e> seg(n);
  rep(i,n) seg.set(i,A[i]);
  
  rep(i,q){
    int t;
    scanf("%d",&t);
    if(t==1){
      int x,v;
      scanf("%d%d",&x,&v);
      seg.set(x-1,v);
    }
    else if(t==2){
      int l,r;
      scanf("%d%d",&l,&r);
      printf("%d\n",seg.prod(l-1,r));
    }
    else{
      int x;
      scanf("%d%d",&x,&m);
      printf("%d\n",seg.max_right<f>(x-1)+1);
    }
  }
   
  return 0;
}

Measured memory_bytes: 7016
#include "bits/stdc++.h"
    using namespace std;
    long long suma;
    int n;
    int main(){
    	scanf("%d",&n);
      	for(int i=1;i<=n;i++){
          if(i%3==0 || i%5==0)
            continue;
          suma+=i;
        }
   	printf("%lld",suma);
    }

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m;
    cin>>n>>m;
    int num[100];
    for(int i=0;i<n;i++)cin>>num[i];
    for(int i=1;i<=m;i++)for(int j=0;j<n-1;j++)if(num[j]%i>num[j+1]%i)swap(num[j],num[j+1]);
    for(int i=0;i<n;i++)cout<<num[i]<<endl;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, T, A):

    ft = [False] * N
    ft[0] = True

    for i in range(1, N):
        if T[i-1] < T[i]:
            ft[i] = True

    fa = [False] * N
    fa[-1] = True
    for i in range(N-2, 0, -1):
        if A[i] > A[i+1]:
            fa[i] = True
    
    H = []
    for i in range(N):
        if ft[i] and fa[i]:
            if T[i] != A[i]:
                return 0
        elif ft[i]:
            if T[i] > A[i]:
                return 0
        elif fa[i]:
            if T[i] < A[i]:
                return 0
        else:
            H.append(min(T[i], A[i]))

    M = Mod(10**9+7)
    ans = 1
    for h in H:
        ans = M.mul(ans, h)
    return ans


def main():
    N = read_int()
    T = read_int_n()
    A = read_int_n()
    print(slv(N, T, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 21632
from bisect import bisect_left
A = input()

N = len(A)
dp = [0] * (N + 2)
dp[N] = 1
d = [[N] for i in range(26)]
a = ord('a')
INF = float('inf')
for i in range(N - 1, -1, -1):
    d[ord(A[i]) - a].append(i)
    tmp = INF
    for j in range(26):
        tmp = min(tmp, dp[d[j][-1] + 1])
    dp[i] = tmp + 1


for i in range(26):
    d[i] = d[i][::-1]

pos = 0
ans = ''
for i in range(dp[0] - 1, -1, -1):
    for j in range(26):
        k = bisect_left(d[j], pos)
        if dp[d[j][k] + 1] == i:
            ans += chr(j + a)
            pos = d[j][k] + 1
            break

print(ans)


Measured memory_bytes: 62156
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int ans=b/a;
	if(ans>c) printf("%d\n",c);
	else printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

char f[303][303];

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

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

    int ret[n][m];
    for(int i = 0, li = 0; i < n; i++){
        cin >> f[i];
        vector<pi> cur;
        for(int j = 0, lj = 0; j < m; j++){
            if(f[i][j] == '#'){
                cur.push_back({lj, j});
                lj = j + 1;
            }
        }
        if(cur.empty()) continue;

        int X = (cur.size() < k ? i : n - 1);
        cur.back().second = m - 1;
        for(pi p : cur){
            for(int x = li; x <= X; x++){
                for(int y = p.first; y <= p.second; y++){
                    ret[x][y] = k;
                }
            }
            k--;
        }
        li = i + 1;
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++) cout << " " << ret[i][j];
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<complex>
using namespace std;
typedef long long int llint;
int main() {
	int a, b;
	cin >> a;
	if (a < 1200) {
		cout << "ABC" << endl;
	}
	else if (a < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 4000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int a[maxn],sum,n;
bitset <maxn> s;

int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),sum+=a[i]; s[0]=1;
	int tot=(sum+1)/2;
	for(int i=1;i<=n;i++) s|=s<<a[i];
	for(int i=tot;i<=sum;i++) if(s[i]) return cout<<i<<endl,0;
	return 0;
}

Measured memory_bytes: 1792
#include<atcoder/all>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;
using namespace atcoder;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    int n,m;
    cin >> n >> m;
    scc_graph graph(n);
    REP(i,m){
        int a1,b1;
        cin >> a1 >> b1;
        graph.add_edge(a1,b1);
    }
    vector<vector<signed>> scces = graph.scc();

    cout << scces.size() << endl;

    REP(i,scces.size()){
        cout << scces[i].size() << " ";
        REP(j,scces[i].size()-1){
            cout << scces[i][j] <<" ";
        }
        cout << scces[i][scces[i].size()-1] << endl;
    }


    return 0;
}

Measured memory_bytes: 40096
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

struct st{int l, r, x, y;};
int n, a[200009], m[200009][20];
priority_queue<st> pq;
bool operator<(st p, st q){return a[p.x]>a[q.x];}

int mn(int p, int q){return a[p]<a[q]?p:q;}

int f(int l,int r){
    int j=0;
    while(1<<(j+1)<=r-l+1) j++;
    return mn(m[l][j],m[r-(1<<j)+1][j]);
}

void add(int l,int r){
    int x, y;
    if(l>r) return;
    x=f(l,r);
    y=x+1==r?r:mn(f(x+1,r-1),r);
    pq.push({l,r,x,y});
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rep(i,n) cin>>a[i], m[i][1]=i;
    for(int j=2;;j++){
        int k=1<<j;
        if(k>n) break;
        for(int i=0;i+k<=n;i++) m[i][j]=mn(m[i][j-1],m[i+k/2][j-1]);
    }
    for(add(0,n-1);!pq.empty();){
        st t=pq.top(); pq.pop();
        cout<<a[t.x]<<" "<<a[t.y]<<" ";
        add(t.l,t.x-1);
        add(t.x+1,t.y-1);
        add(t.y+1,t.r);
    }
    cout<<endl;
}

Measured memory_bytes: 18804
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " ="; for(auto it : x) {cerr << " [" <<  it << "]";} cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 2e18;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	string s, t;
	cin >> s >> t;
	vector<vector<int>> ind(26);
	int n = s.size(), m = t.size();
	for(int i = 0;i < n;++i){
		ind[s[i] - 'a'].push_back(i);
	}
	int cur = -1;
	ll answer = 0;
	for(int i = 0;i < m;++i){
		if(ind[t[i] - 'a'].empty()){
			cout << -1 << '\n';
			return 0;
		}
		int next;
		auto next_ind = lower_bound(ind[t[i] - 'a'].begin(), ind[t[i] - 'a'].end(), cur + 1);
		if(next_ind == ind[t[i] - 'a'].end()){
			next = ind[t[i] - 'a'][0];
		}
		else{
			next = *next_ind;
		}
		if(next == cur){
			answer += n;
		}
		else if(next < cur){
			answer += n - cur - 1 + next + 1;
		}
		else{
			answer += next - cur;
		}
		cur = next;
	}
	cout << answer << '\n';
	return 0;
	
}


Measured memory_bytes: 1228
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int ans=0,n,x[3]={};
  string s;
  cin >> n >> s;
  for(int i=0; i<=999; i++) {
    x[0]=i/100,x[1]=(i%100)/10,x[2]=i%10;
    int cnt=0;
    for(int j=0; j<n; j++) {
      if(s[j]-'0'==x[cnt]) {
        cnt++;
        if(cnt==3) {
          ans++;
          break;
        }
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const int INF = (1LL<<31)-1;
const int MOD = 1000000007;


vector<ll> a;
void dfs(int d, ll s){
    a.push_back(s);

    if(d>=10) return;

    for(int i=-1;i<=1;i++){
        int ad = s%10+i;
        if(ad >= 0 && ad <= 9) dfs(d+1,s*10+ad);
    }
}

int main(){
    int k; cin >> k;
    rep(i,9) dfs(1,i+1);
    sort(a.begin(),a.end());
    cout << a[k-1] << endl;
}

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

int H,W;
string s[100];
int main() {
  cin >> H >> W;
  for(int i = 0; i < H; ++i) {
    cin >> s[i];
  }
  
  for(int j = 0; j < W + 2; ++j) {
    cout << '#';
  }
  cout << endl;
  
  for(int i = 0; i < H; ++i) {
    cout << '#' << s[i] << '#' << endl;
  }
  
  
  for(int j = 0; j < W + 2; ++j) {
    cout << '#';
  }
  cout << endl;
  
  
  
}

Measured memory_bytes: 256
io = STDIN
h,w = io.gets.split.map(&:to_i)
matrix = Array.new(h) do
  Array.new(w,0)
end
blacks = []
h.times do |i|
  io.gets.chomp.each_char.with_index do |c,j|
    next if c == '.'
    matrix[i][j] = 1
    blacks << [i, j]
  end
end

def create_blacks(row, col, matrix, blacks)
    if row > 0 && matrix[row-1][col] == 0
        matrix[row-1][col] = 1
        blacks << [row-1, col]
    end

    if row < matrix.size-1 && matrix[row+1][col] == 0
        matrix[row+1][col] = 1
        blacks << [row+1, col]
    end

    if col > 0 && matrix[row][col-1] == 0
        matrix[row][col-1] = 1
        blacks << [row, col-1]
    end

    if col < matrix[0].size-1 && matrix[row][col+1] == 0
        matrix[row][col+1] = 1
        blacks << [row, col+1]
    end
end

count = 0
while true
    size = blacks.size
    while size > 0
        row, col = blacks.shift
        create_blacks(row, col, matrix, blacks)
        size -= 1
    end


    if blacks.empty?
        break
    else
        count += 1
    end
end

p count

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

int main(){
    int N; cin >> N; 
    vector<int> d(N);
    for(int i = 0; i < N; i++ ) cin >> d[i];
    sort(d.begin(),d.end());
    cout << d[N/2] - d[N/2 - 1] << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
 int n,d,x,i,j,a[100],s;
 scanf("%d%d%d",&n,&d,&x);
 
 for(i=0;i<n;i++)
   scanf("%d",&a[i]);
 s=0;
for(i=0;i<n;i++){
  for(j=1;j<=d;j=j+a[i])
    s=s+1;
}
 
 printf("%d\n",s+x);
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
 
template <class T>
std::vector<T> ToFixedArray(std::istream& is, int n) {
	std::vector<T> ret(n);
	auto* dst = ret.data();
	while(n-- > 0)
		is >> *dst++;
	return ret;
}
 
#define _For(idx, from, to, inc, cmp) \
	for(auto idx=(from) ; idx cmp (to) ; inc idx)
#define ForLE(idx, from, to) \
	_For(idx, from, to, ++, <=)
#define ForGE(idx, from, to) \
	_For(idx, from, to, --, >=)
#define ForLT(idx, from, to) \
	_For(idx, from, to, ++, <)
#define ForGT(idx, from, to) \
	_For(idx, from, to, --, >)
#define For(idx, from, to) \
	_For(idx, from, to, ++, <)
 
void DisableIOSync() {
	std::cin.tie(0);
	std::cout.tie(0);
	std::ios::sync_with_stdio(false);
}
using Dist_t = uint64_t;
constexpr auto DistMax = std::numeric_limits<Dist_t>::max()/2;
using DistV = std::vector<Dist_t>;
int main() {
	DisableIOSync();

	using std::cin;
	using namespace std;
	int NCity, NLink, NDest;
	cin >> NCity >> NLink >> NDest;

	auto dest = ToFixedArray<int>(std::cin, NDest);
	for(auto& d : dest)
		--d;

	using DistV = std::vector<Dist_t>;
	using DistV2 = std::vector<DistV>;
	DistV2 dist(NCity);
	For(i, 0, NCity) {
		auto& d = dist[i];
		d.resize(NCity);
		std::fill(d.begin(), d.end(), DistMax);
		d[i] = 0;
	}
	For(i, 0, NLink) {
		int id0, id1, cost;
		cin >> id0 >> id1 >> cost;
		--id0;
		--id1;
		dist[id0][id1] = cost;
		dist[id1][id0] = cost;
	}
	For(inter, 0, NCity) {
		For(from, 0, NCity) {
			For(to, 0, NCity) {
				dist[from][to] =
					std::min(
						dist[from][to],
						dist[from][inter] + dist[inter][to]
					);
			}
		}
	}
	Dist_t res = DistMax;
	std::sort(dest.begin(), dest.end());
	do {
		Dist_t sum = 0;
		For(i, 1, NDest) {
			sum += dist[dest[i-1]][dest[i]];
		}
		res = std::min(res, sum);
	} while(std::next_permutation(dest.begin(), dest.end()));
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
using namespace std;

typedef long long ll;

ll a[200005], b[200005];

int main(void)
{
	ll n, m, k, i, p;

	scanf("%lld %lld %lld", &n, &m, &k);
	for (i = 1; i <= n; i++)
	{
		scanf("%lld", &p);
		a[i] = a[i - 1] + p;
	}
	for (i = 1; i <= m; i++)
	{
		scanf("%lld", &p);
		b[i] = b[i - 1] + p;
	}

	ll ans = 0;
	for (i = 0; i <= n; i++)
	{
		if (k < a[i])
			break;
		ans = max(ans, i + (upper_bound(b + 1, b + m + 1, k - a[i]) - b) - 1);
	}
	
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 4828
#include<iostream>
#include<algorithm>

using namespace std;


char maze[2002][2002];//迷路・マス



int main(){
int H,W;
cin >>H >>W;
char m;


for(int i=1 ;i<=H; i++){
    for(int k=1 ;k<=W; k++){
        cin >> m;
        maze[i][k]=m;
    }
}
int L[H+2][W+2]={};//全て端を0で初期化
int R[H+2][W+2]={};
int U[H+2][W+2]={};
int D[H+2][W+2]={};

for(int i=1 ;i<=H; i++){
    for(int k=1 ;k<=W; k++){
        if(maze[i][k]=='#'){
            L[i][k]=0;
        }
        else{
            L[i][k]=L[i][k-1]+1;
        }
       
    }
    
}
for(int i=1 ;i<=H; i++){
    for(int k=W ;k>=1; k--){
        if(maze[i][k]=='#'){
            R[i][k]=0;
        }
        else{
            R[i][k]=R[i][k+1]+1;
        }
    }
}

for(int i=1 ;i<=W; i++){
    for(int k=1 ;k<=H; k++){
        if(maze[k][i]=='#'){
            D[k][i]=0;
        }
        else{
            D[k][i]=D[k-1][i]+1;
        }
    }
}

for(int i=1 ;i<=W; i++){
    for(int k=H ;k>=1; k--){
        if(maze[k][i]=='#'){
            U[k][i]=0;
        }
        else{
            U[k][i]=U[k+1][i]+1;
        }
    }
}
int Ans;
int ans=0;
for(int i=1 ;i<=H; i++){
    for(int k=1 ;k<=W; k++){
        Ans=L[i][k]+R[i][k]+U[i][k]+D[i][k];
        ans=max(ans,Ans-3);
    }
 
}


cout << ans <<endl;
//関数searchをスタートの座標から呼び出す






 return 0;
}

Measured memory_bytes: 66816
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }
  


 void solve() {
	 	 int s,w;
	 	 cin>>s>>w;
	 	 if(w>=s) cout<<"unsafe\n";
	 	 else cout<<"safe\n";
						   
 }

    
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	solve();


return 0;	   
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long n;
    cin >> n;
    if (n % 2 == 0){
        long long ans = 0;
        for (long long i = 10; n / i >= 1; i *= 5)
            ans += n / i;
        cout << ans <<"\n";
    }
    else 
        cout << "0\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  char a;cin>>a;
  if(a<'a'){
    a='A';
  }else{
    a='a';
  }
  cout<<a<<endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main () {
  long H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> data(H, vector<char>(W)), sub(H, vector<char>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> data.at(i).at(j);
      sub.at(i).at(j) = data.at(i).at(j);
    }
  }
  long a, co, count = 0, ans = 0;
  for(int i = 0; i < pow(2, H); i++){
    for(int j = 0; j < pow(2, W); j++){
      a = j;
      co = 0;
      count = 0;
      while(a != 0){
        if(a % 2 == 1){
          for(int k = 0; k < H; k++){
            sub.at(k).at(co) = '.';
          }
        }
        a /= 2;
        co++;
      }
      a = i;
      co = 0;
      while(a != 0){
        if(a % 2 == 1){
          for(int k = 0; k < W; k++){
            sub.at(co).at(k) = '.';
          }
        }
        a /= 2;
        co++;
      }
      for(int k = 0 ; k < H; k++){
        for(int l = 0 ; l < W; l++){
          //cout << sub.at(k).at(l);
          if(sub.at(k).at(l) == '#')count++;
          sub.at(k).at(l) = data.at(k).at(l);
        }
        //cout << endl;
      }
      if(count == K)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4108
using System;

class quiz
{
    public int[] solve(string s)
    {
        int[] ans = new int[2];

        ans[0] = -1;
        ans[1] = -1;

        if (s.Length < 2)
            return ans;

        if(s.Length == 2 && s[0] == s[1])
        {
            ans[0] = 1;
            ans[1] = 2;
        }

        for (int i = 0; i < s.Length - 2; i++)
        {
            if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2])
            {
                ans[0] = i + 1;
                ans[1] = i + 3;

                break;
            }
        }

        return ans;
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        int[] ans;
        quiz ex = new quiz();

       // while (true)
        //{
            ans = ex.solve(Console.ReadLine());

            Console.WriteLine(ans[0]+ " " + ans[1]);
        //}
    }
}

Measured memory_bytes: 13140
// #define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<int> a(n),b(n); std::cin>>a>>b;
  int ans = 0;
  rep(i,0,n) {
    int x = a.at(i);
    int y = b.at(i);
    int z = x - y;
    if (z < 0) z = 0;
    ans += z;
  }
  std::cout << ans << std::endl;
  return 0;
}

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

bool is_sharp(int i, int j) {
  return ((i + j) % 2 == 0);
}

int main() {
  int h, w;
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) return 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++)
        cout << (is_sharp(i, j) ? '#' : '.');
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,i,x;
	cin>>a>>b>>c;
	x=0;
	for (i=a;i<=b;i++){
		if (c%i==0){
			x++;
		}
	}
	cout<<x<<endl;
			
}



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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int ans;
string s;

signed main() {
    cin >> s;
    rep(i,s.size()/2) if (s[i] != s[s.size()-i-1]) ans++;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
int getSecond(int h, int m, int s){
	return h * 3600 + m * 60 + s;
}
void getTime(int s, int time[3]){
	time[0] = s / 3600;
	s -= time[0] * 3600;
	time[1] = s / 60;
	s -= time[1] * 60;
	time[2] = s;
}
int main(void){
	int start;
	int sh,sm,ss;
	int end;
	int eh,em,es;
	int time[3];
	int i;
	for(i = 0; i < 3; i++){
		scanf("%d%d%d",&sh,&sm,&ss);
		start = getSecond(sh,sm,ss);
		scanf("%d%d%d",&eh,&em,&es);
		end = getSecond(eh,em,es);
		getTime(end-start,time);
		printf("%d %d %d\n",time[0],time[1],time[2]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, const char *argv[]) {
  int A, B;
  int a, b;
  cin >> A >> B;

  for(int i = 1; i < 1009; i++){
    a = i * 0.08;
    b = i * 0.1;
    if(a == A && b == B){
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------
 
 // snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

// combination c(N);
// mint ans = c(N,n);
// cout << ans.x << endl;
// Nとnはll型(mintではない)
// -------------------------------------------------------------


int main(){
  ll N,M,K;
  cin >> N >> M >> K;
  combination c(N*M);
  mint sum = 0;
  for(ll i=0; i<N; i++){
    for(ll j=0; j<M; j++){
      mint temp = mint(N-i)*mint(M-j)*mint(i+j);
      if(i!=0 && j!=0){
        temp *= 2;
      }
      sum += temp;
    }
  }
  sum *= c(N*M-2,K-2);
  cout << sum.x << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    int M, N;
    cin >> N >> M;

    vector<int> a(N);
    rep(i, N) cin >> a[i];

    sort(ALL(a));
    reverse(ALL(a));

    int sum = accumulate(ALL(a), 0);

    cout << (a[M - 1] >= sum / double(4 * M) ? "Yes" : "No") << endl;
}


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

 
ll  INF=101010101010;
int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    vector<ll> dp(n);
    rep(i,n)cin>>h[i];
    rep(i,n)dp[i]=INF;

    dp[0]=0;
    for(int i=1;i<n;i++){

        for(int j=i-k;j<i;j++){
            if(j<0)continue;
            dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j]);
        }
        /*
        最高２こ飛ばしの場合
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        if(i>=2)dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
        */
    }

    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;vector<ll>arr;
int main(void){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    inarr(n);
    for(int i=0;i<n;i++){
        in(temp);arr.push_back(temp);
    }
    ll money=1000;
    for(int i=0;i<n-1;i++){
        ll stocks = (arr[i+1]>arr[i])?(money/arr[i]):(0);
        money += (arr[i+1]-arr[i])*stocks;
    }
    cout<<money<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 200009
#define MOD 1000000007
#define INF 1000000000000000000
using Graph=vector<vector<int>>;

int main(){
  ll A,C,B,K;
  cin>>A>>B>>C>>K;
  if(K<=A){
    cout<<K<<endl;
  }else if(K<=A+B){
    cout<<A<<endl;
  }else{
    cout<<A-(K-A-B)<<endl;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  int n;cin>>n;
  cout << (n < 1000 ? "ABC" : "ABD") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
   int t,i,a,b,c,res;
   scanf("%d",&t);
   for(i=0;i<t;i++)
   {
    while(scanf("%d %d %d",&a,&b,&c)==3){
    if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b ){
        printf("YES\n");
    }
    else
       printf("NO\n");

    }
   }




    return 0;
}

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

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin >> n;
    n--;
    int cnt=1;
    ll tot=0;
    while(true) {
        tot+=pow(26LL,cnt);
        if(n<tot)
            break;
        cnt++;
    }
    n-=tot-pow(26LL,cnt);
    vector<int> res(cnt,0);
    for(int i=cnt-1; ~i; i--) {
        res[i]=n%26;
        n/=26;
    }
    F0R(i,cnt) {
        cout << (char)(res[i]+'a');
    }

    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n; cin >> n;
    n %= 10;
    if (n == 3)cout << "bon" << endl;
    else if (n==0||n==1||n==6||n==8)cout << "pon" << endl;
    else cout << "hon" << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

ll solve(const std::vector<std::vector<int>> &links, std::vector<int> &indeg) {
  std::vector<int> sorted;
  std::stack<int> st;
  std::vector<long long> depth(links.size(), 1);
  for(int i = 0; i < indeg.size(); ++i) if(indeg[i] == 0) st.push(i);

  while(!st.empty()) {
    int v = st.top();
    st.pop();
    sorted.push_back(v);
    for(int u : links[v]) {
      depth[u] = max(depth[u], depth[v] + 1);
      indeg[u]--;
      if(indeg[u] == 0) st.push(u);
    }
  }
  ll max_depth = 0;
  for(ll d : depth) max_depth = max(max_depth, d);
  return links.size() == sorted.size() ? max_depth : -1;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VVI links(n*n+n+1);
  VI indeg(n*n+n+1, 0);
  rep(i, n) {
    VI a(n-1);
    rep(j, n-1) {
      cin >> a[j];
      a[j]--;
    }
    rep(j, n-2) {
      int from_small = min(i, a[j]);
      int from_big = max(i, a[j]);
      int to_small = min(i, a[j+1]);
      int to_big = max(i, a[j+1]);
      indeg[to_big * n + to_small]++;
      links[from_big * n + from_small].push_back(to_big * n + to_small);
    }
  }
  out(solve(links, indeg));

  return 0;
}


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

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

  if (s[s.size()-1] == 's') s = s + "es";
  else s = s + 's';

  cout << s << endl;

  return 0;
}



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

string S;

bool check(){
    stack<char> s;
    for (int i=0;i<S.size();++i){
        if (S[i]=='(') s.emplace('(');
        if (S[i]=='[') s.emplace('[');
        if (S[i]==')'){
            if (s.empty()||s.top()!='(') return false;
            s.pop();
        }
        if (S[i]==']'){
            if (s.empty()||s.top()!='[') return false;
            s.pop();
        }
    }
    return s.empty();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(getline(cin,S),S!="."){
        stack<char> s;
        cout << (check()?"yes":"no") << '\n';
    }
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N, K;
int a[1111];
vec<int> cand;

int solve(int mask) {
   int cnt = 0;

   for (int i = 0; i < cand.size(); i++) {
      if ((cand[i] & mask) == mask) {
         cnt++;
      }
   }

   return cnt;
}

signed main() {
   cin >> N >> K;
   rep (i, N) {
      cin >> a[i];
   }

   for (int i = 0; i < N; i++) {
      int sum = 0;
      for (int j = i; j < N; j++) {
         sum += a[j];
         cand.push_back(sum);
      }
   }

   int mask = 0;
   for (int i = 40; i >= 0; i--) {
      if (solve(mask | (1LL << i)) >= K) {
         mask |= (1LL << i);
      }
   }
   cout << mask << endl;

   return 0;
}

Measured memory_bytes: 6384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int Max(int a, int b, int c) {
	if (a >= b) { return std::max(a, c); }
	else return std::max(b, c);
}
int main(void) {
	int a, b; cin >> a >> b;
	cout << a * b - a - b + 1 << endl;
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		int a = in.readInt(); 
		int b = in.readInt(); 
		int c = in.readInt();
		int d = in.readInt();

        int lower = Math.max(a, c); 
        int upper = Math.min(b,d); 
        System.out.println(Math.max(0, upper-lower)); 
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long

using namespace std;

set<string>q;
set<string>a[10];

ll  s[10];

int main()
{

    int n;
    string ss;
    scanf("%d", &n);
    while(n--)
    {
        cin>>ss;
        if(ss[0] == 'M')
            a[0].insert(ss);
        else if(ss[0] == 'A')
            a[1].insert(ss);
        else if(ss[0] == 'R')
            a[2].insert(ss);
        else if(ss[0] == 'C')
            a[3].insert(ss);
        else if(ss[0] == 'H')
            a[4].insert(ss);

    }
    for(int i=0;i<5;i++)
    {
        s[i]=a[i].size();
    }
    sort(s, s+5);
    if(s[2]==0)
        cout<<0<<endl;
    else if(s[1]==0)
    {
        printf("%lld\n", s[3]*s[2]*s[4]);
    }
    else if(s[0]==0)
    {
        printf("%lld\n",s[3]*s[2]*s[4]+s[1]*s[2]*s[4]+s[3]*s[1]*s[4]+s[1]*s[2]*s[3]);
    }
    else
    {
        printf("%lld\n", (s[0]*s[1])*(s[2]+s[3]+s[4]) + (s[1]*s[2])*(s[3]+s[4]) + s[1]*s[3]*s[4] + (s[3]+s[4])*(s[0]*s[2] ) + s[2]*s[3]*s[4] + s[0]*s[3]*s[4]);
    }
   // printf("%lld\n", (s[0]+s[1])*(s[2]+s[3]+s[4]) + (s[1]+s[2])*(s[3]+s[4]) + s[1]*s[3]*s[4] + (s[3]+s[4])*(s[0]+s[2]) + s[2]*s[3]*s[4]);
    return 0;

}


Measured memory_bytes: 9600