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

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

  int check, nrow = h, ncol = w;
  
  for(int i = 0;i < nrow;i++) {
    check = 1;
    for(int j = 0;j < w;j++) {
      if(a[i][j] != '.') {
        check = -1;
        break;
      }
    }

    if(check == 1) {
      if(i < nrow-1) {
        for(int j = i;j < nrow-1;j++) { a[j] = a[j+1]; }
        i--;
      }
      nrow--;
    }
  } // row

  for(int i = 0;i < ncol;i++) {
    check = 1;
    for(int j = 0;j < nrow;j++) {
      if(a[j][i] != '.') {
        check = -1;
        break;
      }
    }

    if(check == 1) {
      if(i < ncol-1) {
        for(int j = i;j < ncol;j++) {
          for(int k = 0;k < nrow;k++) { a[k][j] = a[k][j+1]; }
        }
        i--;
      }
      ncol--;
    }
  } // column

  for(int i = 0;i < nrow;i++) { for(int j = 0;j < ncol;j++) { cout << a[i][j]; } cout << endl; }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	string a;
	cin>>a;
	string b;
	cin>>b;
	int i= 0, j = 0, sum = 0;
	for(i=0; i<3; i++)
	{
		if (a[i]==b[j])
	{
		sum++;
		j++;
	}
	else
	{
	    j++;
	}
	}
	cout<<sum<<endl;
	return 0;
	
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
bool solve(ll n, ll a, ll b,vector<ll> &ans){
  if(a+b-1>n||b==0){
    return false;
  }
  if(a+b-1==n){
    for(int i=0;i<a;i++){
      ans.push_back(b+i);
    }
    for(int i=0;i<b-1;i++){
      ans.push_back(b-1-i);
    }
    return true;
  }
  for(int i=0;i<a;i++){
    ans.push_back(n-a+1+i);
  }
  n -= a;
  b--;
  if(n+1-b<=a){
    return solve(n,n+1-b,b,ans);
  }else{
    return solve(n,a,b,ans);
  }
}
signed main(){
  ll n,a,b;
  cin >> n >> a >> b;
  vector<ll> ans;
  if(solve(n,a,b,ans)){
    for(auto i:ans){
      cout << i<<" ";
    }
    cout << endl;
  }else{
    cout << -1 <<endl;
  }
}


Measured memory_bytes: 8564
#define  _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:256000000")

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <deque>
#include <queue>
#include <iomanip>
#include <fstream>
#include <string>
#include <climits>

typedef long long ll;
typedef long double ld;

#define fi(n) for(int i = 0; i < (n); i++)
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define RFOR(i, k, n) for(int i = (k); i >= (n); i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = INT_MAX;
const int mod = 1e9 + 7;
const long long LINF = LLONG_MAX;

using namespace std;

int main()
{
	int n;
	cin >> n;
	queue<pair<ll, int>> que;
	set<int> mbcu;
	fi(n)
	{
		ll x;
		cin >> x;
		que.push({ x, i });
		mbcu.insert(i);
	}
	ll answ = 0, pl = 0;
	vector<ll> m(n);
	
	while (!que.empty() && !mbcu.empty())
	{
		ll v = que.front().first;
		int i = que.front().second;
		que.pop();
		v += answ - m[i];
		
		if (v >= n)
		{
			ll newansw = v / n;
			v = v % n;
			answ += newansw;
			m[i] = answ;
			mbcu.insert(i);
			que.push({ v, i });
		}
		else
		{
			mbcu.erase(i);
			m[i] = answ;
			que.push({ v, i });
		}
	}

	cout << answ << endl;

	return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
if N==2:
    if S[0]==S[1]:print(1,2)
    else:print(-1,-1)
    exit()
for i in range(N-2):
    a,b,c = S[i:i+3]
    if a==b or b==c or c==a:
        print(i+1,i+3)
        break
else:
    print(-1,-1)

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

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

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

int main() {
	int h, w;
	cin >> h >> w;
	char field[105][105];
	rep(i, h + 2)rep(j, w + 2) field[i][j] = '.';
	REP(i, h) {
		REP(j, w) {
			cin >> field[i][j];
		}
	}
	bool ok = true;
	
	REP(i, h) {
		REP(j, w) {
			if (field[i][j] == '.') continue;
			bool exist = false;
			rep(k, 4) {
				int y = i + dy[k];
				int x = j + dx[k];
				if (field[y][x] == '#') exist = true;
			}
			if (!exist) ok = false;
		}
	}
	if (ok) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}



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 int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int mx = 0, mi = 1e9;
	rep(i,n){
		int a;
		cin >> a;
		chmax(mx, a);
		chmin(mi, a);
	}
	cout << mx - mi << endl;
	return 0;
}

Measured memory_bytes: 3616
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
flag=1
s=sum(a)
for i in a[0:m]:
  if i>=s/(4*m):
    pass
  else:
    print('No')
    flag=0
    break
if flag:
  print('Yes')

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

#define ALL(obj) (obj).begin(),(obj).end()
template<class T> using priority_queue_reverse = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = 1'000'000'000LL + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
vector<string> split(const string &str, const char delemiter) {vector<string> res;stringstream ss(str);string buffer; while( getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;}
int msb(int x) {return x?31-__builtin_clz(x):-1;}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> A(N+1,0);
    for(int i = 1; i <= N; ++i) {
        for(int j = i; j <= N; j += i) {
            A[j]++;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= N; ++i) {
        ll M = N - i;
        ans += A[M];
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 11028
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cstring>
#include <cctype>
#include <numeric>
#include <cstdio>
#include <math.h>
#include <functional>
using namespace std;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define na(a, n) rep(i, n) cin >> a[i];
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
vb d(10);
int ans(int x)
{
    while (x)
    {
        if (d[x % 10])
            return 0;
        x /= 10;
    }
    return 1;
}
//ここからメイン
int main()
{
 ll a,b,c,d;
  cin >> a >> b;
  if(a-b<=0){
    cout << 0;
    return 0;}
  cout<<a-b;
    }

Measured memory_bytes: 256
#!/usr/bin/python3

#標準出力からの読み込み

n = int(input())
d_n = [input().split(" ") for i in range(n)]

flag = False

for i in range(n-2):
    if (d_n[i][0] == d_n[i][1]) & (d_n[i+1][0] == d_n[i+1][1]) & (d_n[i+2][0] == d_n[i+2][1]):
        flag=True

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define mp 	    make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod        1000000007
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
ll power(ll a , ll b,ll modi)
{
    a%=modi;
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}
//ll a[100001];
//ll a[200001];
ll dp[3000][3000];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
	//cin>>t;
	while(t--)
	{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	for(ll i=n-1;i>=0;i--){
		for(ll j=i;j<n;j++){
			int chance=n-(j-i);
			if(chance%2){
				if(i==j){
					dp[i][j]=a[i];
				}
				else{
					dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j]);
				}
			}
			else{
				if(i==j){
					dp[i][j]=-1*a[i];
				}
				else{
					dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j]);
				}
			}
		}
	}
	// for(ll i=0;i<n;i++){
		// for(ll j=0;j<n;j++)
		// cout<<dp[i][j]<<" ";
		// cout<<endl;
	// }
	cout<<dp[0][n-1];
	}
return 0;
}

Measured memory_bytes: 49792
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>

using namespace std;

int main(void){
    double N;
    vector<double> a;
    double input;
  
    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> input;
        a.push_back(input);
    }
    double ave = accumulate(a.begin(), a.end(), 0) / N;
    
    for(int i = 0 ; i < N ; i++){
        a[i] = abs(a[i] - ave);
    }
    vector<double>::iterator minIt = min_element(a.begin(), a.end());
    int minIndex = distance(a.begin(), minIt);

    cout << minIndex << endl;
    return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] abcd = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = abcd[0];
        var b = abcd[1];
        var c = abcd[2];
        var d = abcd[3];

        var ans = "Yes";
        while (true)
        {
            c -= b;
            if (c <= 0)
            {
                ans = "Yes";
                break;
            }
            a -= d;
            if (a <= 0)
            {
                ans = "No";
                break;
            }
        }
        // 出力
        Console.WriteLine(ans);
    }
}

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

int main(void)
{
    int d;
    int n;
    int i;
    long int ans;

    while (scanf("%d", &d) != EOF){
        ans = 0;
        n = 600 / d;
        for (i = 1; i < n; i++){
            ans += d * (i * d * i * d);
        }
        printf("%ld\n", ans);
    }
    return (0);
}

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

void solve(ll K, ll X, ll Y) {
    //X, Yを0以上にする
    bool rev_x = (X < 0), rev_y = (Y < 0);
    X = abs(X); Y = abs(Y);
    
    bool swapped = (X < Y);
    if (swapped) {
        swap(X, Y);
    }
    
    if (K % 2 == 0 && (X + Y) % 2 == 1) {
        cout << -1 << endl;
        return;
    }
    
    ll x = 0, y = 0;
    vector<pair<ll, ll>> ans;

    if (X + Y < K) {
        //行ける場合は2 or 3回が最短
        if ((X + Y) % 2 == 0) {
            //2回で行ける
            ll a = (2 * K - (X + Y)) / 2;

            x += K - a;
            y -= a;
            ans.emplace_back(x, y);

            x += X - (K - a);
            y += Y + a;
            ans.emplace_back(x, y);
        } else {
            //K % 2 == 0は最初に弾いているのでK % 2 == 1のときのみ
            x += X;
            y -= K - X;
            ans.emplace_back(x, y);

            ll diff = (Y - y) / 2;
            x += K - diff;
            y += diff;
            ans.emplace_back(x, y);

            x -= K - diff;
            y += diff;
            ans.emplace_back(x, y);
        }
    } else if (X + Y == K) {
        //1回で行ける
        x += X;
        y += Y;
        ans.emplace_back(x, y);
    } else {
        //基本的には切り上げ回数で行ける
        ll n = (X + Y + K - 1) / K;

        if (K * n % 2 != (X + Y) % 2) {
            //偶奇を揃えるために+1する
            n++;
        }

        ll first_step_y = (K * n - X - Y) / 2;
        x += K - first_step_y;
        y -= first_step_y;
        ans.emplace_back(x, y);

        //xをXに揃える
        while (x + K < X) {
            x += K;
            ans.emplace_back(x, y);
        }

        ll diff = X - x;
        x += diff;
        y += K - diff;
        ans.emplace_back(x, y);

        //yをYに揃える
        while (y < Y) {
            y += K;
            ans.emplace_back(x, y);
        }
    }

    cout << ans.size() << endl;
    for (auto& p : ans) {
        if (swapped) {
            swap(p.first, p.second);
        }
        cout << (rev_x ? -p.first : p.first) << " " << (rev_y ? -p.second : p.second) << endl;
    }
}

int main() {
    ll K, X, Y;
    cin >> K >> X >> Y;
    solve(K, X, Y);
}

Measured memory_bytes: 5612
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int a=s.nextInt();
		int b=s.nextInt();
		int c=s.nextInt();
		
		if((a+b+c)/2==a+b||
		   (a+b+c)/2==a+c||
		   (a+b+c)/2==b+c)System.out.print("Yes");
		else System.out.print("No");

	}

}


Measured memory_bytes: 21844
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  if(K==1){
    var ans=0;
  }else{
    var ans=N-K;
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21956
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Node{
	int depth = 0;
	int parent = -1;
	String type = "";
	ArrayList<Integer> children = new ArrayList<Integer>();
} 

public class Main {
	
	private static Scanner src;

	public static void main(String[] args) {
		src = new Scanner(System.in);
		int n = src.nextInt();
		Node[] tree = new Node[n];
		for(int i = 0; i < n; i++) tree[i] = new Node(); 
		for(int i = 0; i < n; i++) {
			int id = src.nextInt(), k = src.nextInt(); 
			for(int j = 0; j < k; j++) {
				Integer child = src.nextInt(); 
				tree[id].children.add(child);
				tree[child].parent = id;
			}
		}
		for(int i = 0; i < n; i++) {
			if(tree[i].parent == -1) {
				Queue<Integer> queue = new LinkedList<Integer>();
				for(Integer child : tree[i].children) queue.add(child);
				int size = tree[i].children.size();
				int d = 1;
				while(!queue.isEmpty()) {
					int child = queue.poll();
					tree[child].depth = d;
					for(Integer j : tree[child].children) queue.add(j);
					size--;
					if(size == 0) {size = queue.size();  d++;}
				}
				break;
			}
		}
		for(int i = 0; i < n; i++) {
			StringBuilder answ = new StringBuilder();
			answ.append("node ").append(i).append(": parent = ").append(tree[i].parent).append(", depth = ")
			.append(tree[i].depth).append(", ");
			if(tree[i].parent == -1) { answ.append("root, ["); } 
			else if(tree[i].children.size() > 0) { answ.append("internal node, ["); }
			else answ.append("leaf, [");
			int l = tree[i].children.size();
			if(l >= 1) {
				for(int j = 0; j < l - 1; j++) {
					answ.append(tree[i].children.get(j)).append(", ");
				}
				answ.append(tree[i].children.get(l - 1)).append("]");
			}else answ.append("]");
			System.out.println(answ);
		}
	}
}



Measured memory_bytes: 140604
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <cassert>
#include <time.h>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>
#define print_time()cout<<clock()/CLOCKS_PER_SEC<<" s"<<endl;

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//  std::ios::sync_with_stdio(false);
//  std::cin.tie(NULL);
//  return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


bool rifa(int x) {
	int c = 0;
	while (x) { c++; x /= 10; }
	return c % 2 != 0;
}
int main() {
	int n; cin >> n;
	int ans = 0;
	repi(1, n + 1)
		if (rifa(i))ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(b<c){
        cout << 0 << endl;
        return 0;
    }

    if(d<a){
        cout << 0 << endl;
        return 0;
    }

    if(b<=d){
        if(a<=c) cout << b - c << endl;
        else cout << b - a << endl;
    }
    else{
        if(c<=a)cout << d - a << endl;
        else cout << d - c << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
enco1={" ":"101","'":"000000",",":"000011","-":"10010001",".":"010001","?":"000001","A":"100101","B":"10011010","C":"0101","D":"0001","E":"110","F":"01001","G":"10011011","H":"010000","I":"0111","J":"10011000","K":"0110","L":"00100","M":"10011001","N":"10011110","O":"00101","P":"111","Q":"10011111","R":"1000","S":"00110","T":"00111","U":"10011100","V":"10011101","W":"000010","X":"10010010","Y":"10010011","Z":"10010000"}
enco2={"00000":"A","00001":"B","00010":"C","00011":"D","00100":"E","00101":"F","00110":"G","00111":"H","01000":"I","01001":"J","01010":"K","01011":"L","01100":"M","01101":"N","01110":"O","01111":"P","10000":"Q","10001":"R","10010":"S","10011":"T","10100":"U","10101":"V","10110":"W","10111":"X","11000":"Y","11001":"Z","11010":" ","11011":".","11100":",","11101":"-","11110":"'","11111":"?"}
while True:
    try:
        s="".join([enco1[w] for w in raw_input()])
        if not len(s)%5==0:s=s+"0"*(5-len(s)%5)
        print "".join([enco2[s[i:i+5]] for i in xrange(0,len(s),5)])
    except:
        break

Measured memory_bytes: 4296
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=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))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
vector<ll> A,B;
int main(){
	cin>>N;
	rep(i,N){
		ll x;
		cin>>x;
		A.pb(x);
		
	}
	rep(i,N){
		ll x;
		cin>>x;
		B.pb(x);
		
	}
	bool ans=true;
	ll plus=0,minuscnt=0;
	rep(i,N){
		if(A[i]>B[i])plus+=A[i]-B[i];
		else{
			minuscnt+=(B[i]-A[i])/2;
		}
	}
	//cout<<plus<<" "<<minus<<endl;
	if(minuscnt>=plus)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 512
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int alice  = 0;
        int bob = 0;
        int n = sc.nextInt();
        Integer[] data = new Integer[n];
        for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        }
      
        Arrays.sort(data,Collections.reverseOrder());
        for(int i=0; i<data.length; i+=2){
            alice += data[i];
        }
        for(int i=1; i<data.length; i+=2){
            bob += data[i];
        }
        System.out.println(alice-bob);
    }
}

Measured memory_bytes: 21716
from collections import deque

S = deque(input())
Q = int(input())
rev = 0

for i in range(Q):
    l = str(input())
    if l[0] == '1':
        rev = (rev + 1) % 2
    else:
        two, F, C = l.split()
        if rev == 0:
            if F == '1':
                S.appendleft(C)
            else:
                S.append(C)

        else:
            if F == '1':
                S.append(C)

            else:
                S.appendleft(C)

if rev == 0:
    print(''.join(S))
else:
    print(''.join(list(reversed(S))))


Measured memory_bytes: 8436
sdash=input()
t=input()
rsdash=sdash[::-1]
rt=t[::-1]
anslist=[]
for i in range(len(sdash)-len(t)+1):
    count=0
    ans=rsdash
    if rsdash[i]==rt[0] or rsdash[i]=="?":
        for j in range(1,len(t)):
            if rsdash[i+j]==rt[j] or rsdash[i+j]=="?":
                count+=1
        if count==len(t)-1:
            ans=rsdash[:i]+rt+rsdash[i+len(t):]
            ans=ans.replace("?","a")
            anslist.append(ans[::-1])
anslist.sort()
if not anslist:
    print("UNRESTORABLE")
else:
    print(anslist[0])

Measured memory_bytes: 3064
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
print(sum((((sum(a[i]>j for j in a[i:])*(k*(k+1)//2)%mod)+(sum(a[i]>j for j in a[:i+1])*(k*(k-1)//2)%mod))%mod) for i in range(n))%mod)

Measured memory_bytes: 74848
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll ans = 0;
  if (X == 1) {
    ans += 300000;
  } else if (X == 2) {
    ans += 200000;
  } else if (X == 3) {
    ans += 100000;
  }
  if (Y == 1) {
    ans += 300000;
  } else if (Y == 2) {
    ans += 200000;
  } else if (Y == 3) {
    ans += 100000;
  }
  if (X == 1 && Y == 1) {
    ans += 400000;
  }

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int n,s[1005],i;
    double a,x;
    for(;scanf("%d",&n),n;)
    {
        for(i=a=0;i<n;a+=s[i++])
            scanf("%d",&s[i]);
        a/=n;
        for(i=x=0;i<n;i++)
            x+=(s[i]-a)*(s[i]-a);
        printf("%.8f\n",sqrt((double)x/n));
    }
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b, c;
    cin >> a >> b >> c;
    bool f = a < c && c < b;
    bool g = b < c && c < a;
    cout << (f || g ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    char s[10],t[10],u[10];
    int a,b;
    scanf("%s %s",s,t);
    scanf("%d %d",&a,&b);
    scanf("%s",u);
    if(strcmp(s,u)==0)
        a--;
    if(strcmp(t,u)==0)
        b--;
    printf("%d %d\n",a,b);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define LL long long
#define M 1000005
using namespace std;
const int P=1e9+7;
int main(){
	int n;
	LL ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%3&&i%5)ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3624
def do_calc(data):
    from collections import deque
    s = deque()  # ??????????????¨??????????????????
    while data:
        elem = data[0]
        data = data[1:]
        if elem == '+' or elem == '-' or elem == '*':
            a = s.pop()
            b = s.pop()
            if elem == '+':
                s.append(b + a)
            elif elem == '-':
                s.append(b - a)
            elif elem == '*':
                s.append(b * a)
        else:
            s.append(int(elem))
    return s.pop()


if __name__ == '__main__':
    # ??????????????\???
    data = [x for x in input().split(' ')]
    # data = ['1', '2', '+', '3', '4', '-', '*']

    # ???????????????
    result = do_calc(data)

    # ???????????????
    print(result)

Measured memory_bytes: 7980
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

signed main(void) {
	char c;
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')print("vowel");
	else print("consonant");
}

Measured memory_bytes: 3552
mod = 10**9+7
class SegmentTree:
    def __init__(self, N, id, fun):
        self.N0 = 2**(N-1).bit_length()
        self.id = id
        self.data = [self.id]*(2*self.N0)
        self.fun = fun
    def update(self, k, x):
        k+=self.N0-1
        self.data[k] = x
        while k>=0:
            k = (k-1)//2
            self.data[k] = self.fun(self.data[2*k+1], self.data[2*k+2])
    def query(self, l, r):
        L = l+self.N0; R = r+self.N0
        s = self.id
        while L<R:
            if R&1:
                R-=1
                s = self.fun(s, self.data[R-1])
            if L&1:
                s = self.fun(s, self.data[L-1])
                L+=1
            L >>= 1; R>>=1
        return s
N = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))
R = SegmentTree(N+1, 0, max)
dp = [0]*N
dp[0] = a[0]
R.update(h[0], dp[0])
for i in range(1, N):
    m = R.query(0, h[i])
    dp[i] = m+a[i]
    R.update(h[i], dp[i])
print(max(dp))




    








Measured memory_bytes: 123600
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
struct Point {
	int x, y;

	double dis(Point a, Point b) {
		double x = a.x - b.x;
		double y = a.y - b.y;
		return sqrt(x*x + y * y);
	}
};

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

	int H, W;
	cin >> H >> W;
	int ai = 1;
	char ac = 'A';


	for (int i = 0; i < H; i++)
	{
		ac = 'A';
		for (int j = 0; j < W; j++)
		{
			string s;
			cin >> s;
			if (s == "snuke") {
				goto LAST;
			}
			ac++;
		}
		ai++;
	}
LAST:
	cout << ac << ai << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 9223372036854775807;
const int MOD = 1000000007;

int main(){
	int n;
	std::cin >> n;
	std::vector<string> s(n);
	rep(i,n)std::cin >> s[i];
	bool han=1;
	rep(i,n-1){
		if(s[i][s[i].size()-1]!=s[i+1][0])han=0;
	}
	sort(all(s));
	rep(i,n-1){
		if(s[i]==s[i+1])han=0;
	}
	if(han)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val flames = readLine()!!.split(" ").map { it.toInt() }
    val avg = flames.average()
    val min = flames.map { Math.abs(it-avg) }.min()!!
    val ans = flames.indices.filter { Math.abs(flames[it]-avg) == min }.first()
    println(ans)
}


Measured memory_bytes: 37820
#include<stdio.h>

int field[105][105] ,n ,m;

int dfs(int x, int y){
  if(x < 0 || x > m + 2 || y < 0 || y > n + 2)return 0;
  if(field[x][y] == 1)return 1;
  if(field[x][y] == 2)return 0;
  int res = 0;
  field[x][y] = 2;
  res += dfs(x, y + 1);
  res += dfs(x, y - 1);
  res += dfs(x + 1, y);
  res += dfs(x - 1, y);
  if(x % 2 == 0){
    res += dfs(x - 1, y - 1);
    res += dfs(x + 1, y - 1);
  }
  else{
    res += dfs(x - 1, y + 1);
    res += dfs(x + 1, y + 1);
  }
  return res;
}

int main(){
  int i, j;
  scanf("%d%d", &n, &m);
  for(i = 1;i <= m;i++){
    for(j = 1;j <= n;j++){
      scanf("%d", &field[i][j]);
    }
  }
  printf("%d\n", dfs(0, 0));
  return 0;
}

Measured memory_bytes: 1056
from decimal import Decimal
n = int(input())
a = []
r = {}
for i in range(n):
    d = int(float(input())*10**9 + 0.1)
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in r.keys():
    for i , j in r.keys():
        if min(x+i,y+j) >= 18:
            ans += r[(x,y)]*r[(i,j)]
            if x == i and y == j:
                ans -= r[(x,y)]
                
print(ans//2)

Measured memory_bytes: 99244
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,i;
  int alice=0;
  int bob=0;
  cin >> N;
  vector<int> a(N);
  for (i=0; i<N; i++){
      cin >> a.at(i);}
  sort(a.begin(), a.end());
  reverse(a.begin(),a.end());

  for (i=0; i<N; i++){
      if(i%2 ==0){
          alice +=a.at(i); }
          else {bob += a.at(i);}
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int n;
  cin >> n;
  vvl d(n,vl(3));
  rep(i,n){
    rep(j,3) cin >> d[i][j];
  }
  vvl dp(n+1,vl(3,0));
  REP(i,1,n+1){
    rep(j,3){
      rep(k,3){
        if(j == k) continue;
        dp[i][j] = max(dp[i][j], dp[i-1][k] + d[i-1][j]);
      }
    }
  }
  cout << max(dp[n][0], max(dp[n][1],dp[n][2]));
}

Measured memory_bytes: 14076
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if (k <= a) {
        ans = k;
    }
    else if (k <= a + b) {
        ans = a;
    }
    else {
        ans = a - (k - a - b);
    }
    out(ans);
    
    return 0;
}




















Measured memory_bytes: 3636
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
ll gcd(ll a,ll b){
	while(b){
		ll r=a%b;
		a=b;
		b=r;
		}
	return a;
	}
int main()
{
	ll n,a;
	cin>>n;
	ll ans=1LL;
	while(n--){
		cin>>a;
		ans = lcm(ans,a);
		}
	cout<<ans<<nw;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// UnionFind
struct UnionFind{
  VI par,sizes; // par[i]:iの親の番号
  UnionFind(int n) : par(n), sizes(n,1){ // 最初は全てが根であるとして初期化
    rep(i,n) par[i] = i;
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x); int ry = root(y);
    if(rx==ry) return;
    if(sizes[rx]<sizes[ry]) swap(rx,ry);
    par[ry] = rx;
    sizes[rx] += sizes[ry];
  }
  bool same(int x, int y){
    return root(x)==root(y);
  }
  int size(int x){
    return sizes[root(x)];
  }
};

signed main(){
  int n,m; cin>>n>>m;
  UnionFind uf(n+m);
  rep(i,n){
    int k; cin>>k;
    rep(j,k){
      int l; cin>>l;
      uf.unite(l-1,m+i);
    }
  }
  rep(i,n-1){
    if(!uf.same(m+i,m+i+1)){
      return cout<<"NO"<<endl, 0;
    }
  }
  cout << "YES" << endl;
  
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> data(H, vector<char>(W));
  
  for (int i = 0; i < H ; i++){
    for (int j = 0; j < W; j++){
     cin >> data.at(i).at(j);
    }// for j
  } //for i
  
 
  
  
  for (int i = 0; i < H  ; i++){
    for( int j = 0; j < W ; j++){
      if (data.at(i).at(j) == '#'){        
        continue;
      }// if
      else if( data.at(i).at(j) == '.'){
        int count = 0;
        for ( int k = i - 1 ; k < i + 2; k++){
          for ( int l = j - 1 ; l < j + 2; l++){
            if (k < 0 || k >= H || l < 0|| l >= W ) continue;
            else if (data.at(k).at(l) == '#')count++;  
            }//for l
         }//for k
        data.at(i).at(j) = count +'0';
      }//else if   
     } // for j
  } //for i
  
  for ( int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if( j == W - 1 ) {
      cout << data.at(i).at(j) << endl;
      }//if
      else{
        cout << data.at(i).at(j);
      }//else
    }//for j
  } //for i
  
  
  
} //main





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

ll dp[3000][3000];
int s[3000],t[3000];
int main(){
	int n,m;cin>>n>>m;
	rep(i,n){
		scanf("%d",&s[i]);
	}
	rep(i,m){
		scanf("%d",&t[i]);
	}
	dp[0][0]=1;
	rep(i,n+1)rep(j,m+1){
		if(i==n&&j==m)continue;
		if(j<m)(dp[i][j+1]+=dp[i][j])%=MOD;
		if(i<n)(dp[i+1][j]+=dp[i][j])%=MOD;
		if(i<n&&j<m){
			(dp[i+1][j+1]+=MOD-dp[i][j])%=MOD;
		}
		if(i<n&&j<m&&s[i]==t[j]){
			(dp[i+1][j+1]+=dp[i][j])%=MOD;
		}
	}
	//~ rep(i,n+1){
		//~ rep(j,m+1)cout<<dp[i][j]<<' ';
		//~ cout<<endl;
	//~ }
	cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 46976
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            while self.parents[x] >= 0:
                if self.parents[self.parents[x]] >= 0:
                    self.parents[x] = self.parents[self.parents[x]]
                x = self.parents[x]
            return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

import sys
input = sys.stdin.buffer.readline
N,Q = map(int,input().split())
uf = UnionFind(N)
for i in range(Q):
    t,u,v = map(int,input().split())
    if t == 0:
        uf.union(u,v)
    else:
        if uf.same(u,v):
            print(1)
        else:
            print(0)


Measured memory_bytes: 77336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;
const ll MAXA = 1000001;

int main()
{
  ll n; cin >> n;
  vector<ll> a(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  map<ll, ll> mp;
  rep(i, n) {
    mp[a[i]]++;
  }
  vector<ll> d(MAXA, 0);
  for (auto v:mp) {
    for (int i=1; i*v.first<MAXA; i++) {
      d[i*v.first] += v.second;
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (d[a[i]] < 2) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 25040
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using ll = int64_t;
using ul = uint64_t;
using namespace std;

void solve() {
  int n;
  ul x;
  cin >> n >> x;

  vector<ul> A(n);
  for (auto &a : A) cin >> a;
  sort(A.begin(), A.end());

  // Tabun Greedy To iu Namae No
  // Algorithm To iuka Kangae Kata
  // Dato Omouno dakedo na ...
  int cnt = 0;
  for (size_t i = 0; i < A.size() - 1; ++i) {
    if (x >= A.at(i)) {
      cnt++;
      x -= A.at(i);
    } else if (x == A.at(i)) {
      cout << cnt + 1 << endl;
      return;
    } else {
      cout << cnt << endl;
      return;
    }
  }

  if (x == A.back())
    cnt++;
  cout << cnt << endl;
}

void wrapper() {
  rep(i, 4) {
    cout << "[TEST " << (i + 1) << "]\n";
    solve();
    cout << "\n";
  }
}

int main() {
  fastIO;
  // wrapper();
  solve();
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define maxn 60
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
char s1[maxn], s2[maxn];
int main() {
    int n;
    LL ans = 1;
    scanf("%d%s%s", &n, s1, s2);
    int tp, beg;
    if (s1[0] == s2[0]) ans = 3, beg = 1, tp = 1;
    else ans = 6, beg = 2, tp = 2;
    for (int i = beg; i < n; ) {
        if (tp == 1) {
            ans = ans * 2 % mod;
            if (s1[i] == s2[i]) ++i;
            else i += 2, tp = 2;
        }
        else {
            if (s1[i] == s2[i]) ++i, tp = 1;
            else ans = ans * 3 % mod, i += 2;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if((A+B+C)%2==max(max(A,B),C)%2){
    cout<<(max(max(A,B),C)*3-A-B-C)/2<<endl;
  }else{
    cout<<(max(max(A,B),C)*3+3-A-B-C)/2<<endl;
  }
  
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int A, B, count=0;
    scanf("%d %d", &A,&B);
    char add[A+B+2];
    scanf("%s", add);
    
    for(int i=0;i<A+B+1;i++){
        if(i!=A){
            if(add[i]>=48 && add[i]<=57){
                count++;
            } 
        } else {
            if(add[i]=='-'){
                count++;
            }
        }
    }
    
    if (count==A+B+1) {
    	printf("Yes");
    	return 0;
	}else {
		printf("No");
	}
	
    return 0;
}

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

const long long MOD = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    long long dp[n + 1][m + 1];
    int s[n], t[m];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    for (int i = 0; i <= m; i++) {
        dp[0][i] = 1;
    }
    for (int i = 1; i <= n; i++) {
        dp[i][0] = 1;
        for (int j = 1; j <= m; j++) {
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
            if (s[i - 1] != t[j - 1]) {
                dp[i][j] = (dp[i][j] - dp[i - 1][j - 1]) % MOD;
            }
        }
    }
    cout << (dp[n][m] + MOD) % MOD;
    return 0;
}


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

int main() {
  int N, l, r, sum;
  cin >> N;
  sum = 0;
    
  for(int i=0; i < N; i++ ){
    cin >> l >> r;
    sum += r-l+1;
  }

  cout << sum << endl;
}


Measured memory_bytes: 256