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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
#define int long long

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX;
const int INF = INT_MAX;

inline int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b)*(1|((a - b)>>(8*sizeof(int)-1)));}
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数

signed main()
{
	int N;
	cin >> N;
	
	VS S(N);
	rbf(s, S) {
		cin >> s;
	}

	set<string> K;
	rbf(s, S) {
		K.insert(s);
	}

	COL(K.size());

	return 0;
}

Measured memory_bytes: 25016
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
vector<int> v[10001];
int col[10001];
int b[10001];
int colt[10001];
inline bool cmp(int x,int y){return v[x].size()>v[y].size();}
int ans=0;
int tms=0;
int tim[10001];
inline bool cmpp(int x,int y){return v[x].size()>v[y].size();}
bool use[10001];
inline void dfs(int x){
	use[x]=1;
	tim[x]=tms++;
	sort(v[x].begin(),v[x].end(),cmpp);
	for(int i=0;i<v[x].size();++i) if(!use[v[x][i]]){
		dfs(v[x][i]);
	}
}
inline void dfss(int x,int par){
	for(int i=0;i<v[x].size();++i) if(v[x][i]!=par) ans+=min(colt[x],colt[v[x][i]]),dfss(v[x][i],x);
}
int main(){
	int i,j,l,r;
	cin>>n;
	for(i=1;i<n;++i){
		cin>>l>>r;
		--l,--r;
		v[l].push_back(r);
		v[r].push_back(l);
	}
	for(i=0;i<n;++i) cin>>col[i]; 
	sort(col,col+n);
	reverse(col,col+n);
	for(i=0;i<n;++i) b[i]=i;
	sort(b,b+n,cmp);
	dfs(b[0]);
	for(i=0;i<n;++i) colt[i]=col[tim[i]];
	dfss(b[0],-1);
	cout<<ans<<endl;
	for(i=0;i<n;++i) cout<<colt[i]<<' ';
	cout<<endl;
}                                                                                      

Measured memory_bytes: 1400
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, a;
  cin >> n >> a;
  int x[n];
  for (int i = 0; i < n; ++i) {
    int xi;
    cin >> xi;
    x[i] = xi-a;
  }
  u64 dp[n][50*n*2+1];
  for (int j = 0; j < 50*n*2+1; ++j) {
    dp[0][j] = 0;
  }
  dp[0][50*n] = 1;
  dp[0][50*n+x[0]] += 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 50*n*2+1; ++j) {
      if (j-x[i] > 0 && j-x[i] < 50*n*2+1) {
        dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i]];
      } else {
        dp[i][j] = dp[i][j-1];
      }
    }
  }
  cout << dp[n-1][50*n]-1 << endl;
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
	return __builtin_parity(x);
}


vint calc(vint A){
	int N=A.size();
	vint acc(N+1);
	rep(i,A.size()){
		acc[max(0ll,i-A[i])]++;
		acc[min(N,i+A[i]+1)]--;
	}
	rep(i,A.size()){
		acc[i+1]+=acc[i];
		A[i]=acc[i];
	}
	return A;
}

signed main(){
	int N,K;
	scanf("%lld%lld",&N,&K);

	vector<int>A(N);
	rep(i,N)scanf("%lld",&A[i]);

	for(int i=0;i<K;i++){
		auto B=calc(A);
		if(A==B)break;
		A=B;
	}

	rep(i,A.size()){
		if(i)cout<<" ";
		cout<<A[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 7984
#include<bits/stdc++.h>
using namespace std;
long long int n,k,i,j,l;
void do_king(){
cin>>n>>k;
cout<<n%k<<endl;
}

int main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
do_king();
}


Measured memory_bytes: 256
'use struct'

const input = require('fs').readFileSync('/dev/stdin', 'utf8')
const lines = input.split('\n')
const hw = lines.shift().split(' ')
const h = parseInt(hw[0], 10)
// const w = parseInt(hw[1], 10)
const dist = []
for (var i = 0; i < 10; i++) {
	dist.push(
		lines
			.shift()
			.split(' ')
			.map(v => parseInt(v, 10))
	)
}
// console.log(dist)
const counts = new Array(10).fill(0)
for (var i = 0; i < h; i++) {
	lines
		.shift()
		.split(' ')
		.map(v => parseInt(v, 10))
		.forEach(v => counts[v]++)
}

for (var k = 0; k < 10; ++k) {
	for (var i = 0; i < 10; ++i) {
		for (var j = 0; j < 10; ++j) {
			dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j])
		}
	}
}
// console.log(dist)

var sum = 0
for (var i = 0; i < 10; i++) {
	sum += counts[i] * dist[i][1]
}
console.log(sum)


Measured memory_bytes: 23052
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;



signed main(){
    int n;;
    cin >> n;
    vector<int> ans;
    int MAX = 0;
    rep(i, 0, n + 1){
        if(i * (i + 1) / 2 >= n){
            MAX = i;
            break;
        }
    }
    int r = MAX * (MAX + 1) / 2 - n;
    // o(MAX);
    // o(r);
    rep(i, 1, MAX + 1){
        if(i != r){
            o(i);
        }
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(int &f){
	f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
string s;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        s[i]='x';
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
// Last Change: 08/10/2019 21:05:34.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll a, b;
  cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << endl;
}



Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ');
  buildMaxHeap(arr);
  console.log(' ' + arr.join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1|0;
    right = 2 * i + 2|0;
    if (left < n && Number(arr[left]) > Number(arr[largest])) largest = left;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };
  for (let i = Math.floor(n / 2 - 1); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 88304
#include <bits/stdc++.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>

using namespace std;
int main() {
  long long int A,B,C,D,N,M,K;
  int num = 0;
  vector<long long int> p_v;
  cin >> N;
      long long int t1 = 0;

  for (int i = 0; ; i++) {
    t1 += pow(26,i);
    if (t1 > N) break;
    num++;
  }
  long long int t = 0;
  for (int i = 0; i < num; i++) {
    t+=pow(26,i);
  }
  long long int num2 = N - t;

  for (long long int i = num-1; i >= 0; i--) {
    long long int syou = num2 / pow(26, i);
    num2 = num2 % (long long int)pow(26, i);
    char cc = syou + 'a';
    printf("%c", cc);  
  }
  puts("");
  return 0;
}

Measured memory_bytes: 4056
#define _USE_MATH_DEFINES // M_PIなどの定義を使用するのに必要
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

int main()
{
  int64_t X;
  cin >> X;

  while (true) {
    static int64_t years = 0;
    static int64_t money = 100;

    if (money >= X) {
      cout << years;
      return 0;
    }
    money *= 1.01;
    years++;
  }

  return 0;
}


Measured memory_bytes: 3672
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
	for j in range(i):
		if A[j] > A[i]:
			ans += 1
A.sort()
s = str(A[0])
for i in range(1, N):
	s += " " + str(A[i])
print(s)
print(ans)


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

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

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string s, S;
    cin >> s;
    rep(i, s.size() - 1) {
        if(s[i] == 'B' && s[i + 1] == 'C') S.push_back('D'), i++;
        else S.push_back(s[i]);
    }
    reverse(S.begin(), S.end());
    ll ans = 0;
    ll count = 0;
    rep(i, S.size()) {
        if(S[i] == 'A') ans += count;
        else if(S[i] == 'D') count++;
        else count = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3924
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for i in range(1, N+1):
    s = str(i)
    top = int(s[0])
    end = int(s[-1])
    d[(top, end)] += 1
counter = 0
for i in range(1, N+1):
    s = str(i)
    top = int(s[0])
    end = int(s[-1])
    if (end, top) in d:
        counter += d[(end, top)]
print(counter)

Measured memory_bytes: 91872
#include <cstdio>

int n, m, p;
int cell[1000];

int main(){
	while(scanf("%d%d", &n, &m)){
		if(n == 0 && m == 0) break;
		p = 0;
		for(int i = 0; i < n; i++) scanf("%d", &cell[i]);
		for(int i = 0; i < m; i++){
			int eye;
			scanf("%d", &eye);
			p += eye;
			if(p >= n-1){
				printf("%d\n", i+1);
				for(int j = i+1; j < m; j++) scanf("%d", &eye);
				break;
			}
			p += cell[p];
			if(p >= n-1){
				printf("%d\n", i+1);
				for(int j = i+1; j < m; j++) scanf("%d", &eye);
				break;
			}
		}
	}
}

Measured memory_bytes: 1032
#include <iostream>
using namespace std;
int main(void){
    int a,b,k;
    cin >> k >> a >> b;
    if(k==1 ||a%k==0 ||b%k==0){
        cout << "OK";
    }
    else if(a/k==b/k){
        cout << "NG";
    }
    else if(a/k!=b/k){
        cout << "OK";
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h> 
using namespace std; 
int main(){
string s;
string t;
int count=0;
cin>>s;
cin>>t;
for(int i=0;i<s.size();i++){
    if(s[i]==t[i]){
        count++;
    }
}
cout<<count<<endl;

    

    return 0;
}


Measured memory_bytes: 256
from typing import List, Tuple

def topological_sort(n: int, m: int, G: List[List[int]]) -> List[int]:
	for u in range(n):
		if color[u] == "WHITE":
			dfs(u)
	return L[::-1]

def dfs(u: int) -> None:
	if color[u] == "GRAY":
		print("Graph is not DAG")
		exit()
	if color[u] == "BLACK":
		return
	color[u] = "GRAY"
	for v in G[u]:
		dfs(v)
	color[u] = "BLACK"
	L.append(u)


if __name__ == "__main__":
	n, m = map(int, input().split())
	G = [[] for _ in range(n)]
	color: List[str] = ["WHITE" for _ in range(n)]
	L: List[int] = []
	for _ in range(m):
		s, t = map(int, input().split())
		G[s].append(t)
	L = topological_sort(n, m, G)
	for v in L:
		print(v)


Measured memory_bytes: 10488
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main() {
	int X, num, point, check = 1;
	cin >> X;

	for (int i = 1; i <= X; i++) {
		for (int j = 2; j <= X; j++) {
			num = pow(i, j);
			if (num > X) {
				break;
			}
			else if (check <= num) {
				check = num;
			}
		}
	}

	cout << check << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

bool is_prime(long long n)
{
    if (n == 1) {
        return false;
    }

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main()
{
    long long h, n;
    std::cin >> h >> n;
    std::vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    if (h <= std::accumulate(a.begin(), a.end(), 0)) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	string s;
	std::cin >> s;
	for (size_t i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			std::cout << "T";
		}
		if (s[i] == 'T') {
			std::cout << "A";
		}
		if (s[i] == 'C') {
			std::cout << "G";
		}
		if (s[i] == 'G') {
			std::cout << "C";
		}
	}
	std::cout << '\n';
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  multiset<int> s;
  for(int i=N-1; i>=0; i--){
    auto it = s.upper_bound(v[i]);
    if(it != s.end()){
      s.erase(it);
    }
    s.insert(v[i]);
  }

  cout << s.size() << endl;
  
  return 0;
}


Measured memory_bytes: 5368
def examA():
    N = LI()
    N.sort()
    if N[0]==N[1] and N[0]!=N[2]:
        print("Yes")
    elif N[1]==N[2] and N[0]!=N[2]:
        print("Yes")
    else:
        print("No")
    return

def examB():
    N = I()
    A = LI()
    for a in A:
        if a%2==0:
            if a%3!=0 and a%5!=0:
                print("DENIED")
                return
    print("APPROVED")
    return

def examC():
    N = I()
    S = [SI()for _ in range(N)]
    d = defaultdict(int)
    for s in S:
        d[s] += 1
    t = max(d.values())
    ans = []
    for s in S:
        if d[s]==t:
            ans.append(s)
            d[s] = 0
    ans.sort()
    for v in ans:
        print(v)
    return

def examD():
    N, K = LI()
    A = LI()


    ans = 0
    print(ans)
    return

def examE():
    S = SI()
    N = len(S)
    flag = False
    ans = 0
    for i in range(N-1,-1,-1):
        #print(ans)
        cur = int(S[i])
        if flag:
            cur += 1
        if cur>=6:
            ans += 10-cur
            flag = True
        else:
            ans += cur
            flag = False
    if flag:
        ans += 1
    print(ans)
    return

def examE2():
    S = SI()
    N = len(S)
    dp = [[0]*2 for _ in range(N+2)]
    dp[0][1] = inf
    S = S[::-1]
    S += "0"
    for i in range(N+1):
        s = int(S[i])
        dp[i+1][0] = dp[i][0] + s
        dp[i+1][1] = dp[i][0] + (10-s)
        if s<9:
            dp[i+1][0] = min(dp[i+1][0],dp[i][1] + (s+1))
        dp[i+1][1] = min(dp[i+1][1],dp[i][1] + (10-s-1))
    #print(dp)
    ans = min(dp[-1][0],dp[-1][1])
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examE2()

"""
4396817
"""

Measured memory_bytes: 151224
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main()
{
	char str[10];

	cin >> str;

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



	return 0;
}


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

long long int f(long long int n, long long int x){
    return n==-1? 0:n/x+1;
}
int main(void){
    // Your code here!
     long long int a, b, x;
    
    cin>>a>>b>>x;
    
    unsigned long long int cnt=0;
    
    cnt=f(b, x)- f(a-1, x);
    
    cout<<cnt<<endl;
    
}


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<int,ii> iii;
typedef vector<iii> viii;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

const int MOD = 1e9 + 7;
const ll INF = ll(1e18);
const ld eps = ld(1e-8);

string s[101];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, l;
	cin>>n>>l;
	for(int i = 0; i < n; i++)
	{
	cin>>s[i];
	}
	sort(s, s+n);
	for(int i = 0; i < n; i++)
	{
	cout<<s[i];
	}
	cout<<'\n'; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  //freopen("input.txt", "r", stdin);
  int len;
  string s;
  cin >> len >> s;
  int co = 0;
  for(int i = 0; i < s.size() - 2; ){
    if(s[i] == 'A'){
      if(s[i + 1] == 'B' && s[i + 2] == 'C'){
        co++;
        i += 3;
      }
      else i++;
    }
    else i++;
  }
  printf("%d\n", co);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(auto& ai:a)cin>>ai;
  map<int,int>cnt;
  for(auto ai:a)cnt[ai]++;
  int ans=0,t=0;
  for(auto val:cnt){
    if(val.second>=4){
      ans=max({ans,val.first*val.first,val.first*t});
    }
    if(val.second>=2){
      ans=max(ans,t*val.first);
      t=max(t,val.first);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N;
vector<ll> A;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
}

void chmax(ll &a, ll b){if(a<b) a=b;}

int solve(){
    ll x = 1000;
    ll cnt = 0;
    A.push_back(0LL);
    for (int i = 0; i < N; i++)
    {
        if(A[i]<A[i+1] && cnt==0){
            cnt = x/A[i];
            x -= cnt*A[i];
        }
        else if(A[i]>A[i+1]){
            x += cnt*A[i];
            cnt = 0;
        }
    }
    cout << x << endl;    
    return 0;
}   

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

Measured memory_bytes: 3640
import sys
input = sys.stdin.buffer.readline
import copy

def main():
    N = int(input())
    x = list(map(int,input().split()))
    MOD = 10**9+7
    fac = [0 for _ in range(N+1)]
    fac[0],fac[1] = 1,1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD
        invfac[i] = (invfac[i-1]*inv[i])%MOD

    cum = [0]
    for i in range(N):
        cum.append(cum[-1]+inv[i+1])

    ans = 0
    for i in range(N-1):
        d = x[i+1]-x[i]
        ans += (d*cum[i+1])%MOD
        
    print((ans*fac[N-1])%MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 24460
#include<cstdio>
#include<cmath>
#include<numeric>
#include<iostream>
using namespace std;

int main(){
  long long A, B, C, D;

  cin >> A >> B >> C >> D;

  long long C_a;
  if (A % C == 0) C_a = A / C - 1;
  else C_a = A / C;
  long long Cn = B / C - C_a;

  long long D_a;
  if (A % D == 0) D_a = A / D - 1;
  else D_a = A / D;
  long long Dn = B / D - D_a;

  long long r, x, tmp;
  x = C * D;
  if (C < D){
    tmp = C;
    C = D;
    D = tmp;
  }

  r = C % D;
  while(r != 0){
    C = D;
    D = r;
    r = C % D;
  }
  long long CD = x / D;


  long long CD_a;
  if (A % (CD) == 0) CD_a = A / (CD) - 1;
  else CD_a = A / (CD);
  long long CDn = B / (CD) - CD_a;

  long long ans = (Cn + Dn) - CDn;
  long long realans = (B - A + 1) - ans;
  cout << realans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <bitset>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOREACH(i, v) for(auto i = v.begin(); i != v.end(); i++)
#define PRINT(n) cout << n << endl

using namespace std;
using ll = long long;

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

void solve(){
    int n;
    cin >> n;
    int a[n];
    REP(i, n) cin >> a[i];

    sort(a, a+n);

    int x = 0, y = 0;
    for(int i = 0; i < n; i++){
        if(i%2 != 0){
            x += a[i];
        }else{
            y += a[i];
        }
    }
    if(n%2 == 0){
        cout << x-y << endl;
    }else{
        cout << y-x << endl;
    }
}

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


Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i).sort!

nums = as.each_with_object(Hash.new(0)) { |a, h| h[a] += 1 }
divisible = Array.new(as.last + 1, 1)
res = 0

as.each do |a|
  next if divisible[a] == 0
  res += 1 if nums[a] == 1

  1.upto(as.last / a) do |i|
    divisible[a * i] = 0
  end
end

puts res


Measured memory_bytes: 43340
n = int(input())
a = int(n**0.5+1)
ans = [0]*n
for x in range(1, a):
    for y in range(1, a):
        for z in range(1, a):
            if x**2 + y**2 + z**2 + x*y + y*z + z*x <= n:
                ans[x**2 + y**2 + z**2 + x*y + y*z + z*x -1] += 1
[print(i) for i in ans]

Measured memory_bytes: 74896
#4
N,W=map(int,input().split())
A=[[0]]+[[int(x) for x in input().split()] for i in range(N)]

dp=[[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,N+1):
    for sum_w in range(W+1):
        w=A[i][0]
        v=A[i][1]
        if sum_w-w>=0:
            dp[i][sum_w]=max(dp[i][sum_w],dp[i-1][sum_w-w]+v)
        dp[i][sum_w]=max(dp[i][sum_w],dp[i-1][sum_w])
        
print(dp[-1][-1])

Measured memory_bytes: 171784
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int sum[400020];
vector<int> v;
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    string S; cin >> S;
    if(S[0] == '0') v.push_back(0);
    int len = 0;
    rep(i, S.length()) {
        if(len == 0 || S[i - 1] == S[i]) len++;
        else if(i + 1 == S.length() || S[i - 1] != S[i]) {
            v.push_back(len);
            len = 1;
        }
    }
    v.push_back(len);
    rep(i, v.size()) sum[i + 1] += sum[i] + v[i];
    rep(i, 400000) sum[i + 1] = max(sum[i + 1], sum[i]);
    int ans = 0;
    rep(i, 50010) {
        ans = max(ans, sum[i * 2 + 1 + K * 2] - sum[i * 2]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5612
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import  java.io.*;
import  java.math.*;
import java.nio.Buffer;
import java.sql.SQLSyntaxErrorException;
import  java.util.*;
import  java.text.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


public class Main {
    public static int gcd(int a,int b){
        return b==0?a:gcd(b,a%b);
    }
    static class kNight implements Comparable<kNight>{
        int p;
        int c;
        kNight(int p,int c){
            this.p=p;
            this.c=c;
        }
        @Override
        public int compareTo(kNight k) {
            if(p==k.p){
                return c-k.c;
            }
            else{
                return p-k.p;
            }
        }


    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String[] args) {
        FastReader cin=new FastReader();
        int n=cin.nextInt();
        int sum=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                for(int k=1;k<=n;k++){
                    int c=gcd(gcd(i,j),k);
                    sum+=c;
                }
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 32728
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

struct edge {ll to, jpy, snu;};

int main(){
    ll N, x; cin >> N >> x;
    vl A(N); REP(i, N) cin >> A[i];
    
    ll ans = LINF;
    vl best(N); REP(i, N) best[i] = A[i];
    REP(i, N){
        ll cur = 0;
        REP(j, N){
            best[j] = min(best[j], A[(j-i+N)%N]);
            cur += best[j];
        }
        ans = min(ans, cur + i*x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

void enqueue(int, int);
int dequeue(void);

int Q[50000][2];
int firstQ, lastQ;

char name[50000][11];

main(){

  int i, index;
  char inName[11];
  int inTime;
  int elapsedTime = 0;
  int n,q;

  firstQ = 0;
  lastQ = 0;

  scanf("%d %d",&n,&q);

  for(index=0; index<n; index++){
    scanf("%s %d",inName,&inTime);
    strcpy(name[index],inName);
    enqueue(index,inTime);
  }

  while(n!=0){

    Q[firstQ][1] -= q;
    elapsedTime += q;

    if(Q[firstQ][1] <= 0){

      elapsedTime += Q[firstQ][1];
      printf("%s %d\n",name[Q[firstQ][0]],elapsedTime);
      n--;

    }else{

      enqueue(Q[firstQ][0],Q[firstQ][1]);

    }

    dequeue();

  }

  return 0;

}

void enqueue(int index, int inTime){

  Q[lastQ][0] = index;
  Q[lastQ][1] = inTime;

  lastQ++;

}

int dequeue(void){

  return Q[firstQ++][1];

}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{a:[i64;3]};
    if a.iter().filter(|&x| *x%2!=0).count() > 0 {
        println!("0");
        return ();
    }
    if a[0] == a[1] && a[1] == a[2] {
        println!("-1");
        return ();
    }

    let mut a = a;
    let mut cnt:i64 = 0;
    loop {
        if a.iter().filter(|&x| *x%2!=0).count() > 0 {
            break;
        }
        cnt += 1;
        let b = a.clone();
        a[0] = b[1]/2 + b[2]/2;
        a[1] = b[0]/2 + b[2]/2;
        a[2] = b[0]/2 + b[1]/2;
    }

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


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner s = new Scanner(System.in);
			int numN = s.nextInt();
			int[] nums = new int[numN];

			for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			}
			s.close();
			int count = 0;
			for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			}
			if(count == 2 ||count ==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}

	}

}


Measured memory_bytes: 21844
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long n;
    cin >> n;

    vector<pair<long long,int>> factors;
    long long x = n;
    for (int i = 2; i * 1LL * i <= x; ++i) {
        if (x % i == 0) {
            int cnt = 0;
            while (x % i == 0) {
                x /= i;
                ++cnt;
            }
            factors.emplace_back(i, cnt);
        }
    }
    if (x > 1) {
        factors.emplace_back(x, 1);
    }

    int res = 0;
    for (auto& p : factors) {
        // cout << p.first << " " << p.second << endl;
        int m = p.second;
        int cnt = 1;
        while (m >= cnt) {
            m -= cnt;
            ++cnt;
        }
        res += cnt - 1;
    }

    cout << res << '\n';


    return 0;
}

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

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

long long tot[11];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long h, w, n, x, y; cin >> h >> w >> n;

    unordered_map<long long, unordered_map<long long, int>> cnt;

    while(n--){
        cin >> x >> y;

        for(int i = max(2LL, x - 1); i <= min(h - 1, x + 1); ++i){
            for(int j = max(2LL, y - 1); j <= min(w - 1, y + 1); ++j){
                --tot[cnt[i][j]];
                cnt[i][j] += 1;
                ++tot[cnt[i][j]];
            }
        }

    }

    cout << (h - 2) * (w - 2) + tot[0] << "\n";

    for(int i = 1; i < 10; ++i)
        cout << tot[i] << "\n";


    return 0;
}


Measured memory_bytes: 70004
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_STN_MAX		500										// 最大駅数

// 内部変数
static FILE *szpFpI;											// 入力
static int siSCnt;												// 駅数
static int si2Trn[D_STN_MAX + 5][D_STN_MAX + 5];				// 列車数[開始駅][終了駅]

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, j;
	char lc1Buf[1024], lc1Out[1024];

	// データ - 初期化
	memset(si2Trn, 0, sizeof(si2Trn));							// 列車数[開始駅][終了駅]

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 駅数・列車数・質問数 - 取得
	int liTCnt, liQCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d%d", &siSCnt, &liTCnt, &liQCnt);

	// 列車 - 取得
	for (i = 0; i < liTCnt; i++) {
		int liSNo1, liSNo2;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &liSNo1, &liSNo2);

		// 開始駅・終了駅 - セット
		si2Trn[1][liSNo2]++;
		si2Trn[liSNo1 + 1][liSNo2]--;
	}

	// 全駅に列車数を反映 - 開始駅
	for (i = 1; i <= siSCnt; i++) {
		for (j = 2; j <= siSCnt; j++) {
			si2Trn[j][i] += si2Trn[j - 1][i];
		}
	}

	// 全駅に列車数を反映 - 終了駅
	for (i = 1; i <= siSCnt; i++) {
		for (j = 2; j <= siSCnt; j++) {
			si2Trn[i][j] += si2Trn[i][j - 1];
		}
	}

	// 質問 - 取得
	for (i = 0; i < liQCnt; i++) {
		int liSNo1, liSNo2;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &liSNo1, &liSNo2);

		// 結果 - セット
		sprintf(lc1Out, "%d\n", si2Trn[liSNo1][liSNo2]);

		// 結果 - 表示
#ifdef D_TEST
		fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
		if (strcmp(lc1Buf, lc1Out)) {
			siRes = -1;
		}
#else
		printf("%s", lc1Out);
#endif
	}

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double minkowski(int n, int *x, int *y, int p) {
  int i;
  double d;
  d = 0;
  for(i = 0;i < n;i++) {
    d += pow(abs(x[i] - y[i]), p);
  }
  d = pow(d, 1.0/p);
  return d;
}

double chebyshev(int n, int *x, int *y) {
  int i;
  double d;
  d = 0;
  for(i = 0;i < n;i++) {
    if(d < abs(x[i] - y[i])) {
      d = abs(x[i] - y[i]);
    }
  }

  return d;
}

int main() {
  int n, i;
  scanf("%d", &n);
  int x[n], y[n];
  for(i = 0;i < n;i++) {
    scanf("%d", x+i);
  }
  for(i = 0;i < n;i++) {
    scanf("%d", y+i);
  }
  for(i = 1;i <= 3;i++) {
    printf("%lf\n", minkowski(n,x,y,i));
  }
  printf("%lf\n", chebyshev(n, x, y));

  return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back


ll modpow(ll a, ll n, ll m)
{
    if(n == 0) return 1;
    ll t = modpow(a, n >> 1, m);
    t = t * t % m;
    if(n & 1) t = t * a % m;
    return t; 
}

ll modinv(ll a, ll m)
{
    return modpow(a, m - 2, m);
}

int main()
{
    ll N;
    cin >> N;
    vec A(N);
    REP(i,0,N) cin >> A[i];

    vec C(60, 0);
    REP(i,0,N) {
        REP(j,0,60) C[j] += ((A[i] >> j) & 1);
    }

    ll sum = 0;
    REP(i,0,N) {
        REP(j,0,60) {
            if((A[i] >> j) & 1) sum = (sum + ((1LL << j) % MOD) * (N - C[j])) % MOD;
            else sum = (sum + ((1LL << j) % MOD) * C[j]) % MOD;
        }
    }
    PR((sum*modinv(2,MOD))%MOD);

    return 0;
}

/*



*/

Measured memory_bytes: 5588
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
import std.numeric;

void main()
{
    readln;
    auto A = readln.chomp.split.to!(long[]);
    A.map!(a => a - 1).sum().writeln;
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =1;

int main(){
    double w,h,x,y;    cin >> w >> h >> x >> y;
    cout << fixed << setprecision(8);
    cout << w*h/2.0 << endl;
    if(2*x == w && 2*y == h)cout << 1 << endl;
    else cout << 0 << endl;
}

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




int main(void){
int x;
scanf("%d",&x);
//分類
if(x>=2000){printf("1");return 0;}

//総当たり
int a=0,b=0,c=0,d=0,e=0,f=0;
const int TIME=20;
    for(a=0;a<TIME;a++){
        for(b=0;b<TIME;b++){
            for(c=0;c<TIME;c++){
                for(d=0;d<TIME;d++){
                    for(e=0;e<TIME;e++){
                        for(f=0;f<TIME;f++){
                            if(a*100+b*101+c*102+d*103+e*104+f*105==x){printf("1");return 0;}
                        }
                    }
                }
            }
        }
    }

printf("0");
}


Measured memory_bytes: 128
H, W, K = map(int, input().split())
C = [input() for _ in range(H)]

ans = 0
for hselection in range(1 << H):
    for wselection in range(1 << W):
        count = 0
        for h in range(H):
            for w in range(W):
                if hselection & (1 << h) or wselection & (1 << w):
                    continue
                if C[h][w] == "#":
                    count += 1
        if count == K:
            ans += 1
print(ans)

Measured memory_bytes: 9112
/*input
8
8 2 7 3 4 5 6 1
*/

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

int main() {
    ll n;
    cin >> n;
    vector<ll> pos(n+1);
    rep(i, n) {
        ll val;
        cin >> val;
        pos[val] = i;
    }
    set<ll> used = {-2, -1, n, n+1, pos[n]};
    ll ans = 0;
    for (int i = n-1; i >= 1; i--) {
        set<ll>::iterator iter = used.upper_bound(pos[i]);
        iter --; iter--;
        ll l1, l2, r1, r2;
        l1= *iter;
        l2 = *(++iter);
        r1 = *(++iter);
        r2 = *(++iter);
        if (l1 == -2) l1 = -1;
        if (r2 == n+1) r2 = n;
        ans += i*(l2-l1)*(r1-pos[i]);
        ans += i*(r2-r1)*(pos[i]-l2);
        used.insert(pos[i]);
    }
    cout << ans << endl;
}

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

int main(){

	char a[6];
	a[0] ='A';
	a[1] ='B';
	a[2] ='C';
	cin >> a[3] >> a[4] >> a[5];
	for(int i = 0; i < 6; i++){
		cout << a[i];
	}
	cout << '\n';
	return 0;

}

Measured memory_bytes: 888