akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> list;
	list.push_back(2);
	int x = 2;
	int count = 0;
	while(1){
		for(int y : list){
			if((int) sqrt(x)<y){
				break;
			}
			if(x%y==0){
				count = 1;
				break;
			}
			
		}
		if(count==0){
			list.push_back(x);
		}
		if(list.back() >= N){
			cout << list.back();
			return 0;
		}
		count = 0;
		x++;
	}
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#define ll long long
#define linf (1ll<<60)
#define iinf 0x3f3f3f3f
#define dinf 1e100
#define eps 1e-8
#define cl(x) memset(x,0,sizeof(x))
using namespace std;
char s[1000];
ll K;
int pos;
int main()
{
	int i, r, l;
	scanf("%s%lld",s+1,&K);
	l=strlen(s+1);
	for(r=0;r<=l and s[r+1]=='1';r++);
	if(K<=r)putchar('1');
	else putchar(s[r+1]);
	return 0;
}

Measured memory_bytes: 128
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    if len([a for a in A if a>=sum(A)/(4*M)])>=M:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
int n;

int t[101010];
int x[101010];
int y[101010];

int main(){
  scanf("%d",&n);
  int fail = 0;
  for(int i=1;i<=n;i++){
    scanf("%d%d%d",&t[i],&x[i],&y[i]);
    int d = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]);
    int dt = t[i] - t[i-1];
    if(dt >= d && (dt - d)%2 == 0)continue;
    else {
      fail = 1;
      break;
    }
  }
  printf("%s\n", fail?"No":"Yes");
}

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

int main() {
  string s;
  cin >> s;
  deque<int> n;
  for (int i=0; i<s.size(); i++) {
    if (s.at(i)=='0') n.push_back(0);
    else if (s.at(i)=='1') n.push_back(1);
    else if(!n.empty()) n.pop_back();
  }
  for (int i=0; i<n.size(); i++) cout << n.at(i);
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, m;
    cin >> n >> m;
    if (n >= 3 && m >= 3) {
        cout << (n - 2) * (m - 2) << endl;
        return 0;
    }
    if (n == 2 || m == 2) cout << 0 << endl;
    else {
        if (n > m) swap(n, m); // mが1でない
        if (n == 1 && m == 1) cout << 1 << endl;
        else cout << m - 2 << endl;
    }
}



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

vector<pair<int,int>> A;

int main(){
    int N, T;
    cin >> N >> T;
    A.resize(N);

    for (int i = 0; i < N;i++)
        cin >> A[i].first >> A[i].second;

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

    vector<vector<int>> dp(3010,vector<int>(3010,0));
    int ans = 0;
    for (int i = 0; i < N;i++){
        for (int j = 0; j < T;j++){
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);

            int tj = j + A[i].first;
            if(tj < T)
                dp[i + 1][tj] = max(dp[i + 1][tj], dp[i][j] + A[i].second);
        }
        int tmp = dp[i][T - 1] + A[i].second;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35840
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    a = list(map(int, input().split()))
    num = 0
    for j in range(m):
        num += a[j] * b[j]
    if num + c > 0:
        cnt += 1
print(cnt)

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, M; cin >> N >> M;
	vector<int>A(N); rep(i, 0, N) { cin >> A[i]; }
	vector<int>B(M), C(M); rep(i, 0, M) { cin >> B[i] >> C[i]; }

	vector<pii>v;
	rep(i, 0, M) {
		v.eb(C[i], B[i]);
	}
	sort(all(v));

	priority_queue < int, vector<int>, greater<int >> pq;
	rep(i, 0, N) {
		pq.push(A[i]);
	}

	rrep(i, 0, v.size()) {
		int c = v[i].first;
		int b = v[i].second;
		rep(j, 0, b) {
			if (pq.top() >= c)break;
			pq.pop();
			pq.push(c);
		}
	}
	int ans = 0;
	while (pq.size()) {
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 6000
#include <stdio.h>
int main(){
  int m,f,r;
  char grade;


  while(1){
    scanf("%d %d %d",&m,&f,&r);

    if(m==-1 && f==-1 && r==-1)break;

    if(m==-1 || f==-1)grade='F';
    else if(m+f>=80)grade='A';
    else if(m+f>=65 && m+f<80)grade='B';
    else if((m+f>=50 && m+f<65)||(m+f>=30 && m+f<50 && r>=50))grade='C';
    else if(m+f>=30 && m+f<50 && r<50)grade='D';
    else grade='F';

    printf("%c\n",grade);
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define int ll

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

vl s;
pll divide(int l, int r)
{
  int m = (s[r]+s[l-1])/2;
  int x = upper_bound(s.begin()+l, s.begin()+r, m) - s.begin()-1;  

  pll ret1 = mp(s[x]-s[l-1], s[r]-s[x]);
  pll ret2 = mp(s[x+1]-s[l-1], s[r]-s[x+1]);

  //  printf("%d %d %d]\n", l, x, r);

  if(ret1.first-ret1.second > ret2.second-ret2.first){
    return ret1;
  }else{
    return ret2;
  }
}

signed main()
{
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];

  s.resize(n+1, 0);
  rep(i, n) s[i+1] = s[i] + a[i];

  ll ans = inf;
  repi(i, 2, n-1){
    vl v(4);
    pii p = divide(1, i);
    v[0] = p.first;
    v[1] = p.second;
    p = divide(i+1, n);
    v[2] = p.first;
    v[3] = p.second;

    /*
       cout << i << " : ";
       rep(j, 4) cout << v[j] << " ";
       cout << endl;
     */

    sort(all(v));
    ans = min(ans, v[3]-v[0]);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
#define front top
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n, m;
int t;
int ans;
Vi v[3];

void solve(){
	stack<int> que[3];
	rep(i,3) rep(j,v[i].size()) que[i].push(v[i][j]);
	rep(i,m){
	//	rep(j,3) cout << que[j].size() << " ";
		//cout << endl;
		if(t == 0){
			if(que[0].size() == 0){
				que[0].push(que[1].front());
				que[1].pop();
			} else if(que[1].size() == 0){
				que[1].push(que[0].front());
				que[0].pop();
			} else{
				if(que[0].front() > que[1].front()){
					que[1].push(que[0].front());
					que[0].pop();
				} else{
					que[0].push(que[1].front());
					que[1].pop();
				}
			}
			t = 1;
		} else{
			if(que[1].size() == 0){
				que[1].push(que[2].front());
				que[2].pop();
			} else if(que[2].size() == 0){
				que[2].push(que[1].front());
				que[1].pop();
			} else{
				if(que[1].front() > que[2].front()){
					que[2].push(que[1].front());
					que[1].pop();
				} else{
					que[1].push(que[2].front());
					que[2].pop();
				}
			}
			t = 0;
		}
		if(que[0].size() == n || que[2].size() == n){
			ans = min(ans,i+1);
			break;
		}
	}
}

int main(){
	while(scanf("%d%d", &n, &m),n||m){
		rep(i,3) v[i].clear();
		rep(i,3){
			int x; scanf("%d", &x);
			rep(j,x){
				int tmp; scanf("%d", &tmp);
				v[i].pb(tmp);
			}
		}
		ans = INF;
		if(v[0].size() == n || v[2].size() == n){
			printf("%d\n", 0);
			continue;
		}
		rep(i,2){
			t = i;
			solve();
		}
		if(ans == INF) printf("-1\n");
		else printf("%d\n", ans);
	}
}

Measured memory_bytes: 1216
#include<iostream>
using namespace std;
int main()
{
	int nedan[] = {6000,4000,3000,2000};
	for(int i=0 ; i<4 ; ++i){
		int t,n;
		cin >> t >> n;
		cout << nedan[t-1]*n << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
int main(void){
	int W,H;
	int i,j;
	
	while(W!=0 || H!=0){
		scanf("%d%d",&H,&W);
		if(W==0 && H==0) break;
		for(i=0; i<H; i++){
			for(j=0; j<W; j++){if(i==0 ||i==H-1 || j==0 || j==W-1) printf("#"); else printf(".");}
			printf("\n");
		}
		printf("\n");
	}
return 0;
}

Measured memory_bytes: 572
#include <limits>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

template<class F>
void times_do(size_t n, F func)
{
    for(size_t i = 0; i < n; ++i) func();
}

template<class T>
T read()
{
    T value;
    std::cin >> value;
    return value;
}

template<class T>
vector<T> reads(size_t n)
{
    vector<T> a;
    a.reserve(n);
    times_do(n, [&](){
        a.push_back(read<T>());
    });
    return a;
}

int main()
{
    const auto n = read<size_t>();
    auto a = reads<int>(n);

    sort(begin(a), end(a), greater<int>());

    int alice = 0;
    int bob = 0;

    for(size_t i = 0; i < a.size(); ++i)
    {
        if(i%2 == 0) alice += a[i];
        else bob += a[i];
    }

    cout << (alice - bob) << '\n';
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
likes = [[int(i) for i in input().split()] for _ in range(N)]
seki = {}
for i in range(N):
    if seki == {}:
        seki = {likes[i][j] for j in range(1, likes[i][0]+1)}

    tag={likes[i][j] for j in range(1, likes[i][0]+1)}
    seki= seki & tag

print(len(seki))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N;
	cin >> N;
	if (N < 1000) {
		cout << "ABC" << endl;
	}
	else cout << "ABD" << endl;
}

Measured memory_bytes: 256
cmds = []
while true do
    cmd = gets.chomp.split(' ')
    break if cmd[0] == "end"
    cmd[1] = cmd[1].to_i unless cmd[1].nil?
    cmds.push(cmd)
end

INF = 20005
heap = [nil]
heapSize = 0

def heapIncreaseKey(heap, i, key)
    if key < heap[i] then
        puts "ERROR : The new key is less than the current key."
        exit
    end
    heap[i] = key
    while i > 1 && heap[i / 2] < heap[i]
        tmp = heap[i]
        heap[i] = heap[i / 2]
        heap[i / 2] = tmp
        i = i / 2
    end
end

def heapInsert(heap, key)
    heap[heap.size] = INF * (-1)
    heapIncreaseKey(heap, heap.size - 1, key)
end

def maxHeapify(heap, i)
    l = i * 2
    r = i * 2 + 1
    if l <= heap.size - 1 && heap[l] > heap[i] then
        largest = l
    else
        largest = i
    end
    if r <= heap.size - 1 && heap[r] > heap[largest] then
        largest = r
    end
    
    if largest != i then
        tmp = heap[i]
        heap[i] = heap[largest]
        heap[largest] = tmp
        maxHeapify(heap, largest)
    end
end

def heapExtractMax(heap)
    puts "ERROR : Heap Underflow" if heap.size - 1 < 1
    max = heap[1]
    heap[1] = heap[heap.size - 1]
    maxHeapify(heap, 1)
    heap.pop
    return max
end

cmds.each do |cmd|
    if cmd[0] == "insert" then
        heapInsert(heap, cmd[1])
        # p heap
    else
        puts heapExtractMax(heap)
        # p heap
    end
end



Measured memory_bytes: 277120
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

r = 0
xsum = 0
sum = 0
ans = 0

n.times do |l|
  while r < n
    break if (xsum ^ a[r]) != (sum + a[r])

    xsum ^= a[r]
    sum += a[r]
    r += 1
  end

  ans += (r-l)
  xsum ^= a[l]
  sum -= a[l]
end

puts ans


Measured memory_bytes: 16644
def main():
    a, b, c = map(int, input().split())
    k = int(input())
    for i in range(1, k+2):
        if a < b and b < c:
            print("Yes")
            return 0
        
        elif i == k+1:
            print("No")
            return 0

        elif c <= a or c <= b:
            c = c * 2

        elif b <= a:
            b = b * 2

main()

Measured memory_bytes: 61908
#include <bits/stdc++.h>
#define ROOT 1

using namespace std;

#define int long long

struct node{
	int val;
};

node tree[4*212345];
node lazy[4*212345];

node combine(node a, node b){
	node res;
	res.val = a.val+b.val;
	return res;
}

void propagate(int root, int l , int r){
	if(lazy[root].val == 0) return;
	
	tree[root].val += (r-l+1)*lazy[root].val;
	
	if(l != r){
		lazy[2*root].val += lazy[root].val;
		lazy[2*root+1].val += lazy[root].val;
	}
	
	lazy[root].val = 0;
	return;
}

void range_update(int root, int l, int r, int a, int b, long long val){
	if(l == a && r == b){
		lazy[root].val+=val;
		return;
	}
	
	int m = (l+r)/2;
	
	if(b <= m) range_update(2*root, l, m, a, b, val);
	else if(m < a) range_update(2*root+1, m+1, r, a, b, val);
	else {
		range_update(2*root, l, m, a, m, val);
		range_update(2*root+1, m+1, r, m+1, b, val);
	}
	
	propagate(root, l , r);
	propagate(2*root, l, m);
	propagate(2*root+1, m+1, r);
	tree[root] = combine(tree[2*root], tree[2*root+1]);
	return;
}

node query(int root, int l, int r, int a, int b){
	propagate(root, l, r);
	if(l == a && r == b) return tree[root];
	
	int m = (l+r)/2;
	if(b <= m) return query(2*root, l, m, a, b);
	else if(m < a) return query(2*root+1, m+1, r, a, b);
	else {
		node left = query(2*root, l, m, a, m);
		node right = query(2*root+1, m+1, r, m+1, b);
		node ans = combine(left, right);
		return ans;
	}
}

int32_t main(){
	int n,q,s,t;
	cin >> n >> q >> s >> t;
	n++;
	for(int i=0; i<4*212345; i++) tree[i].val = lazy[i].val = 0;
	int v[n];
	for(int i=1; i<=n; i++){
		cin >> v[i];
		range_update(ROOT, 1, n, i, i,v[i]);
	}
	int ans = 0;
	for(int i=1; i<n; i++){
		if(v[i] < v[i+1]) ans -= abs(v[i+1]-v[i])*s;
		else ans += abs(v[i+1]-v[i])*t;
	}
	for(int i=0; i<q; i++){
		int l,r,x;
		cin >> l >> r >> x;
		l++, r++;
		if(l > 1){
			v[l-1] = query(ROOT, 1, n, l-1, l-1).val;
			v[l] = query(ROOT, 1, n, l, l).val;
			if(v[l-1] < v[l]) ans += abs(v[l] - v[l-1])*s;
			else ans -= abs(v[l] - v[l-1])*t;
			if(v[l-1] < v[l]+x) ans -= abs(v[l]+x - v[l-1])*s;
			else ans += abs(v[l]+x - v[l-1])*t;
		}
		if(r < n){
			v[r] = query(ROOT, 1, n, r, r).val;
			v[r+1] = query(ROOT, 1, n, r+1, r+1).val;
			if(v[r] < v[r+1]) ans += abs(v[r] - v[r+1])*s;
			else ans -= abs(v[r] - v[r+1])*t;
			if(v[r]+x < v[r+1]) ans -= abs(v[r]+x - v[r+1])*s;
			else ans += abs(v[r]+x - v[r+1])*t;
		}
		range_update(ROOT, 1, n, l, r, x);
		cout << ans << endl;
	}
}
	

Measured memory_bytes: 17916
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
typedef pair<P,int> PP;

void Main() {
  ll n;
  R n;
  PP a[n];
  rep(i,n) cin >> a[i].F.F >> a[i].F.S >> a[i].S;
  rep(x,101) {
    rep(y,101) {
      set<int> s;
      rep(i,n) if(a[i].S) s.in(abs(x-a[i].F.F)+abs(y-a[i].F.S)+a[i].S);
      if(s.size()!=1) continue;
      ll c=0;
      rep(i,n) c+=max(*s.begin()-abs(x-a[i].F.F)-abs(y-a[i].F.S),0LL)==a[i].S;
      if(c==n) {
        pr(x,y,*s.begin());
        return;
      }
    }
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen("input.txt","r",stdin);
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0]) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  int m = 0;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x <= K / 2) m += x;
    else m += K - x;
  }
  
  cout << 2 * m <<endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ans = 0
d = [0] * (max([n,m])+1)
def factorial(n):
    global d
    d[0] = 1
    for i in range(1, n+1):
        d[i] = ((i+1) * d[i-1]) % (10** 9 +7)
factorial(max(m,n))
if abs(n-m) == 1:
    ans = d[n-1] * d[m-1]
elif n == m:
    ans = 2 * d[n-1] * d[m-1]
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 6900
#include <algorithm>
#include <bitset>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;

int main() {
  ll N, M, X;
  cin >> N >> M >> X;

  vector<vector<ll>> book(N, vector<ll>(M));
  vector<ll> money(N);

  for (ll i = 0; i < N; i++) {
    cin >> money[i];

    for (ll j = 0; j < M; j++) {
      cin >> book[i][j];
    }
  }

  ll ans = INT_MAX;

  for (ll i = 0; i < (1 << N); i++) {
    vector<ll> rikai(M, 0);
    ll cur = 0;

    for (ll j = 0; j < N; j++) {
      if (bitset<64>(i)[j] == 0) {
        continue;
      }

      cur += money[j];

      for (ll k = 0; k < M; k++) {
        rikai[k] += book[j][k];
      }
    }
    bool ok = true;
    for (ll j = 0; j < M; j++) {
      if (rikai[j] < X) {
        ok = false;
      }
    }

    if (ok) {
      ans = min(ans, cur);
    }
  }

  if (ans == INT_MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] d = new int[n];

		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}

		Arrays.sort(d);
		int ans = d[d.length / 2] - d[d.length / 2 - 1];

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 50764
#include<string>
#include<vector>
#include<cctype>
#include<cmath>
#include<iostream>
#include<map>
using namespace std;

int main(){
    int N, t;
    vector<long double> vi;
    long double rs = 0;
    cin >> N >> t;

    long double tmp;
    int cp = N;
    while(cp--){
        cin >> tmp;
        vi.push_back((1+tmp)/2);
    }

    cp = t;
    int i = 0;
    auto p2 = vi.begin();
    while(cp--){
        rs += vi[i++];
        p2++;
    }
    long double max = rs;
    
    for (auto p1 = vi.begin(),end = vi.end(); p2 != end; p2++, p1++)
    {
        rs += *p2;
        rs -= *p1;
        if(rs>max)
            max = rs;
    }
    cout.setf(ios::showpoint);
    cout.precision(12);
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 6128
#include <stdio.h>
int main(void){
    int n,m,i;
    int ans;
    for(;;){
        ans=1;
        scanf("%d",&n);
        if(n==0){
            break;
        }
        m=n;
        for(i=2;i<m;i++){
            if(n%i==0){
                if(n==i*i){
                    ans=ans+i;
                    break;
                }else{
                    ans=ans+i+(n/i);
                    m=n/i;
                }
            }
        }
        if(n==1){
            printf("deficient number\n");
        }else if(ans==n){
            printf("perfect number\n");
        }else if(ans<n){
            printf("deficient number\n");
        }else{
            printf("abundant number\n");
        }
    }
    return 0;
}

Measured memory_bytes: 584
#入力受け取りの高速化、しなくてもよい
#但し文字列のまま扱うときは注意、例えば . は46として、 # は35として扱われる
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
#ここまでが高速化
h,w=map(int,input().split())
nx,ny=map(int,input().split())
gx,gy=map(int,input().split())
maze=inputs()
#0 based index (0始まり)にする
nx-=1;ny-=1;gx-=1;gy-=1
from collections import deque
#dqが徒歩、2が魔法での移動を入れる
dq=deque([(nx,ny)])
dq2=deque([])
#かかるコストを保存しておく
T=[[float('inf')]*w for  a in range(h)]
#初期値は0で、スタート地点に保存
T[nx][ny]=0
#徒歩でのx,yの差分
moves=((1,0),(-1,0),(0,1),(0,-1))
from itertools import product as pr
#魔法での移動の差分、tuple( (i,j) |-2<=i,j<=2かつ(i,j)!=(0,0)  )と等価
Mmoves=tuple(i for i in pr((-2,-1,0,1,2),repeat=2)if i!=(0,0) )

while dq:
    #先に徒歩で行けるだけ行きたいので、徒歩を使い切るまでは魔法で行った地点たちに手を出さない
    while dq:
        x,y=dq.popleft()
        for i,j in moves:
            nex,ney=x+i,y+j
            #盤面の外や壁にぶつかるのは除外
            if not(0<=nex<h and 0<=ney<w) or maze[nex][ney]==35:continue
            if T[x][y]<T[nex][ney]:
                #コストを更新できるなら改めて捜査
                T[nex][ney]=T[x][y]
                dq.append((nex,ney))
        for i,j in Mmoves:
            nex,ney=x+i,y+j
            if not(0<=nex<h and 0<=ney<w) or maze[nex][ney]==35:continue
            if T[x][y]+1<T[nex][ney]:
                T[nex][ney]=T[x][y]+1
                dq2.append((nex,ney))
    #徒歩で行ける地点を使い切ったので、今度は魔法で行ける地点を捜査
    dq,dq2=dq2,dq
if T[gx][gy]==float('inf'):print(-1)
else:print(T[gx][gy])

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

int gcd( int m, int n )
{
    // 引数に０がある場合は０を返す
    if ((0==m) || (0==n)) return 0;

    // ユークリッドの方法
    if(m<n) swap(m,n);
    int r;
    while((r = m%n) != 0){
        m = n;
        n = r;
    }
	return n;
}

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

    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n) cin >> a[i];

    sort(a.begin(),a.end());
    if(k > a[n-1]){
        cout << "IMPOSSIBLE\n";
        return 0;
    }

    int adiv = a[0];
    REP(i,n) adiv = gcd(adiv,a[i]);
    if(k%adiv) cout << "IMPOSSIBLE\n";
    else cout << "POSSIBLE\n";
    return 0;
}


Measured memory_bytes: 640
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
p = len(list(set(ls)))
if p <= k:
    print(0)
    sys.exit()
di=[float("inf")]*n
for i in range(n):
    if di[ls[i]-1] == float("inf"):
        di[ls[i]-1] = 1
    else:
        di[ls[i]-1] += 1
di.sort(reverse=True)
q = 0 
while True:
    s = di.pop()
    p -= 1
    q += s
    if p <= k:
        print(q)
        sys.exit()

Measured memory_bytes: 95568
n,m = gets.chomp.split().map(&:to_i)

a = []
n.times do
  a.push gets.chomp.split().map(&:to_i)
end

a = a.sort_by{|k,v| k}

ans = 0
a.each do |k, v|
  if v < m
    m -= v
    ans += v * k
  else
    ans += k * m
    break
  end
end

puts ans

Measured memory_bytes: 12664
#include <stdio.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < n; ++i)

int main(void) {
  int i, n, j;
  while( 1 ) {
    scanf("%d", &n);
    if(!n) break;
    double a[n], ave = 0, sum = 0;
    rep(i, n) {
      scanf("%lf", &a[i]);
      ave += a[i];
    }
    ave /= n;
    rep(i, n) sum += (a[i] - ave) * (a[i] - ave);
    sum /= n;
    sum = sqrt(sum);
    printf("%f\n", sum);
  }
  return 0;
}


Measured memory_bytes: 2752
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
char c,s[200005];
int n,len,cc,p[200005];
bool v[26];
int main()
{
	scanf("%s",s);
	n=strlen(s);
	len=1;
	p[0]=n;
	for(int i=n-1;i>=0;i--)
	{
		if(!v[s[i]-'a'])v[s[i]-'a']=1,cc++;
		if(cc==26)p[len++]=i,memset(v,0,sizeof(v)),cc=0;
	}
	memset(v,0,sizeof(v));
	for(int i=0;i<p[len-1];i++)v[s[i]-'a']=1;
	for(int i=0;i<26;i++)if(!v[i]){printf("%c",c=('a'+i));break;}
	for(int i=len-1;i>=1;i--)
	{
		int pos;memset(v,0,sizeof(v));
		for(pos=p[i];pos<p[i-1];pos++)if(s[pos]==c)break;
		for(pos++;pos<p[i-1];pos++)v[s[pos]-'a']=1;
		for(int j=0;j<26;j++)if(!v[j]){printf("%c",c=('a'+j));break;}
	}
	puts("");
	return 0;
}

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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
        cout << "YES\n";
    }else cout << "NO\n";
}


Measured memory_bytes: 256
N = int(input())
MOD = 10 ** 9 + 7
memo = [{} for _ in range(N)]
def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if 'AGC' in ''.join(t):
            return False
    return True
def dfs(cur, last3):
    if cur == N:
        return 1
    elif last3 in memo[cur]:
        return memo[cur][last3]
    else:
        ret = 0
        for c in 'ACGT':
            if ok(last3 + c):
                ret += dfs(cur + 1, last3[1:] + c)
        ret = ret % MOD
        memo[cur][last3] = ret
        return ret
print(dfs(0, '   '))

Measured memory_bytes: 3872
n=int(input())
A=list(map(int,input().split()))

def counting_sort(A):
    n=len(A)
    K=max(A)
    C=[0]*(K+1)
    for i in range(n):
        C[A[i]]+=1
    
    for i in range(1,K+1):
        C[i]=C[i-1]+C[i]

    ans=[0]*n

    for j in range(n-1,-1,-1):
        ans[C[A[j]]-1] = A[j]
        C[A[j]] -= 1
    return ans

print(*counting_sort(A))


Measured memory_bytes: 224380
X = int(input())

L = [0]
for i in range(1, 10 ** 5):
    L.append(L[i - 1] + i)

ans = 0
for i in range(1, X + 1):
    # print(L[i])
    if L[i] >= X:
        ans = i
        break


print(ans)


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

int main(void){
  int n;
  cin >> n;
  char c;
  vector<int> inp(n,0);
  vector<int> inprev(n,1);
  for(int i=0;i<n;i++){
    cin >> c;
    if(c=='W'){
      inp[i]=1;
      inprev[i]=0;
    }
  }
  vector<int> cost_up(n,0);
  vector<int> cost_down(n,0);
  for(int i=0;i<n;i++){
    cost_up[i+1]=cost_up[i]+inp[i];
    cost_down[i+1]=cost_down[i]+inprev[i];
  }
  vector<int> ans(n,0);
  for(int i=0;i<n;i++){
    ans[i]+=cost_up[i]-cost_up[0]+cost_down[n]-cost_down[i+1];
  }
  sort(ans.begin(), ans.end());
  cout << ans[0] << endl;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,x,y;
int dist[2001][2001];
int ans[2001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>x>>y;
	rep(i,n)
	rep(j,n){
		dist[i][j]=abs(j-i);
	}
	x--,y--;
	rep(i,n)
	forn(j,i+1,n){
		dist[i][j]=min(dist[i][j],abs(i-x)+1+abs(j-y));
	}
	rep(i,n)
	forn(j,i+1,n)
	ans[dist[i][j]]++;
	rep(i,n-1)
	cout<<ans[i+1]<<"\n";
	re 0;
}

Measured memory_bytes: 15872
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;


int main() {
    long long N, T;
    cin >> N >> T;
    long long ans = T;
    vector<long long>t(N);
    for (int i = 0; i < N; i++) {
        cin >> t[i];
        if (i != 0)ans += min(t[i] - t[i - 1], T);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007; 
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}






int main(){
    int N; std::cin >> N;
    std::vector<std::vector<int>> abc(N, std::vector<int>(3));
    std::vector<std::vector<int>> dp(N, std::vector<int>(3));
    for(int i(0); i < N; ++i){
        for(int j(0); j < 3; ++j){
            std::cin >> abc[i][j];
        }
    }
    for(int j(0); j < 3; ++j) dp[0][j] = abc[0][j];
    for(int i(1); i < N; ++i){
        for(int j(0); j < 3; ++j){
            for(int k(0); k < 3; ++k){
                if(j == k) continue;
                chmax(dp[i][j], dp[i-1][k] + abc[i][j]);
            }
        }
    }
    int mx(0);
    for(int j(0); j < 3; ++j) chmax(mx, dp[N-1][j]);
    std::cout << mx << std::endl;
    return 0;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e9
#define MOD 1000000007

int main()
{

    string cur, prev;
    ll n;
    cin >> n;
    map<string,ll> m;
    bool tf=1;
    cin >> cur;
    m[cur]++;
    for(ll i = 1; i < n; i++)
    {

        prev = cur;
        cin >> cur;
        if(m[cur] || prev[prev.size()-1] != cur[0]) tf=0;
        m[cur]++;
    }
    if(tf) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<functional>

using namespace std;

int l;

vector<int> split(int d) {
    vector<int> res;

    for(int i=0; i<l; i++) {
        res.push_back(d%10);
        d /= 10;
    }
    return res;
}

int join(vector<int> d) {
    int res=0,w=1;
    for(int i=0; i<l; i++) {
        res += w*d.back(); d.pop_back();
        w *= 10;
    }
    return res;
}

int main(void) {
    while(true) {
        vector<int> hist;

        int a;
        scanf("%d%d", &a, &l);
        if(!l) break;

        hist.push_back(a);

        for(int i=0; i<30; i++) {
            vector<int> sp = split(a);
            sort(sp.begin(), sp.end(), greater<int>());
            a = join(sp);
            sort(sp.begin(), sp.end());
            a -= join(sp);
            vector<int>::iterator it;
            if((it = find(hist.begin(), hist.end(), a)) != hist.end()) {
                printf("%d %d %d\n",it-hist.begin(), a, i-(it-hist.begin())+1);
                break;
            }
            hist.push_back(a);
        }
    }
    return 0;
}

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


void solve(long long N, long long L, std::vector<std::string> S){
    sort(S.begin(), S.end());
    string ans = S[0];
    for(ll i=1; i< N; i++) ans += S[i];
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long L;
    scanf("%lld",&L);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, L, std::move(S));
    return 0;
}


Measured memory_bytes: 256
import heapq

N=int(input())
A=sorted(map(int,input().split()))[::-1]
que = []
for x in A:
    heapq.heappush(que, -x)

ans=A[0]
while len(que) > 1:
    v1 = abs(heapq.heappop(que))
    v2 = abs(heapq.heappop(que))
    if v2 == 0:
        print (v1)
        break
    heapq.heappush(que, -(v1 % v2))
    heapq.heappush(que, -(v2))



Measured memory_bytes: 14180
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m=nii()
h=lnii()

tree=[[] for i in range(n)]
for i in range(m):
  a,b=nii()
  a-=1
  b-=1
  tree[a].append(h[b])
  tree[b].append(h[a])

ans=0
for i in range(n):
  if tree[i]:
    if  h[i]>max(tree[i]):
      ans+=1
  else:
    ans+=1

print(ans)

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

int main(void){
    int n, m;
    cin >> n >> m;
    
    char a[50][52], b[50][52];
    
    int i;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }
    for(i = 0; i < m; i++){
        cin >> b[i];
    }
    
    bool flg;
    int j, k, l;
    for(i = 0; i < n - m + 1; i++){
        for(j = 0; j < n - m + 1; j++){
            flg = true;
            for(k = 0; k < m; k++){
                for(l = 0; l < m; l++){
                    if(a[i + k][j + l] != b[k][l]){
                        flg = false;
                        break;
                    }
                }
                if(flg == false){
                    break;
                }
            }
            if(flg == true){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    
    cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s = [list(input().split()) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == 'snuke':
            num = i + 1
            alpha = j + 1
            break

num2alpha = lambda c: chr(c+64)

print(str(num2alpha(alpha)) + str(num))

Measured memory_bytes: 3060
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(i=0;i<n;i++)
using namespace std;
int main() {
	int a,b,c;
    cin >> a >> b >> c;
    int A = b - a;
    int B = c - b;
    if (A == B) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    long long n;
    cin >> n;
    long long left, right;
    left = right = 0;
    long long a, b;
    cin >> a >> b;
    left = a;
    right = b;
    for (long long i=1; i<n; i++) {
        cin >> a >> b;
        long long multiple = max((left-1)/a+1, (right-1)/b+1);
        left = a * multiple;
        right = b * multiple;
    }
    cout << left+right << endl;
    return 0;
}


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

int main(){
  while(1){
    int h, w; cin >> h >> w;
    if(h == 0 && w == 0) break;

    int yoko = w;

    cout << string(yoko, '#') << endl;
    h -= 2; w -= 2;
    rep(i,h){
      cout << '#';
      rep(j,w){
        cout << '.';
      }
      cout << '#' << endl;
    }
    cout << string(yoko, '#') << endl;
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define chmin(x, a) do { x = min(x, a); } while(0)

using namespace std;

const int M = 998244353;
int N, S;
// U ⊆T ⊆A
int a[3001];
int dp[3001][3001];

int main() {
  cin >> N >> S;
  for (int i = 1; i <= N; i++)
    cin >> a[i];
  dp[0][0] = 1;
  for (int i = 0; i < N; i++) for (int j = 0; j <= S; j++) {
    int ni = i + 1;

    // 1) a[ni] が U に含まれる
    int nj = j + a[ni];
    if (nj <= S) (dp[ni][nj] += dp[i][j]) %= M;

    // 2) a[ni] が T に含まれる
    (dp[ni][j] += dp[i][j]) %= M;

    // 3) a[ni] が U,T に含まれない
    (dp[ni][j] += dp[i][j]) %= M;
  }
  cout << dp[N][S] << endl;
  return 0;
}

Measured memory_bytes: 38772
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextIntSlice(size int) []int {
	re := make([]int, size)
	for i := 0; i < size; i++ {
		re[i] = nextInt()
	}
	return re
}

func max(a []int) int {
	max := a[0]
	for _, v := range a {
		if v > max {
			max = v
		}
	}
	return max
}

func min(a []int) int {
	min := a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
	}
	return min
}

func main() {
	sc.Split(bufio.ScanWords)
	h, w := nextInt(), nextInt()
	a := make([]string, h)
	for i := 0; i < h; i++ {
		a[i] = nextLine()
	}

	tbframe(w + 2)
	for i := 0; i < h; i++ {
		fmt.Print("#")
		fmt.Print(a[i])
		fmt.Print("#")
		fmt.Println()
	}
	tbframe(w + 2)

}

func tbframe(w int) {
	for i := 0; i < w; i++ {
		fmt.Print("#")
	}
	fmt.Println()
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999


int main() {
	int n;
	cin >> n;
	cout << (8 * n - 2 * (n / 15)) * 100 << endl;

	return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int a,b;
int main(){
  cin >> a >> b;
  int ans = max(a*2-1, max(a+b, b*2-1));
  cout << ans << endl;
  return 0;
}

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

int main(){
    while(1){
        char ch[1001];
        
        scanf("%s",ch);
        
        if(ch[0] == '0') break;
        
        int sum = 0,i = 0;
        
        while(ch[i] != 0){
            sum += ch[i] - '0';
            i++;
        }
        cout << sum << endl;
    }
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	vector<vector<ll>> M(10,vector<ll>(10,0));
	REP(i,N){
		ll V=i+1;
		ll last=V%10,start;
		while(V){
			start=V%10;
			V/=10;
		}
		M[start][last]++;
	}

	ll S=0;
	REP(i,9){
		REP(j,9){
			S += (M[i+1][j+1]*(M[j+1][i+1]));
		}
	}

	out(S);
	return 0;
}


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

int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if(x-r<0 || x+r>W){
    cout << "No" << endl;
    return 0;
  }
  if(x-r>=0 && x+r<=W){
    if(y-r<0 || y+r>H){
      cout << "No" << endl;
      return 0;
    } else{
      cout << "Yes" << endl;
      return 0;
    }
  }
}
  


Measured memory_bytes: 3092
#include <stdio.h>
#include <cmath>
#include <stdlib.h>
#include <algorithm>

int main()
{
    long long x;
    int minValue = 999;
    int i;
    constexpr long long pows[11] = {
        1,
        10,
        100,
        1000,
        10000,
        100000,
        1000000,
        10000000,
        100000000,
        1000000000,
        10000000000,
    };

    scanf("%ld", &x);
    for (i = 3; i < 11; i++)
    {
        if (x >= pows[i - 1])
        {
            int a = (x % pows[i]) / pows[i - 3];
            minValue = std::min(abs(753 - a), minValue);
            //printf("%d ", a);
        }
        else
        {
            break;
        }
    }

    printf("%d", minValue);
    return 0;
}

Measured memory_bytes: 128
import os,io
import sys
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
r,c,k=map(int,input().split())
dp = [[[0 for y in range(c)] for z in range(r)] for P in range(4)]
m=[]
for i in range(r):
  m.append([])
  for j in range(c):
    m[i].append(0)
for i in range(k):
  ri,ci,v=map(int,input().split())
  m[ri-1][ci-1]=v
dp[0][0][0]=0
dp[1][0][0]=m[0][0]
dp[2][0][0]=m[0][0]
dp[3][0][0]=m[0][0]
for i in range(r):
  for j in range(c):
    if j+1<c:
      dp[0][i][j+1]=max(dp[0][i][j+1],dp[0][i][j])
      dp[1][i][j+1]=max(dp[1][i][j],max(dp[1][i][j+1],dp[0][i][j]+m[i][j+1]))
      dp[2][i][j+1]=max(dp[2][i][j],max(dp[2][i][j+1],dp[1][i][j]+m[i][j+1]))
      dp[3][i][j+1]=max(dp[3][i][j],max(dp[3][i][j+1],dp[2][i][j]+m[i][j+1]))
    if i+1<r:
      dp[0][i+1][j]=dp[3][i][j]
      dp[1][i+1][j]=dp[3][i][j]+m[i+1][j]
      dp[2][i+1][j]=dp[3][i][j]+m[i+1][j]
      dp[3][i+1][j]=dp[3][i][j]+m[i+1][j]
print(dp[3][r-1][c-1])
    

Measured memory_bytes: 468416
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	string S;
  	cin >> S;
  	vector<char> A;
  	for(int i = 0; i < S.size(); i++){
    	A.push_back(S[i]);
    }
  	A.push_back('e');
  	int s = 0;
  	int t = 1;
    int count = 0;
/*  	for(int i = 0; i < A.size(); i++){
    	cerr << A[i] << endl;
    }*/
  	while(A[t]!='e' && A[s]!='e'){
    	if((A[t] == '0' && A[s] == '1') || (A[t] == '1' && A[s] == '0')){
        	A.erase(A.begin()+t);
          	A.erase(A.begin()+s);
            count += 2;
          	if(s>0){
            	s--;
              	t--;
            }
       	} else {
        	s = t;
          	t++;
        }
    }
  	cout << count << endl;
}

Measured memory_bytes: 640
/*input
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
*/
#include<bits/stdc++.h>
using namespace std;

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define X first
#define Y second
#define pb push_back
#define all(s) s.begin(),s.end()

typedef pair<int,int> ii;
typedef long long ll;

const int MOD = 1e9+7;

void solve(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++) 
        cin >> a[i] >> b[i] >> c[i];

    int dp[n][3];
    // memset(dp,INT_MAX,sizeof dp);
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i=1;i<n;i++){
        dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

int main(){
    FIN;   
    // test
    solve();
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define DEB 1
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

pair<string,string> pss[12];
map<string,int> msi;

string subplace(string &s, int i){
  int p = 0;
  string ret = s;
  while( (p=ret.find(pss[i].first,p))!=string::npos ){
    ret.replace(p, pss[i].first.length(), pss[i].second);
    p += pss[i].second.size();
  }
  return ret;
}

int main(){
  int n;
  while(cin>>n,n){
    msi.clear();
    rep(i,n){
      cin >> pss[i].first >> pss[i].second;
    }
    string a,b;
    cin>>a>>b;
    
    int ans = -1;
    queue<pair<string,int> > q;
    q.push(mp(a,0));
    msi[a] = 0;
    while( !q.empty() ){
      string s = q.front().first;
      int c = q.front().second;
      q.pop();
      if( s.length() > 100 )break;
      if( s==b ){
	ans = c;
	break;
      }
      rep(i,n){
	string tmp = subplace(s,i);
	if( msi.find(tmp)==msi.end() ){
	  q.push(mp(tmp,c+1));
	  msi[tmp] = c+1;
	}
      }
    }
    
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3108
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
b=-1
ans=[0,0]
for ai in a:
  if len(ans)==4:
    break
  if b==ai:
    ans.append(ai)
    b=-1
  else:
    b=ai
print(ans[-1]*ans[-2])


Measured memory_bytes: 14252
#include <iostream>
using namespace std;
string str;
int main(void){
    // Your code here!
    cin >> str;
    if(str[0] == 'a' || str[0] == 'i' || str[0] == 'u' || str[0] == 'e' || str[0] == 'o') cout << "vowel" << endl;
    else cout << "consonant" << endl;
}


Measured memory_bytes: 256