akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define maxn 200005
ll v[maxn];
int main(){
    ll n,i;
    cin>>n;
    for(i=0;i<n;i++) cin>>v[i];
    ll res=0;
    for(i=0;i<n-1;i++){
        if(v[i+1]<v[i]) {
            res+=(v[i]-v[i+1]);
            v[i+1]=v[i];
        }
    }
    cout<<res;
}

Measured memory_bytes: 5176
#include <iostream>

int value (int pm, int pe, int pj);
int main()
{
    int N;
    std::cin >> N;
    while (N > 0) {
        for (int i = 0; i < N; i++) {
            int pm, pe, pj;	       
            std::cin >> pm >> pe >> pj;
            if (value (pm, pe, pj) == 1) {
                std::cout << "A" <<std::endl;
                } else if (value (pm, pe, pj) == 2) {
                std::cout << "B" <<std::endl;
                } else {
                std::cout << "C" <<std::endl;
                }
        }
    std::cin >> N;
    }
    return 0;
}

int value(int pm, int pe, int pj)
{
    if (pm == 100 || pe == 100 || pj == 100) {
    return 1;
    } else if (pm + pe >= 180) {
    return 1;
    } else if (pm + pe + pj >= 240) {
    return 1;
    } else if (pm + pe + pj >= 210) {
    return 2; 
    } else if (pm + pe + pj >= 150 && (pm >= 80 || pe >=80) ) {
    return 2;
    }else {
    return 3;
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

  int a, b;
  cin >> a >> b;
  cout << max(0, a - b * 2) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict

sys.setrecursionlimit(10**7)
A = int(input())
B = int(input())

l = [1, 2, 3]
l.remove(A)
l.remove(B)
print(l[0])




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

void conv(string &s) {
  map<char, char> M;
  char C = 'a';
  for (char &c : s) M.count(c) ? c = M[c] : c = M[c] = C++;
}

int main() {
  ios::sync_with_stdio(false);

  string S, T;
  cin >> S >> T;

  conv(S);
  conv(T);

  cout << ((S == T) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 916
def merge_jibun(A, left, mid, right):
    global count
    inf = 10 ** 9
    L = A[left:mid] + [inf]
    R = A[mid:right] + [inf]
    # L.append(1000000)
    # R.append(1000000)

    i = 0
    j = 0
    
    
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def merge_hoka(A, left, mid, right):
    global count
    inf = 10 ** 9
    L = A[left:mid] + [inf]
    R = A[mid:right] + [inf]
 
    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        # print(L)
        # print(R)
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge_jibun(A, left, mid, right)
        # merge_hoka(A, left, mid, right)

n = int(input())
A = list(map(int, input().split()))
count = 0
mergeSort(A, 0, n)

print(' '.join(list(map(str, A))))
print(count)


Measured memory_bytes: 66776
#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++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  int k;
  cin >> k >> s;
  if(s.size()<=k) pr(s);
  else pr(s.substr(0,k)+"...");
}

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


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

int main() {
    vector<int>A(9);
    for (int i = 0; i < 9; ++i) {
        cin >> A[i];
    }
    int N;
    cin >> N;
    vector<int>B(N);
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    vector<int>m(9, 0);
    for (int i = 0; i < 9; ++i) {
        for (int j = 0; j < N; ++j) {
            if (A[i] == B[j]) m[i] = 1;
        }
    }
    int ans = 0;
    if (m[0] & m[1] & m[2]) ans = 1;
    if (m[3] & m[4] & m[5]) ans = 1;
    if (m[6] & m[7] & m[8]) ans = 1;
    if (m[0] & m[3] & m[6]) ans = 1;
    if (m[1] & m[4] & m[7]) ans = 1;
    if (m[2] & m[5] & m[8]) ans = 1;
    if (m[0] & m[4] & m[8]) ans = 1;
    if (m[2] & m[4] & m[6]) ans = 1;

    if (ans) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define lld long long double
#define pb push_back
#define mp make_pair
#define M 1000000007
using namespace std;

const int N = 100005;
vector<int>graph[N];
int dp[N];

int f(int src) {
	if (dp[src] != -1) return dp[src];
	if (graph[src].size() == 0) return 0;
	int ans = 0;
	for (auto nbr : graph[src]) {
		ans = max(ans, f(nbr));
	}
	return dp[src] = 1 + ans;
}


void solve() {
	int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
	cin >> n >> m;
	memset(dp, -1, sizeof(dp));
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		graph[x].pb(y);
	}
	ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, f(i));
	}
	cout << ans << "\n";
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	//int t; cin >> t; while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 11880
from bisect import bisect_left


def main():
    N = int(input())
    A = list(map(int, input().split()))
    adj = [set() for _ in range(N)]
    for i in range(N-1):
        u, v = map(int, input().split())
        adj[u-1].add(v-1)
        adj[v-1].add(u-1)
    ans = [0] * N
    q = [(0, -1, [], 0)]
    history = []
    while len(q):
        cur, prev, lis, depth = q.pop()
        while depth < len(history):
            pos, val = history.pop()
            if val is None:
                lis.pop()
            else:
                lis[pos] = val
        idx = bisect_left(lis, A[cur])
        if idx == len(lis):
            history.append((idx, None))
            lis.append(A[cur])
        else:
            history.append((idx, lis[idx]))
            lis[idx] = A[cur]
        ans[cur] = len(lis)
        for nxt in adj[cur]:
            if nxt == prev:
                continue
            q.append((nxt, cur, lis, depth+1))
    for i in range(N):
        print(ans[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 185944
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<climits>
using namespace std;

const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const string dir = "URDL";

string solve(long long x, long long y, const vector<long long>& arm)
{
	string ret;
	int id;
	long long d, dd, xx, yy;
	for(auto it=arm.rbegin(); it!=arm.rend(); it++){
		d = LLONG_MAX;
		for(int i=0; i<4; i++){
			xx = x + dx[i] * *it;
			yy = y + dy[i] * *it;
			dd = abs(xx) + abs(yy);

			if(dd < d){
				id = i;
				d = dd;
			}
		}

		ret += dir[(id+2)%4];
		x += dx[id] * *it;
		y += dy[id] * *it;
	}

	reverse(ret.begin(), ret.end());

	return ret;
}

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

	vector<long long> x(n), y(n);
	for(int i=0; i<n; i++)
		cin >> x[i] >> y[i];

	bool b = (abs(x[0]) + abs(y[0])) % 2;
	for(int i=0; i<n; i++){
		if((abs(x[i]) + abs(y[i]))%2 != b){
			cout << -1 << endl;
			return 0;
		}
	}

	long long md = 0;
	for(int i=0; i<n; i++)
		md = max(md, abs(x[i])+abs(y[i]));

	vector<long long> arm;
	if(b == 0)
		arm.push_back(1);
	for(long long i=1, sum=(b==0 ? 1 : 0); sum<md; i*=2){
		arm.push_back(i);
		sum += i;
	}

	cout << arm.size() << endl;
	for(int i=0; i<arm.size(); i++)
		cout << arm[i] << (i+1==arm.size() ? '\n' : ' ');

	for(int i=0; i<n; i++)
		cout << solve(x[i], y[i], arm) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int mp[2][20010];

int solve(int goal){
  int x=0,f=1,cost=0,y=0;
  while(x!=goal+1) {
    if(f&&mp[0][x])f=0,cost++,y=mp[0][x]=0;
    else if(f&&mp[1][x])cost++,f=y=0;
    else if(mp[1][x]) cost++,y=1,mp[1][x]=0;
    else if(mp[0][x]) cost++,y=mp[0][x]=0;
    else cost++,x++;
  }
  if(y==1)cost++;
  return cost-1;
}

int main(){
  int q;
  cin>> q;
  while(q--){
    int n,pos,cnt;
    cin>>n;
    memset(mp,0,sizeof(mp));

    for(int i=0;i<2;i++){
      pos=0,cnt=1;
      char a;
      for(int j=0;j<2*n;j++){
	cin>> a;
	if(a=='Y') a=1;
	else a=0;
	mp[i][pos] |= a;
	cnt++;
	if(cnt==2)pos++,cnt=0;
      }
    }
    cout<<solve(pos)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1324
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

bool isPowerOfTwo(ll x) {
#if LOCAL&0
    cout<<"a*"<<(x & (x - 1))<<endl;
#endif
    ll tmp = sqrt(x);
    return (tmp*tmp==x);
    //return ((x & (x - 1)) == 0);
}

int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N,D; cin>>N>>D;
    //vector<vector<ll>> abc(3,vector<ll>(N));
    vector<vector<ll>> xd(N);
    for(auto&& t:xd){
        for(ll i=0;i<D;++i){
            ll x; cin>>x;
            t.push_back(x);
        }
    }

    auto calc_dist = [&](ll i, ll j){
        ll ret=0;
        for(ll p=0;p<xd[i].size();++p){
            ll tmp=xd[i][p]-xd[j][p];
            ret += (tmp*tmp);
        }
#if LOCAL&0
        cout<<ret<<endl;
#endif
        return isPowerOfTwo(ret);
    };

    ll ans=0;
    for(ll i=0;i<N;++i){
        for(ll j=0;j<N;++j){
            if(i<j){
                if(calc_dist(i,j)) ++ans;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

string s;
int main(){
    cin >> s;
    lli i = 0;
    while(i < 5) cout << s[i++];
    i++;
    cout << " ";
    while(i < 13) cout << s[i++];
    i++;
    cout << " ";
    while(i < 19) cout << s[i++];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d%d", $n, $a, $b);
const MOD = 1000000007;


$sum = pow_mod(2,$n,MOD);
$sum = $sum - Combination($n, $a);
$sum = $sum - Combination($n, $b);
$sum = $sum -1;
while($sum < 0){
    $sum += MOD;
}
echo $sum;


function Combination($n, $a){
    $ans = 1;
    $now = $n;
    for($i = 1; $i<=$a;$i++){
        $ans = $ans * $now % MOD;
        $ans = $ans * pow_mod($i, MOD-2, MOD) % MOD;
        $now--;
    }
    return $ans;
}


function pow_mod($x, $n, $mod){
    $ans = 1;
    $bin = decbin($n);
    $pos = strlen($bin);
    while ($pos > 0) {
        if ($bin[$pos - 1] == 1) {
            $ans = ($ans * $x) % $mod;
        }
        $x = ($x * $x) % $mod;
        $pos--;
    }
    return $ans;
}


Measured memory_bytes: 4728
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
ma = 80*80+2
DP = [[[0]*ma for i in range(w)] for i in range(h)]

for i in range(h):
    for j in range(w):
        k = abs(a[i][j]-b[i][j])
        if i==0 and j==0:
            DP[i][j][k] = 1
            continue
        else:
            up = min((i+j+1)*80+1, ma-k)
            for l in range(up):
                DP[i][j][l] = DP[i][j-1][abs(l-k)] | DP[i][j-1][l+k] | DP[i-1][j][abs(l-k)] | DP[i-1][j][l+k]
for i in range(ma):
    if DP[-1][-1][i]:
        print(i)
        exit()

Measured memory_bytes: 357256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    int n;
    cin>>n;
    vector<pair<ll,int>> x(n),y(n);

    rep(i,n){
        int a,b;
        cin>>a>>b;
        x[i]={a,i};
        y[i]={b,i};
    }

    sort(all(x));
    sort(all(y));

    // Kruskal法
    // O(ElogE)
    // Kruskal 法で使用する枝
    using pint = pair<int,int>;
    using Edge = pair<ll, pint>;
    vector<Edge> edges;
    //枝入力
    rep(i,n-1) {
        edges.push_back({x[i+1].first-x[i].first, pint(x[i+1].second, x[i].second)});
        edges.push_back({y[i+1].first-y[i].first, pint(y[i+1].second, y[i].second)});
    }
    // Kruskal 法
    sort(all(edges));
    // unionfindのスニペット読み込んで
    UnionFind uf(n);
    ll res = 0;
    for (auto e : edges) {
        int u = e.second.first, v = e.second.second;
        ll cost = e.first;
        if (uf.issame(u, v)) continue;
        uf.merge(u, v);
        res += cost;
    }
    cout << res << endl;
}


 

Measured memory_bytes: 9456
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

using namespace std;

string S, T;

int main() {

    cin >> S >> T;

    cout << T + S << endl;

    return 0;

}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  string foo = s.substr(0, 3);
  string bar = s.substr(1, 3);
  bool ok = equal(foo.begin() + 1, foo.end(), foo.begin()) || equal(bar.begin() + 1, bar.end(), bar.begin());
  cout << (ok ? "Yes" : "No") << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;
 
const int N=1e5+5;
int n,m,ans=123456789;
map<int,vector<int> > E[N];
map<int,int> d[N];
vector<int> G[N];
 
struct three{
	int First;
	int Second;
	int Third;
};
 
three make_three(int x,int y,int z){
	three re;
	re.First=x;
	re.Second=y;
	re.Third=z;
	return re;
}
 
queue<three> q;
 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		x--;y--;
		E[x][z].push_back(y);
		E[y][z].push_back(x);
		G[x].push_back(z);
		G[y].push_back(z);
	}
	q.push(make_three(0,0,0));
	d[0][0]=0;
	while(!q.empty()){
		three now=q.front();
		int f=now.First,s=now.Second,t=now.Third;
//		printf("%d %d %d\n",f,s,t);
		q.pop();
		if(d[f][s]!=t) continue;
		if(d[f].find(0)==d[f].end()||d[f][0]>t){
			d[f][0]=t;
			q.push(make_three(f,0,t));
		}
		if(s==0) for(int i=0;i<G[f].size();i++){
			int color=G[f][i];
			if(d[f].find(color)==d[f].end()||d[f][color]>t+1){
				d[f][color]=t+1;
				q.push(make_three(f,color,t+1));
			}
		}else for(int i=0;i<E[f][s].size();i++){
			int to=E[f][s][i];
			if(d[to].find(s)==d[to].end()||d[to][s]>t){
				d[to][s]=t;
				q.push(make_three(to,s,t));
			}
		}
	}
	for(map<int,int>::iterator it=d[n-1].begin();it!=d[n-1].end();it++) ans=min(ans,(*it).second);
	if(ans!=123456789) printf("%d\n",ans);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 83200
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>

using namespace std;

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

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

const int64_t N_MAX = 1e5 + 5;
const int64_t MOD = 1e9 + 7;
int64_t fac[N_MAX] = {1, 1};
int64_t inv[N_MAX] = {1, 1};
int64_t finv[N_MAX] = {1, 1};

// combinationを計算
int64_t comb(int n, int r)
{
  if (n < r) return 0;
  return fac[n] * finv[n - r] % MOD * finv[r] % MOD;
}

// combinationを求めるためのテーブル初期化
void comb_init()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < N_MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

int main()
{
  int N;

  cin >> N;

  cout << (N + 1) / 2;

  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	scanner := makeWordScanner()
	a := eGetInt(scanner)
	b := eGetInt(scanner)
	if a%2 != b%2 {
		fmt.Println("IMPOSSIBLE")
	} else {
		fmt.Println((a + b) / 2)
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
#include <stdio.h>

/* 年月日を日に変換する */
int toDay(int y, int m, int d){
	d += (20 * 10) * (y - 1);
	d += 20 * (m - 1);

	/* 3 で割り切れない年 */
	d -= ((y - 1) - (y - 1) / 3) * 5;  /* 前年まで */

	if (y % 3 != 0){
		/* 小の月 (2 で割り切れる月) */
		d -= (m - 1) / 2;
	}

	return d;
}

int main(void){
	int n, y, m, d, i;
	int today = toDay(1000, 1, 1);

	scanf("%d", &n);

	for (i = 0; i < n; i++){
		scanf("%d %d %d", &y, &m, &d);
		printf("%d\n", today - toDay(y, m, d));
	}

    return 0;
}

Measured memory_bytes: 596
import sys
input = sys.stdin.readline
import heapq
def main():
    N = int(input())
    a = [int(x) for x in input().split()]
    left = [0]*(N+1)
    left_a = a[:N]
    left[0] = sum(left_a)

    heapq.heapify(left_a)
    for i in range(1,N+1):
        now = heapq.heappop(left_a)

        if now<a[N-1+i]:
            heapq.heappush(left_a,a[N-1+i])
            left[i] = left[i-1]+a[N-1+i]-now
        else:
            heapq.heappush(left_a,now)
            left[i] = left[i-1]
    
    right = [0]*(N+1)
    right_a = [-int(x) for x in a[2*N:]]
    right[-1] = -sum(right_a)
    
    heapq.heapify(right_a)
    for i in range(N):
        now = -1 * heapq.heappop(right_a)
        if now>a[2*N-1-i]:
            heapq.heappush(right_a,-a[2*N-1-i])
            right[N-i-1] = right[N-i]-now+a[2*N-1-i]
        else:
            heapq.heappush(right_a,-now)
            right[N-i-1] = right[N-i]

    ans = -1 * float("inf")
    for i in range(len(left)):
        ans = max(ans,left[i]-right[i])
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 119184
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  string s;
  cin >> s;
  rep(i, s.size()) {
    // cout << (((int)s[i] + n) % 26) << endl;;
    // cout << (s[i]-'A') << endl;;
    cout << (char)('A' + (((s[i]-'A') + n) % 26));
  }
  cout << endl;
}


Measured memory_bytes: 256
//
// Created by tac on 2016/10/13.
//

#include <cstdlib>
#include <string>
#include <iostream>

std::string get_performace(int a, int b, int c) {
    std::string res;
    if (a < 0 || b < 0) {
        res = "F";
    } else if (a + b >= 80) {
        res = "A";
    } else if (a + b >= 65) {
        res = "B";
    } else if (a + b >= 50) {
        res = "C";
    } else if (a + b >= 30) {
        if (c >= 50) {
            res = "C";
        } else {
            res = "D";
        }
    } else {
        res = "F";
    }
    return res;
}

int main() {
    int a, b, c;

    while (true) {
        std::cin >> a >> b >> c;
        if (a < 0 && b < 0 && c < 0) {
            break;
        }
        std::cout << get_performace(a, b, c) << std::endl;
    }

    return EXIT_SUCCESS;
}

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n, r;
  cin >> n >> r;
  if (n < 10) {
    r += 100 * (10 - n);
  }
  cout << r << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    while (H != 0 && W != 0){
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
    return 0;
} 


Measured memory_bytes: 3108
fun main(args: Array<String>) {
    val s = readLine()!!.toCharArray()
    val s2 = s + s
    val k = readLine()!!.toLong()
    if (s.toSet().size == 1) {
        println(s.size * k / 2)
        return
    }
    val c1 = (0 until s.size - 1).map {
        if (s[it] == s[it + 1]) run { s[it + 1] = '*' }.let { 1 } else 0
    }.sum()

    val c2 = (0 until s2.size - 1).map {
        if (s2[it] == s2[it + 1]) run { s2[it + 1] = '*' }.let { 1 } else 0
    }.sum()
    println(c1 + (c2 - c1) * (k - 1))
}


Measured memory_bytes: 37948
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

long INF = 1000000;

int main() {

    int h, w;
    while(cin >> h >> w && (h || w)) {
        queue<int> x;
        queue<int> y;
        char town[h][w];
        long time[h][w];
        int gx, gy;
        string str;
        getline(cin, str);
        for(int i = 0; i < h; i++) {
            getline(cin, str);
            for(int j = 0; j < w; j++) {
                time[i][j] = INF;
                town[i][j] = str[j];
                if(str[j] == 'A') {
                    x.push(i);
                    y.push(j);
                    town[i][j] = '.';
                    time[i][j] = 0;
                }
                if(str[j] == 'B') {
                    gx = i;
                    gy = j;
                    town[i][j] = '.';
                }
            }
        }

        while(!x.empty()) {
            int i = x.front();
            int j = y.front();
            x.pop();
            y.pop();
            if ( i > 0 && town[i-1][j] != '#' && time[i-1][j] == INF ) {
                time[i-1][j] = time[i][j] + 1;
                x.push(i-1);
                y.push(j);
            }
            if ( j > 0 && town[i][j-1] != '#' && time[i][j-1] == INF ) {
                time[i][j-1] = time[i][j] + 1;
                x.push(i);
                y.push(j-1);
            }
            if ( i < h - 1 && town[i+1][j] != '#' && time[i+1][j] == INF ) {
                time[i+1][j] = time[i][j] + 1;
                x.push(i+1);
                y.push(j);
            }
            if ( j < w - 1 && town[i][j+1] != '#' && time[i][j+1] == INF ) {
                time[i][j+1] = time[i][j] + 1;
                x.push(i);
                y.push(j+1);
            }
        }

        getline(cin, str);

        long t = 1;
        int lenpat = str.length();
        while(t < lenpat * 1000) {
            switch(str[(t - 1) % lenpat]) {
                case '2':
                    if (gx < h - 1) gx += 1;
                    break;
                case '4':
                    if (gy > 0) gy -= 1;
                    break;
                case '6':
                    if (gy < w - 1) gy += 1;
                    break;
                case '8':
                    if (gx > 0) gx -= 1;
                    break;
            }
            if (time[gx][gy] <= t) {
                cout << t << " " << gx << " " << gy << endl; 
                break;
            }
            t += 1;
        }
        if (t == lenpat * 1000) {
            cout << "impossible" << endl;
        }

    }
     
    return 0;
}

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

using namespace std;

int max3(int a, int b, int c){
    int d = (b > c ? b : c);
    return a > d ? a : d; 
}

int main()
{
    int A, B;
    cin >> A >> B;
    cout << max3(A+B, A-B, A*B) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

template <int M> class ModInt {
    int x;

  public:
    constexpr ModInt() : x(0) {}
    constexpr ModInt(int64_t y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}
    constexpr ModInt &operator+=(const ModInt p) {
        if((x += p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt p) {
        if((x += M - p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt p) {
        x = (int)(1LL * x * p.x % M);
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt p) {
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-() const { return ModInt(-x); }
    constexpr ModInt operator+(const ModInt p) const {
        return ModInt(*this) += p;
    }
    constexpr ModInt operator-(const ModInt p) const {
        return ModInt(*this) -= p;
    }
    constexpr ModInt operator*(const ModInt p) const {
        return ModInt(*this) *= p;
    }
    constexpr ModInt operator/(const ModInt p) const {
        return ModInt(*this) /= p;
    }
    constexpr bool operator==(const ModInt p) const { return x == p.x; }
    constexpr bool operator!=(const ModInt p) const { return x != p.x; }
    constexpr ModInt inverse() const {
        int a = x, b = M, u = 1, v = 0, t = 0;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(int64_t k) const {
        ModInt ret(1), mul(x);
        while(k > 0) {
            if(k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }
    constexpr friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    constexpr friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t = 0;
        is >> t;
        a = ModInt(t);
        return (is);
    }
};
using mint = ModInt<mod>;

mint dp[45][1 << 17];

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

    int n, x, y, z;
    cin >> n >> x >> y >> z;
    int m = 1 << (x + y + z);
    int ng = 1 << (z - 1) | 1 << (y + z - 1) | 1 << (x + y + z - 1);

    dp[0][0] = 1;

    rep(i, n) rep(j, m) if(dp[i][j] != 0) FOR(k, 1, 11) {
        int nxt = (j << k | 1 << (k - 1)) & (m - 1);
        if((nxt & ng) != ng) dp[i + 1][nxt] += dp[i][j];
    }

    mint sum;
    rep(j, m) sum += dp[n][j];

    cout << mint(10).pow(n) - sum << endl;

    return 0;
}

Measured memory_bytes: 22364
import qualified Data.ByteString.Char8 as BC

main = do
  input <- BC.unpack <$> BC.getLine
  let r = reverse input
      a = solve input 'A' 0
      z = solve r 'Z' 0
  print $ (length input) - a - z

solve :: String -> Char -> Int -> Int
solve (a:as) c i
  | a == c = i
  | otherwise = solve as c $ i + 1


Measured memory_bytes: 12668
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=55;

int n, a;
int x[N];
int cache[N][2*N*N];

int dp(int idx, int sum)
{
	if(idx==n+1)
		return (sum==0);
	int &ans=cache[idx][sum+N*N];
	if(ans!=-1)
		return ans;
	ans=dp(idx+1, sum) + dp(idx+1, sum+x[idx]);
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin>>n>>a;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
		x[i]-=a;
	}
	int ans=dp(1, 0)-1;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    string a,b;
    cin >> a >> b;
    string ans;
    if(a=="H"){
        if(b=="H"){
            ans = "H";
        }else{
            ans = "D";
        }
    }else{
        if(b=="H"){
            ans = "D";
        }else{
            ans ="H";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

namespace OJcsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int N;
            N = int.Parse(Console.ReadLine());
            long ans = 1;
            for (int n = 2; n <= N; n++)
            {
                ans *= n;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  rep(i, 0, 5) {
    int a;
    cin >> a;
    if (a == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3632
#include <vector>
#include <cstdio>
class union_find{
	std::vector<int> parent;
public:
	int root(int a){return parent[a]==a?a:(parent[a]=root(parent[a]));}
	union_find(int n):parent(n+1){for(int i=1;i<=n;i++)parent[i]=i;}
	int same(int a,int b){return root(a)==root(b);}
	int unite(int a,int b){
		int x=root(a),y=root(b);//if(x==y)return 0;
		parent[x]=y;
		return 1;
	}
};
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	union_find uf(n);
	int a,b;
	for(;m--;uf.unite(a,b))scanf("%d%d",&a,&b);
	for(scanf("%d",&m);m--;puts(uf.same(a,b)?"yes":"no"))scanf("%d%d",&a,&b);
}

Measured memory_bytes: 1532
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    ll N,K,X,Y;
    cin >> N >> K >> X >> Y;
    if(N > K){
        fin(K*X+Y*(N-K));
    }else{
        fin(N*X);
    }
    return 0;
}

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

int main(void) {
    string S;cin>>S;
    sort(S.begin(), S.end());
    if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    int s[h][w];
    rep(i,h){
        rep(j,w){
            s[i][j] = 0;
        }
    }

    if(a==0 && b!=0){
        rep(i,b){
            rep(j,w){
                s[i][j] = 1;
            }
        }
    }
    else if(b==0 && a!=0){
        rep(i,h){
            rep(j,a){
                s[i][j] = 1;
            }
        }
    }
    else if(a!=0 && b!= 0){
        rep(i,b){
            rep(j,a){
                s[i][j] = 1;
            }
        }
        repd(i,b,h){
            repd(j,a,w){
                s[i][j] = 1;
            }
        }
    }
   
    rep(i,h){
        rep(j,w-1){
            cout << s[i][j];
        }
        cout << s[i][w-1] << endl;
    }
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[]A = new int[N];
		for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		}
		
		int count = 0;
		int now = 1;
		for(;count<N && now!=2;count++,now = A[now-1]) {
		}
		if(count == N)count = -1;
		
		System.out.println(count);	
	}
}

Measured memory_bytes: 41384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    ll N , ans = 0;
    cin >> N;
    vector <ll> a(3 * N);
    for(int i = 0; i < 3 * N; i++){
        cin >> a[i];
    }
    sort(a.begin() , a.end());
    for(int i = N; i <= 3 * N - 2; i+=2){
        ans+=a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 5640
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (56)
ll n, sum, ans;
ll A[MAXN];
void reduce(ll x) { if(x<=0) return;
	ans += x;
	FOR(i,1,n) A[i] += x;
	ll st=-1, en=*max_element(A+1,A+n+1), mid=0;
	while(en-st>1) {
		mid=(st+en)>>1;
		ll T = 0;
		FOR(i,1,n) T += max((A[i]-mid)/(n+1), 0ll);
		if(T <= x) en=mid;
		else st=mid;
	}
	ll T=0; FOR(i,1,n) T += max((A[i]-en)/(n+1), 0ll);
	FOR(i,1,n) A[i] -= max((A[i]-en)/(n+1), 0ll) * (n+1);
	x -= T; assert(x>=0);
	while(x) {
		A[max_element(A+1,A+n+1)-A] -= (n+1);
		-- x;
	}
	return;
}
int main()
{
	FAST
	cin>>n;
	FOR(i,1,n)cin>>A[i];
	sum = accumulate(A+1, A+n+1, 0ll);
	reduce(sum-n*(n-1));
	ll ofs=0;
	while(*max_element(A+1,A+n+1) + ofs >= n) {
		A[max_element(A+1,A+n+1)-A] -= (n+1);
		++ ofs;
		++ ans;
	}
	cout<<ans<<'\n';
}


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 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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
 
int main() {
    int n;
    cin >> n;
    int d;
    cin >> d;
    out((n + (2 * d + 1 - 1)) / (2 * d + 1));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
  int i, j;
  int H, W;

  char temp[105];

  scanf("%d %d ", &H, &W);

  for (i = 0; i < W+2;i++){
    printf("#");
  }
  printf("\n");

  for (i = 0; i < H;i++){
    scanf("%[^\n]%*c", temp);
    printf("#");
    printf("%s", temp);
    printf("#\n");
  }

  for (i = 0; i < W+2;i++){
    printf("#");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
int getnum(int n,int c)
{
char s[6];
sprintf(s,"%d",n);
return (int(s[c-1])-48);
}
void plusnum(int &n,int c)
{
char s[6];
sprintf(s,"%d",n);
n+=pow(10,strlen(s)-c);
}
bool pass(int n,int (&d)[10],int k)
{
int i,j;
char str[6];
sprintf(str,"%d",n);
for(j=0;j<strlen(str);j++)
for(i=0;i<k;i++)
if(getnum(n,j+1)==d[i])
return false;
return true;
}
int main()
{
int n,k,i;
int d[10];
char ms[6];
cin>>n>>k;
for(i=0;i<k;i++)cin>>d[i];
sprintf(ms,"%d",n);
i=1;
while(1)
{
if(!pass(n,d,k))n++;
else goto STOP_WHILE0;
}
STOP_WHILE0:
cout<<n;
return 0;
}




Measured memory_bytes: 256
from collections import deque

n, m = map(int, input().split())
friend = [set() for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  friend[a-1].add(b-1)
  friend[b-1].add(a-1)

flag = [True for i in range(n)]
max_grupe = 0
for i in range(n):
  if(flag[i] == False):
    continue
  num = 0
  queue = deque([i])
  flag[i] = False
  while queue:
    now = queue.popleft()
    num += 1
    for j in friend[now]:
      if(flag[j]):
        queue.append(j)
        flag[j] = False
        
  max_grupe = max(max_grupe, num)
  
print(max_grupe)

Measured memory_bytes: 72856
H, W  = map(int, input().split())

grid = [list(map(int, input().split())) for i in range(H)]


ans = 0
ansgrid = []


for i in range(H):
  for j in range(W):
    if grid[i][j] % 2 == 1:
      if i == H-1:
        if j != W-1:
          ansgrid.append([i,j,i,j+1])
          ans += 1
          grid[i][j] -= 1
          grid[i][j+1] += 1
        else:
          break


      
      else:
        ansgrid.append([i,j,i+1,j])
        ans += 1
        grid[i][j] -= 1
        grid[i+1][j] += 1

        


print(ans)
for i in range(len(ansgrid)):
  print(ansgrid[i][0]+1,ansgrid[i][1]+1,ansgrid[i][2]+1,ansgrid[i][3]+1)

Measured memory_bytes: 69724
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        a: i32,
        b: i32,
        c: i32,
    }
    if a > b && a > c {
        puts!("A\n");
    } else if b > a && b > c {
        puts!("B\n");
    } else {
        puts!("C\n");
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
typedef long long ll;
using namespace std;
const int inf=1e9;
int drdp[(1<<16)];
int main(){
	int N,M,K;
	cin>>N>>M>>K;
	int D[16];
	int isD[101]={};
	REP(i,0,M) {
		cin>>D[i];
		D[i]--;
		isD[D[i]]=(1<<i);
	}
	vector<int> root[110];
	int a;
	REP(i,0,N){
		REP(j,0,K){
			cin>>a;
			a--;
			root[i].push_back(a);
		}
	}
	REP(i,0,(1<<M)) drdp[i]=inf;
	drdp[(1<<M)-1]=0;
	queue<int> q;
	q.push((1<<M)-1);
	//bfs
	while(!q.empty()){
		int now=q.front();	q.pop();
		if(drdp[0] != inf) break;
		REP(j,0,K){
			int ns=0;
			REP(i,0,M){
				if(now&(1<<i)) {
					//next room is dark or not
					int next = root[D[i]][j];
					if(isD[next]>=0)
						ns |= isD[next];
				}
			}
			if(drdp[ns]==inf) {
				drdp[ns] = drdp[now]+1;
				q.push(ns);
			}
		}
	}
	p(drdp[0]);
	return 0;
}

Measured memory_bytes: 3540
import sys
import math
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()
x = math.floor(A / 0.08)
y = math.ceil((A + 1) / 0.08)

flag = 0
for i in range(x, y):
    if math.floor(i * 0.08) == A and math.floor(i * 0.10) == B:
        print(i)
        flag += 1
        break

if flag == 0:
    print(-1)


Measured memory_bytes: 5576
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> hs(N);
  for (auto i = 0; i < N; i++) cin >> hs[i];
  sort(hs.begin(), hs.end());
  ll res = hs[N-1] - hs[0];
  for (auto i = 0; i + K - 1 < N; i++) {
    if ((hs[i+K-1] - hs[i]) < res) {
      res = (hs[i+K-1] - hs[i]);
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1024
h,w=map(int,input().split())
s=["."*(w+2)]
for i in range(h):
    S="."+input()+"."
    s.append(S)
s.append("."*(w+2))
for i in range(1,h+1):
    ans=[]
    for j in range(1,w+1):
        cnt=0
        if s[i][j]==".":
            if s[i-1][j-1]=="#":
                cnt+=1
            if s[i-1][j]=="#":
                cnt+=1
            if s[i-1][j+1]=="#":
                cnt+=1
            if s[i][j-1]=="#":
                cnt+=1
            if s[i][j+1]=="#":
                cnt+=1
            if s[i+1][j-1]=="#":
                cnt+=1
            if s[i+1][j]=="#":
                cnt+=1
            if s[i+1][j+1]=="#":
                cnt+=1
            ans.append(str(cnt))
        else:
            ans.append("#")
    print("".join(ans))

Measured memory_bytes: 9164