akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int used[16] = {0};

inline int dfs(int step, int s)
{
	int i, res;

	if (!step) return (s == 0);
	if (s < 0) return (0);
	if (s > (step * (step + 1)) / 2 * 9) return (0);
	
	res = 0;
	for (i = 0; i <= 9; ++i){
		if (!used[i]){
			used[i] = 1;
			res += dfs(step - 1, s - (i * step));
			used[i] = 0;
		}
	}
	return (res);
}

int main(int argc, char const *argv[])
{
	int n, v;

	while (~scanf("%d %d", &n, &v)){
		printf("%d\n", dfs(n, v));
	}
	return (0);
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <set>
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;

int main(){
    int n,a,b;
    cin >> n>>a>>b;
    cout<<min(n*a,b)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli x,a,b;
    lli i,j;
    cin>>x;
    rep(i,-200,200){
//        cout<<i<<"の時 "<<x<<"+"<<i<<"の5乗"<<pow(i,5)<<"を足した"<<pow(i,5)+x<<"の5乗根は"<<endl;
        double c=pow(pow(i,5)+x,1.0/5.0);
        c*=10000;
        c=round(c);
        c/=10000;
//        cout<<c<<endl;
        if(floor(c)==ceil(c)){
            b=i;
            a=pow(pow((double)b,5.0)+(double)x,0.2);
            if(pow((double)a,5.0)-pow((double)b,5.0)==x){
                cout<<a<<" "<<b<<endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 4116
#include <iostream>
#include <cstdio>
int main(void){
    int h,m,s,h3,m3,s3;
    int t,t3;
    while(std::cin>>h>>m>>s,h!=-1||m!=-1||s!=-1){
        t=7200;
        t=t-(h*3600+m*60+s);
        t3=t*3;
        h=t/3600;t%=3600;h3=t3/3600;t3%=3600;
        m=t/60;t%=60;m3=t3/60;t3%=60;
        s=t;s3=t3;
        printf("%02d:%02d:%02d\n",h,m,s);
        printf("%02d:%02d:%02d\n",h3,m3,s3);
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
int main(){
  char s[100002];
  int alphabet[27];
  scanf("%s",s);
  int len=strlen(s),i;
  for(i=0;i<26;i++)
    alphabet[i]=0;
  for(i=0;i<len;i++)
    alphabet[s[i]-'a']++;
  for(i=0;i<26;i++)
    if(alphabet[i]==0){
      printf("%c\n",'a'+i);
      return 0;
    }
  puts("None");
  return 0;
}


Measured memory_bytes: 1796
//WA 2
#include <bits/stdc++.h>
 
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ii pair<int,int>
#define qu queue <int>
#define qmax priority_queue <int>
#define qmin priority_queue <int, vector<int>,greater<int>>

using namespace std;

int solve(int k, vector<int>& xs){
    //ordena os números
    sort(xs.begin(), xs.end());

    //Multiplica o maior deles por 2, K vezes (lembrar que tá ordenado)
    xs.back() *= (1 << k); // no primeiro teste k = 0001 shiftado 1 que vez pra esquerda fica 0010

    //Soma todos os números
    return accumulate(xs.begin(), xs.end(), 0); // accumulate(first, last, sum); first, last : first and last elements of range whose elements are to be added sum : initial value of the sum.
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    vector<int> xs(3);

    for(int i=0; i<3; i++)
        cin>>xs[i];
    
    int k;
    cin>>k;

    auto ans = solve(k, xs);

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int n ,  a[101] , x;
int main()
{
    cin >> n >> x;
    for(int i = 1 ; i <= n ; ++i)
        cin >> a[i];
    sort(a + 1 , a + n + 1);
    int cnt = 0;
    for(int i = 1 ; i <= n ; ++i)
        if(a[i] <= x)x -= a[i] , ++cnt;
    if(x > 0 && cnt == n)--cnt;
    cout << cnt;
}


Measured memory_bytes: 256
from collections import deque
d = deque()
for _ in range(int(input())):
  a = input()
  if "i" == a[0]: d.appendleft(int(a[7:]))
  elif "F" == a[6]: d.popleft()
  elif "L" == a[6]: d.pop()
  else:
    try: d.remove(int(a[7:]))
    except: pass
print(*d)


Measured memory_bytes: 45948
#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<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

vector<P> factor(int n) {
  vector<P> res;
  for (int i = 2; i * i <= n; ++i) {
    if(n % i) continue;
    res.emplace_back(i, 0);
    while(n % i == 0) {
      res.back().second++;
      n /= i;
    }
  }
  if(n != 1) res.emplace_back(n, 1);
  return res;

}

int main() {
  int n;
  cin >> n;
  vector<int> cnt(n + 1);

  for(int i = 1; i <= n; ++i) {
    auto f = factor(i);
    for (P p : f) {
      cnt[p.first] += p.second;
    }
  }
  ll ans = 1;
  for(int i = 1; i <= n; ++i) {
    ans *= cnt[i] + 1;
    ans %= mod;
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

char S[SIZE];

int main(){
  ll M;
  int N;

  scanf("%lld%s", &M, S);

  N = strlen(S);

  ll sum[10] = {};

  for(int i=0; i<N; i++) {
    for(int j=0; j<10; j++) sum[j] = sum[j]*10 % mod;

    sum[S[i]-'0']++;
  }

  int per[10];

  iota(per, per+10, 0);

  bool ok = false;

  do{
    ll v = 0;

    if (per[S[0]-'0'] == 0 && N != 1) continue;

    for(int i=0; i<10; i++) {
      v = (v + sum[i] * per[i]) % mod;
    }

    if (v == M) {
      ok = true;
      break;
    }

  }while(next_permutation(per, per+10));

  if (ok) {
    for(int i=0; i<N; i++)
      printf("%d", per[S[i]-'0']);
    puts("");
  } else {
    puts("-1");
  }

  return 0;
}



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

#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007

int main(){
	fast;
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x)
        cout<<(n/x + 1)*t;
    else
        cout<<(n/x)*t;
	return 0;
}



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

int main() {
  	int k;
  	string s,ans;
  
  	cin >> k >> s;

  	if (s.length() <= k)
      ans=s;
  	else
      ans=s.substr(0,k) + "...";
  
  	cout << ans << endl;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v[n];
    for(int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int ans = 1<<30;
    if(k%2){
        for(int i = 0; i < n; i++){
            for(int j : v[i]){
                int cnt = 2;
                queue<int> q;
                vector<int> d(n, 1<<30);
                d[i] = d[j] = 0;
                q.push(i);  q.push(j);
                while(!q.empty()){
                    int x = q.front();  q.pop();
                    if(d[x] == k/2) continue;
                    for(int next : v[x]){
                        if(d[next] != 1<<30)    continue;
                        d[next] = d[x]+1;
                        cnt++;
                        q.push(next);
                    }   
                }
                ans = min(ans, n-cnt);
            }
        }
    }else{
        for(int i = 0; i < n; i++){
            int cnt = 1;
            queue<int> q;
            vector<int> d(n, 1<<30);
            d[i] = 0;
            q.push(i);
            while(!q.empty()){
                int x = q.front();  q.pop();
                if(d[x] == k/2) continue;
                for(int next : v[x]){
                    if(d[next] != 1<<30)    continue;
                    d[next] = d[x]+1;
                    cnt++;
                    q.push(next);
                }
            }
            ans = min(ans, n-cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<long> p(N);
  for(int i=0;i<N;i++) cin>>p[i];
  for(int i=0;i<N;i++) p[i]--;
  int ans=0;
  for(int i=0;i<N-1;i++){
    if(p[i]==i){
      int tmp = p[i+1];
      p[i+1]=p[i];
      p[i]=tmp;
      ans++;
    }
  }
  if(p[N-1]==N-1) ans++;
  cout<<ans<<endl;

  }


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <cmath>
#include <stdio.h>
using namespace std;

typedef pair<double,double> P;
typedef pair<P,double> PP;
int N;

double xs,ys,xt,yt;
double x,y,r;

double dist(P a, P b){
	return sqrt((a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second));
}
vector<PP> zahyou(1002);
int main(){
	cin >> xs >> ys >> xt >> yt;
	cin >> N;
	zahyou[0] = PP(P(xs,ys),0);
	zahyou[N+1] = PP(P(xt,yt),0);
	for(int i=1;i<=N;i++){
		cin >> x >> y >> r;
		zahyou[i] = PP(P(x,y),r);
	}
	vector<vector<pair<double,int>>> v(N+2);
	for(int i=0;i<N+1;i++){
		for(int j=i+1;j<N+2;j++){
			double d = dist(zahyou[i].first,zahyou[j].first);
			//cout << d << endl;
			v[i].push_back(make_pair(max(0.0,d-zahyou[i].second-zahyou[j].second),j));
			v[j].push_back(make_pair(max(0.0,d-zahyou[i].second-zahyou[j].second),i));
		}
	}
	priority_queue<pair <double,int> > P;
	P.push(make_pair(0,0));
	double C[N+2];
	double inf = 1e10;
	for(int i=0;i<N+2;i++){
		C[i] = inf;
	}
	C[0] = 0;
	while(!P.empty()){
		pair<double,int> t = P.top();
		int s = t.second;
		P.pop();
		if(C[s] < t.first) continue;
		for(int i=0;i<v[s].size();i++){
			pair<double,int> e = v[s][i];
			if(C[e.second] > C[s] + e.first){
				C[e.second] = C[s] + e.first;
				P.push(make_pair(-C[e.second],e.second));
			}
		}
	}
	printf("%.9f\n",C[N+1]);
}


Measured memory_bytes: 22768
import java.io.*;


public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in = br.readLine().split(" ");
    long H = Long.parseLong(in[0]);
    long W = Long.parseLong(in[1]);
    br.close();

    if(H == 1 || W == 1){
      System.out.println(1);
    }else{
      System.out.println((H * W + 1) / 2);
    }
  }
}


Measured memory_bytes: 20308
import math
s = list(input()) + ['R', ]
n = len(s) - 1
def num_ab(a, b, n):
    if n % 2 == 0:
        return math.ceil((b - 1) / 2) + 1 - (math.ceil((a - 2) / 2) + 1)
    else:
        return (b + 1) // 2 + 1 - (a // 2 + 1)
sections = []
destinations = []
sec_l = 0
sec_r = 0
for i in range(n):
    if s[i] == 'R' and s[i + 1] == 'L':
        destinations.append([i, i + 1])
    elif s[i] == 'L' and s[i + 1] == 'R':
        sec_r = i
        sections.append([sec_l, sec_r])
        sec_l = i + 1
ans = ['0'] * n
for sec, des in zip(sections, destinations):
    for d in des:
        ans[d] = str(num_ab(sec[0], sec[1], d))
print(' '.join(ans))

Measured memory_bytes: 27640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int a[][][] = new int[4][3][10];
		int i;
		for(i=0;i<n;i++) {
			int b=scan.nextInt();
			int f=scan.nextInt();
			int r=scan.nextInt();
			int v=scan.nextInt();
			a[b-1][f-1][r-1] +=v;
		}
		for(int b=0;b<4;b++) {
			for(int f=0;f<3;f++) {
				for(int r=0;r<10;r++) {
					System.out.print(" "+ a[b][f][r]);
				}
				System.out.println();
			}
			if(b<3)
				System.out.println("####################");
			}
		scan.close();
}
}


Measured memory_bytes: 29964
#include<stdio.h>

int main(){
	int i,j,max,max_j,buf;
	int io[5];
	scanf("%d %d %d %d %d",&io[0],&io[1],&io[2],&io[3],&io[4]);
	for(i=0;i<5;i++){
		max=io[i];
		max_j=i;
		for(j=i+1;j<5;j++){
			if(max<io[j]){
				max=io[j];
				max_j=j;
			}
		}
		buf=io[i];
		io[i]=io[max_j];
		io[max_j]=buf;
		i<4?printf("%d ",io[i]):printf("%d\n",io[i]);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point {
    public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) { return Point(x + p.x, y + p.y); }
    Point operator - (Point p) { return Point(x - p.x, y - p.y); }
    Point operator * (double a) { return Point(x * a, y * a); }
    Point operator / (double a) { return Point(x / a, y / a); }

    double norm() { return x * x + y * y; }
    double abs() { return sqrt(norm()); }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};

struct Segment {
    Point p1, p2;
};

typedef Point Vector;
typedef Segment Line;

double dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
    return a.x * b.y - a.y * b.x; 
}

bool isOrthogonal(Vector a, Vector b) {
    return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
    return isOrthogonal(a1 - a2, b1 - b2);
}

bool isOrthogonal(Segment s1, Segment s2) {
    return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

bool isParallel(Vector a, Vector b) {
    return equals(cross(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2) {
    return isParallel(a1 - a2, b1 - b2);
}

bool isParallel(Segment s1, Segment s2) {
    return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

Point project(Segment s, Point p) {
    Vector base = s.p2 - s.p1;
    double r = dot(p - s.p1, base) / base.norm();
    return s.p1 + base * r;
}

Point reflect(Segment s, Point p) {
    return p + (project(s, p) - p) * 2.0;
}

int main()
{
    int q;
    double x1, x2, x3, y1, y2, y3;
    Segment s;

    cin >> x1 >> y1 >> x2 >> y2;
    s.p1 = Point(x1, y1);
    s.p2 = Point(x2, y2);
    
    cin >> q;
    for (int i = 0; i != q; ++i)
    {
        cin >> x3 >> y3;
        Point p3 = Point(x3, y3);
        Point e = reflect(s, p3);
        cout << fixed << setprecision(10) << e.x << " " << e.y << endl;
    }
    return 0;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    string s; cin >> s;
    int n = s.size();
    int ans = 0;
    int nump = 0;
    rep(i,n){
        if(s[i] == 'g'){
            if(nump > 0){
                ans++;
                nump--;
            }
            else nump++;
        }
        else{
            if(nump > 0) nump--;
            else{
                ans--;
                nump++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<set>
#include<queue>
using namespace std;

struct edge
{
	int to,color;
};

vector<edge> w[100010];
int n,m,d[100010];
set<int> s[100010];

int main()
{
	cin>>n>>m;
	while(m--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		w[a].push_back({b,c});
		w[b].push_back({a,c});
	}
	d[1]=0;
	for(int i=2; i<=n; i++)
	d[i]=0x3f3f3f3f;
	priority_queue<pair<int,int>> q;
	q.push({-d[1],1});
	while(q.size())
	{
		int now=q.top().second,cost=-q.top().first;
		q.pop();
		if(d[now]<cost) 
		continue;
		for(edge j:w[now])
		{
			int dist=d[now];
			if(!s[now].count(j.color)) 
			dist++;
			if(dist<d[j.to])
			{
				d[j.to]=dist;
				s[j.to].clear();
				s[j.to].insert(j.color);
				q.push({-d[j.to],j.to});
			}
			else if(dist==d[j.to])
			s[j.to].insert(j.color);
		}
	}
	if(d[n]>4e5)cout<<-1<<endl;
	else cout<<d[n]<<endl;
	return 0;
}


Measured memory_bytes: 23412
a,b,x=map(int,input().split())

import math
if a**2*b/2 >= x:
    h=x*2/a/b
    ans=math.degrees(math.atan(b/h))
else:
    h=b-(x-a**2*b/2)*2/(a**2)
    ans=math.degrees(math.atan(h/a))
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <math.h> 
#include <vector>
#include <algorithm>
#include <iomanip>      // std::setprecision
#include <map>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int min = 2000000;
	int sol = 0;
	for (int i = 0; i < N; ++i)
	{
		int num;
		cin >> num;
		if (num < min)
		{
			sol++;
			min = num;
		}
	}
	std::cout << sol << std::endl;
}

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


int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n)
    cin >> a[i];
  int ans = 0;
  int id = 0;
  int i = 1;
  while (true)
  {
    while (id < n && a[id] != i)
    {
      id++;
      ans++;
    }
    if (id == n)
      break;
    i++;
    id++;
  }
  if (i == 1)
    puts("-1");
  else
    cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        x: usize,
    }

    const MAX_X: usize = 200;

    let mut p = vec![0; MAX_X+1];
    for i in 0..=MAX_X {
        p[i] = i*i*i*i*i;
    }

    for i in 0..=MAX_X {
        for j in 0..=i {
            if p[i] - p[j] == x {
                println!("{} {}", i, j);
                return;
            }
            if p[i] + p[j] == x {
                println!("{} -{}", i, j);
                return;
            }
        }
    }
}


Measured memory_bytes: 2092
import math

n,d=map(int,input().split())
li=[]
for i in range(n):
  li.append(list(map(int,input().split())))

count=0
for i in range(n-1):
  for j in range(i+1,n):
    num=0
    for k in range(d):
      num+=(li[i][k]-li[j][k])**2
    num=math.sqrt(num)
    if num%1==0:
      count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>

int main() {
  int N, K;

  std::cin >> N >> K;

  double ans = 0;

  for (int i=1; i<=N; i++) {
    double a = 1.0/N;
    for (int j=i; j<K; j<<=1) {
      a *= 0.5;
    }
    ans += a;
  }

  std::cout << std::setprecision(10) << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }
    sort(p.begin(),p.end());
  p.at(N-1) /= 2;
  int sum=0;
  for(int i=0;i<N;i++){
    sum += p.at(i);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
import collections
import itertools as it
import math
import numpy as np

# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

X = int(input())
nshohin = X // 100
amari = X % 100

print(0 if nshohin * 5 < amari else 1)

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

int main() {
	int H, W;
	string S[50];
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') {
				int count = 0;
				for (int x = i - 1; x <= i + 1; x++) {
					for (int y = j - 1; y <= j + 1; y++) {
						if (x != -1 && x != H && y != -1 && y != W && S[x][y] == '#') count++;
					}
				}
				cout << count;
			}
			else cout << "#";
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;

class D
{
	static long[] Read() => Console.ReadLine().Split().Select(long.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		long n = h[0], k = h[1];
		var a = Read().OrderBy(x => x).ToArray();

		Console.WriteLine(First(-1L << 60, 1L << 60, x => Enumerable.Range(0, (int)n - 1).Sum(i => a[i] >= 0 ? First(i + 1, n, j => a[i] * a[j] > x) - i - 1 : n - 1 - Last(i, n - 1, j => a[i] * a[j] > x)) >= k));
	}

	static long First(long l, long r, Func<long, bool> f)
	{
		long m;
		while (l < r) if (f(m = l + (r - l - 1) / 2)) r = m; else l = m + 1;
		return r;
	}

	static long Last(long l, long r, Func<long, bool> f)
	{
		long m;
		while (l < r) if (f(m = r - (r - l - 1) / 2)) l = m; else r = m - 1;
		return l;
	}
}


Measured memory_bytes: 69352
x, k, d = map(int, input().split())
x = abs(x)
if (x - k*d) >= 0:
    x -= k*d
else:
    k -= int(x/d)
    x -= int(x/d) * d
    if (k%2) != 0:
        x -= d 
print(abs(x))

Measured memory_bytes: 9184
MOD = 10**9 + 7
n = int(input())
A = list(int(x) for x in input().split())
acc = [A[-1]]
for a in reversed(A[:-1]):
    acc.append((acc[-1] + a) % MOD)
acc.reverse()

ans = 0
for i in range(n - 1):
    ans += (A[i] * acc[i + 1]) % MOD
    ans %= MOD
print(ans)


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

using namespace std;

int main(int argc, char const *argv[])
{
    string S, T;
    cin >> S >> T;
    string tmp;
    int l = (int)S.length();
    for (int i = 0; i < l; i++)
    {
        tmp = *(S.end() - 1);
        S.erase(l - 1);
        S.insert(0, tmp);
        if (S == T)
        {
            cout << "Yes" << endl;
            return 0;
        }

    }
    
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N; int M; int R;
	while(~scanf("%d%d%d", &N, &M, &R)) {
		vector<int> d(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &d[i]);
		vector<vi> dist(N, vi(N, INF));
		vector<vpii> adj(N);
		rep(i, M) {
			int a; int b; int c;
			scanf("%d%d%d", &a, &b, &c), -- a, -- b;
			amin(dist[a][b], c);
			amin(dist[b][a], c);
			adj[a].emplace_back(b, c);
			adj[b].emplace_back(a, c);
		}
		rep(i, N) amin(dist[i][i], 0);
		rep(k, N) rep(i, N) rep(j, N)
			amin(dist[i][j], dist[i][k] + dist[k][j]);
		const int T = 15;
		const int X = N + 1;
		vector<vi> dpp(R + 1, vi(X * X * T, -1));
		auto dp = [&dpp, X, T](int r, int i, int j, int t) -> int& {
			return dpp[r][(i * X + j) * T + t];
		};
		dp(0, 0, N, 0) = 0;
		int ans = -1;
		rep(r, R + 1) rep(i, X) rep(j, X) rep(t, T) {
			int x = dp(r, i, j, t);
			if(x == -1) continue;
			if(r + dist[i][N - 1] <= R)
				amax(ans, x);
			if(j != N && t + dist[i][j] >= T) {
				amax(dp(r, i, N, 0), x);
				continue;
			}
			rep(k, N) if(k != i && k != j) {
				int c = dist[i][k];
				if(r + c <= R) {
					if(c >= T)
						amax(dp(r + c, k, N, 0), x + d[k]);
					else
						amax(dp(r + c, k, i, c), x + d[k]);
				}
			}
			if(r + T <= R)
				amax(dp(r + T, i, N, 0), x + d[i]);
			if(j != N) {
				int c = T - dist[i][j];
				if(r + c <= R)
					amax(dp(r + c, j, i, c), x + d[j]);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 59384
#include <cstdio>

int n;

main(){
  scanf("%d", &n);

  if(n==0) return 0;

  int m,e,j,s;
  while(n--){
    scanf("%d%d%d", &m, &e, &j);
    s = m+e+j;
    if(m == 100 || e == 100 || j == 100) puts("A");
    else if(m+e >= 180) puts("A");
    else if(s >= 240) puts("A");
    else if(s >= 210) puts("B");
    else if(s >= 150 && (m >= 80 || e >= 80)) puts("B");
    else puts("C");
  }

  main();
}

Measured memory_bytes: 0
def main():
    n = int(input())
    jobs = []
    for i in range(n):
        a,b = map(int,input().split())
        jobs.append((b,a))

    jobs.sort()

    time = 0

    for i in jobs:
        time += i[1]
        if time > i[0]:
            print('No')
            return

    print('Yes')


main()


Measured memory_bytes: 29440
if __name__ == '__main__':
    A, B, C, D, E, K = int(input()), int(input()), int(input()), int(input()), int(input()), int(input())
    AB, AC, AD, AE = B-A, C-A, D-A, E-A
    BC, BD, BE = C-B, D-B, E-B
    CD, CE = D-C, E-C
    DE = E-D
    if max(AB, AC, AD, AE, BC, BD, BE, CD, CE, DE) <= K:
        print("Yay!")
    else:
        print(":(")


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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b;cin>>a>>b;
  cout<<(b%a==0 ? a+b : b-a)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

typedef long long ll;

using namespace std;

int main(){

    string s;
    cin>>s;

    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]){
        cout<<"Bad"<<endl;
    }
    else{
        cout<<"Good"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.StringTokenizer;

public class Main {
	static long N = 1000000007;

	static long exponentiation(long base, long exp) {
		long t = 1L;
		while (exp > 0) {
			if (exp % 2 != 0)
				t = (t * base) % N;

			base = (base * base) % N;
			exp /= 2;
		}
		return t % N;
	}

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long n = sc.nextLong();
		
		long x = 0;
		
		if(b - 1 > n)
			x = n;
		else
			x = b - 1;
		
		long ans = (long)(Math.floorDiv((a * x) , b));
		System.out.println(ans);
		
		
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 32516
#include <stdio.h>

int main(void) {
	int a, b, c, cnt;

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

	cnt = 3;
	if (a == b) {
		cnt--;
	}
	if (b == c) {
		cnt--;
	}
	if (c == a) {
		cnt--;
	}

	printf("%d\n", cnt ? cnt : 1);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

ll n,k;
double a[200010];

bool check(double x){
    ll count=0;
    for(int i=0;i<n;i++){
        count+=max(ll(0),ll(ceil(a[i]/x)-1));
    }
    if(count<=k) return true;
    return false;
}

double solve(){
    double low=0,high=1e9+1;
    for(int i=0;i<100;i++){
        double mid=(low+high)/2;
        if(check(mid)) high=mid;
        else low=mid;
    }
    return high;
}

int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=ceil(solve());
    cout<<ans<<endl;
}

Measured memory_bytes: 5320
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String s = scan.next();
		String abc ="ABC";
		
		if(s.equals(abc)) {
			System.out.println("ARC");
		}else {
			System.out.println("ABC");
		}
		
	}	
	
	
	//最小公約数
	/*
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	*/
	
}



Measured memory_bytes: 35700
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define endl  '\n'
using namespace std;
const int mod=1e9+7;
const int MAX=1e6+7;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);
  	int x,y;cin>>x>>y;
  	if(y%2==1){
  		cout<<"No";
	  }
  	else if(y<2*x||y>4*x){
  		cout<<"No";
	  }
	  else cout<<"Yes";
  	
    return 0 ;
}


Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N + 1);
  for (int i = 0; i < N + 1; i++) std::cin >> A[i];
  std::vector<int> B(N);
  for (int i = 0; i < N; i++) std::cin >> B[i];
  long long total = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] - B[i] >= 0) {
      A[i] -= B[i];
      total += B[i];
      continue;
    }
    auto rem = B[i] - A[i];
    auto stock = std::min(A[i + 1], rem);
    total += A[i] + stock;
    A[i + 1] -= stock;
  }
  std::cout << total << std::endl;
  return 0;
}


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

#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define A_CODE 65
#define ALPHABET_NUM 26

string str_replace(string input, const int num){
    
    string result = input;
    
    for(int i = 0; i < result.size(); i++){
        result[i] = result[i] + num;
        if(result[i] >= A_CODE + ALPHABET_NUM){
            result[i] = result[i] - ALPHABET_NUM;
        }
//        cout << int(result[i]) << endl;
    }
    
    return result;
}


int main(void){
    // Your code here!
    
    int a;
    string b;
//    cin >> a >> b;
    cin >> a >> b;
    cout << str_replace(b,a) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
int dfs(vector< vector< int > > &G, vector< int > &dp, int x) {
	if (dp[x] != -1)
		return dp[x];
	int ret = -1;
	for (auto j : G[x]) {
		chmax(ret, dfs(G, dp, j));
	}
	ret++;
	return dp[x] = ret;
}
signed main() {
	cin >> N >> M;
	vector< vector< int > > G(N);
	rep(i, M) {
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		G[x].push_back(y);
	}
	vector< int > dp(N, -1);
	int ans = 0;
	rep(i, N) chmax(ans, dfs(G, dp, i));
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

using R = long double;
R sq(R x) { return x*x; }

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

    ll n, k;
    cin >> n;
    k = 1;
    vector<ll> xs(n), ys(n);
    REP(i, n) cin >> xs[i] >> ys[i];

    R ans = LLINF;
    auto check_yx = [&](R y, R x) {
        vector<R> dist(n);
        REP(i, n) dist[i] = sqrt(sq(xs[i]-x)+sq(ys[i]-y));
        sort(ALL(dist));
        R ret = 0;
        FOR(i, n-k, n) ret += dist[i];
        chmin(ans, ret);
        return ret;
    };

    auto check_y = [&](R y) {
        R lb = -1000, ub = 1000;
        REP(i, 80) {
            R m1 = (2*lb+ub)/3, m2 = (lb+2*ub)/3;
            if(check_yx(y, m1) < check_yx(y, m2)) ub = m2;
            else lb = m1;
        }
        return check_yx(y, lb);
    };

    R lb = -1000, ub = 1000;
    REP(i, 80) {
        R m1 = (2*lb+ub)/3, m2 = (lb+2*ub)/3;
        if(check_y(m1) < check_y(m2)) ub = m2;
        else lb = m1;
    }
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#2019/10/17
N, *A = map(int, open(0).read().split())
#print(N, A)

cnt = 0
endFlg = False
while(True):
    #print(A)
    for i in range(N):
        if A[i] % 2 == 0:
            A[i] = A[i] / 2
        else:
            endFlg=True
            break
    if endFlg == True:
        print(cnt)
        break
    else:
        cnt+=1
        

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
#define             ll  long long
#define            ull  unsigned long long
#define            P_B  push_back
#define            M_P  make_pair
#define         DBG(x)  printf("%s %d\n", #x, x)
#define       DBGLL(x)  printf("%s %lld\n", #x, x)
#define         SCI(x)  scanf("%d",&x)
#define         SCD(x)  scanf("%lf",&x)
#define         SCS(x)  scanf("%s",x)
#define         CLR(x)  memset(x, 0, sizeof(x))
#define        CLRN(x)  memset(x, -1, sizeof(x))
#define        SCLL(x)  scanf("%lld", &x)
#define      FOR(i, n)  for(int i = 0; i < n; i++)
#define  FORR(i, m, n)  for(int i = m; i < n; i++)
#define     SCI2(m, n)  scanf("%d%d", &m, &n)
#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)
#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)
#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)
#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)
#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)
#define             vi  vector<int>
#define            vii  vector<pair<int, int> >
#define            vll  vector<pair<ll, ll> >
#define            Mod  998244353
#define            INF  1000000000
 

int main()
{	
	int a[100005][4];
	int n;
	SCI(n);
	FOR(i, n)
		FOR(j, 3)
			SCI(a[i][j]);
	FORR(i, 1, n){
		a[i][0] = a[i][0] + max(a[i-1][1], a[i-1][2]);
		a[i][1] = a[i][1] + max(a[i-1][0], a[i-1][2]);
		a[i][2] = a[i][2] + max(a[i-1][0], a[i-1][1]);
	}
	printf("%d\n", max(a[n-1][0], max(a[n-1][1] , a[n-1][2])));    
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


const int mod=1000000007;
//const int mod=998244353;
vvi adj;
vpll ans;

void recur(int u ,int p){
    for(auto it: adj[u]){
        if(it!=p){
            recur(it,u);
            ans[u].fi*=(ans[it].fi+ans[it].se);
            ans[u].se*=ans[it].fi;
            ans[u].fi%=mod;
            ans[u].se%=mod;
        }
    }
}



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d,y,l,r;
    cin >> n;
    adj.resize(n+1);
    ans.assign(n+1,{1,1});
    for(int i=0; i<n-1; i++){
        cin >> a >> b;
        adj[a].pb((int)b);
        adj[b].pb((int)a);
    }
    recur(1,1);
    cout << (ans[1].fi+ans[1].se)%mod << el;
    return 0;
}


Measured memory_bytes: 14208
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> Xs(M);
    for (int i = 0; i < M; ++i)
    {
        cin >> Xs[i];
    }
    sort(Xs.begin(), Xs.end());
    if (N >= M)
    {
        cout << 0 << endl;
        return 0;
    }
    if (N == 1)
    {
        cout << (Xs[M - 1] - Xs[0]) << endl;
        return 0;
    }

    using t = pair<int, int>;
    vector<t> diffs;
    for (int i = 0; i < Xs.size() - 1; ++i)
    {
        diffs.push_back(make_pair(i, Xs[i + 1] - Xs[i]));
    }
    std::sort(diffs.begin(), diffs.end(), [](const t &a, const t &b) { return a.second > b.second; });
    // 差が大きいところから N-1 個選ぶ
    vector<int> split_indexes;
    for (int i = 0; i < N - 1; ++i)
    {
        split_indexes.push_back(diffs[i].first);
    }
    sort(split_indexes.begin(), split_indexes.end());

    vector<vector<int>> vs;
    vector<int> lengths;
    for (int i = 0; i < split_indexes.size(); ++i)
    {
        if (i == 0)
        {
            vector<int> l(Xs.begin(), Xs.begin() + split_indexes[i] + 1);
            vs.push_back(l);
            lengths.push_back(*(l.end() - 1) - *(l.begin()));
        }
        else
        {
            vector<int> l(Xs.begin() + split_indexes[i - 1] + 1, Xs.begin() + split_indexes[i] + 1);
            vs.push_back(l);
            lengths.push_back(*(l.end() - 1) - *(l.begin()));
        }

        if (i == split_indexes.size() - 1)
        {
            vector<int> l(Xs.begin() + split_indexes[i] + 1, Xs.end());
            vs.push_back(l);
            lengths.push_back(*(l.end() - 1) - *(l.begin()));
        }
    }

    cout << accumulate(lengths.begin(), lengths.end(), 0) << endl;

    return 0;
}


Measured memory_bytes: 7664
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	int colors[3];
	int num = 1;
	REP(i, 3){
		cin >> colors[i];
		REP(j, i){
			if(colors[j] == colors[i]) break;
			if(j == i-1) num++;
		}
	}
	cout << num << '\n';

	return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        var line = Console.ReadLine().Split(' ');
        int n = int.Parse(line[0]);
        int m = int.Parse(line[1]);

        int[,] A = new int[n, m];
        int[] b = new int[m];
        int[] c = new int[n];

        for(var i=0; i < n; i++)
        {
            var dataline_A = Console.ReadLine().Split(' ');
            for (var j = 0; j < m; j++)
            {
                A[i, j] = int.Parse(dataline_A[j]);
            }
        }

        for(var i=0; i<m; i++)
        {
            b[i] = int.Parse(Console.ReadLine());
        }

        for(var i=0; i<n; i++)
        {
            for(var j=0; j<m; j++)
            {
                c[i] += A[i, j] * b[j];
            }
        }

        for (var i = 0; i < n; i++) Console.WriteLine(c[i]);
    }
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

const int dx[]={-1,1,0,0}, dy[]={0,0,-1,1};
int N, M;
vector<string> F;
bool chk[400][400];

bool valid_coord(int x, int y)
{
	return 0<=x && x<N && 0<=y && y<M && !chk[x][y];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	long long ans=0;
	queue<pair<int,int>> Q;
	cin>>N>>M;
	F.resize(N);
	for(int i=0;i<N;i++) {
		cin>>F[i];
	}
	for(int i=0;i<N;i++) {
		for(int j=0;j<M;j++) {
			if(chk[i][j]) continue;
			int x, y, cnt[2]={};
			chk[i][j]=true;
			cnt[F[i][j]=='#']++;
			Q.push({i,j});
			while(!Q.empty()) {
				tie(x,y)=Q.front();
				Q.pop();
				for(int k=0;k<4;k++) {
					if(valid_coord(x+dx[k],y+dy[k]) && F[x+dx[k]][y+dy[k]]!=F[x][y]) {
						cnt[F[x+dx[k]][y+dy[k]]=='#']++;
						chk[x+dx[k]][y+dy[k]]=true;
						Q.push({x+dx[k],y+dy[k]});
					}
				}
			}
			ans+=1LL*cnt[0]*cnt[1];
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 640
num = input()

a = int(num) % 100
b = int(num) // 100

if 0 < a <= 12:
  if 0 < b <= 12:
    print("AMBIGUOUS")
  
  else:
    print("YYMM")
    

else:
  if 0 < b <= 12:
    print("MMYY")
  
  else:
    print("NA")

Measured memory_bytes: 2940
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T*)array, (T*)(array+N), val);
}
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


class DPeopleOnALine {
public:
	void solve(std::istream& in, std::ostream& out) {
	    struct node {
	        ll to, cost;
	        node(ll to, ll cost): to(to),cost(cost){}
	    };
        ll n, m, l, r, d;
        vector<node> v[100010];
        in >> n >> m;
        rep(i, m){
            in >> l >> r >> d;
            v[l].push_back(node(r, d));
            v[r].push_back(node(l, -d));
        }

        vector<ll> dist(n+1, 0);
        vector<ll> visit(n+1, 0);

        bool res = true;
        function<void(ll, ll)> dfs = [&](ll u, ll d){
            if(visit[u]){
                if(dist[u] != d) res = false;
                return;
            }
            visit[u] = 1;
            dist[u] = d;
            for(auto const& e : v[u]){
                dfs(e.to, dist[u] + e.cost);
            }
        };

        reps(i, 1, n){
            if(visit[i]) continue;
            dfs(i, 0);
        }

        if(res) out << "Yes" << endl;
        else out << "No" << endl;
	}
};


int main() {
	DPeopleOnALine solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 18176
/* In the name of Allah */

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

// const int INF = 20000000;

#define ll long long
#define _SetBit(A, k) (A[(k / 32)] |= (1 << (k % 32)))
#define _ClearBit(A, k) (A[(k / 32)] &= ~(1 << (k % 32)))
#define _CheckBit(A, k) (A[(k / 32)] & (1 << (k % 32)))
#define SetBit(x, k) (x |= (1 << k))
#define ClearBit(x, k) (x &= ~(1 << k))
#define CheckBit(x, k) (x & (1 << k))

int vis[26];

int main()
{
  int n;
  cin >> n;
  char x[n + 1];
  ll r = 0, g = 0, b = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> x[i];
    if (x[i] == 'R')
      r++;
    else if (x[i] == 'G')
      g++;
    else
      b++;
  }

  ll cnt = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < (n - i + 1) / 2; j++)
    {
      if (x[i] != x[i + j] && x[i + j] != x[i + 2 * j] && x[i] != x[i + 2 * j])
        cnt++;
    }
  }

  ll res = r * g * b;
  res -= cnt;
  // cout << "**" << r << " " << g << " " << b << " " << cnt << ":\n";
  cout << res << "\n";

  return 0;
}

Measured memory_bytes: 3612
n = gets.to_i
a =  gets.split.map(&:to_i)
puts a.join(' ')

for i in 1..n-1
  v = a[i]
  j = i - 1
  while j >= 0 && a[j] > v
    a[j+1] = a[j]
    j-=1
  end
  a[j+1] = v
  puts a.join(' ')
end

Measured memory_bytes: 8840