akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

typedef pair<int, int> P;

struct Node {
    int x, y;
    int cost;
    int k;
    int dir;
};

int main() {
    int H, W, K;
    P s, g;
    cin >> H >> W >> K;
    cin >> s.second >> s.first >> g.second >> g.first;
    s.first--;
    s.second--;
    g.first--;
    g.second--;

    vector<string> m(H);
    rep(i, H) cin >> m[i];

    vector<vector<vector<bool>>> visit(
        H, vector<vector<bool>>(W, vector<bool>(4)));
    auto comp = [](const Node& a, const Node& b) {
        if (a.cost != b.cost) return a.cost > b.cost;
        if (a.k != b.k) return a.k > b.k;
        if (a.dir != b.dir) return a.dir > b.dir;
        if (a.y != b.y) return a.y > b.y;
        return a.x > b.x;
    };
    priority_queue<Node, vector<Node>, decltype(comp)> Q(comp);

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

    rep(i, 4) {
        Q.push({
            s.first,
            s.second,
            0,
            K,
            i,
        });
    }

    while (!Q.empty()) {
        auto node = Q.top();
        Q.pop();

        if (visit[node.y][node.x][node.dir]) {
            continue;
        }
        visit[node.y][node.x][node.dir] = true;

        if (make_pair(node.x, node.y) == g) {
            cout << node.cost << endl;
            return 0;
        }

        rep(i, 4) {
            P np(node.x + dx[i], node.y + dy[i]);
            if (!(0 <= np.first && np.first < W)) continue;
            if (!(0 <= np.second && np.second < H)) continue;
            if (m[np.second][np.first] != '.') continue;
            auto nc = (node.dir == i && node.k < K) ? node.cost : node.cost + 1;
            auto nk = (node.dir == i && node.k < K) ? node.k + 1 : 1;
            Q.push({
                np.first,
                np.second,
                nc,
                nk,
                i,
            });
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 144868
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pi;

void solve(){
    int a, b;
    cin >> a >> b;
    int maxi = max(a,b);
    int mini = min(a,b);
    
    if(mini == 1){
       cout << 1 << endl;
       return;
    }
    ll ans = (maxi/2) * (ll)mini;
    if(maxi & 1){
        if(mini & 1)
            ans += mini/2 + 1;
        else
            ans += mini/2;
    }
    cout << ans << endl;
}

int main(){
    //int t; cin >> t;
    //while(t--) solve();

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n,k; cin>>n>>k;
	vector<bool> a(n,false);
	rep(i,k){
		int d; cin>>d;
		rep(j,d){
			int x; cin>>x; x--; a[x]=true;
		}
	}
	int ans=0;
	rep(i,n){
		if(a[i]==false)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3660
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    cout << fixed << setprecision(15);
    
    int n;
    cin >> n;
    if(n%2==0)
    cout << (1.0/2.0);
    else 
    cout << (n/2+1.0)/(n*1.0);
    
    
	return 0;
    
}

Measured memory_bytes: 8832
N, M = list(map(int, input().split(' ')))

L = 1
R = N

for _ in range(M):
    l, r = list(map(int, input().split(' ')))
    if l > L:
        L = l
    if r < R:
        R = r

ans = R-L+1
if ans >= 0:
  print(ans)
else:
  print(0)

Measured memory_bytes: 3060
/*
    Name:zhangchuanyan
    Copyright:HHTC
    Author:zhangchuanyan
    Date: 2020/8/15 20:53:15
    Description:
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
int main()
{
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	if(x==0){
		if(k%2==0){
			cout<<"0\n";
		}else 
		    cout<<d<<endl;
	}else {
	    ll num=x/d;
		if(num>=k){
			cout<<x-k*d<<endl;
		}else{
			
			ll kk=k-num;
			if(kk%2==0){
				cout<<abs(x-num*d)<<endl;
			}else{
				cout<<abs(x-num*d-d)<<endl;
			}
		}
	}
    return 0;
}



Measured memory_bytes: 3188
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

ll m,a,b;
vector<int> prime;
bool is_prime[100005];

void solve() {
    P ans;
    ll maxi = 0;
    rep(i,prime.size()) for(int j=i;j<prime.size();j++) {
        ll p=prime[i];
        ll q=prime[j];
        if(m < p*q) break;
        if(m >= p*q && 1.0*a/b <= 1.0*p/q && 1.0*p/q <= 1.0) {
            if(maxi < p*q) {
                ans = P(p,q);
                maxi=p*q;
            }
        }
    }
    cout<<ans.fr<<" "<<ans.sc<<endl;


}

void init() {
    rep(i,100005) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<100005;i++) {
        if(is_prime[i]) for(int j=i+i;j<100005;j+=i) is_prime[j]=false;
    }

    rep(i,100005) if(is_prime[i]) prime.pb(i);
}

int main() {
    init();
    while(cin>>m>>a>>b) {
        if(m+a+b==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int h[N];
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  int cost = h[0];
  for (int i = 1; i < N; i++) {
    if (h[i - 1] < h[i]) {
      cost += h[i] - h[i - 1];
    } 
  }
  cout << cost << "\n";
  return 0;
}

Measured memory_bytes: 256
#  --*-coding:utf-8-*--

def main():
    N = int(input())
    S = input()

    lastC = None
    n = 0

    for c in S:
        if lastC != c:
            lastC = c
            n += 1

    print(n)
    


if __name__ == '__main__':
    main()



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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

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

    string s; cin >> s;
    int n = (int) s.length();
    char la = s[n-1];
    if (la == '2' || la == '4' || la == '5' || la == '7' || la == '9') {
        cout << "hon\n";
    } else if (la == '0' || la == '1' || la == '6' || la == '8') {
        cout << "pon\n";
    } else if (la == '3') {
        cout << "bon\n";
    }
}

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

def kai(n):
    u = 1
    for i in range(1,n+1):
        u = (u*(i%(10**9+7)))%(10**9+7)
    return u
        
if abs(n-m)==1:
    print((kai(n)*kai(m))%(10**9+7))
elif n-m==0:
    print((kai(n)*kai(m)*2)%(10**9+7))
else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
ll MOD = 1000000007ll;
using namespace std;
vector<vector<int>> g;

void gen(int s, int e, int nowcol)
{
   // cerr << s << " " << e << endl;
    int med = (e + s) / 2;
    rep(i, s, med)
    {
        rep(j, med, e)
        {
            g[i][j] = nowcol;
            g[j][i] = nowcol;
        }
    }
    nowcol++;
    if (med - s <= 2)
    {
        rep(i, s, med)
        {
            rep(j, i + 1, med)
            {
                g[i][j] = nowcol;
                g[j][i] = nowcol;
            }
        }
    }
    else
    {
        gen(s, med, nowcol);
    }

    if (e - med <= 2)
    {
        rep(i, med, e)
        {
            rep(j, i + 1, e)
            {
                g[i][j] = nowcol;
                g[j][i] = nowcol;
            }
        }
    }
    else
    {
        gen(med, e, nowcol);
    }
}

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    g = vector<vector<int>>(n, vector<int>(n, 0));
    gen(0, n, 0);
    cerr << 0 << endl;
    rep(i, n)
    {
        rep(j, i + 1, n)
        {
            cout << g[i][j] + 1 << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = int64_t;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(int i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(int i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
#define vvv(T) v(v(v(T)))
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  int A, B, Q;
  cin >> A >> B >> Q;
  set<i64> S, T;
  i64 s;
  S.insert(-1 * INF);
  S.insert(INF);
  rep(i,A){
    cin >> s;
    S.insert(s);
  }

  i64 t;
  T.insert(-1 * INF);
  T.insert(INF);
  rep(i, B) {
    cin >> t;
    T.insert(t);
  }

  v(i64) X(Q);
  cin >> X;

  i64 sl, sr, tl, tr;
  for(auto &x:X){
    i64 ans = INF;
    decltype(S)::iterator key1 = S.lower_bound(x);
    sr = *key1 - x;
    sl = x - *(--key1);
    decltype(T)::iterator key2 = T.lower_bound(x);
    tr = *key2 - x;
    tl = x - *(--key2);
    chmin(ans, max(sl, tl));
    chmin(ans, max(sr, tr));
    chmin(ans, sl * 2 + tr);
    chmin(ans, tl * 2 + sr);
    chmin(ans, sr * 2 + tl);
    chmin(ans, tr * 2 + sl);
    cout << ans << "\n";
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e5 + 1;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

template <class T>
ostream &operator<<(ostream &out, deque<T> &dq) {
    while (!dq.empty()) {
        out << dq.front() << " ";
        dq.pop_front();
    }
    return out;
}

int32_t main() {
    IOS deque<char> dq;
    string p;
    cin >> p;
    for (auto x : p) {
        dq.push_front(x);
    }
    bool flag = true;
    int k;
    cin >> k;
    while (k--) {
        int n;
        cin >> n;
        if (n == 1) {
            flag = !flag;
        } else {
            char x, y;
            cin >> x >> y;
            if (flag) {
                if (x == '1') {
                    dq.push_back(y);
                } else {
                    dq.push_front(y);
                }
            } else {
                if (x == '1') {
                    dq.push_front(y);
                } else {
                    dq.push_back(y);
                }
            }
        }
    }
    // cout << dq << "ok" << endl;
    string s;
    if (flag) {
        while (!dq.empty()) {
            s += dq.back();
            dq.pop_back();
        }
    } else {
        while (!dq.empty()) {
            s += dq.front();
            dq.pop_front();
        }
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 4252
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int n,m,u,v,cnt1=0,cnt2=0;
int vis[100007],num[100007];
bool bip = true;
vector <int> edge[100007];
void dfs(int u,int par){
	vis[u]=1;
	for(int v:edge[u]){
		if(v==par) continue;
		if(vis[v]==0){
			num[v]=num[u]^1;
			dfs(v,u);
		}
		else{
			if(num[u]==num[v]) bip=false;
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	dfs(1,1);
	if(!bip) cout<<1LL*n*(n-1)/2LL-m<<"\n";
	else{
		for(int i=1;i<=n;i++){
			if(num[i]==0) cnt1++;
			else cnt2++;
		}
		cout<<1LL*cnt1*cnt2-m<<"\n";
	}
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
string s;
int main(int argc,char const* argv[])
{
  cin >> s;
  for(int i=0;i<s.size();i++)
    {
      if(s[i]=='9') 
	{
	  s[i]='1';
	  continue;
	}
      else if(s[i]=='1') 
	{
	  s[i]='9';
	  continue;
	}
    }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n;
  cin >> n; 
  int ans=pow(floor(sqrt(n)),2);
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }
int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x%y)); }
int gcd(vector<int>&v) {
	int ret = v[0];
	for (int i = 1; i < v.size(); i++) {
		ret = gcd(ret, v[i]);
	}
	return ret;
}
//エラトステネスの篩
vector<char> eratos(int n) {
	vector<char> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; i++)
		if (is_prime[i]) {
			int j = i + i;
			while (j <= n) {
				is_prime[j] = false;
				j += i;
			}
		}
	return is_prime;
}
//戻り値: n以下の素数
vector<int> get_primes(int n) {
	vector<char> is_prime = eratos(n);
	vector<int> primes;
	for (int i = 0; i < n + 1; i++)
		if (is_prime[i])
			primes.emplace_back(i);
	return primes;
}
//素因数分解
vector<int> prime_factorization(int x) {
	vector<int> primes = get_primes(sqrt(x)); //√x以下の素数について調べれば良い
	vector<int> factors;
	// xまでのeratosと同じ。ｘはgiven ｘまでの最大の素数。
	// だんだん左によってくる。だからsqrt(x)まででいい
	for (auto &p : primes) {
		while (x % p == 0) {
			x /= p;
			factors.emplace_back(p);
		}
	}
	if (x != 1)
		factors.emplace_back(x);
	return factors;
}
signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int A, B; cin >> A >> B;

	int g = gcd(A, B);

	auto f = prime_factorization(g);
	sort(all(f));
	f.erase(unique(all(f)), f.end());

	dump(f);

	cout << f.size() + 1 << endl;

	return 0;
}


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

using namespace std;

long long n, u, v, ans = 0, mn, mx;

vector<pair<long long, long long>> adj;

void solve() {
	cin >> n;
	adj.resize(n + 1);
	for (long long i = 1; i < n; ++i) {
		cin >> u >> v;
		adj[i] = {u, v};
	}
	for (long long i = 1; i <= n; ++i) {
		ans += i * (n - i + 1);
	}
	for (long long i = 1; i < n; ++i) {
		mn = min(adj[i].first, adj[i].second), mx = max(adj[i].first, adj[i].second), ans -= mn * (n - mx + 1);
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);    
    //freopen("input.txt", "r", stdin);
	solve();
    return 0;
}

Measured memory_bytes: 6340
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
		int n,k;
		cin>>n>>k;
		ll ans=pow(k-1,n-1);
		cout<<k*ans;
}
int main()
{
//code
	
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define float       double
#define	endl		'\n'
#define maxpq       priority_queue<ll>
#define minpq       priority_queue<ll, vector<ll>, greater<ll> >
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define EPS         1e-9
#define INF         1e18
#define PI          3.14159265358979323846
#define MAXI        1000000
#define what_is(x)  cerr << #x << " is " << x << endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define N 100005
int modexp(int x,int n,int mod){
	x%=mod;
	int res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n/=2;
	}
	return res;
}
int modInverse(int n, int p)
{ 
    return modexp(n, p - 2, p); 
} 
int nCr(int n,int r, int p) 
{ 
    if (r == 0) 
        return 1; 
    int fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
// writing good dfs function
//void dfs(int start,int parent)
//{
//	sz[start]=1;
//	df[start]=df[parent]+1;
//	for(auto x:v[start])
//	{
//		if(x==parent) continue;
//		dfs(x,start);
//		sz[start]+=sz[x];
//	}
//}
signed main()
{
	fast;
	int t=1;
//	cin>>t;
	while(t--)
	{
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int x=max(a*c,max(a*d,max(b*c,b*d)));
		cout<<x<<endl;
	}
   return 0;
}

Measured memory_bytes: 3620
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

int main()
{
	int M,D;cin>>M>>D;
	int cnt=0;
	rep(i,1,M)
	{
		rep(j,1,D)
		{
			if((j%10)>=2 && (j/10)>=2 && (j%10) * (j/10)==i) 
				++cnt;	
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#define M_MAX 200
#define N_MAX 1000
struct Point{
	Point():x(0),y(0){}
	Point(int x,int y):x(x),y(y){}
	int x,y;
	Point operator+(const Point &t)const{return Point(x+t.x,y+t.y);}
	Point operator-(const Point &t)const{return Point(x-t.x,y-t.y);}
	bool operator<(const Point &t)const{if(x<t.x)return true;else if(x==t.x&&y<t.y)return true;else return false;} 
};
using namespace std;
ostream &operator<<(ostream &os, const Point &p){
	os << p.x << ' ' << p.y;
	return os;
}
int main(){
	while(true){
		int m,n;
		Point o_constellation;
		Point constellation[M_MAX];
		Point stars[N_MAX];
		set<Point> stars_set;
		
		scanf("%d", &m);
		if(m==0)break;
		for(int i = 0; i < m; ++i){
			Point p;
			scanf("%d%d", &p.x, &p.y);
			if( i == 0 ){
				o_constellation = p;
				constellation[0] = Point(0,0);
			}else{
				constellation[i] = p - o_constellation;
			}
		}
		scanf("%d",&n);
		for(int i = 0; i < n; ++i){
			Point p;
			scanf("%d%d", &p.x, &p.y);
			stars[i] = p;
			stars_set.insert( p );
		}
		
		for(int i = 0; i < n; ++i){
			bool bFound = true;
			for(int j = 0; j < m; ++j){
				if( stars_set.find( stars[i] + constellation[j] ) == stars_set.end() ){
					bFound = false;
					break;
				}
			}
			if( bFound ){
				cout << (stars[i] - o_constellation) << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(2000000000)
input=lambda : sys.stdin.readline().rstrip('\n')

n=int(input())
h=list(map(int,input().split()))

dp=[10**18 for i in range(n)]
def cost(n):
    if n==0:
        return 0
    if n<0:
        return 10**18
    if dp[n]!=10**18:
        return dp[n]
    dp[n] = min(cost(n-1)+abs(h[n]-h[n-1]),cost(n-2)+abs(h[n]-h[n-2]))
    return dp[n]

print(cost(n-1))


Measured memory_bytes: 117880
#define _CRT_SECURE_NO_WARNINGS
////#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	char *pt,r[101];
	int pA, pB,f=0;
	while (fscanf(stdin, "%s", r),getchar()) {
		if (r[0] == '0') break;
		pA = pB = 0;
		pt = r+1;
		while (*pt) {
			if (*pt == 'A') pA++;
			else pB++;
			pt++;
		}
		if (pA > pB) pA++;
		else pB++;
		fprintf(stdout, "%d %d\n", pA, pB);
	}

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll a,b;

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

  cin>>a>>b;
  b+=3*a;
  cout<<b/2<<endl;

  return 0;
}


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

int main()
{
  int A, B;
  cin >> A >> B;
  
  int count = 0;
  for(int i = A; i <= B; i++)
  {
    string str_i = to_string(i);
    string str_rev;
    for(int j = str_i.size(); j > 0; j--)
    {
      str_rev += str_i.at(j - 1);
    }
    
    if(str_i == str_rev)
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n;
    string s;
    double x,ans=0;
    cin>>n;
    rep(i,n){
        cin>>x>>s;
        if(s=="JPY") ans+=x;
        else ans+=x*380000;
    }
    cout<<ans;
}

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

int main() {
    int r;
    cin >> r;
    if(r < 1200) cout << "ABC" << endl;
    else if(r < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}

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

m=n//3
r=n%3
a=[0]
for i in range(1,m+1):
	t=a[i-1]+3
	j=2
	while i>=j:
		t=min(t,a[i-j]+1)
		j*=6
	k=3
	while i>=k:
		t=min(t,a[i-k]+1)
		k*=9
	a.append(t)
print(a[m]+r)


Measured memory_bytes: 3444
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1,-1):
  if st-A[i]>0:
    ls += [st-A[i]]
  else:
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Measured memory_bytes: 64368
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <array>
#include <bitset>
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define inf 0x3f3f3f3f3f3f3f3f
#define endl '\n'
using namespace std;

signed main() {
    fastio;
    int n; cin >> n;
    vector<int> a(n), b(n);
    rep (i,n) {
        cin >> a[i] >> b[i];
    }

    for (int i = 0; i + 2 < n; i++) {
        if (a[i] == b[i] and a[i+1] == b[i+1] and a[i+2] == b[i+2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n,m,c;
	cin>>n>>m>>c;
	int b[m];
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
	}
	int a[n][m];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	int sum=0,count=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			sum = sum+(a[i][j]*b[j]);
		}
		sum=sum+c;
		if(sum>0)
		{
			count++;
		}
		sum=0;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc153_d
{
    class Program
    {
        static void Main(string[] args)
        {
            var H = GetDecimal();

            decimal r = 0;
            decimal i = 0;

            while (true)
            {
                r += (decimal)Math.Pow(2, (double)i);
                i++;
                H = Math.Floor(H / 2);
                if (H == 0) break;
            }

            Console.WriteLine(r);

        }

        public static string GetStr() => Console.ReadLine();
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());

        public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList();
        public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
        public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();

    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
 
int PLen, CNum, Width, CSpace;
vector<string> lines;
 
int currColumn;
pair<int, int> currPos;
int N, M;
vector<string> output;
bool dirty;
 
void printPage() {
  rep(i, N) cout << output[i] << endl;
  cout << "#" << endl;
  fill(output.begin(), output.end(), string(M, '.'));
  currColumn = 0;
  currPos = {0, 0};
  dirty = 0;
}
 
void print(char c) {
  if(currPos.second >= (currColumn * Width + CSpace * currColumn) + Width) {
    currPos.first ++;
    if(currPos.first >= PLen) {
      currPos.first = 0;
      currColumn ++;
    }
    currPos.second = currColumn * Width + CSpace * currColumn;
  }
     
  if(currColumn >= CNum) {
    printPage();
  }
   
  dirty = 1;
  output[currPos.first][currPos.second++] = c;
}
 
void nextLine() {
  currPos.first ++;
  if(currPos.first >= PLen) {
    currColumn ++;
    currPos.first = 0;
    if(currColumn >= CNum && dirty) printPage();
  }
  currPos.second = currColumn * Width + CSpace * currColumn;
}
 
void solve() {
   
  output.clear();
  output.resize(PLen);
  dirty = 0;
   
  N = PLen, M = Width * CNum + CSpace * (CNum - 1);
   
  rep(i, N) output[i] = string(M, '.');
 
  currColumn = 0;
  currPos = {0, 0};
   
  rep(i, lines.size()) {    
    int LLen = lines[i].size();
    dirty = 1;
    rep(j, LLen) {
      print(lines[i][j]);
    }
    nextLine();
  }
   
  if(dirty) printPage();
  cout << "?" << endl;
}
 
int main() {
 
  while(1) {
     
    lines.clear();    
    cin >> PLen >> CNum >> Width >> CSpace; cin.ignore();
 
    if(PLen == 0) break;
     
    for(int i=0;; i++) {
      string in;
      getline(cin, in);
      if(in == "?") break;
      else {
    lines.push_back(in);
      }
    }
     
    solve();
     
  }
   
  return 0;
}

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

int main(){
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}

Measured memory_bytes: 3604
N, M = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(M)]

def check(v):
    c[v] = 1
    for i in range(len(lst2)):
        if lst2[i][0]-1 == v and c[lst2[i][1]-1] == 0 and d[i] == 0:
            d[i] = 1
            check(lst2[i][1]-1)
        if lst2[i][1]-1 == v and c[lst2[i][0]-1] == 0 and d[i] == 0:
            d[i] = 1
            check(lst2[i][0]-1)
    return
    
count = 0
for i in range(M): #使わない橋を全探索
    c = [0] * N #到達したかのチェック
    d = [0]* (M-1) #確認した橋のチェック
    lst2 = lst[:i] + lst[i+1:] #使っても良い橋のリストを準備
    # print (lst2)
    check(0) #0からはじめて、繋がっているところを探索
    if 0 in c:
        count += 1
    else:
        pass
    
print (count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,C;
    cin >> A >> B >> C;
    if((A == 5 && B == 5 && C == 7) || (A == 5 && B == 7 && C == 5) || (A == 7 && B == 5 && C == 5)) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
long long int llmin(long long int a, long long int b)
{
	if (a < b)
		return a;
	else
		return b;
}
long long int llabs(long long int n)
{
	if (n < 0)
		n *= -1;
	return n;
}
int main()
{
	int a, b, q;
	scanf("%d %d %d", &a, &b, &q);
	int i;
	long long int s[100005], t[100005], x[100005];
	for (i = 0; i < a; i++)
		scanf("%lld", &s[i]);
	for (i = 0; i < b; i++)
		scanf("%lld", &t[i]);
	for (i = 0; i < q; i++)
		scanf("%lld", &x[i]);
	long long int ms[100005], mt[100005];
	int min, mid, max;
	for (i = 0; i < a; i++)
	{
		if (s[i] <= t[0])
			ms[i] = t[0] - s[i];
		else if (s[i] >= t[b - 1])
			ms[i] = s[i] - t[b - 1];
		else
		{
			min = 0;
			max = b - 1;
			while (max - min > 1)
			{
				mid = (max + min) / 2;
				if (t[mid] < s[i])
					min = mid;
				else
					max = mid;
			}
			ms[i] = llmin(s[i] - t[min], t[max] - s[i]);
		}
	}
	for (i = 0; i < b; i++)
	{
		if (t[i] <= s[0])
			mt[i] = s[0] - t[i];
		else if (t[i] >= s[a - 1])
			mt[i] = t[i] - s[a - 1];
		else
		{
			min = 0;
			max = a - 1;
			while (max - min > 1)
			{
				mid = (max + min) / 2;
				if (s[mid] < t[i])
					min = mid;
				else
					max = mid;
			}
			mt[i] = llmin(t[i] - s[min], s[max] - t[i]);
		}
	}
	long long int ans;
	for (i = 0; i < q; i++)
	{
		max = a - 1;
		min = 0;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (s[mid] < x[i])
				min = mid;
			else
				max = mid;
		}
		ans = llmin(llabs(x[i] - s[min]) + ms[min], llabs(x[i] - s[max]) + ms[max]);
		max = b - 1;
		min = 0;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (t[mid] < x[i])
				min = mid;
			else
				max = mid;
		}
		ans = llmin(ans, (llmin(llabs(x[i] - t[min]) + mt[min], llabs(x[i] - t[max]) + mt[max])));
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
int main(void)
{
    int N;
    cin >> N;
    int M;
    cin >> M;
    vector<int> a;
    for (int i = 0; i < M; i++)
    {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    lli sum = 0;
    for (int i = 0; i < M; i++)
    {
        sum += a[i];
    }
    if (N - sum >= 0)
    {
        cout << N - sum << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

int N;
const int maxn = 1e4+5;
int degree[maxn];
int A[maxn];

vector<int> vi;
queue<int> que;
set<int> G[maxn];

int main()
{
    scanf("%d",&N);
    _for(i,0,N-1){
        int a,b;
        scanf("%d %d",&a,&b);
        degree[a]++;
        degree[b]++;
        G[a].insert(b);
        G[b].insert(a);
    }
    _for(i,0,N){
        int num;
        scanf("%d",&num);
        vi.push_back(num);
    }
    sort(ALL(vi));

    _rep(i,1,N){
        if(degree[i] == 1) que.push(i);
    }


    int p = 0;
    int ans = 0;
    while(!que.empty()){
        int k = que.front();que.pop();
        if(degree[k] == 0){
            A[k] = vi[p];
            break;
        }
        ans += vi[p];
        int o = *G[k].begin();
        degree[o]--;
        degree[k]--;
        if(degree[o] == 1){
            que.push(o);
        }
        G[o].erase(k);
        A[k] = vi[p];
        p++;
    }

    printf("%d\n",ans);
    _rep(i,1,N){
        if(i != 1) printf(" ");
        printf("%d",A[i]);
    }

    return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
ll const mod=998244353;
const ll MAX=200000;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////


int main(){
    ll n;
    cin>>n;
    ll a,b;
    cin>>a>>b;
    vl x(n);
    rep(i,n)cin>>x[i];
    ll now=1;
    ll ans=0;
    rep(i,n){
        if(i==0){
            now=x[i];
            continue;
        }
        if((x[i]-now)*a<b)ans+=(x[i]-now)*a;
        else ans+=b;
        now=x[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
 <url:https://arc058.contest.atcoder.jp/tasks/arc058_a>
 問題文============================================================
 いろはちゃんはこだわりもので、嫌いな数字が K 個あり、それぞれ D1,D2,…,DK です。
 
 いろはちゃんはお店でお買い物をしていて、 N 円の品物を買おうとしています。
 もちろん、この品物は N 円以上のお金を支払えば買うことができます。
 しかし、先ほど述べたようにいろはちゃんは強いこだわりがあるので、
 自分がお店に支払う金額の 10 進表記にいろはちゃんの嫌いな数字が出現しないような最も少ない金額を支払おうとします。
 
 いろはちゃんが支払う金額を求めてください。
 =================================================================
 
 解説=============================================================
 制約弱いので順番にインクリメントの貪欲で間に合う
 ================================================================
 */
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; int K; cin >> N >> K;
    bool D[10] = {false};
    for(int i = 0; i < K;i++){
        int x; cin >> x;
        D[x] = true;
    }
    for(int ans = N;; ans++){
        int tmp = ans;
        while(tmp){
            if(D[tmp%10]) break;
            tmp/=10;
        }
        if(tmp != 0)continue;
        else{
            cout << ans << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
//g++ -std=c++17 -Wall t.cpp -o test -lm -g -O2
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl '\n'
#define teto(a, b) (a+b-1)/(b)

const int MAX = 400010;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-8;
const ld PI = acosl(-1.0);

// End - Template //

using namespace std;

vector<vi> grafo(100010, vi());
bool visited[100010];

void dfs(int u)
{
    visited[u]=true;
    for(auto v: grafo[u])
        if(!visited[v])
            dfs(v);
}

int main()
{

    int n, m, x, y, z;
    cin >> n >> m;

    for(int i=0;i<m;i++)
    {
        cin >> x >> y >> z;
        grafo[x].pb(y);
        grafo[y].pb(x);
    }

    int resp=0;
    for(int i=1;i<=n;i++)
        if(!visited[i])
        {
            dfs(i);
            resp++;
        }

    cout << resp << endl;


    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr <<"\e[91m"<<__func__<<": "<< #x << " = " << x <<"\e[39m"<< "\n"
typedef pair<int, int> pii;
typedef long long ll;
const double eps = 1e-9;
const int inf = 0x3f3f3f3f;

int h, w, k;
char a[7][7];
char b[7][7];

void cp() 
{
    for(int i=0; i<h; i++) 
        for(int j=0; j<w; j++) b[i][j] = a[i][j];

    return;
}

void color(int m, int n) 
{
    for(int i=0; i<h; i++) {
        if(m&(1<<i)) {
            for(int x=0; x<w; x++) b[i][x] = 'r';
        }
    }

    for(int i=0; i<w; i++) {
        if(n&(1<<i)) {
            for(int x=0; x<h; x++) b[x][i] = 'r';
        }
    }
}

bool check() 
{
    int total = 0;
    for(int i=0; i<h; i++) 
        for(int j=0; j<w; j++) 
            if(b[i][j] == '#') 
                total++;
    
    if(total == k) return true;
    else return false;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("../io/in.txt", "r", stdin);
    //freopen("../io/out.txt", "w", stdout);
#endif // ONLINE_JUDGE
    cin >> h >> w >> k;
    for(int i=0; i<h; i++) 
        for(int j=0; j<w; j++) cin >> a[i][j];
    
    int ans = 0;
    for(int i=0; i<(1<<h); i++) {
        for(int j=0; j<(1<<w); j++) {
            cp();
            color(i, j);
            if(check()) ans++;
        }
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			int[] dis = new int[n-1];
			for(int i = 0;i < n-1;i++){
				dis[i] = scan.nextInt();
			}
			int sum = 0;
			int now = 0;
			for(int i = 0;i < m;i++){
				int a = scan.nextInt();
				if(a > 0){
					for(int j = now;j < now+a;j++){
						sum += dis[j];
					}
				}else{
					for(int j = now-1;j >= now+a;j--){
						sum += dis[j];
					}
				}
				now += a;
				if(sum >= 500000){
					sum %= 100000;
				}
			}
			System.out.println((sum>=100000)?sum%100000:sum);
		}
	}
}

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

int n,m;
char cha[2][100];
char str[100000000];

void solve()
{
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(str[i] == cha[0][j]){
				str[i] = cha[1][j];
				break;
			}
		}
		cout << str[i];
	}
	cout << endl;
}

int main()
{
	cin >> n;
	while(n){
		for(int i=0;i<n;i++){
			cin >> cha[0][i] >> cha[1][i];
		}
		cin >> m;
		for(int i=0;i<m;i++){
			cin >> str[i];
		}
		solve();
		cin >> n;
	}
	return 0;
}

Measured memory_bytes: 940
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int numPos = Integer.parseInt(br.readLine());
    int sum = 0;
    String[] data = br.readLine().split(" ");
    int[] pos = new int[numPos];
    for(int i=0; i<numPos; i++){
      pos[i] = Integer.parseInt(data[i]);
      sum += pos[i];
    }
    double average = (double)sum/(double)numPos;
    
    int meetingPos = (int)Math.round(average);
    int result = 0;
    
    for(int i=0; i<numPos; i++){
      result += Math.pow(pos[i]-meetingPos, 2);
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 21332