akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <cassert>
using namespace std;

int D;
vector<int> C;
vector<vector<int>> S;

struct State
{
    vector<int> T;
    vector<set<int>> X;
    long long score;
    State(): T(D, -1), X(26, set<int>{-1, D})
    {
        score = 0;
        for (int i=0; i<26; i++)
            score -= (long long)C[i]*D*(D+1)/2;
    }

    void add(int d, int t)
    {
        assert(T[d]==-1);
        assert(X[t].count(d)==0);

        auto p1 = X[t].lower_bound(d);
        auto p0 = p1;
        p0--;
        score += (long long)C[t]*(d-*p0)*(*p1-d);
        score += S[d][t];
        X[t].insert(d);
        T[d] = t;
    }

    void remove(int d)
    {
        assert(T[d]!=-1);
        assert(X[T[d]].count(d)>0);

        int t = T[d];
        auto p = X[t].find(d);
        auto p0 = p;
        p0--;
        auto p1 = p;
        p1++;
        score -= (long long)C[t]*(d-*p0)*(*p1-d);
        score -= S[d][t];
        X[t].erase(d);
        T[d] = -1;
    }
};

int main()
{
    cin>>D;
    C = vector<int>(26);
    for (int &c: C)
        cin>>c;
    S = vector<vector<int>>(D, vector<int>(26));
    for (auto &s: S)
        for (auto &x: s)
            cin>>x;

    State state;
    for (int i=0; i<D; i++)
    {
        int t;
        cin>>t;
        t--;
        state.add(i, t);
    }
    int M;
    cin>>M;
    for (int i=0; i<M; i++)
    {
        int d;
        int q;
        cin>>d>>q;
        d--, q--;
        state.remove(d);
        state.add(d, q);
        cout<<state.score<<endl;
    }
}


Measured memory_bytes: 3256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  FOR(7){
    int a,b;
    scanf("%d %d",&a,&b);
    PRN(a-b);
  }
  return 0;
}


Measured memory_bytes: 2104
import java.util.Arrays;
import java.util.Scanner;
        
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] values = new int[n];
        int answer = 0;

        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }

        Arrays.sort(values);
        
        for (int i = 0; i < k; i++) {
            answer += values[i];
        }

        System.out.println(answer);
    }
}

Measured memory_bytes: 39028
#include <iostream>
#define rep(i,n) for(int i=0; i<n; i++)

int main(void){

	int m;

	std::cin >> m;	//データセットの数

	while(m--){
		double amt;		//初期運用資金量
		int year;		//運用年数
		int n;			//運用方法の種類数
		int ans = 0;

		std::cin >> amt >> year >> n;

		while(n--){

			int f;			//単利０、複利１
			double roi;	//利率
			double chg;	//手数料
			int itr = 0;		//利子
			double fin = 0;	//最終資金

			int amt_tmp = amt;	//資金初期化

			std::cin >> f >> roi >> chg;

			if(f == 0){		//単利

				rep(i,year){
					itr += amt_tmp * roi;
					amt_tmp -= chg;
				}
				fin = amt_tmp + itr;

			}else{			//複利

				rep(i,year){
					amt_tmp += amt_tmp * roi;
					amt_tmp -= chg;
				}
				fin = amt_tmp;

			}
			if(ans < fin){
				ans = fin;
			}
		}

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

	return 0;
}

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

int main() {
  int n, t;
  cin>>n>>t;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  int min_a = a[0], cnt = 0;
  int max_v = -1e9;
  for (int i=1; i<n; i++) {
    if (a[i] - min_a > max_v) {
      max_v = a[i] - min_a;
      cnt = 1;
    } else if (a[i] - min_a == max_v) {
      ++cnt;
    }
    min_a = min(a[i], min_a);
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 640
n = int(input())
a = []
while True:
  try:
    a.append(int(input()))
  except:
    break

A = sorted(a,reverse=True)

MAX = A[0]
SMAX = A[1]

for i in range(n):
  if a[i]==MAX:
    print(SMAX)
  else:
    print(MAX)

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

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using LL   =  long long;
using pii  =  pair <int, int>;
using vii  =  vector <pii>;

const int INF = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

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

    int n = s.size(), ans = n;
    for(int i = 1; i < n; i++)
    {
        if(s[i] != s[i-1])
        {
            ans = min(ans, max(i, n-i));
        }
    }

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

Measured memory_bytes: 512
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  int n, m;
  ll sum = 0;
  cin >> n >> m;
  FOR(i, 1, m) {
    int a;
    cin >> a;
    sum += a;
  }
  if (sum > n) {
    cout << -1 << "\n";
  } else {
    cout << n - sum << "\n";
  }
}


Measured memory_bytes: 3196
N,M= map(int,input().split())

h = [int(i) for i in input().split()]
judge = [True]*N

for i in range (M):
    a,b= map(int,input().split())
    if h[a - 1] > h[b - 1]:
        judge[b-1] = False
    if h[a - 1] < h[b - 1]:
        judge[a - 1] = False
    if h[a - 1] == h[b - 1]:
        judge[b-1] = False
        judge[a - 1] = False

print(judge.count(True))

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

int main(){
    int A,B;
    cin >> A >> B;
    if(13<=A){
        cout << B << endl;
    }
    else if(6<=A && A<=12){
        cout << B/2 << endl;
    }
    else{
        cout << 0 << endl;
    }
    
    }

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

int n,m,a[1024000],cnt,b[1024000];

int findset(int x){
    if(a[x]==x){
        return x;
    }else{
        a[x]=findset(a[x]);
        return a[x];
    }
}

int main(){
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        a[i]=i;
        cin >> b[i];
    }
    for(int i=1;i<=m;i++){
        int ii,jj;
	    cin >> ii >> jj;
        ii=findset(ii);
        jj=findset(jj);
    	if(ii!=jj) a[jj]=ii;
    }
    for(int i=1;i<=n;i++){
    	if(findset(i)==findset(b[i])) cnt++;
	}
	cout << cnt;    
    return 0;
}

Measured memory_bytes: 4736
N = int(input())
xorz = list(map(int, input().split()))

xorall = 0
for i in xorz:
    xorall ^= i

numx = [0]*N
for i in range(N):
    numx[i] = xorall ^ xorz[i]

for i in range(N):
    print(numx[i]),


Measured memory_bytes: 105684
#include <iostream>
using namespace std;
int gcd(int x, int y) {
    if (x == 0) return y;
    if (y == 0) return x;
    return gcd(y, x%y);
}

int main(void){
  long long N;
  cin >> N;
  
  long long ans = 0;
  
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      for(int k=1;k<=N;k++){
        ans += gcd(gcd(i, j), k);
      }
    }
  }

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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  ll n;
  cin >> n;
  ll s = 0;
  vi v;
  while (n) {
    v.push_back(n % 10);
    s += v.back();
    n /= 10;
  }
  cout << max(s, (ll)v.size() * 9 - 9 + v.back() - 1) << endl;
//  vl pw(v.size(), 1);
//  for (int i = 1; i < pw.size(); ++i) pw[i] = pw[i-1] * 10;
//  for (int i = v.size() - 1;)
  return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<int, int> m;
	int ans = 0;
	REP(i, n){
		int t;
		cin >> t;
		++m[t];
		if(m[t] % 2 == 0) --ans;
		else ++ans;
	}
	cout << ans << "\n";
	return 0;
}


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

public class Main {
    private FastScanner in;
    private PrintWriter out;

    private void solve() {
        String s = in.next();
        out.println(s.substring(0, s.length() - 8));
    }

    private void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void runIO() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

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

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

using namespace std;

int main()
{
    long long a,b;
    char op;
    scanf("%lld %c%lld",&a,&op,&b);
    if(op=='+')
    {
        printf("%lld\n",a+b);
    }
    else if(op=='-')
    {
        printf("%lld\n",a-b);
    }
}


Measured memory_bytes: 256
/*  ex 5_4
    supercomputerjoi    */

#include <stdio.h>

int main(void){

    char str[11];
    int len = 0, maxLen = 0;
    int i;

    // input S
    scanf("%s", str);

    // calculate max length
    for(i = 0; i < 11; i++){
        // if ATGC len + 1
        if(str[i] == 'A' || str[i] == 'T' || str[i] == 'G' || str[i] == 'C'){
            len++;
        }else{
            if(len > maxLen){
                maxLen = len;
                len = 0;
            }
            if(str[i] == '\0'){
                break;
            }
        }
    }

    // output answer
    printf("%d\n", maxLen);

    return 0;
}

Measured memory_bytes: 1708
#include <stdio.h>

int main (void)
{
int a, b, c;
	
	scanf("%d""%d""%d",&a,&b,&c);
	
	if(a<b&&b<c){
		printf("%d %d %d\n",a,b,c);
	}
	else if(a<c&&c<b){
		printf("%d %d %d\n",a,c,b);
	}
	else if(b<c&&c<a){
		printf("%d %d %d\n",b,c,a);
	}
	else if(b<a&&a<c){
		printf("%d %d %d\n",b,a,c);
	}
	else if(c<a&&a<b){
		printf("%d %d %d\n",c,a,b);
	}
	else if(c<b&&b<a){
		printf("%d %d %d\n",c,b,a);
	}
	else if(b==c&&b<a){
		printf("%d %d %d\n",c,b,a);
	}
	else if(b==a&&b<c){
		printf("%d %d %d\n",b,a,c);
	}
	else if(a==b&&b<c){
		printf("%d %d %d\n",a,b,c);
	}
	else if(a==c&&c<b){
		printf("%d %d %d\n",a,c,b);
	}
	else if(c==a&&a<b){
		printf("%d %d %d\n",a,c,b);
	}
	else if(c==b&&b<a){
		printf("%d %d %d\n",a,b,c);
	}
	else{
		printf("%d %d %d\n",a,b,c);
	}
return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> vpii;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        vpii.emplace_back(a, b);
    }
    int t = 1;
    rep(i, n)
    {
        t *= 10;
    }
    bool flg = true;
    rep(i, t)
    {
        flg = true;
        string s = to_string(i);
        if (s.size() != n)
            continue;
        rep(j, vpii.size())
        {
            int a = vpii[j].first;
            int b = vpii[j].second;
            if (s.size() < a)
            {
                flg = false;
                break;
            }
            if (s[a - 1] - '0' != b)
            {
                flg = false;
                break;
            }
        }
        if (flg)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

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;}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  VI ct(4, 0);
  REP(i, 3)
  {
    int a, b;
    cin >> a >> b;
    a--; b--;
    ct[a]++; ct[b]++;
  }
  REPx(x, ct) if (x != 1 && x != 2) {cout << "NO" << endl; return 0;}
  cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;
int main(){
  int a[100],b[100],c[100],d[100],N,M;
  cin >> N >> M;
  FOR(i,0,N)cin >> a[i] >> b[i];
  FOR(i,0,M)cin >> c[i] >> d[i];
  FOR(i,0,N){
    int ma = 1e9,ans;
    FOR(j,0,M){
      if(ma > abs(a[i]-c[j])+abs(b[i]-d[j])){
        ans = j;
        ma = abs(a[i]-c[j])+abs(b[i]-d[j]);
      }
    }
    cout << ans+1 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	int n,m;
	cin >> n >> m;
	int foods[m] = {0};
	for(int i=0; i<n; i++){
		int k;
		cin >> k;
		for(int i=0; i<k; i++){
			int food;
			cin >> food;
			foods[food-1]++;
		}
	}
	int count =0;
	for(int i=0; i<m; i++){
		if(foods[i]==n) count++;
	}
	cout << count;
	return 0;
}

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

int main(){
  double n , k;
  cin >> n >> k ;
  double ans =0;
  
  for(int i=1;i<=n;i++){
    int tmp = i;
  double  count = 1.0/n;
    while(k>tmp){
      tmp *= 2;
      count /= 2;
    }
    ans += count ;
  }
  
  cout << setprecision(15) << ans << endl;
}





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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

string s;

int main() {
  cin >> s;
  deque<char> deq;
  rep(i,(int)s.size()) deq.pb(s[i]);
  int q;
  cin >> q;
  int f = 0;
  rep(_,q) {
    int t;
    cin >> t;
    if( t == 1 ) {
      ( f += 1 ) %= 2;
    } else {
      int a;
      char b;
      cin >> a >> b;
      if( a == 1 ) {
	if( f == 0 ) {
	  deq.push_front(b);
	} else {
	  deq.push_back(b);
	}
      } else {
	if( f == 1 ) {
	  deq.push_front(b);
	} else {
	  deq.push_back(b);
	}
      }	
    }
  }
  if( f ) reverse(ALL(deq));
  rep(i,(int)deq.size()) cout <<deq[i]; puts("");
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int m, d;
  cin >> m >> d;
  int ans = 0;
  for (int j = 1; j <= m; ++j) {
    for (int i = 1; i <= d; ++i) {
      int d1 = i % 10;
      int d2 = i / 10;
      if(d1 >= 2 && d2 >= 2 && d1 * d2 == j) ++ans;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=["."+input()+"." for i in range(h)]
s=["."*(w+2)]+s+["."*(w+2)]
flag=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]=="#":
      if s[i-1][j]=="." and s[i+1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
        flag=1
print("Yes" if flag==0 else "No")

Measured memory_bytes: 3064
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		main.solve(sc);
		sc.close();
	}

	void solve(Scanner sc) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		char[][] S = new char[H][W];
		String[][] T = new String[H][W];

		for (int i = 0; i < H; i++) {
			String l = sc.next();
			S[i] = l.toCharArray();
		}

		for (int h = 0; h < H; h++) {
			char[] line = S[h];
			for (int w = 0; w < W; w++) {
				if (line[w] == '#') {
					T[h][w] = Character.toString(line[w]);
				} else {
					T[h][w] = Integer.toString(calc(S, h, w, H, W));
				}
				System.out.print(T[h][w]);
			}
			System.out.println();
		}
	}

	int calc(char[][] S, int h, int w, int H, int W) {
		int cnt = 0;

		if (h >= 1 && w >= 1 && S[h - 1][w - 1] == '#') {
			cnt++;
		}
		if (h >= 1 && S[h - 1][w] == '#') {
			cnt++;
		}
		if (h >= 1 && w < W - 1 && S[h - 1][w + 1] == '#') {
			cnt++;
		}
		if (w >= 1 && S[h][w - 1] == '#') {
			cnt++;
		}
		if (w < W - 1 && S[h][w + 1] == '#') {
			cnt++;
		}
		if (h < H-1 && w >= 1 && S[h + 1][w - 1] == '#') {
			cnt++;
		}
		if (h < H-1 && S[h + 1][w] == '#') {
			cnt++;
		}
		if (h < H-1 && w < W - 1 && S[h + 1][w + 1] == '#') {
			cnt++;
		}
		return cnt;
	}
}


Measured memory_bytes: 21972
let main () =
  let n = Scanf.scanf "%d\n" Batteries.identity in
  let xs : int array = Array.make n 0 in
  for i = 0 to n - 2 do
    xs.(i) <- Scanf.scanf "%d " Batteries.identity;
  done;
  xs.(n-1) <- Scanf.scanf "%d\n" Batteries.identity;
  Array.sort BatInt.compare xs;
  let alice, bob, _ = Array.fold_right (fun elm (a, b, t) -> if t then (a + elm, b, not t) else (a, b + elm, not t)) xs (0, 0, true) in
  Printf.printf "%d\n" (alice - bob)

let _ = main ()


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define maxn 4002
using namespace std;
inline int read()
{
	char x = getchar();
	int lin = 0, f = 1;
	while(x < '0' || x > '9')
	{
		if(x == '-') f = -1;
		x = getchar();
	}
    while(x >= '0' && x <= '9')
	{
		lin = lin * 10 + x - '0';
		x = getchar();
	}
	return lin * f;
}
#define PII pair<int,int>
#define fir first
#define sec second
#define ma(a,b) make_pair(a,b)
int head[maxn],tot,u,v,n,k,ans = 3000,k1[maxn],k2[maxn];
struct st{
	int v,nex;
}s[maxn];
void add(int u,int v)
{
	s[++tot] = (st) { v,head[u] };
	head[u] = tot;
}
int dfs(int now,int fa,int len)
{
	if(len < 0) return 0;
	if(!len) return 1;
	int t = 1;
	for(int i = head[now]; i; i = s[i].nex)
		if(s[i].v != fa)
			t += dfs(s[i].v,now,len - 1);
	return t;
}
int query(int now,int len)
{
	int t = 1;
	for(int i = head[now]; i; i = s[i].nex)
		t += dfs(s[i].v,now,len - 1);
	return t;
}
int main(){
	n = read(); k = read();
	for(int i = 1; i < n; i++)
	{
		u = read(); v = read();
		add(u,v);
		add(v,u);
	}
	if(k & 1)
	{
		for(int i = 1; i <= n; i++)
		{
			int t = 1;
			for(int j = head[i]; j; j = s[j].nex)
			{
				k1[j] = dfs(s[j].v,i,k / 2 - 1);
				k2[j] = dfs(s[j].v,i,k / 2);
				t += k1[j];
			}
			for(int j = head[i]; j; j = s[j].nex)
			{
				t = t - k1[j] + k2[j];
				ans = min(ans,n - t);
				t = t - k2[j] + k1[j];
			}
		}
	}
	else
	{
		for(int i = 1; i <= n; i++)
			ans = min(ans,n - query(i,k / 2));
	}
	if(ans == 3000) cout << 0;
	else cout << ans;
}

Measured memory_bytes: 384
// ALDS1_12_C: Single Source Shortest Path II
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#define NIL -1
#define INF 1000000
using intpair = std::pair<int,int>;
bool debug = false;

std::vector<std::vector<intpair>> adjacency_list; // pair = (vertex_num, weight)
std::vector<bool> node_stat;
std::vector<int> minimum_cost;
std::priority_queue<intpair, std::vector<intpair>, std::greater<intpair>> que; // pair = (weight, vetrex_num)

void dijkstra(int vertex) {
    if (debug) std::cout << "dijkstra(" << vertex << ")\n";
    // 1. mark as visited
    node_stat.at(vertex) = false;

    // 2. push weights into priority queue.
    for (int i=0; i<adjacency_list.at(vertex).size(); i++) {
        int next = adjacency_list.at(vertex).at(i).first;
        int edge_weight = adjacency_list.at(vertex).at(i).second;
        int weight = minimum_cost.at(vertex) + edge_weight;

        if (debug) std::cout << "next = " << next << ", weight = " << weight << "\n";
        intpair tmp = std::make_pair(weight, next);
        que.push(tmp);
    }

    // 3. get appropriate next_vertex and determine minimum_cost(next_vertex)
    int next = NIL;
    int size = que.size(); // do NOT use .size() when it can change!!!!!!
    for (int i=0; i<size; i++) {
        int cost = que.top().first, next_vertex = que.top().second;
        que.pop(); 
        if (node_stat.at(next_vertex)) {
            if (cost < minimum_cost.at(next_vertex)) {
                minimum_cost.at(next_vertex) = cost;
                next = next_vertex;
                break;
            }
        }
    }
    // 4. end of recursion
    if (next == NIL) return;

    // 5. recurving
    dijkstra(next);
}

int main() {
    int total_node_num; std::cin >> total_node_num;
    adjacency_list.resize(total_node_num);
    node_stat.assign(total_node_num, true);
    minimum_cost.assign(total_node_num, INF);
    minimum_cost.at(0) = 0;

    for (int i=0; i<total_node_num; i++) {
        int vertex, outdegree; std::cin >> vertex >> outdegree;
        for (int j=0; j<outdegree; j++) {
            std::pair<int,int> tmp; std::cin >> tmp.first >> tmp.second;
            adjacency_list.at(vertex).push_back(tmp);
        }
    }

    dijkstra(0);
    for (int i=0; i<minimum_cost.size(); i++) {
        std::cout << i << " " << minimum_cost.at(i) << "\n";
    }
}


Measured memory_bytes: 11724
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

string sortString(string &str) 
{ 
     sort(str.begin(), str.end()); 
     return str;
}

int main(){
  I n;
  cin >> n;
  vector<string> v(n);
  REP(i,n){
    cin >> v.at(i);
    v.at(i) = sortString(v.at(i));
  }
  SORT(v);
  string now;
  I t=0;
  I an=0;
  REP(i,n){
    if (now == v.at(i)){
      t++;
    }else{
      if (t>0){
        an += t * (t+1) / 2;
        t=0;
      }else{
        t=0;
      }
    }
    now = v.at(i);
  }
      if (t>0){
        an += t * (t+1) / 2;
        t=0;
      }else{
        t=0;
      }
  cout << an << endl;
  return 0;
}



Measured memory_bytes: 5760
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

ll gcd(ll a, ll b){
    if(a % b == 0){
        return(b);
    }
    else{
        return(gcd(b, a % b));
    }
}

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

int N, M, K, Q, i, j, k, l, tmp, ans;

int main(){
    cin >> N;
    cin >> K;
    vector<int> p(N, 0);
    REP(i, N){
        cin >> p.at(i);
    }
    sort(ALL(p));
    
    REP(i, K){
        ans += p.at(i);
    }

    cout << ans;
    cout << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	int N, D; cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(D));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++)cin >> X[i][j];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			double x = 0;
			for (int k = 0; k < D; k++) {
				x += pow(X[i][k] - X[j][k], 2);
			}
			if (sqrt(x) == (int)sqrt(x))ans++;
		}
	}
	cout << ans << endl;
}





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

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<int> cnt(n + 1, 0);
    for(int i = 2; i <= n; ++i){
        int a;
        cin >> a;
        ++cnt[a];
    }
    for(int i = 1; i <= n; ++i) cout << cnt[i] << '\n';
}

Measured memory_bytes: 3960
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;

vector<vector<int> >g;
int n,m,q,s,t;

vector<bool>visited;
vector<int>color;
void dfs(int s){
    for(int i=0;i<g[s].size();i++){
        if(color[g[s][i]]==-1){
            color[g[s][i]]=color[s];
            dfs(g[s][i]);
        }
    }
}
bool dfs2(int s,int t){
    if(s==t)return true;
    visited[s]=true;
    for(int i=0;i<g[s].size();i++){
        if(!visited[g[s][i]]){
            if(dfs2(g[s][i],t)){
                return true;
            }
        }
    }
    return false;
}
int main() {
    scanf("%d %d",&n,&m);
    g.resize(n);
    color.resize(n,-1);
    for(int i=0;i<m;i++){
        scanf("%d %d",&s,&t);
        g[s].push_back(t);
        g[t].push_back(s);
    }
    for(int i=0;i<n;i++){
        if(color[i]==-1){
            color[i]=i;
            dfs(i);
        }
    }
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d %d",&s,&t);
        visited.resize(n,false);
        string s1=(dfs2(s,t)?"yes":"no");
        string s2=(color[s]==color[t]?"yes":"no");
        if(s1!=s2&&s1=="yes")return 1;
        printf((color[s]==color[t]?"yes\n":"no\n"));
    }
    return 0;
}

Measured memory_bytes: 11388
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

/* Node treeMinimum(Node x){ */


/* } */

/* Node treeSearch(Node u, int k){ */


/* } */

/* Node treeSuccessor(Node x){ */


/* } */

/* void treeDelete(Node z){ */
/*   Node y; // node to be deleted */
/*   Node x; // child of y */



/* } */

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if((z->key) < (x->key)) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if((z->key) < (y->key)) y->left = z;
  else y->right = z;

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}


int main(){
  int n, i, x;
  char command[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", command);
/*     if ( command[0] == 'f' ){ */
/*       scanf("%d", &x); */
/*        Node t = treeSearch(root, x); */
/*       if ( t != NIL ) printf("yes\n"); */
/*        else printf("no\n"); */
/*     }  */
    if ( command[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( command[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
/*     else if ( command[0] == 'd' ){ */
/*       scanf("%d", &x); */
/*       treeDelete(treeSearch(root, x)); */
/*     } */
  }

  return 0;
}

Measured memory_bytes: 24040
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  
  vector<int> a(3);
  
  REP(i,3) cin >> a[i];
  
  sort(a.begin(), a.end());
  
  int ans = 0;
  if((a[2] - a[1]) % 2 == 0 &&(a[2] - a[0]) % 2 == 0){
    ans += (a[2] - a[1]) / 2 + (a[2] - a[0]) / 2;
  }
  else if((a[2] - a[1]) % 2 == 1 &&(a[2] - a[0]) % 2 == 1){
    int n = (a[2] - a[1]) / 2;
    int m = (a[2] - a[0]) / 2;
    ans += n + m + 1;
  }
  else{
    int n = (a[2] - a[1]) / 2;
    int m = (a[2] - a[0]) / 2;
    ans += n + m + 2;
  }
          
          
  cout << ans << endl;
  
}

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

signed main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    bool yes = true;
    rep(i,n-1){
        if (a[i] == a[i+1]){
            yes = false;
            break;
        }
    }
    if (yes) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){

    char str[3];
    scanf("%s",str);

    if('R' == str[1]){
        printf("ABC\n");
    }else if('B' == str[1]){
        printf("ARC\n");
    }else{
        printf("Error\n");
    }

    return 0;
}

Measured memory_bytes: 1620
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    cout << a / b << ' ' << a % b << ' ' ;
    double f=1.0*a/b;
    printf("%6lf\n",a*1.0/b);
}



Measured memory_bytes: 3224
X,Y = map(int,input().split())
mod = pow(10,9)+7
n,m = -1,-1
for i in range(X+1):
    if (X-i)==2*(Y-2*i):
        n,m = i,Y-2*i
if n==-1:print(0)
else:
    a,b,m = 1,1,n+m
    for i in range(1,n+1):
        a=(a*m)%mod
        b=(b*i)%mod
        m-=1
    b = pow(b,mod-2,mod)
    print((a*b)%mod)

Measured memory_bytes: 3064
import sys
input = lambda :sys.stdin.readline().rstrip()

N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))

if x > sum(A):
  cnt = -1
else:
  cnt = 0
  
for i in range(N):
    if x - A[i] >= 0:
        cnt += 1
        x -= A[i]
    if x <= 0:
        break
    #print(cnt, x)

print(cnt)

Measured memory_bytes: 9132
N,T = map(int,input().split())
CT = []
for n in range(N):
  c,t = map(int,input().split())
  CT.append([c,t])
CT = sorted(CT,key=lambda x: x[0])
ans = True
for ct in CT:
  if ct[1] <= T:
    print(ct[0])
    ans = False
    break
if ans:
  print("TLE") 


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

ll gcd(ll a, ll b){
  if(b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b){return a/gcd(a, b)*b;}
ll num(ll N, ll a, ll b){
  ll na = N / a;
  ll nb = N / b;
  ll nab = N / lcm(a, b);
  return N - na - nb + nab;
}
int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << num(b, c, d) - num(a-1, c, d) << endl; 
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (((ll)1<<31)-1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0;
using namespace std;
signed main(){
    string s;
    while(getline(cin,s)){
        rep(i,26){
            bool flag=false;
            string t="";
            rep(j,s.size()){
                if(isalpha(s[j]))t=t+(char)('a'+(s[j]-'a'+i)%26);
                if(s[j]==' '){
                    if(t=="the"||t=="this"||t=="that"){
                        flag=true;
                        break;
                    }
                    t="";
                }
            }
            if(flag){
                rep(j,s.size()){
                    if(isalpha(s[j]))cout<<(char)('a'+(s[j]-'a'+i)%26);
                    else cout<<s[j];
                }
                cout<<endl;
                goto kaage;
            }
        }
        kaage:;
    }
    ggr;
}


Measured memory_bytes: 3048
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ll long long int
#define PI 3.141592653589793
using namespace std;

int main() {
    int N, ans;
    string S,T;

    cin >> N >> S >> T;
    REP(i,N) cout << S[i] << T[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    int a;
    cin >> n >> a;
    cout << n * n - a;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX_LEN 1001
 
int LCS_length(char *, char *);
 
int C[MAX_LEN][MAX_LEN];
 
int main()
{
    int n;
    int i;
    char S1[MAX_LEN], S2[MAX_LEN];
     
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%s", S1);
        scanf("%s", S2);
         
        printf("%d\n", LCS_length(S1, S2));
    }
    return 0;
}
 
int LCS_length(char *S1, char *S2)
{
    int i, j;
    int S1_len, S2_len;
 
    S1_len = strlen(S1);
    S2_len = strlen(S2);
 
    for(i = 0; i < S1_len; i++)
    {
        C[i][0] = 0;
    }
    for(j = 0; j < S2_len; j++)
    {
        C[0][j] = 0;
    }
 
    for(i = 1; i <= S1_len; i++)
    {
        for(j = 1; j <= S2_len; j++)
        {
            if(S1[i - 1] == S2[j - 1])
            C[i][j] = C[i - 1][j - 1] + 1;
             
            else if(C[i - 1][j] >= C[i][j - 1])
            C[i][j] = C[i - 1][j];
             
            else
            C[i][j] = C[i][j - 1];
        }
    }
    return C[S1_len][S2_len];
}

Measured memory_bytes: 4524
#include <iostream>
#include <string>
#include <sstream>
int main(){
    std::string a,b;
    std::cin>>a>>b;

    if(a.size()!=b.size()){
        if(a.size()>b.size())std::cout<<"GREATER";
        else std::cout<<"LESS";
    }else{
        int i=0;
        for(;i<a.size();++i){
            if(a[i]>b[i])
            {
                 std::cout<<"GREATER";
                 break;
            }
            else if(a[i]<b[i]){
                 std::cout<<"LESS";
                 break;
            }
        }
        if(i==a.size()&&a[i]==b[i]) std::cout<<"EQUAL";

    }
    std::cout<<std::endl;
}

Measured memory_bytes: 256
import fractions


a, b, c, d = list(map(int, input().split()))

def lcm(x, y):
    return x * y // fractions.gcd(x, y)

def get_num(x):
    ans = x - x // c - x // d + x // lcm(c, d)
    return ans


print(get_num(b) - get_num(a -1))


Measured memory_bytes: 5304
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		int[] arg =new int[100];
        int i=0,sum=0,n=0,m=0;
        int[] dist=null,weather=null;
        int state=0;

        int[] k=new int[5];
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null) {
                k[0]=Integer.parseInt(line);
                k[1]=Integer.parseInt(br.readLine());
                k[2]=Integer.parseInt(br.readLine());
                k[3]=Integer.parseInt(br.readLine());
                k[4]=Integer.parseInt(br.readLine());
                if(k[0]<0){
                	System.out.println(Math.abs(k[0])*k[2]+k[3]+k[1]*k[4]);
                }else{
                	System.out.println((k[1]-k[0])*k[4]);
                }
                break;
            }
        }
	}

}

Measured memory_bytes: 24156
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int a[200005];
int b[200005];
int n;
map<int,int> mp;
bool check(int mid){
	mp.clear();
	for(int i=1;i<n;i++){
		if(a[i]>a[i-1]) continue;
		mp.erase(mp.upper_bound(a[i]),mp.end());
		int j;
		for(j=a[i];j>0;j--){
			if(mp[j]<mid){
				mp[j]++;
				break;
			}
			mp.erase(mp.find(j));
		}
		if(j==0) return 0;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	bool flag=0;
	for(int i=0;i<n-1;i++) if(a[i]>=a[i+1]) flag=1;
	if(!flag){
		cout<<1;
		return 0;
	}
	int l=1,r=n,res=-1;
	while(l<=r){
		int mid=l+r>>1;
		if(!check(mid)){
			l=mid+1;
		}
		else {
			res=mid;
			r=mid-1;
		}
	}
	cout<<res+1;
}

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

int main () {
	int n, s;
	while (cin >> n >> s, n || s) {
		int r[n];
		for (int i = 0; i < n; i++) {
			cin >> r[i];
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (r[i] + r[j] > s) {
					count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    string S, T;
    cin >> S >> T;
    i32 sum = 0;
    for (i32 i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) sum++;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
 
const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x( (x%mod + mod) % mod ) {}
    mint operator-() const { return mint(-x); }
    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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
 
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
 
int main() {
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  mint ans = 0;
  vector<mint> q(s+1);
  q[0] = 1;
  rep(i,n) {
    {
      vector<mint> q2(s+1);
      rep(j,s+1) {
        q2[j] += mint(2)*q[j];
        if (j + a[i] <= s) q2[a[i] + j] += q[j];
      }
      q = q2;
    }
  }
  cout << q[s] << endl;
  return 0;
}

Measured memory_bytes: 3684