akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void dump_(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

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

  vector<int> x(10);
  rep(i, 3) IN(x[i]);

  sort(all(x), greater<>());

  OUTL(x[0] * 10 + x[1] + x[2]);
  return 0;
}


Measured memory_bytes: 256
import sys


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a%b)


if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    ans = a_list[0]
    for a in a_list[1:]:
        ans = gcd(ans, a)
    print(ans)


Measured memory_bytes: 14172
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ost;

const ll maxN = 1e5 + 11;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll idx, ll val){
	if(start == end)
		segtree[node] += val;
	else{
		ll mid=(start + end)/2;
		if(idx <= mid)
			update(left(node), start, mid, idx, val);
		else
			update(right(node), mid+1, end, idx, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll a[n];
	ll sums = 0;
	for(ll i=0; i<n; i++){
		cin >> a[i];
		sums += a[i];
	}
	bool ns = true;
	for(ll i=0; i<n; i++){
		if(sums - a[i] <= a[i])
			ns = 0;
	}
	if(ns)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

signed main() {
  IOS;
  int x,a;
  cin >> x >> a ;
  cout << (x < a ? 0 : 10) << endl;
  return 0;
}

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

int N, M, Q;
long long ans = 0;
int A[101], B[101], C[101], D[101];

void dfs(vector<int> v, int cnt, int las) {
	if (cnt == N) {
		long long res = 0;
		for (int i = 0; i < Q; i++) {
			if (v[B[i] - 1] - v[A[i] - 1] == C[i])res += D[i];
		}
		ans = max(ans, res);
	}
	else {
		for (int i = las; i < M + 1; i++) {
			vector<int>nw = v;
			nw.push_back(i);
			dfs(nw, cnt + 1, i);
		}
	}

}

int main() {
	cin >> N >> M >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> A[i] >> B[i] >> C[i] >> D[i];
	}
	vector<int> v;
	dfs(v, 0, 1);
	cout << ans;
}

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

long long H[101][101];
bool can[101][101];

int main() {
    int n;
    cin >> n;
    long long x[n],y[n],h[n];
    for(int i=0;i<n;i++) cin >> x[i] >> y[i] >> h[i];
    
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            H[i][j] = -1;
            can[i][j] = true;
        }
    }
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            for(int k=0;k<n;k++){
                if(h[k] != 0){
                if(H[i][j] == -1) H[i][j] = max(i-x[k],x[k]-i)+max(j-y[k],y[k]-j)+h[k];
                else if(H[i][j] != max(i-x[k],x[k]-i)+max(j-y[k],y[k]-j)+h[k]){
                    can[i][j] = false;
                }
                }
            }
        }
    }
    for(int k=0;k<n;k++){
        if(h[k] == 0) can[x[k]][y[k]] = false;
    }
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            for(int k=0;k<n;k++){
                if(h[k] == 0){
                    if(H[i][j] >  max(i-x[k],x[k]-i)+max(j-y[k],y[k]-j)) can[i][j] = false;
                }
            }
        }
    }
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            if(can[i][j]) cout << i << ' '  << j << ' ' << H[i][j] << endl;
        }
    }
}

Measured memory_bytes: 384
#include <cstdlib>
#include <iostream>
#include <typeinfo>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  string v = "aiueo";
  char c;
  cin >> c;
  for (int i = 0; i < 5; i++)
  {
    if (c == v.at(i))
    {
      cout << "vowel" << endl;
      break;
    }
    else
    {
      if (i == 4)
      {
        cout << "consonant" << endl;
      }
    }
  }
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;
const ll MOD = 1e9+7;


// n^m%MOD を求める。O( log(m) )
ll modpow(ll n, int m){
	ll ret=1;
	for(int i=1; i<=m; i<<=1, (n*=n)%=MOD){
		if( m&i ) (ret *= n) %= MOD;
	}
	return ret;
}

// 逆元を求める
ll modinv(ll n){
	return modpow( n, MOD-2 );
}

// 階乗を求める。O(1)  準備O( n*log(n) )
// fact[n]     : nの階乗
// fact.inv[n] : nの階乗の逆元
class FACTORIAL{
	public:
		vector<ll> fact, inv;
		FACTORIAL(int MAX_NUM): fact(MAX_NUM), inv(MAX_NUM) {
			fact[0] = inv[0] = 1;
			for(ll i=1; i<MAX_NUM; i++){
				fact[i] = (fact[i-1] * i) % MOD;
				inv[i] = modinv( fact[i] );
			}
		}
		const ll& operator [ ] ( const int i ) const {
			return fact[i];
		}
} fact(1000006); // nの最大値を指定


// 組み合わせ(Combinationを求める) O(1)
ll cmb(unsigned int n, unsigned int r){
	if( n < r ) return 0;
	return fact[n] * fact.inv[r] % MOD * fact.inv[n-r] % MOD;
}

int main(){
	//ios_base::sync_with_stdio(0);
	ll N, M, ans=0;

	cin >> N >> M;
	if( abs(N-M) <= 1 ){
		ans = fact[N] * fact[M] % MOD;
		if( N == M ) ans = ans * 2ll % MOD;
	}else{
		ans = 0;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 15872
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    N = int(input())
    s = str(N)
    print("Yes" if s == "".join(reversed(s)) else "No")

if __name__ == "__main__": main()


Measured memory_bytes: 4084
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

lli gcd(lli a,lli b){
    lli c,d;
    c=max(a,b);
    d=min(a,b);
    if(c%d==0){
        return d;
    }
    else{
        return gcd(d,c%d);
    }
}

int main(){
    lli n,a,ans;
    vector<lli> vec,def;
    lli i,j;
    cin>>n;
    rep(i,0,n){
        cin>>a;
        if(i==0){
            ans=a;
        }
        else{
            ans=gcd(ans,a);
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	vector<VI> vv(m, VI(2));
	rep(i, m) cin >>vv[i][0] >> vv[i][1];
	sort(all(vv),[](auto& l, auto& r){return l[1]<r[1];});
	int ans =0, cr= 0;
	rep(i, m){
		if(cr <= vv[i][0]){
			ans++; cr = vv[i][1];
		}
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 5760
#include <cstdio>
#include <iostream>
#include <algorithm>
#define SENTINEL 1e9
using namespace std;

int cnt;
void Merge(int* A, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int *L,*R;
  L = new int[n1+1]; R=new int[n2+1];
  for(int i=0;i<n1;i++){
	  L[i] = A[left + i];
  }
  for(int i = 0; i< n2;i++){
	  R[i] = A[mid + i];
  }
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  int i = 0;
  int j = 0;
  for(int k = left; k < right; k++){
	  cnt++;
    if(L[i] <= R[j]){
		A[k] = L[i];
		i = i + 1;
	} else {
		A[k] = R[j];
		j = j + 1;
	}
  }
}

void Merge_Sort(int* A, int left, int right){
  if(left+1 < right){
    int mid = (left + right)/2;
    Merge_Sort(A, left, mid);
    Merge_Sort(A, mid, right);
    Merge(A, left, mid, right);
  }
}
		 
int main(){
	int *a;
	int n;
	cnt = 0;
	scanf("%d",&n);
	a = new int[n];
	for(int i=0;i<n;i++){
		scanf(" %d",&a[i]);
	}
	Merge_Sort(a, 0, n);
	for(int i=0;i<n-1;i++){
		printf("%d ", a[i]);
	}
	printf("%d\n%d\n",a[n-1],cnt);
	return 0;
}

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

int main(void){

    int N, M, X;

    scanf("%d%d%d", &N, &M, &X);

    int A[M];

    for(int i = 0; i < M; i++){
        scanf("%d", &A[i]);
    }

    int l = 0;

    for(int i = 0; i < M; i++){
        if(A[i] < X){
            l++;
        }else{
            break;
        }
    }

    int r = M - l;

    if(l < r){
        printf("%d\n", l);
    }else{
        printf("%d\n", r);
    }

    return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <string>

int main() {
	int D, N;
	std::cin >> D >> N;
	if (N == 100) {
		std::cout << 101;
	} else {
		std::cout << N;
	}
	for (int i = 0; i < D; i++) {
		std::cout << "00";
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto n = readln.chomp.to!int;
	int[2] ans;
	ans[0] = 101;
	ans[1] = -1;
	while (n--) {
		auto x = readln.split.map!(to!int);

		if (ans[1] < x[1]) {
			ans = x.array;
		} else if (ans[1] == x[1] && ans[0] > x[0]) {
			ans = x.array;
		}
	}
	writeln(ans[0], " ", ans[1]);
}

Measured memory_bytes: 1064
import sys


def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))

    count1 = 0
    count2 = 0

    for i in range(N - 1):
        for j in range(i + 1, N):
            if A[i] > A[j]:
                count1 = count1 + 1
            if A[i] != A[j]:
                count2 = count2 + 1
    count1 = count1 * K
    count2 = count2 * (K * (K - 1) // 2)

    ans = (count1 + count2) % 1000000007
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((ll)2e5+5)
#define MOD ((ll)1e9 + 7)
#define INF ((ll)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<ll,ll>
#define mid ((l+r)/2)

ll n,a,b;

ll fast(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
		{
			res*=a;
			res%=MOD;
		}
		b>>=1LL;
		a*=a;
		a%=MOD;
	}
	return res;
}

ll modInverse(ll a)
{
	ll m = MOD;
	ll y = 0, x = 1;
	if (m == 1)
		return 0;
	while (a > 1)
	{
		ll q = a / m;
		ll t = m;
		m = a % m, a = t;
		t = y;
		y = x - q * y;
		x = t;
	}
	if (x < 0)
		x += MOD;
	return x;
}

ll C(ll a, ll b)
{
	ll res = 1;

	for (int i = 0; i < b; ++i)
		res = ((res) * (a-i)) % MOD;

	for (int i = 2; i <= b; ++i)
		res = (res * modInverse(i)) % MOD;

	return (res + MOD) % MOD;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n >> a >> b;

	cout << (fast(2,n)-1- C(n,a) - C(n,b) + MOD + MOD) % MOD << endl;
}

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

t_score = 0
h_score = 0


for i in range(n):
 t, h = input().split()
 if t == h:
  t_score += 1
  h_score += 1
  continue
 if len(t) >= len(h):
  for j in range(len(h)):
   if ord(t[j]) > ord(h[j]):
    t_score += 3
    break
   elif ord(t[j]) < ord(h[j]):
    h_score += 3
    break
  else:
   t_score += 3
 elif len(t) < len(h):
   for j in range(len(t)):
    if ord(t[j]) > ord(h[j]):
     t_score += 3
     break
    elif ord(t[j]) < ord(h[j]):
     h_score += 3
     break
   else:
    h_score += 3

   
print("{0} {1}".format(t_score, h_score))

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

typedef long long ll;

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

    vector<int> cnt(M+1, 0);
    for(int i=0; i<N; i++){
        int K;
        cin>> K;
        for(int j=0; j<K; j++){
            int A;
            cin>>A;
            cnt[A]++;
        }
    }

    int all_cnt = 0;
    for(int i=1; i<=M; i++){
        if(cnt[i]==N){
            all_cnt++;
        }
    }

    cout<< all_cnt <<endl;
    return 0;
}

Measured memory_bytes: 3612
N = int(input())
X = input()

def calc(S, L):
    cnt = 0
    for i in range(L):
        if S[i] == "1":
            cnt += 1

    a_1 = 1
    r_1 = [0] * (L+1)
    for i in reversed(range(L)):
        r_1[i] = (r_1[i+1] + int(S[i]) * a_1) % cnt
        a_1 = (a_1 * 2) % cnt

    return r_1[0]

def calc_first(S, L):
    cnt = 0
    for i in range(L):
        if S[i] == "1":
            cnt += 1

    a_1 = 1
    a_2 = 1
    r_1 = [0] * (L+1)
    r_2 = [0] * (L+1)
    for i in reversed(range(L)):
        r_1[i] = (r_1[i+1] + int(S[i]) * a_1) % (cnt+1)
        if cnt-1 > 0:
            r_2[i] = (r_2[i+1] + int(S[i]) * a_2) % (cnt-1)

        a_1 = (a_1 * 2) % (cnt + 1)
        if cnt-1 > 0:
            a_2 = (a_2 * 2) % (cnt - 1)

    for i in range(L):
        if S[i] == "0":
            ans = (r_1[0] - r_1[i] + r_1[i+1] + pow(2, N-i-1, (cnt+1))) % (cnt+1)
        else:
            if cnt == 1:
                print(0)
                continue
            else:
                ans = (r_2[0] - r_2[i] + r_2[i+1]) % (cnt-1)

        cnt_ans = 1
        while ans > 0:
            ans = calc(str(bin(ans))[2:], len(str(bin(ans))[2:]))
            cnt_ans += 1
        print(cnt_ans)

calc_first(X, N)


Measured memory_bytes: 91348
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import numpy as np

def dfs1(v, G, Siz):
    siz = 1
    for u in G[v]:
        G[u].remove(v)
        siz += dfs1(u, G, Siz)
    Siz[v] = siz
    return siz

def dfs(v, N, C, G, Cnt, Siz, Ans):
    color = C[v]
    cnt_old = Cnt[color]
    siz = 1
    siz_up = N
    for u in G[v]:
        Cnt[color] = N - Siz[u]  # 上を塞ぐ
        s = dfs(u, N, C, G, Cnt, Siz, Ans)
        siz += s
        siz_up -= s
        Ans[color] += s * (siz_up - cnt_old)
    Ans[color] += siz_up - cnt_old
    Cnt[color] = cnt_old + siz
    return siz

def solve(N, C, AB):
    G = [[0]*0 for _ in range(N)]
    for i in range(N-1):
        a, b = AB[i]
        G[a].append(b)
        G[b].append(a)
    Cnt = np.zeros(N, dtype=np.int64)
    Ans = np.zeros(N, dtype=np.int64)
    Siz = np.zeros(N, dtype=np.int64)
    dfs1(0, G, Siz)
    dfs(0, N, C, G, Cnt, Siz, Ans)
    return Ans

numba_compile([
    [dfs1, "i8(i8,List(List(i8)),i8[:])"],
    [dfs, "i8(i8,i8,i8[:],List(List(i8)),i8[:],i8[:],i8[:])"],
    [solve, "i8[:](i8,i8[:],i8[:,:])"],
])

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = np.array(input().split(), dtype=np.int64) - 1
AB = np.array([list(map(int, input().split())) for _ in range(N-1)], dtype=np.int64) - 1
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans)))


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

int main()
{
    int H, A;
    cin>>H>>A;
    int ans = (H+A-1)/A;
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
n, k = gets.split(' ').map(&:to_i)
s = gets.chomp

data = []
s.each_char do |c|
  if c == '0'
    if data.empty? or data[-1] > 0
      data.push(-1)
    else
      data[-1] -= 1
    end
  else
    if data.empty? or data[-1] < 0
      data.push(1)
    else
      data[-1] += 1
    end
  end
end

i = data[0] < 0 ? 1 : 0
m = data.length/2 + i
if k >= m
  puts n
else
  data.map!(&:abs)
  j = 0
  l = k*2 + 1 - i
  sum = data[j, l].inject(:+)
  max = sum
  while l < data.length
    unless i == 1 and j == 0
      sum -= data[j]
      j += 1
    end
    sum -= data[j]
    j += 1
    sum += data[l,2].inject(:+)
    l += 2
    max = sum if sum > max
  end
  puts max
end


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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

int N;
int X[111111];
int A[111111];
int nex[70][111111];

int M,K;

signed main(){
    cin>>N;
    rep(i,N)cin>>X[i];
    cin>>M>>K;
    rep(i,M)cin>>A[i],A[i]--;
    rep(i,N-1)nex[0][i]=i;
    rep(i,M)swap(nex[0][A[i]-1],nex[0][A[i]]);

    for(int i=0;i<70-1;i++){
        for(int j=0;j<N-1;j++){
            nex[i+1][j]=nex[i][nex[i][j]];
        }
    }

    cout<<X[0]<<endl;
    int x=X[0];
    for(int i=0;i<N-1;i++){
        int v=i;
        rep(j,60)if(K>>j&1)v=nex[j][v];
        x+=X[v+1]-X[v];
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 63360
#include <iostream>
 
using namespace std;
 
long long a[26], sol;
string s;
 
long long pov2(long long x){
  if (x == 0)
    return 0;
  return ( (long long)x * (long long)(x+1)) / 2;
}
 
int main(){
  cin >> s;
 
  for (int i = 0; i < s.length(); i++){
    a[s[i] - 'a']++;
  }
  sol = ((long long)s.length() * (long long)(s.length() + 1)) / 2;
 
  for (int i = 0; i < 26; i++){
    sol -= pov2(a[i]);
  }
 
  cout << sol + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    for(int i = k; i > 0; i--) {
        if(a >= b) {
            b *= 2;
            continue;
        }
        if(b >= c) {
            c *= 2;
            continue;
        }
    }

    if(a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int main(){
  int a;
  cin>>a;
  int price[a];
  for(int i=0;i<a;i++)cin>>price[i];
  double num=0;
  sort(price,price+a);
  num=(price[0]+price[1])/2.000000;
  for(int i=2;i<a;i++){
    num=(num+price[i])/2.0000000;
  }
  cout<<num<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n)
	{
		int sum = 0;
		for(int i = n; i < 600; i += n)
		{
			sum += i * i * n;
		}
		cout << sum << endl;
	}
}

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

Measured memory_bytes: 0
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][][] menber = new int[4][3][10];
        
        for(int i = 1 ; i <= n ; i++){
            int b = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int v = sc.nextInt();
            menber[b-1][f-1][r-1] += v;
        }
        
        for(int i = 1 ; i <= 4 ; i++){
            for(int j = 1 ; j <= 3 ; j++){
                for(int k = 1 ; k <= 10 ; k++){
                    System.out.print(" " + menber[i-1][j-1][k-1]);
                }
                System.out.println();
            }
            if(i != 4){
                System.out.println("####################");
            }
        }
    }
}


Measured memory_bytes: 30024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<typename T> 
struct BIT{
  int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(int n_,T d):n(n_),bit(n_+1,d){}
  
  T sum(int i){
    T s=0;
    for(int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(int i,T a){
    if(i==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
  
  int lower_bound(int w){
    if(w<=0) return 0;
    int x=0,r=1;
    while(r<n) r<<=1;
    for(int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
	w-=bit[x+k];
	x+=k;
      }
    }
    return x+1;
  }
  
  T sum0(int i){
    return sum(i+1);
  }
  void add0(int i,T a){
    add(i+1,a);
  }
};
//END CUT HERE

signed main(){
  int n,q;
  cin>>n>>q;
  BIT<int> bit(n+100,0);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<bit.sum(y)-bit.sum(x-1)<<endl;
    else bit.add(x,y);
  }
  return 0;
}
/*
verified on 2017/10/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B&lang=jp
 */

Measured memory_bytes: 3048
/*"Nothing is true."*/
#include<bits/stdc++.h>
using namespace std;
inline int min(int _a, int _b) {return _a < _b ? _a : _b;}
inline int max(int _a, int _b) {return _a > _b ? _a : _b;}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

template <class _T> inline void rd(_T &_a) {
	int _f=0,_ch=getchar();_a=0;
	while(_ch<'0' || _ch>'9'){if(_ch=='-')_f=1;_ch=getchar();}
	while(_ch>='0' && _ch<='9')_a=(_a<<1)+(_a<<3)+_ch-'0',_ch=getchar();
	if(_f)_a=-_a;
}

long long n, sum, ans, t[20], ct;

int main() {
	//freopen("CW7_A.in","r",stdin);
	//freopen("CW7_A.out","w",stdout);
	rd(n); sum = n; t[0] = 1;
	for(int i = 1;i <= 16; ++i) t[i] = t[i - 1] * 10;
	while(n >= 10) n /= 10, ++ct;
	if(sum == (n + 1) * t[ct] - 1) ans = ct * 9 + n;
	else ans = ct * 9 + n - 1;
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
#include <queue>
using namespace std;

#define ll long long
#define ld long double
#define pi 3.14159265359;
// %llu %lf

// v:vector  type:型  order:greater(大きい順) or less(小さい順)
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 特定コンテナの中から特定の値をカウントする
#define _count(v,value) count(v.begin(),v.end(),value)

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//                                                              member.emplace(2)とかも同じ
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
template<typename T>
static T _abs(const T x) { return  (x > 0 ? x : -x); }

// 最大公約数
int64_t gcd(int64_t a, int64_t b) { while (b) { int64_t c = b; b = a % b; a = c; } return a; }
// 最小公倍数
int64_t lcm(int64_t a, int64_t b) { if (!a || !b) return 0; return a * b / gcd(a, b); }

// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

// ■
// UINT32_MAX
// 4294967295 ≒ 4 * 1e9

// ■
// 割り算した結果との比較での丸め対処時 
// ABC 161 B
// https://atcoder.jp/contests/abc161/tasks/abc161_b
// double   border = _sum(v, 0 / (double)(4 * m);
//            ↓
// uint32_t border = (_sum(v, 0) + (4 * m) - 1) / (4 * m);

// ■
// N の数が与えられた場合の組合せ N * (N - 1) / 2


/*
*/
// ABC 157 A
// https://atcoder.jp/contests/abc157/tasks/abc157_a
int main()
{
	uint32_t n;
	cin >> n;

	printf("%d\n", (n+1)/2);
	return 0;
}

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

using namespace std;

#define ll long long




void solve() {

	int n;
	cin >> n;
	int k = n - n / 2;
	cout << k / (double)n;

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3800
process.stdin.resume();
process.stdin.setEncoding('utf8');

var input_string = "";
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  input_string = line;
});
reader.on('close', () => {
  const str = input_string.toString();
  const delimiter = /\s/;
  const array = str.split(delimiter);
  const a = Number(array[0]);
  const b = Number(array[1]);
  const area = a*b;
  const length = (a + b) * 2;
  console.log(area,length);
});



Measured memory_bytes: 16252
#include <iostream>

using namespace std;

int gcd(int m, int n){
	if(m < n){ return gcd(n, m); }
	if(n == 0){ return m; }
	if(m % n == 0){ return n; }
	return gcd(n, m % n);
}

int main(){
	int a, b;
	while(cin >> a >> b){
		cout << gcd(a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;

		try {
			scanner = new Scanner(System.in);

			System.out.println((scanner.nextInt() - scanner.nextInt()) + 1);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numH = 0;
		int numW = 0;

		try {
			scanner = new Scanner(System.in);
			numH = scanner.nextInt();
			numW = scanner.nextInt();

			char[][] wk = new char[numH][numW];

			char[] def = new char[numW];
			for (int i = 0; i < numW; i++) {
				def[i] = '@';
			}

			int index = Integer.MAX_VALUE;
			for (int i = 0; i < numH; i++) {
				String wkS = scanner.next();
				if (wkS.indexOf('#') < 0) {
					wk[i] = def;
				} else {
					index = Math.min(i, index);
					wk[i] = wkS.toCharArray();
				}
			}
			char[] wk1 = wk[index];
			for (int i = 0; i < numW; i++) {
				if (wk1[i] == '.') {
					int count = 0;
					for (int j = 0; j < numH; j++) {
						if (wk[j][i] == '.' || wk[j][i] == '@') {
							count++;
						}
					}
					if (count == numH) {
						for (int j = 0; j < numH; j++) {
							wk[j][i] = '@';
						}
					}
				}
			}
			for (int i = 0; i < numH; i++) {
				StringBuilder builder = new StringBuilder();
				for (int j = 0; j < numW; j++) {
					if (wk[i][j] != '@') {
						builder.append(wk[i][j]);
					}
				}
				if (builder.length() != 0) {
					System.out.println(builder.toString());
				}
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	/**
	 * Cは、とりあえず|r|に移動して|r|+|r+numK|-|r|
	 * を右と左から実施する。
	 * |  1---N  | 0 |  1---N  |
	 * というように、0より大きい場合も0より小さい場合もあるので。
	 */
	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numK = scanner.nextInt();

			if (numK == 1) {
				System.out.println(0);
				return;
			}
			int[] wk = new int[numN];
			for (int i = 0; i < numN; i++) {
				wk[i] = scanner.nextInt();
			}

			int plusNumK = numK - 1;
			int res = Integer.MAX_VALUE;
			for (int i = 0; i < wk.length - plusNumK; i++) {
				res = Math.min(res, Math.abs(wk[i]) + Math.abs(wk[i] - wk[i + plusNumK]));
			}

			for (int i = wk.length - 1; i >= plusNumK; i--) {
				res = Math.min(res, Math.abs(wk[i]) + Math.abs(wk[i] - wk[i - plusNumK]));
			}
			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 49648
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

void solve(){
  int n, m; cin >> n >> m;
  vector<int> a(n);
  map<long long, long long> mp;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    mp[a[i]]++;
  }
  for(int i = 0; i < m; i++){
    auto it = --mp.end();
    long long a = it->first, b = it->second;
    //cout << a << " -> " << b << endl;
    mp[a / 2]++;
    mp[a]--;
    if(mp[a] == 0) mp.erase(it);
    if(mp.size() == 0) break;
  }
  long long ans = 0;
  for(auto it = mp.begin(); it != mp.end(); it++){
    //cout << it->first << " -> " << it->second << endl;
    ans += it->first * it->second;
  }
  cout << ans << endl;

  return;
}

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


Measured memory_bytes: 6912
import numpy as np

S = input()
l = [int(s) for s in S]
t1 = [i % 2 for i in range(len(S))]
t2 = [(i+1) % 2 for i in range(len(S))]
l, t1, t2 = np.array(l), np.array(t1), np.array(t2)

d1 = ((t1 - l)**2).sum()
d2 = ((t2 - l)**2).sum()

print(int(min(d1, d2)))

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, d;
    cin >> n >> d;
    vector<Int> x(n), y(n);
    for (Int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    Int res = 0;
    for (Int i = 0; i < n; i++) {
        if (x[i] * x[i] + y[i] * y[i] <= d * d) {
            res++;
        }
    }
    print(res);
    return 0;
}


Measured memory_bytes: 6336
#include <bits/stdc++.h> 
using namespace std;
int n,k,ans,p;
int GuiLv[12][6]= {
	{4,2,0,9,7},
	{1,10,8,6,4},
	{9,7,5,3,1},
	{6,4,2,0,9},
	{3,1,10,8,6},
	{0,9,7,5,3},
	{8,6,4,2,0},
	{5,3,1,10,8},
	{2,0,9,7,5},
	{10,8,6,4,2},
	{7,5,3,1,10}
};//找出来的规律 ，7列14行的3*3矩阵相加得出来的一个二维答案数组 
int main() {
	scanf("%d%d",&n,&k);
	ans=((n-2)/11)*5;
	if(n<=2)//因为前两行是单独的 
		for(int i=0; i<p; i++)
			for(int j=0; j<5; j++) {
				if(GuiLv[i][j]==k)
					ans++;
			}//相等就++ 
	else//而后几行是是每12行就有规律的 
		for(int i=0; i<(n-2)%11; i++)//可能会很大得取模 
			for(int j=0; j<5; j++)
				if(GuiLv[i][j]==k)
					ans++;//相等就++ 
	printf("%d\n",ans);//输出答案 
	return 0;//功德圆满 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};

const int MAX = 5000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll s; cin >> s;
    ll num = 0;
    ll ans = 0;
    while (s>=3) {
        num++;
        s -=3;
        ans += COM(num+s-1,s);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3756
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
int main() {

  int N;
  cin>>N;
  int count=0;
  int numa;
  int numb;
  for(int i=1;i<=N;i++){
  
    cin>>numa;
    cin>>numb;
    if(numa==numb)count++;
    else count=0;
    if(count>=3){
    
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
  return 0;
}

Measured memory_bytes: 3592
import math
from functools import reduce


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


k = int(input())
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for k in range(1, k + 1):
            s += gcd_list([i, j, k])
print(s)


Measured memory_bytes: 75160
#include<bits/stdc++.h>
using namespace std;
//int a[1001],b[1001]={100001};
//void dfs(int s)
//{
//	if(s>n)
//	{
//		ans++;
//		for(int i=1;i<=n;i++)cout<<b[i]<<" ";
//		cout<<endl;
//		return;
//	}
//	for(int i=0;i<x;i++)
//	{
//		if(a[s]==0&&b[s-1]!=i)
//		{
//			a[s]=1;
//			b[s]=i;
//			dfs(s+1);
//			a[s]=0;
//		}
//	}
//}
long long a,b,c;
int main()
{



    cin>>a>>b;
    c=b*pow(b-1,a-1);
    cout<<c<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;
struct color
{
    int x,y,no;
}s[100000];
int n,k,ans,sum;
int v[2000];
int main()
{
    char ch;
    scanf("%d%d",&n,&k);///每个区域都是k*k个格子一个颜色 要么黑要么白相邻区域异色 对角区域同色
    for(int i = 0;i < n;i ++)
    {
        scanf("%d %d %c",&s[i].x,&s[i].y,&ch);
        s[i].x %= k * 2;///通过移位（每次移动2k）都可以在这个2k*2k的图里进行操作 不改变原来的意义 也就是当前坐标和原坐标涂的颜色肯定是相同的
        s[i].y %= k * 2;
        s[i].no = (ch == 'W' ? 1 : 0);///颜色转为数字
    }
    for(int i = 0;i < k;i ++)///y轴移动 x坐标边界改变
    {
        sum = 0;
        memset(v,0,sizeof(v));///初始化
        for(int j = 0;j < n;j ++)
        {
            int p = s[j].x >= i && s[j].x < i + k;///x坐标在i 到 i + k为一个区域
            int q = s[j].y >= 0 && s[j].y < k;///y坐标先不改变 默认 0 到 k - 1
            if(p ^ q ^ s[j].no)sum ++,v[s[j].y] ++;///先选定一种情况 满足的话 sum ++  y坐标对应对应的 v ++
            else v[s[j].y] --;///不满足的话 就是不满足 0 到 k - 1 的划分 在v中对应y坐标位置进行标记
        }
        for(int j = 0;j < k;j ++)
        {
            sum -= v[j] + v[j + k];///y坐标在 j 到j + k 区域  去掉
            ans = max(ans,max(sum,n - sum));///更新最大值，sum 和 n - sum 是黑白互换的不同结果（原来黑色的地方可以变白色，那么白色的变黑色）
        }
    }
    printf("%d",ans);
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int h,w,c;

int calc(int map[8][8], int c[6]){
    bool isConnedted[8][8];
    fill(isConnedted[0],isConnedted[8],false);
    typedef pair<int,int> P;
    queue<P> que;
    int d[5]={-1,0,1,0,-1};
    int num;
    for(int k=0;k<6;k++){
        que.emplace(0,0);
        isConnedted[0][0]=true;
        while(!que.empty()){
            P p = que.front(); que.pop();
            for(int i=0;i<4;i++){
                int y=p.first+d[i];
                int x=p.second+d[i+1];
                if(x<0||w<=x) continue;
                if(y<0||h<=y) continue;
                if(map[y][x]==map[p.first][p.second]&&!isConnedted[y][x]){
                    isConnedted[y][x]=true;
                    que.emplace(y,x);
                }
            }
        }
        num=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(isConnedted[i][j]){
                    isConnedted[i][j]=false;
                    num++;
                    map[i][j]=c[k];
                }
            }
        }        
    }
    return num;
}

int main(){
    int p[8][8];
    while(cin>>h>>w>>c,h){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>p[i][j];
            }
        }
        int ans=0;
        int C[6];
        C[4]=C[5]=c;
        for(C[0]=1;C[0]<=6;C[0]++){
            for(C[1]=1;C[1]<=6;C[1]++){
                for(C[2]=1;C[2]<=6;C[2]++){
                    for(C[3]=1;C[3]<=6;C[3]++){
                        int temp[8][8];
                        for(int i=0;i<h;i++){
                            for(int j=0;j<w;j++){
                                temp[i][j]=p[i][j];
                            }
                        }
                        ans=max(ans,calc(temp,C));
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3084
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int n;
  char c;
  cin >> c;
  vector<int> v(n + 10);
  if (c >= 'a' && c <= 'z') {
    cout << "a" << endl;
  } else {
    cout << "A" << endl;
  }
}

Measured memory_bytes: 3592
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

struct node{
    ll parent;
    ll black;
    ll white;
    ll dist;
    bool col;
};

vector<node> uft;

pll parent(ll a){
    if(uft[a].parent==a){return {a,0};}
    pll ret=parent(uft[a].parent);
    uft[a].dist+=ret.S;
    uft[a].parent=ret.F;
    ret.S=uft[a].dist;
    return {uft[a].parent,uft[a].dist};
}

void merge(ll a,ll b){
    pll A=parent(a),B=parent(b);
    if(A.F==B.F){
        if(((A.S+B.S)&1)==0){uft[A.F].col=false;}
    }
    else{
        if((A.S+B.S)&1){
            uft[A.F].white+=uft[B.F].white;
            uft[A.F].black+=uft[B.F].black;
            uft[A.F].col&=uft[B.F].col;
            uft[B.F].dist=0;
            uft[B.F].parent=A.F;
        }
        else{
            uft[A.F].white+=uft[B.F].black;
            uft[A.F].black+=uft[B.F].white;
            uft[A.F].col&=uft[B.F].col;
            uft[B.F].dist=1;
            uft[B.F].parent=A.F;
        }
    }
}


int main(){
    ll n,m;
    cin>>n>>m;
    uft.resize(n);
    for(int i=0;i<n;i++){
        uft[i].white=1;
        uft[i].black=0;
        uft[i].dist=0;
        uft[i].parent=i;
        uft[i].col=true;
    }
    for(int i=0;i<m;i++){
        ll u,v;
        cin>>u>>v;
        u--; v--;
        merge(u,v);
    }
    set<ll> S;
    ll one=0;
    ll dbl=0;
    ll tri=0;
    ll ans=0;
    for(int i=0;i<n;i++){
        pll ret=parent(i);
        if(S.count(ret.F)==0){
            S.insert(ret.F);
            //cout<<ret.F<<" ";
            if(uft[ret.F].white+uft[ret.F].black==1){
                //cout<<"one"<<endl;
                ans+=n;
                one++;
            }
            else if(uft[ret.F].col){
                //cout<<"dbl"<<endl;
                dbl++;
            }
            else{
                //cout<<"tri"<<endl;
                tri++;
            }
        }
    }
    S.clear();
    //cout<<one<<" "<<dbl<<" "<<tri<<endl;
    for(int i=0;i<n;i++){
        pll ret=parent(i);
        if(S.count(ret.F)==0){
            S.insert(ret.F);
            if(uft[ret.F].white+uft[ret.F].black==1){
                ans+=(n-one);
            }
            else if(uft[ret.F].col){
                ans+=dbl*2;
                ans+=tri;
            }
            else{
                ans+=(dbl+tri);
            }
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 8832
n, l = map(int, input().split())
ans = 0
if l > 0:
    for i in range(l+1, l+n):
        ans += i
elif l+n-1 >= 0:
    for i in range(l, l+n):
        ans += i
else:
    for i in range(l, l+n-1):
        ans += i
print(ans)


Measured memory_bytes: 38408
def S(n):
    return sum(int(x) for x in str(n))
rest = K = int(input())

ans = list(range(1, 10))

rest -= 9
suffix = 10
i = 0
while rest > 0:
    num = int(str(suffix) + '9' * i)
    if suffix % 10 == 0:
        while suffix % 10 == 0:
            next_suffix = suffix + 9
            next_num = int(str(next_suffix) + '9' * i)
            if num / S(num) > next_num / S(next_num):
                i += 1
                suffix //= 10
            else:
                break
        num = int(str(suffix) + '9' * i)
    ans.append(num)
    rest -= 1
    suffix += 1

for i in range(K):
    print(ans[i])


Measured memory_bytes: 3188
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        int n = c.length;
        
        if (c[n-1] == 's') {
            str += "es";
        } else {
            str += "s";
        }
        System.out.println(str);
    }
}


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

int main() {
    int N, T, A; 
    cin >> N >> T >> A;
    double minimum = 1000; // 十分大きな値
    double temp;
    int index; // minimum のときのindexの値
    int foo; // 一時的に入力を受け取る

    for (int i = 0; i < N; i++) {
        cin >> foo;
        temp = (double)T - (double)foo*0.006;
        if (abs(temp - A) < minimum) {
            minimum = abs(temp - A);
            index = i+1; // 1スタートの補正
        }
    }

    cout << index << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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++)

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    cout << "A" << b[0] << "C" << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>

int prime[1234568];

int main(void){
  int n,i,j,count;

  prime[0]=1;
  prime[1]=0;
  for(i=2;i<1234568;i++)
    prime[i]=0;

  for(i=2;i*i<1234568;i++){
    if(prime[i]==0){
      for(j=i*2;j<1234568;j+=i)
	prime[j]=1;
    }
  }

  while(1){
    count=0;
    scanf("%d",&n);
    if(n==0)break;
    for(i=n+1;i<=2*n;i++)
      if(prime[i]==0)count++;

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

Measured memory_bytes: 0