akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
	
//see http://www.prefield.com/algorithm/container/range_minimum.html

int *buildRMQ(int *a, int n) {
  int logn = 1;
  for (int k = 1; k < n; k *= 2) ++logn;
  int *r = new int[n * logn];
  int *b = r; copy(a, a+n, b);
  for (int k = 1; k < n; k *= 2) {
    copy(b, b+n, b+n); b += n;
    rep(i, n-k) b[i] = min(b[i], b[i+k]);
  }
  return r;
}
int minimum(int x, int y, int *rmq, int n) {
  int z = y - x, k = 0, e = 1, s; // y - x >= e = 2^k なる最大 k
  s = ( (z & 0xffff0000) != 0 ) << 4; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x0000ff00) != 0 ) << 3; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x000000f0) != 0 ) << 2; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x0000000c) != 0 ) << 1; z >>= s; e <<= s; k |= s;
  s = ( (z & 0x00000002) != 0 ) << 0; z >>= s; e <<= s; k |= s;
  return min( rmq[x+n*k], rmq[y+n*k-e+1] );
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    int p[250000];rep(i,n)cin>>p[i];
    vector<ll> k_inc(n,0);
    ll cnt = 1;
    for(ll i=n-2; i>=0; i--){
        if(p[i]<p[i+1])cnt++;
        else cnt=1;
        if(cnt>=k)k_inc[i]=1;
    }
    //rep(i,n)cout<<k_inc[i];
    vector<ll> k_inc_sum(n,0);
    for(ll i=n-2; i>=0; i--){
        k_inc_sum[i]=k_inc_sum[i+1]+k_inc[i];
    }
    //rep(i,n)cout<<k_inc_sum[i];
    ll ans = n-k+1;//separated
    /*for(ll i=n-k-1; i>=0; i--){
        ans -= k_inc[i]*k_inc_sum[i+k];
    }*/
    if(k_inc_sum[0])ans-=k_inc_sum[0]-1;
    
    int minus_p[250000];rep(i,n)minus_p[i]=-p[i];
    int *RMQ = buildRMQ(p,n);
    int *minus_RMQ = buildRMQ(minus_p,n);
    for(int i=0; i+k<n; i++){
        if(!(k_inc[i])&&p[i]==minimum(i,i+k,RMQ,n)&&p[i+k]==-minimum(i,i+k,minus_RMQ,n))ans--;
    }


    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 34688
package main

import "fmt"

func main() {
	var a, b, c, x, y int
	fmt.Scan(&a, &b, &c, &x, &y)

	maxXY := x
	if y > maxXY {
		maxXY = y
	}
	ans := a*x + b*y
	for i := 1; i <= maxXY; i++ {
		if x > 0 {
			x--
		}
		if y > 0 {
			y--
		}
		if v := a*x + b*y + 2*i*c; v < ans {
			ans = v
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char b;
int main(){
    cin>>b;
    switch(b){
        case 'A':cout<<'T';break;
        case 'G':cout<<'C';break;
        case 'C':cout<<'G';break;
        case 'T':cout<<'A';break;
    }

}


Measured memory_bytes: 256
N = int(input())
n = 1000000000000001

# 数値→アルファベット
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

print(num2alpha(N).lower())

Measured memory_bytes: 9128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


static const int N = 100;


int main()
{
	int M[N][N];
	int n, u, k, v;
	
	cin >> n;
	rep(i, n) rep(j, n) M[i][j] = 0;
	rep(i, n)
	{
		cin >> u >> k;
		u--;
		rep(j, k)
		{
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	
	rep(i, n)
	{
		rep(j, n)
		{
			if (j) cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1196
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')


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


c = 1
ans = 0
for a in A:
    if a == c:
        c += 1
        continue
    ans += 1
if ans == N:
    print(-1)
else:
    print(ans)

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

typedef  long long ll;

#define rep(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(ll (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007


using namespace std;

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

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

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}


void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

ll divisors(ll n) {
    vector<ll> res;

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i-1);
        if(n/i == i) continue;
        res.push_back((n/i)-1);
    }

    ll ans = 0;

    rep(i,0,res.size()){
        if(res[i] != 0)
        if(n/res[i] == n%res[i]) ans += res[i];
    } 
    return ans;
}
vector<string> ans;

void solve(void){
    ll n;
    cin >> n;
    vector <ll> x(n),y(n);
    rep(i,0,n) {
        cin >> x[i];
        y[i] = x[i];
    }
    sort(y.begin(),y.end());
    
    rep(i,0,n){
        if(x[i] <= y[n/2-1]) cout << y[n/2] << endl;
        else cout << y[n/2-1] << endl;
    }

}

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

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

int main(void){
  int n;
  int price = 0;
  int max=0;
  int sum = 0;
  vector<int> v;

  cin >> n;
  for(int i = 0;i<n;i++){
    cin >> price;
    v.push_back(price);
  }
  for(auto s:v){
    if(s > max){
      max = s;
    }
    sum += s;
  }
  sum -= max/2;

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

int main(){
  char buf[1024];
  int *a=(int *)malloc(sizeof(int)*5);

  rep(i,5){
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf, "%d", &a[i]);
  }

  int min=INF;
  int min_n=INF;
  rep(i,5){
    int temp=a[i]%10;
    if(temp!=0 && temp<min){
      min=temp;
      min_n=i;
    }
  }

  int ans=0;
  rep(i,5){
    if(a[i]%10==0){
      ans+=a[i];
    }
    else if(i!=min_n){
      ans+=((a[i]/10)+1)*10;
    }
    else{
      ans+=a[i];
    }
  }

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


  return 0;


}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n;
    cin >> n;
    vvi cnt(10, vi(10, 0));
    repf(i, n){
        vi d;
        lli digit = i;
        while(digit != 0){
            d.push_back(digit % 10);
            digit /= 10;
        }
        lli a = d.front();
        lli b = d.back();
        if(a == 0 || b == 0) continue;
        else cnt[a][b]++;
    }
    lli ans = 0;
    repf(i, 9){
        repf(j, 9){
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=1234;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    ll n;
	while(sf("%lld",&n)==1)
	{
		if(n%11==0)pf("%lld\n",(n/11)*2);
        else
        {
            ll ans=n/11;
            ans*=2;
            if(n%11>6)ans+=2;
            else ans++;
            pf("%lld\n",ans);
        }
	}
    return 0;
}
 









 




























Measured memory_bytes: 256
/* 
    @author : srinathbalaji_99
*/


#include<bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for(long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b)/GCD(a, b)
#define ff first
#define ss second
#define pall(a) REP(i, sizeof(a)/sizeof(a[0]))cout << a[i] << " ";cout << endl;
#define pvall(v) REP(i, v.size())cout << v[i] << " ";cout << endl;
#define gall(a, n) REP(i, n)cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;


using namespace std;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

LL weight[101], value[101], dp[101][100001];

int main()
{
    fast();

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    LL t,n,i,j,k,x,y,c, W;
    cin >> n >> W;
    REP(i, n){
        cin >> weight[i] >> value[i];
    }

    REP(i, n){
        for(LL w = 0; w <= W; ++w){
            if(w - weight[i] >= 0){
                dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + value[i]);
            }
            else dp[i + 1][w] = dp[i][w];
        }
    }

    cout << dp[n][W];
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int x, y;
        cin >> x >> y;
        if(y % 2 == 0 and y / 2 - x >= 0 and 2 * x - y / 2 >= 0){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 34596
inf = 10**9
H, N = map(int, input().split())
AB = []
for n in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(reverse=True, key=lambda x: x[0])
dp = [inf] * (H + 10 ** 4)
dp[0] = 0
for a, b in AB:
    for h in range(H):
        if dp[h] != inf:
            tmp = dp[h] + b
            if tmp < dp[h + a]:
                dp[h + a] = tmp
print(min(dp[H:]))


Measured memory_bytes: 41580
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
typedef long long LL;
int main()
{
    int N;
    scanf("%d",&N);
    int t = N;
    int sn = 0;
    while(t) {
        sn += t%10;
        t/=10;
    }
    printf("%s\n",N%sn?"No":"Yes");
}


Measured memory_bytes: 256
import math

tmp = list(map(int,input().split()))
a = tmp[0]
b = tmp[1]
x = tmp[2]

h = x / (a * a)


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

Measured memory_bytes: 38524
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int count(ll x){
	int cnt = 0;
	while(x != 0){
		cnt++;
		x /= 10;
	}
	return cnt;
}
vector< pair< int , int > > st(100) , ch(100);
vector< int > ans(100);
int main()
{
	int n , m;
	cin >> n >> m;
	for(int i = 1 ; i <= n ; i++)
	{
		int a , b;
		cin >> a >> b;
		st[i]={a,b};
	}
	for(int j = 1 ; j <= m ; j++){
		int a , b;
		cin >> a >> b;
		ch[j]= {a,b};
	}
	for(int i = 1 ; i <= n ; i++){
		int ans1 = 999999999;
		for(int j = 1 ; j <= m ; j++){
			int temp = abs(st[i].first - ch[j].first) + abs(st[i].second - ch[j].second);
			if(temp < ans1){
				ans1=temp;
				ans[i] = j;
			}
		}
	}
	for(int i = 1 ; i <= n ; i++)
		cout << ans[i] << endl;
}



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

typedef vector<int> vi;
typedef set<int> si;

class UnionFind {
	private: 
		vi p, rank, t;
	public:
		UnionFind(int N) { 
			rank.assign(N, 0);
			t.assign(N, 1);
			p.assign(N, 0); 
			for (int i = 0; i < N; i++) 
				p[i] = i;
		}
		int findSet(int i) { 
			return (p[i] == i) ? i : (p[i] = findSet(p[i])); 
		}
		bool isSameSet(int i, int j) { 
			return findSet(i) == findSet(j);
		}
		void unionSet(int i, int j) {
			if (!isSameSet(i, j)) {
				int x = findSet(i), y = findSet(j);
				if (rank[x] > rank[y]) {
					p[y] = x;
					t[x] += t[y];
				} else {
					p[x] = y;
					t[y] += t[x];
					if (rank[x] == rank[y])
						rank[y]++;
				}
			}
		}
		int totalSet(int i) {
			return t[findSet(i)];
		}
};

int main()
{
	int n, m, x, y, z, i, c = 0;
	scanf("%d %d", &n, &m);
	//vi cards()
	UnionFind UF(n + 1);
	si parents;
	for (i = 0; i < m; i++) {
		scanf("%d %d %d", &x, &y, &z);
		if (!UF.isSameSet(x, y))
			UF.unionSet(x, y);
	}
	for (i = 1; i <= n; i++)
		parents.insert(UF.findSet(i));
	printf("%d\n", (int)parents.size());
	return 0;
}

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

int main(){
  string s;
  map<char, int> mp;
  int sum = 0;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'S') mp[s[i]]++;
    if(s[i] == 'T' && mp['S'] != 0) sum += 2, mp['S']--;
  }
  cout << s.size() - sum << endl;
  return 0;
}

Measured memory_bytes: 640
from ctypes import *
import subprocess as sp
from operator import itemgetter
import sys
import os.path

set_code = r"""
#include <set>

std::set<int> s;

void add(int x) {
    s.insert(x);
}

bool find(int x) {
    return s.find(x) != s.end();
}

void remove(int x) {
    s.erase(x);
}

bool empty() {
	return s.empty();
}

int getMin() {
	return *s.begin();
}
"""

class CppSet:
	counter = 0

	def __init__(self):
		lib_name = './hoge{}.so'.format(CppSet.counter)

		code_file_name = "tmp.cpp"
		with open(code_file_name, "w") as f:
			f.write(set_code)

		CppSet.counter += 1
		sp.Popen(['g++', '-fPIC', '-shared', '-std=c++11', code_file_name, '-o', lib_name]).communicate()

		lib = CDLL(lib_name)
		self.add = getattr(lib, "_Z3addi")
		self.find = CFUNCTYPE(c_bool, c_int)(
						("_Z4findi", lib),
						((1, "x"), )
					)
		self.remove = getattr(lib, "_Z6removei")
		self.empty = CFUNCTYPE(c_bool)(
						("_Z5emptyv", lib),
						()
					)

		self.getMin = CFUNCTYPE(c_int)(
						("_Z6getMinv", lib),
						()
					)

def main():
	N, Q = map(int, sys.stdin.readline().split())
	tmp = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
	stx = [(s - x, 1, x) for s, t, x in tmp] + [(t - x, -1, x) for s, t, x in tmp]
	stx.sort()
	
	D = [int(sys.stdin.readline()) for _ in range(Q)] 
	ans = [-1]*Q

	idx = 0
	stx_len = len(stx)
	se = CppSet()
	for i, d in enumerate(D):
		while idx < stx_len:
			t, com, x = stx[idx]
			if t > d:
				break
			if com == 1:
				se.add(x)
			else:
				se.remove(x)
			idx += 1
		ans[i] = (-1 if se.empty() else se.getMin())

	print(*ans, sep='\n')

if __name__ == "__main__":
	main()


Measured memory_bytes: 111376
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        if (x == y) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int H, W;
    read(H, W);

    char mat[55][55] {};
    reps(i, 1, H) {
        reps(j, 1, W) {
            char c; read(c);
            mat[i][j] = c;
        }
    }

    reps(i, 1, H) reps(j, 1, W) {
        if (mat[i][j] == '.') {
            int cnt = 0;
            reps(y, i-1, i+1) reps(x, j-1, j+1) cnt += mat[y][x] == '#';
            mat[i][j] = '0' + cnt;
        }
    }

    reps(i, 1, H) {
        reps(j, 1, W) cout << mat[i][j];
        cout << endl;
    }

    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int s = S.size();
  vector<int> RL(0);
  int cnt = 0;
  for (int i = 0; i < s; i++) {
    if (S[i] != S[i+1]) {
      cnt++;
      RL.push_back(cnt);
      cnt = 0;
    }
    else {
      cnt++;
    }
  }
  int rl = RL.size();
  vector<int> ans(s, 0);
  int len = 0;
  for (int i = 0; i < rl/2; i++) {
    int r = RL[2*i];
    int l = RL[2*i+1];
    int c = max(r, l) -1;
    if (c%2 == 1 && r >= l) {
      ans[len+r-1] = (r+l)/2;
      ans[len+r] = ceil((r+l)/2.0);
    }
    if (c%2 == 1 && r < l) {
      ans[len+r-1] = ceil((r+l)/2.0);
      ans[len+r] = (r+l)/2;
    }
    if (c%2 == 0 && r >= l) {
      ans[len+r-1] = ceil((r+l)/2.0);
      ans[len+r] = (r+l)/2;
    }
    if (c%2 == 0 && r < l) {
      ans[len+r-1] = (r+l)/2;
      ans[len+r] = ceil((r+l)/2.0);
    }
    len += RL[2*i] + RL[2*i+1];
  }
  for (int i = 0; i < s; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}

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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef unsigned int UI;
typedef pair<int, int> pii;

namespace IO
{
    const UI Buffsize=1<<15,Output=1<<24;
    static char Ch[Buffsize],*St=Ch,*T=Ch;
    inline char getc()
    {
        return((St==T)&&(T=(St=Ch)+fread(Ch,1,Buffsize,stdin),St==T)?0:*St++);
    }

    template<typename T>inline T read()
    {
        T x=0;static char ch;T f=1;
        for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
        for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
		return x * f;
    }
}
using IO::read;

const int MOD = (int) 1e9 + 7;

const int MAXN = (int) 2e6;

struct point
{
	int x, y, rnk;

	point() { }
	point(int _x, int _y): x(_x), y(_y) { }
}a[MAXN + 5];

int n;

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) a[i].x = read<int>(), a[i].y = read<int>();
}

inline void solve()
{
	static int rnk[MAXN + 5];

	sort(a + 1, a + n + 1, [&](point p, point q) { return p.y < q.y; });
	for(int i = 1; i <= n; ++i) a[i].rnk = i;

	static pii seg[MAXN + 5];

	sort(a + 1, a + n + 1, [&](point p, point q) { return p.x < q.x; });
	seg[0].snd = 0;
	for(int i = 1; i <= n; ++i) seg[i].snd = max(a[i].rnk, seg[i - 1].snd);
	seg[n + 1].fst = n + 1;
	for(int i = n; i >= 1; --i) seg[i].fst = min(a[i].rnk, seg[i + 1].fst);

	sort(seg + 1, seg + n + 1, [&](pii p, pii q) { return p.snd == q.snd ? p.fst < q.fst : p.snd < q.snd; });

	static int f[MAXN + 5], pre[MAXN + 5];

	f[0] = 1, pre[0] = 1;
	for(int lst_pos = 0, i = 1; i <= n; ++i)
	{
		for(int j = lst_pos + 1; j <= seg[i].snd; ++j) pre[j] = (pre[j - 1] + f[j]) % MOD;
		lst_pos = seg[i].snd;
		(f[seg[i].snd] += (pre[seg[i].snd] - (seg[i].fst == 1 ? 0 : pre[(seg[i].fst - 1) - 1])) % MOD) %= MOD;
		pre[seg[i].snd] = (pre[seg[i].snd - 1] + f[seg[i].snd]) % MOD;
	}

	printf("%d\n", (f[n] + MOD) % MOD);
}

int main()
{
#ifdef K_ON
	freopen("run.in", "r", stdin);
	freopen("run.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 10496
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  int N;
  long long K;
  cin>>N>>K;
  PA S[100000];
  FOR(i,0,N){
    cin>>S[i].first>>S[i].second;
  }
  sort(S,S+N);
  int i=0;
  while(K>0&&i<N){
    K-=S[i].second;
    i++;
  }
  i--;
  cout<<S[i].first<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
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; }
const long long MOD = 1000000007;
const long long INF = (1LL << 29);
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
	cout << max({ (n - 1) / a,(n - 1) / b,(n - 1) / c,(n - 1) / d,(n - 1) / e }) + 5 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <cmath>
#include <iostream>
using i64 = long long;
using namespace std;

class ModInt {
public:
  int value;
  static const int mod = 1e9 + 7;
  ModInt() : value(0) {}
  ModInt(int value) {
    this->value = normalize(value);
  }  
  ModInt operator+(ModInt const &other) {
    return ModInt(normalize(this->value + other.value));
  }
  ModInt operator-(ModInt const &other) {
    return ModInt(normalize(this->value - other.value));
  }
  ModInt& operator+=(const ModInt& other) {
      this->value = normalize(this->value + other.value);
      return *this;
}
  int normalize(i64 value) {
    while (value < 0) value += mod;
    value %= mod;
    return value;
  }
};
 
ostream& operator<<(ostream& os, ModInt const &m) {
  os << (m.value);
  return os;
}

const int maxn = 21;
int n;
int a[maxn + 1][maxn + 1];
ModInt dp[1 << 21];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) 
    for (int j = 0; j < n; j++)
      cin >> a[i][j];
  
  dp[0] = 1;
  for (int b = 1; b < (1 << 21); b++) {
    int man = __builtin_popcount(b) - 1;
    for (int t = b; t; ) {
      int woman = __builtin_ctz(t);

      if (a[woman][man]) 
        dp[b] += dp[b & ~(1 << woman)];

      t &= ~(1 << woman);
    }
  }
  cout << dp[(1 << n) - 1] << endl;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll update(ll t)
{
    ll s[15],cnt=0;
    while(t)
    {
        s[cnt++]=t%10;
        t/=10;
    }
    int i=0;
    for(; i<cnt; i++)
    {
        if(s[i]==7)
            s[i]=3;
        else
        {
            if(s[i]==3)
                s[i]=5;
            else if(s[i]==5)
                s[i]=7;
            break;
        }
    }
    if(i>=cnt)
        s[cnt]=3,cnt++;
    ll ans=0;
    for(i=cnt-1; i>=0; i--)
        ans=ans*10+s[i];
    return ans;
}
bool check(ll t)
{
    int f1=0,f2=0,f3=0;
    while(t)
    {
        ll p=t%10;
        if(p==3)
            f1++;
         if(p==5)
            f2++;
         if(p==7)
            f3++;
            if(f1&&f2&&f3)
                return true;
        t/=10;
    }
    return false;
}
int main()
{
    ll n;
    scanf("%lld",&n);
    ll ans=0,tmp=333;
    while(tmp<=n)
    {
        if(check(tmp))
            ans++;
        tmp=update(tmp);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2,s3;
    int n,m,i,a[200010],f=0,j;
    set <int> s;
    //vector <int> v1;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>m;
        s.insert(m);
        //v1.push_back(m);
    }
    if(s.size()!=n)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}




Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n, k; cin >> n >> k;

    int tr = (n - 1) * (n - 2) / 2;
    if (tr < k) {
        cout << -1 << endl;
        return 0;
    }

    int m = n - 1 + tr - k;
    cout << m << endl;

    loop (n - 1, i) {
        cout << 1 << " " << i + 2 << endl;
    }
    int cnt = 0;
    loop (n - 1, i) loop (n - 1, j) {
        if (i >= j) continue;
        if (cnt >= tr - k) break;
        cout << i + 2 << " " << j + 2 << endl;
        cnt++;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a, b;   
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> a >> b;
    if (a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int w;
	int h;
} mt;

int max(int a, int b) {
	return a > b ? a : b;
}

int main(void) {
	while(1) {
		int N, M, i, j;
		mt M1[100];
		mt M2[100];
		mt M3[200];
		scanf("%d", &N);
		if (N == 0) break;
		for(i = 0; i < N; i++) {
			scanf("%d %d", &(M1[i].w), &(M1[i].h));
		}
		scanf("%d", &M);
		for(j = 0; j < M; j++) {
			scanf("%d %d", &(M2[j].w), &(M2[j].h));
		}
		
		//merge
		int target = 0;
		int lt = 0, gt = 0;
		while(1) {
			while(lt < N && gt < M && M1[lt].w > M2[gt].w) {
				M3[target].w = M2[gt].w;
				M3[target].h = M2[gt].h;
				gt++;
				target++;
			}
			while(lt < N && gt < M && M1[lt].w < M2[gt].w) {
				M3[target].w = M1[lt].w;
				M3[target].h = M1[lt].h;
				lt++;
				target++;
			}
			while(lt < N && gt < M && M1[lt].w == M2[gt].w) {
				if (M1[lt].h < M2[gt].h) {
					M3[target].w = M1[lt].w;
					M3[target].h = M1[lt].h;
					lt++;
					target++;
				} else {
					M3[target].w = M2[lt].w;
					M3[target].h = M2[lt].h;
					gt++;
					target++;
				}
			}
			while(lt == N && gt < M) {
				M3[target].w = M2[gt].w;
				M3[target].h = M2[gt].h;
				gt++;
				target++;
			}
			while(gt == M && lt < N) {
				M3[target].w = M1[lt].w;
				M3[target].h = M1[lt].h;
				lt++;
				target++;
			}
			if (lt == N && gt == M) break;
		}
		
		//dp
		int dp[200] = {0};

		for(i = 0; i < N + M - 1; i++) {
			for(j = i + 1; j < N + M; j++) {
				if (M3[i].w < M3[j].w && M3[i].h < M3[j].h) {
					dp[j] = max(dp[j], dp[i] + 1);					
				}
			}
		}
		int ans = 0;
		for(i = 0; i < N + M; i++) {
			if (dp[i] > ans) {
				ans = dp[i];
			}
		}
		printf("%d\n", ans + 1);
	}
	
	
	return 0;
}

Measured memory_bytes: 604
#include<cstdio>

#define MIN(X,Y) ((X<Y)?(X):(Y))

int trrt(int x) {
    int a,b;
    a=-1000;
    b=10000;
    while(b-a>1) {
        int m = (a+b)/2;
        if(m*m*m > x)
            b = m;
        else
            a = m;
    }
    return b;
}
int sqrt(int x) {
    int a,b;
    a=0;
    b=10000;
    while(b-a>1) {
        int m = (a+b)/2;
        if(m*m > x)
            b = m;
        else
            a = m;
    }
    return b;
}

int main(void) {
    while(true) {
        int e,res=1e6;
        scanf("%d", &e);
        if(!e) break;

        int zmax = trrt(e)*2;
        for(int z=0; z<zmax; z++) {
            int ymax = sqrt(e-z*z*z)*2;
            for(int y=0; y<ymax; y++) {
                int x = e - y*y - z*z*z;
                if(x<0) continue;

                res = MIN(x+y+z, res);
            }
        }

        printf("%d\n", res);
    }
    return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace _gnu_pbds;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define fr(i,a,b) for(ll i = a ; i < b ; i++)
#define stoink stack<ll>
#define quu queue<ll>
#define quee queue<pair<ll,ll>>
#define vec vector <ll>
#define vecd vector<ld>
#define vg vector<vector<ll> >
#define eg vector<pair<ll,ll>>
#define vgw vector<vector<pair<ll,ll> > >
#define pa pair<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 100000000
#define mod (ll)(1e9 + 7)
#define endl '\n'
ll n;
vg graph;
ll dp[100005][2];
ll func(ll ver,ll par,ll col) {
    if(graph[ver].size() == 1 && ver != 1)
        return 1;
    if(dp[ver][col] != -1)
        return dp[ver][col];
    ll ans = 1;
    for(auto i : graph[ver]) {
        if(i == par)
            continue;
        if(col)
            ans = (ans * func(i,ver,0)) % mod;
        else
            ans = (ans * (func(i,ver,0) + func(i,ver,1)) % mod) % mod;
    }
    return dp[ver][col] = ans;
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    cin >> n;
    graph.resize(n + 1);
    memset(dp,-1,sizeof(dp));
    fr(i,1,n) {
        ll u,v;
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    if(n == 1) {
        cout << "2";
        return 0;
    }
    cout << (func(1,0,0) + func(1,0,1)) % mod;
    return 0;
}	

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

using namespace std;

const int MAX = 300000 + 5;
int ID[MAX], Ls[MAX], Rs[MAX], ans[MAX], store[MAX];

void update(int i, int x) {
    for (; i < MAX; i += i & -i) store[i] += x;
}

int Sum(int i) {
    int ret = 0;
    for (; i; i -= i & -i) ret += store[i];
    return ret;
}

bool cmp(int i1, int i2){
    if (Ls[i1] == Ls[i2]) return i1 < i2;
    return Ls[i1] > Ls[i2];
}

int main(){
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 0; i < m + q; i++){
        ID[i] = i;
        scanf("%d%d", &Ls[i], &Rs[i]);
    }
    sort(ID, ID + m + q, cmp);
    for (int i = 0; i < m + q; i++){
        if (ID[i] >= m){
            ans[ID[i] - m] = Sum(Rs[ID[i]]);
        }
        else {
            update(Rs[ID[i]], 1);
        }
    }
    for (int i = 0; i < q; ++i)
        printf("%d\n", ans[i]);
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b = a;
  sort(RALL(b));
  rep(i, n) {
    if(a[i] != b[0]) cout << b[0] << endl;
    else cout << b[1] << endl;
  }
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

void fastscan(int &number) 
{ 
    //variable to indicate sign of input number 
    bool negative = false; 
    register int c; 
  
    number = 0; 
  
    // extract current character from buffer 
    c = getchar(); 
    if (c=='-') 
    { 
        // number is negative 
        negative = true; 
  
        // extract the next character from the buffer 
        c = getchar(); 
    } 
  
    // Keep on extracting characters if they are integers 
    // i.e ASCII Value lies from '0'(48) to '9' (57) 
    for (; (c>47 && c<58); c=getchar()) 
        number = number *10 + c - 48; 
  
    // if scanned input has a negative sign, negate the 
    // value of the input number 
    if (negative) 
        number *= -1; 
} 
 
inline int divide(int x, int y){
    if (x % y == 0) return x / y;
    else return x / y + 1;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, H; fastscan(N); fastscan(H);
  	int a = 0;
	int b[N] = {};
    for (int i = 0; i < N; ++i) {
      	int ta, tb; fastscan(ta); fastscan(tb);
    	a = max(a, ta); b[i] = tb;
    }
 
    sort(b, b + N);
    auto it = lower_bound(b, b + N, a);
 
    int temp = 0; int cnt = 0;
 
    for (int i = N - 1; i >= (int) (it - b); --i){
        temp += b[i]; ++cnt;
        if (temp >= H){
            print(cnt); return 0;
        }
    }
    print(cnt + divide((H - temp), a));
    
    return 0;
}


Measured memory_bytes: 640
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

vector<P> prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({ a, ex });
    }
    if (N != 1) res.push_back({ N, 1 });
    return res;
}

int main() {
    ll n;
    cin >> n;
    vector<P>p = prime_factorize(n);
    ll count = 0;
    for (auto id : p) {
        ll index = 2;
        while (id.second > 0) {
            id.second-= index;
            count++;
            index++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3616
n,m = map(int,input().split())

from collections import defaultdict
dic = defaultdict(int)
wa = defaultdict(int)
ans1 = 0
ans2 = 0
for _ in range(m):
    p,s = map(str,input().split())
    p = int(p)
    if s == "AC":
        if dic[p] == 0:
            ans2 += wa[p]
            ans1 += 1
            dic[p] = 1

    else:
        if dic[p] == 0:
            wa[p] += 1
   
print(ans1)
print(ans2)


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

class Program
{
	static void Main(string[] args)
	{
		string[] nm = Console.ReadLine().Split();

		int n = int.Parse(nm[0]);
		int m = int.Parse(nm[1]);

		int[] cs = Console.ReadLine().Split().Select(str => int.Parse(str)).ToArray();

		int[] minCounts = new int[50001];

		// コイン1枚で実現できる金額には枚数1を入れておく
		for (int ci = 0; ci < m; ci++)
		{
			minCounts[cs[ci]] = 1;
		}

		// 1から順番に辿る
		for (int i = 1; i <= n; i++)
		{
			if (minCounts[i] > 0) continue;
			minCounts[i] = GetMinCounts(i, minCounts);
		}
		System.Console.WriteLine(minCounts[n]);
	}

	// Kを実現する最小コイン枚数を返す
	static int GetMinCounts(int k, int[] minCounts)
	{
		// 頭と後ろからの組み合わせで最小値を計算
		int min = minCounts[k - 1] + minCounts[1];
		for (int j = 2; j < k / 2 + 1; j++)
		{
			int current = minCounts[k - j] + minCounts[j];
			if (current < min) min = current;
		}
		return min;
	}
}



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

int main() {
  int N,l,r,res;
  cin >> N;

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



cout << res << endl;
}

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

int main()
{
    int n, ans = 0;
    int l, r;
    cin >> n;

    vector<int> h(n), tmp(n, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> h.at(i);
    }

    while (h != tmp)
    {
        l = -1;
        r = -1;
        for (int i = 0; i < n; i++)
        {
            if (tmp.at(i) < h.at(i)) {
                if (l < 0)
                    l = i;

                if ((i != n - 1) and (tmp.at(i + 1) >= h.at(i + 1))) {
                    if (r < 0)
                        r = i;
                }
                if ((r < 0) and (i == n - 1))
                    r = i;
            }
        }
        for (int i = l; i <= r; i++)
            tmp.at(i)++;
        
        ans++;
    }
    cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<long int> a(n), b(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i) >> b.at(i);
  }
  long int count = 0;
  for(int i = n - 1; i >= 0; i--){
    if((a.at(i) + count) % b.at(i) == 0) continue;
    count += b.at(i) - ((a.at(i) + count) % b.at(i));
  }
  cout << count;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

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

    int a,b;
    // 引数の受け取り
    cin >> b >> a ;
    string c[b];

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

    sort(c,c+b);
    string d;
    for(int i=0; i<b;i++){
        d = d + c[i];
    }
    

    cout << d  << endl;

    // 出力
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}

int main(){
    ll n;cin>>n;
    vector<ll> vec(n);
    vector<ll> dp(n+1);
    vector<ll> pd(n+1);
    dp.at(0)=0;
    pd.at(0)=0;
    For(i,n){
        cin>>vec.at(i);
    }
    For(i,n){
        dp.at(i+1)=max(dp.at(i),vec.at(i));
        pd.at(i+1)=max(pd.at(i),vec.at(n-1-i));
    }
    For(i,n){
        cout<<max(dp.at(i),pd.at(n-1-i))<<endl;
    }
}


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

int main() {
  int N, ans = 0, i;
  cin >> N;
  
  vector<int> v(N);
  vector<int> c(N);
  for(i = 0; i < N; i++){
    cin >> v.at(i);
  }
  for(i = 0; i < N; i++){
    cin >> c.at(i);
  }
  
  for(i = 0; i < N; i++){
    if(v.at(i) > c.at(i)){
      ans += v.at(i) - c.at(i);
    }
  }
  
  cout << ans << endl;
}


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

int main(){
	while(1){
		int n, ans=0;
		scanf(" %d", &n);
		if(n==0) break;
		
		for(long i=1; i<=n; ++i){
			int t=i;
			while(t%5==0){
				t/=5;
				++ans;
			}
		}
		
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1188
X = int(input())

for a in range(10 ** 3):
  for b in range(10 ** 3):
    for ap in (1,-1):
      for bp in (1,-1):
        if (a * ap) ** 5 - (b * bp) ** 5 == X:
          print(a * ap,b * bp)
          exit(0)

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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> n;
    vector<int> p(n);
    long long ans = 0;
    for(i = 0;i < n;i++){
        cin >> p[i];
        if(p[i] != i+1) ans++;
    }
    if(ans <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())
E = [[] for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  E[a - 1].append([b - 1, -c])
D = [N * 10 ** 9 + 1] * N
D[0] = 0
def bf(D):
  for i in range(N):
    _D = [d for d in D]
    for s in range(N):
      for adj in E[s]:
        _D[adj[0]] = min(D[s] + adj[1], _D[adj[0]])
    D = _D
  return D
D = bf(D)
d1 = D[-1]
D = bf(D)
print(-d1 if d1 == D[-1] else 'inf')

Measured memory_bytes: 3568