akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long
#define pi pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define vi vector<int>

int32_t main()
{
    IOS;
    int n; cin>>n;
 vi a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    

    sort(a.rbegin(),a.rend());
    
    int k=2;
    int res = a[0];
    for(int i=1;i<n;i++){
        if(k==n) break;

       
    res += a[i];
    k++;
    if (k == n)
        break;
    res += a[i];
    k++;

    }

    cout<<res<<endl;

}

Measured memory_bytes: 4776
#include<cstdio>
#include<vector>

using namespace std;

class ExhaustiveSearch
{
public:
	void solve(int n, int A[], int q, int M[])
	{
		for (int i = 0; i < q; i++)
		{
			if (search(n, A, 0, M[i]))
				printf("yes\n");
			else
				printf("no\n");
		}
	}

	bool search(int n, int A[], int i, int m)
	{
		if (m == 0)
			return true;
		else if (i >= n)
			return false;

		return (search(n, A, i + 1, m) || search(n, A, i + 1, m - A[i]));
	}
};

int main()
{
	int n, temp;
	scanf("%d", &n);
	vector<int> A;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &temp);
		A.push_back(temp);
	}
	int q;
	scanf("%d", &q);
	vector<int> M;
	for (int i = 0; i < q; i++)
	{
		scanf("%d", &temp);
		M.push_back(temp);
	}

	auto es = ExhaustiveSearch();
	es.solve(n, A.data(), q, M.data());
}



Measured memory_bytes: 2664
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll V[1<<18];
ll W[1<<18];
ll n;
const ll sikiri = 9;
vector<vector<P>> g(1<<18);
ll ans[1<<18];
ll dp1[sikiri + 1][101010];
P dp2[1<<10];

void dfs(ll node, ll depth){
	//cout << "dfs: " << node << " " << depth << endl;
	if(n <= node)return;
	if(depth < sikiri){
		REP(i, 101010){
			ll now = dp1[depth][i];
			if(0 <= i - W[node])now = max(now, dp1[depth][i - W[node]] + V[node]);
			if(i)now = max(now, dp1[depth+1][i-1]);
			dp1[depth+1][i] = now;
		}

		REP(i, g[node].size()){
			ll id = g[node][i].FI;
			ll L = g[node][i].SE;
			ans[id] = dp1[depth + 1][L];
		}
	}
	else {
		ll kake = depth - sikiri;
		REP(i, 1 << kake){
			dp2[(1 << kake) | i] = MP(dp2[i].FI + W[node], dp2[i].SE + V[node]);
		}

		REP(i, g[node].size()){
			ll id = g[node][i].FI;
			ll L = g[node][i].SE;
			REP(j, 1 << (kake + 1)){
				if(L < dp2[j].FI)continue;
				ans[id] = max(ans[id], dp2[j].SE + dp1[sikiri][L - dp2[j].FI]);
			}
		}
	}

	dfs(2 * node + 1, depth + 1);
	dfs(2 * node + 2, depth + 1);
}

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

	cin >> n;
	REP(i, n)cin >> V[i] >> W[i];
	ll q;cin >> q;
	REP(i, q){
		ll v, l;cin >> v >> l;
		g[v-1].EB(i, l);
	}

	dfs(0, 0);
	REP(i, q)cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 24552
#include <stdio.h>

int main()
{

    char a[1010];
    scanf("%s",a);
    int i;
    for (i = 0; a[i] != '\0'; i++)
    {
    }
    if(a[i-1]=='s'){
        printf("%ses",a);
    }else {
        printf("%ss",a);
    }

    printf("\n");
  
}

Measured memory_bytes: 2152
from collections import defaultdict


def solve(x):
    if x % 11 == 0:
        return x // 11 * 2
    if x % 11 <= 6:
        return x // 11 * 2 + 1
    return x // 11 * 2 + 2


def main():
    x = int(input())
    print(solve(x))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point
{
public:
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}

  Point operator+(Point p)
  {
    return Point(x + p.x, y + p.y);
  }
  Point operator-(Point p)
  {
    return Point(x - p.x, y - p.y);
  }
  Point operator*(double a)
  {
    return Point(a * x, a * y);
  }
  Point operator/(double a)
  {
    return Point(x / a, y / a);
  }

  double abs()
  {
    return sqrt(norm());
  }
  double norm()
  {
    return x * x + y * y;
  }

  bool operator<(const Point &p) const
  {
    return x != p.x ? x < p.x : y < p.y;
  }
  bool operator==(const Point &p) const
  {
    return equals(x, p.x) && equals(y, p.y);
  }

  void print()
  {
    printf("%.10f %.10f\n", x, y);
  }
};

typedef Point Vector;

double dot(Vector a, Vector b)
{
  return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b)
{
  return a.x * b.y - a.y * b.x;
}

struct Segment
{
  Point p1, p2;
};

typedef Segment Line;

class Circle
{
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0) : c(c), r(r) {}
};

typedef vector<Point> Polygon;

Point projection(Line l, Point p)
{
  return l.p1 + (l.p2 - l.p1) * (dot(p - l.p1, l.p2 - l.p1) / (l.p2 - l.p1).norm());
}

Point reflection(Line l, Point p)
{
  Point x = projection(l, p);
  return p + (x - p) * 2;
}

bool is_ccw(Point p0, Point p1, Point p2)
{
  Vector a = p1 - p0, b = p2 - p0;
  return cross(a, b) > 0;
}

bool is_cw(Point p0, Point p1, Point p2)
{
  Vector a = p1 - p0, b = p2 - p0;
  return cross(a, b) < 0;
}

bool is_parallel(Line l1, Line l2)
{
  Vector a = l1.p2 - l1.p1, b = l2.p2 - l2.p1;
  return equals(cross(a, b), 0);
}

bool is_orthogonal(Line l1, Line l2)
{
  Vector a = l1.p2 - l1.p1, b = l2.p2 - l2.p1;
  return equals(dot(a, b), 0);
}

int main()
{
  int q;
  cin >> q;
  rep(i, q)
  {
    double x0, y0, x1, y1, x2, y2, x3, y3;
    cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    Line l1 = {Point{x0, y0}, Point{x1, y1}}, l2 = {Point{x2, y2}, Point{x3, y3}};
    if (is_parallel(l1, l2))
    {
      cout << 2 << endl;
    }
    else if (is_orthogonal(l1, l2))
    {
      cout << 1 << endl;
    }
    else
    {
      cout << 0 << endl;
    }
  }
}


Measured memory_bytes: 3228
/* ex 9_2
   nknm */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
node* push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL){
        exit(1);
    }
    new->elem = elem;
    new->next = *first;
    *first = new;
    return *first;

}


node* delete_node(node **first){
  // deletion
    node *tmp = *first;
    if(tmp == NULL){
        exit(1);
    }
    
    *first = tmp->next;
    free(tmp);
    return *first;
}


int main(void){

    char imput[SIZE];
    int i = 0, count = 0;
    scanf("%s", imput);
    //最初のノードの指す先
    node *first = NULL;
    //スタックにノードを追加
    while(imput[i] != '\0'){
        /*if(first != NULL){
            if(first->elem != imput[i]){
                delete_node(&first);
                count += 2;
            }else{
                if(imput[i] == '0'){
                    push(first, '0');
                }else if(imput[i] == '1'){
                    push(first, '1');
                }
            }
        }else{
            if(imput[i] == '0'){
                push(first, '0');
            }else if(imput[i] == '1'){
                push(first, '1');
            }
        }*/

        if(imput[i] == '0'){
            push(&first, '0');
        }else if(imput[i] == '1'){
            push(&first, '1');
        }
            
            
        
        if(first->next != NULL){
            if(first->elem == '1' && (first->next)->elem == '0'){
                delete_node(&first);
                delete_node(&first);
                count += 2;
            }else if(first->elem == '0' && (first->next)->elem == '1'){
                delete_node(&first);
                delete_node(&first);
                count += 2;
            }
        }
        i++;
    }
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 4876
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
    ll n;
    cin >> n;
    vl vec(n);
    ll sum = 0;
    rep(i, n){
        ll num;
        cin >> num;
        vec[i] = num;
        sum += num;
        sum %= mod;
    } 
    ll ans = 0;
    ll no = 0;
    rep(i, n){
        no += vec[i];
        no %= mod;
        ll gap = sum - no;
        if(gap < 0) gap += mod;
        ll tmp = vec[i]*gap;
        tmp %= mod;
        ans += tmp;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4804
#include<bits/stdc++.h>
#define M 500005
using namespace std;
struct node{double t,v;}q[M]={0},p;
int head=0,tail=0;
int main(){
    double l=0,ll=0,now=0;
    int n; scanf("%d",&n);
    scanf("%lf",&ll); l=ll;
    while(n--){
        scanf("%lf%lf",&p.t,&p.v);
        while(p.v>l){
            if(q[head].v+l<=p.v)
            now-=q[head].v*q[head].t,l+=q[head++].v;
            else{
                double x=p.v-l;
                now-=x*q[head].t;
                l+=x;
                q[head].v-=x;
            }
        }
        l-=p.v; now+=p.v*p.t; q[++tail]=p;
        while(head<tail&&q[tail-1].t>=q[tail].t){
            q[tail-1].t=(q[tail-1].t*q[tail-1].v+q[tail].t*q[tail].v)/(q[tail-1].v+q[tail].v);
            q[tail-1].v+=q[tail].v;
            tail--;
        }
        printf("%.10lf\n",now/ll);
    }
}

Measured memory_bytes: 18800
#include<bits/stdc++.h>
int main(void){
  int n;
  int t,a;
  std::cin >> n >> t>>a;
  std::vector<int> h(n);
  std::vector<double> tem(n);
  for(int i = 0;i< n;i++){
    std::cin>>h[i];
  }
  double dis;
  int count = 0;
  for (int i = 0; i < n; i++) {
    tem[i]= t-(h[i]*0.006);
  }
  dis = abs(tem[0]-a);
  double  diff;
  for (size_t i = 1; i < n; i++) {
    diff = fabs(tem[i]-a);
    if(dis>diff){
      dis = diff;
      count = i;
    }
  }
  std::cout<<count+1;
}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d)cout << "Left" << endl;
	else if (a + b < c + d)cout << "Right" << endl;
	else cout << "Balanced" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define _ %1000000007

typedef long long LL;
using namespace std;

int compute(int M, int D) {
    if (abs(M-D) > 1) return 0;
    int tiny = min(M, D);
    LL ret = 1;
    for (LL item = tiny; item >= 2; item--) {
        ret = (item*ret)_;
    }
    ret = (ret*ret)_;
    if(M == D) {
        ret = (ret<<1)_;
    }
    else {
        int big = max(M, D);
        ret = (ret*big)_;
    }
    return ret;


}

int main() {
    int m,d;
    cin >> m >> d;
    int ret = compute(m, d);
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r, D, x2000;
  cin >> r >> D >> x2000;
  int x = x2000;
  for (int i = 0; i < 10; i++) {
    x = r * x - D;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FR first
#define SE second
#define inf 0x3f3f3f3f3f3f3f3fLL

using namespace std;

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

map <pr,ll> f[20][20];
int num[20];

ll dfs(int l,int r,ll s1,ll s2) {
  if (r-l==1) return s1*num[l]+s2*num[r];
  if (f[l][r].count(pr(s1,s2))) return f[l][r][pr(s1,s2)];
  ll ans=inf;
  for(int i=l+1;i<r;i++)
    ans=min(ans,dfs(l,i,s1,s1+s2)+dfs(i,r,s1+s2,s2)-num[i]*(s1+s2));
  return f[l][r][pr(s1,s2)]=ans;
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&num[i]);
  printf("%lld\n",dfs(1,n,1,1));
  return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;




class UnionFind{
    vector<int> par;
    int all = 0;
    vector<int> siz;
    int treenum;

    public:UnionFind(int N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par.eb(i);
        for(int i = 0; i < N; i++) siz.eb(1);
        all = N;
        treenum = N;
    }

    public:int root(int x){
        if(par[x]==x) return x;
        else{
            par[x]=root(par[x]);
            return par[x];
        }
    }

    public:bool same(int x, int y){
        return root(x)==root(y);
    }

    public:void unite(int x, int y){
        if(same(x,y)) return;
        else{
            int rx=root(x);
            int ry=root(y);
            par[ry]=rx;
            siz[rx]=siz[rx]+siz[ry];
            siz[ry]=siz[rx];
            treenum--;
            return;
        }
    }

    public:int size(int x){
        siz[x]=siz[root(x)];
        return siz[x];
    }

    public:void sizall(){
        rep(i,all){
            siz[i] = siz[root(i)];
        }
    }

    public:int treenumber(){
        return treenum;
    }

    public:void add(){
        par.eb(all);
        siz.eb(1);
        all++;
        treenum++;
    }

    public:void del(int x){
        //xを木から外して単一ノードの木に分離する
        //子の検索にO(n)かける. UF木の弱点なので使用は推奨されない
        //根であれば繋ぎ直し、素集合としてみなさない.
        bool isroot=false;
        //あるノードの根であるかどうか.
        rep(i,all){
            if(root(i)==x) isroot=true;
        }
        if(!isroot){
            rep(i,all){
                if(par[i]==x){
                    par[i]=par[x];
                }
            }
            par[x]=x;
            return;
        }

        if(isroot){
            sizall();
            if(size(x)==1) return;
            rep(i,all){
                if(par[i]==x){
                    treenum++;
                    par[i]=i;
                }
            }
            return;
        }

    }

};



void solve(){

    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    int v[n];
    rep(i,n){
        v[i]=-1;
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a,b);
        v[a]--;
        v[b]--;
    }
    rep(i,n){
        v[i] += uf.size(i);
    }
    rep(i,k){
        int c,d;
        cin >> c >> d;
        c--;
        d--;
        if(uf.same(c,d)){
            v[c]--;
            v[d]--;
        }
    }

    rep(i,n){
        cout << v[i] << " ";
    }
    cout << endl;

}

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


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//typedef int ll;
typedef long double ld;
//#define int ll
#define pb push_back
#define __bp __builtin_popcount
using vint = vector<int>;
using pii = pair<int,int>;
using pdd = pair<ld,ld>;
using vpii = vector<pii>;
#define F first
#define S second
const int N = 1e5+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int Inf = 1e9+7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("sweets.in", "r", stdin);
//	freopen("sweets.out", "w", stdout);
	cout << setprecision(2) << fixed;
}

int n, m, k;
char a[8][8];

signed main()
{	
	io();
	cin >> n >> m >> k;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int m1 = 0; m1 < (1 << n); ++m1)
	{
		for (int m2 = 0; m2 < (1 << m); ++m2)
		{
			int sm = 0;
			for (int i = 0; i < n; ++i)
			{
				for (int j = 0; j < m; ++j)
				{
					if ((a[i][j] == '#') && !(((1 << i) & m1) || ((1 << j) & m2)))
					{
						++sm;
					}
				}
			}
			if (sm == k)
				++ans;
		}
	}
	cout << ans;
}

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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  double a, t;
  cin >> n >> t >> a;
  double res = 1001001;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int ans = 1;
  rep(i,n) {  
    double now;
    now = abs(t-h[i]*0.006-a);
    if(now<res) {
      ans = i+1;
      res = now;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> X(N), Y(N);
	vector<long long> P(N);

	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> Y[i] >> P[i];
	}

	vector<vector<long long>> h(N, vector<long long>(1 << N));
	vector<vector<long long>> v(N, vector<long long>(1 << N));

	for (int i = 0; i < N; ++i) {
		for (int mask = 0; mask < (1 << N); ++mask) {
			h[i][mask] = P[i] * abs(Y[i]);
			v[i][mask] = P[i] * abs(X[i]);
			for (int k = 0; k < N; ++k) {
				if (mask & (1 << k)) {
					h[i][mask] = min(h[i][mask], P[i] * abs(Y[i] - Y[k]));
					v[i][mask] = min(v[i][mask], P[i] * abs(X[i] - X[k]));
				}
			}
		}
	}

	vector<int> p3(N + 1);
	p3[0] = 1;
	for (int i = 1; i <= N; ++i) {
		p3[i] = 3 * p3[i - 1];
	}

	vector<long long> ans(N + 1, numeric_limits<long long>::max());

	for (int mask = 0; mask < p3[N]; ++mask) {
		int mask_h = 0;
		int mask_v = 0;
		int k = N;
		for (int i = 0; i < N; ++i) {
			int t = (mask / p3[i]) % 3;
			if (t == 1) {
				mask_h |= 1 << i;
			}
			else if (t == 2) {
				mask_v |= 1 << i;
			}
			else {
				--k;
			}
		}

		long long result = 0;
		for (int i = 0; i < N; ++i) {
			result += min(h[i][mask_h], v[i][mask_v]);
		}
		ans[k] = min(ans[k], result);
	}

	for (int i = 0; i <= N; ++i) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 11220
n = int(input())
sp = [0]*n
z = [0]*n
for i in range(n):
    sp[i]    = input().split() + [i+1]
    sp[i][1] = int(sp[i][1])
    z[i]     = sp[i][0]
a = sp
a.sort(key=lambda val : val[0])
import collections
c = collections.Counter(z)

i = 0
while i < n:
    b = c[a[i][0]]
    d = a[i:i+b][:]
    d.sort(key= lambda val : val[1],reverse=True)
    for j in range(b):
        print(d[j][2])
    i += b

Measured memory_bytes: 3316
import numpy as np
words = lambda t : list(map(t, input().split()))
n,m = words(int)
a = words(int)
cb = []
for i in range(m):
    b,c = words(int)
    cb.append((c,b))

a.sort()
cb = list(reversed(sorted(cb)))

#print(a)
#print(cb)

ind_a = 0
end = False
for (c,b) in cb:
    for i in range(b):
        if ind_a >= n:
            end = True
            break
        if a[ind_a] < c:
            a[ind_a] = c
            ind_a += 1
        else:
            end = True
            break
    if end:
        break

print(sum(a))


Measured memory_bytes: 32196
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

template <class T, class T2>
class LazySegTree {
    using F = function<T(T, T)>;
    using G = function<T(T, T2)>;
    using H = function<T2(T2, T2)>;
    using P = function<T2(T2, int)>;
    int n;
    vector<T> data;
    vector<T2> lazy;
    const F f;
    const G g;
    const H h;
    const P p;
    const T e;
    const T2 e2;

public:
    LazySegTree(const vector<T>& as, const F f, const G g, const H h, const P p, const T& e, const T2 e2) : f(f), g(g), h(h), p(p), e(e), e2(e2) {
        n = 1;
        while (n < as.size()) n <<= 1;
        data.assign(2 * n, e);
        lazy.assign(2 * n, e2);
        for (int i = 0; i < as.size(); i++) {
            data[n + i] = as[i];
        }
        for (int i = n - 1; i > 0; i--) {
            data[i] = f(data[2 * i], data[2 * i + 1]);
        }
    }

    void propagate(int k, int len) {
        if (lazy[k] != e2) {
            if (k < n) {
                lazy[2 * k] = h(lazy[2 * k], lazy[k]);
                lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
            }
            data[k] = g(data[k], p(lazy[k], len));
            lazy[k] = e2;
        }
    }

    T update(int a, int b, const T2& x, int k, int l, int r) {
        propagate(k, r - l);
        if (r <= a || b <= l) {
            return data[k];
        } else if (a <= l && r <= b) {
            lazy[k] = h(lazy[k], x);
            propagate(k, r - l);
            return data[k];
        } else {
            return data[k] = f(update(a, b, x, 2 * k, l, (l + r) >> 1), update(a, b, x, 2 * k + 1, (l + r) >> 1, r));
        }
    }

    T update(int a, int b, const T2& x) {
        return update(a, b, x, 1, 0, n);
    }

    T query(int a, int b, int k, int l, int r) {
        propagate(k, r - l);
        if (r <= a || b <= l) {
            return e;
        } else if (a <= l && r <= b) {
            return data[k];
        } else {
            return f(query(a, b, 2 * k, l, (l + r) >> 1), query(a, b, 2 * k + 1, (l + r) >> 1, r));
        }
    }

    T query(int a, int b) {
        return query(a, b, 1, 0, n);
    }
};

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

    // RUQ, RMQ
    // auto f = [](i64 a, i64 b) {return min(a, b);};
    // auto g = [](i64 a, i64 b) {return b < 0 ? a : b;};
    // auto h = [](i64 a, i64 b) {return b < 0 ? a : b;};
    // auto p = [](i64 a, int b) {return a;};
    // LazySegTree<i64, i64> tree(as, f, g, h, p, 1e18, -1);

    // RAQ, RMQ
    auto f = [](i64 a, i64 b) {return min(a, b);};
    auto g = [](i64 a, i64 b) {return a + b;};
    auto h = [](i64 a, i64 b) {return a + b;};
    auto p = [](i64 a, i64 b) {return a;};
    LazySegTree<i64, i64> tree(as, f, g, h, p, 1e18, 0);

    int q;
    cin >> q;
    while (q--) {
        int c;
        cin >> c;
        if (c == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            tree.update(s, t + 1, x);
        } else {
            int s, t;
            cin >> s >> t; 
            cout << tree.query(s, t + 1) << endl;
        }
    }
}


Measured memory_bytes: 7884
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void){
    int n,m,c;
    cin >> n >> m >> c;

    vector <int> b(m);
    for(int i = 0;i < m;i++){
        cin >> b[i];
    }

    vector<vector<int> > a(n, vector<int>(m));
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin >> a[i][j];
        }
    }

    int ans = 0;
    for(int i = 0;i < n;i++){
        int sum = 0;
        for(int j = 0;j < m;j++){
            sum += a[i][j] * b[j];
        }
        
        if(sum + c > 0){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

double dp[3003][3003] , a[3003];

main()
{
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++)
	{
		scanf("%lf" , &a[i]);
	}
	
	dp[0][0] = 1;
	
	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j <= i; j++)
		{
			dp[i + 1][j] += dp[i][j] * ( 1.0 - a[i+1] );
			dp[i + 1][j + 1] += dp[i][j] * a[i+1];
		
		}
	}
	
	
	//for(int i = 0; i <= n; i++)
	//{
		//for(int j = 0; j <= n; j++)
			//cout << dp[i][j] << " ";
		//cout << endl;			
	//}
	
	double ans = 0;
	for(int i = ( n / 2 + 1 ); i <= n; i++)
		ans += dp[n][i];
	
	cout << fixed << setprecision(9) << ans << endl;
	
	
	
}


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

using namespace std;

int main() {

	long long n, tt;
	cin >> n >> tt;

	long long ans = 0;
	long long t,tim;
	cin >> t;
	ans = tt;
	tim = tt;
	for (long long i = 2; i <= n; i++) {
		cin >> t;
		if (tim  > t) {
			ans +=  tt - (tim - t);
			tim = t + tt;
		}
		else {
			ans += tt;
			tim = t + tt;
		}


	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(u == s){
     a--;   
    }
    if(u == t){
     b--;   
    }
    cout << a << " " << b;
 return 0;   
}

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

typedef long long ll;
const ll INF = 1LL << 60;

int main(void){
    int N;
    cin >> N;
    
    vector<ll> h(110000);
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    
    vector<ll> dp(110000,INF);
    
    dp[0] = 0;
    for(int i = 0; i < N; i++){
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }
    
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5116
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;

struct Color{
    long color, cost;
}


class UnionFind{
    UnionFind parent = null;

    void merge(UnionFind a)
    {
        if(same(a))
            return;
        a.root.parent = this.root;
    }
    UnionFind root()
    {
        if(parent is null)return this;
        parent = parent.root;
        return parent;
    }
    bool same(UnionFind a)
    {
        return this.root == a.root;
    }
}
void main()
{
    long N = scanElem;
    long M = scanElem;
    long[] line = scanArray;

    UnionFind[] trees = generate!(()=>new UnionFind()).take(N+1).array;
    foreach(i; 0..M)
    {
        long a = scanElem;
        long b = scanElem;
        trees[a].merge(trees[b]);
    }
    long count;
    foreach(i, a; line)
    {
        count += trees[a].same(trees[i+1]) ? 1 : 0;
    }
    writeln(count);
}

void scanValues(TList...)(ref TList list)
{
    auto lit = readln.splitter;
    foreach (ref e; list)
    {
        e = lit.fornt.to!(typeof(e));
        lit.popFront;
    }
}

T[] scanArray(T = long)()
{
    return readln.split.to!(long[]);
}

void scanStructs(T)(ref T[] t, size_t n)
{
    t.length = n;
    foreach (ref e; t)
    {
        auto line = readln.split;
        foreach (i, ref v; e.tupleof)
        {
            v = line[i].to!(typeof(v));
        }
    }
}

T scanElem(T = long)()
{
    char[] res;
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        res ~= cast(char) c;
        c = getchar;
    }
    return res.strip.to!T;
}

template fold(fun...) if (fun.length >= 1)
{
    auto fold(R, S...)(R r, S seed)
    {
        static if (S.length < 2)
        {
            return reduce!fun(seed, r);
        }
        else
        {
            import std.typecons : tuple;

            return reduce!fun(tuple(seed), r);
        }
    }
}

struct Factor
{
    long n;
    long c;
}

Factor[] factors(long n)
{
    Factor[] res;
    for (long i = 2; i ^^ 2 <= n; i++)
    {
        if (n % i != 0)
            continue;

        int c;
        while (n % i == 0)
        {
            n = n / i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if (n != 1)
        res ~= Factor(n, 1);

    return res;
}

bool isPrime(long n)
{
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (long i = 3; i ^^ 2 <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

Measured memory_bytes: 10940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(a+b >= c-1){
		cout<<b+c<<endl;
	}
	else{
		cout<<b+a+b+1<<endl;
	}
}

Measured memory_bytes: 256
from collections import deque

h,w = [int(x) for x in input().split()]
m = []
for _ in range(h):
    m.append(list(input()))

def bfs(sy,sx):
    res = [[-1]*(w) for i in range(h)]
    res[sy][sx] = 0
    q = deque()
    q.append([sy,sx])
    dis = 0
    while q:
        z = q.popleft()
        for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
            ny = z[0] + dy
            nx = z[1] + dx
            if 0<=ny<h and 0<=nx<w and m[ny][nx]=="." and res[ny][nx]==-1:
                q.append([ny,nx])
                res[ny][nx] = res[z[0]][z[1]] + 1
                dis = res[ny][nx]
    return dis

ans = -1
for i in range(h):
    for j in range(w):
        if m[i][j] == ".":
            ret = bfs(i,j)
            if ret > ans:
                ans = ret
print(ans)

Measured memory_bytes: 45420
def read_input():
    n = int(input())
    return n

def submit():
    n = read_input()

    if n // 10 == 9:
        print('Yes')
        return
    if n % 10 == 9:
        print('Yes')
        return

    print('No')

if __name__ == '__main__':
    submit()

Measured memory_bytes: 38384
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Either
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V
 
getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]
 
type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)
 
mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac
 
(.<.) f g -- combination
    | f < g = 0 
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)
 
unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)
 
mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a
 
countIf f = length . filter f
 
-- 
--
--

main = do
  [a,b,c]<-getIs
  putStrLn . show $ a * b `div` 2


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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = r/d - (l-1)/d;
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-10;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 1e5+10;
const int MAXM = (int) 1e5+10;
const int sigma_size = (int) 26;

///--------------------START-------------------------
int n;
int k;
int x[MAXN];

void work(){
    scanf("%d%d",&n,&k);
    int ans=INF;
    for(int i=1;i<=n;i++) scanf("%d",&x[i]);
    for(int i=1;i+k-1<=n;i++){
        if(x[i+k-1]<=0) ans=min(ans,0-x[i]);
        else if(x[i]>=0) ans=min(ans,x[i+k-1]);
        else ans=min(ans,x[i+k-1]-x[i]+min(x[i+k-1],-x[i]));
    }
    printf("%d\n",ans);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}






Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 1000000000;
int a[100005],sum[100005],save[100005];
typedef long long ll;
ll to,to1;
int n;int maxl,minl;
void sortl(int left,int right)
{
    if(left==right)
        return ;
    int mid=(right+left)/2;
    sortl(left,mid);
    sortl(mid+1,right);
    int l=left,l2=mid+1,r=left;
    while(l<=mid&&l2<=right)
    {
        if(sum[l]<sum[l2])
            save[r++]=sum[l++];
        else
        {
            to1+=l-left;
            save[r++]=sum[l2++];
        }
    }
    while(l<=mid)
        save[r++]=sum[l++];
    while(l2<=right)
    {
        to1+=l-left;
        save[r++]=sum[l2++];
    }
    for(int i=left;i<=right;i++)
        sum[i]=save[i];
}
bool ck(int x)
{
    to1=0;
    for(int i=1;i<=n;++i)
        sum[i]=(a[i]<=x?1:-1);
    for(int i=1;i<=n;++i)
        sum[i]+=sum[i-1];
    sortl(0,n);
    return to1>=to/2+1;
}
int main()
{
    maxl=-INF;minl=INF
    scanf("%d",&n);
    to=0;
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        minl=min(minl,a[i]);
        maxl=max(maxl,a[i]);
        to+=i;
    }
    while(minl<maxl)
    {
        int mid=(minl+maxl)/2;
        if(ck(mid))
            maxl=mid;
        else
            minl=mid+1;
    }
    printf("%d\n",maxl);
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

map<int, int> cnt;

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		int a;
		scanf("%d", &a);
		cnt[-a]++;
	}
	int ans = 0;
	FA(it, cnt) {
		int val = -it->_1;
		int st2 = 1;
		for(; st2 <= val; st2 *= 2);
		int dif = st2 - val;
		if (dif == val) {
			ans += it->_2 / 2;
			it->_2 &= 1;
		} else {
			if (cnt.find(-dif) != cnt.end()) {
				int add = min(it->_2, cnt[-dif]);;
				ans += add;
				it->_2 -= add;
				cnt[-dif] -= add;
			}
		}
	}
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 9600
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)

using ll = int64_t;
using ld = long double;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr ll inf = 2e18;
constexpr int M = 1e9 + 7;

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

	int n; cin >> n;
	ld p[n]; rep(i, 0, n) cin >> p[i];
	ld dp[n + 1] = {1};
	rep(x, 0, n) dp[x + 1] = 0;
	rep(i, 0, n) {
		per(x, 0, n)
			dp[x + 1] = p[i] * dp[x] + (1 - p[i]) * dp[x + 1];
		dp[0] = (1 - p[i]) * dp[0];
	}
	ld ans = 0;
	rep(x, n / 2, n) ans += dp[x + 1];
	cout << fixed << setprecision(10) << ans;
}

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

int main()
{
    int i,n,k=0;
    string s;
    getline(cin,s);
    cout<<s[0];
    for(i=6;i<s.size();i++)
    {
      if(s[i]>=65&&s[i]<=90)
      cout<<s[i];
    }
  cout<<endl;
  return 0;
}


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

using namespace std;

#define ops cout<<"ops"<<endl;
#define freopens freopen("cowpatibility.in", "r", stdin);freopen("cowpatibility.out", "w", stdout);
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define DIM 100007
#define DIMM 50007
#define INF 10000000000000000007.0
#define X 31
#define eps 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO (long long)1000000007

const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll n;
ll a[DIM],d[DIM];

int main()
{
    //ops;
    //freopens;
    fast;
    //ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    d[2]=abs(a[1]-a[2]);
    for(int i=3;i<=n;i++){
     d[i]=min((d[i-1]+abs(a[i-1]-a[i])),(d[i-2]+abs(a[i-2]-a[i])));
    }
    cout<<d[n]<<endl;
    return 0;
}



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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0, j = s.length()-1; i < j; ++i, --j)
		ans += s[i] != s[j];
	cout << ans << "\n";

	return 0;
}


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

Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int n,m,l;
 	cin >> n>>m>>l;
 	if(n==m&&m==l){
 		cout << "Yes" << endl;
 	}else{
 		cout << "No" << endl;
 	}
 }

Measured memory_bytes: 256
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
LL read(){
    LL f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	x*=f;
    return x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int cnt[50];
LL a[MAXN+5];
bool part[MAXN+5][50];
int main(){
	LL n=read(),k=read(),Max=0;
	for(int i=1;i<=n;i++){
		a[i]=read(),Max=max(Max,a[i]);
		for(int j=0;(1ll<<j)<=a[i];j++)
			part[i][j]=(1ll<<j)&a[i];
	}
	for(int j=0;(1ll<<j)<=Max;j++)
		for(int i=1;i<=n;i++)
			cnt[j]+=part[i][j];
	LL ans=0,tmp=0;
	for(int j=45;j>=0;j--){
		if(cnt[j]<n-cnt[j]&&((tmp|(1ll<<j))<=k))
			ans+=(1ll<<j)*(n-cnt[j]),tmp|=(1ll<<j);
		else 
			ans+=(1ll<<j)*cnt[j];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5888
#include <vector>
#include <iostream>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int n, q;
string s;
vector<vector<int>> BIT;

void update(int i, int c, int inc) {
	s[i] = (char)(c + 'a');
	while (i <= n) {
		BIT[i][c] += inc;
		i += (i & (-i));
	}
}

int query(int i, int c) {
	int res = 0;
	while (i > 0) {
		res += BIT[i][c];
		i -= (i & (-i));
	}

	return res;
}

int main() {

	cin >> n >> s >> q;
	BIT.resize(n + 1, vector<int>(26, 0));
	s = "*" + s;

	for (int i = 1; i <= n; i++) update(i, s[i] - 'a', 1);

	while (q--) {
		int type; cin >> type;
		if (type == 1) {
			int i;
			char c;
			cin >> i >> c;

			update(i, s[i] - 'a', -1);
			update(i, c - 'a', 1);
		}
		else {
			int l, r; cin >> l >> r;
			int ans = 0;

			for (int c = 0; c <= 25; c++) if (query(r, c) - query(l - 1, c)) ans++;
			cout << ans << "\n";
		}
	}

	return 0;
}

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

#define pb push_back
#define all(a) a.begin(), a.end()

using ll = long long;
using pii = pair<int, int>;

const int N = 3e4 + 10;
vector<int> pos[11];
int ans;

void solve(int i, string &num) {
	if (i == 3) {
		int on = num[0] - '0';
		int tw = num[1] - '0';
		int th = num[2] - '0';
		auto it1 = upper_bound(all(pos[on]), -1);
		if (it1 != pos[on].end()) {
			auto it2 = upper_bound(all(pos[tw]), *it1);
			if (it2 != pos[tw].end()) {
				auto it3 = upper_bound(all(pos[th]), *it2);
				if (it3 != pos[th].end())
					++ans;
			}
		}
		return;
	}
	for (char c = '0'; c <= '9'; ++c) {
		num += c;
		solve(i + 1, num);
		num.pop_back();
	}
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    string s; cin >> s;
    for (int i = 0; i < n; ++i) {
    	char c = s[i];
    	pos[c - '0'].pb(i);
    }
    string num;
    ans = 0;
    solve(0, num);
    cout << ans << "\n";
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(){
int i,a=0,b=0;
char s[1000000];
while(1){
fgets(s,1000000,stdin);
if(s[0]=='0'){
break;
}
for(i=1;i<strlen(s);i++){
if(s[i]=='A'){
a++;
}
else if(s[i]=='B'){
b++;
}
}
if(a>b){
a++;
}
else{
b++;
}
printf("%d %d\n",a,b);
a=0,b=0;
}
return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	int sum=0;
	vector<char> vec(3);
	for(int i=0; i<3; i++){
		vec[i]=s[i];
	}
	sort(vec.begin(),vec.end());
	if(vec[0]=='a'){
		sum++;
	}
	if(vec[1]=='b'){
		sum++;
	}
	if(vec[2]=='c'){
		sum++;
	}
	
	if(sum==3){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
int N;
int ans=0;
cin >> N;
if(N<=9)ans=N;
else if(N<=99)ans=9;
else if(N<=999)ans=N-90;
else if(N<=9999)ans=909;
else if(N<=99999)ans=N-9090;
else if(N<=100000)ans=90909;
cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>

#include <ctype.h>
#include <string.h>


int main() {
        char s[20] = { 0 };
        char t[20] = { 0 };
        scanf("%s", s);
        scanf("%s", t);
        int i = 0;
        for (i = 0; s[i] != '\0'; i++);
        if(i==1){
        if(s[0]==t[0]){
        printf("Yes");}
        else {
printf("No");}}
        int u;
        for (u =0 ; u < i-1; u++) {
                if (s[u] != t[u]) {
                        printf("No\n");
                        u=i;
                }
                if (u==i-2&&s[i - 1] == t[i - 1]) {
                        printf("Yes");
                }
                else if(u==i-2&&s[i-1]!=t[i-1])  {
                  printf("No");
        }
        }
return 0;
}
                               

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e,Min;
	cin>>a>>b;
	c=a+b;
	d=a-b;
	e=a*b;
	 Min=c;
    if(Min<d)
	 Min=d;
	if(Min<e)
	 Min=e;
	 {
	 	cout<<Min;
	 	return 0;
	 }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2000+10,inf=0x3f3f3f3f;
char s[2];
int a[maxn],b[maxn];
int s1[maxn][maxn],s2[maxn][maxn];
int dp[maxn][maxn];
int main(){
	int n=read();
	REP(i,1,(n<<1)){
		scanf("%s",s+1);
		int x=read();
		if(s[1]=='W') a[x]=i;
		else b[x]=i;
	}
	REP(i,1,n) REP(j,i+1,n) if(a[j]<a[i]) s1[i][0]++;
	REP(i,1,n) REP(j,1,n) if(b[j]<a[i]) s1[i][j]++;
	REP(i,1,n) REP(j,i+1,n) if(b[j]<b[i]) s2[0][i]++;
	REP(i,1,n) REP(j,1,n) if(a[j]<b[i]) s2[j][i]++;
	REP(i,1,n) REP(j,1,n) s1[i][j]+=s1[i][j-1];
	REP(i,1,n) REP(j,1,n) s2[i][j]+=s2[i-1][j];
	memset(dp,inf,sizeof(dp));
	dp[0][0]=0;
	REP(i,0,n) REP(j,0,n){
		if(i) chkmin(dp[i][j],dp[i-1][j]+s1[i][0]+s1[i][n]-s1[i][j]);
		if(j) chkmin(dp[i][j],dp[i][j-1]+s2[0][j]+s2[n][j]-s2[i][j]);
	}
	printf("%d\n",dp[n][n]);
	return 0;
}


Measured memory_bytes: 47488