akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;

//clang++ -std=c++11 -stdlib=libc++ 
// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<ii> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<ii> res(1, ii(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

bool b[1000005];

int main() {
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  int ans =0;
  rep(i,n) {
    if (i && a[i] == a[i-1]) continue;
    ll num = a[i];
    ll now = a[i];
    if (b[num] == false && (i==n-1 || a[i] != a[i+1])) ans++;
    while (now <= 1e6) {
      b[now] = true;
      now += num;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5824
class UnionFind:
    def __init__(self, n): # 初期化。1スタートで設計
        self.par = [i for i in range(n+1)] #親
        self.rank = [0]*(n+1) # 高さ

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int, input().split())
p = list(map(int, input().split()))
pab = [list(map(int, input().split())) for i in range(m)]

uf = UnionFind(n)
for x,y in pab:
    uf.union(x,y)

cnt = 0
for i,k in enumerate(p):
    if k == i+1: # そもそもカウントできる場所にいる場合
        cnt += 1
    else:
        if uf.same_check(i+1,k):
            cnt += 1
print(cnt)


Measured memory_bytes: 35528
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read()
{
	char x = getchar();
	ll lin = 0,f = 1;
	while(x < '0' || x > '9')
	{
		if(x == '-') f = -1;
		x = getchar();
	}
	while(x >= '0' && x <= '9')
	{
		lin = lin * 10 + x - '0';
		x = getchar();
	}
	return lin * f;
}
#define PII pair<ll,ll>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
#define maxn 1000001
ll pos[maxn],f,l,t,n,m,zhuan;
int main(){
	n = read(); l = read(); t = read();
	
	for(ll i = 1; i <= n; i++)
	{
		pos[i] = read();
		f = read();
		if(f == 2) pos[i] -= t;
		else pos[i] += t;
		if(pos[i] < 0)
			zhuan -= (-pos[i] + l - 1) / l;
		else
			zhuan += pos[i]/ l;
		pos[i] = (pos[i] % l + l) % l;
	}
	zhuan = (zhuan % n + n) % n;
	sort(pos + 1,pos + 1 + n);/*
	for(ll i = zhuan; i <= n; i++)
		printf("%lld\n",pos[i]);
	for(ll i = 1; i < zhuan; i++)
		printf("%lld\n",pos[i]);*/
			for (int i=1;i<=n;i++)
	 printf("%d\n",pos[(i+zhuan-1)%n+1]);
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
#define ll long long
#define pii pair<int,int>
const int inf = 1 << 30;

struct edge{
    int to, cost;
};

int N, M, K, Q, S[100010], T[100010], D[100010], l2;
vector<edge> G[100010];
vector<int> to[100010];
vector<int> F;
int root[100010], par[100010][20], depth[100010];

int find(int x){
    return (root[x] == x ? x : root[x] = find(root[x]));
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    root[x] = y;
}

bool same(int x, int y){
    return find(x) == find(y);
}

void dijk(){
    fill(D, D + N + 1, inf);
    priority_queue<pii, vector<pii>, greater<>> pq;//cost, from
    for(auto u : F){
        D[u] = 0;
        pq.push({0, u});
    }
    while(!pq.empty()){
        int cost = pq.top().first;
        int from = pq.top().second;
        pq.pop();
        if(D[from] < cost) continue;

        for(auto u : G[from]){
            int to = u.to;
            int new_c = cost + u.cost;
            if(D[to] > new_c){
                D[to] = new_c;
                pq.push({new_c, to});
            }
        }
    }
}

void dfs(int v, int p, int d){
    par[v][0] = p;
    depth[v] = d;
    for(auto u : to[v]){
        dfs(u, v, d + 1);
    }
}

void build_tree(){
    dijk();
    vector<pii> vs;
    for(int i = 1; i <= N; i++){
        vs.push_back({D[i], i});
    }
    sort(vs.rbegin(), vs.rend());
    for(int i = 0; i < N; i++){
        int dist = vs[i].first;
        int e = vs[i].second;
        for(auto &u : G[e]){
            int p = find(u.to);
            if(D[p] >= dist && !same(e, p)){ 
                unite(p, e);
                to[e].push_back(p);
            }
        }
    }
    dfs(find(1), -1, 0);
    for(int k = 0; k < l2; k++){
        for(int v = 1; v <= N; v++){
            if(par[v][k] == -1) par[v][k + 1] = -1;
            else par[v][k + 1] = par[par[v][k]][k];
        }
    }
}

int lca(int s, int t){
    if(depth[s] < depth[t]) swap(s, t);
    for(int i = 0; i <= l2; i++){
        if(((depth[s] - depth[t]) >> i) & 1){
            s = par[s][i];
        }
    }
    if(s == t) return s;
    for(int i = l2; i >= 0; i--){
        if(par[s][i] != par[t][i]){
            s = par[s][i];
            t = par[t][i];
        }
    }
    return par[s][0];
}

void solve(){
    build_tree();
    for(int i = 0; i < Q; i++){
        cout << D[lca(S[i], T[i])] << endl;
    }
}

void init(){
    cin >> N >> M >> K >> Q;
    for(int i = 0; i < M; i++){
        int A, B, L;
        cin >> A >> B >> L;
        G[A].push_back(edge{B, L});
        G[B].push_back(edge{A, L});
    }
    for(int i = 0; i < K; i++){
        int fes;
        cin >> fes;
        F.push_back(fes);
    }
    for(int i = 0; i < Q; i++){
        cin >> S[i] >> T[i];
    }
    for(int i = 0; i <= N; i++){
        root[i] = i;
    }
    while((1 << l2) < N) l2++; 
}

int main(){
    init();
    solve();
    return 0;
}


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

const long long A=100000;
int main(){
  int H, W, M;
  cin >> H >> W >> M;
  vector<int> h(M), w(M);
  vector<int> row(H+1,0), col(W+1,0);
  for(int i=0; i<M; i++){
    cin >> h.at(i) >> w.at(i);
    row.at(h.at(i))++;
    col.at(w.at(i))++;
  }
  int maxrow=row.at(1), maxcol=col.at(1);
  int rown=0, coln=0;
  for(int i=1; i<=H; i++){
    if(maxrow==row.at(i)){
      rown++;
    }else if(maxrow<row.at(i)){
      maxrow=row.at(i);
      rown=1;
    }
  }
  for(int j=1; j<=W; j++){
    if(maxcol==col.at(j)){
      coln++;
    }else if(maxcol<col.at(j)){
      maxcol=col.at(j);
      coln=1;
    }
  }
  int x=0;
  for(int i=0; i<M; i++){
    if(row.at(h.at(i))==maxrow 
       && col.at(w.at(i))==maxcol){
      x++;
    }
  }
  cout << maxcol+maxrow-(rown*coln==x);
  return 0;
}

Measured memory_bytes: 8004
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
typedef long long ll;
using namespace std;

vector<vector<pair<ll,ll> > > v(200000);
ll ret[200000];
void dfs(ll u) {
  for(int x=0;x<v[u].size();x++){
    bool flag = false;
    if(ret[v[u][x].first]==0){
      if(v[u][x].second%2!=0)ret[v[u][x].first]=ret[u]*-1;
      else ret[v[u][x].first]=ret[u];
      dfs(v[u][x].first);
    }
  }
  return;
}
int main(){
  ll i,j,k,n,m;
  cin >> n;
  for(i=0;i<n-1;i++){
    cin >> j >> k >> m;
    v[j].push_back(make_pair(k,m));
    v[k].push_back(make_pair(j,m));
  }
  ret[1]=1;
  dfs(1LL);
  for(i=1;i<=n;i++){
    if(ret[i]==-1)ret[i]=0;
    cout << ret[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 11776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define lowbit(a) a&(-a)
#define INF 0x3f3f3f3f
using namespace std;

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

const int N=100001;
ll n,a[N];ll s[N];
ll c[N],tot;ll t[(N<<1)+5];

inline ll ask(int x){
	ll ret=0;
	for(int i=x;i;i-=lowbit(i)) ret+=t[i];
	return ret;
}

inline void add(int x,int k){
	for(int i=x;i<=(N<<1);i+=lowbit(i)) t[i]+=k;
}

inline bool check(int mid){
	memset(t,0,sizeof(t));s[0]=0;ll sum=0;
	for(int i=1;i<=n;i++) s[i]=s[i-1]+(a[i]>=mid? 1:-1);
	for(int i=0;i<=n;i++){
		sum+=ask(s[i]+N);add(s[i]+N,1);
	}
	return sum>=n*(n+1)/4;
}

int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read(),c[i]=a[i];
	sort(c+1,c+n+1);int m=unique(c+1,c+n+1)-c-1;
	for(int i=1;i<=n;i++) a[i]=lower_bound(c+1,c+m+1,a[i])-c;
	int l=1,r=n;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)) l=mid+1;
		else r=mid-1;
	}
	printf("%lld\n",c[r]);
	return 0;
}


Measured memory_bytes: 4096
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

using LL = long long;


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

    string s;cin >> s;
    map<char,int> mp;
    mp['a'] = 0;
    mp['b'] = 0;
    mp['c'] = 0;
    for(auto a : s)mp[a]++;
    int ma = 0, mi = 1e9;
    for(auto a : mp){
        ma = max(ma, a.second);
        mi = min(mi, a.second);
    }
    if(ma - mi > 1){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s, s1;
    cin >> n >> s;
    vector<char> se;
    for(int i = 0; i < n/2; i++){
        s1 += s[i];
    }
    s1 += s1;
    //cout << s1 << endl;
    if(s1 == s && n%2 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pint;
typedef pair<double,int> pdi;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)


int main(void) {
  ll R,G,B,N;
  ll ans = 0;
  cin >> R >> G >> B >> N;

  ll tmp,zan;
  REP(r,N/R+3){
    REP(g,N/G+3){
      tmp = r*R + g*G;
      zan = N - tmp;
      if(0 <= zan && zan%B == 0){
        ans ++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t; 
int main()
{
	cin>>s>>t;
	for(int i=0;i<t.size();i++)
	{
		cout<<s[i]<<t[i];
	}
	if(s.size()>t.size())
	{
        cout<<s[s.size()-1];
    }
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n,x;
  int i,j,k,count=0;

	

	for(;;)
	{
			count =0;

		scanf("%d%d",&n,&x);
			if(n==0&&x==0) break;
	for(i=1; i<=n; i++)
	{
		
		for(j=1; j<=n; j++)
		{
			for(k=1; k<=n; k++)
			{
				if(i!=j&&j!=k&&k!=i&&i+j+k==x)
				{
					// printf("%d+%d+%d=%d\n",i,j,k,x);
					count++;	
				} 
			}
		}
	}
		printf("%d\n",count/6);
	}
    return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) prllf("%d",n)
#define pl(n) prllf("%d",n)
using namespace std;

int main(){
  string s;
  cin >> s;
  int ans = 700;
  for(int i=0;i<3;i++){
    if(s[i]=='o'){
      ans+=100;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import math

a,b,x = map(int, input().split())

V = (a**2)*b

if x < V/2:
    t = (2*x)/(a*b**2)
    print(90 - math.degrees(math.atan(t)))
else:
    t = (2*b/a) - (2*x/a**3)
    print(math.degrees(math.atan(t)))

Measured memory_bytes: 3060
def resolve():
    x,n = map(int, input().split())
    if n==0:
        print(x)
    else:
        a = list(map(int, input().split()))
        ans=0
        for i in range(102):
            if i not in a:
                if abs(ans-x)>abs(i-x):
                    ans=i
        print(ans)
resolve()

Measured memory_bytes: 61692
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int n, m; cin >> n >> m;
	if(n==1 && m==1){
		cout << 1 << endl;
		return 0;
	}
	if(n==1){
		cout << m-2 << endl;
		return 0;
	}
	if(m==1){
		cout << n-2 << endl;
		return 0;
	}
	if(n==2 || m==2){
		cout << 0 << endl;
		return 0;
	}
	cout << (n-2)*(m-2) << endl;
	return 0;
}

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

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

                for (int i=0; i<h; i++) {
                        for (int j=0; j<w; j++) {
                                cout << "#";
                        }
                        cout << endl;
                }
                cout << "\n";
        }
        return 0;
}

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

int main(void){
    int s, fir, sec;

    cin >> s;
    fir = s / 100;
    sec = s - fir * 100;

    if(fir > 12 || fir == 0){
        if(sec > 12 || sec == 0)
            puts("NA");
        else
            puts("YYMM");
    }else if(sec > 12 || sec == 0){
        puts("MMYY");
    }else
        puts("AMBIGUOUS");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int number[3];
  scanf("%d %d %d", &number[0], &number[1], &number[2]);
  if((number[1] * 10 + number[2]) % 4 == 0) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128
A, B, K = map(int, input().split())

lst = []

for i in range(K):
    if A + i <= B:
        lst.append(A+i)
    else:
        break

for j in range(K):
    if A <= B - j:
        lst.append(B-j)
    else:
        break

lst = sorted(list(set(lst)))

for l in lst:
    print(l)


Measured memory_bytes: 9096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10;

ll r,c,vr[N],vc[N],k,ans;
string s[N];

void change(){
	for(ll i=1;i<=r;i++)
		if(vr[i]){
			for(ll j=1;j<=c;j++)
				if(s[i][j]=='.') s[i][j]='R';
				else if(s[i][j]=='#') s[i][j]='r';
		}
	for(ll i=1;i<=c;i++)
		if(vc[i]){
			for(ll j=1;j<=r;j++)
				if(s[j][i]=='.') s[j][i]='R';
				else if(s[j][i]=='#') s[j][i]='r';
		} 
}

ll count(){
	ll res=0;
	for(ll i=1;i<=r;i++)
		for(ll j=1;j<=c;j++)
			if(s[i][j]=='#') res++;
	return res;
}

void ret(){
	for(ll i=1;i<=r;i++)
		for(ll j=1;j<=c;j++)
			if(s[i][j]=='R') s[i][j]='.';
			else if(s[i][j]=='r') s[i][j]='#';
}

void printrc(){
	for(ll i=1;i<=r;i++)
		cout<<vr[i]<<" "; puts("");
	 for(ll i=1;i<=c;i++)
		cout<<vc[i]<<" "; puts("");
for(ll i=1;i<=r;i++)
cout<<s[i]<<endl;
}

int main(){
	cin>>r>>c>>k;
	for(ll i=1;i<=r;i++)
		cin>>s[i], s[i].insert(0," ");
	for(ll i=0;i<1<<(r+c);i++){
		ll sel=i;
		for(ll j=1;j<=r;j++)
			if(sel&(1<<(j-1))) vr[j]=1;
			else vr[j]=0;
		sel>>=r;
		for(ll j=1;j<=c;j++)
			if(sel&(1<<(j-1))) vc[j]=1;
			else vc[j]=0;
		change();
		if(count()==k) ans++;
		ret();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int v, i, t, min;
	i = 2;
	fscanf(stdin, "%d", &v), min = v;
	while (i--) { fscanf(stdin, "%d", &v); if (min > v) min = v; }
	t = min;
	fscanf(stdin, "%d", &v), min = v;
	fscanf(stdin, "%d", &v); if (min > v) min = v;
	P(d, t + min - 50);
	return 0;
}

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


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


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

    n--;
    m--;

    cout << n * m << endl;

}

Measured memory_bytes: 384
use proconio::input;

fn main() {
    input! {
        n: usize,
        s: String,
    }
    let r = s.match_indices("R").count();
    let g = s.match_indices("G").count();
    let b = s.match_indices("B").count();
    let c = s.as_bytes();

    let mut total = r * g * b;
    for i in 0..n {
        for j in i+1..n {
            let k = j + j - i;
            if k >= n  {
                continue;
            }
            if c[i] != c[j] && c[i] != c[k] && c[j] != c[k] {
                total -= 1;
            }
        }
    }

    println!("{}", total);
}

Measured memory_bytes: 2188
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
immutable long MOD = 1000000007;
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t)(N));
    foreach (i; 0 .. cast(size_t)(N))
    {
        A[i] = input.front.to!long;
        input.popFront;
    }

    solve(N, A);
}

void solve(long N, long[] A)
{
    long ans;
    long s = A.sum();
    foreach (a; A)
    {
        s -= a;
        ans += (s % MOD) * a;
        ans %= MOD;
    }
    writeln(ans);
}


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

int h, w;
P st, go;
char b[500][500];
ll gist[500][500], wist[500][500];
queue<P> que;
int dh[4] = {1,0,-1,0};
int dw[4] = {0,1,0,-1};
int flo = 0;

int main(){
    cin >> w >> h;
    rep(i,h) rep(j,w) cin >> b[i][j];
    rep(i,h) rep(j,w){
        if(b[i][j] == 's'){
            st.first = i;
            st.second = j;
            b[i][j] = '.';
        }
        if(b[i][j] == '.'){
            flo++;
        }
        if(b[i][j] == 'g'){
            go.first = i;
            go.second  = j;
            b[i][j] = '.';
        }
    }
    rep(i,h) rep(j,w){
        gist[i][j] = INF;
        wist[i][j] = INF;
    }
    gist[go.first][go.second] = 0;
    que.push(go);
    while(!que.empty()){
        P p = que.front();
        que.pop();
        rep(i,4){
            int nh = p.first+dh[i];
            int nw = p.second+dw[i];
            if(0>nh||nh>=h||0>nw||nw>=w) continue;
            if(b[nh][nw] != '.') continue;
            if(gist[nh][nw] <= gist[p.first][p.second]+1) continue;
            gist[nh][nw] = gist[p.first][p.second]+1;
            que.push(P(nh,nw));
        }
    }
    rep(i,h) rep(j,w){
        if(b[i][j] == '*'){
            que.push(P(i,j));
            wist[i][j] = 0;
        }
    }
    while(!que.empty()){
        P p = que.front();
        que.pop();
        rep(i,4){
            int nh = p.first+dh[i];
            int nw = p.second+dw[i];
            if(0>nh||nh>=h||0>nw||nw>=w) continue;
            if(b[nh][nw] != '.') continue;
            if(wist[nh][nw] <= wist[p.first][p.second]+1) continue;
            wist[nh][nw] = wist[p.first][p.second]+1;
            que.push(P(nh,nw));
        }
    }
    long double s = 0.0, e = 1000000000000.0, mid;
    rep(u,1000){
        mid = (s+e)/2.0;
        long double sum = 0.0;
        rep(i,h) rep(j,w){
            if(b[i][j] == '.' && go != P(i,j)){
                sum += min((long double)gist[i][j],wist[i][j]+mid);
            }
        }
        sum /= (long double)flo;
        if(mid > sum){
            e = mid;
        } else{
            s = mid;
        }
    }
    long double ans = min((long double)gist[st.first][st.second],wist[st.first][st.second]+mid);
    printf("%.15Lf\n",ans);
}

Measured memory_bytes: 7532
import java.util.*;
import java.lang.*;

class Main {
    static Deque<Integer> nowX = new ArrayDeque<Integer>();
    static Deque<Integer> nowY = new ArrayDeque<Integer>();
    static Scanner scan = new Scanner(System.in);
    static int ans;

    public static void main(String[] args) {
        while (scan.hasNext()) {
            boolean[][] field = new boolean[301][301];
            int turn = scan.nextInt();
            int n = scan.nextInt();
            if (turn == 0) {
                break;
            }
            init(field, n);
            for (int i = 0; i < turn; i++) {
                bfs(field);
            }
            System.out.println(ans);
        }
    }

    static void init(boolean field[][], int n) {
        while (nowX.peek() != null) {
            nowX.remove();
            nowY.remove();
        }
        for (int i = 0; i < 301; i++) {
            for (int j = 0; j < 301; j++) {
                field[i][j] = false;
            }
        }
        for (int i = 0; i < n; i++) {
            int x1 = scan.nextInt() + 150;
            int y1 = scan.nextInt() + 150;
            field[x1][y1] = true;
        }
        int x = scan.nextInt() + 150;
        int y = scan.nextInt() + 150;
        nowX.add(x);
        nowY.add(y);
        ans = 1;
        field[x][y] = true;
    }

    static void bfs(boolean field[][]) {
        Deque<Integer> nextX = new ArrayDeque<Integer>();
        Deque<Integer> nextY = new ArrayDeque<Integer>();
        int[] dx = {0, 1, 1, 0, -1, -1};
        int[] dy = {1, 1, 0, -1, -1, 0};
        while (nowX.peek() != null) {
            int x = nowX.remove();
            int y = nowY.remove();
            for (int i = 0; i < 6; i++) {
                if (!field[x+dx[i]][y+dy[i]]) {
                    ans++;
                    field[x+dx[i]][y+dy[i]] = true;
                    //System.out.println(x+dx[i]);
                    //System.out.println(y+dy[i]);
                    nextX.add(x+dx[i]);
                    nextY.add(y+dy[i]);
                }
            }
        }
        nowX = nextX;
        nowY = nextY;
    }
}

Measured memory_bytes: 72620
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long double N, K;
    cin >> N >> K;

    long double ex = 0;
    FOR(sai, 1, N + 1) {
        if (sai >= K) {
            ex++;
        } else {
            ll n_trial = ceil(log2(K / sai));
            // if (n_trial < 1) n_trial = 1;
            ex += 1/pow(2, n_trial);
            debug(sai, n_trial);
        }
    }
    long double ans = ex / N;
    cout << setprecision(20) << ans << endl;

    return 0;
}


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

int gcd(int x,int y){
  if(y == 0) return x;
  return  gcd(y,x%y);
}

int lcm(int x,int y){
  int g = gcd(x,y);
  return (x/g)*y;
}

int main(){
  int x,y;
  while(scanf("%d%d",&x,&y) != EOF) cout << gcd(x,y)<<" "<<lcm(x,y)<<endl;
  return 0;
}

Measured memory_bytes: 1208
S = input()
ans = 0
n = len(S)
for i in range(2 ** (n - 1)):
    ex = S[0]
    for j in range(n - 1):
        if (i >> j) & 1:
            ex += "+"
        ex += S[j + 1]
    ans += eval(ex)
print(ans)

Measured memory_bytes: 73732
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    int a[x];
    int b[y];
    int c[z];
    for(int i=0;i<x;i++){
        cin>>a[i];
    }
    for(int i=0;i<y;i++){
        cin>>b[i];
    }
    for(int i=0;i<z;i++){
        cin>>c[i];
    }
    //meet in the middle
    vector<int>res;
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            res.push_back(a[i]+b[j]);
        }
    }
    sort(res.rbegin(),res.rend());
    //cerr<<res[0]<<" "<<res[1]<<endl;
    vector<int>ans;
    for(int i=0;i<min(k,(int)res.size());i++){
        for(int j=0;j<z;j++){
            ans.push_back(res[i]+c[j]);
        }
    }
    sort(ans.rbegin(),ans.rend());
    for(int i=0;i<k;i++){
        cout<<ans[i]<<endl;
    }
    
    return 0;
    
}



Measured memory_bytes: 43108
N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[-1])
ans = 0
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[-1])
  # 一桁
  if lead == end:
    ans += 1
  #2桁以上ループ lead + 中間 + end　
  for j in range((len(str(N)) - 2) + 1):
    if end == 0 or (end > lead_N and j == (len(str(N)) - 2)):
      #末尾が0　または　生成する整数がNに収まらない場合
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      #生成する整数の一部がNに収まらない場合
      #中間の数字
      if len(str(N)) >= 3:
        ans += int(str(N)[1:-1])
      if lead <= end_N:
        ans += 1
    else:
      #何も気にしないときは組み合わせの分だけたす
      ans += 10 ** j

print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sn = new Scanner(System.in);
        
        String n = sn.nextLine();
        String tmp = null;
        int cnt = 0;
        
        for(int i = 0; i < n.length(); i++) {
            tmp = n.substring(i, i + 1);
            
            if(tmp.equals("7")){
                System.out.print("Yes");
                return;
            }
        }
        
        System.out.print("No");
    }
}


Measured memory_bytes: 35880
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int main()
{
    int prime[1010];
    for(int i=1;i<=1000;i++) prime[i]=1;
    prime[1]=0;
    for(int i=2;i<=1000;i++){
        if(prime[i]){
            for(int j=i+i;j<=1000;j+=i){
                prime[j]=0;
            }
        }
    }
    int n;
    while(~scanf("%d",&n)){
    int sum[1010];
    memset(sum,0,sizeof sum);
    long long ans=1;
    for(int i=2;i<=n;i++){
        if(prime[i]){
            sum[i]++;
            continue;
        }
        int k=i;
        for(int j=2;j<=k;j++){
            if(prime[j]){
                while(k%j==0){
                    sum[j]++;
                    k/=j;
                }
            }
        }
        if(k) sum[k]++;
    }
    for(int i=2;i<=n;i++){
        if(sum[i]){
            ans=ans*(sum[i]+1);
            ans=ans-(ans/mod)*mod;
        }
    }
    printf("%lld\n",ans%mod);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;


void solve(long long N, std::string S){
  ll rc=0,lc=0;
  ll now=0;
  rep(i,S.size()){
    if(S[i]=='(')lc++;
    else{
      lc=max(lc-1,(ll)0);
    }
    if(S[S.size()-1-i]==')')rc++;
    else{
      rc=max(rc-1,(ll)0);
    }
  }
  vector<char> ns(0);
  rep(i,rc){
    ns.push_back('(');
  }
  rep(i,S.size()){
    ns.push_back(S[i]);
  }
  rep(i,lc){
    ns.push_back(')');
  }
  
  rep(i,ns.size()){
    cout<<ns[i];
  }
 cout<<endl; 
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


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

int main(){
  
  int N,M,K;
  cin>>N>>M>>K;
  
  long long A[N],B[M],TA[N+1],TB[M+1];
  TA[0]=0;
  TB[0]=0;
  
  rep(i,N){
    cin>>A[i];
    TA[i+1]=TA[i]+A[i];
  }
  
  rep(i,M){
    cin>>B[i];
    TB[i+1]=TB[i]+B[i];
  }
  
  int ans=0;
  int j=M;
  
  rep(i,N+1){
    while(j>0 && TA[i]+TB[j]>K){
      j--;
    }
    //cout<<i<<" "<<j<<" "<<TA[i]<<" "<<TB[j]<<endl;
    if(TA[i]+TB[j]>K) break;
    if(j<0) break;
    
    ans=max(i+j,ans);
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9828
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
   int n,m,l,a,b;
   cin >> n >> m >> l;
   int A[n][m],B[m][l];
   long long C[n][l];

   for(int i=0;i<n;i++){
      for(int j=0;j<l;j++){
         C[i][j]=0;
      }
   }

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

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

   for(int i=0;i<n;i++){
      for(int j=0;j<l;j++){
         for(int k=0;k<m;k++){
            C[i][j] += A[i][k]*B[k][j];
         }
      }
   }

   for(int i=0;i<n;i++){
      for(int j=0;j<l-1;j++){
         printf("%lld ",C[i][j]);
      }
      printf("%lld\n",C[i][l-1]);
   }
   return 0;
}



Measured memory_bytes: 3292
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    int n;
    int l[15];
    cin >> n;
    rep(i,n){
        cin >> l[i];
    }
    sort(l,l+n);
    int cmp = 0;
    rep(i,n-1){
        cmp+=l[i];
    }
    if(l[n-1]<cmp)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
 
void solve(){
 
    lli ans = 0;
    priority_queue<pair<lli,lli>> q;
    priority_queue<pair<lli,lli>,vector<pair<lli,lli>>,greater<pair<lli,lli>>> qq;
 
    lli n;
    cin>>n;
    REP(i,0,n){
        lli k,l,r;
        cin>>k>>l>>r;
        if(l-r>0){
            q.push({k,l-r});
            ans += r;
        }
        else{
            qq.push({k,r-l});
            ans += l;
        }
    }
 
    lli now = 0;
 
    priority_queue<lli> s;
    lli cnt = 0;
    for(lli i=n;i>=1;i--){
        while(q.size() && q.top().first >= i){
            s.push(q.top().second);
            q.pop();
        }
        if(s.size()==0)continue;
        ans += s.top();
        s.pop();
    }
 
    while(s.size())s.pop();

    for(lli i=1;i<=n;i++){
        while(qq.size() && qq.top().first < i){
            s.push(qq.top().second);
            qq.pop();
        }
        if(s.size()==0)continue;
        ans += s.top();
        s.pop();
    }
    cout<<ans<<endl;
 
}
 
 
int main(){
 
    lli t;
    cin>>t;
    while(t--)solve();
 
    return 0;
}

Measured memory_bytes: 6732
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;
using LL = long long;
const int INF = 1e9;

int K = 0;

vector<pair<int, int>> G[100000];
int color[100000];

void dfs(int n, int nb, int kb)
{
    int k = 0;
    for (auto ns : G[n]) {
        if (ns.first == nb) continue;
        k++;
        if (k == kb) k++;
        K = max(k, K);
        color[ns.second] = k;
        dfs(ns.first, n, k);
    }
}

int main(void)
{
    LL N;
    cin >> N;
    LL a, b;
    for (int i = 0; i < N-1; i++) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(make_pair(b, i));
    }
    dfs(0, -1, 0);

    cout << K << endl;
    for (int i = 0; i < N-1; i++) {
        cout << color[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010

int main()
{
    int n;
    cin >> n;
    vector<char> s(n);
    
    rep(i,n){
        cin >>s[i];
    }
    int count_w,count_r;
    count_w=count_r=0;
    rep(i,n){
        if(s[i]=='W')
            count_w++;
    }

    rep(i,count_w){
        if(s[n-1-i]=='R'){
            count_r++;
        }
    }
    cout << count_r << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll ANS = 1e10, sum;
struct node
{
    int c, a[20];
} p[20];
int ans[15], v[20];
int n, m, u, x;
void dfs(int cnt, int pre)
{
    if (cnt == u)
    {
        sum = 0;
        fill(v, v + 20, 0);  //记录总的学习程度
        for (int j = 0; j < cnt; j++)
        {
            for (int k = 0; k < m; k++)
                v[k] += p[ans[j]].a[k];
            sum += p[ans[j]].c;
        }
        int flag = 1;
        for (int j = 0; j < m; j++)
            if (v[j] < x)
            {
                flag = 0;
                break;
            }
        if (flag)
            ANS = min(ANS, sum);
        return;
    }
    for (int j = 0; j <= n; j++)
    {
        if (j > pre)
        {
            pre = j;
            ans[cnt] = pre;
            dfs(cnt + 1, pre);
        }
    }
}

int main()
{
    cin >> n >> m >> x;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i].c;
        for (int j = 0; j < m; j++)
            cin >> p[i].a[j];
    }
    for (u = 1; u <= n; u++)
    {
        dfs(0, 0);
    }
    if (ANS == 1e10)
        puts("-1");
    else
        cout << ANS;
    return 0;
}


Measured memory_bytes: 3556
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    a, b, c = map(int, input().split())
    if (a * b * c) % 2 == 0:
        return 0
    mi = min(a * b, b * c, c * a)
    return mi

print(main())


Measured memory_bytes: 3444
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=1000;
const int inf=1e8;
int a[L];
int b[L];
int c[L];
int dist[100][100];
int main() {
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			dist[i][j]=inf;
		}
		dist[i][i]=0;
	}
	for(int i=0;i<M;i++){
		scanf("%d%d%d",a+i,b+i,c+i);
		a[i]--;b[i]--;
		dist[a[i]][b[i]]=dist[b[i]][a[i]]=c[i];
	}
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	int ret=0;
	for(int i=0;i<M;i++){
		if(dist[a[i]][b[i]]<c[i]){
			ret++;
		}
	}
	printf("%d\n",ret);


	return 0;
}



Measured memory_bytes: 256
from collections import deque
H,W = map(int,input().split())
A = [input().strip() for _ in range(H)]
B = [[-1 for j in range(W)] for i in range(H)]
que = deque([])
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            B[i][j] = 0
            que.append((i,j,0))
bmax = 0
while que:
    i,j,d = que.popleft()
    bmax = max(bmax,d)
    if j+1<W and B[i][j+1]<0:
        B[i][j+1] = d+1
        que.append((i,j+1,d+1))
    if i-1>=0 and B[i-1][j]<0:
        B[i-1][j] = d+1
        que.append((i-1,j,d+1))
    if j-1>=0 and B[i][j-1]<0:
        B[i][j-1] = d+1
        que.append((i,j-1,d+1))
    if i+1<H and B[i+1][j]<0:
        B[i+1][j] = d+1
        que.append((i+1,j,d+1))
print(bmax)

Measured memory_bytes: 147548
#include<stdio.h>
int main(){
  int x1,x2,x3,x4,x5,total;
  scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
  total=x1+x2+x3+x4+x5;
  printf("%d\n",15-total);
  }


Measured memory_bytes: 1724
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var xs = new List<string>(Console.ReadLine().Split(' '))
            .Select(x=>int.Parse(x)).ToList();
        var max = xs.Max();
        var max2 = max / 2.0;
        var m = xs.Aggregate((x, acc)=>Math.Abs(x-max2)<Math.Abs(acc-max2)?x:acc);
        Console.WriteLine("{0} {1}", max, m);
    }
}

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

using namespace std;

int main()
{
  int N, L; cin >> N >> L;
  vector<string> S(N);
  for (int i = 0; i < N; ++i) cin >> S[i];

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

  for (int i = 0; i < N; ++i) cout << S[i];
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int op(int x, int y, int i)
{
  if(i == 0)
    return x + y;
  else
    return x - y;
}

int main()
{
  string s;
  cin >> s;
  int A = int(s[0] - '0');
  int B = int(s[1] - '0');
  int C = int(s[2] - '0');
  int D = int(s[3] - '0');
  int i,j,k;
 //cout << A << B << C << D << endl;
 bool ok = false;
  for(i=0; i < 2; i++){
    for(j=0; j < 2; j++){
      for(k=0; k < 2; k++){
	//cout << op(op(op(A, B, i), C, j), D, k)  << endl;
	if(op(op(op(A, B, i), C, j), D, k) == 7){
	  ok = true;
	  break;
	}
      }
      if(ok)
	break;
    }
    if(ok)
      break;
  }
  string opp = "+-";
  //cout << i << j << k << endl;
  cout << s[0] << opp[i] << s[1] << opp[j] << s[2] << opp[k] << s[3] << "=7" << endl;
  return 0;
}



Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

S = X()
for i in S:
    if i == "+":
        ans += 1
    else:
        ans -= 1

print(ans)


Measured memory_bytes: 9968
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long int

int main() {
  int n,k;
  string s;
  cin >> n >> s >> k;
  char x = s[k - 1];
  for ( int i = 0; i < n; i++ ) {
    if ( s[i] != x ) cout << '*';
    else cout << s[i]; 
  }
  cout << endl;
  return 0;
}



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

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
#define f(i,n) for (int i = 0; i < n; i++)
using pii = pair<int,int>;
 
int di[] = {0,0,1,-1};
int dj[] = {1,-1,0,0};
 
int main() {
	int n,m;
	cin >> n >> m;
	int dp[n][m];
	queue<pii> pq;
	f(i,n) {
		string s; cin >> s;
		f(j,m) {
			dp[i][j] = s[j] == '#'?0:n+m+1;
			if (!dp[i][j]) pq.push(pii(i,j));
		}
	}
	auto IN = [&](int i, int j) {
		return i>=0&&i<n&&j>=0&&j<m;
	};
	int ans = 0;
	while (pq.size()) {
		pii pp = pq.front(); pq.pop();
		int i = pp.first, j = pp.second;	
		f(k,4) {
			int ni = i+di[k], nj = j+dj[k];
			if (IN(ni,nj) && dp[ni][nj] == n+m+1) {
				dp[ni][nj] = dp[i][j]+1;
				pq.push(pii(ni,nj));
				ans = max(ans,dp[ni][nj]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12304
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vla(i) vector<ll[i]>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

ll nc2size[100000];

void debug(string name, int x) {
    cout << name << "=" << x << endl;
}

ll nc2(int n) {
    if (n == 1) return 0;
    if (n == 2) return 1;
    if (nc2size[n] == 0) nc2size[n] = nc2(n-1) * n / (n - 2);
    return nc2size[n];
}

struct UnionFind {
    vector<int> parent;
    vector<int> tsize;
 
    UnionFind(int n) : parent(n), tsize(n) {
        for (int i = 0; i < n; i++) parent[i] = i;
        for (int i = 0; i < n; i++) tsize[i] = 1;
    }
 
    int root(int x) {
        if (parent[x] == x) return x;
        else return parent[x] = root(parent[x]);
    }
 
    void unite(int x, int y) {
        int rootX = root(x);
        int rootY = root(y);
        if (rootX == rootY) return;
        parent[rootX] = rootY;
        tsize[rootY] = tsize[rootX] + tsize[rootY];
    }

    void unite(pair<int, int> p) {
        unite(p.first, p.second);
    }
 
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    bool same(pair<int,int> p) {
        return same(p.first, p.second);
    }
 
    int count() {
        int counter = 0;
        for (int i = 0; i < parent.size(); i++) {
            if (parent[i] == i) ++counter;
        }
		return counter;
    }

    int sizeX(int x) {
        return tsize[root(x)];
    }
};


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}


int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n,m;
    cin >>n>>m;
    UnionFind t(n);
    ll total[m+1];
    ll inc[m+1];
    for (int i = 0; i < m+1; i++)
    {
        total[i] = 0;
        inc[i] = 0;
    }
    pair<ll,ll> p[m];
    for (int i = 0; i < m; i++)
    {
        cin >> p[i].first >> p[i].second;
        p[i].first--;
        p[i].second--;
    }
    for (int i = m-1; i >= 0; i--)
    {
        if (t.same(p[i])) continue;
        ll osize = nc2(t.sizeX(p[i].first)) + nc2(t.sizeX(p[i].second));
        t.unite(p[i]);
        total[i] = total[i+1] + nc2(t.sizeX(p[i].first))-osize;
        inc[i] = total[i]-total[i+1];
    }
    ll ans = 0;
    for (int i = 0; i < m; i++)
    {
        ans += inc[i];
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string w;
  cin >> w;
  bool tf = true;
  for(int i=0; i<w.size(); i++){
    int q = 0;
    for(int j=0; j<w.size(); j++){
      if(w[i] == w[j]) q++;
    }
    if(q%2 == 1) tf &= false;
  }
  if(tf) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[5001][5001];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll pre[n+1];
    pre[0]=0;
    ll suf[n+2];
    suf[n+1]=0;
    for(ll i=1;i<=n;i++)
    {
        pre[i]=__gcd(pre[i-1],a[i]);
    }
    for(ll i=n;i>=1;i--)
    {
        suf[i]=__gcd(suf[i+1],a[i]);
    }
    ll maxi=1;
    for(ll i=1;i<=n;i++)
    {
        maxi=max(maxi,(ll)__gcd(pre[i-1],suf[i+1]));
    }
    cout<<maxi;
}

Measured memory_bytes: 2560