akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define ITR(i,x) for(auto i=(x).begin();i!=(x).end();++i)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const ll mod = 1000000007;

ll mpow(ll x, ll n){ //x^n(mod) ←普通にpow(x,n)では溢れてしまうため，随時mod計算 2分累乗法だから早い
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
ll inv_mod(ll a){return mpow(a,mod-2);}
template<ll mod> class modll {
 private:
  ll _num;
  modll set(ll num){ _num = num % mod; return *this; }
 public:
  modll(){ _num = 0; }
  modll(ll num){ _num = num % mod; }

  modll operator= (ll x){ return set(x % mod); }
  modll operator+ (ll x){ return modll<mod>(_num + (x % mod)); }
  modll operator- (ll x){ return modll<mod>(_num - (x % mod)); }
  modll operator* (ll x){ return modll<mod>(_num * (x % mod)); }
  modll operator+=(ll x){ return set(_num + (x % mod)); }
  modll operator-=(ll x){ return set(_num - (x % mod)); }
  modll operator*=(ll x){ return set(_num * (x % mod)); }

  explicit operator ll() { return _num; }
  friend ostream& operator<<(ostream &os, const modll<mod> &x){ os << x._num; return os; }
};
class UnionFind{//UnionFind木
 private:
    vector<int> Parent;
 public:
    UnionFind(int N){
        for(int i=0;i<N;i++) Parent.push_back(-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};
bool square(ll a){ll n=(ll)sqrt(a);return a==n*n;}
int digitsum(ll N,int a){
    if(N==0) return 0;
    int ret=0;
    ret+=digitsum(N/a,a)+N%a;
    return ret;
}
int gcd(int x,int y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数
int lcm(int x,int y){return x*y/gcd(x,y);}//xとyの最小公倍数

class Factorial{//階乗とその逆元を求めて計算に利用するクラス
 private:
    vector<ll> fac;
 public:
    
    Factorial(ll N){
        fac.push_back(1);
        for(int i=0;i<N;i++) fac.push_back(fac[i]*(i+1)%mod);
    }

    ll fact(ll a){return fac[a];}
    ll ifact(ll a){return inv_mod(fac[a]);}

    ll cmb(ll a,ll b){
        if(a==0&&b==0) return 1;
        if(a<b||a<0) return 0;
        ll tmp =ifact(a-b)*ifact(b)%mod;
        return tmp*fac[a]%mod;
    }
};

int main(){
    int X,A;
    cin>>X>>A;
    if(X<A) cout<<0<<endl;
    else cout<<10<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 700;


int main()
{
    string tmp;
    cin >> tmp;
    int c = 0;

    for(int i = tmp.size() - 1; i >= 0; i--)
    {
        if(tmp.substr(tmp.size() - 8) == "FESTIVAL")
        {
            cout << tmp.substr(0, tmp.size() - 8) << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
vector<int> ans;
vector<int> G[1001];
int main(){
  int n,m; cin >> n >> m;
  rep(i,m){
    int a,b; cin >> a >> b;
    G[a].pb(b);
  }
  rep(i,n){
    int s = i + 1;
    bool used[1001] = {};
    vt<int> ss; ss.pb(s);
    queue<vector<int>> q; q.push(ss);
    while(!q.empty()){
      auto now = q.front(); q.pop();
      if(now.size() >= 2 && *now.rbegin() == s){
        if(ans.size() == 0 || ans.size() > now.size()) ans = now;
        break;
      }
      auto n = *now.rbegin();
      for(auto nn : G[n]){
        if(used[nn] == 0){
          now.pb(nn); q.push(now); now.pop_back();used[nn]=1;
        }
      }
    }
  }
  if(ans.size() == 0)  cout << -1 << endl;
  else{
    cout << ans.size() - 1 << endl;
    rep(i,ans.size()-1)  cout << ans[i] << endl;
  }
}


Measured memory_bytes: 384
#include <cstdio>
#include <cmath>

using namespace std;

int a[19][19];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", a[i] + j);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int x = 0;
      for (int k = 0; k < m; ++k) {
        x += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
      }
      int y = (int)sqrt(x);
      while (y * y < x) {
        ++y;
      }
      while (y * y > x) {
        --y;
      }
      if (y * y == x) {
        ++ans;
      }
    }
  }
  printf("%d\n", ans);
}


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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define INF INT_MAX
#define NINF INT_MIN
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "\n";
    err(++it, args...);
}

const int MAX_N = 400 + 5;
int N, a[MAX_N];
ll pa[MAX_N], dp[MAX_N][MAX_N];

ll calc(int i, int j) {

	if(i == j)
		return 0ll;

	if(dp[i][j])
		return dp[i][j];

	ll res = 1e18;

	tik(k,i,j) {
		res = min(res,pa[j]-pa[i-1]+calc(i,k)+calc(k+1,j));
	}

	return dp[i][j] = res;
}

int main() {

	fast();

	cin >> N;

	tik(i,1,N+1) {
		cin >> a[i];
		pa[i] = a[i] + pa[i-1];
	}

	cout << calc(1,N);
}

Measured memory_bytes: 1536
s = input()
n = len(s)
gamedict = dict()
gamedict['p'] = 1
gamedict['g'] = 0
score = 0
for i in range(n):
    if i%2 == 0:
        mymove = 0
    else:
        mymove = 1
    score = score + (mymove - gamedict[s[i]])
print(score)

Measured memory_bytes: 3316
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if(Character.isUpperCase(c)) {
                c = Character.toLowerCase(c);
            } else {
                c = Character.toUpperCase(c);
            }
            sb.append(c);
        }
        System.out.println(sb.toString());
        
    }
}



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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<ll> H(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  
  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());
  
  ll count = 0;
  
  if (N <= K) {
    cout << 0;
  } else {
    for (int i = K; i < N; i++) count += H.at(i);
    cout << count;
  }
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int[] A = new int[5];
        for(int i=0;i<5;i++){
            A[i]=sc.nextInt();
            if(A[i]==0){
                System.out.println((i+1));
            }
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 35784
#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() {
    int k;
    string s;
    cin >> k >> s;
    int n = s.size();
    if(n <= k) {
        cout << s << endl;
    } else {
        string a = s.substr(0,k);
        cout << a << "..." << endl;
    }
    return 0;
}

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

int main() {
  vector<int> a(3); for (int i = 0; i < 3; ++i) cin >> a[i];
  int ans = 0;
  sort(begin(a), end(a));
  int d1 = a[2] - a[1];
  ans += d1;
  a[0] += d1;
  a[1] += d1;
  int d2 = a[2] - a[0];
  ans += d2 / 2;
  if (d2 % 2) ans += 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// Problem : D - Semi Common Multiple
// Contest : AtCoder - AtCoder Beginner Contest 150
// URL : https://atcoder.jp/contests/abc150/tasks/abc150_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mod (int)1e9+7
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repf(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define N 100005
int main()
{
	FAST
    int t=1;
    // cin>>t;
    while(t--)
    {
		int k,x;
		cin>>k>>x;
		if(k* 500 >=x) cout<<"Yes"; else cout<<"No";
    }
    return 0;
} 


Measured memory_bytes: 3612
#include <iostream>
#include <string>

int main()
{
	int a, b;
	std::cin >> a >> b;

	int n[] = { a, b, a + b };
	std::string ans = "Impossible";
	for( int i = 0; i < 3; i++ ) {
		if( n[ i ] % 3 == 0 ) {
			ans = "Possible";
			break;
		}
	}

	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll n; cin >> n;
	vector<ll> a(n);
	rep(i,0,n) cin >> a[i];

	// 高速素因数分解
	vector<ll> spf(1000010,0);
	rep(i,0,spf.size()) spf[i] = i;
	for(ll i = 2; i * i < (ll)spf.size(); i++){
		if(spf[i] != i) continue;
		for(ll j = i * i; j < (ll)spf.size(); j += i){
			if(spf[j] == j) spf[j] = i;
		}
	}
	// rep(i,0,30) cout << spf[i] << endl;
	
	bool pairwise = true;
	// 前のと違うのにかぶってたらだめ
	vector<ll> div(1000010,-1);
	rep(i,0,n){
		ll dv = a[i];
		ll prev = 0;
		while(dv != 1){
			if(div[spf[dv]] != -1 && prev != spf[dv]){
				pairwise = false;
				break;
			}
			prev = spf[dv];
			div[spf[dv]] = 1;
			dv /= spf[dv];
		}
		if(!pairwise) break;
	}
	// 判定
	bool not_coprime = false;
	ll gcd = a[0];
	rep(i,0,n){
		gcd = __gcd(a[i], gcd);
	}
	if(gcd > 1){
		not_coprime = true;
	}

	if(not_coprime == true){
		cout << "not coprime" << endl;
	}else if(pairwise){
		cout << "pairwise coprime" << endl;
	}else{
		cout << "setwise coprime" << endl;
	}


}

Measured memory_bytes: 26736
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 998244353LL;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 3656
// 動的計画法
// knapsack

#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int n_max = 1e5 + 5;

int n,m,value;
int x[n_max], y[n_max];
vector<int> v[n_max];
vector<int> s[n_max];
bool h[n_max];
int dp[n_max];
int temp, result;

int depth(int i) {
  if(dp[i] != -1) return dp[i];
  for (int j=0; j<v[i].size(); j++) {
    temp = v[i][j];
    dp[i] = max(dp[i], depth(temp) + 1);
  }
  dp[i] = max(dp[i], 0);
  return dp[i];
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  rep(i,m) {
    cin >> x[i] >> y[i];
    s[x[i]].push_back(y[i]);
    v[x[i]].push_back(y[i]);
    h[y[i]] = true;
  }
  rep(i,n+1) dp[i] = -1;
  rep(i,n) {
    // cout << s[i+1].size() << endl;
    if(!h[i+1]) {
      depth(i+1);
    }
  }
  rep(i,n) {
    //cout << dp[i+1] << endl;
    result = max(result, dp[i+1]);
  }
  cout << result << endl;
}


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

int main(){
	const int I=99999999;
	int n,c,m;
	int p[2][5000+2][2];
	for(int i=0;i<2;i++)for(int j=0;j<5002;j++){p[i][j][0]=I; p[i][j][1]=I;}
	p[1][1][0]=0;
	p[1][0][1]=0;
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		int s=i%2,t=1-s;
		scanf("%d",&c);
		m=min(i,n/2);
		for(int j=0;j<=m;j++){
			if(j!=0)p[s][j][0]=min(p[t][j-1][0],p[t][j-1][1]+c);
			p[s][j][1]=min(p[t][j][0]+c,p[t][j][1]);
		}
	}
	printf("%d\n",min(p[0][m][0],p[0][m][1]));
}

Measured memory_bytes: 1264
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Seven Segments
 */
public class Main {

	static int[] N = new int[10];

	static {
		N[0] = Integer.valueOf("0111111", 2);
		N[1] = Integer.valueOf("0000110", 2);
		N[2] = Integer.valueOf("1011011", 2);
		N[3] = Integer.valueOf("1001111", 2);
		N[4] = Integer.valueOf("1100110", 2);
		N[5] = Integer.valueOf("1101101", 2);
		N[6] = Integer.valueOf("1111101", 2);
		N[7] = Integer.valueOf("0100111", 2);
		N[8] = Integer.valueOf("1111111", 2);
		N[9] = Integer.valueOf("1101111", 2);
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == -1) break;

			int c = 0;
			for (int i = 0; i < n; i++) {
				int d = parseInt(br.readLine());
				System.out.println(Integer.toBinaryString(((1 << 7) + c) ^ N[d]).substring(1));
				c = N[d];
			}
		}

	}
}

Measured memory_bytes: 24196
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
#define pr(x) cout << x << endl;
using namespace std;

//const int mod = 998244353;
const int mod=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// 出力は.xで！！！！

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll mpow(ll a, ll b){
  ll ans=1;
  rep(i,b){
    ans*=a;
    ans%=mod;
  }
  return ans;
}

int main(){
  int n; cin >> n;
  mint ans=mpow(10,n)-(mpow(9,n)+mpow(9,n)-mpow(8,n));
  cout << ans.x << endl;

return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int mod=1e9+7;
const int maxn=400;

int C[maxn][maxn],jc[maxn],jcn[maxn],inv[maxn];

int n,k;
char str[maxn];

int len;
int rk[maxn],tp;

inline void init()
{
	C[0][0]=1; REP(i,1,300)REP(j,0,i)C[i][j]=(C[i-1][j]+(j?C[i-1][j-1]:0))%mod;
	jc[0]=jc[1]=jcn[0]=jcn[1]=inv[1]=1;
	REP(i,2,300)jc[i]=(ll)i*jc[i-1]%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)jcn[i-1]*inv[i]%mod;
	n=read();k=read(); len=n+1>>1;
	scanf("%s",str+1);
	REP(i,1,k)if(str[i]=='r')rk[++tp]=i;
}

int p[maxn];
int tot;
int wp[maxn],B[maxn];

inline bool check()
{
	static int vis[maxn],RK[maxn];
	memset(vis,0,sizeof(int)*(k+1));

	int now=0,num=0;
	DREP(i,tot,0)num+=p[i];
	if(num>tp)return 0;
	REP(i,1,num)vis[rk[i]]=1;

	int it=1;
	DREP(i,tot,0)
	{
		REP(j,1,p[i])
		{
			int x=rk[++now];
			if(i>=1)
			{
				while(it<=k && (it<=x || vis[it] || str[it]=='r'))++it;
				if(it>k)return 0;
				RK[now]=it;
				vis[it]=1;
			}else RK[now]=x;
		}
	}

	now=0;
	it=1;
	DREP(i,tot,0)
	{
		int NUM=p[i];
		while(NUM--)
		{
			int x=RK[++now];
			int tim=i-1;
			if(i>=2)
			{
				while(tim--)
				{
					while(it<=k && (it<=x || vis[it] ))++it;
					if(it>k)return 0;
					vis[it]=1;
				}
			}
		}
	}
	return 1;
}

int ans;

void dfs(int u,int num,int s,int wz,int N,int pro)
{
	if(u==-1)
	{
		pro=(ll)pro*jc[num]%mod;
		wz++; N+=2;
		//DREP(i,len,0)pro=(ll)pro*jcn[p[i]]%mod;
		ans=(ans+(ll)pro*C[N-1][wz-1])%mod;
		return;
	}
	//int ad=u%4==0?2:u%4==1?0:1;
	REP(j,0,(n-s+1)/(wp[u]+1))
	{
		p[u]=j;
		if(num+j<=tp && check())
			dfs(u-1,num+j,s+j*wp[u]+j,wz+wp[u]*j+j+(u>0?2*j:0),N+(u>0?2*j:0),(ll)pro*jcn[j]%mod);
		p[u]=0;
	}
}

inline void doing()
{
	wp[0]=1;
	REP(i,1,len)
	{
		wp[++tot]=i*2-1; B[tot]=i;
	}
	dfs(tot,0,0,0,n,1);
	printf("%d\n",ans);
}

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


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

using namespace std;

using ll = long long;

int main () {
    ll min_sum = LONG_LONG_MAX;
    ll max_sum = LONG_LONG_MIN;
    ll min_dif = LONG_LONG_MAX;
    ll max_dif = LONG_LONG_MIN;
    ll N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        if ((x + y) < min_sum) min_sum = x + y;
        if ((x + y) > max_sum) max_sum = x + y;
        if ((x - y) < min_dif) min_dif = x - y;
        if ((x - y) > max_dif) max_dif = x - y;
    }
    cout << max(max_sum - min_sum, max_dif - min_dif) << endl;
}

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

using namespace std;

int main(){
	int N, ans; cin >> N;
	int a[N];
	for(int i = 0; i < N; ++i){
		cin >> a[i];
	}
	ans = *max_element(a, a + N) - *min_element(a, a + N);
	cout << ans << endl;
}

Measured memory_bytes: 256
program bproblem
implicit none
integer R, G, B, N, count
integer i, j
read(*, *) R, G, B, N
count = 0
do i = 0, N/R+1
    do j = 0, N/G+1
        if (R*i + G*j <= N) then
            if (mod((N-R*i-G*j), B) == 0) then
                count = count + 1
            end if
        end if
    end do
end do
write(*, *) count
stop
end program bproblem

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fastio        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll            long long
#define fl            long double
#define pll           pair<ll,ll>
#define onebits(x)    __builtin_popcountll(x)
#define fbo(x)        find_by_order(x)
#define ook(x)        order_of_key(x)
#define pb            push_back
#define mk            make_pair
#define endl          "\n"
#define ff            first
#define ss            second
#define mt            make_tuple
#define np            next_permutation
#define pi            3.141592653589793238
#define deb(x)        cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define vll           vector<ll>
#define vp            vector<pair<ll,ll>>
#define all(x)        x.begin(),x.end()
#define rall(x)       x.rbegin(),x.rend()
#define revpq         priority_queue <int, vector<int>, greater<int>>
#define pq            priority_queue<ll>
#define ps(x,y)       fixed<<setprecision(y)<<x
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const ll MAXN = 200005;
ll power(ll a, ll b) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod % mod; a = a * a % mod;} return res;}

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main()
{
    fastio;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll i, j, t, k, l, r, tp, n, m;
    cin >> n;
    ll a[n];
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll ans = 0;
    ll mx = a[0];
    for (i = 1; i < n; i++)
    {
        if (a[i] < mx)
        {
            ans += mx - a[i];
        }
        else
        {
            mx = a[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>


int main ()
{
  std::stack<int> st;
  std::stack<std::pair<int, int> > each;
  int total_area = 0;

  char slope;
  int cur_pos=0, this_area=0;
  while (std::cin >> slope)
    {
      if (slope == '\\')
        {
          st.push(cur_pos);
        }
      else if (slope == '/' && !st.empty())
        {
          auto closest = st.top();
          st.pop();

          this_area = cur_pos - closest;
          total_area += this_area;

          while (!each.empty() && each.top().first > closest)
            {
              this_area += each.top().second;
              each.pop();
            }

          each.push(std::make_pair(closest, this_area));
        }
      cur_pos++;
    }

  std::cout << total_area << std::endl;
  auto k = each.size();


  std::stack<int> tmp_stack;
  for (int i=0; i<k; i++)
    {
      tmp_stack.push(each.top().second);
      each.pop();
    }

  std::cout << k;
  for (int i=0; i<k; i++)
    {
      std::cout << " " << tmp_stack.top();
      tmp_stack.pop();
    }
  std::cout << std::endl;
}



Measured memory_bytes: 3164
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        String result = "Yes";

        while (true) {
            c = c - b;
            if (c <= 0) {
                break;
            }

            a = a - d;
            if (a <= 0) {
                result = "No";
                break;
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 27080
/*
Owner: dxxrk
Problem: Multiple Array
Date: 22/11/2019
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
 	long long n; cin >> n;
 	
 	vector<long long> a(n), b(n);
 	
 	for(long long i = 0; i < n; i++){
 		cin >> a[i] >> b[i];	
	}
	
	long long ans = 0, p = 0;
	
	for(long long i = n - 1; i >= 0; i--){
		a[i] += p;
		if(a[i] % b[i] == 0){
			continue;
		}	
		else {
			ans += ((((a[i] / b[i]) + 1) * b[i]) - a[i]);
			p += ((((a[i] / b[i]) + 1) * b[i]) - a[i]);
		}
	}
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

//constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/


int main() {
	int n; cin >> n;
	ll a[100005];

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

	sort(a, a + n);

	ll sum = 0;
	int check = 0;
	for (int i = 0; i < n - 1; i++) {
		sum += a[i];
		if (2 * sum < a[i + 1]) { check = i + 1; }
	}


	cout << n - check;


	return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

using Graph = vector<vector<int>>;
Graph G;

vector<int> a, b;
int deg = 0;

using P = pair<int, int>;
map<P, int> m;

void dfs(int v, int p, int c){
    int nec = 1;
    for(auto nv: G[v]){
        if(nv == p) continue;
        if(nec == c) nec++;
        m[P{v, nv}] = nec;
        dfs(nv, v, nec);
        nec++;
    }
}



int main(){
    int n;
    cin >> n;
    G.assign(n+1, vector<int>());
    a.resize(n-1);
    b.resize(n-1);
    rep(i, n-1){
        int x, y;
        cin >> x >> y;
        a[i] = x;
        b[i] = y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    rep(i, n+1) chmax(deg, (int)G[i].size());

    dfs(1, -1, 0);

    /*
    for(auto x: m){
        auto p = x.first;
        auto c = x.second;
        cout << p.first << ", " << p.second << ": " << c << endl;
    }
    */

    cout << deg << endl;
    rep(i, n-1){
        cout << m[P{a[i], b[i]}] << endl;
    }

}

Measured memory_bytes: 14976
#include<stdio.h>
#define N 2100000000
#define M 500000

int cnt=0,a[M];

void merge(int left, int mid, int right){
  int i, j, k, n1=mid-left, n2=right-mid, L[n1+1], R[n2+1];
  
  for(i=0;i<n1;i++) L[i]=a[left+i];
  for(i=0;i<n2;i++) R[i]=a[mid+i];
  L[n1]=R[n2]=N;
  i=j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      a[k]=L[i++];
    }
    else{
      a[k]=R[j++];
    }
  }
}

void sort(int left, int right){
  if(left+1<right){
    int mid=(left+right)/2;
    sort(left,mid);
    sort(mid,right);
    merge(left,mid,right);
  }
}

int main(){
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  
  sort(0,n);

  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);

  printf("%d\n",cnt);
  
  return 0;
}



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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int calc(string s) {
  int res = 0;
  res += 60 * 60 * ((s[0] - '0') * 10 + (s[1] - '0'));
  res += 60 * ((s[3] - '0') * 10 + (s[4] - '0'));
  res += (s[6] - '0') * 10 + (s[7] - '0');
  return res;
}

bool solve() {
  int n; cin >> n;
  if(n == 0) return false;

  vector<P> v;
  REP(i, n) {
    string l, r; cin >> l >> r;
    v.push_back({calc(l), calc(r)});
  }

  vector<int> imos(60 * 60 * 60+1, 0);
  REP(i, n) {
    imos[v[i].first]++;
    imos[v[i].second]--;
  }
  REP(i, SZ(imos)-1) {
    imos[i+1] += imos[i];
  }

  int ans = 0;
  REP(i, SZ(imos)-1) {
    chmax(ans, imos[i]);
  }
  cout << ans << endl;

  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while(1) {
    if(!solve()) break;
  }

}

























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

using namespace std;
#define ull unsigned long long int
int main(void)
{
	int n, m;
	cin>>n>>m;
	int s[n+1];
	bool vis[n+1], flag=true;
	memset(s, 0, sizeof(s));
	memset(vis, 0 ,sizeof(vis));
	for(int i=0; i<m; i++)
	{
		int a, b;
		cin>>a>>b;
		if(!vis[a]){ s[a]=b; vis[a]=true;}

		else if(vis[a] && s[a]!=b) flag=false;

	}

	if(!flag) {cout<<"-1\n"; return 0;}

	else if(n==1 && vis[1] && s[1]==0)
		{cout<<"0\n"; return 0;}

	else if(n!=1 && vis[1] && s[1]==0)
		{cout<<"-1\n"; return 0;}

	if(!vis[1] && n>1)
		s[1]=1;

	for(int i=1; i<=n; i++)
		cout<<s[i];
	cout<<"\n";

	return 0;
}

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

int main(void) 
{

    int n, m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];

    int cnt1 = 0;
    ll sum = 0;
    rep(i,n)
    {
        if(sum + a[i] <= k)
        {
            cnt1++;
            sum += a[i];
        }
        else break;
    }
    int size = cnt1;
    int ans = cnt1;
    int b_index = 0;

    while(1)
    {
        if(b_index >= m) break;
        if(sum + b[b_index] <= k)
        {
            sum += b[b_index];
            b_index++;
            ans++;
        }
        else break;
    }
    int prev = ans;
    rep(i, size)
    {
        sum -= a[size -i-1];
        int cnt = 0;
        ll tmp = m - 1;
        for(ll index = b_index; index < m ; index++)
        {
            tmp = index;
            if(sum + b[index] <= k)
            {
                sum += b[index];
                cnt++;
            }
            else 
            {
                break;
            }
        }
        b_index = tmp;
        ans = max(ans, prev -1 + cnt);
        prev = prev - 1 + cnt;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

typedef long long ll;

const int dd = (int)1e5 + 7;
int a[dd];
int b[dd];
int c[dd];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n; i++) cin >> c[i];
	
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	
	
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int ind1 = lower_bound(a, a + n, b[i]) - a;
		int ind2 = upper_bound(c, c + n, b[i]) - c - 1;
		

		if (ind1) {
			ans += 1ll * ind1 * (n - ind2 - 1);
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1408
def solve(string):
    n, *h = map(int, string.split())
    ans = count = 0
    for h0, h1 in zip(h, h[1:]):
        if h0 >= h1:
            count += 1
        else:
            ans = max(ans, count)
            count = 0
    return str(max(ans, count))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 15176
// abc.117 C - Streamline

#include <bits/stdc++.h>
using namespace std;

int main( void ) {

    int n, m;
    cin >> n >> m;
    if( n >= m ) {
        cout << 0 << endl;
        return 0;
    }
	//各座標の配列、各区間の配列
    vector<int> p( m ), l(m-1);
    for( int i = 0; i < m; i++ ) {
        cin >> p.at( i );
    }
	//距離順にソート
    sort( p.begin(), p.end() );

	//各区間を求める
    for( int i = 0; i < m - 1; i++ ) {

        l.at( i ) = p.at( i + 1 ) - p.at( i );
    }
	//区間をソート（降順）
    sort( l.begin(), l.end(),greater<int>() );
    int sum = 0;
	//区間は2座標で作られるので、n-1にする
    for( int i = n-1; i <m-1; i++){
        sum += l.at( i );
    }
    cout <<sum << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    long a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    long c;
    if(a<b) c=b-a;
    else c=a-b;
    
    if((v-w)*t<c) cout << "NO" <<endl;
    else cout <<"YES"<<endl;
}


Measured memory_bytes: 3676
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program{
  public static void Main(){

    var input = Console.ReadLine().Split();
    string a = input[0].ToUpper();
    string b = input[1].ToUpper();
    string c = input[2].ToUpper();

    Console.Write(a[0]);
    Console.Write(b[0]);
    Console.Write(c[0]);
  }
}


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

char search(vector<string> m, int i, int j, int H, int W) {
  if (m.at(i).at(j) == '#') {
    return '#';
  }
  int ans = 0;
  if (i-1 >= 0) {
    if (j-1 >= 0) {
      if (m.at(i-1).at(j-1) == '#') {
        ans++;
      }
    }
    if (m.at(i-1).at(j) == '#') {
        ans++;
    }
    if (j+1 < W) {
      if (m.at(i-1).at(j+1) == '#') {
        ans++;
      }
    }
  }
  
  if (j-1 >= 0) {
    if (m.at(i).at(j-1) == '#') {
      ans++;
    }
  }
  if (j+1 < W) {
    if (m.at(i).at(j+1) == '#') {
      ans++;
    }
  }
  
  if (i+1 < H) {
    if (j-1 >= 0) {
      if (m.at(i+1).at(j-1) == '#') {
        ans++;
      }
    }
    if (m.at(i+1).at(j) == '#') {
        ans++;
    }
    if (j+1 < W) {
      if (m.at(i+1).at(j+1) == '#') {
        ans++;
      }
    }
  }
  
  return (char)(ans + 48);
}

int main() {
  int H;
  int W;
  cin >> H >> W;
  
  vector<string> mine;
  
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    mine.push_back(s);
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      mine.at(i).at(j) = search(mine, i, j, H, W);
    }
  }
  
  for (int i = 0; i < H; i++) {
    cout << mine.at(i) << endl;
  }
}

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

using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

size_t N;
vector<int64_t> a(int(1e5)), b(int(1e5)), c(int(1e5));

auto dp = make_v(-1LL, int(1e5), 4);

int64_t solve(size_t idx, int yesterday) {
    if (idx >= N) return 0;
    if (~dp[idx][yesterday]) return dp[idx][yesterday];

    int64_t ret = 0;
    if (yesterday != 0) chmax(ret, solve(idx + 1, 0) + a[idx]);
    if (yesterday != 1) chmax(ret, solve(idx + 1, 1) + b[idx]);
    if (yesterday != 2) chmax(ret, solve(idx + 1, 2) + c[idx]);

    return dp[idx][yesterday] = ret;
}

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

    cin >> N;

    for (size_t i = 0; i < N; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }

    cout << solve(0, 3) << "\n";

    return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <iomanip>

using namespace std;

const double EPS = 1e-8;

int n;
pair<int, int> s, t, b;
double dp[16][3][3];
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

bool equals(double a, double b){
  return abs(a-b) < EPS;
}

void setp(pair<int, int>& p, char c){
  int tmp = c - 'A';
  p = make_pair(tmp/3, tmp-(tmp/3)*3);
}

main(){
  while(cin >> n && n){
    char in1, in2, in3;
    cin >> in1 >> in2 >> in3;
    setp(s, in1);
    setp(t, in2);
    setp(b, in3);
    fill(dp[0][0], dp[16][0], 0.0);
    dp[0][s.first][s.second] = 1.0;
    for(int i=0;i<n;i++){
      for(int j=0;j<3;j++){
	for(int k=0;k<3;k++){
	  if(equals(dp[i][j][k], 0.0)) continue;
	  /*if(j == t.first && k == t.second){
	    dp[i+1][j][k] += dp[i][j][k];
	    continue;
	    }*/
	  for(int l=0;l<4;l++){
	    int ty = j + dy[l];
	    int tx = k + dx[l];
	    if(ty>=0 && ty<3){
	      if(tx>=0 && tx<3){
		if(ty != b.first || tx != b.second){
		  dp[i+1][ty][tx] += dp[i][j][k] / 4.0;
		  continue;
		}
	      }
	    }
	    dp[i+1][j][k] += dp[i][j][k] / 4.0;
	  }
	}
      }
      /*for(int j=0;j<3;j++){
	for(int k=0;k<3;k++){
	  cout << setw(6) << dp[i][j][k] << ' ';
	}
	cout << endl;
      }
      cout << endl;*/
    }
    /*for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
	cout << setw(6) << dp[n][j][k] << ' ';
      }
      cout << endl;
      }*/
    printf("%.8f\n", dp[n][t.first][t.second]);
  }
  return 0;
}

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

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
  nimble;
  int tt=1;//cin>>tt;
  while(tt--){
    int h,n;
    cin>>h>>n;
    vector<int> a(n);
    rep(i,0,n)cin>>a[i];
    rep(i,0,n){
      h-=a[i];
    }
    if(h<=0){
      cout<<"Yes"<<nl;
    }
    else cout<<"No"<<nl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
static const int MAXN = 3e5 + 4;
typedef long long int64;

int n, a[MAXN];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n * 3; ++i) scanf("%d", &a[i]);
    std::sort(a, a + n * 3);

    int64 ans = 0;
    for (int i = 0; i < n; ++i) ans += a[n * 3 - (i + 1) * 2];
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main() {
	int n, a, b, c, d, e, k;

	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);
	scanf("%d", &e);
	scanf("%d", &k);

	if (k >= b - a)
		if (k >= c - a)
			if (k >= d - a)
				if (k >= e - a)
					if (k >= c - b)
						if (k >= d - b)
							if (k >= e - b)
								if (k >= d - c)
									if (k >= e - c)
										if (k >= e - d) {
											printf("Yay!\n");
											return 0;
										}
	printf(":(\n");

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, S;
	int r;
	int power[101];
	int i, j;
	int count;
	
	while (1){
		scanf("%d%d", &n, &S);
		if (n == 0 && S == 0){
			break;
		}
		
		memset(power, 0, sizeof(power));
		for (i = 0; i < n; i++){
			scanf("%d", &r);
			power[r]++;
		}
		
		count = 0;
		
		for (i = 1; i <= 100; i++){
			for (j = 1; j <= 100; j++){
				if ((i + j) > S){
					if (power[i] != 0 && power[j] != 0){
						if (i != j){
							count += (power[i] * power[j]);
						}
						else {
							count += (power[i] * (power[i] - 1));
						}
					}
				}
			}
		}
		printf("%d\n", count / 2);
	}
	return (0);
}

Measured memory_bytes: 600
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int []a = new int [n];
		int []b = new int [n-1];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		   Arrays.sort(a);
		for(int i = 0; i < n-1;i++) {
			b[i] = Math.abs(a[i + 1] - a[i]);
		}
		int min = 1000000000;
		
		for(int i = 0; i < n - k + 1 ; i++) {
			int sum = 0;
			for(int j = 0; j < k - 1; j++) {	
				sum += b[i + j];
			}
			min = Math.min(sum, min);
		}
		System.out.println(min);

	}

}


Measured memory_bytes: 50652
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int N=250009;
const int M=509;

typedef pair<int,int> pr;
#define x first
#define y second

int n,e,a[N],x[M],cnt[M];
priority_queue<pr,vector<pr>,greater<pr> > q;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

int main()
{
	n=read();
	e=n*n;
	for(int i=1;i<=n;i++)
	{
		x[i]=read();
		cnt[i]=n;
		q.push((pr){x[i],i});
	}

	int cursor=0;
	for(int i=1,tot;i<=n;i++)
	{
		pr tmp=q.top();
		q.pop();
		tot=tmp.y-1;
		while(tot--)
		{	
			while(a[++cursor]);
			a[cursor]=tmp.y;
			cnt[tmp.y]--;
		}
		if(cursor>=tmp.x || a[tmp.x])
		{
			puts("No");
			return 0;
		}
		a[tmp.x]=tmp.y;
		cnt[tmp.y]--;
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=x[i]+1;j<=e && cnt[i];j++)
			if(!a[j])
			{
				a[j]=i;
				cnt[i]--;
			}
		if(cnt[i])
		{
			puts("No");
			return 0;
		}
	}

	puts("Yes");
	for(int i=1;i<=e;i++)
		printf("%d%c",a[i]," \n"[i==e]);

	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define EPS 0.000000001
using namespace std;

struct Info{
	int x;
	double h;
};

double  calc(double  tmp_x,double  tmp_dist){
	return sqrt(tmp_x*tmp_x + (tmp_dist/(2*tmp_x))*(tmp_dist/(2*tmp_x)));
}

int main(){

	double dist;
	int N,B;

	scanf("%lf %d %d",&dist,&N,&B);

	Info info[N];

	for(int i = 0; i < N ;i++)scanf("%d %lf",&info[i].x,&info[i].h);

	double  tmp_dist;

	double  ans = 1000000.0;
	double  left,right,m,tmp_x,max_x,tmp_y,diff_dist,tmp_h,limit,maximize_x;

	bool FLG;

	for(int b_count = 1; b_count <= B+1; b_count++){

		tmp_dist = (double)dist/b_count;

		left = 0.0,right = DBL_MAX,m = (left+right)/2;
		max_x = 0;

		while(left <= right){

			tmp_x = m;
			tmp_y = tmp_dist/(2*tmp_x);

			FLG = true;

			for(int i = 0; i < N; i++){
				diff_dist = info[i].x;

				while(diff_dist >= tmp_dist)diff_dist -= tmp_dist;

				tmp_h = (tmp_y/tmp_x)*diff_dist-1.0/(2*tmp_x*tmp_x)*(diff_dist*diff_dist);

				if(info[i].h > tmp_h){
					FLG = false;
					break;
				}
			}
			if(FLG){
				max_x = max(max_x,m);
				left = m+EPS;
			}else{
				right = m-EPS;
			}
			m = (left+right)/2;
		}

		limit = tmp_dist*tmp_dist/4.0;

		left = 0.0,right = 101.0,m = (left+right)/2;

		while(left <= right){
			if(m*m*m*m > limit){
				right = m-EPS;
			}else{
				maximize_x = m;
				left = m+EPS;
			}
			m = (left+right)/2;
		}

		if(max_x >= maximize_x){
			ans = min(ans,calc(maximize_x,tmp_dist));
		}else{
			ans = min(ans,calc(max_x,tmp_dist));
		}
	}

	printf("%.12lf\n",ans);

	return 0;
}

Measured memory_bytes: 3176