akhauriyash/Code-Regression huggingface dataset:
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            price = 500*i + 100*j + 50*k
            if price == x:
                cnt += 1
print(cnt)

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

int main() {
  string S, T;
  cin >> S >> T;
  
  int ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == T.at(i)) {
      ans++;
    }
  }
  
  if (ans == S.size()) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
n=int(input())
a=list(map(int,input().split()))
r=[[] for _ in range(n)]
l=[[] for _ in range(n)]
for i in range(n):
	if i+a[i]<n:
		r[i+a[i]].append(i)
	if i-a[i]>=0:
		l[i-a[i]].append(i)
cnt=0
for i in range(n):
	cnt+=len(l[i])*len(r[i])
print(cnt)

Measured memory_bytes: 56820
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int N = 2e6 + 6;
int A[N];
int n;



void solve()
{
	long double n;
	cin >> n;
	long double a = 100;
	loop(i,1,10000)
	{
		a = a*(1.01);
		int xa = a;
		a = (xa*(1.0));
		if(a >= n)
		{
			cout << i;
			return;
		}
	}
}
 
int32_t main()
{
 
cout<<fixed<<setprecision(2);

ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	

 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>

using namespace std;

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

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

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M; cin >> N >> M;

  ll ans = 0;
  if (N == 1 && M == 1) {
    ans = 1;
  } else if (N == 1 || M == 1) {
    ans = N * M - 2;
  } else {
    ans = (N - 2) * (M - 2);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> adj(n, vector<int>(n, inf));
    for(int i=0; i<n; i++){
        adj[i][i] = 0;
    }
    vector<int> a(m),b(m),c(m);
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        adj[a[i]][b[i]] = adj[b[i]][a[i]] = c[i];
    }
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                adj[i][j] = min(adj[i][j], adj[i][k] +adj[k][j]);
            }
        }
    }
    int ans = 0;
    for(int i=0; i<m; i++){
        bool ok = false;
        for(int j=0; j<n; j++){
            for(int k=0; k<n; k++){
                if(adj[j][k] == adj[j][a[i]] +c[i] +adj[b[i]][k]){
                    ok = true;
                }
            }
        }
        if(!ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    if(s[0]=='2')
        cnt++;
        if(s[1]=='2')
            cnt++;
            if(s[2]=='2')
                cnt++;
                if(s[3]=='2')
                    cnt++;
                cout << cnt << endl;
                return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int n;
    cin >> n;
    map<int, int> a;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }

    int cnt = 0;
    for (pair<int, int> p: a) {
        // cout << p.first << " " << p.second << endl;
        if (p.first < p.second) cnt += p.second - p.first;
        else if (p.first > p.second) cnt += p.second;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 4736
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        int N = input.nextInt();

        List<Integer> h = new ArrayList();

        for (int i = 0; i<N;i++){
            h.add(input.nextInt());
        }
        long answer = 0;
        for (int i = 0; i < N-1;i++){
            for (int j = i + 1; j < N; j++){
                answer += h.get(i) * h.get(j);
            }
        }

        System.out.println(answer);

    }
}

Measured memory_bytes: 23636
#include<stdio.h>
#define N 10000

int main(){
	int num,i,sosu,j,sum=0,f;

	scanf("%d",&num);

	for(i=0;i<num;i++){
		f=0;
		scanf("%d",&sosu);
		//1
		if(sosu==1){
			f=1;
		}

		else if(sosu!=2){
		//偶数
			if(sosu%2==0){
				f=1;
			}
			else{
				j=2;
				 while (j*j<= sosu) {
		        	if (sosu%j== 0) {
		            	f=1;
		            	break;
		        	}
		        	j++;
				}
			}
		}
			//素数
		if(f==0)
			sum++;

	}

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



Measured memory_bytes: 1968
/*
ABC119-D
問題
A社の神社とB軒の寺がある。
西からi社目の神社はsiメートル、i軒目の寺はtiメートルの地点
があります。
以下Q個の問いに答える。
問i:道路のxiメートルの地点から出発して自由に移動したとき、
神社1社と寺1軒に訪れるのに必要な最小の移動距離は何メートルか。
制約
1<=A,B<=10^5
1<=Q<=10^5
1<=si,ti,xi<=10^10
方針
単純にxiに一番近い神社と寺に行くのが最短距離なのはわかる。
ただし、パターンとしては以下があるので、全パターン試す。
・最初に前方最寄りの神社に行き、前方最寄りの寺にいく
・最初に前方最寄りの神社に行き、後方最寄りの寺にいく
・最初に後方最寄りの神社に行き、前方最寄りの寺にいく
・最初に後方最寄りの神社に行き、後方最寄りの寺にいく
・最初に前方最寄りの寺に行き、前方最寄りの神社にいく
・最初に前方最寄りの寺に行き、後方最寄りの神社にいく
・最初に後方最寄りの寺に行き、前方最寄りの神社にいく
・最初に後方最寄りの寺に行き、後方最寄りの神社にいく
最寄りを調べるためには以下の二分探索を用いる(O(logN))
lower_bound
・探索したい値以上が現れる最初の位置のイテレータ
v ={1,2,3,4,5} x = 3だったら、index:2の位置のイテレータ
upper_bound
・探索したい値より大きい値が現れる最初の位置のイテレータ
v ={1,2,3,4,5} x = 3だったら、index:3の位置のイテレータ
・前方のindex(自分自身を含む)
upper_bound(v.begin(), v.end(), x) - v.begin() - 1
・前方のindex(自分自身を含まない)
lower_bound(v.begin(), v.end(), x) - v.begin() - 1
・後方のindex(自分自身を含む)
lower_bound(v.begin(), v.end(), x) - v.begin()
・後方のindex(自分自身を含まない)
upper_bound(v.begin(), v.end(), x) - v.begin()
*/

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int A, B, Q; cin >> A >> B >> Q;

    vector<ll> s(A), t(B), x(Q);
    rep(i,A) cin >> s[i];
    rep(i,B) cin >> t[i];
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    rep(i,Q) cin >> x[i];

    rep(i,Q){

        ll ng = -1;
        ll ok = s.size();
        
        while(abs(ok-ng)>1){
            ll mid = (ok+ng) / 2;
            auto f = [&](ll mid){
                return s[mid] > x[i]; 
            };
            if(f(mid)) ok = mid;
            else ng = mid;
        }
        int s_right = min(ok, (ll)(s.size()-1));
        
        ng = -1;
        ok = t.size();
        while(abs(ok-ng)>1){
            ll mid = (ok+ng) / 2;
            auto f = [&](ll mid){
                return t[mid] > x[i];
            };
            if(f(mid)) ok = mid;
            else ng = mid;
        }
        int t_right = min(ok, (ll)(t.size()-1));
        

        ll s_distances[2];
        s_distances[0] = s[max(0,s_right-1)];
        s_distances[1] = s[s_right];

        ll t_distances[2];
        t_distances[0] = t[max(0,t_right-1)];
        t_distances[1] = t[t_right];

        ll ans = INF;
        for (int j = 0; j < 2; j++){
            ans = min(ans, abs(x[i] - s_distances[j]) +abs(s_distances[j] - t_distances[j]));
            ans = min(ans, abs(x[i] - s_distances[j]) +abs(s_distances[j] - t_distances[(j+1)%2]));
        }
        for (int j = 0; j < 2; j++){
            ans = min(ans, abs(x[i] - t_distances[j]) +abs(t_distances[j] - s_distances[j]));
            ans = min(ans, abs(x[i] - t_distances[j]) +abs(t_distances[j] - s_distances[(j+1)%2]));
        }
        // coutを遅いので、クエリが多い場合はprintfを使用
        printf("%lld\n", ans);

    }
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A, C, D;
bool B[8];

int main(){
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		if (A >= 3200)++C;
		else B[A / 400] = true;
	}
	for (int i = 0; i < 8; ++i) {
		C += B[i];
		D += B[i];
	}
	cout << max(D, 1) << sp << C << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "
#define TIME (chrono::steady_clock::now().time_since_epoch().count())

const int MXN = 2e5+5;
int dp[MXN];
int mod = 998244353;

const int BASE = 1 << 18;
int mx[BASE*2];
void insert(int x, int val)
  {
  x += BASE;
  while(x){maxi(mx[x], val); x/=2;}
  }
int query(int a, int b)
  {
  a += BASE-1;
  b += BASE+1;
  int res = 0;
  while(a / 2 != b / 2)
    {
    if(a % 2 == 0)maxi(res, mx[a+1]);
    if(b % 2 == 1)maxi(res, mx[b-1]);
    a /= 2;
    b /= 2;
    }
  return res;
  }
int main()
  {
  int n;
  scanf("%d", &n);
  VPII pairs;
  FOR(i, 1, n)
    {
    int a, b;
    scanf("%d%d", &a, &b);
    pairs.PB(MP(a, b));
    }
  sort(ALL(pairs));
  pairs.PB(MP(2e9, 2e9));
  dp[n] = 1;

  FORD(i, n-1, 0)
    {
    insert(i, i);
    dp[i] = dp[i+1];
    auto pos2 = upper_bound(ALL(pairs), MP(pairs[i].f + pairs[i].s, -1)) - pairs.begin() - 1;
    pos2 = query(i, pos2);
    insert(i, pos2);
    dp[i] += dp[pos2+1];
    debug(i, pos2);
    dp[i] %= mod;
    }
  printf("%d\n", dp[0]);
  }

Measured memory_bytes: 4336
from collections import OrderedDict, deque


def main():
    n = int(input())
    edges = [tuple(map(int, input().split())) for _ in range(n - 1)]
    tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる.
    coloring = OrderedDict()
    for e in edges:
        a, b = e[0] - 1, e[1] - 1
        tree[a].append(b)
        tree[b].append(a)
        coloring[(a, b)] = 0

    q = deque()
    seen = [False] * n
    q.append(0)
    col_count_by_v = [set() for _ in range(n)]
    while len(q):
        new_v = q.popleft()
        seen[new_v] = True
        color_i = 1  # One-based index.
        for adj in tree[new_v]:
            if seen[adj]:
                continue
            q.append(adj)
            while color_i in col_count_by_v[new_v]:
                color_i += 1
            coloring[(new_v, adj)] = color_i
            col_count_by_v[new_v].add(color_i)
            col_count_by_v[adj].add(color_i)
            color_i += 1

    print(len(set(coloring.values())))
    for c in coloring.values():
        print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 95072
class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end

de = false
n, m = gets.chomp.split().map(&:to_i)
q = gets.chomp.split().map(&:to_i)

uf = UnionFind.new(n+1)

m.times do
  x, y = gets.chomp.split().map(&:to_i)
  uf.unite(x,y)
end

ans = 0
1.upto(n) do |i|
  if q[i-1] == i
    p ['same',i] if de
    ans += 1
  elsif uf.same_parent?(q[i-1], i)
    p ['uf', i] if de
    ans += 1
  end
end

puts ans


Measured memory_bytes: 12812
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int main(){
  char x,y;
  cin >> x >> y;
  if(x-'A'<y-'A') cout << "<" << endl;
  else if(x==y) cout << "=" << endl;
  else cout << ">" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
long int GCD(long int a,long int b){
	if(a < b){
		long int bf = a;
		a = b;
		b = bf;
	}
	while(b != 0){
		long int mod = a % b;
		a = b;
		b = mod;
		//printf("mod = %ld\n",mod);
	}
	return a;
}

int main(){
	long int a,b;
	while(scanf("%ld %ld",&a,&b) != EOF){
		long int gcd = GCD(a,b);
		long int lcm = (a/ gcd) * b;
		printf("%ld %ld\n",gcd,lcm);
	}
	return 0;
}

Measured memory_bytes: 2708
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        long ans = 0;
        for (int i = 1; i <= N - 1; i++) {
            ans += i;
        }
        System.out.print(ans);
    }

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

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

int main()
{
  int n;
  cin >> n;
  long double denominator = 0;
  int i;
  while(cin >> i)
    denominator += (long double)1 / i;
  cout << fixed << setprecision(10) << 1 / denominator << endl;
  return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
//#include <cmath>
#include <math.h>

using namespace std;


void Main43_c(void) {
	int n;
	int i, j, temp;
	int mi, ma;
	double x = 0;
	vector <int> a;
	int cost;


	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> temp;
		a.push_back(temp);
	}

	sort(a.begin(), a.end());

	mi = a[0];
	ma = a[n - 1];

	for (i = mi; i <= ma; i++) {

		//コストの計算
		for (j = 0; j < n; j++) {
			x = x + pow(double(a[j] - i), 2.0);
		}



		if (i == mi) {
			cost = int(x);
		}
		else {
			if(cost > int(x)){
				cost = int(x);
			}
		}
		x = 0;
	}

	cout << cost << endl;

	return;

}




int main(void) {
	Main43_c();
	return 0;
}

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

long long data[200005],pref[200005];
map<long long,long long> ada;

int main(){
	long long n;
	long long sum=0;
	long long ban=0;
	scanf("%lld",&n);
	for(long long i=0;i<n;i++){
		scanf("%lld",&data[i]);
		sum+=data[i];
		pref[i+1]=sum;
		if(sum==0)ban++;
		if(ada[sum]==0){
			ada[sum]++;
		}
		else{
			ban+=ada[sum];
			ada[sum]++;
		}
	}
	printf("%lld",ban);
	return 0;
}

Measured memory_bytes: 15872
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>

int main()
{
	int h, w;
	while (1) {
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0) break;
		if (h < 3 || h>300 || w < 3 || w>300) break;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				if (i == 1 || i == h || j == 1 || j == w) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2036
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int[][] map=new int[14][14];	//2~11*2~11
		String str;
		String[] input;
		int x,y,size,max=0,cnt=0;
		try{
			while((str=br.readLine())!=null&&!str.isEmpty()){
				input=str.split(",");
				x=Integer.parseInt(input[0])+2;
				y=Integer.parseInt(input[1])+2;
				size=Integer.parseInt(input[2]);
				map[x-1][y]++;
				map[x][y-1]++;
				map[x][y]++;
				map[x][y+1]++;
				map[x+1][y]++;
				if(size>=2){
					map[x-1][y-1]++;
					map[x-1][y+1]++;
					map[x+1][y-1]++;
					map[x+1][y+1]++;
					if(size==3){
						map[x-2][y]++;
						map[x][y-2]++;
						map[x][y+2]++;
						map[x+2][y]++;
					}
				}
			}
			for(int i=2;i<=11;i++){	//2~11
				for(int j=2;j<=11;j++){	//2~11
					if(map[i][j]==0) cnt++;
					else if(map[i][j]>max) max=map[i][j];
				}
			}
			System.out.println(cnt+"\n"+max);
		}catch(Exception e){
		}
	}
}

Measured memory_bytes: 17076
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

#define ll long long

int main()
{
    ll N, A, B;
    std::cin >> N >> A >> B;

    ll sum = A + B;
    ll sho = N / sum;
    ll ans = sho * A;
    ll amari = N % sum;

    if(amari > A) {
        ans += A;
    }
    else {
        ans += amari;
    }

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

Measured memory_bytes: 3648
/**************************************************************************************************
 * 方針
 * - 貪欲的にシミュレートして探索していったら計算量を考えるとまるで足りない(O(10^9 * 10^5))
 * - そこで，計算量的にO(N)またはO(NlogN)だなと見当をつけておく(がこれは少し罠)
 * - 次に，T回攻撃した時は，全体にT回攻撃して，何体かに合計でT回攻撃するのと同じだと気づく
 * - 今求めたいのはT回の最小→Tって最高10^9回→長さ10^9の配列に二分探索！(これ天才解法すぎでは？)
 * - 次にTの時の二分探索上での判定基準を考えなければならない
 *   1. N体全てにBダメージ与えた後，生き残ってる奴らに対し，あと何回(A-B)ダメージ与えなければならないか考える
 *   2. つまりN体全てに対して(残りHP/(A-B)ダメージ)回を数え上げる(切り捨てだと体力残っちゃうので切り上げ)
 *   3. その回数がT以下であれば攻撃をT回すれば確実に全員を仕留められると判断できる！
 * - これらをTについてめぐる式二分探索で実装したらおしまい！(オーバーフローに注意)
 *  - けんちょんさんのにぶたん記事に書いてあるlower_boundとupper_boundで個数求められるやつも覚えとこうな 
 **************************************************************************************************/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int n, a, b;
vector<ll> h;
/**
 * 条件(上記参照)を満たすか
 * @param t: int 何回爆発させたか
 * @return cnt <= t: bool 敵キャラの全ての残りHPを減らすために必要な回数は
 *                        爆発させた回数よりも小さいかどうか判定
 */
bool isOk(ll t)
{
  ll cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    ll tmp = h[i] - b * t;
    if (tmp > 0)
      cnt += (tmp - 1) / (a - b) + 1;
  }
  return cnt <= t;
}

int main()
{
  cin >> n >> a >> b;

  for (int i = 0; i < n; ++i)
  {
    ll t;
    cin >> t;
    h.push_back(t);
  }

  ll ng = 0, ok = 1e9 + 10;
  // OKとNG区間幅が1以上の間→条件を抜けたらOKとNGの境界がわかる(OKの時が条件を満たす)
  while (ng + 1 < ok)
  {
    ll mid = (ok + ng) / 2;
    if (isOk(mid))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

  return 0;
}


Measured memory_bytes: 1400
cards=[[False for j in range(13)] for i in range(4)]
pattern=["S","H","C","D"]
n=int(input())
for i in range(n):
	table =input().split()
	ch=table[0]
	rank=table[1]
	cards[pattern.index(ch)][int(rank)-1] = True
	
for i in range(4):
	for j in range(13):
		if cards[i][j] == False:
			print(pattern[i],j+1)


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> A, B, C;
    rp(i, 0, x) {
        ll a;
        cin >> a;
        A.emplace_back(a);
    }
    rp(i, 0, y) {
        ll b; cin >> b;
        rp(j, 0, x) {
            B.emplace_back(A[j] + b);
        }
    }
    rp(i, 0, z) {
        ll a;
        cin >> a;
        C.emplace_back(a);
    }
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());
    priority_queue< ll, vector<ll>, greater<ll> > value;
    rp(i, 0, x*y) {
        bool flag = 1;
        int j = 0;
        while(flag) {
            if(j >= z) flag = 0;
            else if(int(value.size()) < k){
                value.push(B[i] + C[j]);
                j++;
            }
            else{
                if(value.top() >= B[i] + C[j]) flag = 0;
                else {
                    value.push(B[i] + C[j]);
                    value.pop();
                    j++;
                }
            }
        }
    }
    vector<ll> res;
    while(!value.empty()) {
        res.emplace_back(value.top()); value.pop();
    }
    for(int i = k-1; i >= 0; i--) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 11672
program V1004;
 var
  a:array[0..200001,0..1] of longint;
  i,m,n,x,y,u:longint;
 begin
  readln(n,m);
  fillchar(a,sizeof(a),0);
  a[1,0]:=1;
  a[n,1]:=1;
  for i:=1 to m do
   begin
    readln(x,y);
    if x=1 then inc(a[y,0]);
    if y=n then inc(a[x,1]);
   end;
  u:=0;
  for i:=1 to n do
   if (a[i,0]>0) and (a[i,1]>0) then u:=1;
  if u=1 then writeln('POSSIBLE')
         else writeln('IMPOSSIBLE');
 end.


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;

int main()
{
    ll n , p ;
    map<ll , ll> mp;
    cin >> n >> p;
    ll t;
    ll t1 = 2;
    while(t1 * t1 <= p){
        t = 0;
        while(p % t1 == 0){
            t += 1;
            p = p / t1;
        }
        if(t > 0){
            mp[t1] = t;
            //cout << t1 << ":" << t << endl;
        }
        t1 += 1;
    }
    if(p > 1){
        mp[p] = 1;
    }
    ll ans = 1;
    ll t2;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        t2 = itr->second / n;
        while(t2 > 0){
            ans = ans * itr->first;
            t2 -= 1;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n;
int a[N];
ll f[N];
int ans;
int mx;

int main () {
	cin >> n;
	For (i, 1, n) {
	    cin >> a[i];
	}
	
	sort(a + 1, a + n + 1);
	ll cur = 0;
	For (i, 1, n) {
	    int j = i + 1;
	    cur += a[i];
	    while (j <= n && a[j] <= cur * 2) {
	        cur += a[j];
	        j ++;
	    }
	   // cout << i << ' ' << j << '\n';
	    if (j > n) {
	        ans = i;
	        break;
	    }
	    i = j - 1;
	}
	
	cout << n - ans + 1 << '\n';
	return Accepted;
}

// Coded By OB

Measured memory_bytes: 2304
#include <stdio.h>

int main(){
  int N;
  int A[100];
  int count = 0,flag = 1,num = 0;
  int i;

  scanf("%d",&N);

  for(i=0;i<N;i++)scanf("%d",&A[i]);

  while(flag==1){
    flag=0;
    for(i=N-1;i>=1;i--){
      if(A[i]<A[i-1]){
	num=A[i];
	A[i]=A[i-1];
	A[i-1]=num;
	count++;
	flag=1;
      }
    }
  }

  for(i=0;i<N-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[i]);

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



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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}
string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}
 
string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	string s;
	cin>>n;
	cin>>s;
	if (n<3200)
	{
		cout<<"red";
	}
	else
	{
		cout<<s;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
#include<tuple>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;


/*
struct kouji
{
	int X;
	int S;
	int T;
};
*/


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

	int N, Q;
	cin >> N >> Q;
	
	vector<tuple<int, int, int>> stx(N);
	REP(i, N) {
		int a, b, c;
		cin >> a >> b >> c;
		stx[i] = make_tuple(c, a, b);
	}
	SORT(stx);
	set<pair<int, int> >d;
	REP(i, Q) {
		int x;
		cin >> x;
		d.emplace(x, i);
	}
	VI tm(Q);
	REP(i, Q)tm[i] = -1;
	REP(i, N) {
		auto first = d.lower_bound(make_pair(get<1>(stx[i]) - get<0>(stx[i]), 0));
		auto end = d.upper_bound(make_pair(get<2>(stx[i]) - get<0>(stx[i]) - 1, Q));

		for (auto it = first; it != end; it++) {
			tm[it->second] = get<0>(stx[i]);
		}

		d.erase(first, end);
	}

	REP(i, Q) {
		cout << tm[i] << endl;
	}
	return 0;
}



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

void solve(long long N, std::vector<long long> P, std::vector<long long> Q){

    vector<ll> vec;
    for(int i=1;i<=N;i++){
        vec.push_back(i);
    }
    ll s,t;
    ll j =0;
    do{
        bool isP = true;
        bool isQ = true;
        for(int i=0;i<N;i++){
            if(vec[i] != P[i]){
                isP =false;
            }
            if(vec[i] != Q[i]){
                isQ =false;
            }
           
        }
         if(isP){
                s = j;
            }
            if(isQ){
                t  = j;
            }
        j++;
    }while(next_permutation(vec.begin(),vec.end()));
    cout << abs(t-s)<<endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    std::vector<long long> Q(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
even_s, even_t = 2, N-1
even = 0
for i in range(N):
  if (i+1) % 2 == 0:
    even += A[i]
odd_s, odd_t = 3, N
odd = 0
for i in range(2, N):
  if (i+1) % 2 == 1:
    odd += A[i]
odd_s, odd_t = 3, N
X = [0]*N
X[0] = S - even * 2
X[1] = S - odd * 2
for i in range(3, N+1):
  if i % 2:
    even -= A[even_s-1] 
    even += A[(even_t+2)%N-1]
    even_s += 2
    even_t = (even_t+2)%N
    X[i-1] = S - even * 2
  else:
    odd -= A[odd_s-1]
    odd += A[(odd_t+2)%N-1]
    odd_s += 2
    odd_t = (odd_t+2)%N
    X[i-1] = S - odd * 2

X = list(map(str, X))
print(" ".join(X))

  

Measured memory_bytes: 18488
import time
from bisect import bisect_left
t = time.time()
H,W,m = map(int,input().split())
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1,10**6] for i in range(H+1)]
for i in range(m):
    a,b = map(int,input().split())
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in range(H+1):
    c[i].sort()
# print(hkouho)
# print(wkouho)
for i in hkouho:
    for j in wkouho:
        # print(c[i],i,j,bisect_left(c[i],j))
        if c[i][bisect_left(c[i],j)] != j:
            print(mh+mw)
            exit()
        if time.time()-t > 2.7:
            print(mh+mw-1)
            exit()
print(mh+mw-1)

Measured memory_bytes: 167200
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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 ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

vvll dp, G;

ll getLargestSquare(ll h, ll w) {
  ll maxWidth = 0;
  REP(i, h) {
    REP(j, w) {
      dp[i][j] = (G[i][j]+1)%2;
      maxWidth |= dp[i][j];
    }
  }

  rep(i, 1, h) {
    rep(j, 1, w) {
      if (G[i][j]) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = min(dp[i-1][j-1], min(dp[i-1][j], dp[i][j-1])) + 1;
        chmax(maxWidth, dp[i][j]);
      }
    }
  }
  return maxWidth * maxWidth;
}

int main() {
  ll h, w; cin >> h >> w;
  dp.resize(h, vll(w, 0));
  G.resize(h, vll(w));
  REP(i, h) REP(j, w) cin >> G[i][j];

  cout << getLargestSquare(h, w) << endl;
  return 0;
}



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

using namespace std;

#define ll long long 
#define IOS ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define SIZE 100005

int main()
{
	int t;
   string ch, bh;
   cin>> t;
   cin>> ch >> bh;
   for(int i = 0; i < t; i++)
   {
	   cout << ch[i] << bh[i];
   }
   cout << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int N;
  int M;
  scanf("%d", &N);
  scanf("%d", &M);
  int cnt_a = 0;
  int cnt_b = 0;

  cnt_a = (N * (N - 1)) / 2;
  cnt_b = (M * (M - 1)) / 2;
  int sum = cnt_a + cnt_b;
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const long long INF=2e9;

template <class A, class B> ostream& operator<<(ostream& os, const pair<A,B> p) {return os << "(" << p.first << "," << p.second << ")";} 

void dprint(string s) { cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w = s.find(','); cout << "[" << s.substr(0,w) << ": " << t << "] "; dprint(s.substr(w+1, (int)s.size()-w), u...);} 

#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X,X)
#else
#define dbg(X...) "KEEP CALM" 
#endif

const int N=1e5+5; // Don't forget to CHANGE this value ACC. TO Q.

int dp[105][N];

int32_t main()
{
    IOS;
    int n,W; cin>>n>>W;
    int wt[n+1], val[n+1];
    for(int i=1;i<=n;i++)
        cin>>wt[i]>>val[i];
    for(auto &x: dp)
    {
        for(auto &y: x)
            y=INF;
    }
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=100004;j++)
        {
            
                if(j-val[i]>=0)
                    dp[i][j]=min(dp[i-1][j], dp[i-1][j-val[i]]+wt[i]);
                else
                    dp[i][j]=dp[i-1][j];
            
        }
    }
    for(int i=N;i>=0;i--)
    {
        if(dp[n][i]<=W)
           {cout<<i; break;}
    }
    return 0;
}

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

int main(){
    int X,A,B;
    cin >> X >> A >> B;

    int h = A - B;

    if(h >= 0){
        cout << "delicious" << endl;

    }else{
        if((X - (-h)) >= 0)
            cout << "safe" << endl;
        else
            cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


int main()
{
	int r;
	cin >> r;
	cout << 3 * r*r << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import math

def combnations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
a = list(map(int, input().split()))
rui = [0] * (N + 1)
for i in range(N):
    rui[i + 1] = rui[i] + a[i]

d = defaultdict(int)
for key in rui:
    d[key] += 1

sortd = sorted(d.items(), key=lambda x: x[1], reverse=True)

cnt = 0
for i, j in sortd:
    if j >= 2:
        cnt += combnations(j, 2)
    else:
        break
print(cnt)

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

int main(){
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	rep(i,n){
		cout << s[i] << t[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*
                 ,,ggddY888Ybbgg,,
          ,agd8""'   .d8888888888bga,
       ,gdP""'     .d88888888888888888g,
     ,dP"        ,d888888888888888888888b,
   ,dP"         ,8888888888888888888888888b,
  ,8"          ,8888888P"""88888888888888888,
 ,8'           I888888I    )88888888888888888,
,8'            `8888888booo8888888888888888888,
d'              `88888888888888888888888888888b
8                `"8888888888888888888888888888
8                  `"88888888888888888888888888
8                      `"8888888888888888888888
Y,                        `8888888888888888888P
`8,                         `88888888888888888'
 `8,              .oo.       `888888888888888'
  `8a             8888        88888888888888'
   `Yba           `""'       ,888888888888P'
     "Yba                   ,88888888888'
       `"Yba,             ,8888888888P"'
          `"Y8baa,      ,d88888888P"'
               ``""YYba8888P888"'
*/
using namespace std;
#define int long long
#define KOD ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define sz size()
#define S second
#define m1x(a,b) a = max((a) , (b));
#define m1n(a,b) a = max((a) , (b));
#define F first
#define SORT(x) sort(x.begin(),x.end())
#define Rev(a) reverse(a.begin() , a.end());
#define pb push_back
#define pre(x) cout.precision(0);
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unordered_map<int,int> wi;
typedef unordered_set<int> si;
const int M = 1e5+2;
const int inf = 1e18;
main(){
	int a;
	cin >> a;
	cout << a/2 + a%2;
}



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

int main() {
	
	vector<int> a(5);
	rep(i, 5) cin >> a[i];
	
	int ans = 1000;
	
	for(int i=0; i<5; i++){
		int sum = 0;
		for(int j=0; j<4; j++){
			int tmp = a[(j+i)%5];
			while(tmp%10 != 0) tmp++;
			sum += tmp;
		}
		sum += a[(i+4)%5];
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

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

namespace ConsoleApp15
{
    class Class241
    {
        static int[] dy = new int[8] { 0, 1, 1, 1, 0, -1, -1, -1 };
        static int[] dx = new int[8] { 1, 1, 0, -1, -1, -1, 0, 1 };
        static void Main()
        {
            var HW = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int H = HW[0], W = HW[1];
            var map = new char[H, W];
            for(int i = 0; i < H; i++)
            {
                var r = Console.ReadLine();
                for(int j = 0; j < W; j++)
                {
                    map[i, j] = r[j];
                }
            }

            var newmap = new char[H, W];
            for(int i = 0; i < H; i++)
            {
                for(int j = 0; j < W; j++)
                {
                    int num = 0;
                    if (map[i, j] == '#')
                    {
                        newmap[i, j] = '#';
                        continue;
                    }

                    for(int k = 0; k < 8; k++)
                    {
                        int ny = i + dy[k];
                        int nx = j + dx[k];
                        if (0 <= ny && ny < H && 0 <= nx && nx < W)
                        {
                            if (map[ny, nx] == '#')
                                num++;
                        }
                    }

                    newmap[i, j] = num.ToString()[0];
                }
            }

            for(int i = 0; i < H; i++)
            {
                string ans = "";
                for (int j = 0; j < W; j++)
                    ans += newmap[i, j];
                Console.WriteLine(ans);
            }
        }
    }
}


Measured memory_bytes: 13268
import math


def prime_factors(n: int) -> list:
    tmp = n
    i = 2
    res = []
    while i*i <= n:
        cnt = 0
        while tmp%i==0:
            cnt += 1
            tmp //= i
        if cnt > 0:
            res.append((i, cnt))
        i += 1
    # add remaining factor
    if tmp > 1:
        res.append((tmp, 1))
    return res


def f(n):
    res = 1
    while res*(res+1)//2 <= n:
        res += 1
    return res-1


def main():
    N = int(input())
    ans = 0
    for _, ex in prime_factors(N):
        ans += f(ex)
    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int main() {
  cout << setprecision(12) << fixed << boolalpha;
  int N;
  cin >> N;
  vector<int> a(2 * N);
  for (int &i: a) cin >> i;
  sort(ALL(a));
  int res = 0;
  REP(i,N) res += a[i * 2];
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
k = int(input())
ans = [i for i in range(1,10)]

i = 0

for i in range(k):
    now = ans[i]
    if str(now)[-1] == '0':
        ans.append(now*10)
        ans.append(now*10+1)
    elif str(now)[-1] == '9':
        ans.append(now*10+8)
        ans.append(now*10+9)
    else:
        ans.append(now*10+now%10-1)
        ans.append(now*10+now%10)
        ans.append(now*10+now%10+1)
    if len(ans) > k:
        break

print(ans[k-1])


Measured memory_bytes: 7184
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define l first
#define r second

using namespace std;

const int maxn = 3e5 + 1;

int n;
int a[maxn], p[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    map<int, int> mp; mp[0] = 1;
    for (int i = 0; i < n; i++) {
        p[i + 1] = p[i] + a[i];
        ++mp[p[i + 1]];
    }
    int ans = 0;
    for (auto gg : mp)
        ans += gg.second * (gg.second - 1) / 2;
    cout << ans;
    return 0;
}


Measured memory_bytes: 16384
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  string S, T;
  cin >> S >> T;
  long result = 0;
  rep (i, 3) if (S[i] == T[i]) result++;
  cout << result << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// ?????¬???????????¬??????
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), c.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;


int main() {
  long long n;
  long long x, sum=0, mx=-1000000, mn=1000000;
  scanf("%lld", &n);
  while(n--) {
    scanf("%lld", &x);
    mx = max(mx, x);
    mn = min(mn, x);
    sum += x;
  }
  printf("%lld %lld %lld\n", mn, mx, sum);
}

Measured memory_bytes: 3200
w,h,n=map(int,input().split())
b=c=0
for _ in [0]*n:
    x,y,a=map(int,input().split())
    if a==1:b=max(b,x)
    if a==2:w=min(w,x)
    if a==3:c=max(c,y)
    if a==4:h=min(h,y)
print([(w-b)*(h-c),0][(w<b)|(h<c)])


Measured memory_bytes: 38256
#include<iostream>

using namespace std;

const int inf = 1<<30;


int l[10];
//int A=0, B=0, C=0;

int n, a, b, c;
int ans = inf;

void dfs(int i, int A, int B, int C,int cost) {
	if (i == n) {
		if (A == 0 || B == 0 || C == 0) {
			return;
		}
		const int tmp = cost + abs(a - A) + abs(b - B) + abs(c - C);
		if (ans > tmp) {
			ans = tmp;
		}
		return;
	}
	dfs(i + 1, A + l[i], B, C,cost+10);
	dfs(i + 1, A, B + l[i], C, cost + 10);
	dfs(i + 1, A, B, C + l[i], cost + 10);
	dfs(i + 1, A, B, C, cost);
}

int main() {
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	dfs(0, 0, 0, 0, 0);
	cout << ans-30 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vvl c(10, vl(10));  // c[i][j] : 先頭がiで末尾がjのn以下の数の個数
    exrep(x, 1, n) {
        string s = to_string(x);
        ll m = s.size();
        c[s[0] - '0'][s[m-1] - '0']++;
    }

    ll ans = 0;
    rep(i, 10) {
        rep(j, 10) {
            ans += c[i][j]*c[j][i];
        }
    }

    out(ans);
    re0;
}

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

const int maxn=100010;
int isprime[maxn],cnt,vis[maxn];

void prime()
{
    for(int i=2;i<=55555;i++)
    {
        if(!vis[i])
            isprime[cnt++]=i;
        for(int j=0;j<cnt&&i*isprime[j]<=55555;j++)
        {
            vis[i*isprime[j]]=1;
            if(i%isprime[j]==0)
                break;
        }
    }
}

int main()
{
    prime();
    int n;
    cin >> n;
    int num=0;
    for(int i=0;i<cnt&&num!=n;i++)
    {
        if(isprime[i]%5==1)
        {
            cout << isprime[i] << " ";
            num++;
        }
    }
    return 0;
}


Measured memory_bytes: 512