akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
	map<char, bool> mp;
	string S;
	bool check = true;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		mp[S[i]] = !mp[S[i]];
	}
	for (auto i = mp.begin(); i != mp.end(); ++i) {
		if (i->second == true) check = false;
	}
	if (check) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main ()
{
    char s[20];
    gets (s);
    int i,count=0;
    for (i=0;s[i]!='\0';i++)
    {
        if (s[i]=='x')
        {
            count++;
        }

    }
    if ((15-count)<8)
    {
        printf ("NO\n");
    }
    else
        printf ("YES\n");

    return 0;
}


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

int main(void) {
    int n, m, ret, t, i;
    ret = -1234567890;
    cin >> n;
    cin >> m;

    for (i = 1; i < n; i++) {
        cin >> t;
        ret = max(ret, t - m);
        m = min(m, t);
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <iterator>
#include <vector>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;

int h, w;
vector<string> v;

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

int res = 0;

int s(int sy, int sx){
  queue<pair<p, int>> st;
  st.push({{sy, sx}, 0});
  int vis[h][w];
  rep(i, h)rep(j, w) vis[i][j] = false;
  vis[sy][sx] = true;

  while(!st.empty()){
    int y = st.front().first.first;
    int x = st.front().first.second;
    int d = st.front().second;

    st.pop();

    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      int nd = d+1;
      if(ny < 0 || nx < 0) continue;
      if(ny >= h || nx >= w) continue;
      if(v[ny][nx] == '#') continue;
      // cout << ny << ' ' << nx << endl;

      if(!vis[ny][nx]){
        vis[ny][nx] = true;
        st.push({{ny, nx}, nd});
        res = max(res, nd);
      }
    }

  }
  return -1;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  v = vector<string> (h);
  rep(i, h) cin >> v[i];

  for (int sy = 0; sy < h; sy++) {
    for (int sx = 0; sx < w; sx++) {
      if(v[sy][sx] == '#') continue;
      res = max(s(sy, sx), res);
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
int gi() { int x;cin>>x;return x;}
int m,ans;
int head[N],nxt[N];
inline int dfs(int k) {
	int mx=0,i,t;
	for (i=head[k];i;i=nxt[i]) {
		t=dfs(i)+1;
		if (t==m) ans++;
		else mx=max(mx,t);
	}
	return mx;
}
int main()
{
	int n=gi(),i,k;m=gi();
	ans=gi()!=1;
	for (i=2;i<=n;i++) nxt[i]=head[k=gi()],head[k]=i;
	for (i=head[1];i;i=nxt[i]) dfs(i);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2560
N,M=map(int,input().split())

pair=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
graph=[[0]*N for _ in range(N)] 


for p in pair:
	graph[p[0]][p[1]]= graph[p[1]][p[0]]=1
	
def DFS(v):
	if visited[v]:
		return 
	visited[v]=True
	for j in [j for j,v2 in enumerate(graph[v]) if v2==1]:
		DFS(j)
		
res = 0

for i in range(M):
	visited=[False for _ in range(N)] 
	x,y=pair[i]
	graph[x][y]=graph[y][x]=0 
	DFS(0 if i>0 else 1)
	
	if not all(visited):
		res+=1
	
	graph[x][y]=graph[y][x]=1

print(res)

Measured memory_bytes: 3064
n , k = map(int, input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(n)

for i in range(n):
    uf.union(i,p[i]-1)

ma = float('INF')*(-1)
listcase = []
cc=0
for i in uf.roots():
    st = uf.members(i)[0]
    listcase.append([])
    while True:
        listcase[cc].append(c[st])
        st=p[st]-1
        if st == uf.members(i)[0]:
            break
    cc+=1

for i in listcase:
    m = len(i)
    i2=i*2
    su = 0
    if sum(i)>0:
        su = sum(i)*(k//m)
    m2 = k%m
    if m2==0 and su>0:
        m2=m
        su-=sum(i)
    elif m2==0:
        m2=m
    if sum(i)<=0:
        m2=m
    for l in range(m):
        dp=[float('INF')*(-1)]*(m*2)
        dp[l]=i2[l]
        for j in range(l+1,l+m2):
            dp[j]=max(dp[j-1]+i2[j],i2[j])
        ma = max(ma,su+max(dp))
print(ma)


Measured memory_bytes: 134280
args=list(map(int,input().strip().split()))

msg = ['Yes', 'No']

a = args[2] - args[1] - args[0]
b = args[0] * args[1] * 4

if((a>0)and(pow(a,2)>b)):
    print(msg[0])
else:
    print(msg[1])


Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


#define X real()
#define Y imag()
typedef complex<double> P;

int main(){
	  
	  int a;
	  while(cin>>a){
	  	vector<int> A;
		A.push_back(a);
		rep(i,3){
			int b;
			cin>>b;
			A.push_back(b);
		}
		
		vector<int> B;
		rep(i,4){
			int b;
			cin>>b;
			B.push_back(b);
		}
		
		int hit=0;
		int blow = 0;
		rep(i,4){
			rep(j,4){
				if(A[i]==B[j]){
					if(i==j)hit++;
					else blow++;
				}
				
			}
		}
		
		printf("%d %d\n",hit,blow);
	  }
	
}

Measured memory_bytes: 1180
N, K = map(int, input().split())
*V, = map(int, input().split())

def solve(x, y):
    S = []
    r = 0
    for i in range(x):
        S.append(V[i])
        r += V[i]
    for i in range(N-1, N-y-1, -1):
        S.append(V[i])
        r += V[i]
    S.sort()
    for i in range(min(K-x-y, x+y)):
        if S[i] >= 0:
            break
        r -= S[i]
    return r

ans = 0
for i in range(K+1):
    for j in range(min(K-i+1, N-i+1)):
        ans = max(ans, solve(i, j))

print(ans)

Measured memory_bytes: 3064
// ABC 153-C
// 2020.1.26 bal4u

#include <stdio.h>

typedef long long ll;

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0; int c;
	c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void Qsort(int *a, int l, int r) {
	int i, j, m; int t;
	
	i = l, j = r, m = a[(l+r) >> 1];
	while (1) {
#if 1  // 昇順
		while (a[i] < m) i++;
		while (m < a[j]) j--;
#else  // 降順
		while (a[i] > m) i++;
		while (m > a[j]) j--;
#endif
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}

int N;
int H[200005];

int main()
{
	int i, K, N;
	ll s;
	
	N = in(), K = in();
	for (i = 0; i < N; ++i) H[i] = in();
	Qsort(H, 0, N-1);
	s = 0, N -= K;
	for (i = 0; i < N; ++i) s += H[i];
	printf("%lld\n", s);
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int countDivisors(int x)
{
    int cnt=0;
    for(int i=1;i*i<=x;i++)
    {
        if(x%i==0)
        {
            if(x/i==i)
                cnt+=1;
            else
                cnt+=2;
        }
    }
    return cnt;
}
int main(int argc, const char * argv[])
{
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%2==0)
            continue;
        if(countDivisors(i)==8)
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
int h[100100];
vector < int > v[100100];

int main()
{
    int n,m;  cin >> n >> m;
    for(int i = 1;i<=n;i++)  cin >> h[i];
    int Ans = 0;
    while(m--){
        int x,y;  cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i = 1;i<=n;i++){
        bool ch = true;
        for(auto j : v[i])  ch&=(h[i] > h[j]);
        if(ch)  Ans++;
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 9148
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int x,y,z,b=0,c=0,i;
  int a[2]={500,5};
  cin>>x;
  for(i=0;i<2;i++)
  {
	y=x/a[i];
    if(a[i]==500)
    b+=y;
    if(a[i]==5)
    c+=y;
    x%=a[i];
  }
  z=b*1000+c*5;
  cout<<z;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D, N; cin >> D >> N;
    if(N == 100) N++;
    cout << N;
    rep(i, D) cout << "00";
    cout << endl;

    return 0;
}


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

int n;

int main() {
  cin >> n;
  vector<int> h(n);
  rep (i, n) {
    cin >> h[i];
  }
  string ans = "Yes";
  for (int i = n-2; i > 0; i--) {
    if (h[i+1] < h[i]) h[i]--;
    if (h[i+1] < h[i]) ans = "No";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int n,r;
char s[200001],t[200001];
int main()
{ cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin>>s>>t;
  n=strlen(s);
  for(int i=0;i<n;i++)
    if(s[i]!=t[i])
       r++;
  cout<<r<<'\n';
  return 0;
}


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

using namespace std;

const int N=1e5+10;

int n,a[N];
int psum[N];
int main(){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=n;i>=1;i--) psum[i]=psum[i+1]+abs(a[i]-a[i+1]);
        int sum=0;
        for(int i=1;i<=n;i++){
                sum+=abs(a[i]-a[i-1]);
                cout<<sum+psum[i]-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i+1]-a[i-1])<<'\n';
        }
}


Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>

struct node{
	struct node *right;
	struct node *left;
	struct node *parent;
	int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
	Node c = x;
	while (c->left != NIL){
		c = c->left;
	}
	return c;
}

Node treeMaximum(Node x){
	Node c = x;
	while (c->right != NIL){
		c = c->right;
	}
	return c;
}

Node treeSearch(Node u, int k){
	if (u == NIL) return NIL;
	if (u->key == k){
		return u;
	}
	else if (u->key > k){
		Node n = treeSearch(u->left, k);
		if (n != NIL) return n;
	}
	else{
		Node m = treeSearch(u->right, k);
		if (m != NIL) return m;
	}
	return NIL;
}


Node treeSuccessor(Node x){
	if (x->right != NIL){
		return treeMinimum(x->right);
	}
	else{
		Node c = x;
		while (c != root){
			if (c->parent->left == c){
				return c->parent;
				break;
			}
		}
		return NIL;
	}
}

void treeDelete(Node z){
	if (z->left == NIL && z->right == NIL){
		if (z->parent->left == z){
			z->parent->left = NIL;
		}
		else{
			z->parent->right = NIL;
		}
		delete z;
	}
	else if (z->left == NIL){
		if (z->parent->left == z){
			z->parent->left = z->right;
		}
		else{
			z->parent->right = z->right;
		}
		z->right->parent = z->parent;
		delete z;
	}
	else if (z->right == NIL){
		if (z->parent->left == z){
			z->parent->left = z->left;
		}
		else{
			z->parent->right = z->left;
		}
		z->left->parent = z->parent;
		delete z;
	}
	else{
		Node y = treeSuccessor(z);
		z->key = y->key;
		treeDelete(y);
	}
}

void insert(int k){
	Node y = NIL;
	Node x = root;
	Node z = new node;

	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL){
		y = x;
		if (z->key < x->key){
			x = x->left;
		}
		else{
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else if (z->key < y->key){
		y->left = z;
	}
	else{
		y->right = z;
	}

	return;


}

void inorder(Node u){
	if (u->left != NIL) inorder(u->left);
	printf(" %d", u->key);
	if (u->right != NIL) inorder(u->right);
	return;
}
void preorder(Node u){
	printf(" %d", u->key);
	if (u->left != NIL) preorder(u->left);
	if (u->right != NIL) preorder(u->right);
	return;
}


int main(){
	int n, i, x;
	char com[20];
	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%s", com);
		if (com[0] == 'f'){
			scanf("%d", &x);
			Node t = treeSearch(root, x);
			if (t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if (com[0] == 'i'){
			scanf("%d", &x);
			insert(x);
		}
		else if (com[0] == 'p'){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com[0] == 'd'){
			scanf("%d", &x);
			treeDelete(treeSearch(root, x));
		}
	}

	return 0;
}


Measured memory_bytes: 21872
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn two_count(n: u64) -> u32 {
    let mut n = n;
    let mut res = 0;
    while n % 2 == 0 {
        res += 1;
        n /= 2;
    }
    res
}

fn solve() {
    input! {
        n: usize, m: u64,
        av: [u64; n]
    };

    let two_counts = av.iter().map(|&a| two_count(a)).collect::<Vec<_>>();
    let is_ok = two_counts.iter().collect::<HashSet<_>>().len() == 1;
    if !is_ok {
        println!("0");
        return;
    }
    let two_p = two_counts[0];
    let odd_lcm = av
        .iter()
        .map(|&a| {
            let m = 2.pow(two_p);
            a / m
        })
        .fold(1, |acc, x| acc.lcm(&x));
    let first_gcd = 2_u64.pow(two_p - 1) * odd_lcm;
    let res = if first_gcd > m {
        0
    } else {
        1 + (m - first_gcd) / (first_gcd * 2)
    };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 3372
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#include <stack>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll D, G;
	cin >> D >> G;
	vector<ll> P(D), C(D); 
	ll sum = 0;
	FOR(i, D) {
		cin >> P[i] >> C[i];
		sum += P[i];
	}

	ll ans = sum;
	FOR(i, 1 << D) {
		set<ll> complete_idx_set;
		ll score = 0;
		ll num = 0;
		FOR(j, D) {
			if ( (i & (1 << j)) != 0) {
				complete_idx_set.insert(j);
				score += 100 * (j + 1) * P[j] + C[j];
				num += P[j];
			}
		}
		//ll idx = -1;
		FOR(_ri, D) {
			auto  ri = D - 1 - _ri;
			if (!complete_idx_set.count(ri)) {
				auto cnt = P[ri];
				auto pnt = 100 * (ri + 1);
				if (score + cnt * pnt >= G) {
					while (score < G) {
						num += 1;
						score += pnt;
					}
					chmin(ans, num);
				}
				else break;
			}
		}
	}
	cout << ans << endl;


	return 0;
}
 	


Measured memory_bytes: 256
N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = float('inf')

for i in range(1<<N):
    seen = 1
    pay = 0
    now = a[0]
    for j in range(1, N):
        if (i >> j) & 1:
            if a[j] <= now:
                pay += now - a[j] + 1
                now += 1
                seen += 1
            else:
                break
        else:
            if a[j] > now:
                seen += 1
                now = a[j]
        if seen >= K:
            ans = min(ans, pay)
            break


print(ans)

Measured memory_bytes: 73484
//FIRST THINK, THEN CODE.


#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}
 
const ll mxn=1e6+5;





int main()
{ 
IOS;


ll n;

cin>>n;

ll tot=0;


vl a(n);

ll x=0;

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

for(int i=0;i<n;i++){
  ll d=x^a[i];
  cout<<d<<" ";
}

 return 0;
 
 
 
}

Measured memory_bytes: 4776
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val array = Array.fill(n - 1)(sc.nextLong)
  val ai = if (n > 2) {
    array
      .sliding(2)
      .map(b => Math.min(b(0), b(1)))
      .sum
  } else 0

  println(array(0) + array(n - 2) + ai)
}


Measured memory_bytes: 25540
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        
        int cnt = N / K;
        long ans = (long)cnt * cnt * cnt;
        
        if(  K % 2 == 0 ){
            int cnt2 = 0;
            int i = 1;
            while( K * i / 2 <= N ){
                i += 2;
                cnt2++;
            }
            
            ans += (long)cnt2 * cnt2 * cnt2;
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=100000;
    cin>>n;
    for(int i=0;i<=n;i++){
        int tmp=0,t=i;
        while(t){
            tmp+=t%6;
            t/=6;
        }
        t=n-i;
        while(t){
            tmp+=t%9;
            t/=9;
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
X,N=map(int,input().split())
p=list(map(int,input().split()))

m=float('inf')
l=[]
       
for i in range(-100,N+101):
    if i not in p:
        l.append(i)
    else:
        continue

for j in l:
    m=min(m,abs(X-j))
    
if (X-m) not in p:
    print(X-m)
else:
    print(X+m)

Measured memory_bytes: 9100
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	private static       boolean flg     = false;
	private static       int     index   = 0;
	private static final boolean SUCCESS = true;
	private static final int     EMPTY   = -1,
			                     END     = 10;

	private static int[]               pipe_A = new int[10];
	private static ArrayDeque<Integer> pipe_B = new ArrayDeque<Integer>(),
                                       pipe_C = new ArrayDeque<Integer>();

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in).useDelimiter(System.getProperty("line.separator"));
    	int n = sc.nextInt();

    	String[] s;
    	for(int i=0;i<n;i++){
    		s = sc.next().split("\\s");
    		for(int j=0;j<10;j++){pipe_A[j] = Integer.parseInt(s[j]);}
    		pipe_B.clear();
    		pipe_C.clear();
    		pipe_B.add(EMPTY);
    		pipe_C.add(EMPTY);
    		flg = false;
    		index = 0;
    		push('B');
			if   (flg){System.out.println("YES");}
			else      {System.out.println("NO"); }
    	}
    }

    private static void push(char pipe){

//    	System.out.println("index:" + index);
//    	System.out.print("pipe_B:");
//    	for(int i:pipe_B){System.out.print(i + " ");}
//    	System.out.println();
//    	System.out.print("pipe_C:");
//    	for(int i:pipe_C){System.out.print(i + " ");}
//    	System.out.println();
//
    	if(flg){return;}
    	if(index == END){
    		flg = SUCCESS;
    		return;
   		}
    	int ball = pipe_A[index];
    	switch (pipe) {
    		case 'B': {
    			if(pipe_B.peek() < ball ){
    				pipe_B.push(ball);
//    				System.out.println("B:push: index : " + index);
//    				System.out.println("B:ball : " + ball);
//    				System.out.println((pipe_B.peek()));
    		    	index++;
    		    	break;
    			} else {
    				return;
    			}
   			}
    		case 'C': {
    			if(pipe_C.peek() < ball){
    				pipe_C.push(ball);
//    				System.out.println("C:push: index : " + index);
//    				System.out.println("C:ball : " + ball);
//    				System.out.println((pipe_C.peek()));
    				index++;
    				break;
    			} else {
    				if(index == 0){return;}
    				if     (pipe_A[index - 1] == pipe_B.peek()){pipe_B.pop();}
    				else if(pipe_A[index - 1] == pipe_C.peek()){pipe_C.pop();}
    				index--;
    				return;
    			}
    		}
    	}
		push('B');
		push('C');
    }
}

Measured memory_bytes: 17312
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = Integer.parseInt(sc.next());
		long l[] = new long[h + 1];
		l[0] = 2;
		l[1] = 1;
		for (int i = 2; i <= h; i++)
			l[i] = l[i - 1] + l[i - 2];
		System.out.println(l[h]);
	}
}

Measured memory_bytes: 22604
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int N, M;

int d[20010];

signed main()
{
    cin >> N >> M;

    int p; cin >> p;

    rep(i, M) {
        cin >> d[i];
        d[i] = p > d[i] ? d[i] + N - p : d[i] - p;
    }

    sort(d, d + M);

    int mi = min(N - d[0], d[M - 1]);

    if (M == 1) {
        cout << mi * 100 << endl;
        return 0;
    }

    rep(i, M - 1) {
        chmin(mi, d[i] * 2 + (N - d[i + 1]));
        chmin(mi, (N - d[i + 1]) * 2 + d[i]);
    }

    cout << mi * 100 << endl;
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
struct UnionFind{
    vector<int> parent;
    vector<int> rank;
    UnionFind(int n):parent(n),rank(n){
        for (int i=0;i<n;i++){
            parent[i]=i;
            rank[i]=0;
        }
    }
    int root(int x){
        if (parent[x]==x)return x;
        return parent[x]=root(parent[x]);
    }
    void unite(int x, int y){
        int rx=root(x);
        int ry=root(y);
        if (rx==ry)return;
        if (rank[rx]<rank[ry]) parent[rx]=ry;
        else{
            parent[ry]=rx;
            if (rank[rx]==rank[ry]) rank[rx]++;
        }
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<int> p(n);
    for (int i = 0;i<n;i++)
        cin >> p[i];
    unordered_map<int,int> D;
    for (int i = 0; i < n;i++){
        D[p[i]-1] = i;
    }
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x, y);
    }
    int res=0;
    for(auto it:D){
        if(uf.same(it.first,it.second)){
            res++;
        }
    }
    cout << res << endl;


}

Measured memory_bytes: 6692
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)
#define l_ength size

int main(void){
	int n,ans=1;
	cin >> n;
	while(n>1){
		ans *= 2;
		n /= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def resolve():
    
    X=int(input())
    # A=list(map(int,input().split()))

    ans=""
    if(X<600):
        ans=8
    elif(X<800):
        ans=7
    elif(X<1000):
        ans=6
    elif(X<1200):
        ans=5
    elif(X<1400):
        ans=4
    elif(X<1600):
        ans=3
    elif(X<1800):
        ans=2
    else:
        ans=1

    print(ans)        


resolve()

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(ll i = (m); i < (n); ++i)

#define INF 1e9

ll F(ll a){
  if(a % 2){
    return (a+1)/2 % 2;
  }
  else{
    return F(a-1) ^ a;
  }
}

int main(){
  ll A, B;
  cin >> A >> B;
  cout << (F(B) ^ F(A-1)) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, N) for(int i = 0; i < N; i++)

char s[20];

int main() {
    int y, m, d;
    scanf("%d\/%d02\/%02d", &y, &m, &d);
    if (y <= 2019 && m <= 4 && d <= 30) printf("Heisei\n");
    else printf("TBD\n");
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    int[] arg = new int[4];
    bool[] op = new bool[3];
    void Run()
    {
        var sc = new Scanner();
        string s = sc.NextString();
        for (int i = 0; i < 4; i++) arg[i] = s[i] - '0';
        Dfs(0);
        Console.Write(arg[0]);
        for (int i = 0; i < 3; i++)
            Console.Write("{0}{1}", op[i] ? "+" : "-", arg[i + 1]);
        Console.WriteLine("=7");
    }

    bool Dfs(int i)
    {
        if (i == 3)
        {
            int res = arg[0];
            for (int j = 1; j < 4; j++)
                res += arg[j] * (op[j - 1] ? 1 : -1);
            return res == 7;
        }
        op[i] = true;
        if (Dfs(i + 1)) return true;
        op[i] = false;
        if (Dfs(i + 1)) return true;
        return false;
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
#include <cstdio>

int main()
{
  int a = 0;
  for (int i = 0; i < 4; ++i)
  {
    int b;
    scanf("%d", &b);
    a |= (1 << b);
  }
  puts(a == 658 ? "YES" : "NO");
  return 0;
}

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

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
// constexpr ll mod = 1e9 + 7;

int main(){
    int A, B;
    cin >> A >> B;

    ll ans = ceil(A/0.08)-10;

    while (ans<ceil((A+1)/0.08)+10) {
        if(floor(ans*0.08)==A && floor(ans*0.10)==B) {
            cout << ans << endl;
            return 0;
        } else {
            ans++;
        }
    }
    cout << -1 << endl;


    return 0;
}


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

int n;


priority_queue<int,vector<int>,greater<int>> que;

int main()
{
	cin >> n;

	for(int i = 0;i < 2 * n;i++)
	{
		int l;
		cin >> l;

		que.push(l);
	}

	int result = 0;

	for(int i = 0;i < n;i++)
	{
		result += que.top();
		que.pop();
		que.pop();
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int N,i;
    long long int  c=1000000000000000000,d=1;
    scanf("%d",&N);
    long long int A[N];
    for(i=0;i<N;i++)
    {
      scanf("%lld",&A[i]);
      if(A[i]==0)
        d=0;
    }
    for(i=0;i<N;i++)
    {
        if(A[i]==0) {
          d=0;
          break;
        }
        else if(c/A[i]<d)  {
          d=-1;
          break;
        }
        else d*=A[i];
    }
    printf("%lld",d);

    return 0;
}


Measured memory_bytes: 2888
N, M, Q = gets.split.map(&:to_i)
A = Array.new(N + 1) {Array.new(N + 1, 0)}
M.times do
  l, r = gets.split.map(&:to_i)
  A[l][r] += 1
end 

(1..N).each do |i|
  (i...N).each do |j|
    A[i][j+ 1] += A[i][j]
  end 
end 

N.downto(2).each do |j|
  j.downto(2).each do |i|
    A[i - 1][j] += A[i][j]
  end 
end

Q.times do
  pi, qi = gets.split.map(&:to_i)
  puts A[pi][qi]
end


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

int main(void){
    vector<string> str;
    vector<int> cnt;
    int n, m;
    string tmp;
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> tmp;
        auto itr = find(str.begin(), str.end(), tmp);
        if (itr == str.end()){
            str.emplace_back(tmp);
            cnt.emplace_back(1);
        } else{
            int index = distance(str.begin(), itr);
            cnt[index]++;
        }
    }
    cin >> m;
    for (int i=0; i<m; i++){
        cin >> tmp;
        auto itr = find(str.begin(), str.end(), tmp);
        if (itr == str.end()){
            str.emplace_back(tmp);
            cnt.emplace_back(-1);
        } else{
            int index = distance(str.begin(), itr);
            cnt[index]--;
        }
    }
    int ans = 0;
    for (auto x : cnt){
        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <math.h>
#include <limits.h>

using namespace std;
int dist(int x1,int y1,int x2,int y2){
  return abs(x1-x2)+abs(y1-y2);
}

int main(){
  int N,M;
  vector<int> a,b,c,d;
  cin >> N >> M;
  a.resize(N);
  b.resize(N);
  c.resize(M);
  d.resize(M);
  for(int i=0;i<N;i++){ cin >> a[i] >> b[i]; }
  for(int j=0;j<M;j++){ cin >> c[j] >> d[j]; }
  for(int i=0;i<N;i++){
    int min=INT_MAX;
    int index=0;
    for(int j=0;j<M;j++){
      int distance = dist(a[i],b[i],c[j],d[j]);
      if(min >  distance ){
         min = distance;
         index=j;
      }
     }
     cout << index+1 << endl;
  }
  return 0;
}

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

int main() {

  int N; cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  int i = 1;
  int c = 0;
  int M = 0;
  while (i < N) {
    if (H.at(i - 1) >= H.at(i)) {
      c++;
      if (i == N - 1) {
        M = max(M, c);
      }
    }
    else {
      M = max(M, c);
      c = 0;
    }
    i++;
  }
  cout << M << endl;
    
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  n %=100;
  n %=10;
  if(n==2 || n ==4 || n==5 || n ==7 ||n==9){
    cout << "hon" << endl;
  }else if (n == 3){
    cout << "bon" << endl;
  }else {
    cout << "pon" <<endl;
  }
}


Measured memory_bytes: 3564
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

int main() {
  int N; cin >> N;

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long a; cin >> a;
    ans += a - 1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()

total = 0
n = len(S)
ans = 0

for i in range(2**(n-1)):
    form = S
    bit = []
    for _ in range(n-1):
        bit.append(i%2)
        i =  i // 2
    eq = ""
    for i, b in enumerate(bit):
        eq += (form[i])
        if b == 1:
            eq += ('+')
    eq += form[-1]

    ans += eval(eq)

print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
 
int main(){
  int a,b;
  cin >> a >> b;
 
  int ans = 0;
  
  if(a>12) ans = b;
  else if(a>5) ans = b/2;
  else ans = 0;
  cout << ans << endl;
 
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e8 ;
int main()
{
    ll n,i;
    cin>>n;
    vector< ll > jump(n);
    vector< ll > dp(n);
    for(i=0;i<n;i++){
        cin>>jump[i];
    }
    dp[0]=0;
    dp[1]=fabs(jump[1]-jump[0]);
    for(i=2;i<n;i++){
        dp[i]= min( dp[i-1]+fabs(jump[i]-jump[i-1]),dp[i-2]+fabs(jump[i]-jump[i-2]));
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 4828
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<i32>();

    println!("{}", 800*N - (N/15)*200);
}


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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }






int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    REP(i, N) cin >> d[i];

    ll sum = 0;
    REP(i, N){
        for(int j = i + 1; N > j ; j++){
            sum += d[i] * d[j];
        }
    }
    print(sum);
}



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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (size_t i = 0; i < n; i++)
		cin >> a[i];
	for (size_t i = 0; i < n; i++)
		cin >> b[i];
	int res = 0;
	for (int i = 28; i >= 0; i--)
	{
		int dig = 0;
		int zeroCountA = 0;
		int zeroCountB = 0;
		for (size_t j = 0; j < n; j++)
		{
			if ((a[j] >> i & 1) == 0) zeroCountA++;
			if ((b[j] >> i & 1) == 0) zeroCountB++;
			a[j] &= ((1 << i) - 1);
			b[j] &= ((1 << i) - 1);
		}
		int oneCountA = n - zeroCountA;
		int oneCountB = n - zeroCountB;
		dig ^= (oneCountA & 1) * (zeroCountB & 1) ^ (zeroCountA & 1) * (oneCountB & 1);
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		size_t bInd = 0;
		for (int aInd = n - 1; aInd >= 0; aInd--)
		{
			while (bInd < n && a[aInd] + b[bInd] < (1 << i))
				bInd++;
			dig ^= n - bInd;
		}
		res ^= (dig & 1) << i;
	}
	cout << res << endl;
}


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

using lint = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a, b, k;
	cin >> a >> b >> k;
	int g = __gcd(a,b), q = 0;
	for (int i = g; i >= 1; --i) {
		if (g % i == 0) {
			q++;
			if (q == k) {
				cout << i << '\n';
				exit(0);
			}
		}
	}
}



Measured memory_bytes: 256
#!/usr/bin/env python3
from heapq import *

a = [*range(1, 10)]
heapify(a)
i = 0
k = int(input())
c = 0
while True:
    t = str(heappop(a))
    i += 1
    if i == k:
        break
    if t[-1] != "0":
        heappush(a, int(t + str(int(t[-1]) - 1)))
    heappush(a, int(t + t[-1]))
    if t[-1] != "9":
        heappush(a, int(t + str(int(t[-1]) + 1)))
print(t)


Measured memory_bytes: 16392
N=input()
if N[-1]== "2" or N[-1]=="4" or N[-1]=="5" or N[-1]=="7" or N[-1]=="9":
    print("hon")
if N[-1]== N[-1]=="0" or N[-1]=="1" or N[-1]=="6" or N[-1]=="8":
    print("pon")
if N[-1]== "3":
    print("bon")

Measured memory_bytes: 9132
a,b=map(int,input().split())
tower_list=[]
tower_length=1
tower_list.append(tower_length)
for i in range(1,999):
    tower_length+=(i+1)
    tower_list.append(tower_length)

for idx in range(1,len(tower_list)-1):
    if tower_list[idx]>a and tower_list[idx+1]>b:
        x_west=tower_list[idx]-a
        x_east=tower_list[idx+1]-b
        if x_east==x_west:
            print(x_east)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    struct rectangle{
        int h,w;
    };

    struct rectangle rect[300];
    int n=0;
    int i,j,k;

    while(1){
        int a,b;
        scanf("%d %d",&a,&b);

        if(a==0&&b==0) break;
        
        rect[n].h=a;
        rect[n].w=b;

        n++;
    }

    for(i=0;i<n;i++){

        for(j=0;j<rect[i].h;j++){
            for(k=0;k<rect[i].w;k++){
                if(j==0||j==rect[i].h-1||
                        k==0||k==rect[i].w-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }

        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 572
package main

import "fmt"

func main() {
	var X int
	fmt.Scan(&X)
	expo := map[int]bool{}
	expo[1] = true
	for b := 2; b < X; b++ {
		v := b * b
		for v <= X {
			expo[v] = true
			v *= b
		}
	}
	for i := X; i > 0; i-- {
		if expo[i] {
			fmt.Println(i)
			return
		}
	}
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,b) for(int i=0;i<b;i++)
#define rrep(i,a,b) for(int i=a;i<=b;i++)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;

bool isPrime(int n) {
	if (n == 1)return false;

	for (int i = 2; i < n; i++) {
		if (n%i == 0)return false;
	}

	return true;
}

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

	int cnt = 0;
	for (int i = 6; i <= 55555; i += 5) {


		if (isPrime(i)) {
			cout << i << " ";
			cnt++;
		}

		if (cnt == n) {
			cout << endl;
			return 0;
		}
	}

	
}

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

int w, h;
int s[32][32];
int cost[4];

// dir
// 0 : right
// 1 : up
// 2 : left
// 3 : down
const int dr[4] = {0, -1, 0, 1};
const int dc[4] = {1, 0, -1, 0};
const int dd[4] = {0, 3, 2, 1};

typedef std::pair<int, int> Pii;

class Node {
public:
  Node() {}
  Node(int r_, int c_, int dir_) : r(r_), c(c_), dir(dir_) {}
  int r, c, dir;
};

class Data {
public:
  Data() {}
  Data(Node s_, Node t_, int cost_) : s(s_), t(t_), cost(cost_) {}
  Node s, t;
  int cost;
};

inline bool operator < (const Data& a, const Data& b) {
  return a.cost > b.cost;
}

int dist[32][32][8];
int dijkstra() {
  std::priority_queue<Data> q;
  int r = 0;
  int c = 0;
  int dir = 0;
  dist[r][c][dir] = 0;
  for(int k = 0; k < 4; ++k) {
    int nd = (dir + dd[k]) % 4;
    int nr = r + dr[nd];
    int nc = c + dc[nd];
    if( not ( 0 <= nr and nr < h and 0 <= nc and nc < w ) ) continue;
    q.push(Data(Node(r, c, dir), Node(nr, nc, nd), dist[r][c][dir] + (k == s[r][c] ? 0 : cost[k])));
  }
  while( not q.empty() ) {
    Data t = q.top(); q.pop();
    int r = t.t.r, c = t.t.c, dir = t.t.dir;
    if( dist[r][c][dir] <= t.cost ) continue;
    dist[r][c][dir] = t.cost;
    if( r == h - 1 and c == w - 1 ) continue;
    for(int k = 0; k < 4; ++k) {
      int nd = (dir + dd[k]) % 4;
      int nr = r + dr[nd];
      int nc = c + dc[nd];
      if( not ( 0 <= nr and nr < h and 0 <= nc and nc < w ) ) continue;
      int ncost = dist[r][c][dir] + (k == s[r][c] ? 0 : cost[k]);
      if( ncost >= dist[nr][nc][nd] ) continue;
      q.push(Data(Node(r, c, dir), Node(nr, nc, nd), ncost));
    }
  }
  int res = (1 << 30);
  for(int i = 0; i < 4; ++i) {
    res = std::min(res, dist[h-1][w-1][i]);
  }
  return res;
}

void Init() {
  for(int i = 0; i < 32; ++i) {
    for(int j = 0; j < 32; ++j) {
      for(int k = 0; k < 4; ++k) {
        dist[i][j][k] = (1 << 29);
      }
    }
  }
}

int main() {
  for(;;) {
    Init();
    scanf("%d %d", &w, &h);
    if( w == 0 and h == 0 ) break;
    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
        scanf("%d", &s[i][j]);
      }
    }
    for(int i = 0; i < 4; ++i) {
      scanf("%d", &cost[i]);
    }
    int res = dijkstra();
    printf("%d\n", res);
  }
  
  return 0;
}

Measured memory_bytes: 3304
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; string s; cin >> n >> s;
  map<char, int> mp;
  mp['R'] = 0; mp['G'] = 1; mp['B'] = 2;
  long long ans = 1;
  vector<int> ball(3, 0);
  REP(i, 3 * n) {
    int c = mp[s[i]], mn = INF;
    REP(j, 3) if (j != c) {
      mn = min(mn, ball[j]);
    }
    if (mn > 0) {
      (ans *= mn) %= MOD;
      REP(j, 3) if (j != c) --ball[j];
    } else {
      bool used = false;
      int idx = -1;
      REP(j, 3) if (j != c) {
        if (ball[j] > 0) {
          idx = j;
          break;
        }
      }
      if (idx != -1 && ball[idx] > ball[c]) {
        (ans *= ball[idx] - ball[c]) %= MOD;
      }
      ++ball[c];
    }
    // cout << ball[0] << ' ' << ball[1] << ' ' << ball[2] << '\n';
  }
  FOR(i, 1, n + 1) (ans *= i) %= MOD;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll base = 0, ld = 0, rd = 0, wo, w, x;
    cin >> wo >> x;
    wo = x - wo;
    multiset<ll> ls{x}, rs{x};
    for (int i = 0; i < n - 1; ++i) {
        cin >> w >> x;
        w = x - w;
        ld -= wo;
        rd += w;
        wo = w;
        ll bl = *prev(end(ls)) + ld, br = *begin(rs) + rd;
        if (bl <= x && x <= br) {
            ls.insert(x - ld);
            rs.insert(x - rd);
        } else if (x < bl) {
            base += bl - x;
            ls.insert(x - ld);
            ls.insert(x - ld);
            ls.erase(prev(end(ls)));
            rs.insert(bl - rd);
        } else {
            base += x - br;
            rs.insert(x - rd);
            rs.insert(x - rd);
            rs.erase(begin(rs));
            ls.insert(br - ld);
        }
    }
    cout << base << '\n';
}


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

int main() {
	int a, b;
	char op;

	while (1) {
		cin >> a >> op >> b;
		if (op == '?') break;

		if (op == '+') cout << a + b << endl;
		else if (op == '-') cout << a - b << endl;
		else if (op == '*') cout << a * b << endl;
		else if (op == '/') cout << a / b << endl;
	}
	return 0;
}


Measured memory_bytes: 3080
import java.util.*;

class Main{
    static int mod = 1000000000+7;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        while(a>0 || c>0){
            c = c-b;
            if(c<=0){
                System.out.println("Yes");
                break;
            }
            a = a-d;
            if(a<=0){
                System.out.println("No");
                break;
            }
        }
        
    }
}


Measured memory_bytes: 27044