akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int MAX_A = 1000000;
const int INF = INT_MAX / 2;

int memo[MAX_A + 1];

int f(const int x) {
    if (x % 2 == 0) {
        return x / 2;
    } else {
        return x * 3 + 1;
    }
}

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

    memo[s] = 1;

    int prev = s;
    for (int i = 2; i <= MAX_A; i++) {
        int v = f(prev);
        if (memo[v] != 0) {
            cout << i << endl;
            return 0;
        }
        memo[v] = i;
        prev = v;
    }

    return 0;
}


Measured memory_bytes: 256
s = input()
t = input()
count_list = []
count = 0

for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i+j] == t[j]:
            count += 1
    count_list.append(len(t) - count)
    count = 0

print(min(count_list))

Measured memory_bytes: 9112
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    int ans[30];
    for (int i = 0; i < 26; i++)
        ans[i] = 0;

    string s;

    while (getline(cin, s))
    {
        for (int i = 0; i < s.size(); i++)
        {
            if ('A' <= s[i] && s[i] <= 'Z')
                ans[s[i] - 'A']++;
            if ('a' <= s[i] && s[i] <= 'z')
                ans[s[i] - 'a']++;
        }
    }
    for (int i = 0; i < 26; i++)
        cout << (char)('a' + i) << " : " << ans[i] << endl;
}


Measured memory_bytes: 3156
#include <cmath>
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    double x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double d = sqrt((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2));

    printf("%lf\n", d);

    return 0;


}


Measured memory_bytes: 3280
/*** I came, I saw, I conquered. ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
#define sc(a) cin >> a
#define pf(a) cout << a << endl
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define mod 1000000007
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define GET_SET_BITS(a) (__builtin_popcount(a))
#define GET_SET_BITSLL(a) ( __builtin_popcountll(a))
#define GET_TRAIL_ZERO(a) (__builtin_ctz(a))
#define GET_LEAD_ZERO(a) (__builtin_clz(a))
#define GET_PARITY(a) (__builtin_parity(a))
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
void go() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/*----------------------------------------------------------------*/
void solve() {
    int n;
    sc(n);

    vector<pair<int, int>> v(n);
    for(int i = 0;i < n;i++) {
        cin >> v[i].first >> v[i].second;
    }

    bool flag = false;
    int cnt = 0;
    for(int i = 0;i < n;i++) {
        if(v[i].first == v[i].second) {
            cnt++;
        } else {
            cnt = 0;
        }

        if(cnt == 3) {
            flag = true;
        }
    }

    if(flag) {
        pf("Yes");
    } else {
        pf("No");
    }
}

int main() {
    go();
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> m(26);
    rep(i, n) m[s[i] - 'a'].insert(i);
    rep(i, q)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int j;
            char c;
            cin >> j >> c;
            j--;
            m[s[j] - 'a'].erase(j);
            m[c - 'a'].insert(j);
            s[j] = c;
        }
        else
        {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            int ans = 0;
            rep(j, 26)
            {

                auto lb = m[j].lower_bound(l);
                int lbn = lb == m[j].end() ? -1 : *lb;
                if (lbn >= l && lbn <= r)
                {
                    ans++;
                }
            }

            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 24196
def prime_factorize(N,lis):
    a = []
    n = N
    while n % 2 == 0:
        lis[2] += 1
        n //= 2
    f = 3
    while f * f <= N:
        if n % f == 0:
            lis[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        lis[n] += 1

N = int(input())
lis = [0] * 101
for i in range(1,N+1):
    prime_factorize(i,lis)
d = [0] * 100
for i in lis:
    d[i] += 1
for i in reversed(range(len(d)-1)):
    d[i] += d[i+1]

print(d[74] + d[24] * (d[2]-1) + d[14] * (d[4]-1) + (d[4] * (d[4]-1) * (d[2]-2)) // 2)


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

int main() {
  string s, t;
  cin >> s >> t;
  string answer = "No";
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s.size() < t.size() && s == t.substr(0, s.size())) answer = "Yes";
  for (int i = 0; i < min(s.size(), t.size()); i++) {
    if ((s[i] > t[i])) break;
    if (s[i] < t[i]) answer = "Yes";
  }
  cout << answer;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	auto solve = [](){		
		int n; cin >> n;
		vi a(n); rep(i, n) cin >> a[i];
		sort(all(a));
		
		if(a[0] + 1 < a.back()) return false;
		if(a[0] == a.back() && a[0] == n - 1) return true;
		
		int cnt = n - count(all(a), a.back());
		// cnt <= col
		// col <= cnt + (n - cnt) / 2
		return cnt < a.back() && a.back() <= cnt + (n - cnt) / 2 && n - cnt > 1;
	};
	cout << (solve() ? "Yes" : "No") << endl;
	
	
	return 0;
}

Measured memory_bytes: 768
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()

	fmt.Println(n*800 - (n/15)*200)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

using namespace std;


int main()
{
	int a,b;
	cin>>a>>b;
	if(a>9||a<1||b>9||b<1)
	{
		cout<<-1<<endl;
		
	}
	else
	{
		cout<<a*b<<endl;
	 } 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
//#define s second
#define f first
long long const mod = 1000000007; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

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

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
        
   
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    ll dp[n][3];
    memset(dp,0,sizeof(dp));
    for(ll i=0;i<n;i++)
    {
        char c=s[i];
        //char a,b;
        if(s[i]=='R')
        {
            ll z=0;
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='G')
                    z++;
            }
            dp[i][1]=z;
            z=0;
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='B')
                    z++;
            }
            dp[i][2]=z;
        }
        else if(s[i]=='G')
        {
            ll z=0;
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='R')
                    z++;
            }
            dp[i][0]=z;
            z=0;
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='B')
                    z++;
            }
            dp[i][2]=z;
        }
        else if(s[i]=='B')
        {
            ll z=0;
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='G')
                    z++;
            }
            dp[i][1]=z;
            z=0;
            for(ll j=i+1;j<n;j++)
            {
                if(s[j]=='R')
                    z++;
            }
            dp[i][0]=z;
        }
    }

    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            if(s[i]==s[j])
                continue;
            if((s[i]=='R' && s[j]=='G')||(s[i]=='G' && s[j]=='R'))
            {
                ans=ans+dp[j][2];
                ll diff=j-i;
                ll k=j+diff;
                if(k<n && s[k]=='B')
                    ans--;
            }
            else if((s[i]=='R' && s[j]=='B')||(s[i]=='B' && s[j]=='R'))
            {
                ans=ans+dp[j][1];
                ll diff=j-i;
                ll k=j+diff;
                if(k<n && s[k]=='G')
                    ans--;
            }
            else if((s[i]=='B' && s[j]=='G')||(s[i]=='G' && s[j]=='B'))
            {
                ans=ans+dp[j][0];
                ll diff=j-i;
                ll k=j+diff;
                if(k<n && s[k]=='R')
                    ans--;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a=n/1000,b=(n%1000)/100,c=(n%100)/10,d=n%10;
    if(a+b+c+d==7){
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    }
    else if(a+b+c-d==7){
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
    }
    else if(a+b-c+d==7){
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    }
    else if(a+b-c-d==7){
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
    }
    else if(a-b+c+d==7){
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
    }
    else if(a-b+c-d==7){
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
    }
    else if(a-b-c+d==7){
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
    }
    else{
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  string s;
  map<char,int> a, b;
  for(int i=0; i<n; i++) {
    cin >> s;
    if(i==0) for(int j=0; j<s.size(); j++) b[s[j]]++;
    else for(int j=0; j<s.size(); j++) a[s[j]]++;
    
    if(i==0) continue;
    else {
      for(auto p : b) {
        if(a.count(p.first)) b[p.first] = min(a[p.first], b[p.first]);
        else b[p.first] = 0;
      }
      for(auto p : a) a[p.first] = 0;
    }
  }
  
  string ans;
  for(auto p : b) {
    for(int i=0; i<b[p.first]; i++) {
      ans.push_back(p.first);
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

//#define v(T) vector<T>
//#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
//typedef vector<int> vi;
//typedef vector<vi> vvi;
//typedef vector<ll> vl;
//typedef vector<P> vp;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> to[10];
    int a, b;
    rep(i,m) {
        cin >> a >> b;
        --a; --b;
        to[a].pb(b);
        to[b].pb(a);
    }

    vector<int> v(n-1);
    rep(i,n-1) v[i] = i+1;
    int ans = 0;
    do {
        int pre = 0;
        bool ok = true;
        for(auto i: v) {
            auto itr = find(all(to[pre]), i);
            if (itr == to[pre].end()) ok = false;
            pre = i;
        }
        if (ok) ++ans;
    } while(next_permutation(all(v)));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def insert(tree:Node, key:Node) = {
    val keyNode = key
    def getNodeToInsert(node:Node):Node =
      if(node.key > keyNode.key) {
        if(node.left == null) node
        else getNodeToInsert(node.left)
      } else {
        if(node.right == null) node
        else getNodeToInsert(node.right)
      }

    val target = getNodeToInsert(tree)

    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<1000) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<1000) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 301404
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n;
    cin >> n;
    vector<int> c(n),s(n),f(n);
    for(int i = 0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];
    for(int i = 0; i < n-1; i++){
        int res = s[i]+c[i];
        for(int j = i+1; j < n-1; j++){
            if(res <= s[j]) res = s[j];
            if(res%f[j]) res += f[j]-(res%f[j]);
            res += c[j];
        }
        cout << res << endl;
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io;

fn read_int_2() -> (i32, i32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let s = s.trim().to_owned();
    let mut ws = s.split_whitespace();
    let x: i32 = ws.next().unwrap().parse().unwrap();
    let y: i32 = ws.next().unwrap().parse().unwrap();
    (x, y)
}

fn main() {
    let (n, d) = read_int_2();

    let mut ans=0;
    for _ in 0..n{
        let (x,y)=read_int_2();
        
        let d:i64=From::from(d);
        let x:i64=From::from(x);
        let y:i64=From::from(y);
        if x*x+y*y<=d*d{
            ans=ans+1;
        }
    }

    println!("{}",ans);
}


Measured memory_bytes: 2160
def ma():
  import sys
  input = sys.stdin.readline
  n,m=map(int,input().split())
  ans=0
  e=[set(list(map(int,input().split()))[1:]) for i in range(m)]
  f=list(map(int,input().split()))
  for i in range(2**n):
    l={a for a,b in zip(range(1,n+1),bin(i)[2:].zfill(n)) if b=="1"}
    for j in range(1,m+1):
      if len(e[j-1]&l)%2!=f[j-1]:break
    else:ans+=1
  print(ans)

if __name__=="__main__":
  ma()


Measured memory_bytes: 42460
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n;
vector<Int> a;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for(auto &i:a) cin >> i;
	vector<Int> b(a);
	sort(b.begin(), b.end());
	for(Int i=0; i<n; ++i)
		a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
//	for(Int i=0; i<n; ++i)
//		cout << a[i] << " \n"[i+1==n];
	Int ans = 0;
	for(Int i=0; i<n; ++i)
		if(a[i] % 2 != i % 2)
			++ans;
	cout << ans / 2 << "\n";
}

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

int main() {
    int N, K;
    cin >> N >> K;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = K; i < N; i++) {
        if (A[i] > A[i-K]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4412
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		int a = as.nextInt();
		int b = as.nextInt();
		int c;
		int l =0;
		if(a<b){
			for(int i=0;i<=a;i++){
				c=b;
				c-=i;
				for(int s=0;s<=a;s++){
					c-=s;
					if(c<0){
						break;
					}else {
						if(c>a){
							c+=s;
						}else{
							l++;
							c+=s;
						}
					}
				}
			}
		}else{
			l+=(b+2)*(b+1)/2;
		}
		System.out.println(l);
	}
}


Measured memory_bytes: 9684
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
struct E {
	int a, b, c;
	E(int aa, int bb, int cc) {
		a = aa; b = bb; c = cc;
	}
	E() {}
};

bool comp(E i, E j) {
	return i.c < j.c;
}
struct UnionFind {
	vector<int> par;
	vector<int> ran;

	UnionFind(int n) {
		par.resize(n);
		ran.resize(n);
		REP(i, n) {
			par[i] = i;
			ran[i] = 0;
		}
	}

	int root(int a) {
		return par[a] == a ? a : par[a] = root(par[a]);
	}

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

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y]) ran[x]++;
		}
	}
};
bool c(pair<pii,int> a, pair<pii,int> b) {
	if (a.first.second == b.first.second)return a.first.first < b.first.first;
	return a.first.second < b.first.second;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pair<pii,int>> v(n);
	REP(i, n) {
		cin >> v[i].first.first >> v[i].first.second;
		v[i].second = i;
	}
	vector<E> e;
	sort(ALL(v)); 
	REP(i, n) {
		if (i != 0) {
			int a = v[i].second, b = v[i - 1].second, c = min(abs(v[i].first.first - v[i - 1].first.first), abs(v[i].first.second - v[i - 1].first.second));
			e.push_back(E(a, b, c)); e.push_back(E(b, a, c));
		}
		if (i != n - 1) {
			int a = v[i].second, b = v[i + 1].second, c = min(abs(v[i].first.first - v[i + 1].first.first), abs(v[i].first.second - v[i + 1].first.second));
			e.push_back(E(a, b, c)); e.push_back(E(b, a, c));
		}
	}
	sort(ALL(v),c);
	REP(i, n) {
		if (i != 0) {
			int a = v[i].second, b = v[i - 1].second, c = min(abs(v[i].first.first - v[i - 1].first.first), abs(v[i].first.second - v[i - 1].first.second));
			e.push_back(E(a, b, c)); e.push_back(E(b, a, c));
		}
		if (i != n - 1) {
			int a = v[i].second, b = v[i + 1].second, c = min(abs(v[i].first.first - v[i + 1].first.first), abs(v[i].first.second - v[i + 1].first.second));
			e.push_back(E(a, b, c)); e.push_back(E(b, a, c));
		}
	}
	sort(ALL(e), comp);
	UnionFind uf(n);
	ll ans = 0;
	REP(i, e.size()) {
		E f = e[i];
		if (!uf.same(f.a, f.b)) {
			uf.unite(f.a, f.b);
			ans += f.c;
		}
	}
	cout << ans << endl;
}


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

int main(void)
{
    string a,b;
    //int a,b;
    int i;
    cin>>a>>b;
    for(i=0;i<3;i++)
    {
        if(a[i]!=b[2-i])
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
int main()
{
	int a,b;
	int count=0;
	cin>>a>>b;
	int p=b;
	while(p)
	{
		p/=10;
		count++;
	}
	ll sum=a*pow(10,count)+b;
	int flag=0;
	ll i;
	for(i=1;i<=sqrt(sum);i++)
	{
		if(i*i==sum)
		{
			flag=1;
		}
	}	
	if(flag==1)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	//cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

// MOD確認

ll ans[200010];

int main(){
    ll N;
    cin >> N;
    rep(i,N-1){
      ll a;cin >> a;
      a--;
      ans[a]++;
    }
    rep(i,N) cout << ans[i] << endl;
}


Measured memory_bytes: 5152
#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;

  //mapを宣言し、代入する
  map<string,int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++; //文字をインクリメントする
  }

  //頻度の最大値を求める
  int mx = 0;
  for (auto p : mp) mx = max(mx, p.second); //firstにインデックスキー、secondに値が代入されている
  for (auto p : mp) {
    if (p.second != mx) continue;
    cout << p.first << endl;//出力はキーのみで可能
  }
}


Measured memory_bytes: 25216
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
vector<char>se, ko;
int main() {
    string s;
    int q;
    cin >> s >> q;
    int h = 0;
    int t, f;
    char c;
    for (int i = 0; i < q; i++) {
        cin >> t;
        if (t == 1) {
            h++;
            continue;
        }
        else {
            cin >> f >> c;
            if (f == 1) {
                if (h % 2 == 0) {
                    se.emplace_back(c);
                }
                else {
                    ko.emplace_back(c);
                }
                continue;
            }
            else {
                if (h % 2 == 0) {
                    ko.emplace_back(c);
                }
                else {
                    se.emplace_back(c);
                }
                continue;
            }
        }
    }
    int n = se.size();
    int n1 = ko.size();
    if (h % 2 == 0) {
        for (int j = n - 1; j >= 0; j--) {
            cout << se[j];
        }
        cout << s;
        for (int k = 0; k < n1; k++) {
            cout << ko[k];
        }
    }
    else {
        for (int j = n1 - 1; j >= 0; j--) {
            cout << ko[j];
        }
        int n2 = s.size();
        for (int k = n2 - 1; k >= 0; k--) {
            cout << s[k];
        }
        for (int l = 0; l < n; l++) {
            cout << se[l];
        }
    }
    cout << endl;
    return 0;
}

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

using namespace std;

namespace abreto {

typedef vector<int> vi;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back

typedef long long int ll;

void main(void)
{
    ll N;
    ll minone = (ll) 1e16;
    cin >> N;
    for (int i = 0; i < 5; i++)
    {
        ll A;
        cin >> A;
        minone = min(minone, A);
    }
    ll teams = (N + minone - 1) / minone;
    cout << (teams + 4) << '\n';
}

}

int main(void)
{
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    abreto::main();
    return 0;
}


Measured memory_bytes: 256
import math
n=int(input())
def sosu(a):
    for i in range(2,int(math.sqrt(a))+1):
        if a%i==0:
            return False
    return True
m=0
for i in range(n):
    a=int(input())
    if sosu(a):
        m+=1
print(m)


Measured memory_bytes: 5672
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h> 

using namespace std;
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pb push_back
 
#ifdef LOCAL
    #define dbg(x) cout << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(10);
    solve();    
}

const int INF = 1e18, MAXN = 2e5 + 10, MOD = 1e9 + 7;

void solve() {
	string s; 
	cin >> s;
	int n = len(s);

	int cnt1 = 0, cnt2 = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] - '0' != i % 2) {
			cnt1++;
		}	

		if (s[i] - '0' != (i + 1) % 2) {
		 	cnt2++;
		}
	}

	cout << min(cnt1, cnt2) << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = (int) 2e5 + 7;
int n, a[N];
multiset<pair<int, int>> s;

void ins(int x, int y) {
  if (x > y) {
    swap(x, y);
  }
  s.insert({x, y});
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  s.insert({a[1], a[1]});
  ll sol = 0;
  for (int i = 2; i <= n; i++) {
    int x = a[i];
    auto it = s.end();
    it--;
    pair<int, int> pr = *it;
    sol += pr.first;
    s.erase(s.find(pr));
    ins(pr.first, x);
    ins(x, pr.second);
  }
  cout << sol << "\n";
  return 0;
}
//4
//8 7 6 6


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

using namespace std;
string s;

void revert(int begin, int end)
{
    for (int i = end; i <= begin; i++)
    {
        if (s[i] == 'L')
            s[i] = 'R';
        else
            s[i] = 'L';
    }
}

void cal(int N, int *K, int *num)
{
    int f_begin, begin, end;
    f_begin = begin = N - 2;
    while ((*K) > 0 && f_begin > 0)
    {
        for (; begin > 0 && s[begin] == s[N - 1]; begin--)
            ;
        for (end = begin - 1; end > 0 && s[end] != s[begin]; end--)
            ;
        for (; end > 0 && s[end] == s[begin] && s[end - 1] == s[begin]; end--)
            ;

        if (end > 0)
        {
            revert(begin, end);
            (*K)--;
            begin = end - 2;
        }
        else
        {
            for (f_begin = f_begin - 1; f_begin > 0 && s[f_begin] == s[N - 1]; f_begin--)
                ;
            begin = f_begin;
        }
    }
}

int main()
{
    int N, K, num = 0;
    char t;

    cin >> N >> K;
    cin >> s;

    cal(N, &K, &num);

    if (N > 1)
    {
        if (K > 0 && s[1] == s[N - 1])
        {
            for (int i = 2; i < N; i++)
                if (s[i] != s[N - 1])
                {
                    s[i] = s[N - 1];
                    K--;
                    break;
                }
        }
        if (K > 0 && s[0] != s[N - 1])
        {
            int i;
            for (i = 1; s[i] == s[0]; i++)
                ;
            revert(i - 1, 0);
            K--;
        }
        if (K > 0 && s[1] != s[N - 1])
        {
            s[1] = s[N - 1];
            K--;
        }
    }

    for (int i = 0; i < N - 1; i++)
    {
        if (s[i + 1] == s[i])
            num++;
    }

    cout<< num << endl;

    return 0;
}

Measured memory_bytes: 3756
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>

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


int main()
{
    int a,b;
    int c[4]={};
    REP(i,2){
        scanf("%d%d",&a,&b);
        c[a]++;
        c[b]++;
    }
    scanf("%d%d",&a,&b);
    if(c[a]==2||c[b]==2)printf("NO\n");
    else printf("YES\n");
    return 0;
}

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

int main()
{
    int x, y;
    while (1) {
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x < y) {
            cout << x << " " << y << endl;
        }
        else if (x > y) {
            cout << y << " " << x << endl;
        }
        else {
            cout << x << " " << y << endl;
        }
    }
}


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

long int a,b,ans,sum;
int main()
{

    while(scanf("%ld%ld",&a,&b)!=EOF)
    {
        ans=0;
        sum=a+b;
        while(1){

        if(sum<10)
        {
            ans=ans+1;
            break;
        }
        ans=ans+1;
        sum=sum/10;
        }
        printf("%ld\n",ans);
    }
}

Measured memory_bytes: 1188
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val h, w = sc.nextInt
    sc.nextLine
    val s = new Array[Array[Char]](h)
    for (i <- 0 until h) {
      s(i) = sc.nextLine.toCharArray
    }

    val result = ArrayBuffer.fill[ArrayBuffer[Int]](h)(ArrayBuffer.fill[Int](w)(0))

    val SHP = 1001001001
    val DI = Array(-1, -1, 0, 1, 1, 1, 0, -1)
    val DJ = Array(0, -1, -1, -1, 0, 1, 1, 1)

    for (si <- 0 until h; sj <- 0 until w) {
      // すべてのマスをチェックしていく
      if (s(si)(sj) == '#') {
        result(si)(sj) = SHP
      } else {
        for (i <- 0 until 8) {
          val ni = si + DI(i)
          val nj = sj + DJ(i)
          if (
            ((ni >= 0 && ni < h) && (nj >= 0 && nj < w)) // 枠内に収まる
              && s(ni)(nj) == '#' // 到達不可能マス
          ) {
            result(si)(sj) += 1
          }
        }
      }
    }
    result.foreach(raw => println(raw.map(v => if (v == SHP) "#" else v.toString).mkString))
  }
}


Measured memory_bytes: 28124
#D問題
#gcd(二つの数)
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)

A,B = map(int,input().split())
G = gcd(A,B)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        if 2 not in a:
            a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f not in a:
                a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        if n not in a:
            a.append(n)
    return a

li = prime_factorize(G)
#print(li)
print(len(li)+1)
    

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> h(n);
  for(int i = 0;i < n;i++)cin >> h[i];
  vector<ll> res(n);
  for(int i = 0;i < n;i++)res[i] = 100000000000;
  res[0] = 0;
  //res[1] = abs(h[0] - h[1]);
  for(int i = 0;i < n - 1;i++){
    for(int j = i + 1;j < min(i + k + 1,n);j++){
      res[j] = min(res[j],res[i] + abs(h[j] - h[i]));
    }
  }
  //for(auto i:res)cout << i << " ";
  //cout << endl;
  cout << res[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    rep(i, 365) {
        cout << 26-(i+rand()%2)%26 << endl;
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int N;
    string S;
    cin >> N >> S;
    vector<int> E(N+2), W(N+2);
    for(int i=0; i<N; i++) {
        if(S[i] == 'W') {
            W[i+1] = W[i] + 1;
        } else {
            W[i+1] = W[i];
        }
    }
    for(int i=N-1; i>=0; i--) {
        if(S[i] == 'E') {
            E[i+1] = E[i+2] + 1;
        } else {
            E[i+1] = E[i+2];
        }
    }

    int ans = numeric_limits<int>::max();
    for(int i=1; i<=N; i++) {
        ans = min(ans, W[i-1] + E[i+1]);
    }

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


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

typedef long long ll;

const ll MOD = 1e9+7;

int main() {
    int n; cin >> n;
    vector<ll> t(n), a(n);
    for (int i=0; i<n; ++i) {
        cin >> t[i];
    }
    for (int i=0; i<n; ++i) {
        cin >> a[i];
    }
    vector<bool> ft(n);
    ll cur=t[0];
    ft[0]=true;
    for (int i=1; i<n; ++i) {
        if (t[i]!=cur) {
            ft[i]=true;
            cur=t[i];
        }
    }
    vector<bool> fa(n);
    cur=a[n-1];
    fa[n-1]=true;
    for (int i=n-1; i>=0; --i) {
        if (a[i]!=cur) {
            fa[i]=true;
            cur=a[i];
        }
    }
    ll ans=1;
    for (int i=0; i<n; ++i) {
        if (fa[i] && ft[i]) {
            if (a[i]!=t[i]) {
                ans=0;
            }
        } else if (fa[i]) {
            if (a[i]>t[i]) {
                ans=0;
            }
        } else if (ft[i]) {
            if (t[i]>a[i]) {
                ans=0;
            }
        } else {
            ans*=min(a[i], t[i]);
            ans%=MOD;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int i=1;
  while(a>0 && c>0) {
    if(i%2==1) {
      c-=b;
    }else {
      a-=d;
    }
    i++;
  }
  if(a>0) {
    cout<<"Yes";
  }else {
    cout<<"No";
  }
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	int max = 0;
	int now = 0;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int H;
		cin >> H;
		if (now >= H) sum++;
		else {
			max = max < sum ? sum : max;
			sum = 0;
		}
		now = H;
	}
	max = max < sum ? sum : max;
	cout << max << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#define ll long long

int main(){
    ll n, d; scanf("%lld%lld", &n, &d);
    int ans = 0;
    for (ll i = 0; i < n; i++){
        ll x, y; scanf("%lld%lld", &x, &y);
        if (x*x+y*y <= d*d) ans++;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



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

  ll ans = INF<ll>;
  ll snuke = 0, kuma;
  rep(i, n-1) {
    _sum -= a[i];
    snuke += a[i];
    kuma = _sum;
    ans = min(ans, abs(snuke - kuma));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>

typedef long long ll;

int main(int argc, char** argv) {
  ll s, t;
  std::cin >> s >> t;
  

  ll l1 = 25 * s, r1 = 25 * s + 24;
  ll l2 = 20 * t, r2 = 20 * t + 18;

  ll b = std::min(r1, r2), a = std::max(l1, l2);
  if (b < a)
    std::cout << "-1\n";
  else {
    if (a != b) {
      if (a & 1)
        std::cout << (a + 1) / 2 << std::endl;
      else
        std::cout << a / 2 << std::endl;
    } else {
      if (a % 2 == 0)
        std::cout << (a / 2) << '\n';
      else
        std::cout << "-1\n";
    }
  }
}

Measured memory_bytes: 256
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　| 　_　 _ l
　 　　　／` ミ＿xノ
　　 　 /　　　 　 |　見ちゃだめだよ！
　　　 /　 ヽ　　 ﾉ　　
　 　 │　　|　|　|　　
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)__)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  string s[50];
  int h, w;
  cin >> h >> w;

  rep(i, h) cin >> s[i];

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

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;

      int num = 0;
      for (int d = 0; d < 8; ++d) {
        const int ni = i + dy[d];
        const int nj = j + dx[d];

        if (ni < 0 or h <= ni) continue;
        if (nj < 0 or w <= nj) continue;
        if (s[ni][nj] == '#') num++;
      }

      s[i][j] = char(num + '0');
    }
  }

  for (int i = 0; i < h; i++) cout << s[i] << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define mod (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A,ll B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	a--;
	ll l = (c*d)/gcd(c,d);
	b = b - (b/d + b/c - b/l);
	a = a - (a/d + a/c - a/l);
	cout<<b-a;
	
}


Measured memory_bytes: 3592
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func calc(ps []int, cs []int, k int, s int) int {
	n := len(ps)
	mx := int(-1e18)
	l := 0
	sumT := 0
	done := make([]bool, n)
	var dfs func(i int)
	dfs = func(i int) {
		if done[i] {
			return
		}
		l++
		done[i] = true
		sumT += cs[i]
		mx = larger(mx, sumT)
		k--
		if k == 0 {
			return
		}
		dfs(ps[i])
	}
	dfs(ps[s])

	if sumT > 0 && k > 0 {
		cc := k / l
		if k%l == 0 {
			cc = (k - 1) / l
		}
		sumT += sumT * cc
		mx = larger(mx, sumT)
		k -= cc * l
		done = make([]bool, n)
		dfs(ps[s])
	}
	return mx
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	n := iScan()
	k := iScan()
	ps := make([]int, n)
	for i := 0; i < n; i++ {
		ps[i] = iScan()
		ps[i]--
	}
	cs := make([]int, n)
	for i := 0; i < n; i++ {
		cs[i] = iScan()
	}
	ans := int(-1e18)
	for i := 0; i < n; i++ {
		c := calc(ps, cs, k, i)
		ans = larger(ans, c)
	}
	fmt.Println(ans)
}

Measured memory_bytes: 6860
N, T = map(int, input().split())
A = list(map(int, input().split()))

B = []
n = A[0]
for a in A:
    B.append(a-n)
    n = min(n, a)

B.sort(reverse=True)
c = 0
for b in B:
    if b == B[0]:
        c += 1
    else:
        break
print(c)

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

public class Program
{
	public static void Main()
	{
		var NM = Console.ReadLine().Split().Select(long.Parse);
		long N = NM.First(), M = NM.Last() / 2;
		if (M <= N)
		{
			Console.WriteLine(M);
		}
		else
		{
			Console.WriteLine((N + M) / 2);
		}
	}
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
using P = pair<int, int>;
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<P> AB(N);
    REP(i, N) { cin >> AB[i].first >> AB[i].second; }
    sort(ALL(AB));

    int ans = 0;
    priority_queue<int> q;

    int now = 0;
    REP(d, M + 1) {
        int i = M - d;
        // cout << "i:" << i << " d:" << d << endl;
        while (AB[now].first <= d) {
            q.push(AB[now].second);
            now++;
        }
        if (!q.empty()) {
            ans += q.top();
            // cout << " " << q.top() << endl;
            q.pop();
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
using namespace std;
int main(void){
  int a[3];
  int mn = 101;
  int mx = -1;
  for(int i = 0; 3 > i ; i++){
    cin >> a[i];
    if(mn > a[i]) mn = a[i];
    if(mx < a[i]) mx = a[i];
    
  }
  cout << mx - mn << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n,i,x,t=1;
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        if(x%2==0) if(x%3 && x%5) t=0;
    }

    if(t) printf("APPROVED\n");
    else printf("DENIED\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,ll>;
vector<vector<P>> tree(100010);
vector<ll> depth(100010);

void dfs(int v,int p,ll d){
    depth[v] = d;
    for(auto e : tree[v]){
        if(e.first == p) continue;
        dfs(e.first, v, d+e.second);
    }
}

int main(){
    int n; cin >> n;
    for(int i = 0;i<n-1;++i){
        int a, b;ll c; cin >> a >> b >> c;
        a--;b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }
    int q,k; cin >> q >> k;
    k--;
    dfs(k,-1,0ll);
    rep(i,q){
        int x,y; cin >> x >> y;
        x--;y--;
        cout << depth[x]+depth[y] << endl;
    }
}


Measured memory_bytes: 14336