akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 1000000007;

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

ll dp[101][5000];

ll naive(ll n, ll k){
    ll ret = 0;
    REP(x,powll(k+1,n)){
        VI a(n);
        ll tmp = x;
        REP(i,n){
            a[i] = tmp % (k+1);
            tmp /= k+1;
        }
        while (1){
            bool found = false;
            REP(i,n){
                if (a[i] == i+1){
                    a[i] = 0;
                    REP(j,i) a[j]++;
                    found = true;
                    break;
                }
            }
            if (!found) break;
        }
        REP(i,n) ret += a[i];
    }
    return ret;
}

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

    ll all = k * n;
    REP(i,n) all = (all * (k+1)) % mod;
    all = divll(all, 2);

    dp[n][0] = 1;
    FORR(i,n,1){
        REP(j,5000){
            if (dp[i][j] == 0) continue;
            REP(x,k+1){
                if (x > i) dp[i-1][j] = (dp[i-1][j] + dp[i][j]) % mod;
                else dp[i-1][j+(j+x)/i] = (dp[i-1][j+(j+x)/i] + dp[i][j]) % mod;
            }
        }
    }

    ll ans = all;
    REP(j,5000) ans = (ans - j * dp[0][j] + 50000 * mod) % mod;

    // cout << all << endl;

    // REP(i,n+1){
    //     REP(j,10) cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    cout << ans << endl;

    // cout << naive(n,k) << endl;
    return 0;
}




Measured memory_bytes: 768
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc115_a.cpp
 * time   : Fri May  1 14:24:11 2020
 * quest  : A - Christmas Eve Eve Eve
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int d;
  cin >> d;
  cout << ((d > 24) ? "Christmas\n" : (d > 23) ? "Christmas Eve\n" : (d > 22) ? "Christmas Eve Eve\n" : "Christmas Eve Eve Eve\n");
  return 0;
}


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

using namespace std;

int main() {
    int n;
    cin>>n;
    vector<long long> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    long long sum=0;
    for(int i=0;i<n;i++){
        if(i%2==0)sum+=a[i];
        else sum-=a[i];
    }
    sum/=2;
    cout<<sum*2<<" ";
    for(int i=1;i<n;i++){
        sum=a[i-1]-sum;
        cout<<sum*2<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mod=1e9+7;

ll prod(ll x, ll y) {
	x%=mod;
	y%=mod;
	return (x*y)%mod;
}

ll sum(ll x, ll y) {
	return (x+y)%mod;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll N,K; cin>>N>>K;
	vector<ll> A(N);
	for (int i=0; i<N; i++)
		cin>>A[i];
	ll same=0, diff=0;
	for (int i=0; i<N; i++)
		for (int j=i+1; j<N; j++)
			if(A[i]>A[j])
				same++;
	for (int i=0; i<N; i++)
		for (int j=0; j<N; j++)
			if(A[i]>A[j])
				diff++;
	cout<<sum(prod(same,K),prod(diff,K*(K-1)/2))<<"\n";
	return 0;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getbit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

map<int, map<int, double>> mem;

double cal(vector<double> &a, int k, int n) {
  if (k == 0) return 1.0;
  if (mem[n].count(k)) return mem[n][k];
  if (n == k) {
    double ret = 1.0;
    for (int i = 1; i <= n; i++) {
      ret *= a[i];
    }
    return mem[n][k] = ret;
  }
  double ret = 0.0;
  ret += cal(a, k - 1, n - 1) * a[n];
  ret += cal(a, k, n - 1) * (1 - a[n]);
  return mem[n][k] = ret;
}

void MAIN() {
  int n; cin >> n;
  vector<double> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cout << fixed << setprecision(10);
  cout << cal(a, (n + 1) / 2, n) << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 145060
<?php

fscanf(STDIN, "%d", $n);
$a = trim(fgets(STDIN));
$a_array = explode(' ', $a);

$cnt = 0;
while (true) {
    $new_array = array();
    foreach ($a_array as $value) {
        if ($value % 2 == 0) {
            $new_array[] = $value / 2;
        } else {
            echo $cnt;
            return;
        }
    }
    $a_array = $new_array;
        $cnt++;
}
echo $cnt;


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)	cin>>a[i];
	sort(a,a+n);
	int count=0;
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			for(int k=j+1;k<n;k++){
				if(a[i]!=a[j]&&a[j]!=a[k]){
					if(a[i]+a[j]>a[k])	count++;
				}
			}
		}
	}
cout<<count;
return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
typedef unsigned long long ull;
typedef pair<int, int> pr;

int main(){
    int n;
    cin>>n;
    vector<ll>a(n);

    vector<ll>p;
    map<ll,ll>mp;
    for(int i=0;i<n;i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a.begin(),a.end());
    ll ans=0;
    ll v=1;
    while(v<2e9+1){
        v*=2;
        p.push_back(v);
    }
    for(int i=n-1;i>=0;i--){
        if(mp.count(a[i])==0){
            continue;
        }
        if(mp[a[i]]==0){
            continue;
        }
        ll x=*upper_bound(p.begin(), p.end(), a[i]);
        ll res=x-a[i];
        if(res==a[i]){
            if(mp[a[i]]>1){
                ans++;
                mp[a[i]]-=2;
            }
            continue;
        }
        if(mp.count(res)==0){
            continue;
        }
        if(mp[res]==0){
            continue;
        }
        ans++;
        mp[a[i]]--;
        mp[res]--;
    }
    cout<<ans;
    return 0;
}

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

#define pb            push_back
#define mp            make_pair
#define ins           insert
#define endl          '\n'
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<endl<<(#X)<<" = "<<(X)<<endl; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,a,b,s=LLONG_MAX;
    cin >> n;

    for (ll i=sqrt(n); i>=1; --i)
        if (!(n%i)) {
            a = n/i;
            b = i+a-2;
            break; 
        }


    cout << b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MAX_N = 362881;

// 重複があってもすべての順列を列挙する
// next_permutationは辞書順で次の順列を生成する
int perm[MAX_N];
vector<vector<bool> > p(8, vector<bool>(8));
vector<vector<bool> > used(8, vector<bool>(8));
int answer = 0;
void permutation(int n) {
    rep(i, n){
        perm[i] = i;
    }
    do {
        // permに対する操作
        if(perm[0] != 0) return;
        rep(i, n)
            rep(j, n) used.at(i).at(j) = false;
        rep(i, n){
            if(i == n-1) {
                answer++;
                break;
            }
            if(p.at(perm[i]).at(perm[i+1]) && !used.at(perm[i]).at(perm[i+1])) {
                used.at(perm[i]).at(perm[i+1]) = true;
                used.at(perm[i+1]).at(perm[i]) = true;
            }
            else break;
        }
    } while (next_permutation(perm, perm + n));
    return;
    
}

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n)
        rep(j, n) p.at(i).at(j) = false;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        p.at(a-1).at(b-1) = true;
        p.at(b-1).at(a-1) = true;
    }
    permutation(n);
    cout << answer << endl;
}

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

using namespace std;

#define int long long
#define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Printv(v)                                                              \
    {                                                                          \
        REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll dp[3030][3030];

VVL G;
VL in;
ll d[100000];

ll dfs(ll now) {
    if(d[now]) return d[now];
    ll &res = d[now];
    FOREACH(to, G[now]) res = max(res, dfs(to) + 1);
    return res;
}

signed main() {
    LCIN(N, M);
    G.resize(N);
    in.resize(N);
    REP(i, M) {
        LCIN(x, y);
        x--, y--;
        in[y]++;
        G[x].emplace_back(y);
    }
    ll ans = 0;
    REP(i, N) {
        if(d[i] == 0) {
            ans = max(ans, dfs(i));
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
#include<string>
using namespace std;
int N;
void dfs(string s,char mx)
{if(s.length() ==N)
{printf("%s\n",s.c_str());}
 else{for(char c='a';c<=mx;c++)
 {dfs(s+c, ((c==mx) ? (char)(mx+ 1) :mx));}
     }
}
int main(void)
{cin>>N;
 dfs("", 'a');
 return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
    
using namespace std;
 
#define f first
#define s second
#define pb push_back
#define sz(v) ((int)v.size())   
#define rad(a) a * PI / 180  
 
typedef long long ll;
typedef vector<int> vi;	
typedef pair<ll,ll> ii;
typedef pair<int,char> ic;
typedef pair<ll, bool> llb;
 
const int SIGMA = 20;
const int MAX = 2010;
const int MAXT = 1048576;
const ll INF = 1000000001;
const ll P = 1000000007;
const double EPS = 1e-6;
const double PI = 3.14159265358979;

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

	int n;

	cin >> n;

	int total = 0;

	for(int i = 1; i <= n; i++){
		int j = n-i;
		if(j > i) total++;
	}

	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main() {
  int array[4];
  for(int i = 0; i < 4; i++) {
    scanf("%1d", &array[i]);
  }
  for(int i = 0; i < 3; i++) {
    if(array[i] == array[i+1]) {
      printf("Bad\n");
      return 0;
    }
  }
  printf("Good\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int A,B,Q;cin>>A>>B>>Q;
    vector<int>S(A+2);
    vector<int>T(B+2);
    S[0]=-INF;
    S[A+1]=INF;
    T[0]=-INF;
    T[B+1]=INF;
    REPS(i,A)cin>>S[i];
    REPS(i,B)cin>>T[i];
    REP(k,Q){
        int x;cin>>x;
        int ans=INF;
        for(int i=0;i<=1;i++){
            for(int j=0;j<=1;j++){
                auto v=lower_bound(all(S),x);
              	auto w=lower_bound(all(T),x);
              	if(i==1)v--;
              	if(j==1)w--;
                chmin(ans,abs(x-*v)+abs(*w-*v));
            }
        }
        for(int i=0;i<=1;i++){
            for(int j=0;j<=1;j++){
                auto v=lower_bound(all(T),x);
              	auto w=lower_bound(all(S),x);
              	if(i==1)v--;
              	if(j==1)w--;
                chmin(ans,abs(x-*v)+abs(*w-*v));
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2944
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;

    N = N % 10;

    if (N == 0 || N == 1 || N == 6 || N == 8) cout << "pon";
    else if (N == 3) cout << "bon";
    else cout << "hon";

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const int INF = 1001001001;

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

struct Edge
{
    int to;
    int cost;
};

int k;

vector<vector<Edge>> g(114514);

void dijkstra() {
    vi d(k, INF);
    d[1] = 1;

    // int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義する場合
    priority_queue<P, vector<P>, greater<P>> q;
    q.push(P(1, 1));

    while(!q.empty()) {
        P p = q.top(); q.pop();
        int v = p.first;
        if(d[v] < p.second) continue;
        for(auto e : g[v]) {
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.push(P(e.to, d[e.to]));
            }
        }
    }

    cout << d[0] << endl;
}

int main() {
    cin >> k;
    rep(i, k) {
        if(i != k-1) g[i].push_back(Edge{i+1, 1});
        else g[i].push_back(Edge{0, 1});
        if((i * 10) % k != i) g[i].push_back(Edge{(i * 10) % k, 0});
    }

    /*
    rep(i, k) {
        cout << i << ": " << endl;
        for(auto j : g[i]) {
            cout << j.to << " " << j.cost << endl;
        }
    }
    */

    dijkstra();
    
    return 0;
}


Measured memory_bytes: 8564
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    if(n%2==0){
      System.out.println(n/2);
    }else{
      System.out.println(n/2+1);
    }
  }
  

  
}

Measured memory_bytes: 23764
icase=0
if icase==0:
    number=["0","1","2","3","4","5","6","7","8","9"]
    a,b=map(int,input().split())
    s=list(input())
    yn=""
    for i in range(a):
        if not s[i] in number:
            yn="No"
            break
    if s[a]!="-":
        yn="No"
    for i in range(b):
        if not s[a+i+1] in number:
            yn="No"
            break
    if yn=="No":
        print("No")
    else:
        print("Yes")

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

int main(){
  int n;
  string s;
  cin >>n >>s;
  int ans = 0;
  for(int i = 1; i<=n; i++){
    if(s[i-1]!=s[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;

ll dp[55][55][2505];
ll N, A, x[100];


int main() {
	cin >> N >> A;
	for (int i = 0; i < N; i++) cin >> x[i]; dp[0][0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < 2505; k++) {
				if (dp[i][j][k] == 0)continue;
				dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	ll sum = 0;
	for (int i = 1; i <= N; i++)sum += dp[N][i][A*i];
	cout << sum << endl;
	

	return 0;
}

Measured memory_bytes: 53504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<int, int> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
int ans = 0;

void step(int num,int sum,int n,int m, vector<int> a, vector<int> b, vector<int> c) {

	c.at(num - 1) = 1;
	sum++;
	if (sum == n) {
		ans++;
	}
	rep(i, m) {
		if (num == a.at(i) && c.at(b.at(i) - 1) == 0) {
			step(b.at(i), sum, n, m, a, b, c);
			continue;
		}
		if (num == b.at(i) && c.at(a.at(i) - 1) == 0) {
			step(a.at(i), sum, n, m, a, b, c);
		}
	}
}

int main() {

	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	vector<int> c(n, 0);
	rep(i, m) cin >> a.at(i) >> b.at(i);
	
	int num = 1;
	int sum = 0;
	step(num, sum, n, m, a, b, c);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    
//解説AC
  int main(){
      lint n,a,b;
      cin>>n>>a>>b;
      lint h[n];
      rep(i,n)cin>>h[i];
      lint ng=0;
      lint ok=1000000009;
        while(ok-ng>1){
            lint mid=(ng+ok)/2;
            lint count=0;
            rep(i,n){
                lint x=b*mid;
                if(h[i]-x>0)count+=(h[i]-x+a-b-1)/(a-b);
            }
           // cout<<count<<" "<<ng<<" "<<ok<<" "<<mid<<endl;
            if(count<=mid)ok=mid;
            else ng=mid;
        }
        cout<<ok<<endl;
  }
  
     


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

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

    int countSum = 0;
    for (int i = 1; i <= n; ++i)
    {
        int digitNum = to_string(i).size();
        if (digitNum % 2 == 1)
        {
            ++countSum;
        }
    }

    cout << countSum << endl;
}

Measured memory_bytes: 256
#from heapq import heappush, heappop
import heapq

N,M=map(int,input().split())
alist=list(map(int,input().split()))

hq=[]
for a in alist:
  heapq.heappush(hq,-a)
  
while(M>0):
  target=-1*heapq.heappop(hq)
  target//=2
  heapq.heappush(hq,-target)
  M-=1

answer_list=[heapq.heappop(hq) for i in range(len(hq))]
#print(answer_list)
print(-sum(answer_list))

Measured memory_bytes: 14184
import fractions

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

ans = nums[0]

def lcm(a, b):
    return a * b // fractions.gcd(a, b)

for i in range(1, N):
    ans = lcm(ans, nums[i])

total = 0

for num in nums:
    total += (ans-1) % num
print(total)

Measured memory_bytes: 5344
#include <stdio.h>
#define N 200000
long jud_big(long,long);
long jud_small(long,long);
int main(){
  int i,j,n;
  long minv,maxv,R[N];
  
    scanf("%d",&n);
  for(j=0;j<n;j++)scanf("%ld",&R[j]);
  
maxv = R[1]-R[0];
  minv = R[0];
  for(i=1;i<n;i++){
      maxv = jud_big(maxv,R[i]-minv);
      minv=jud_small(minv,R[i]);
    }
  printf("%ld\n",maxv);
  return 0;
}

long jud_big(long a, long b){
  if(a >= b)return a;
  else return b;
}

long jud_small(long a,long b){
  if(a>=b)return b;
  else return a;
}





Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T,class U>
ostream& operator << (ostream& os,pair<T,U>& p){
	os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
	is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		os << vec[i];
		if(i+1<vec.size())os << ' ';
	}
	return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
	for(int i=0;i<vec.size();i++)is >> vec[i];
	return is;
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
const int SIZE = 1<<18;
struct segtree{
	ll minimum[SIZE*2],lazy[SIZE*2];
	void lazy_evaluate(int k){
		minimum[k]+=lazy[k];
    // k isn't leaf of SegmentTree
		if(k<SIZE-1){
			lazy[2*k+1]+=lazy[k];
			lazy[2*k+2]+=lazy[k];
		}
		lazy[k]=0;
	}
	void update(int a,int b,int k,int l,int r,ll x){
		lazy_evaluate(k);
		if(r<=a||b<=l)return;
		if(a<=l&&r<=b){
			lazy[k]+=x;
			lazy_evaluate(k);
		}else{
			update(a,b,k*2+1,l,(l+r)/2,x);
			update(a,b,k*2+2,(l+r)/2,r,x);
			minimum[k] = max(minimum[k*2+1],minimum[k*2+2]);
			return;
		}
	}
	ll query(int a,int b,int k,int l,int r){
		lazy_evaluate(k);
		if(r<=a||b<=l)return -LLINF; // min,max henkouji chuui !!!!!!!
		if(a<=l&&r<=b)return minimum[k];
		else{
			ll lch = query(a,b,k*2+1,l,(l+r)/2);
			ll rch = query(a,b,k*2+2,(l+r)/2,r);
			return max(lch,rch);
		}
	}
}seg;
int N,M;
int l[200100],r[200100];
ll a[200100];
vector<int> id[200100];
int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> l[i] >> r[i] >> a[i];
    id[r[i]].pb(i);
  }
  for(int i=1;i<=N;i++){
    ll x = seg.query(0,i,0,0,SIZE);
    for(int j=0;j<id[i].size();j++){
      int idx = id[i][j];
      x += a[idx];
      seg.update(l[idx],r[idx],0,0,SIZE,a[idx]);
    }
    seg.update(i,i+1,0,0,SIZE,x);
  } 
  ll ans = 0ll;
  for(int i=0;i<=N;i++){
    chmax(ans,seg.query(i,i+1,0,0,SIZE));
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 22016
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

vl fact,finv;
ll modpw(ll x,ll k){
	ll res=1;
	while(k!=0){
		if(k&1)res=res*x%MOD;
		x=x*x%MOD;
		k=k>>1;
	}
	return res;
}

ll comb(ll n,ll k) {
	if(n==0&&k==0)return 1;
	if(n<k||n<0)return 0;
	return fact[n]*finv[n-k]%MOD*finv[k]%MOD;
}

struct ferm{
	ferm(ll n){
		fact.resize(n);
		finv.resize(n);
		fact[0]=1;
		finv[0]=1;
		rep(i,n-1){
			fact[i+1]=(fact[i]*(i+1))%MOD;
			finv[i+1]=modpw(fact[i+1],MOD-2);
		}
	}
};

ll f(ll r,ll c){
	ll ret=0;
	if(r<c)swap(r,c);
	range(i,1,r+2){
		ret+=comb(c+i,c);
		ret%=MOD;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ferm(2000010);
	ll r1,r2,c1,c2;
	cin>>r1>>c1>>r2>>c2;
	ll ans=f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1);
	ans+=5*MOD;
	ans%=MOD;
	cout<<ans<<endl;
}


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

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n;
    cin >> n;
    int all = 1;
    int even = 1;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        if (a%2 == 0) even *= 2;
        all *= 3;
    }
    cout << all - even << endl;
}


Measured memory_bytes: 3180
class stack:
    def __init__(self):
        self.s = []
    def push(self, x):
        self.s.append(x)
    def pop(self):
        ret = self.s[-1]
        del self.s[-1]
        return ret
    def size(self):
        return len(self.s)

inputL = input().split()
s = stack()
for char in inputL:
    if char == '+':
        b = s.pop()
        a = s.pop()
        s.push(a+b)
    elif char == '-':
        b = s.pop()
        a = s.pop()
        s.push(a-b)
    elif char == '*':
        b = s.pop()
        a = s.pop()
        s.push(a*b)
    elif char == '/':
        b = s.pop()
        a = s.pop()
        s.push(a/b)
    else:
        s.push(int(char))
print(s.pop())


Measured memory_bytes: 5600
<?php

     $S = trim(fgets(STDIN));

     $T = trim(fgets(STDIN));

$arrS = str_split($S);

$arrT = str_split($T);

$wether_count = 0;


for($i = 0; $i < 3; $i++) {

     if ($arrS[$i] === $arrT[$i]) {

              $wether_count++;

      }

}

echo $wether_count;

?>

Measured memory_bytes: 3828
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int x;
	cin >> x;

	if (x < 1200)
		cout << "ABC" << endl;
	else
		cout << "ARC" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		String S = stdIn.next();
		String T = stdIn.next();

		if(S.equals(T.substring(0,(T.length()-1)))) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s(n+1);
  int m;
  for(int i = 0; i < n; i++){
    cin >> m;
    s.at(i+1) = s.at(i) + m+1;
  }
  
  int ans = 0;
  int tmp = 0;
  for(int i = 0; i + k <= n; i++){
    tmp = s.at(i+k) - s.at(i);
    if(ans < tmp) ans = tmp;
  }
  cout << setprecision(12) << (double)ans/2;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  vector<long long> S(N);
  S[0] = A[0];
  for (int i = 1; i < N; i++){
    S[i] = S[i - 1] + A[i];
  }
  int m = 0;
  for (int i = 1; i < N; i++){
    if (A[i] > S[i - 1] * 2){
      m = i;
    }
  }
  cout << N - m << endl;
}

Measured memory_bytes: 4476
// atcoder/abc143/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    stack<char> s;
    for (int i = 0; i < n; ++i) {
      char c;
      cin >> c;
      if (s.empty()) s.push(c);
      else if (s.top() != c) s.push(c);
    }
    cout << s.size() << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#define mp make_pair
#define pii pair<int,int> 
#define ff first
#define ss second

using namespace std;

stack<int> stk;
int input;
int main()
{
	while(scanf("%d",&input)!=EOF)
	{
		if(input==0)
		{
			printf("%d\n",stk.top());
			stk.pop();
		}
		else
		{
			stk.push(input);
		}
	}
	return 0;
}

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

const int mod=998244353;
#define ll long long
#define ld long double
#define pb push_back
#define Dracarys ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()

ll po(ll x,ll y,ll md=mod){
	ll res=1;
	x%=md;
	
	while(y){
		if (y&1){
			res=(res*x)%md;
		}
		y>>=1;
		x=(x*x)%md;
	}
	return res;
}
vector<ll> v;
ll n,avg,now;
vector<vector<vector<ll> > > dp[2];
ll rec(ll pos,ll rem,ll till,ll ty){
	if (rem<0 or till>now){
		return 0;
	}
	if (pos==n){
		//base
		if (ty){
			//take
			if (till!=now-1 or v[pos]!=rem){
				dp[ty][pos][rem][till]=0;
			}
			else{
				dp[ty][pos][rem][till]=1;
			}
		}
		else{
			//don't take
			if (rem or (till!=now)){
				return dp[ty][pos][rem][till]=0;
			}
			else{
				return dp[ty][pos][rem][till]=1;
			}
		}
	}
	
	if (dp[ty][pos][rem][till]!=-1)
	return dp[ty][pos][rem][till];
	
	ll res=0;
	if (ty){
		res+=rec(pos+1,rem-v[pos],till+1,0);
		res+=rec(pos+1,rem-v[pos],till+1,1);
	}
	else{
		res+=rec(pos+1,rem,till,0);
		res+=rec(pos+1,rem,till,1);
	}
	return dp[ty][pos][rem][till]=res;	
}

void solve(){
	cin>>n>>avg;
	v.resize(n+1,0);
	ll sum=0;	
	for (ll i=1;i<=n;i++){
		cin>>v[i];
		sum+=v[i];
	}
	
	ll ways=0;
	// O(n^5)
	for (ll i=1;i<=n;i++){
		//no of nums selected
		if (avg*i>sum)
		continue;
		now=i;
		dp[0].clear();dp[1].clear();
		dp[0].resize(n+1,vector<vector<ll> >(avg*i+1,vector<ll>(i+1,-1)));
		dp[1].resize(n+1,vector<vector<ll> >(avg*i+1,vector<ll>(i+1,-1)));
		ways+=(rec(1,avg*i,0,0)+rec(1,avg*i,0,1));
	}
	cout<<ways<<"\n";
}

int main(){
	
	Dracarys

	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int l2(int j, int k){
	int i = 0;
	while(j < k){
		j *= 2;
		i++;
	}
	return i;
}
int p2(int i){
	ll x = 1;
	while(i--) x*=2;
	return x; 
}
int main(void)
{
	int n, k, a[20] = {};
	double p = 0;
	cin >> n >> k;
	rep(i, n){
		int t = i + 1;
		a[l2(t, k)]++;
	}
	rep(i, 20){
		// cout << a[i] << " ";
		p += a[i] / (double)(n * p2(i));
	}
	printf("%.16f\n", p);
	// cout << p << endl;
	return 0;
}

Measured memory_bytes: 256
#include <climits>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
inline bool validate(int x, int y, int H, int W) {
  return 0 <= x && x < H && 0 <= y && y < W;
}
int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<string> v(H);
  for (int i = 0; i < H; i++)
    cin >> v[i];
  int sx = 0, sy = 0;
  for (int i = 0, f = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (v[i][j] == 'S') {
        f = 1;
        sx = i;
        sy = j;
        break;
      }
    }
    if (f)
      break;
  }
 
  int cheese = N;
  int dst = 0;
  int life = 1;
  while (cheese > 0) {
    vector<vector<int>> w(H, vector<int>(W, INT_MAX));
    queue<pair<int, int>> q;
    q.push(make_pair(sx, sy));
    w[sx][sy] = 0;
    while (!q.empty()) {
      const int tbl[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
      pair<int, int> p = q.front();
      q.pop();
      const int x = p.first, y = p.second;
      if ('1' <= v[x][y] && v[x][y] <= '9') {
        if (life >= (v[x][y] - '0')) {
          life++;
          cheese--;
          v[x][y] = '.';
          
          sx = x, sy = y;
          dst += w[x][y];
break;
        }
      }
      for (int i = 0; i < 4; i++) {
        int nx = x + tbl[i][0], ny = y + tbl[i][1];
        if (validate(nx, ny, H, W)) {
          if (v[nx][ny] != 'X' && w[nx][ny] == INT_MAX) {
            q.push(make_pair(nx, ny));
            w[nx][ny] = w[x][y] + 1;
          }
        }
      }
    }
  }
  cout << dst << endl;
 
  return 0;
}


Measured memory_bytes: 7888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 59; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n;
cin >> n;
ll a[6]={0,0,(ll)1e+9,1,(ll)1e+9-(n-1)%(ll)1e+9 -1,(n-1)/(ll)1e+9 +1};

rep(i,5){
    cout <<a[i] << " ";
}
    cout <<a[5] << endl;

return 0;
}


Measured memory_bytes: 256
use io::*;
use std::collections::HashSet;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let m: usize = sc.next();
    let v0: Vec<usize> = sc.next_vec_len();
    let mut set: HashSet<usize> = v0.iter().map(|x| *x).collect();
    for i in 1..n {
        let v: Vec<usize> = sc.next_vec_len();
        let set_t: HashSet<usize> = set.intersection(&v.iter().map(|x| *x).collect()).map(|x| *x).collect();
        set = set_t;
    }
    println!("{}", set.len());
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


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

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  int total = 0;
  rep(i, n) {
    cin >> s[i];
    total += s[i];
  }
  SORT(s);
  bool ans = true;
  if (total % 10 == 0) {
    rep(i, n) {
      if (s[i] % 10 == 0)
        continue;
      else {
        cout << total - s[i] << endl;
        ans = false;
        break;
      }
    }
    if (ans) cout << 0 << endl;
  } else {
    cout << total << endl;
  }
}

Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
k=int(input())
n=k
x=7
for i in range(n):
    if x%k==0:
        print(i+1)
        break
    x=(x%k)*10+7
else:
    print(-1)

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

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

	ll x, y;
	bool can = false;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			x = i;
			y = n / i;
		}
	}

	cout << x - 1 + y - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int main()
{
	char s[4];
	cin >> s[0] >> s[1] >> s[2] >> s[3];
	int a = s[0] - '0';
	int b = s[1] - '0';
	int c = s[2] - '0';
	int d = s[3] - '0';
	if (a + b + c + d == 7)	cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
	else if (a - b + c + d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
	else if (a + b - c + d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
	else if (a + b + c - d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a - b - c + d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
	else if (a - b + c - d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a + b - c - d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
	else if (a - b - c - d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()
	M := sc.NextInt()
	v := make([]int, N+2)
	for i := 0; i < M; i++ {
		l := sc.NextInt()
		r := sc.NextInt()
		v[l]++
		v[r+1]--
	}
	ans := 0
	for i := 0; i < len(v)-1; i++ {
		v[i+1] += v[i]
		if v[i+1] == M {
			ans++
		}
	}
	fmt.Println(ans)
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func gcd(x, y int) int {
	if y > 0 {
		return gcd(y, x%y)
	}
	return x
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func max64(x, y float64) float64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func min64(x, y float64) float64 {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


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

int main(){
    int n,m;
    vector<int> s(m),c(m);
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> s[i] >> c[i];
    }
    
    for(int i=0;i<1000;i++){
        string S = to_string(i);
        if(S.size() != n) continue;
        bool ok = true;
        for(int j=0;j<m;j++){
            if(S[s[j]-1] != c[j]+'0'){
                ok = false;
                break;
            }
        }
        if(ok){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 512