akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll N;
    set<string> sset;
    cin >> N;
    rep(i, N) {
        string S;
        cin >> S;
        sset.insert(S);
    }
    out(sset.size());
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 19196
if __name__ == '__main__':
	data = input().split()
	w = int(data[0])
	h = int(data[1])
	x = int(data[2])
	y = int(data[3])
	r = int(data[4])

	if x-r >= 0 and x+r <= w:
		if y-r >= 0 and y+r <= h:
			print("Yes")
			exit()
	print("No")


Measured memory_bytes: 5596
#include <iostream>
#include <map>
#include <utility>
using namespace std;

int dist(pair<int,int> a, pair<int,int> b){
    int x,y;
    x=a.first-b.first;
    if(x<0) x*=-1;
    y=a.second-b.second;
    if(y<0) y*=-1;

    return x+y;
}

int main(){
    int H,W,D;
    cin >> H >> W >> D;

    map<int,pair<int,int>> bd;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            int A;
            cin >> A;
            bd[A]=make_pair(i,j);
        }
    }

    int Q;
    cin >> Q;

    unsigned long long d[180001];
    for(int i=1;i<=D;i++){
        int max=0;
        for(int j=0;j*D+i<=H*W;j++){
            d[j*D+i]=dist(bd[j*D+i],bd[j*D+i+D]);
            max=j;
        }
        for(int j=max-1;j>=0;j--){
            d[j*D+i]+=d[j*D+i+D];
        }
    }

    for(int i=0;i<Q;i++){
        int L,R;
        cin >> L >> R;

        cout << (d[L]-d[R]) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N, A, B, a, sum, count=0;
	
	cin >> N >> A >> B;
	
	for(int i=1; i<=N; i++){
		a = i;
		sum = 0;
		while(a != 0){
			sum += a%10;
			a /= 10;
		}
		if(sum >= A && sum <= B)
			count += i;
	}
	
	cout << count;
	
	return 0;
}//not yet

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  double N;
  cin >> N;
  rep(i, 50000 + 1)
  {
    if (floor(i * 1.08) == N)
    {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
a,b,c,d=-10**10,10**10,-10**10,10**10
l=[0]*4
for x,y in XY:
    if x+y>a: a=x+y;l[0]=(x,y)
    if x+y<b: b=x+y;l[1]=(x,y)
    if x-y>c: c=x-y;l[2]=(x,y)
    if x-y<d: d=x-y;l[3]=(x,y)
from itertools import combinations
print(max([abs(p[0]-q[0])+abs(p[1]-q[1]) for p,q in combinations(l,2)]))

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

int main()
{
	string s;
	string t;
	cin >> s >> t;
	int len = t.size();
	t.erase(len - 1, 1);
	if (s == t)
		cout << "Yes";
	else
		cout << "No";
	return (0);
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n,m;cin>>n>>m;
	vl a(n);
	rep(i,n)cin>>a[i];
	ll ans=0;
	rep(i,n-1){
		if(a[i]+a[i+1]>m){
            ans+=(a[i+1]+a[i])-m;
			a[i+1]-=(a[i+1]+a[i])-m;	
			if(a[i+1]<0){
				a[i]-=abs(a[i+1]);
				a[i+1]=0;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int32_t> x(N);
  vector<int32_t> y(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i];
  }

  int32_t maxv = 0;
  map<pair<int32_t, int32_t>, int> mpi;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (i == j) continue;
      pair<int32_t, int32_t> p = make_pair(x[j] - x[i], y[j] - y[i]);
      mpi[p] += 1;
      maxv = max(maxv, mpi[p]);
    }
  }

  cout << N - maxv << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

const int MAX = 500000, MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;

struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }
};

bool solve(int &len, rolling_hash &rh, int &n, string &s) {
    map<pair<LL,LL>,int> m;
    REP(i,0,n-len+1) {
        LL hash1 = rh.hash(i,i+len,0), hash2 = rh.hash(i,i+len,1);
        if (m.count(MP(hash1,hash2)) > 0) {
            if (m[MP(hash1,hash2)] + len <= i) return true;
            else continue;            
        }
        m.emplace(MP(hash1,hash2),i);
    }
    return false;
};

int meguru_bin(rolling_hash &rh, int &n, string &s) {
    int ng = n + 1;
    int ok = -1;

    while (abs(ok - ng) > 1) {
        int mid = ng + (ok - ng) / 2;
        if (solve(mid, rh, n, s)) ok = mid;
        else ng = mid;
    }

    return ok;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    rolling_hash rh(s);
    cout << meguru_bin(rh,n,s) << endl;
}

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

Measured memory_bytes: 768
#!/usr/bin/python
# -*- Coding: utf-8 -*-

x1, x2, x3, x4, x5 = (int(i) for i in input().split())

if x1 == 0:
    print("1")
elif x2 == 0:
    print("2")
elif x3 == 0:
    print("3")
elif x4 == 0:
    print("4")
else:
    print("5")

Measured memory_bytes: 9040
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define N 421
#define M 38300
int s[N][3],v[N][2],n,m,l[N][2],r[N][2],head[N],cur[N],cnt,in[N],vis[N];
char c[12];
long long dis[N],c1[N],as1,as;
struct edge{int t,next,v;long long c;}ed[M];
void adde(int f,int t,int v,long long c){ed[++cnt]=(edge){t,head[f],v,c};head[f]=cnt;ed[++cnt]=(edge){f,head[t],0,-c};head[t]=cnt;}
bool spfa(int s,int t)
{
	memset(dis,-0x3f,sizeof(dis));
	memcpy(cur,head,sizeof(cur));
	queue<int> tp;
	tp.push(s);dis[s]=0;in[s]=1;
	while(!tp.empty())
	{
		int r=tp.front();tp.pop();in[r]=0;
		for(int i=head[r];i;i=ed[i].next)
		if(ed[i].v&&dis[ed[i].t]<dis[r]+ed[i].c)
		{
			dis[ed[i].t]=dis[r]+ed[i].c;
			if(!in[ed[i].t])in[ed[i].t]=1,tp.push(ed[i].t);
		}
	}
	return dis[t]>-1e18;
}
int dfs(int u,int t,int f)
{
	if(!f||u==t)return f;
	vis[u]=1;
	int tp,as=0;
	for(int& i=cur[u];i;i=ed[i].next)
	if(!vis[ed[i].t]&&ed[i].v&&dis[ed[i].t]==dis[u]+ed[i].c&&(tp=dfs(ed[i].t,t,min(f,ed[i].v))))
	{
		ed[i].v-=tp;ed[i^1].v+=tp;
		f-=tp,as+=tp;as1+=ed[i].c*tp;
		if(!f){vis[u]=0;return as;}
	}
	vis[u]=0;return as;
}
int dinic(int s,int t){int tp=0;while(spfa(s,t))tp+=dfs(s,t,1e8);return tp;}
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d%lld",&v[i][0],&v[i][1],&c1[i]);
	scanf("%d",&m);for(int i=1;i<=m;i++){scanf("%s%d%d",c+1,&s[i][1],&s[i][2]);if(c[1]=='U')s[i][0]=0;if(c[1]=='D')s[i][0]=1;if(c[1]=='R')s[i][0]=2;if(c[1]=='L')s[i][0]=3;}
	for(int i=1;i<=n;i++)
	{
		cnt=1;for(int j=1;j<=402;j++)head[j]=0;
		for(int j=1;j<=i;j++)l[j][0]=1,l[j][1]=100,r[j][0]=1,r[j][1]=100;
		for(int j=1;j<=m;j++)if(i>s[j][2])
		{
			int tp=s[j][2];
			if(s[j][0]==1)
			{
				for(int k=1;k<=i-tp;k++)l[k][0]=max(l[k][0],s[j][1]+1);
			}
			if(s[j][0]==0)
			{
				for(int k=tp+1;k<=i;k++)l[k][1]=min(l[k][1],s[j][1]-1);
			}
			if(s[j][0]==3)
			{
				for(int k=1;k<=i-tp;k++)r[k][0]=max(r[k][0],s[j][1]+1);
			}
			if(s[j][0]==2)
			{
				for(int k=tp+1;k<=i;k++)r[k][1]=min(r[k][1],s[j][1]-1);
			}
		}
		int s1=401,t=402;
		for(int j=1;j<=i;j++)adde(s1,j,1,0);
		for(int j=1;j<=i;j++)
		for(int k=l[j][0];k<=l[j][1];k++)
		adde(j,k+100,1,0);
		for(int j=1;j<=n;j++)adde(v[j][1]+100,v[j][0]+200,1,c1[j]);
		for(int j=1;j<=i;j++)
		for(int k=r[j][0];k<=r[j][1];k++)
		adde(k+200,j+300,1,0);
		for(int j=1;j<=i;j++)adde(j+300,t,1,0);
		as1=0;int tp2=dinic(s1,t);
		if(tp2==i)as=max(as,as1);
	}
	printf("%lld\n",as);
}

Measured memory_bytes: 896
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 998244353
N, K = map(int, readline().split())
data = []
for _ in range(K):
    L,R = map(int, readline().split())
    data.append((L,R))
    
data = sorted(data)
A = [0]*(N+1)
A[1] = 1
S = [0]*(N+1)
S[1] = 1

for i in range(2,N+1):
    for k in range(K):
        L,R = data[k]
        A[i] += (S[max(0,i-L)]- S[max(0,i-R-1)]) % MOD
        A[i] %= MOD
    S[i] = (S[i-1] + A[i]) % MOD

print(A[N])

Measured memory_bytes: 24572
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

signed main() {
	double n;
	cin >> n;

	range(i, 1, 50000 + 1) {
		if (abs(floor(static_cast<double>(i) * 1.08) - n) < 1e-9) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}


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

int n,a[100];

int main()
{
  int res = 0;
  cin >> n;
  for (int i=1; i<=n; i++) cin >> a[i];
  for (int i=1; i<=n; i++)
    for (int j=i + 1; j<=n; j++) res += a[i] * a[j];
  cout << res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define int long long
using namespace std;
static const int MAX_N = 100000;
static const int inf  = 1ll<<60;
static const int MAX_SEG=1<<17;
typedef pair<int,int> pii;

int N,Q;
vector<int> g[MAX_N+5];
int root;
int depth[MAX_N+5];
int par[21][MAX_N];

void dfs(int v,int p,int d){
    par[0][v]=p;
    depth[v]=d;
    for(int u=0;u<g[v].size();++u){
        if(g[v][u]!=p)dfs(g[v][u],v,d+1);
    }
}

void fill_table(){
    dfs(root,-1,0);
    for(int i=0;i<20;i++){
        for(int j=0;j<N;j++){
            if(par[i][j]==-1)par[i+1][j]=-1;
            else par[i+1][j]=par[i][par[i][j]];
        }
    }
}

int LCA(int u,int v){
    if(depth[u]>depth[v])swap(u,v);
    for(int i=0;i<20;++i){
        if((depth[v]-depth[u])>>i&1)v=par[i][v];
    }
    if(v==u)return u;
    for(int i=20;i>=0;--i){
        if(par[i][u]!=par[i][v]){
            u=par[i][u];
            v=par[i][v];
        }
    }
    return par[0][u];
}

signed main(){
    cin>>N;
    for(int i=0;i<N;++i){
        int k;
        cin>>k;
        for(int j=0;j<k;++j){
            int c;
            cin>>c;
            g[i].PB(c);
        }
    }
    fill_table();
    cin>>Q;
    while(Q--){
        int u,v;
        cin>>u>>v;
        cout<<LCA(u,v)<<endl;
    }
}

Measured memory_bytes: 28532
def main():
    N, C, K = map(int, input().split())
    T = []
    for _ in range(N): T.append(int(input()))
    T.sort()

    dep = T[0]
    count = 1
    cap = 1
    i = 1
    while i < N:
        while i < N and cap < C and T[i] <= dep +K:
            cap += 1
            i += 1
        if i < N:
            dep = T[i]
            cap = 1
            count += 1
            i += 1
    return count

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 7384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main{
    public static void main(String[] args) throws IOException{
        InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

        String inputLines[] = { bufferedReader.readLine(),
                                bufferedReader.readLine() };

        int inputs[] = Arrays.stream(inputLines[0].split(" "))
                       .mapToInt(Integer::parseInt)
                       .toArray();
        int votes[]  = Arrays.stream(inputLines[1].split(" "))
                       .mapToInt(Integer::parseInt)
                       .toArray();

        int votesSum = Arrays.stream(votes).sum();
        int selectable = 0;
        for(int vote : votes){
            if(vote >= (double)votesSum / (double)(4 * inputs[1])){
                selectable++;
            }
        }

        if(inputs[1] <= selectable){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 200000, MAX_C = 200000;
const ll MOD = 1000000007;
int n;
int c[MAX_N];
ll dp[MAX_N];
int last[MAX_C+1];

int main()
{
#define FASTIO
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  fill_n(last,MAX_C+1,-1);

  cin >> n;
  forn (i,n) cin >> c[i];

  n = unique(c,c+n) - c;

  last[c[0]] = 0;
  dp[0] = 1;

  forn1 (i,n-1) {
    dp[i] = dp[i-1];
    if (last[c[i]] >= 0) {
      dp[i] = (dp[i] + dp[last[c[i]]]) % MOD;
    }
    last[c[i]] = i;
  }

  cout << dp[n-1] << "\n";

  return 0;
}


Measured memory_bytes: 3328
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int s,b;cin>>s>>b;
  if(s%2==0||b%2==0)cout<<"Even"<<endl;
  else cout<<"Odd"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    for (int i = (a < b ? a : b); i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            k--;

            if (k == 0) {
                cout << i << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int f[100111],ord[100111];
int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
int n,x[100111],y[100111];
vector<pair<int,pii> >es;
bool cmp1(int a,int b){return x[a]<x[b];}
bool cmp2(int a,int b){return y[a]<y[b];}
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)
	{
		get2(x[i],y[i]);
		f[i]=ord[i]=i;
	}
	sort(ord+1,ord+n+1,cmp1);
	for(int i=1;i<n;i++)es.pb(mp(x[ord[i+1]]-x[ord[i]],mp(ord[i],ord[i+1])));
	sort(ord+1,ord+n+1,cmp2);
	for(int i=1;i<n;i++)es.pb(mp(y[ord[i+1]]-y[ord[i]],mp(ord[i],ord[i+1])));
	sort(es.begin(),es.end());
	LL ans=0;
	for(int i=0;i<(int)es.size();i++)
	{
		int u=es[i].ss.ff,v=es[i].ss.ss;
		if(gf(u)==gf(v))continue;
		ans+=es[i].ff;
		f[gf(u)]=gf(v);
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 6516
#include <stdio.h>

int main(void)
{
	char s[100000];
	int i=0,cnt=0;
	scanf("%s",s);
	
	while(s[i] != '\0'){
		if(s[i] == '0' && s[i+1] == '0'){
			s[i+1] = '1';
			cnt++;
		}else if(s[i] == '1' && s[i+1] == '1'){
			s[i+1] = '0';
			cnt++;
		}
		i++;
	}
	printf("%d\n",cnt);
	
	return 0;
}


Measured memory_bytes: 256
def examA():
    R = I()
    if R<1200:
        ans = "ABC"
    elif R<2800:
        ans = "ARC"
    else:
        ans = "AGC"
    print(ans)
    return

def examB():
    S = SI(); N = len(S)
    ans = "AC"
    if not S[0]=="A":
        ans = "WA"
    flag = False
    for i in range(2,N-1):
        if S[i]=="C":
            flag = True
    if not flag:
        ans = "WA"
    num = 0
    for i in S:
        if ord("A")<=ord(i)<=ord('Z'):
            num +=1
    if not num==2:
        ans = "WA"
    print(ans)
    return

def examC():
    return

def examD():
    S = SI(); N = len(S)
    dp = [[0]*4 for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        C = S[i]
        if C=="?":
            dp[i+1][0] = dp[i][0]*3
            dp[i+1][1] = dp[i][1]*3 + dp[i][0]
            dp[i+1][2] = dp[i][2]*3 + dp[i][1]
            dp[i+1][3] = dp[i][3]*3 + dp[i][2]
        elif C=="A":
            dp[i+1][0] = dp[i][0]
            dp[i+1][1] = dp[i][1] + dp[i][0]
            dp[i+1][2] = dp[i][2]
            dp[i+1][3] = dp[i][3]
        elif C=="B":
            dp[i+1][0] = dp[i][0]
            dp[i+1][1] = dp[i][1]
            dp[i+1][2] = dp[i][2] + dp[i][1]
            dp[i+1][3] = dp[i][3]
        elif C=="C":
            dp[i+1][0] = dp[i][0]
            dp[i+1][1] = dp[i][1]
            dp[i+1][2] = dp[i][2]
            dp[i+1][3] = dp[i][3] + dp[i][2]
        for j in range(4):
            dp[i+1][j] %=mod
    ans = dp[-1][3]
    print(ans)
    return


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examD()


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

 
int main()
{
	long long i,k=0,n;
   string str;
   cin>>n;
   cin>>str;
   for(i=0;i<n;i++)
   {
   	if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C')k++;
   }
   cout<<k;
   
 return 0;
 
}

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

int main()
{ 
  int a, b, c, k ;
  cin >> a >> b >> c >> k ;
  vector<int> data = {a, b, c} ;
  sort(data.begin(), data.end()) ;
  reverse(data.begin(), data.end()) ;


  for(int i = 0 ; i < k ; i++)
  {
    data.at(0) *= 2 ;
  }

  cout << data.at(0) + data.at(1) + data.at(2) << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie(0);
cin.sync_with_stdio(0);
}
int main()
{
    int co=0;int n;cin>>n;int c=0;
   for(int i=105;i<=n;i+=2){
       c=0;
        for(int j=1;j<=i;j++){
            if(i%j==0)
                c++;
                if(c==8)
                    break;
        }
        if(c==8)
                co++;
   }
   cout<<co;
          return 0;
}


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0;
int N,X;
vi A;

void solve(){
    for(int i = 1; i < N; ++i){
        int diff = A[i] + A[i-1] - X;
        // cout << diff << endl;
        if(diff > 0){
            ans += diff;
            int tmp = diff - A[i];
            A[i] -= min(diff, A[i]);
            A[i-1] -= max(tmp, 0);
        }
    }

    cout << ans << endl;
}

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

    rep(i, N) cin >> A[i];

    solve();
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>

#include <complex>
//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin, (v).end);


typedef unsigned long long int ull;
typedef long long lint;

using namespace std;














int main(){
    int N;
    string S;


    //入力
    cin >> N;
    cin >> S;
    
    if(N%2==1) {
        cout << "No" << endl;
        return 0;
    }

    for(int i=0; i<N/2; i++) {
        if(S[i] != S[i+N/2]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

long long int gcd(long long int a, long long int b){
  long long int t;
  while( b ) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

long long int powi(int a, long long int b) {
  return !b ? 1 : powi(a, b - 1) * a;
}

int main(void) {
  long long int i, j, ansi;
  char num[1000], temp[1000];
  scanf("%s",num);
  for(i = 0; num[i] != '.'; ++i) {
    temp[i] = num[i];
  }
  temp[i] = '\0';
  ansi = atoll(temp);
  if(strchr(num, (int)'(') == NULL) {
    long long int ansn;
    char tem[1000];
    for(j = i + 1; j < strlen(num); ++j) {
      tem[j - i - 1] = num[j];
    }
    tem[j] = '\0';
    ansn = atoll(tem);
    long long int ansu, ansa;
    ansu = powi(10, j - i - 1);
    ansa = ansn;
    long long int oo = gcd(ansu, ansa);
    ansu /= oo;
    ansa /= oo;
    ansa += ansu * ansi;
    printf("%lld/%lld\n",ansa, ansu);
  } else {
    long long int ansn, ansd;
    char tem[1000];
    for(j = i + 1; num[j] != '('; ++j) {
      tem[j - i - 1] = num[j];
    }
    ansn = atoll(tem);
    long long int ansu, ansa;
    ansu = powi(10, j - i - 1);
    ansa = ansn + ansi * ansu;
    for(i = j + 1; i < strlen(num) - 1; ++i) {
      tem[i - j - 1] = num[i];
    }
    tem[i - j - 1] = '\0';
    ansd = atoll(tem);
    long long tnuma, tnumu;
    tnumu = ansu * (powi(10, i - j - 1) - 1);
    tnuma = ansd;
    ansa = ansa * (powi(10, i - j - 1) - 1) + tnuma;
    ansu = tnumu;
    long long oo = gcd(ansa, ansu);
    ansa /= oo;
    ansu /= oo;
    printf("%lld/%lld\n",ansa, ansu);
  }
  return 0;
}


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

int main(){
   int x,y;
   cin >> x >> y;
   while(!(x==0 && y==0)){
      if(x>y){
         cout << y << " " << x << "\n";
      }
      else{
         cout << x << " " << y << "\n";
      }
      cin >> x >> y;
   }

   return 0;
}



Measured memory_bytes: 3056
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  pair<pair<string,int>,int> p[100];
  int N;
  cin>>N;

  for(int i=0;i<N;i++){
    cin>>p[i].first.first>>p[i].first.second;
    p[i].first.second*=-1;
    p[i].second=i+1;
  }

  sort(p,p+N);
  for(int i=0;i<N;i++){
    cout<<p[i].second<<endl;
  }
}


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

namespace Range
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = int.Parse(str[2]);

            if (a < b && b < c)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 8888
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    ll A,B;
    cin >> A >> B;
    ll ans = A*B/__gcd(A,B);
    cout <<ans<< "\n";
}

Measured memory_bytes: 256
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

n,x,m = (int(x) for x in input().split())
lst = []
ans = 0
cnt = 0
i = 0
visited = [-1 for _ in xrange(m)]
stop_c = False
while i < n:
    if i == 0:
        ret = pow(x,1,m)
    else:
        ret = pow(x,2,m)
    x = ret
    if visited[ret] == -1:
        visited[ret] = i
    else:
        stop_c = True
        # i += 1
        break
    ans += ret
    lst.append(ret)
    i += 1

if stop_c:
    cycle_len = len(lst[visited[ret]:])
    cycle_sum = sum(lst[visited[ret]:])
    remsum  = sum(lst[visited[ret]:][:(n-visited[ret]) % cycle_len])
    print((ans -cycle_sum) + (cycle_sum * ((n-visited[ret]) // cycle_len)) + remsum)
else:
    print(ans)

Measured memory_bytes: 85788
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; 
int main()
{
	string str;string b;
	cin>>str;
	for(int i=0;i<str.size();i++)
	{
		if(str[i]=='0')
		{
			b=b+"0";
//			cout<<b<<endl;
		}
		else if(str[i]=='1')
		{
			b=b+"1";
//			cout<<b<<endl;
		}
		else 
		{
			if(b.size()==0)
			{
//				cout<<b<<endl;
				continue;
			
			}
			else
			{
				b=b.substr(0,b.size()-1);
//			cout<<b<<endl;
			}
		}
	}
	cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

modint dp[3005][3005];

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    dp[A][B] = 1;
    for(int i = A; i <= C; ++i){
        for(int j = B; j <= D; ++j){
            dp[i][j + 1] += dp[i][j] * i;
            dp[i + 1][j] += dp[i][j] * j;
            dp[i + 1][j + 1] -= dp[i][j] * i * j;
        }
    }
    cout << dp[C][D] << endl;
}

Measured memory_bytes: 38912
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
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;
}

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// v ector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(w + 1, vector<int>(k+1, 0)));

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    ll d;
    cin >> s >> d;
    ll n = s.size();
    vvvl dp(n+1,vvl(d+1,vl(2,0)));
    //0:s以下であることが確定。1:sより大きいことが未確定
    dp[0][0][0] = 1;
    rep(i,n) {
        rep(j,d) {
            rep(k,2) {
                rep(l,10) {
                    ll ns = s[i]-'0';
                    ll nk = k;
                    if (ns < l && !k) continue;
                    if (ns > l) nk = 1;
                    dp[i+1][(j+l)%d][nk] += dp[i][j][k];
                    dp[i+1][(j+l)%d][nk] %= MOD;
                }
            }

        }
    }
    print((dp[n][0][0]+dp[n][0][1]+MOD-1)%MOD);

    return 0;
}


Measured memory_bytes: 58996
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

const int MAX = 13;
int n;
string cmd;
string s;
set<string> S;

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> cmd >> s;
        if (cmd == "insert") {
            S.insert(s);
        } else {
            if (S.count(s)) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 29780
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    string s;
    cin >> s;

    string t = s;
    reverse(t.begin(), t.end());
    int is = 0;
    int it = 0;
    int ans = 0;
    while(is < (int)s.length() || it < (int)t.length()){
        if(s[is] == t[it]){
            is++;
            it++;
            continue;
        }
        if(s[is] == 'x'){
            is++;
            ans++;
            continue;
        }
        if(t[it] == 'x'){
            it++;
            ans++;
            continue;
        }
        cout << -1 << endl;
        return 0;
    }
    cout << ans / 2 << endl;

    return 0;
}


Measured memory_bytes: 512
from collections import defaultdict
import heapq

N, M = map(int, input().split())
daily_jobs = defaultdict(list)

for _ in range(N):
    A, B = input().split()
    daily_jobs[A].append(-int(B))

ans = 0
now_cand = []
for i in range(1, M+1):
    for job in daily_jobs[str(i)]:
        heapq.heappush(now_cand, job)
    if now_cand:
        ans += heapq.heappop(now_cand)

print(-ans)


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

int main(){
    int N,M,count=0,tmp_x,tmp_y,red_ball=1;
    cin>>N>>M;
    int x[N+1]={};
    bool f[N+1]={};
    for(int k=1;k<=N;k++){
        x[k]=1;
        f[k]=false;
    }
    f[1]=true;
    for(int i=0;i<M;i++){
        cin>>tmp_x>>tmp_y;
        if(tmp_x==red_ball||f[tmp_x]==true){
            f[tmp_y]=true;
            red_ball = tmp_y;
        }
        x[tmp_x]--;x[tmp_y]++;
        if(x[tmp_x]==0){
            f[tmp_x]=false;
        }
    }
    for(int j=1;j<=N;j++){
        if(f[j]==true&&x[j]>0){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

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

    long long int n;
    cin >> n;
    cout << n * (n - 1) / 2 << endl;

    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i = 0; i < h; ++i)
  {
    cin >> s[i];
  }

  vector< vector<int> > ans(h, vector<int>(w, 0));
  for(int j = 0; j < h; ++j)
  {
    for(int i = 0; i < w; ++i)
    {
      if (s[j][i] == '#')
      {
        ans[j][i] = -1;
        for(int y = -1; y <= 1; ++y)
        for(int x = -1; x <= 1; ++x)
        {
          if (j + y < 0 || h <= j + y) continue;
          if (i + x < 0 || w <= i + x) continue;
          if (s[j + y][i + x] == '#') continue;
          ans[j + y][i + x]++;
        }
      }
    }
  }


  for(int j = 0; j < h; ++j)
  {
    for(int i = 0; i < w; ++i)
    {
      if (ans[j][i] == -1) cout << '#';
      else cout << ans[j][i];
    }
    cout << endl;
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3616
#define _GLIBCXX_DEBUG
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

typedef long long ll;

const ll val10 = std::pow(2, 10);

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;

  std::vector< ll > va(n, 0);
  std::vector< ll >::iterator it;

  for (int i = 0; i < n; i++) {
    std::cin >> va[i];
  }

  ll ans = 0;
  for (it = va.begin(); it != va.end(); it++) {
    ll cnt = 0;
    ll x = *it;
    while (x % val10 == 0) {
      cnt += 10;
      x = x / val10;
    }
    while (x % 2 == 0) {
      cnt ++;
      x = x / 2;
    }
    ans += cnt;
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 384
N = gets.to_i
arr = gets.split(" ").map{ |v|
	v.to_i
}

arr.sort!.reverse!

e1 = -1
for i in 0..arr.length-1 do
	if arr[i] == arr[i+1] then
		e1 = arr[i]
		arr.delete_at(i)
		arr.delete_at(i)
		break
	end
end

if e1 < 0 then
	puts 0
	exit
end

e2 = -1
for i in 0..arr.length-1 do
	if arr[i] == arr[i+1] then
		e2 = arr[i]
		arr.delete_at(i)
		arr.delete_at(i)
		break
	end
end

if e2 < 0 then
	puts 0
	exit
end

puts e1 * e2


Measured memory_bytes: 9232
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
  int n,k,res=0; cin>>n>>k; a[0] = 0;
  for(int i=1; i < n+1; ++i) cin>>a[i], ++a[i];
  for(int i=1; i<=n; ++i) a[i] += a[i-1];
  for(int i=k; i<=n; ++i) {
  	if(res < a[i]-a[i-k]) res = a[i]-a[i-k]; 
  }
  printf("%.10lf\n", 0.5*res);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> qua;
typedef vector<qua> vec;
const double epx=1e-7;
namespace std
{
    bool operator < (const qua &a,const qua &b)
    {
        return (a.imag()==b.imag()?a.real()<b.real():a.imag()<b.imag());
    }
}
int ccw(qua a,qua b,qua c)
{
    b-=a,c-=a,a=c*conj(b);
    if(a.imag()>epx) return 1;
    if(a.imag()<-epx) return -1;
    if(a.real()<-epx) return 2;
    if(abs(b)+epx<abs(c)) return -2;
    return 0;
}
vec judge_convex(vec &v)
{
    int n=v.size(),c=0;
    vec r(n);
    for(int i=0; i<n; i++)
    {
        while(2<=c&&ccw(r[c-2],r[c-1],v[i])==-1) c--;
        r[c++] = v[i];
    }
    vec res(c);
    for(int i=0; i<c; i++) res[i]=r[i];
    return res;
}
vec calc_convex(vec &v)
{
    sort(v.begin(),v.end());
    vec u=judge_convex(v);
    reverse(v.begin(),v.end());
    vec l=judge_convex(v);
    for(int i=1; i+1<l.size(); i++) u.push_back(l[i]);
    return u;
}
int main()
{
    int n;
    double x,y;
    vec v;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%lf%lf",&x,&y);
        v.push_back(qua(x,y));
    }
    vec ans=calc_convex(v);
    printf("%d\n",ans.size());
    for(int i=0;i<ans.size();i++)
    {
        printf("%d %d\n",(int)ans[i].real(),(int)ans[i].imag());
    }
    return 0;
}



Measured memory_bytes: 7752
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	template<typename U>
	int lis(vector<U> a, bool broad = true) {//broad=true:広義、false:狭義
		int rtn = 0;
		vector<int> lis;
		lis.push_back(a[0]);
		FOR(i, 1, a.size()) {
			if (broad) {
				if (lis.back() <= a[i]) {
					lis.push_back(a[i]);
				} else {
					auto itr = upper_bound(all(lis), a[i]) - lis.begin();
					lis[itr] = a[i];
				}
			} else {
				if (lis.back() < a[i]) {
					lis.push_back(a[i]);
				} else {
					auto itr = lower_bound(all(lis), a[i]) - lis.begin();
					lis[itr] = a[i];
				}
			}

		}
		rtn = lis.size();//LISの長さ
		return rtn;
	}

	void solve() {
		IOS;
		int n;
		cin >> n;
		vector<int> a(n);
		REP(i, n) {
			cin >> a[i];
		}
		reverse(all(a));
		auto l = lis(a);
		put(l);
	}

} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


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

  ll a, b, c;
  cin >> a >> b >> c;

  ll res = 3;
  if (a==b) res--;
  if (a==c) res--;
  if (b==c) res--;
  if (a==b && b==c) res++;

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n)
	ss := make([]string, n)
	for i := range ss {
		fmt.Scan(&ss[i])
	}
	fmt.Scan(&m)
	ts := make([]string, m)
	for i := range ts {
		fmt.Scan(&ts[i])
	}

	earns := make(map[string]int)
	for _, s := range ss {
		earns[s]++
	}
	for _, t := range ts {
		earns[t]--
	}

	max_earn := 0
	for _, v := range earns {
		if v > max_earn {
			max_earn = v
		}
	}
	fmt.Println(max_earn)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <utility>
using namespace std;
typedef long long int ll; // int -> ll


int main(){
    string s;
    int k;
    cin >> k;
    cin >>s;
    if(s.size() <= k) {
        cout << s << endl;
    }
    else {
        cout << s.substr(0,k) << "..." << endl;
     }
     return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    int p[50],q[50];
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
        q[i]=p[i];
    }
    sort(q,q+n);
    int cnt=0;
    for (int i = 0; i < n; i++) {
        if(q[i]!=p[i]){
            cnt++;
        }
    }
    if(cnt<=2){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
}


Measured memory_bytes: 256
num = int(input())

Office1 = [[0 for i in range(10)] for j in range(3)]
Office2 = [[0 for i in range(10)] for j in range(3)]
Office3 = [[0 for i in range(10)] for j in range(3)]
Office4 = [[0 for i in range(10)] for j in range(3)]

def printfunc(Office):
    for i in range(3):
        for j in range(10):
            print(" ",Office[i][j],sep="",end="")
        print()

for i in range(num):
    s = input().split()
    b=int(s[0])
    f=int(s[1])
    r=int(s[2])
    v=int(s[3])

    if b==1:
        Office1[f-1][r-1]+=v
    if b==2:
        Office2[f-1][r-1]+=v
    if b==3:
        Office3[f-1][r-1]+=v
    if b==4:
        Office4[f-1][r-1]+=v
    
str = "#" * 20
printfunc(Office1)
print(str)
printfunc(Office2)
print(str)
printfunc(Office3)
print(str)
printfunc(Office4)



Measured memory_bytes: 5644
nk = input().split()
n = int(nk[0])
k = int(nk[1])
li = input().split()

for i in range(n):
	li[i] = int(li[i])

li = sorted(li, reverse = True)

ans = 0
for i in range(k):
	ans += li[i]

print(ans)

Measured memory_bytes: 3064