akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)


int H[200];
void sub(int l, int r){
    for(int i = l; i <= r; i++){
        H[i]--;
    }
}

int main(){
    int N;
    cin >> N;
    int M = -1;
    REP(i,N){
        int h;
        cin >> h;
        H[i] = h;
        M = max(M, h);
    }

    ll ans = 0;
    bool state;
    for(int i = 0; i < M; i++){
        state = false;
        int left;
        int right;
        for(int j = 0; j < N; j++){
            int h = H[j];
            if(h > 0 && !state){
                state = true;
                left = j;
            }
            else if(h <= 0 && state){
                state = false;
                right = j;
                sub(left, right);
                ans++;
            }

            if(j == N-1 && state){
                state = false;
                right = j;
                sub(left, right);
                ans++;
            }
        }
    }

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


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    int a, b;
    cin >> a >> b;
    int ans = 1;
    int i = 0;
    
    if(b == 1){cout << 0 << endl; return 0;}
    while(ans < b){
        --ans;
        ans += a;
        ++i;
    }
    cout << i << endl;
}


Measured memory_bytes: 3636
using System;
 
public class p0003{
     
    public static void Main(string[] args){
        int n;
        string str;
        string[] s;
        int[] a = new int[3];

        while ((str = Console.ReadLine()) != null)
        {
            n = int.Parse(str);

            while (0 < n--)
            {
                s = (Console.ReadLine()).Split(' ');
                for (int i = 0; i < 3; ++i)
                {
                    a[i] = int.Parse(s[i]);
                    a[i] = a[i] * a[i];
                }
                Console.WriteLine("{0}", ((func(a)) ? "YES" : "NO"));
            }
        }
    }
     
    public static bool func(int[] a){
        return (a[0] == a[1]+a[2] || a[1] == a[0]+a[2] || a[2] == a[0]+a[1]);
    }
}

Measured memory_bytes: 5460
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<int> L(N);
	for (int i=0; i<N; i++)
		cin>>L[i];
	sort(L.begin(), L.end());
	int ret=0;
	for (int i=0; i<N; i++)
		for (int j=i+1; j<N; j++)
			for (int k=j+1; k<N; k++)
				if(L[i]!=L[j] && L[j]!=L[k] && L[i]+L[j]>L[k])
					ret++;
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int N = 2e6 + 6;
int A[N];
int n;

void solve()
{
	int a , b ,c ,d;
	cin >> a >> b >> c >> d;
	
	while(1)
	{
		c -= b;
		if(c <= 0)
		{
			cout << "Yes";
			return;
		}
		a -= d;
		if(a <= 0)
		{
			cout << "No";
			return;
		}
	}
}
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);

ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	

 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

char c[20][20];

bool can_go(char path){
	if(path=='.') return true;
	else return false;
}

void bfs(vector<vector<int>> &g, vector<int> &dist, int sv){
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int h,w; cin >> h >> w;
	rep(j,h)rep(i,w) cin >> c[i][j];
	vvi to(h*w);
	rep(i,w)rep(j,h){
		if(c[i][j]=='#') continue;
		if(i-1>=0&&can_go(c[i-1][j])) to[w*j+i].push_back(w*j+i-1);
		if(i+1<w&&can_go(c[i+1][j])) to[w*j+i].push_back(w*j+i+1);
		if(j-1>=0&&can_go(c[i][j-1])) to[w*j+i].push_back(w*(j-1)+i);
		if(j+1<h&&can_go(c[i][j+1])) to[w*j+i].push_back(w*(j+1)+i);
	}
	int st;
	int ans = 0;
	rep(j,h)rep(i,w){
		int st = w*j+i;
		vi dist(h*w,-1);
		bfs(to,dist,st);
		ans = max(ans,MAX(dist));
	}
	out(ans);
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define select(_1, _2, x, ...) x
 
#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)
 
using namespace std;
 
using ll = long long int;
 
struct node {
    ll num;
    string all;
};
 
int main() {
    ll k;
    cin >> k;
 
    if (k <= 9) {
        cout << k << endl;
        return 0;
    }
 
    queue<struct node> q;
    rep(i, 1, 10) {
        struct node temp = {i, to_string(i)};
        q.push(temp);
    }
 
    ll cnt = 0;
 
    struct node t;
    while (cnt < k) {
        t = q.front(); q.pop();
        rep(i, t.num - 1, t.num + 2) {
            if (i < 0 || i > 9) continue;
            struct node temp = {i, t.all + to_string(i)};
            q.push(temp);
        }
        cnt++;
    }
 
    cout << t.all << endl;
 
    return 0;
}


Measured memory_bytes: 12288
#include<iostream>
#include<algorithm>
#include<map>
#include<functional>
using namespace std;
#define ll long long
#define P pair<int,int>

int t[70000];
P p[70000];
int main(){
	int n;
	unsigned int ans=0;

	while(cin>>n,n!=0){
	for(int i=0;i<70000;i++)t[i]=0,p[i].first=0,p[i].second=0;
	for(int i=0;i<n;i++)cin>>t[i];
	for(int i=0;i<n-1;i++){
	int tmp;
	cin>>tmp;
	p[i]=P(tmp,i);//長さでソートして,iとi+1を継ぐパイプ
	}
	sort(&p[0],&p[0]+n,greater<pair<int,int> >());
	int sum=0,cnt=n;
	for(int i=0;i<n;i++)sum+=t[i];
	ans=sum*cnt;
	for(int i=0;i<n-1;i++){
	P tmp=p[i];
	sum+=p[i].first;
	cnt--;
	ans=max(ans,(unsigned int)sum*cnt);
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1980
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N;cin >> N;
	map<int, int>D, T;
	rep(i, 0, N) {
		int a; cin >> a;
		D[a]++;
	}
	int M; cin >> M;
	rep(i, 0, M) {
		int a; cin >> a;
		T[a]++;
	}
	bool ans = true;
	for (auto p : T) {
		if (p.second > D[p.first])ans = false;
	}
	cout << (ans ? "YES" : "NO") << "\n";

	return 0;
}

Measured memory_bytes: 22256
import java.util.*;

public class Main {
 
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0 ;i<n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        boolean[] b = new boolean[1000001];
 
        int res = 0;
        for(int i=0; i<n; i++) {
            int num = a[i];
            if(!b[num] && !(i<n-1 && num == a[i+1])) res++;
            if(!b[num]) {
                for(int j = num; j<=1000000; j+=num) {
                    b[j] = true;
                }
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 61172
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
  LL n; cin >> n;
  vector<LL> a(n), b(n);
  for (int i = 0; i < n; i ++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a.begin(), a.end());
  LL maxv = a[n - 1];
  LL t = a[n - 2];

  for (int i = 0; i < n; i ++) {
    if (maxv != b[i]) cout << maxv << endl;
    else cout << t << endl;
  }
}

Measured memory_bytes: 4736
n, m = map(int, input().split())
d = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    d[a-1] ^= 1
    d[b-1] ^= 1
ans = 0
for j in range(n):
    ans |= d[j]
if ans:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

lli x;
bool cmp(int a, int b)
{
  return abs(a - x) < abs(b - x);
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> x >> n;
  vlli p(n), d(300, 0), e;
  set<lli> g;
  repe(i, 1, 300)
  {
    d[i - 1] = i - 100;
  }
  rep(i, 0, n)
  {
    cin >> p[i];
    g.insert(p[i]);
  }
  sort(d.begin(), d.end(), cmp);

  rep(i, 0, d.size())
  {
    if (g.count(d[i]) == 0)
    {
      e.push_back(d[i]);
    }
  }
  // SORT(e);
  if (abs(x - e[0]) == abs(x - e[1]))
  {
    if (e[0] > e[1])
    {
      cout << e[1] << endl;
    }
    else
    {
      cout << e[0] << endl;
    }
  }
  else
  {
    cout << e[0] << endl;
  }

  // rep(i, 0, d.size())
  // {
  //   cout << d[i] << " ";
  // }
  // cout << endl;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll d = b - a;
    d--;
    ll ans = 0;
    while(d > 0){
        ans += d;
        d--;
    }

    cout << ans - a << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

#define N 2000001
#define M 10000

int  B[N], C[M];

void CountingSort(int A[N], int k, int n);
  
 


int main(){
  
  int i,n, max = 0, A[N];
  scanf("%d", &n);

  for(i = 1 ; i <=n ; i++ ){
    
    scanf("%d", &A[i]);

    if(A[i] > max) max = A[i];
     
  }
  

CountingSort(A, max, n);

 return 0;
}   
  
void CountingSort(int A[N], int k, int n){
  
  int i, j;
  
 
  for(i = 0 ; i <= k ; i++){
    
    C[i] = 0;
  
  }
  
    for(j = 1 ; j <= n ; j++){
      
      C[A[j]] = C[A[j]]+1;
      
    }

  
  
  for(i = 1 ; i <= k ; i++){
    
    C[i] = C[i] + C[i - 1];
  }
  
  for(j = n ; j >= 1 ; j--){
    
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]]-1;
    
  }
  
  for(i = 1 ; i <= n ; i++){
  printf("%d", B[i]);
  if (i < n)printf(" ");
   }
  printf("\n");
}
 

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (((a == 5) && (b == 7) && (c == 5)) || ((a == 5) && (b == 5) && (c == 7)) || ((a == 7) && (b == 5) && (c == 5))) {
		cout << "YES" ;
	}else{
		cout << "NO" ;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long

using namespace std;

int main(void){
    string s;
    cin >> s;

    string head = s.substr(0,7); 
    string back = s.substr(s.size()-7, 7);

    string truekey = "keyence";
    int count = 0;
    bool headflag = true;
    for(int i = 0;i < 7;i++){
        if(head[i] == truekey[i] && headflag){
            count++;
        } else if(headflag){
            headflag = false;
        }

        if(back[i] == truekey[i] && !headflag){
            count++;
        }
    }

    if(count == 7){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}

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


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner br = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String turn = br.next();
		Integer tarou = 0;
		Integer hanako = 0;
		for(int i = 0; i < Integer.parseInt(turn); i++){
			String[] battle = {br.next(), br.next()};
			String[] battle_bkp = battle.clone();
			Arrays.sort(battle);
			if(battle[0].equals(battle[1])){
				tarou += 1;
				hanako += 1;
			}
			else if(battle[0].equals(battle_bkp[0]) && battle[1].equals(battle_bkp[1])){
				hanako += 3;
			}
			else{
				tarou += 3;
			}
		}
		System.out.println(tarou + " " + hanako);
	}
}

Measured memory_bytes: 20916
fun main(args: Array<String>) {
    val n = readInt()
    val a = List(n) { readInt() }

    var c = a[0]
    var cnt = 1
    repeat(n) {
        if (c == 2) {
            println(cnt)
            return
        }
        c = a[c - 1]
        cnt++
    }
    println(-1)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()

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

int main() {
    int N;
    int n1 = 0, n2 = 0, n4 = 0;
    cin >> N;
    for (int i = 0; i != N; ++i){
        int a;
        cin >> a;
        if (a % 2 == 1){
            ++n1;
        }else if (a % 4 != 0){
            ++n2;
        }else{
            ++n4;
        }
    }
    if (n1 > n4){
        if (n1 == n4 + 1 and n2 == 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(), k = scanner.nextInt();
		int result = 1;
		for(int i=0;i<n;i++){
			if(result * 2 < result + k){
				result *= 2;
			}else{
				result += k;
			}
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 22864
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

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

    int ans = 1000000000;
    for(int i = 0;i < (int)pow(2.0, (double)n);++i){
        int bit_mask = 1;
        int c_sum = 0;
        vector<int> r(m, 0);

        for(int j = 0;j < n;++j){
            if(i & bit_mask){
                c_sum += c[j];

                for(int k = 0;k < m;++k){
                    r[k] += a[j][k];
                }
            }

            bit_mask = bit_mask << 1;
        }

        int flag = 1;
        for(int k = 0;k < m;++k){
            if(r[k] < x){
                flag = 0;
            }
        }

        if(flag){
            ans = min(ans, c_sum);
        }
    }

    if(ans == 1000000000){
        cout << "-1" << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4084
from collections import (
    Counter,
)


def input_ints():
    return list(map(int, input().strip().split()))


def _main():
    n = input_ints()[0]
    xy = [input_ints() for _ in range(n)]

    if len(xy) == 1:
        print(1)
        return

    (_, count), = Counter(
        (x1 - x2, y1 - y2)
        for (x1, y1) in xy
        for (x2, y2) in xy
        if not (x1 == x2 and y1 == y2)
    ).most_common(1)

    print(len(xy) - count)


if __name__ == '__main__':
    _main()


Measured memory_bytes: 3820
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
	double T, X;
	cin >> T >> X;
	cout << T / X;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a(m+1);
    for(int i=1; i<=m; i++){
        cin >> a.at(i);
    }
    int div;
    if(n%2==1){
        div = (n+1)/2;
    }else{
        div = n/2;
    }
    int cst1=0;
    int cst2=0;
        for(int i=x-1; i>=1; i--){
            for( int j=1; j<=m; j++){
                if( i==a.at(j)){
                    cst1++;
                    break;
                }
            }
        }
        for( int i=x+1; i<=n-1; i++){
            for( int j=1; j<=m; j++){
                if(i==a.at(j)){
                    cst2++;
                    break;
                }
            }
        }
    cout << min(cst1,cst2) << endl;
}




Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int h, w;
	char tmp[101];
	scanf("%d%d", &h, &w);
	rep(i, h + 2) {
		rep(j, w + 2) {
			if (i == 0 || i == h + 1 || j == 0 || j == w + 1) {
				printf("#");
			}
			else {
				scanf("%s", tmp);
				printf("%s", tmp);
				j += strlen(tmp) - 1;
			}
		}
		printf("\n");
	}

	return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector<ll> f(n+1);
  for(ll i=1; i<=n; i++){
    for(ll j=i; j<=n; j += i) f[j]++;
  }
  ll ans = 0;
  rep(i,n+1) ans += i*f[i];
  cout << ans << endl;
}


Measured memory_bytes: 81328
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll a[100005];
ll ans[100005] = {};
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans[a[i] - 1]++;
		ans[a[i]]++;
		ans[a[i] + 1]++;
	}
	ll max = -inf;
	
	for (int i = 0; i < 100005; i++) {
		if (max < ans[i]) {
			max = ans[i];
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 1792
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as BS
main=do
 [n,m]<-map read.words<$>getLine
 ab<-replicateM n (map (read.BS.unpack).BS.words<$>BS.getLine)
 print(f m (sort ab) 0)
  where f m ([a,b]:ab) i = if m<=b then (i+m*a) else (f (m-b) ab (i+b*a))

Measured memory_bytes: 66940
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  ll ans = 1;
  for (int i = 1; i < 7; i++) {
    ll x = pow(2, i);
    if (x <= N) ans = x;
  }
  cout << ans << endl;
  return 0;
}

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

string s;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s;
  if (s.size() == 1) {
    cout << "YES" << endl;
    return 0;
  }
  if (s.size() == 2) {
    cout << (s[0] != s[1] ? "YES" : "NO") << endl;
    return 0;
  }

  int sz = s.size();
  map<int, int> cnt;
  for (int i = 0; i < sz; i++) {
    cnt[s[i] - 'a']++;
  }
  if (cnt.size() <= 2) {
    cout << "NO" << endl;
    return 0;
  }
  int tmp = min({cnt[0], cnt[1], cnt[2]});
  cnt[0] -= tmp;
  cnt[1] -= tmp;
  cnt[2] -= tmp;
  vector<int> v{cnt[0], cnt[1], cnt[2]};
  sort(v.begin(), v.end());
  if (v[0] == 0 && v[1] == 0) {
    cout << (v[2] <= 1 ? "YES" : "NO") << endl;
  } else {
    cout << (v[1] == 1 && v[2] == 1 ? "YES" : "NO") << endl;
  }

  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){

  int a,b,d,r;
  double f;
  scanf("%d%d",&a,&b);
  
  d=a/b;
  r=a%b;
  f=(double)a/b;
  
  printf("%d %d %f\n",d,r,f);
  
  return 0;
}

Measured memory_bytes: 1068
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>

using namespace std;
long long int dp[48][408][408];
int main() {

	long long int N, A, B;
	cin >> N >> A >> B;
	long long int a[48], b[48], c[48];

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

	for (int i = 0; i <= N; i++) {
		for (int k = 0; k <= N * 10; k++) {
			for (int j = 0; j <= N * 10; j++) {
				dp[i][k][j] = 1000000000000000000;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int k = 0; k <= N * 10; k++) {
			for (int j = 0; j <= N * 10; j++) {
				dp[i][k][j] = dp[i - 1][k][j];

				if (k >= a[i] && j >= b[i]) {
					dp[i][k][j] = min(dp[i][k][j], dp[i - 1][k - a[i]][j - b[i]] + c[i]);
				}


			}
		}
	}

	long long int Z = 1000000000000000000;
	for (int i = 1; A*i <= N * 10 && B*i <= N * 10; i++) {
		Z = min(Z, dp[N][A*i][B*i]);
	}
	if (Z != 1000000000000000000)cout << Z << endl;
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 55552
import math

N, M = map(int, input().split())


if M > 1 and N > 1:
    print(int(math.factorial(N) / (2 * math.factorial(N - 2))) + int(math.factorial(M) / (2 * math.factorial(M - 2))))
elif M <= 1 and N <= 1:
    print(0)
elif M <= 1:
    print(int(math.factorial(N) / (2 * math.factorial(N - 2))))
elif N <= 1:
    print(int(math.factorial(M) / (2 * math.factorial(M - 2))))


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

int main() {
  int h, w;
  cin >> h >> w;
  std::vector< std::vector<char> > input(h, vector<char>(w));
  for(int i = 0; i < h; i++) {
    for(int k = 0; k < w; k++) {
      cin >> input[i][k];
    }
  }
  for(int i = 0; i < h; i++) {
    for(int k = 0; k < w; k++)
      cout << input[i][k];
    puts("");
    for(int k = 0; k < w; k++)
      cout<< input[i][k];
    puts("");
  }
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

const ll MAX_N = 2 * 1e5;
ll N;
ll a[MAX_N];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	ll sum[N];
	memset(sum, 0, sizeof(sum));
	ll X = 0;
	rep(i, 0, N) {
		cin >> a[i];
		if(i == 0) sum[0] = a[0];
		else sum[i] += a[i] + sum[i - 1];
		X += a[i];
	}

	ll min_v = 1e18;
	rep(i, 0, N - 1) {
		ll x = sum[i];
		min_v = min(min_v, abs(2 * x - X));
	}
	cout << min_v << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=2e5;
const int INF=1e9;
int main(){
	long N;cin>>N;
	cout<<N*(N-1)/2<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define D(x) cout << (#x) << " is " << x << endl;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

lli cnt[200005];
 
int main()
{
    lli n, x, m;
    cin >> n >> x >> m;
    lli ans = x;
    cnt[x] = 1;
    n--;
    while(n){
		x = (x*x)%m;
		if( cnt[x] ){
			break;
		}
		cnt[x]++;
		ans += x;
		
		n--;
	}
	if(n == 0 ){
		cout << ans << endl;
		return 0;
	}
	vector<lli> v;
	v.push_back(x);
	while(1){
		x = (x*x)%m;
		if(cnt[x] == 2) break;
		
		
		v.push_back(x);
		cnt[x]++;
	}
	v.pop_back();
	lli si = v.size();
	lli div = n/si;
	lli mod = n%si;
	//for(lli fx: v) cout << fx << endl;
	//D(si)D(div)D(mod)
	for(int i=0; i<si; i++){
		ans += (v[i]*div);
		if(i<mod){
			ans += v[i];
		}
	}
	cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];
int main() {
	int n,k;
	cin>>n>>k;
	string str;
	cin>>str;
	int r=0;
	rep(i,n-1){
		if(str[i]!=str[i+1])r++;
	}
	r=max(0,r-2*k);

	cout<<n-1-r<<endl;	
	return 0;
}


Measured memory_bytes: 5120
N, Y = [int(n) for n in input().split(' ')]

def solver():
    for a in range(N+1):
        for b in range(N+1-a):
            if (10000*a + 5000*b + 1000*(N-a-b))==Y:
                print(a, b, N-a-b)
                return 1
    print(-1, -1, -1)
    return 0

solver()

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
  char input[5];
  int y1,y2;
  int flag=0;
  
  scanf("%s",input);
  
  y1=(input[0]-'0')*10+(input[1]-'0');
  y2=(input[2]-'0')*10+(input[3]-'0');
  
  if(1<=y1 && y1<=12){
    flag+=2;
  }
  if(1<=y2 && y2<=12){
    flag+=1;
  } 
  
  switch(flag){
    case 0:
      printf("NA");
      break;
    case 1:
      printf("YYMM");
      break;
    case 2:
      printf("MMYY");
      break;
    case 3:
      printf("AMBIGUOUS");
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    ll ans = 0, prev = 0;
    for (int i=0; i<n; i++) {
        ll ai; cin >> ai;
        ans += max(ai, prev) - ai;
        prev = max(ai, prev);
    }
    cout << ans << '\n';
    return 0;
}

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

const llong MOD = 1e9+7;
const llong inf = 1<<30;

int main() {
    int A, B;
    cin >> A >> B;
    cout << max(A+B, max(A-B, A*B)) << endl;
    return 0;
}

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

int main() {
	int x;
	cin >> x;
	int sum = 0;
	for (int i = 1; i < 10; i++) {
		for (int j = i; j < 10; j++) {
			if (i * j == x) {
				sum++;
				break;
			}
		}
	}
	if (sum == 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		if(N > 999)
			System.out.println("ABD");
		else
			System.out.println("ABC");
	}
}


Measured memory_bytes: 21332
N,*xyhs=$<.read.split.map(&:to_i)
xyhs = xyhs.each_slice(3).select {|x,y,h| h != 0 }.sort_by {|x,y,h| -h}

if xyhs.one?
    puts xyhs[0].join(' ')
    exit
end

0.upto(100) do |cx|
    0.upto(100) do |cy|
        x,y,h = xyhs[0]
        h1 = h+(x-cx).abs+(y-cy).abs
        if xyhs.all? { |x,y,h| h1 == h+(x-cx).abs+(y-cy).abs }
            puts [cx,cy, h1].join(' ')
            exit
        end
    end
end




Measured memory_bytes: 14352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int l, r, ans;
string s;
int main() {
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A') {
			l = i;
			break;
		}
	}
	for (int i = s.length() - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			r = i;
			break;
		}
	}
	cout << r - l + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
using namespace std;
int min(int a,int b, int c){
  if(a<=b&&a<=c) return a;
  else if (b<=a && b<=c) return b;
  else return c;
}
int main(){
  int n;
  cin >>n;
  long long a[90];
  a[0]=2; a[1]=1;
  for(int i=2 ;i<=n;i++)
  a[i]=a[i-1]+a[i-2];
  cout<<a[n]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

string str;
vector <string> v;

map <string, bool> mp;

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, k;
    ios::sync_with_stdio(false);
    cin >> str;
    cin >> k;
    for(int i = 0; i < str.size(); i++) {
        string aux;
        for(j = i; j < i + 5 && j < str.size(); j++) {
            aux = aux + str[j];
            v.push_back(aux);
        }
    }
    sort(v.begin(), v.end());
    int cnt = 0;
    for(auto it : v) {
        if(mp[it] == 0) {
            mp[it] = 1;
            cnt++;
        }
        if(cnt == k) {
            cout << it;
            return 0;
        }
    }
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s,t;
  cin>>s>>t;
  if(s[0]==t[2] && s[1]==t[1] && s[2]==t[0]) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x[ohara],y[ohara],sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
map<ll,ll> le;
map<ll,ll> ri;
U_MAP vi;
U_MAP hen;

//-------------------------↓↓↓↓↓↓------------------------

struct UnionFind{
	std::vector<int> data;
	
	UnionFind(int n){
		data.assign(n, -1);
	}
	
	void unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}
	
	int find(int k){
		if(data[k] < 0) return k;
		return data[k] = find(data[k]);
	}

	int size(int k) {
		return -data[find(k)];
	}

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

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

    cin>>n;
    rep(i,n)cin>>x[i]>>y[i];

    UnionFind uf(ohara);
    rep(i,n){
        uf.unite(x[i],y[i]+100000);
    }
    rrep(i,1,100001){
        le[uf.find(i)]++;
        ri[uf.find(i+100000)]++;
    }
    rep(i,n){
        hen[uf.find(x[i])]++;
    }
    rep(i,n){
        if(vi[uf.find(x[i])]==1)continue;
        vi[uf.find(x[i])]=1;
        ans+=max(le[uf.find(x[i])]*ri[uf.find(x[i])]-hen[uf.find(x[i])],0LL);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 21504
use proconio::{input, marker::Usize1};
// dbg {{{
#[allow(dead_code)]
mod dbg {
    use std::fmt::{Debug, Formatter};

    #[derive(Clone)]
    pub struct Tabular<'a, T: Debug>(pub &'a [Vec<T>]);
    impl<'a, T: Debug> Debug for Tabular<'a, T> {
        fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
            for i in 0..self.0.len() {
                writeln!(f, "{:2} | {:?}", i, &self.0[i])?;
            }
            Ok(())
        }
    }

    #[derive(Clone)]
    pub struct BooleanTable<'a>(pub &'a [Vec<bool>]);
    impl<'a> Debug for BooleanTable<'a> {
        fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
            for i in 0..self.0.len() {
                writeln!(f, "{:2} | {:?}", i, BooleanSlice(&self.0[i]))?;
            }
            Ok(())
        }
    }

    #[derive(Clone)]
    pub struct BooleanSlice<'a>(pub &'a [bool]);
    impl<'a> Debug for BooleanSlice<'a> {
        fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
            write!(
                f,
                "{}",
                self.0
                    .iter()
                    .map(|&b| if b { '#' } else { '.' })
                    .collect::<String>()
            )?;
            Ok(())
        }
    }
}
// }}}

fn main() {
    input!(n: usize, ab: [(Usize1, Usize1); n - 1]);
    let mut g = vec![vec![]; n];
    for (a, b) in ab {
        g[a].push(b);
        g[b].push(a);
    }

    let mut path = Vec::new();
    fn dfs(x: usize, p: usize, path: &mut Vec<usize>, g: &[Vec<usize>]) -> bool {
        if x == g.len() - 1
            || g[x]
                .iter()
                .copied()
                .filter(|&y| y != p)
                .any(|y| dfs(y, x, path, g))
        {
            path.push(x);
            true
        } else {
            false
        }
    }
    dfs(0, 0, &mut path, &g);
    path.reverse();
    let mut belongs_to_path = vec![false; n];
    path.iter().for_each(|&x| belongs_to_path[x] = true);

    let fennec = path[0..(path.len() + 1) / 2]
        .iter()
        .map(|&root| {
            fn dfs(x: usize, p: usize, g: &[Vec<usize>]) -> usize {
                1 + g[x]
                    .iter()
                    .copied()
                    .filter(|&y| y != p)
                    .map(|y| dfs(y, x, g))
                    .sum::<usize>()
            }
            1 + g[root]
                .iter()
                .copied()
                .filter(|&subroot| !belongs_to_path[subroot])
                .map(|subroot| dfs(subroot, root, &g))
                .sum::<usize>()
        })
        .sum::<usize>();
    println!("{}", if n < fennec * 2 { "Fennec" } else { "Snuke" });
}


Measured memory_bytes: 17200
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int h, w;
   cin >> h >> w;
   vector<string> s(h);
   rep(i, 0, h) { cin >> s[i]; }
   vector<vector<char>> ans(h);
   rep(i, 0, h) rep(j, 0, w) {
      int cnt = 0;
      rep(dy, -1, 2) rep(dx, -1, 2) {
         if (dx == 0 && dy == 0) continue;
         int x, y;
         x = dx + j, y = dy + i;

         if (x < 0 || x >= w || y < 0 || y >= h) continue;
         if (s[y][x] == '#') cnt++;
      }
      if (s[i][j] == '.')
         ans[i].push_back(cnt + '0');
      else
         ans[i].push_back('#');
   }
   rep(i, 0, h) {
      rep(j, 0, w) { cout << ans[i][j]; }
      cout << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  string s; cin >> s;
  string retval = "";
  rep(i,s.size()){
    if (s[i]=='B' && retval.size()>0) retval.erase(retval.size()-1);
    else if (s[i]=='0' || s[i]=='1') retval += s[i];
  }
  cout << retval << endl;

  

  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 256
n = int(input())
a = []

for x in range(1,n+1):
  if x % 15 == 0:
    x = "FizzBuzz"
  elif x % 3 == 0:
    x = "Fizz"
  elif x % 5 == 0:
    x = "Buzz"
  else :
    a.append(x)
  

print(sum(a))
    

Measured memory_bytes: 30084
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int f,n,m;
    cin>>n;
    m=n/2;
    f=n%2;
    string a,s,t;
    cin>>a;
    s=a.substr(0,m);
    t=a.substr(m,n-m);
    if(f==0)
    {
        if(s==t)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    else
        cout<<"No"<<endl;
    //cout<<t<<" "<<s;
    return 0;
}



Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int N;
	char S[100001] = {};
	cin >> N;
	int ans = 0;
	for (int i = 1; i < N+1; i++) {
		cin >> S[i];
		if (S[i] != S[i - 1]) {
			ans++;
		}
	}
	cout << ans<<endl;
	return 0;
}

Measured memory_bytes: 384
N = int(input())
 
erace1 = 1
erace2 = (N//2)*2
ans = []
for i in range(1,N):   
    for j in range(i+1,N+1):
        if i!=erace1 or j!=erace2: 
            ans.append([i,j])
        else:
            erace1 += 1
            erace2 -= 1
            
print(len(ans))
for a,b in ans:
    print(a,b)


Measured memory_bytes: 43888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	ll n,k;
	ll ch[3];
	cin>>n>>k;
	for(ll i=0;i<3;i++){
		ch[i]=-1;
	}
	for(ll i=0;i<k;i++){
		ll x,y;
		cin>>x>>y;
		x--;
		if(ch[x]==-1){
			ch[x]=y;
		}
		else{
			if(ch[x]!=y){
				cout << -1;
				return 0;
			}
		}
	}
	for(ll i=0;i<n;i++){
		if(i==0){
			if(ch[i]==0){
				if(n==1){
					cout << 0;
					return 0;
				}
				cout << -1;
				return 0;
			}
			else{
				if(n==1&&ch[i]==-1){
					cout << 0;
					return 0;
				}
				cout <<max(ch[i],ll(1));
			}
		}
		else{
			cout << max(ch[i],ll(0));
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define endl "\n"
template <typename T>
void printvec(vector<T> &v, int n, int start = 0)
{
    //cout << "\nprinting vector\n";
    for (int i = start; i < n; i++)
    {
        cout << v[i] << " ";
    }
    cout << "done printing";
    cout << endl;
}
const int mod = 1e9 + 7;

void solve()
{
    int n;
    cin >> n;
    vi a(n);
    for (int &x : a)
        cin >> x;
    ll prev = 0, ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] < prev)
        {
            ans += prev - a[i];
            a[i] = prev;
        }
        prev = a[i];
    }
    // printvec(a, a.size());
    cout << ans << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3948
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
	int n ; 
	cin>>n ;
	if(n>=30){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

ll powmod(ll x,ll n) {
  ll res = 1;
  rep(i,n) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll U = powmod(10,n), A = powmod(9,n), B = powmod(8,n);
  ll ans = U - 2 * A + B;
  ans %= mod;
  ans = (ans + mod) % mod;
  cout << ans << endl;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	r := []rune(s)
	if r[0] == r[1] && r[1] == r[2] {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


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

int main(){
    long long h,w;
    cin>>h>>w;
    long long n=h/2;
    long long m=h-h/2;
    long long a=w/2;
    long long b=w-w/2;
    long long lastmin=1000000000;
    long long callmax,realmax,callmin,realmin,cmax,rmax,cmin,rmin;
    if(h%3==0||w%3==0){
        cout<<0<<endl;
    }
    else{
        for(int i=0;i<=h;i++){
            callmax=max(i*w,(h-i)*a);
            realmax=max(callmax,(h-i)*b);
            callmin=min(i*w,(h-i)*a);
            realmin=min(callmin,(h-i)*b);
            lastmin=min(lastmin,realmax-realmin);
        }
        for(int i=0;i<=w; i++){
            cmax=max(i*h,(w-i)*n);
            rmax=max(cmax,(w-i)*m);
            cmin=min(i*h,(w-i)*n);
            rmin=min(cmin,(w-i)*m);
            lastmin=min(lastmin,rmax-rmin);
        }
        long long dark=min(h,w);
        cout<<min(lastmin,dark)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256