akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll x, y;
	cin >> x >> y;
	ll unko = INF;
	if (x <= y) unko = min(unko, y - x);
	if (-x <= y) unko = min(unko, x + y + 1);
	if (x <= -y) unko = min(unko, -x - y + 1);
	if (-x <= -y) unko = min(unko, x - y + 2);
	cout << unko;
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;



int main() {
  ll s;
  cin >> s;
  ll u=1000000000;
  ll a=s/u+1;
  if (s%u==0) a=s/u;
  cout << 0 << " " << 0 << " " << u << " " << 1 << " " << u*a-s << " " << a << endl;
  }

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll a,b,h;cin>>a>>b>>h;
  cout<<(a+b)*h/2.0<<endl;
  

  return 0;
}

Measured memory_bytes: 256
// in the name of Allah

#include <bits/stdc++.h>

#define endl '\n'
#define ll long long
#define pb push_back
#define ld double
#define sz(x) ((int) (x.size()))

#define max_n 5123456
#define mod 1000000007
// #define mod 998244353
#define myPrime 97654321

#define fr first
#define se second

using namespace std;

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll x, ll y) {
	if(y == 0) return 1;
	ll foo = power(x, y/2);
	foo = mul(foo, foo);
	if(y&1) return mul(x, foo);
	return foo;
}

int x[123456];
int y[123456];
vector <int> g[123456];

string get(int n) {
    string s = "";
    for(int i=0; i<6; i++) {
        s += ((char) ('0' + n%10));
        n/=10;
    }
    reverse(s.begin(), s.end());
    return s;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	for(int i=0; i<m; i++) {
	    cin >> x[i] >> y[i];
	    g[x[i]].pb(y[i]);
	}
	for(int i=0; i<123456; i++) sort(g[i].begin(), g[i].end());
	for(int i=0; i<m; i++) {
	    int pos = lower_bound(g[x[i]].begin(), g[x[i]].end(), y[i]) - g[x[i]].begin();
	    cout << get(x[i]) << get(pos+1) << endl;
	}
	return 0;
}

Measured memory_bytes: 8448
#include <stdio.h>
#include <stdlib.h>

typedef long long int lli;

void pushBack(lli** pplliData, int* piRecordCnt);
void dump(lli** pplliData, int* piRecordCnt);
void clear(int* piRecordCnt);

// n個の可変長配列Ai(i=0,1,...,n-1)に対して以下の操作を行う。
// ・pushBack(t, x): Atの末尾に整数xを挿入する。
// ・dump(t): Atの全ての要素を出力する。
// ・clear(t): Atを空にする。ただし、Atが空の場合は何もしない。
// 操作は数字で与えられ、上から0,1,2で指定される。
int main()
{
	lli** pplliData;	//	全配列データ
	int iInputN, iInputQ;
	int iInputOrder;	// 命令番号
	int* piRecordCnt;	// 各配列の要素数
	int iCnt;

	scanf("%d %d", &iInputN, &iInputQ);

	// iInputN個のポインタ配列をメモリ確保
	pplliData = (lli**)malloc(sizeof(lli*) * iInputN);

	// それぞれのポインタ配列がiInputQ個分のメモリ確保
	for (iCnt = 0; iCnt < iInputN; iCnt++)
	{
		pplliData[iCnt] = (lli*)malloc(sizeof(lli) * iInputQ);
	}

	// メモリ確保し0初期化
	piRecordCnt = (int*)calloc(iInputN, sizeof(int));

	// 処理入力
	for (iCnt = 0; iCnt < iInputQ; iCnt++)
	{
		scanf("%d", &iInputOrder);

		switch (iInputOrder)
		{
		case 0:
			pushBack(pplliData, piRecordCnt);
			break;
		case 1:
			dump(pplliData, piRecordCnt);
			break;
		case 2:
			clear(piRecordCnt);
			break;
		default:
			break;
		}
	}

	// メモリ解放
	for (iCnt = 0; iCnt < iInputN; iCnt++)
	{
		free(pplliData[iCnt]);
	}
	free(pplliData);
	free(piRecordCnt);


	return 0;
}

// iInputT番目の配列の末尾に要素を挿入
void pushBack(lli** pplliData, int* piRecordCnt)
{
	int iInputT;
	
	scanf("%d", &iInputT);

	scanf("%lld", &(pplliData[iInputT][piRecordCnt[iInputT]]));
	(piRecordCnt[iInputT])++;

	return;
}

// iInputT番目の配列の要素を全て表示
void dump(lli** pplliData, int* piRecordCnt)
{
	int iInputT;
	int iCnt;

	scanf("%d", &iInputT);

	for (iCnt = 0; iCnt < piRecordCnt[iInputT]; iCnt++)
	{
		// 末尾は後ろに空白なし
		if (iCnt != piRecordCnt[iInputT] - 1)
		{
			printf("%lld ", pplliData[iInputT][iCnt]);
		}
		else
		{
			printf("%lld", pplliData[iInputT][iCnt]);
		}
	}

	printf("\n");

	return;
}

// iInputT番目の配列を空にする
void clear(int* piRecordCnt)
{
	int iInputT;
	scanf("%d", &iInputT);

	// 配列の要素数を0にすることで疑似的に要素クリア
	(piRecordCnt[iInputT]) = 0;

	return;
}


Measured memory_bytes: 9472
s = input()
lis = ["A", "G", "C", "T"]
count = 0
ans = 0

for i in range(len(s)):
    for j in range(i, len(s)):
        if s[j] in lis:
            count += 1
        else:
            break
    ans = max(ans, count)
    count = 0

print(ans)

Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int A, B;

signed main(){
	cin >> A >> B;
	cout << max(0, A-2*B) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int n, a[100], ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		if ((i+1) % 2 == 1 && a[i] % 2 == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3628
// 7/4
#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 N, K;
    cin >> N >> K;
    vector<int> V(N);
    rep(i, N) cin >> V[i];

    int res = 0;

    vector<int> MV;

    for (int A = 0; A <= N; A++) {
        for (int B = 0; B <= N - A; B++) {
            int now = 0;

            int T = K - A - B;  // Through / 捨てる
            if (T < 0) continue;
            
            MV.clear();
            rep(i, A) {
                now += V[i];
                if (V[i] < 0) MV.push_back(V[i]);
            }
            rep(i, B) {
                now += V[N-1-i];
                if (V[N-1-i] < 0) MV.push_back(V[N-1-i]);
            }
            sort(MV.begin(), MV.end());

            int t = min(T, (int)MV.size());
            rep(i, t) now -= MV[i];

            res = max(res, now);
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  string a,s,c;cin>>a>>s>>c;
  cout<<a[0]<<s[0]<<c[0]<<endl;
  return 0;
}


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

int main(void){
    int i, j, n, k;
    double res, sum = 0, total = 0;
    scanf("%d %d", &n, &k);
    
    for( i = 1; i < n+1; i++ ){
        sum = 1;
        res = i;
        for( j = 0; res < k ; j++ ){
            sum *= 0.5;
            res *= 2;
        }
        
        total += sum/n;
    }
    
    printf("%.10lf\n", total);
    return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int ss = 0;
    for (auto &x: s) ss += x & 1;
    long long cnt[n], sum[n], ans[n];
    vector<int> e[n];
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        e[a].emplace_back(b);
        e[b].emplace_back(a);
    }
    auto dfs = [&e, &cnt, &sum, &ans, &s](auto f, int curr, int prev) -> void {
        cnt[curr] = 0, sum[curr] = 0, ans[curr] = 0;
        long long sumi = 0, maxi = 0;
        for (auto &to: e[curr]) {
            if (to == prev) continue;
            f(f, to, curr);
            cnt[curr] += cnt[to];
            ans[curr] += ans[to];
            sumi += cnt[to]+sum[to];
            maxi = max(maxi, cnt[to]+sum[to]);
        }
        if (prev != -1) {
            if (maxi * 2 <= sumi) {
                ans[curr] += sumi / 2;
                sum[curr] = sumi - (sumi / 2) * 2;
            } else {
                ans[curr] += sumi - maxi;
                sum[curr] = sumi - (sumi - maxi) * 2;
            }
        } else {
            int j;
            for (auto &to: e[curr]) {
                if (maxi == cnt[to]+sum[to]) {
                    j == to; break;
                }
            }
            long long sums = 0;
            for (auto &to: e[curr]) {
                long long d = min(ans[to], (maxi-(cnt[to]+sum[to]))/2);
                sums += cnt[to]+sum[to] + d * 2;
                ans[curr] -= d;
            }
            if (maxi * 2 <= sums) {
                ans[curr] += sums / 2;
                sum[curr] = sums % 2;
            } else {
                sum[curr] = -1;
            }
        }
        if (s[curr] & 1) cnt[curr]++;
    };
    long long mini = 1e18;
    for (int i = 0; i < n; i++) {
        dfs(dfs, i, -1);
        assert(cnt[i] == ss);
        if (!sum[i]) mini = min(mini, ans[i]); 
    }
    mini = mini == 1e18 ? -1 : mini;
    cout << mini << "\n";
    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void){
    float time;
	int a = 0,b = 0,c  = 0;
	scanf("%d""%d""%d",&a,&b,&c);
	if(a+b >= c){
		printf("Yes\n");
	}
	else{
	printf("No\n");
	}
	
		return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 300000

int main(){
	int b[N];
	vector<int>a;
	stack<int>q;
	int c[N];
	int n;
	int x, y, z;
	scanf("%d", &n);
	f(i, n){
		scanf("%d", &b[i]);
		b[i]--;
	}
	f(i, n - 1)if (b[i] >= b[i + 1]&&b[i+1]<=250000)a.push_back(b[i + 1]);
	if (a.size() == 0){
		printf("1\n");
		return 0;
	}
	int l = 2;
	int r = 300000;
	int m;
	while (l + 1 < r){
		m = (l + r) / 2;
		m--;
		f(i, N)c[i] = 0;
		while (!q.empty())q.pop();
		f(i, a.size()){
				if (i > 0){
					if (a[i] >= a[i - 1]){
						c[a[i]]++;
						if (a[i] > 0){
							if (c[a[i]] >= m){
								x = a[i];
								while (c[x] >= m){
									c[x - 1] += (c[x] / m);
									c[x] = c[x] % m;
									if (x <= 1)break;
									else x--;
								}
								while (!q.empty()){
									y = q.top();
									if (x < y){
										c[y] = 0;
										q.pop();
									}
									else break;
								}
								q.push(x);
							}
							else q.push(a[i]);
						}
						else q.push(a[i]);
					}
					else{
						while (!q.empty()){
							y = q.top();
							if (a[i] < y){
								c[y] = 0;
								q.pop();
							}
							else break;
						}
						c[a[i]]++;
						if (a[i] > 0){
							if (c[a[i]] >= m){
								x = a[i];
								while (c[x] >= m){
									c[x - 1] += (c[x] / m);
									c[x] = c[x] % m;
									if (x <= 1)break;
									else x--;
								}
								while (!q.empty()){
									y = q.top();
									if (x < y){
										c[y] = 0;
										q.pop();
									}
									else break;
								}
								q.push(x);
							}
							else q.push(a[i]);
						}
						else q.push(a[i]);
					}
				}
				else{
					c[a[i]]++;
					q.push(a[i]);
				}
		}
		if (c[0] < m)r = m + 1;
		else l = m + 1;

	}
	printf("%d\n", l);


	return 0;
}


Measured memory_bytes: 3828
inp = []
n = [int(w) for w in list(input())]
first = []
sec = []
fres = 0
sres = 0


for f in range(len(n)):
    if f % 2 == 1:
        first.append(1)
    else:
        first.append(0)
for f in range(len(n)):
    if f % 2 == 0:
        sec.append(1)
    else:
        sec.append(0)
for x in range(len(n)):
    if n[x] != first[x]:

        fres += 1

for x in range(len(n)):
    if n[x] != sec[x]:

        sres += 1

if sres >= fres:
    print(fres)
else:
    print(sres)

Measured memory_bytes: 5400
n = int(input())
a = [int(input()) for i in range(n)]
ls = [0 for i in range(n)]
for i in range(n):
  x = a[i]
  ls[x-1] = i+1
cnt = 1
ans = 0
ls.append(0)
for i in range(1,n+1):
  if ls[i]>ls[i-1]:
    cnt += 1
  else:
    ans = max(ans,cnt)
    cnt = 1
print(n-ans)

Measured memory_bytes: 18996
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    ret = 0
    for i in range(N):
        ret = max(ret, len(set(S[:i]).intersection(set(S[i:]))))
    print(ret)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;

int getResult(vector<int> nums){
    int n = nums.size();
    int maxx1 = nums[0];
    int maxx2 = nums[n-1];
    int res1 = 0,res2 = 0;
    for(int i = 1 ; i < n ; i ++){
        if(maxx1 < nums[i]){
            res1 ++;
        }
        maxx1 = min(maxx1,nums[i]);
    }
    for(int i = n-2; i >= 0 ; i --){
        if(maxx2 < nums[i]){
            res2 ++;
        }
        maxx2 = min(maxx2,nums[i]);
    }
    return min(res1,res2);
}

signed main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int res = 0;
    for(int i = 1 ; i < s.size(); i ++)
        if(s[i] == s[i-1]){
            res ++;
        }
    res = min(res+2*k,n-1);
    cout<<res<<endl;
}


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

void printStep(int *a, int n){
    for(int j=0; j<n-1; j++){
        cout << a[j] << " ";
    }
    cout << a[n-1] << "\n";
}

void insertionSort(int *a, int n){
    printStep(a, n);
    
    for(int i=1; i<n; i++){
        int v=a[i];
        int j = i-1;
        
        while(j>=0 && a[j]>v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        printStep(a, n);
    }
}

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



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
const int MOD = 1e9+7;
const int N=3e5+5;
Int n,cnt[70],x[N],ans;

signed main(){
    cin >> n;
    for(Int i=0;i<n;i++) cin >> x[i];
    for(Int i=n-1;i>=0;i--){
        Int ji = 0;
        while(ji<=61){
           if(x[i]%2==1) cnt[ji]++;
           ji++;
           x[i]/=2; 
        }
    }
    //  
    for(Int i=0;i<=60;i++){
        Int cheng = (cnt[i])*(n-cnt[i])%MOD;
        for(Int j=1;j<=i;j++) cheng = cheng*2%MOD;
        ans = (ans+cheng)%MOD;
    }//ここ分からんぞ〜〜？！
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main() {
	int num[10] , n , i , pow;
	
	while ( scanf("%d",&n) !=EOF ) {
		pow = 1;
		for ( ; pow *2 <= n; pow *= 2 );
		for ( i = 0; n != 0; pow = pow / 2 ) {
			if ( (n - pow) >= 0 ) {
				n -= pow;
				num[i] = pow;
				i++;
			}
		}
		for ( i -= 1; i >= 0; i-- ) {
			printf("%d",num[i]);
			if ( i == 0 ) break;
			else printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	vector<pair<int,int>>ab(n);
	for(auto&&i:ab)cin>>i.first>>i.second;
	sort(ab.begin(),ab.end());
	priority_queue<int>q; q.push(0);
	int64_t ans=0;
	for(int i=1,j=0;i<=m;++i){
		while(j<n&&ab.at(j).first<=i){
			q.push(ab.at(j).second);
			++j;
		}
		ans+=q.top();
		q.pop();
		q.push(0);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 4672
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <random>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
 
template <class T> struct Dijkstra {

    struct Edge{
        int to;
        T cost;
        Edge(int _to, T _cost) : to(_to), cost(_cost) {}
    };
    
    const T INF_T = numeric_limits<T>::max() / 2;
    vector< vector< Edge > > G;
    vector< T > d;
    Dijkstra (int n) : G(n), d(n) {}

    void add_directed_edge(int a, int b, T c) {
        G[a].push_back(Edge(b,c));
    }
    
    void add_undirected_edge(int a, int b, T c) {
        G[a].push_back(Edge(b,c));
        G[b].push_back(Edge(a,c));
    }

    void init(int s) {
        priority_queue< pair<T,int>,vector< pair<T,int> >, greater< pair<T,int> > > que;
        for (int i = 0; i < d.size(); i++) d[i] = INF_T;
        d[s] = 0;
        que.push(make_pair(0,s));
        while (!que.empty()){
            pair<T,int> p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (int i = 0; i < G[v].size(); i++) {
                Edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to],e.to));
                }
            }
        }
    }
    
    T dist(int a) {
        return d[a];
    }
    
}; 

int main() {

    int N,M; cin >> N >> M;
    Dijkstra<int> inst(201000);

    REP(i,M) {
        int a,b; cin >> a >> b;
        inst.add_undirected_edge(a,b,1);
    }

    inst.init(1);

    int d = inst.dist(N);
    if(d == 2) {
        cout << "POSSIBLE" << endl;
    } else{
        cout<<"IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 15080
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}



struct UnionFind {
	vector<int> par, rank, cnt;
	UnionFind(int n) : par(n), rank(n, 0), cnt(n, 1){
		for(int i = 0; i < n; ++i) par[i] = i;
	}
 
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	
 
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
 
		if (rank[x] < rank[y]) swap(x, y);
 
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
 
	bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	int size(int x) {
		return cnt[find(x)];
	}
};



int main(){
    int N, M; cin >> N >> M;
    vector<int> a(M), b(M);
    for (int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    int ans = 0;
    for (int i = 0; i < M; i++){
        int point = i;
        UnionFind uf(N);
        for (int j = 0; j < M; j++){
            if (j == point) continue;
            uf.unite(a[j], b[j]);
        }

        if (!uf.same(a[point], b[point])){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;


ll X,Y;

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

    ll cnt = 1;
    while(X <= Y){
        X *= 2;
        cnt++;
    }

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



Measured memory_bytes: 256
#include "cstring"
#include "iostream"

using namespace std;

int main()
{
	int N, X;
	int t;
	int m[101];
	int min = 1000;
	int n=0;
	cin >> N >> X;

	for (t = 0; t < N; ++t) {
		cin >> m[t];
		X -= m[t];
		n++;
		if (min > m[t]) {
			min = m[t];
		}
	}

	int answer = n + (X / min);

	cout << answer;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
vi = list(map(int,input().split()))
vi_sort = sorted(vi)

if N == 2:
  print((vi[0]+vi[1])/2)
else:
  i = 0
  while i < (N-1):
    new_number = (vi_sort[0]+vi_sort[1])/2
    del vi_sort[0:2]
    vi_sort.append(new_number)
    vi_sort.sort()
    i += 1
    
  print(vi_sort[0])

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

int h,w;
vector<vector<char>> field;

bool dfs(int x,int y){
    if(field[x+1][y]=='#'&&field[x][y+1]=='#') return false;
    if(field[x-1][y]=='#'&&field[x][y-1]=='#') return false;
    if(x==h&&y==w) return true;
    if(field[x+1][y]=='#'){
        if(dfs(x+1,y)) return true;
    }
    if(field[x][y+1]=='#'){
        if(dfs(x,y+1)) return true;
    }
    return false;
}

int main(){
    cin>>h>>w;
    field.resize(h+3,vector<char>(w+3));
    rep(i,h) rep(j,w) cin>>field[i][j];
    if(dfs(1,1)) cout<<"Possible";
    else cout<<"Impossible";
}

Measured memory_bytes: 3596
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	char a[]=input.readLine().toCharArray();
	String str=String.valueOf(a);
	for(int i=0;i<a.length;i++)
	    {
		if(a[i]=='A')a[i]='X';
		else if(a[i]=='B')a[i]='Y';
		else if(a[i]=='C')a[i]='Z';
		else
		    {
			a[i]=(char)(a[i]-3);
			str=String.valueOf(a);
		    }
	    }
	System.out.println(str);
    }
}

Measured memory_bytes: 18164
#include<stdio.h>
#include<math.h>


typedef long long ll;

int degnum(long long x)
{
	int i;

	for(i=1;x>=10;i++,x/=10)
		;
	return i;
}


int min(int a, int b)
{
	if(a<b) return a;
	return b;
}

int main(void)
{
	ll N, i;
	int result;
	double t;

	while(scanf("%lf", &t)==1)
	{
		N=t;
		t=sqrt(N)+0.1;

		result=50;
		for(i=1;i<t;i++)
		{
			if(N%i==0)
			{
				result=min(result, degnum(N/i));
			}
		}
		printf("%d\n", result);
	}

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v_odd(100100), v_even(100100);
  int odd1count = 0, odd2count = 0, even1count = 0, even2count = 0;
  int odd1value = 0, odd2value = 0, even1value = 0, even2value = 0;
  int v;
  rep(i,n) {
    cin >> v;
    if (i%2 == 0) {
      v_odd[v]++;
      if (v_odd[v] > odd1count) {
        odd1count = v_odd[v];
        odd1value = v;
      } else if (v_odd[v] > odd2count) {
        odd2count = v_odd[v];
        odd2value = v;
      }
    } else {
      v_even[v]++;
      if (v_even[v] > even1count) {
        even1count = v_even[v];
        even1value = v;
      } else if (v_even[v] > even2count) {
        even2count = v_even[v];
        even2value = v;
      }
    }
  }

  int ans;
  if (odd1value != even1value) {
    ans = n - odd1count - even1count;
  } else {
    ans = n - max(odd1count+even2count, odd2count+even1count);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int H[1000],W[1000];
    int h,w;
    int a=0,b=0;
    for(;;){
        cin>>H[a]>>W[a];
        if(H[a]==0&&W[a]==0){
            break;
        }
        a++;
    }
    for(;;){
        h = H[b];
        for (;;) {
            w = W[b];
            for(;;){
                cout << "#";
                w = w-1;
                if(w==0){
                    cout<<endl;
                    break;
                }
                cout<<".";
                w=w-1;
                if(w==0){
                    cout<<endl;
                    break;
                }
            }
            h=h-1;
            if(h==0){
                cout<<endl;
                break;
            }
            w=W[b];
            for(;;){
                cout<<".";
                w=w-1;
                if(w==0){
                    cout<<endl;
                    break;
                }
                cout<<"#";
                w=w-1;
                if(w==0){
                    cout<<endl;
                    break;
                }
            }
            h=h-1;
            if(h==0){
                cout<<endl;
                break;
            }
        }
        b=b+1;
       if(a==b){
            return 0;
        }
    }
}



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

int main(){
    int A,B;
    cin >> A >> B;
    if(A>=13){
        cout << B << endl;
    }
    else if(A<=12){
        if (A>=6){
            cout << B/2 << endl;
        }
        else{
            cout << "0" << endl;
        }
    }
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    vector<int>a(n);
    rep(i,n)cin>>a[i];

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

    int sum=0,ans=mod;

    rep2(i,a[0],a[n-1]+1){
        rep(j,n){
            sum+=pow(abs(a[j]-i),2);
        }

        ans=min(ans,sum);
        sum=0;
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	
	if (n % k == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

string s[5000];
int n, m;
int cnt[5000];

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (i * m + j * n - 2 * i * j == k)
            {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
}

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

#define int long long 


signed main(void){
    int n; cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin >>a[i];
    int ans = 1e9;
    for(int i=-100;i<=100;i++){
        int tmp = 0;
        for(int j=0;j<n;j++){
            tmp += pow((a[j]-i),2);
        }
        if(tmp < ans) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = $stdin.gets.chomp.to_i

if N == 3
    print '2 5 63'
    exit
else
    print '2 3 4 9'
    if N % 2 == 0
        en0 = [N - 4, 5000].min
    else
        en0 = [N - 4, 4999].min
    end
    rest = N - 4 - en0
    en1 = [rest/2, 4999].min
    on = rest - 2 * en1
    en0.times do |i|
        print ' ', i * 6 + 6
    end
    en1.times do |i|
        print ' ', i * 6 + 10
    end
    en1.times do |i|
        print ' ', i * 6 + 8
    end
    on.times do |i|
        print ' ', i * 6 + 15
    end
end


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

int main(){
  char mat[8][8];
  
  for(int i = 0 ; i < 8 ; i++)
    for(int j = 0 ; j < 8 ; j++)
      cin >> mat[i][j];

  cout << "90" << endl;
  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      cout << mat[8-j-1][i];
    }
    cout << endl;
  }
  
  cout << "180" << endl;
  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      cout << mat[8-i-1][8-j-1];
    }
    cout << endl;
  }  

  cout << "270" << endl;
  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      cout << mat[j][8-i-1];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1136
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

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

using ll = long long;
using P = pair<int,int>;

template<class T> inline bool chmin(T& a, T b){ if(a>b){a=b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b){ if(a<b){a=b; return 1;} return 0;}

const ll INF = 1LL<<60;

//#define __DBG__


void solve(void){

  int N;

  cin >> N;
  
  vector<int> P={2};

  REP2(i,2,N+100){
    int count=0;
    REP(j,P.size()){
      if(i%P[j]!=0){
        count++;
      }
    }
    if(count==P.size()){
      P.push_back(i);
//      cout << i << ',';
    }
  }
 
  auto iter = lower_bound(P.begin(),P.end(), N);

  
  cout << *iter << endl;
  
  return;
}

int main(int argc, const char * argv[]) {



    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}





Measured memory_bytes: 384
import math
hl, ml, h, m = map(int, input().split())

rot = (h * 30 + m * 0.5) / 360 * math.pi * 2

hx = math.sin(rot) * hl
hy = math.cos(rot) * hl

rot = m * 6 / 360 * math.pi * 2
mx = math.sin(rot) * ml
my = math.cos(rot) * ml

dx = hx - mx
dy = hy - my
ans = math.sqrt(dx * dx + dy * dy)
print(ans)

Measured memory_bytes: 9516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
	ll n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n) cin>>a[i];
	ll before=0;
	ll ans=0;
	for(ll i=n-1;i>=0;i--){
		if(a[i]>=before){
			ans+=a[i];
		}
		else if(before-a[i]>=2){
			cout<<-1<<endl;
			return 0;
		}
		before=a[i];
	}
	if(a[0]!=0){
		cout<<-1<<endl;
		return 0;
	}
	cout<<ans<<endl;

}

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

int int_sort(const void *a, const void *b)
{
	if (*(int *)a < *(int *)b){
		return (-1);
	}
	else if (*(int *)a == *(int *)b){
		return (0);
	}
	
	return (1);
}

int main(void)
{
	int com[10000];
	long long sum[10000];
	long long ans;
	long long tmp;
	int i, n;
	
	while( scanf("%d", &n)){
		if( n == 0 )break;
		
		for (i = 0; i < n; i++){
			scanf("%d", &com[i]);
		}
		
		qsort(com, n, sizeof(com[0]), int_sort);
		
		tmp = ans = 0;
		for (i = 0; i < n - 1; i++){
			tmp += com[i];
			sum[i] = tmp;
			ans += sum[i];
		}
		
		printf("%lld\n", ans);
	}
	
	return (0);
	
}

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

const ll INF = 1LL << 60;

template<class T> inline bool chmax(T &a, T b)
{
    if(a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for(int i=0; i<N; i++)
    {
        cin >> P[i];
        P[i]--;
    }
    vector<int> C(N);
    for(int i=0; i<N; i++) cin >> C[i];

    ll ans = -INF;
    for(int i=0; i<N; i++)
    {
        int start = i;
        int now = P[start];
        ll lans = 0;
        int cnt = 1;
        for(; cnt<=K; cnt++)
        {
            lans += C[now];
            chmax(ans, lans);
            if(now == start) break;
            now = P[now];
        }
        chmax(ans, lans);
        if(K % cnt != 0)
        {
            lans *= K / cnt;
            cnt = K - (K % cnt) + 1;
        }
        else
        {
            lans *= K / cnt - 1;
            cnt = K - (K % cnt) - cnt + 1;
        }
        
        for(; cnt<=K; cnt++)
        {
            now = P[now];
            lans += C[now];
            chmax(ans, lans);
        }
        chmax(ans, lans);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define foro(i, n) for(i=0; i<n; i++)
#define forl(i, n) for(i=1; i<=n; i++)
#define x first
#define y second
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;

int main()
{
	int i, j, k, l, tmp;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n >> k;
	if(!n)
		printf("1\n");
	else{
		int cnt=0;
		while(n){
			cnt++;
			n/=k;
		}
		printf("%d\n", cnt);
	}
}


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

void dfs(int y, int x, vector<string>& v) {
    int dx[4] = {0, -1, 0, 1},
        dy[4] = {1, 0, -1, 0};
    for(int i=0; i<4; ++i) {
        int ny = y + dy[i], nx = x + dx[i];
        if(0 <= ny && ny < 12 && 0 <= nx && nx < 12 && v[ny][nx] == '1') {
            v[ny][nx] = '0';
            dfs(ny, nx, v);
        }
    }
}

int main() {
    vector<string> v(12);
    while(cin >> v[0]) {
        for(int i=1; i<12; ++i) {
            cin >> v[i];
        }
        int res = 0;
        for(int i=0; i<12; ++i) {
            for(int j=0; j<12; ++j) {
                if(v[i][j] == '1') {
                    res++;
                    dfs(i, j, v);
                }
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3156
//***********************************************************************************************************//
//    TOPIC :
//***********************************************************************************************************//
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define ll long long int
#define ull unsigned long long int
#define INF 99999999
ll mod = 1e9 + 7;

// int mod = 1e9 + 7;
#define fr(a, b, c) for (int a = b; a < c; a++)
#define fre(a, b, c) for (int a = b; a <= c; a++)

class Timer
{
public:
    clock_t starting;
    Timer()
    {
        cout << "**..** Timer clock init **..**" << endl;
    }
    void start()
    {
        starting = clock();
    }
    void end()
    {
        double duration = (clock() - this->starting) / (double)CLOCKS_PER_SEC;
        cout << "**..** Time taken is " << duration << endl;
    }
};

void the_martian()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll powm(ll a, ull b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

vector<vector<ll>> dp;
void init(int n)
{
    vector<vector<ll>> d(n + 1);

    for (int i = 0; i < n + 1; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            d[i].pb(-1);
        }
    }
    dp = d;
}

int main()
{
    
    int n, k;
    cin >> n >> k;
    int w[n];
    int v[n];
    for (int i = 0; i < n; i++)
    {
        cin >> w[i];
        cin >> v[i];
    }

    ll mat[n + 1][k + 1];
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            if (i == 0)
                mat[i][j] = 0;
            else
            {
                if (j < w[i - 1])
                    mat[i][j] = mat[i - 1][j];
                else
                {
                    mat[i][j] = max(mat[i - 1][j], (v[i - 1] + mat[i - 1][j - w[i - 1]]));
                }
            }
        }
    }

    cout << mat[n][k] << endl;
}


Measured memory_bytes: 79104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner src = new Scanner(System.in);
		String s=src.next();
		String s2=src.next();
		int equal=0;
		for(int i=0;i<3;i++) {
			if(s.charAt(i)==s2.charAt(i))
				equal++;
		}
		System.out.print(equal);

	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

using namespace std;
typedef long long ll;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll n, x, t; cin >> n >> x >> t;
	cout << (n + x - 1) / x * t << endl;
}

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

inline int read()
{
    int x=0;
    char c=getchar();
    bool flag=0;
    while(c<'0'||c>'9')
	{
		if(c=='-') flag=1;
		c=getchar();
	}
    while(c>='0'&&c<='9')
	{
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
    return flag?-x:x;
}

int main()
{
	ll r,d,x;
	cin>>r>>d>>x;
	rep(i,1,10)
	{
		x*=r;
		x-=d;
		cout<<x<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int n, k; cin >> n >> k;
    int ans = k;
    rep(i,0,n-1) {
        ans *= (k-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int N,M,Q;
vector<int> a,b,c,d;
ll score(const vector<int> &A){
    int ans=0;
    rep(i,Q){
        if(A[b[i]]-A[a[i]]==c[i]) ans+=d[i];
    }
    return ans;
}

ll dfs(vector<int> &A){
    int num=A.size();
    if(num==N){
        return score(A);
    }

    int p=(A.empty()?0:A.back());
    ll res=0;
    for(int v=p; v<M; v++){
        A.push_back(v);
        res=max(res,dfs(A));
        A.pop_back();

    }
    return res;
}

int main(){
    cin>>N>>M>>Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    rep(i,Q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }
    vector<int> A;
    cout<<dfs(A)<<endl;
}

Measured memory_bytes: 3580
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)

	H, W := getInt(), getInt()
	a := make([][]byte, H)
	for i := 0; i < H; i++ {
		a[i] = []byte(getString())
	}

	hflg := make([]bool, H)
	for i := 0; i < H; i++ {
		del := true
		for j := 0; j < W; j++ {
			if a[i][j] != '.' {
				del = false
				break
			}
		}
		if del {
			hflg[i] = true
		}
	}

	wflg := make([]bool, W)
	for i := 0; i < W; i++ {
		del := true
		for j := 0; j < H; j++ {
			if a[j][i] != '.' {
				del = false
				break
			}
		}
		if del {
			wflg[i] = true
		}
	}

	for i := 0; i < H; i++ {
		if hflg[i] {
			continue
		}
		for j := 0; j < W; j++ {
			if wflg[j] != true {
				fmt.Print(string(a[i][j]))
			}
		}
		fmt.Println()
	}

}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    int l = 0, r = INF;
    for( int i = 0; i < m; ++i ) {
        int L, R;
        cin >> L >> R;
        if( l < L ) l = L;
        if( r > R ) r = R;
            
    }
    if( r < l ) cout << 0 << endl;
    else cout << r - l + 1 << endl;
    return 0;
}



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

int main() {
  int N, M;
  cin >>N >>M;// 島数、橋数
  vector<int> I(N+1, 0);// 島
  vector<int> A(M+1);// 橋始点
  vector<int> B(M+1);// 橋終点
  vector<long> F(M+1);// 取り除いた橋の数に対する不便さ
  vector<int> C(M/2+2, 0);// 島 Group 内の島数
  vector<vector<int>> L(N+1, vector<int>(0));
  long S=N*((long)N-1)/2;// 最初の不便さ
  // 橋読み込み
  for (int i=1; i<=M; i++) {
    cin >>A.at(i) >>B.at(i);
  }
  F.at(M)=S;/// 最初の（M 個の橋を取り除いたときの）不便さ
  int num=0;/// 島 Group#
  //int nn;
  for (int i=M; i>0; i--) {
    int a=A.at(i);
    int b=B.at(i);
    //cout << a << ":" << b << ":" << I.at(a) << ":" << I.at(b) << endl;/////////////
    int Ia=I.at(a);
    int Ib=I.at(b);
    if ((Ia==0) && (Ib==0)) {
      num++;
      //cout <<"0-0:"<< a << ":" << b << endl;////
      I.at(a)=I.at(b)=num;/// 新 Group： num
      S--;/// 解消された不便さ
      C.at(num)=2;///// num の島の数
      L.at(num)={a, b};
      /*//////////////////////////
      for (int jj=0; jj<L.at(num).size(); jj++)
        cout << L.at(num).at(jj);
      cout << endl;
      */////////////////////////
    } else if (Ia==0) {
      //cout <<"0-X:"<< a << ":" << b << endl;////
      I.at(a)=Ib;
      S-=C.at(Ib);/// 解消された不便さ
      C.at(Ib)++;/// num の島の数
      L.at(Ib).insert(L.at(Ib).end(), {a});
      /*//////////////////////////
      for (int jj=0; jj<L.at(nn).size(); jj++)
        cout << L.at(nn).at(jj);
      cout << endl;
      */////////////////////////
    } else if (Ib==0) {
      //cout <<"X-0:"<< a << ":" << b << endl;////
      I.at(b)=Ia;
      S-=C.at(Ia);/// 解消された不便さ
      C.at(Ia)++;/// num の島の数
      L.at(Ia).insert(L.at(Ia).end(), {b});
      /*//////////////////////////
      for (int jj=0; jj<L.at(nn).size(); jj++)
        cout << L.at(nn).at(jj);
      cout << endl;
      */////////////////////////
    } else if (Ia!=Ib) {
      if (C.at(Ia)<C.at(Ib)) swap(Ia, Ib);
      S-=C.at(Ia)*C.at(Ib);/// 解消された不便さ
      C.at(Ia)+=C.at(Ib);/// num の島の数
      //C.at(I.at(b)=0;/// Not required
      for (int j=0; j<C.at(Ib); j++)
        I.at(L.at(Ib).at(j))=Ia;
      L.at(Ia).insert(L.at(Ia).end(), L.at(Ib).begin(), L.at(Ib).end());
      L.at(Ib).erase(L.at(Ib).begin(), L.at(Ib).end());
      /*//////////////////////////
      for (int jj=0; jj<L.at(nn).size(); jj++)
        cout << L.at(nn).at(jj);
      cout << endl;
      */////////////////////////
    } else {
      /// Do nothing
    }
    //cout << i-1 << ":" << S << endl;/////
    F.at(i-1)=S;
  }
  for (int i=1; i<=M; i++)
    cout << F.at(i) << endl;
  return 0;
}


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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define int long long
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 10000000000000003;

int n,m,b[li],a[li],k,flag,t,p[li];
int cev;
string s;
map<int,int> mpp,st;
vector<int> v;

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

inline int add(int x,int y){
	int xx=(x%mod);
	int yy=(y%mod);
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

main(void){
	fio();
	cin>>n>>s;
	//~ int n=(int)s.size();
	int bas=1;
	int son=(n)/2;
	//~ cout<<ort<<endl;
	p[0]=1;
	for(int i=1;i<=n;i++){
		p[i]=mul(p[i-1],37);
	}
	while(bas<=son){
		cev=0;
		flag=0;
		mpp.clear();
		for(int i=0;i<ort;i++){
			cev=add(cev,mul(p[ort-i-1],(s[i]-'a'+1)));
		}
		st[cev]=ort-1;
		mpp[cev]=1;
		//~ if(ort==3)cout<<cev<<endl;
		for(int i=ort;i<n;i++){
			cev=add(cev-mul(p[ort-1],(s[i-ort]-'a'+1)),mod);
			cev=mul(cev,37);
			cev=add(cev,s[i]-'a'+1);
			if(mpp[cev]==0)st[cev]=i;
			//~ if(ort==3)cout<<cev<<endl;
			mpp[cev]++;
			if(mpp[cev]>=2 && i-st[cev]>=ort){flag=1;break;}
		}
		if(flag==1){bas=ort+1;}
		else son=ort-1;
	}
	cout<<max(son,0ll)<<endl;
	return 0;
}


Measured memory_bytes: 5760